001: /*
002: * Copyright (c) 2001 - 2005 ivata limited.
003: * All rights reserved.
004: * -----------------------------------------------------------------------------
005: * ivata groupware may be redistributed under the GNU General Public
006: * License as published by the Free Software Foundation;
007: * version 2 of the License.
008: *
009: * These programs are free software; you can redistribute them and/or
010: * modify them under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; version 2 of the License.
012: *
013: * These programs are distributed in the hope that they will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: *
017: * See the GNU General Public License in the file LICENSE.txt for more
018: * details.
019: *
020: * If you would like a copy of the GNU General Public License write to
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place - Suite 330
024: * Boston, MA 02111-1307, USA.
025: *
026: *
027: * To arrange commercial support and licensing, contact ivata at
028: * http://www.ivata.com/contact.jsp
029: * -----------------------------------------------------------------------------
030: * $Log: FindTopicAction.java,v $
031: * Revision 1.4 2005/04/29 02:48:16 colinmacleod
032: * Data bugfixes.
033: * Changed primary key back to Integer.
034: *
035: * Revision 1.3 2005/04/10 20:31:58 colinmacleod
036: * Added new themes.
037: * Changed id type to String.
038: * Changed i tag to em and b tag to strong.
039: * Improved PicoContainerFactory with NanoContainer scripts.
040: *
041: * Revision 1.2 2005/04/09 17:19:46 colinmacleod
042: * Changed copyright text to GPL v2 explicitly.
043: *
044: * Revision 1.1.1.1 2005/03/10 17:52:05 colinmacleod
045: * Restructured ivata op around Hibernate/PicoContainer.
046: * Renamed ivata groupware.
047: *
048: * Revision 1.10 2004/12/31 18:27:44 colinmacleod
049: * Added MaskFactory to constructor of MaskAction.
050: *
051: * Revision 1.9 2004/12/23 21:01:29 colinmacleod
052: * Updated Struts to v1.2.4.
053: * Changed base classes to use ivata masks.
054: *
055: * Revision 1.8 2004/11/12 18:19:15 colinmacleod
056: * Change action and form classes to extend MaskAction, MaskForm respectively.
057: *
058: * Revision 1.7 2004/11/12 15:57:16 colinmacleod
059: * Removed dependencies on SSLEXT.
060: * Moved Persistence classes to ivata masks.
061: *
062: * Revision 1.6 2004/11/03 15:31:51 colinmacleod
063: * Change method interfaces to remove log.
064: *
065: * Revision 1.5 2004/07/13 19:47:29 colinmacleod
066: * Moved project to POJOs from EJBs.
067: * Applied PicoContainer to services layer (replacing session EJBs).
068: * Applied Hibernate to persistence layer (replacing entity EJBs).
069: *
070: * Revision 1.4 2004/03/21 21:16:29 colinmacleod
071: * Shortened name to ivata op.
072: *
073: * Revision 1.3 2004/02/10 19:57:23 colinmacleod
074: * Changed email address.
075: *
076: * Revision 1.2 2004/02/01 22:07:31 colinmacleod
077: * Added full names to author tags
078: *
079: * Revision 1.1.1.1 2004/01/27 20:58:41 colinmacleod
080: * Moved ivata openportal to SourceForge..
081: *
082: * Revision 1.3 2003/10/28 13:16:14 jano
083: * commiting library,
084: * still fixing compile and building openGroupware project
085: *
086: * Revision 1.2 2003/10/15 14:16:53 colin
087: * fixing for XDoclet
088: *
089: * Revision 1.2 2003/03/03 16:57:12 colin
090: * converted localization to automatic paths
091: * added labels
092: * added mandatory fieldName attribute
093: *
094: * Revision 1.1 2003/02/24 19:09:24 colin
095: * moved to business
096: *
097: * Revision 1.9 2003/02/04 17:43:50 colin
098: * copyright notice
099: *
100: * Revision 1.8 2003/01/18 20:21:18 colin
101: * conversion to new MaskAction methods
102: * -----------------------------------------------------------------------------
103: */
104: package com.ivata.groupware.business.library.struts;
105:
106: import java.lang.reflect.InvocationTargetException;
107:
108: import javax.servlet.http.HttpServletRequest;
109: import javax.servlet.http.HttpServletResponse;
110: import javax.servlet.http.HttpSession;
111:
112: import org.apache.commons.beanutils.PropertyUtils;
113: import org.apache.struts.action.ActionErrors;
114: import org.apache.struts.action.ActionForm;
115: import org.apache.struts.action.ActionMapping;
116:
117: import com.ivata.groupware.admin.security.server.SecuritySession;
118: import com.ivata.groupware.business.addressbook.person.group.right.RightConstants;
119: import com.ivata.groupware.business.library.Library;
120: import com.ivata.groupware.business.library.right.LibraryRights;
121: import com.ivata.groupware.business.library.topic.TopicDO;
122: import com.ivata.mask.MaskFactory;
123: import com.ivata.mask.util.StringHandling;
124: import com.ivata.mask.util.SystemException;
125: import com.ivata.mask.web.struts.MaskAction;
126: import com.ivata.mask.web.struts.MaskAuthenticator;
127:
128: /**
129: * <p><code>Action</code> invoked when you calling topicModify.jsp
130: * from topic.jsp.</p>
131: * <!--**********************************************************************-->
132: *
133: * @since 2002-11-22
134: * @author Jan Boros <janboros@sourceforge.net>
135: * @version $Revision: 1.4 $
136: */
137: public class FindTopicAction extends MaskAction {
138: Library library;
139: LibraryRights libraryRights;
140:
141: /**
142: * TODO
143: * @param library
144: * @param libraryRights
145: * @param maskFactory This factory is needed to access the masks and groups
146: * of masks.
147: * @param authenticator used to confirm whether or not the
148: * user should be allowed to continue, in the <code>execute</code> method.
149: */
150: public FindTopicAction(Library library,
151: LibraryRights libraryRights, MaskFactory maskFactory,
152: MaskAuthenticator authenticator) {
153: super (maskFactory, authenticator);
154: this .library = library;
155: this .libraryRights = libraryRights;
156: }
157:
158: /**
159: * <p>Submit or cancel the form in
160: * <code>/library/topicModify.jsp</code>.</p>
161: *
162: * @param mapping current action mapping from <em>Struts</em> config.
163: * @param log valid logging object to write messages to.
164: * @param errors valid errors object to append errors to. If there are
165: * any errors, the action will return to the input.
166: * @param form optional ActionForm bean for this request (if any)
167: * @param request non-HTTP request we are processing
168: * @param response The non-HTTP response we are creating
169: * @param session returned from the <code>request</code> parameter.
170: * @param userName current user name from session. .
171: * @param settings valid, non-null settings from session.
172: * @exception SystemException if there is any problem which
173: * prevents processing. It will result in the webapp being forwarded
174: * to
175: * the standard error page.
176: * @return this method returns the string used to identify the correct
177: * <em>Struts</em> <code>ActionForward</code> which should follow this
178: * page, or <code>null</code> if it should return to the input.
179: *
180: */
181: public String execute(final ActionMapping mapping,
182: final ActionErrors errors, final ActionForm form,
183: final HttpServletRequest request,
184: final HttpServletResponse response,
185: final HttpSession session) throws SystemException {
186: SecuritySession securitySession = (SecuritySession) session
187: .getAttribute("securitySession");
188: try {
189: TopicForm libraryTopicForm = new TopicForm(library);
190:
191: // request parameter overrides
192: String requestId = request.getParameter("id");
193: Integer id;
194: if (requestId != null) {
195: id = StringHandling.integerValue(requestId);
196: } else {
197: id = (Integer) PropertyUtils.getSimpleProperty(form,
198: "id");
199: }
200:
201: TopicDO topic = library.findTopicByPrimaryKey(
202: securitySession, id);
203:
204: libraryTopicForm.setTopic(topic);
205:
206: // set view rights to ITEM in the form
207: java.util.Collection rights = libraryRights
208: .findRightsForItemsInTopic(securitySession, id,
209: RightConstants.ACCESS_VIEW);
210: Integer[] tmp = new Integer[rights.size()];
211: int a = 0;
212:
213: for (java.util.Iterator i = rights.iterator(); i.hasNext();) {
214: tmp[a] = (Integer) i.next();
215: a++;
216: }
217:
218: libraryTopicForm.setRightsViewItem(tmp);
219:
220: // set add rights to ITEM in the form
221: rights = libraryRights.findRightsForItemsInTopic(
222: securitySession, id, RightConstants.ACCESS_ADD);
223: tmp = new Integer[rights.size()];
224: a = 0;
225:
226: for (java.util.Iterator i = rights.iterator(); i.hasNext();) {
227: tmp[a] = (Integer) i.next();
228: a++;
229: }
230:
231: libraryTopicForm.setRightsAddItem(tmp);
232:
233: // set amend rights to ITEM in the form
234: rights = libraryRights.findRightsForItemsInTopic(
235: securitySession, id, RightConstants.ACCESS_AMEND);
236: tmp = new Integer[rights.size()];
237: a = 0;
238:
239: for (java.util.Iterator i = rights.iterator(); i.hasNext();) {
240: tmp[a] = (Integer) i.next();
241: a++;
242: }
243:
244: libraryTopicForm.setRightsAmendItem(tmp);
245:
246: // set delete rights to ITEM in the form
247: rights = libraryRights.findRightsForItemsInTopic(
248: securitySession, id, RightConstants.ACCESS_REMOVE);
249: tmp = new Integer[rights.size()];
250: a = 0;
251:
252: for (java.util.Iterator i = rights.iterator(); i.hasNext();) {
253: tmp[a] = (Integer) i.next();
254: a++;
255: }
256:
257: libraryTopicForm.setRightsRemoveItem(tmp);
258:
259: // set view rights to TOPIC in the form
260: rights = libraryRights.findRightsForTopic(securitySession,
261: id, RightConstants.ACCESS_VIEW);
262: tmp = new Integer[rights.size()];
263: a = 0;
264:
265: for (java.util.Iterator i = rights.iterator(); i.hasNext();) {
266: tmp[a] = (Integer) i.next();
267: a++;
268: }
269:
270: libraryTopicForm.setRightsView(tmp);
271:
272: // set amend rights to TOPIC in the form
273: rights = libraryRights.findRightsForTopic(securitySession,
274: id, RightConstants.ACCESS_AMEND);
275: tmp = new Integer[rights.size()];
276: a = 0;
277:
278: for (java.util.Iterator i = rights.iterator(); i.hasNext();) {
279: tmp[a] = (Integer) i.next();
280: a++;
281: }
282:
283: libraryTopicForm.setRightsAmend(tmp);
284:
285: // set delete rights to TOPIC in the form
286: rights = libraryRights.findRightsForTopic(securitySession,
287: id, RightConstants.ACCESS_REMOVE);
288: tmp = new Integer[rights.size()];
289: a = 0;
290:
291: for (java.util.Iterator i = rights.iterator(); i.hasNext();) {
292: tmp[a] = (Integer) i.next();
293: a++;
294: }
295:
296: libraryTopicForm.setRightsRemove(tmp);
297: libraryTopicForm.setTopicTab_activeTab(new Integer(0));
298: session.setAttribute("libraryTopicForm", libraryTopicForm);
299: session.removeAttribute("topicTab_activeTab");
300:
301: // Forward control to the topicModify.jsp - FORM for add new or modify existing TOPIC
302: return "libraryTopic";
303: } catch (NoSuchMethodException e) {
304: throw new SystemException(e);
305: } catch (InvocationTargetException e) {
306: throw new SystemException(e);
307: } catch (IllegalAccessException e) {
308: throw new SystemException(e);
309: }
310: }
311: }
|