1
2
3
4
5
6
7
8 package net.stff.ical;
9
10 import java.io.InputStream;
11 import java.util.Date;
12 import java.util.List;
13
14 import net.stff.ical.beans.ICal;
15 import net.stff.ical.beans.IEvent;
16 import net.stff.ical.persistance.ICalDAO;
17
18 import org.springframework.beans.factory.xml.XmlBeanFactory;
19
20
21
22 /***
23 * <br>The CalendarManager presents the facade to the Calendar data. All access to Calendar data is routed through here.
24 * @author buntekuh
25 *
26 */
27 public class CalendarManager {
28
29 private ICalDAO iCalDAO;
30
31
32 public CalendarManager(){
33 InputStream stream= getClass().getClassLoader().getResourceAsStream("applicationContext.xml");
34 XmlBeanFactory beanFactory= new XmlBeanFactory(stream);
35 iCalDAO= (ICalDAO)beanFactory.getBean("iCalDAO");
36 }
37
38 /***
39 * Returns a List of all calendars associated to the given user.
40 * @param user The user associated to the calendars to be returned.
41 * @return Returns a List of all calendars created by the given user.
42 */
43 public List getCalendars(String user) {
44 return iCalDAO.getCalendars(user);
45 }
46
47 /***
48 * Returns a List of all calendarnames associated to the given user.
49 * @param user The user associated to the calendarnames to be returned.
50 * @return Returns a list of all calendar names associated to the given user.
51 */
52 public List getCalendarNames(String user) {
53
54 return iCalDAO.getCalendarNames(user);
55 }
56
57 /***
58 * Adds a new Calendar.
59 * @param name The key under which the calendar is to be stored. The key must be unique for the given user.
60 * @param user The user to be associated to the new calendar.
61 */
62 public void addCalendar(String name, String user){
63 iCalDAO.addCalendar(name, user);
64 }
65
66 /***
67 * Stores an ICal Object in the datastore
68 * @param cal The Calendar object to be added
69 */
70 public void addCalendar(ICal cal){
71 iCalDAO.addCalendar(cal);
72 }
73
74 /***
75 * Retrieves a calendar.
76 * @param name The key under which the calendar is stored
77 * @param user The user that is associated to the calendar to return.
78 * @return The requested calendar.
79 */
80 public ICal getCalendar(String name, String user){
81
82 return iCalDAO.getCalendar(name, user);
83
84 }
85
86 /***
87 * Returns a List of events that <b>start</b> within the given time range.
88 * @param s The earliest moment a returned event is to sart at
89 * @param e The latest moment a returned event is to sart at
90 * @param user the associated user.
91 * @param which Discerns between available event types. @see iCalDAO
92 * @return Returns a List of events.
93 */
94 public List getEventsForPeriod(Date s, Date e, String user, int which){
95 return iCalDAO.getEventsForPeriod(s, e, user, which);
96 }
97
98 /***
99 * Updates a given event in the datastore.
100 * @param event The event to be updated
101 * @return Returns the calendar wherein the event is stored in
102 */
103 public ICal editEvent(IEvent event){
104 iCalDAO.updateEvent(event);
105 event.recompute();
106 return event.getCalendar();
107
108 }
109
110 /***
111 * Returns an event.
112 * @param id The event id.
113 * @return
114 */
115 public IEvent getEvent(String id){
116 return iCalDAO.getEvent(id);
117 }
118
119 /***
120 * Utility method that saves the shown attribute of a given calendar
121 * @param name The name under which the calendar is stored
122 * @param shown the value to be saved
123 * @param user The associated user
124 */
125 public void setShown(String name, boolean shown, String user){
126 ICal cal= getCalendar(name, user);
127 cal.setShown(shown);
128 iCalDAO.updateCalendar(cal);
129 }
130
131 /***
132 * Utility method that saves the color attribute of a given calendar
133 * @param name The name under which the calendar is stored
134 * @param col the value to be saved
135 * @param user The associated user
136 */
137 public void setColor(String name, String col, String user){
138 ICal cal= getCalendar(name, user);
139 cal.setColor(col);
140 iCalDAO.updateCalendar(cal);
141 }
142
143 /***
144 * Utility method to rename a given calendar
145 * @param name The name under which the calendar is currently stored
146 * @param newName the new value for the calendar name
147 * @param user The associated user
148 */
149 public void rename(String name, String newName, String user){
150 ICal cal= getCalendar(name, user);
151 cal.setName(newName);
152 iCalDAO.updateCalendar(cal);
153 }
154
155 /***
156 * Deletes a calendar from the datastore.
157 * @param name the name of the calendar to be deleted
158 * @param user the associated user
159 */
160 public void delete(String name, String user){
161 ICal cal= getCalendar(name, user);
162 iCalDAO.removeCalendar(cal);
163 }
164
165 /***
166 * Deletes the given event from the datastore.
167 * @param event the given event.
168 */
169 public void deleteEvent(IEvent event){
170 iCalDAO.removeEvent(event);
171 }
172
173 /***
174 * Sets the DAO object. The DAO object is the datastore specific implementation
175 * @param calDAO The iCalDAO to set.
176 */
177 public void setICalDAO(ICalDAO iCalDAO) {
178 this.iCalDAO = iCalDAO;
179 }
180 }