View Javadoc

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.DeploymentActions;
19  
20  import org.apache.struts.action.ActionMapping;
21  
22  import javax.servlet.http.HttpServletRequest;
23  
24  import java.util.Date;
25  import java.util.Calendar;
26  import java.text.SimpleDateFormat;
27  /**
28   * Form object used for manipulating Deployments into Join application.
29   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
30   * @version $Revision: 1.2 $
31   *
32   * @struts.form name="deploymentForm"
33   */
34  public class DeploymentForm extends JoinForm{
35  
36     // Attributes ---------------------------------------------------------------
37  
38     /** Identifier of user who asked for deployment */
39     private String applicantId;
40     /** Comments on deployment demand made by applicants */
41     private String applicantComments;
42     /** Identifier of user assigned to deployment relaization */
43     private String assigneeId;
44     /** Comments on deployment relalization made by assignee */
45     private String assigneeComments;
46     /** The deployment demand creation date */
47     private Date creationDate;
48     /** The deployment demand assignation date */
49     private Date assignationDate;
50     /** The deployment realization date */
51     private Date realizationDate;
52     /** The date applicant wished the deployment's done */
53     private Date wishedDate;
54  
55     /** The key of assembly to deploy */
56     private String assemblyKey;
57     /** The key of logical environment to deploy on */
58     private String logicalEnvKey;
59     /** The identifier of deployment target */
60     private String targetName;
61     /** The key of deployment status */
62     private String statusKey;
63  
64     /** String representation of <code>creationDate</code> */
65     private String creationDateStr;
66     /** String represantation of <code>assignationDate</code> */
67     private String assignationDateStr;
68     /** String representation of <code>realizationDate</code> */
69     private String realizationDateStr;
70     /** String representation of <code>wishedDate</code> */
71     private String wishedDateStr;
72     /** String representation of <code>wishedHour</code> */
73     private String wishedHourStr = "12";
74     /** String representation of <code>wishedMin</code> */
75     private String wishedMinStr = "00";
76  
77  
78     // Constructors -------------------------------------------------------------
79  
80     /** Creates a new DeploymentForm instance */
81     public DeploymentForm(){
82     }
83  
84  
85     // Public -------------------------------------------------------------------
86  
87     /** @return The identifier of user who asked for deployment */
88     public String getApplicantId(){
89        return applicantId;
90     }
91     /** @param applicantId The identifier of user who asked for deployment */
92     public void setApplicantId(String applicantId){
93        this.applicantId = applicantId;
94     }
95     /** @return The comments made by applicant on deployment demand */
96     public String getApplicantComments(){
97        return applicantComments;
98     }
99     /** @param comments The comments made by applicant on deployment demand */
100    public void setApplicantComments(String comments){
101       this.applicantComments = comments;
102    }
103    /** @return The identifier of user assigned to deployment realization */
104    public String getAssigneeId(){
105       return assigneeId;
106    }
107    /** @param assigneeId The identifier of user assigned to deployment realization */
108    public void setAssigneeId(String assigneeId){
109       this.assigneeId = assigneeId;
110    }
111    /** @return The comments on deployment from assignee */
112    public String getAssigneeComments(){
113       return assigneeComments;
114    }
115    /** @param comments The comments on deployment from assignee */
116    public void setAssigneeComments(String comments){
117       this.assigneeComments = comments;
118    }
119 
120    /** @return The creation date of the deployment demand */
121    public Date getCreationDate(){
122       return creationDate;
123    }
124    /** @param creationDate The creation date of the deployment demand */
125    public void setCreationDate(Date creationDate){
126       this.creationDate = creationDate;
127       // Format to string according to locale.
128       SimpleDateFormat format = new SimpleDateFormat(getMessageResources().getMessage("pattern.date.stringtodate"));
129       this.creationDateStr = format.format(creationDate);
130    }
131    /** @return The deployment demand assignation date */
132    public Date getAssignationDate(){
133       return assignationDate;
134    }
135    /** @param assignationDate The date deployment realization is assigned to an integrator */
136    public void setAssignationDate(Date assignationDate){
137       this.assignationDate = assignationDate;
138       // Format to string according to locale.
139       SimpleDateFormat format = new SimpleDateFormat(getMessageResources().getMessage("pattern.date.stringtodate"));
140       this.assignationDateStr = format.format(assignationDate);
141    }
142    /** @return The deployment realization date */
143    public Date getRealizationDate(){
144       return realizationDate;
145    }
146    /** @param realizationDate The deployment realization timestamp */
147    public void setRealizationDate(Date realizationDate){
148       this.realizationDate = realizationDate;
149       // Format to string according to locale.
150       SimpleDateFormat format = new SimpleDateFormat(getMessageResources().getMessage("pattern.date.stringtodate"));
151       this.realizationDateStr = format.format(realizationDate);
152    }
153    /** @return The date applicant wished the deployment's done */
154    public Date getWishedDate(){
155       return wishedDate;
156    }
157    /** @param wishedDate The date application wished the deployment's done */
158    public void setWishedDate(Date wishedDate){
159       this.wishedDate = wishedDate;
160       // Format to string according to locale.
161       SimpleDateFormat format = new SimpleDateFormat(getMessageResources().getMessage("pattern.date.stringtodate"));
162       this.wishedDateStr = format.format(wishedDate);
163    }
164 
165    /** @return The key of assembly to deploy */
166    public String getAssemblyKey(){
167       return assemblyKey;
168    }
169    /** @param assemblyKey The key of assembly to deploy */
170    public void setAssemblyKey(String assemblyKey){
171       this.assemblyKey = assemblyKey;
172    }
173    /** @return The key of logical environment to deploy on */
174    public String getLogicalEnvKey(){
175       return logicalEnvKey;
176    }
177    /** @param logicalEnvKey The key of logical environment to deploy on */
178    public void setLogicalEnvKey(String logicalEnvKey){
179       this.logicalEnvKey = logicalEnvKey;
180    }
181    /** @return The identifier of deployment target */
182    public String getTargetName(){
183       return targetName;
184    }
185    /** @param targetName The identifier of deployment target */
186    public void setTargetName(String targetName){
187       this.targetName = targetName;
188    }
189    /** @return The key of deployment status */
190    public String getStatusKey(){
191       return statusKey;
192    }
193    /** @param statusKey The key of deployment status */
194    public void setStatusKey(String statusKey){
195       this.statusKey = statusKey;
196    }
197 
198    /** @return Date of creation (must be a date) */
199    public String getCreationDateStr(){
200       return creationDateStr;
201    }
202    /** @param creationDateStr Date of creation (must be a date) */
203    public void setCreationDateStr(String creationDateStr){
204       this.creationDateStr = creationDateStr;
205    }
206    /** @return Date of assignation (must be a date) */
207    public String getAssignationDateStr(){
208       return assignationDateStr;
209    }
210    /** @param assignationDateStr Date of assignation (must be a date) */
211    public void setAssignationDateStr(String assignationDateStr){
212       this.assignationDateStr = assignationDateStr;
213    }
214    /** @return realizationDateStr Date of realisation (must be a date) */
215    public String getRealizationDateStr(){
216       return realizationDateStr;
217    }
218    /** @param realizationDateStr Date of realisation (must be a date) */
219    public void setRealizationDateStr(String realizationDateStr){
220       this.realizationDateStr = realizationDateStr;
221    }
222    /** @return Date of wished deployment (must be a date) */
223    public String getWishedDateStr(){
224       return wishedDateStr;
225    }
226    /** @param wishedDateStr Date of wished deployment (must be a date) */
227    public void setWishedDateStr(String wishedDateStr){
228       this.wishedDateStr = wishedDateStr;
229    }
230 
231    /** @return String representation of wished hour */
232    public String getWishedHourStr(){
233       return wishedHourStr;
234    }
235    /** @param wishedHourStr String representation of wished hour */
236    public void setWishedHourStr(String wishedHourStr){
237       this.wishedHourStr = wishedHourStr;
238    }
239    /** @return String representation of wished minutes */
240    public String getWishedMinStr(){
241       return wishedMinStr;
242    }
243    /** @param wishedMinStr String representation of wished minutes */
244    public void setWishedMinStr(String wishedMinStr){
245       this.wishedMinStr = wishedMinStr;
246    }
247 
248 
249    // Implementation of JoinForm -----------------------------------------------
250 
251    /**
252     * Validate form attributes.
253     * @param operation String representing the operation to invoke on Action
254     * @param mapping Mapping between forwards name and path for this action
255     * @param request The servlet container request wrapper
256     */
257    public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
258 
259       if (DeploymentActions.LOAD_OP.equals(operation) || DeploymentActions.PREPARE_OP.equals(operation)
260             || DeploymentActions.REALIZE_OP.equals(operation) || DeploymentActions.END_OP.equals(operation)
261                || DeploymentActions.CANCEL_OP.equals(operation) || DeploymentActions.STATUS_OP.equals(operation)){
262          // Check if deployment id is missing.
263          validateEntityObjectId();
264       }
265       else if (DeploymentActions.CREATE_OP.equals(operation)){
266          // Check if assembly key is missing.
267          if (assemblyKey == null || assemblyKey.length() == 0)
268             addActionError("errors.required", getGuiMessageResources().getMessage("label.deployment.assembly"));
269          // Check if logical environment key is missing.
270          if (logicalEnvKey == null || logicalEnvKey.length() == 0)
271             addActionError("errors.required", getGuiMessageResources().getMessage("label.deployment.environment"));
272          // Check if deployment target name is missing.
273          if (targetName == null || targetName.length() == 0)
274             addActionError("errors.required", getGuiMessageResources().getMessage("label.deployment.target"));
275          // Check if applicant comments are missing.
276          if (applicantComments == null || applicantComments.length() == 0)
277             addActionError("errors.required", getGuiMessageResources().getMessage("label.deployment.applicantcomments"));
278          // Check if wished date is missing.
279          if (wishedDateStr == null || wishedDateStr.length() == 0)
280             addActionError("errors.required", getGuiMessageResources().getMessage("label.deployment.wisheddate"));
281          else{
282             // Check if it's parsable.
283             SimpleDateFormat format = new SimpleDateFormat(getMessageResources().getMessage("pattern.date.stringtodate"));
284             try {wishedDate = format.parse(wishedDateStr);}
285             catch (Exception e){
286                addActionError("errors.format", getGuiMessageResources().getMessage("label.deployment.wisheddate"));
287             }
288 
289             if (wishedDate != null){
290                Calendar wishedCal = Calendar.getInstance();
291                wishedCal.setTime(wishedDate);
292                // Check if hour is missing.
293                if (wishedHourStr == null || wishedHourStr.length() == 0)
294                   addActionError("errors.required", getGuiMessageResources().getMessage("label.deployment.wihedhour"));
295                else{
296                   // Check if it's parsable.
297                   try {wishedCal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(wishedHourStr));}
298                   catch (Exception e){
299                      addActionError("errors.range",
300                              getGuiMessageResources().getMessage("label.deployment.wisheddate.hour", "0", "23"));
301                   }
302                }
303                // Check if minute is missing.
304                if (wishedMinStr == null || wishedMinStr.length() == 0)
305                   addActionError("errors.required", getGuiMessageResources().getMessage("label.deployment.wishedmin"));
306                else{
307                   // Check if it's parsable.
308                   try {wishedCal.set(Calendar.MINUTE, Integer.parseInt(wishedMinStr));}
309                   catch (Exception e){
310                      addActionError("errors.range",
311                              getGuiMessageResources().getMessage("label.deployment.wisheddate.minute", "0", "59"));
312                   }
313                }
314             }
315          }
316       }
317    }
318 
319 
320    // Override of ActionForm ---------------------------------------------------
321 
322    /**
323     * Reset form attributes.
324     * @param mapping Mapping between forwards name and path for this action
325     * @param request The servlet container request wrapper
326     */
327    public void reset(ActionMapping mapping, HttpServletRequest request){
328       super.reset(mapping, request);
329       this.applicantId = null;
330       this.applicantComments = null;
331       this.assigneeId = null;
332       this.assigneeComments = null;
333       this.wishedDate = null;
334       this.assemblyKey = null;
335       this.logicalEnvKey = null;
336       this.targetName = null;
337       this.statusKey = null;
338       this.wishedDateStr = null;
339       this.wishedHourStr = "12";
340       this.wishedMinStr = "00";
341    }
342 }