1 /**
2 * Copyright 2005-2006 the original author or authors.
3 *
4 * Licensed under the Gnu General Pubic License, Version 2.0 (the
5 * "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/gpl-license.php
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the Gnu General Public License for more details.
14 */
15 package org.figure8.join.control.action;
16
17 import org.figure8.join.control.JoinAction;
18 import org.figure8.join.control.form.DeliverableTypeForm;
19 import org.figure8.join.businessobjects.artifact.DeliverableType;
20 import org.figure8.join.businessfacades.artifact.ArtifactManager;
21 import org.figure8.join.util.LogUtil;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.beanutils.PropertyUtils;
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionForward;
27 import org.apache.struts.action.ActionMapping;
28
29 import javax.servlet.http.HttpSession;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 /**
33 * Struts action used for managing Deliverable categories (types) within Join application
34 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
35 * @version $Revision: 1.1 $
36 *
37 * @struts.action path="/deliverableType" name="deliverableTypeForm"
38 * scope="request" parameter="op" validate="true"
39 * input="/pages/mainpage.jsp?body=/jsp/deliverabletypes.jsp"
40 * @struts.action-forward name="DeliverableTypes" path="/jsp/deliverabletypes.jsp"
41 */
42 public class DeliverableTypeActions extends JoinAction{
43
44
45
46 /** Get a commons logger. */
47 private static final Log log = LogUtil.getLog(DeliverableTypeActions.class);
48
49 /** Operation code for loading a specific DeliverableType */
50 public static final String LOAD_OP = "load";
51 /** Operation code for saving a DeliverableType (create or update) */
52 public static final String SAVE_OP = "save";
53
54 /**
55 * The session scope attribute under which the DeliverableType object currently
56 * selected by our logged-in User is stored.
57 */
58 public static final String DELIVERABLE_TYPE_KEY = "deliverableType";
59
60
61
62
63 /** Join artifact manager instance. */
64 protected ArtifactManager artifactManager;
65
66
67
68
69 /** Creates a new instance of DeliverableTypeActions. */
70 public DeliverableTypeActions(){
71 }
72
73
74
75
76 /** @param manager <code>ArtifactManager</code> implementation instance */
77 public void setArtifactManager(ArtifactManager manager){
78 this.artifactManager = manager;
79 }
80
81
82
83
84 /**
85 *
86 * @param operation String representing the operation to invoke on Action
87 * @param mapping Mapping between forwards name and path for this action
88 * @param form The form object containing request parameters
89 * @param request The servlet container request wrapper
90 * @param response The servlet container response wrapper
91 * @return A forward to the next view to render and display
92 */
93 public ActionForward doExecute(String operation, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{
94
95 log.debug("doExecute() called for '" + operation + "' operation");
96
97 if (LOAD_OP.equals(operation)){
98 return loadDeliverableType(mapping, form, request, response);
99 }
100 else if (SAVE_OP.equals(operation)){
101 return saveDeliverableType(mapping, form, request, response);
102 }
103 else{
104
105 request.getSession().removeAttribute(DELIVERABLE_TYPE_KEY);
106 return mapping.findForward("DeliverableTypes");
107 }
108 }
109
110
111
112
113 /**
114 * Load a specified deliverable type from datastore and fill form with it.
115 * @return A forward to the next view to render and display
116 */
117 protected ActionForward loadDeliverableType(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
118 throws Exception{
119
120 if (form instanceof DeliverableTypeForm){
121
122 DeliverableTypeForm tForm = (DeliverableTypeForm)form;
123 DeliverableType type = artifactManager.getDeliverableType(tForm.getKey());
124
125
126 HttpSession session = request.getSession();
127 session.setAttribute(DELIVERABLE_TYPE_KEY, type);
128
129 PropertyUtils.copyProperties(tForm, type);
130
131
132 return mapping.findForward("DeliverableTypes");
133 }
134
135 return null;
136 }
137
138 /**
139 * Save a deliverable type into datastore. The type may be an already existing one or a
140 * new one (this is indeed a create or update method).
141 * @return A forward to the next view to render and display
142 */
143 protected ActionForward saveDeliverableType(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
144 throws Exception{
145
146 if (form instanceof DeliverableTypeForm){
147
148 DeliverableTypeForm tForm = (DeliverableTypeForm)form;
149
150
151 HttpSession session = request.getSession();
152 DeliverableType type = (DeliverableType)session.getAttribute(DELIVERABLE_TYPE_KEY);
153
154
155 if (type == null){
156 log.info("Creation of a new DeliverableType with key: " + tForm.getKey());
157 type = new DeliverableType(tForm.getKey(), tForm.getLabel(),
158 tForm.getKeyTemplate(), tForm.isVersionable(), tForm.isMandatory());
159
160 if (tForm.isVcsDeliverable()){
161 type.setVcsDeliverable(true);
162 type.setVcsUser(tForm.getVcsUser());
163 type.setVcsPassword(tForm.getVcsPassword());
164 type.setVcsRoot(tForm.getVcsRoot());
165 type.setVcsModule(tForm.getVcsModule());
166 type.setVcsAccessorClass(tForm.getVcsAccessorClass());
167 }
168 }
169 else{
170 log.info("Update of existing DeliverableType having key: " + type.getKey());
171 PropertyUtils.copyProperties(type, tForm);
172 }
173
174 artifactManager.saveDeliverableType(type);
175
176
177 session.removeAttribute(DELIVERABLE_TYPE_KEY);
178 removeObsoleteForm(mapping, request);
179
180
181 return mapping.findForward("DeliverableTypes");
182 }
183
184 return null;
185 }
186 }