KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > business > calendar > struts > FindEventAction


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: FindEventAction.java,v $
31  * Revision 1.3 2005/04/10 20:09:42 colinmacleod
32  * Added new themes.
33  * Changed id type to String.
34  * Changed i tag to em and b tag to strong.
35  * Improved PicoContainerFactory with NanoContainer scripts.
36  *
37  * Revision 1.2 2005/04/09 17:19:18 colinmacleod
38  * Changed copyright text to GPL v2 explicitly.
39  *
40  * Revision 1.1.1.1 2005/03/10 17:47:45 colinmacleod
41  * Restructured ivata op around Hibernate/PicoContainer.
42  * Renamed ivata groupware.
43  *
44  * Revision 1.8 2004/12/31 18:27:43 colinmacleod
45  * Added MaskFactory to constructor of MaskAction.
46  *
47  * Revision 1.7 2004/11/12 18:19:14 colinmacleod
48  * Change action and form classes to extend MaskAction, MaskForm respectively.
49  *
50  * Revision 1.6 2004/11/12 16:08:11 colinmacleod
51  * Removed dependencies on SSLEXT.
52  * Moved Persistence classes to ivata masks.
53  *
54  * Revision 1.5 2004/11/03 15:31:50 colinmacleod
55  * Change method interfaces to remove log.
56  *
57  * Revision 1.4 2004/07/13 19:42:14 colinmacleod
58  * Moved project to POJOs from EJBs.
59  * Applied PicoContainer to services layer (replacing session EJBs).
60  * Applied Hibernate to persistence layer (replacing entity EJBs).
61  *
62  * Revision 1.3 2004/03/21 21:16:22 colinmacleod
63  * Shortened name to ivata op.
64  *
65  * Revision 1.2 2004/02/01 22:07:29 colinmacleod
66  * Added full names to author tags
67  *
68  * Revision 1.1.1.1 2004/01/27 20:58:21 colinmacleod
69  * Moved ivata openportal to SourceForge..
70  *
71  * Revision 1.4 2003/11/13 16:07:26 jano
72  * commitng everything to CVS
73  * can deploy and application is ruuning, can login into
74  *
75  * Revision 1.3 2003/10/28 13:10:23 jano
76  * commiting calendar,
77  * still fixing compile and building openGroupware project
78  *
79  * Revision 1.2 2003/10/15 13:57:23 colin
80  * fixing for XDoclet
81  *
82  * Revision 1.5 2003/04/14 07:10:15 peter
83  * fixed helpKey logic
84  *
85  * Revision 1.4 2003/02/28 09:36:51 jano
86  * RuntimeException(e) -> IntrnetRuntimeException
87  *
88  * Revision 1.3 2003/02/27 12:30:42 peter
89  * fixed converting of attendeeIds to String in execute
90  *
91  * Revision 1.2 2003/02/25 17:26:46 peter
92  * fixed SettingDateFormatter initialisation settings
93  *
94  * Revision 1.1 2003/02/24 19:09:22 colin
95  * moved to business
96  *
97  * Revision 1.3 2003/02/20 13:00:58 peter
98  * 24H time formats changed to simple ones
99  *
100  * Revision 1.2 2003/02/13 08:45:42 colin
101  * conversion to Struts/popups
102  *
103  * Revision 1.1 2003/02/04 17:41:16 colin
104  * first version in CVS
105  *
106  * Revision 1.6 2003/01/30 09:02:19 colin
107  * updates for struts conversion
108  *
109  * Revision 1.5 2003/01/18 20:12:36 colin
110  * fixes and changes to override new MaskAction method
111  *
112  * Revision 1.4 2003/01/10 10:29:46 jano
113  * we need information about user who created group
114  *
115  * Revision 1.3 2003/01/09 10:50:54 jano
116  * I need only one method for finding right for group
117  *
118  * Revision 1.2 2003/01/08 17:16:21 jano
119  * We will use new methods for finding and changing rights for
120  * GROUP of AddressBookRightsBean
121  * -----------------------------------------------------------------------------
122  */

123 package com.ivata.groupware.business.calendar.struts;
124
125 import java.util.HashSet JavaDoc;
126 import java.util.Iterator JavaDoc;
127 import java.util.List JavaDoc;
128 import java.util.Set JavaDoc;
129 import java.util.Vector JavaDoc;
130
131 import javax.servlet.http.HttpServletRequest JavaDoc;
132 import javax.servlet.http.HttpServletResponse JavaDoc;
133 import javax.servlet.http.HttpSession JavaDoc;
134
135 import org.apache.struts.action.ActionErrors;
136 import org.apache.struts.action.ActionForm;
137 import org.apache.struts.action.ActionMapping;
138
139 import com.ivata.groupware.admin.security.server.SecuritySession;
140 import com.ivata.groupware.business.addressbook.person.PersonDO;
141 import com.ivata.groupware.business.calendar.Calendar;
142 import com.ivata.groupware.business.calendar.event.EventDO;
143 import com.ivata.groupware.business.calendar.event.meeting.MeetingDO;
144 import com.ivata.groupware.business.calendar.event.publicholiday.PublicHolidayDO;
145 import com.ivata.groupware.container.PicoContainerFactory;
146 import com.ivata.groupware.util.SettingDateFormatter;
147 import com.ivata.mask.MaskFactory;
148 import com.ivata.mask.util.CollectionHandling;
149 import com.ivata.mask.util.SystemException;
150 import com.ivata.mask.web.format.DateFormatterConstants;
151 import com.ivata.mask.web.struts.MaskAction;
152 import com.ivata.mask.web.struts.MaskAuthenticator;
153
154
155 /**
156  * <p>This action is invoked from the main calendar viewpage. This
157  * action locates the event and prepares the form for
158  * <code>event.jsp</code>.</p>
159  *
160  * @since 2003-02-02
161  * @author Colin MacLeod
162  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
163  * @version $Revision: 1.3 $
164  */

