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.AssemblyActions;
19  import org.figure8.join.businessobjects.artifact.Deliverable;
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 Assemblies into Join application.
31   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
32   * @version $Revision: 1.2 $
33   *
34   * @struts.form name="assemblyForm"
35   */
36  public class AssemblyForm extends JoinForm{
37  
38     // Attributes ---------------------------------------------------------------
39  
40     /** The assembly key */
41     private String key;
42     /** The assembly comments */
43     private String comments;
44     /** Assembly version info */
45     private String versionInfo;
46     /** The assembly creation date */
47     private Date creationDate;
48     /** The identifier of user that has composed assembly */
49     private String composerId;
50     /** The name of release this assembly is attached to */
51     private String releaseName;
52     /** The key of assembly status */
53     private String statusKey;
54  
55     /** String representation of <b>creationDate</b> */
56     private String creationDateStr;
57  
58     /**
59      * The map of deliverables that are used for assembly composition. Values
60      * are the deliverable unique business identifier, keys are their type key.
61      */
62     private Map deliverables = new HashMap();
63  
64  
65     // Constructors -------------------------------------------------------------
66  
67     /** Creates a new instance of AssemblyForm. */
68     public AssemblyForm(){
69     }
70  
71  
72     // Public -------------------------------------------------------------------
73  
74     /** @return This assembly unique key */
75     public String getKey(){
76        return key;
77     }
78     /** @param key This assembly unique key */
79     public void setKey(String key){
80        this.key = key;
81     }
82     /** @return The comments on assembly creation */
83     public String getComments(){
84        return comments;
85     }
86     /** @param comments The comments on assembly creation */
87     public void setComments(String comments){
88        this.comments = comments;
89     }
90     /** @return The information on this assembly version */
91     public String getVersionInfo(){
92        return versionInfo;
93     }
94     /** @param versionInfo the information on this assembly version */
95     public void setVersionInfo(String versionInfo){
96        this.versionInfo = versionInfo;
97     }
98     /** @return The identifier of user that has composed this assembly */
99     public String getComposerId(){
100       return composerId;
101    }
102    /** @param composerId The identifier of user that has composed this assembly */
103    public void setComposerId(String composerId){
104       this.composerId = composerId;
105    }
106    /** @return The creation date of this assembly */
107    public Date getCreationDate(){
108       return creationDate;
109    }
110    /** @param creationDate The creation date of this assembly */
111    public void setPublicationDate(Date creationDate){
112       this.creationDate = creationDate;
113       // Format to string according to locale.
114       SimpleDateFormat format = new SimpleDateFormat(getMessageResources().getMessage("pattern.date.stringtodate"));
115       this.creationDateStr = format.format(creationDate);
116    }
117    /** @return The name of the release this assembly is attached to */
118    public String getReleaseName(){
119       return releaseName;
120    }
121    /** @param releaseName The name of release this assembly is attached to */
122    public void setReleaseName(String releaseName){
123       this.releaseName = releaseName;
124    }
125    /** @return The key of assembly status */
126    public String getStatusKey(){
127       return statusKey;
128    }
129    /** @param statusKey The key of assembly status */
130    public void setStatusKey(String statusKey){
131       this.statusKey = statusKey;
132    }
133 
134    /** @return Creation date for this assembly (should be a date) */
135    public String getCreationDateStr(){
136       return creationDateStr;
137    }
138    /** @param creationDateStr Creation date for this assembly (should be a date) */
139    public void setCreationDateStr(String creationDateStr){
140       this.creationDateStr = creationDateStr;
141    }
142 
143    /** @return Map of deliverables composing assembly */
144    public Map getDeliverables(){
145       return deliverables;
146    }
147    /**
148     * @param key Key of deliverable type to get deliverable for
149     * @return The deliverable in assembly corresponding to specified type
150     */
151    public Object getMappedDeliverable(String key){
152       return deliverables.get(key);
153    }
154    /**
155     * @param key Key of the type of deliverable to add
156     * @param value The key of deliverable to add to assembly composition
157     */
158    public void setMappedDeliverable(String key, Object value){
159       if (key != null && key.length() > 0)
160          deliverables.put(key, value);
161    }
162 
163    /** @param deliverable Existing assembly deliverable to add to mapped one */
164    public void addDeliverable(Deliverable deliverable){
165       setMappedDeliverable(deliverable.getDeliverableType().getKey(), deliverable.getKey());
166    }
167 
168 
169    // Implementation of JoinForm -----------------------------------------------
170 
171    /**
172     * Validation of the form attributes.
173     * @param operation String representing the operation to invoke on Action
174     * @param mapping Mapping between forwards name and path for this action
175     * @param request The servlet container request wrapper
176     */
177    public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
178 
179       if (AssemblyActions.DETAILS_OP.equals(operation) || AssemblyActions.STATUS_OP.equals(operation)){
180          // Check and see if key is missing.
181          if (key == null || key.length() == 0)
182             addActionError("errors.required", getGuiMessageResources().getMessage("label.assembly.key"));
183       }
184       else if (AssemblyActions.CREATE_OP.equals(operation)){
185          // Check and see if comments are missing.
186          if (comments == null || comments.length() == 0)
187             addActionError("errors.required", getGuiMessageResources().getMessage("label.assembly.comments"));
188          // Check and see if version is missing.
189          if (versionInfo == null || versionInfo.length() == 0)
190             addActionError("errors.required", getGuiMessageResources().getMessage("label.assembly.version"));
191          // Check and see if releaseName is missing.
192          if (releaseName == null || releaseName.length() == 0)
193             addActionError("errors.required", getGuiMessageResources().getMessage("label.assembly.release"));
194       }
195       else if (AssemblyActions.SEARCH_OP.equals(operation)){
196          // Check and see if releaseName is missing.
197          if (releaseName == null || releaseName.length() == 0)
198             addActionError("errors.required", getGuiMessageResources().getMessage("label.assembly.release"));
199       }
200    }
201 
202 
203    // Override of ActionForm ---------------------------------------------------
204 
205    /**
206     * Reset form attributes.
207     * @param mapping Mapping between forwards name and path for this action
208     * @param request The servlet container request wrapper
209     */
210    public void reset(ActionMapping mapping, HttpServletRequest request){
211       super.reset(mapping, request);
212       key = null;
213       comments = null;
214       versionInfo = null;
215       creationDate = null;
216       composerId = null;
217       releaseName = null;
218       statusKey = null;
219       creationDateStr = null;
220       deliverables = new HashMap();
221    }
222 }