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.form;
16
17 import org.figure8.join.control.JoinForm;
18 import org.figure8.join.control.action.BuildActions;
19 import org.figure8.join.businessobjects.artifact.Component;
20
21 import org.apache.struts.action.ActionMapping;
22
23 import javax.servlet.http.HttpServletRequest;
24
25 import java.util.Map;
26 import java.util.Date;
27 import java.util.HashMap;
28 import java.text.SimpleDateFormat;
29 /**
30 * Form object used for manipulating Builds into Join application.
31 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
32 * @version $Revision: 1.1 $
33 *
34 * @struts.form name="buildForm"
35 */
36 public class BuildForm extends JoinForm{
37
38
39
40 /** The build key */
41 private String key;
42 /** The build comments */
43 private String comments;
44 /** Build version info */
45 private String versionInfo;
46 /** The build creation date */
47 private Date creationDate;
48 /** The identifier of user that has composed build */
49 private String composerId;
50 /** The name of release this build is attached to */
51 private String releaseName;
52
53 /** String representation of <b>creationDate</b> */
54 private String creationDateStr;
55
56 /**
57 * The map of components that are used for build composition. Values
58 * are the components unique business identifier, keys are their type key.
59 */
60 private Map components = new HashMap();
61 /**
62 * The map of components that shoud be extracted from assembly for
63 * build composition. Values are the assemblies unique business identifier, keys are
64 * the key of type of component to extract from this assembly.
65 */
66 private Map extractedComponents = new HashMap();
67
68
69
70
71 /** Creates a new instance of BuildForm */
72 public BuildForm(){
73 }
74
75
76
77
78 /** @return This build unique key */
79 public String getKey(){
80 return key;
81 }
82 /** @param key This build unique key */
83 public void setKey(String key){
84 this.key = key;
85 }
86 /** @return The comments on build creation */
87 public String getComments(){
88 return comments;
89 }
90 /** @param comments The comments on build creation */
91 public void setComments(String comments){
92 this.comments = comments;
93 }
94 /** @return The information on this build version */
95 public String getVersionInfo(){
96 return versionInfo;
97 }
98 /** @param versionInfo the information on this build version */
99 public void setVersionInfo(String versionInfo){
100 this.versionInfo = versionInfo;
101 }
102 /** @return The identifier of user that has composed this build */
103 public String getComposerId(){
104 return composerId;
105 }
106 /** @param composerId The identifier of user that has composed this build */
107 public void setComposerId(String composerId){
108 this.composerId = composerId;
109 }
110 /** @return The creation date of this build */
111 public Date getCreationDate(){
112 return creationDate;
113 }
114 /** @param creationDate The creation date of this build */
115 public void setPublicationDate(Date creationDate){
116 this.creationDate = creationDate;
117
118 SimpleDateFormat format = new SimpleDateFormat(getMessageResources().getMessage("pattern.date.stringtodate"));
119 this.creationDateStr = format.format(creationDate);
120 }
121 /** @return The name of the release this build is attached to */
122 public String getReleaseName(){
123 return releaseName;
124 }
125 /** @param releaseName The name of release this build is attached to */
126 public void setReleaseName(String releaseName){
127 this.releaseName = releaseName;
128 }
129
130 /** @return Creation date for this build (should be a date) */
131 public String getCreationDateStr(){
132 return creationDateStr;
133 }
134 /** @param creationDateStr Creation date for this build (should be a date) */
135 public void setCreationDateStr(String creationDateStr){
136 this.creationDateStr = creationDateStr;
137 }
138
139 /** @return Map of components composing build */
140 public Map getComponents(){
141 return components;
142 }
143 /**
144 * @param key Key of component type to get component for
145 * @return The component in build corresponding to specified type
146 */
147 public Object getMappedComponent(String key){
148 return components.get(key);
149 }
150 /**
151 * @param key Key of the type of component to add
152 * @param value The key of component to add to build composition
153 */
154 public void setMappedComponent(String key, Object value){
155 if (key != null && key.length() > 0)
156 components.put(key, value);
157 }
158
159 /** @param component Existing build component to add to mapped one */
160 public void addComponent(Component component){
161 setMappedComponent(component.getComponentType().getKey(), component.getKey());
162 }
163
164 /** @return Map of components composing build that shoule be extracted from assemblies */
165 public Map getExtractedComponents(){
166 return extractedComponents;
167 }
168 /**
169 * @param key Key of component type to get extraction assembly for
170 * @return The assembly from whom component of this type has to be extracted
171 */
172 public Object getExtractedComponent(String key){
173 return extractedComponents.get(key);
174 }
175 /**
176 * @param key Key of the type of component to extract
177 * @param value The key of assembly to extract component from
178 */
179 public void setExtractedComponent(String key, Object value){
180 if (key != null && key.length() > 0)
181 extractedComponents.put(key, value);
182 }
183
184
185
186
187 /**
188 * Validate form attributes.
189 * @param operation String representing the operation to invoke on Action
190 * @param mapping Mapping between forwards name and path for this action
191 * @param request The servlet container request wrapper
192 */
193 public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
194
195 if (BuildActions.CREATE_OP.equals(operation)){
196
197 if (comments == null || comments.length() == 0)
198 addActionError("errors.required", getGuiMessageResources().getMessage("label.build.comments"));
199
200 if (versionInfo == null || versionInfo.length() == 0)
201 addActionError("errors.required", getGuiMessageResources().getMessage("label.build.version"));
202
203 if (releaseName == null || releaseName.length() == 0)
204 addActionError("errors.required", getGuiMessageResources().getMessage("label.build.release"));
205 }
206 else if (BuildActions.SEARCH_OP.equals(operation)){
207
208 if (releaseName == null || releaseName.length() == 0)
209 addActionError("errors.required", getGuiMessageResources().getMessage("label.build.release"));
210 }
211 }
212
213
214
215
216 /**
217 * Reset form attributes.
218 * @param mapping Mapping between forwards name and path for this action
219 * @param request The servlet container request wrapper
220 */
221 public void reset(ActionMapping mapping, HttpServletRequest request){
222 super.reset(mapping, request);
223 key = null;
224 comments = null;
225 versionInfo = null;
226 creationDate = null;
227 composerId = null;
228 releaseName = null;
229 creationDateStr = null;
230 components = new HashMap();
231 extractedComponents = new HashMap();
232 }
233 }