165 public class FindEventAction extends MaskAction {
166     private Calendar calendar;
167     private SettingDateFormatter dateFormatter;
168     /**
169      * TODO
170      *
171      * @param calendar
172      * @param dateFormatter
173      * @param maskFactory This factory is needed to access the masks and groups
174      * of masks.
175      * @param authenticator used to confirm whether or not the
176      * user should be allowed to continue, in the <code>execute</code> method.
177      */

178     public FindEventAction(Calendar calendar, SettingDateFormatter dateFormatter,
179             MaskFactory maskFactory, MaskAuthenticator authenticator) {
180         super(maskFactory, authenticator);
181         this.calendar = calendar;
182         this.dateFormatter = dateFormatter;
183     }
184
185     /**
186      * <p>Invoked when the user clicks on an event in the calendar.</p>
187      *
188      * @param mapping current action mapping from <em>Struts</em> config.
189      * @param log valid logging object to write messages to.
190      * @param errors valid errors object to append errors to. If there are
191      * any errors, the action will return to the input.
192      * @param form optional ActionForm bean for this request (if any)
193      * @param request non-HTTP request we are processing
194      * @param response The non-HTTP response we are creating
195      * @param session returned from the <code>request</code> parameter.
196      * @param userName current user name from session. .
197      * @param settings valid, non-null settings from session.
198      * @exception SystemException if there is any problem which
199      * prevents processing. It will result in the webapp being forwarded
200      * to
201      * the standard error page.
202      * @return this method returns the string used to identify the correct
203      * <em>Struts</em> <code>ActionForward</code> which should follow this
204      * page, or <code>null</code> if it should return to the input.
205      *
206      *
207      */

208     public String JavaDoc execute(final ActionMapping mapping,
209             final ActionErrors errors,
210             final ActionForm form,
211             final HttpServletRequest JavaDoc request,
212             final HttpServletResponse JavaDoc response,
213             final HttpSession JavaDoc session) throws SystemException {
214         // create a new event form then call reset to make sure the calendar is there
215
SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession");
216         EventForm eventForm = (EventForm)
217             PicoContainerFactory.getInstance().instantiateOrOverride(
218                     securitySession.getContainer(),
219                     EventForm.class);
220
221         eventForm.reset(mapping, request);
222         String JavaDoc id = request.getParameter("id");
223
224         if (id == null) {
225             throw new SystemException("ERROR in FindEventAction: id is null");
226         }
227         EventDO event = calendar.findEventByPrimaryKey(securitySession, id);
228         // ok, this is not very efficient. it kinda grew this way out of
229
// hysteric reasons :-)
230
// the only alternative I can see is to add a 'type' request parameter
231
// and I don't want to do this as it will make all the views more
232
// complicated
233
if (event instanceof MeetingDO) {
234             MeetingDO meeting = (MeetingDO) event;
235             Set JavaDoc attendees = meeting.getAttendees();
236             if (attendees == null) {
237                 meeting.setAttendees(attendees = new HashSet JavaDoc());
238             }
239             List JavaDoc attendeeIds = new Vector JavaDoc(attendees.size());
240             // make strings of Integers
241
for (Iterator JavaDoc i = attendees.iterator(); i.hasNext(); ) {
242                 PersonDO attendee = (PersonDO) i.next();
243                 attendeeIds.add(attendee.getId().toString());
244             }
245             eventForm.setAttendees(CollectionHandling.convertToLines(attendeeIds, ';'));
246         }
247         dateFormatter.setDateTimeText("{0}");
248         // TODO: replace this with settings
249
dateFormatter.setDateFormat(DateFormatterConstants.DATE_INPUT_DISPLAY);
250         dateFormatter.setTimeFormat(DateFormatterConstants.TIME_INPUT_DISPLAY);
251         eventForm.setStartDate(dateFormatter.format(event.getStart().getTime()));
252         if (event.getFinish() == null) {
253             eventForm.setFinishDate("");
254         } else {
255             eventForm.setFinishDate(dateFormatter.format(event.getFinish().getTime()));
256         }
257         dateFormatter.setDateTimeText("{1}");
258         eventForm.setStartTime(dateFormatter.format(event.getStart().getTime()));
259         if (event.getFinish() == null) {
260             eventForm.setFinishTime("");
261         } else {
262             eventForm.setFinishTime(dateFormatter.format(event.getFinish().getTime()));
263         }
264
265         // go thro' all the types and set the form up for the right one
266
// note if this request parameter is set, it indicates a new event
267
// existing events are retrieved in FindEventAction.java
268
if (event instanceof MeetingDO) {
269             eventForm.setTitleKey("event.title.amend.meeting");
270             eventForm.setHelpKey("calendar.meeting.event");
271         } else if (event instanceof PublicHolidayDO) {
272             eventForm.setTitleKey("event.title.amend.publicHoliday");
273             eventForm.setHelpKey("calendar.publicHoliday");
274         } else {
275             // default is standard event
276
eventForm.setHelpKey("calendar.event");
277             eventForm.setTitleKey("event.title.amend");
278         }
279         eventForm.setEvent(event);
280         session.setAttribute("calendarEventForm", eventForm);
281         return "calendarEvent";
282     }
283 }
284
Popular Tags