001: package com.technoetic.xplanner.forms;
002:
003: import javax.servlet.http.HttpServletRequest;
004:
005: import org.apache.struts.action.ActionErrors;
006: import org.apache.struts.action.ActionMapping;
007:
008: import com.technoetic.xplanner.XPlannerProperties;
009:
010: public class UserStoryEditorForm extends AbstractEditorForm {
011: private String name;
012: private String description;
013: private int trackerId;
014: private int iterationId;
015: private int targetIterationId;
016: private double estimatedHours;
017: private double taskBasedEstimatedHours;
018: private int priority;
019: private int orderNo;
020: private String dispositionName;
021: private String statusName;
022: private int customerId;
023: /*package*/
024: static final int DEFAULT_PRIORITY = 4;
025: static final String DEFAULT_PRIORITY_KEY = "xplanner.story.defaultpriority";
026: static final String INVALID_PRIORITY_ERROR_KEY = "story.editor.invalid_priority";
027: static final String NEGATIVE_ESTIMATED_HOURS_ERROR_KEY = "story.editor.negative_estimated_hours";
028: static final String MISSING_NAME_ERROR_KEY = "story.editor.missing_name";
029: static final String SAME_ITERATION_ERROR_KEY = "story.editor.same_iteration";
030: static final String PRIORITY_PARAM = "priority";
031:
032: public String getContainerId() {
033: return Integer.toString(getIterationId());
034: }
035:
036: public ActionErrors validate(ActionMapping mapping,
037: HttpServletRequest request) {
038: ActionErrors errors = new ActionErrors();
039: if (isSubmitted()) {
040: if (!isMerge()) {
041: require(errors, name, MISSING_NAME_ERROR_KEY);
042: require(errors, estimatedHours >= 0,
043: NEGATIVE_ESTIMATED_HOURS_ERROR_KEY);
044: validateIsNumber(errors, request, PRIORITY_PARAM,
045: INVALID_PRIORITY_ERROR_KEY);
046: } else {
047: require(errors, targetIterationId != iterationId,
048: SAME_ITERATION_ERROR_KEY);
049: }
050:
051: }
052: return errors;
053: }
054:
055: private void validateIsNumber(ActionErrors errors,
056: HttpServletRequest request, String param, String errorKey) {
057: String priority = request.getParameter(param);
058: if (priority == null)
059: return;
060: try {
061: Integer.parseInt(priority);
062: } catch (NumberFormatException e) {
063: error(errors, errorKey);
064: }
065: }
066:
067: public void reset(ActionMapping mapping, HttpServletRequest request) {
068: XPlannerProperties props = new XPlannerProperties();
069: reset(mapping, request, props);
070: }
071:
072: public void reset(ActionMapping mapping,
073: HttpServletRequest request, XPlannerProperties props) {
074: super .reset(mapping, request);
075: name = null;
076: description = null;
077: trackerId = 0;
078: iterationId = 0;
079: estimatedHours = 0;
080: taskBasedEstimatedHours = 0;
081: targetIterationId = 0;
082: customerId = 0;
083: orderNo = 0;
084: resetPriority(props);
085: }
086:
087: public void resetPriority(XPlannerProperties props) {
088: if (props.getProperty(DEFAULT_PRIORITY_KEY) != null) {
089: priority = Integer.parseInt(props
090: .getProperty(DEFAULT_PRIORITY_KEY));
091: } else {
092: priority = DEFAULT_PRIORITY;
093: }
094: }
095:
096: public String getName() {
097: return name;
098: }
099:
100: public void setName(String name) {
101: this .name = name;
102: }
103:
104: public void setDescription(String description) {
105: this .description = description;
106: }
107:
108: public String getDescription() {
109: return description;
110: }
111:
112: public void setIterationId(int iterationId) {
113: if (targetIterationId == 0) {
114: targetIterationId = iterationId;
115: }
116: this .iterationId = iterationId;
117: }
118:
119: public int getIterationId() {
120: return iterationId;
121: }
122:
123: public void setTrackerId(int trackerId) {
124: this .trackerId = trackerId;
125: }
126:
127: public int getTrackerId() {
128: return trackerId;
129: }
130:
131: public void setEstimatedHours(double estimatedHours) {
132: this .estimatedHours = estimatedHours;
133: }
134:
135: public double getEstimatedHours() {
136: return estimatedHours;
137: }
138:
139: public void setPriority(int priority) {
140: this .priority = priority;
141: }
142:
143: public int getPriority() {
144: return priority;
145: }
146:
147: public String getDispositionName() {
148: return dispositionName;
149: }
150:
151: public void setDispositionName(String dispositionName) {
152: this .dispositionName = dispositionName;
153: }
154:
155: public String getStatusName() {
156: return statusName;
157: }
158:
159: public void setStatusName(String statusName) {
160: this .statusName = statusName;
161: }
162:
163: public void setCustomerId(int customerId) {
164: this .customerId = customerId;
165: }
166:
167: public int getCustomerId() {
168: return customerId;
169: }
170:
171: public double getTaskBasedEstimatedHours() {
172: return taskBasedEstimatedHours;
173: }
174:
175: public void setTaskBasedEstimatedHours(double hours) {
176: taskBasedEstimatedHours = hours;
177: }
178:
179: public int getTargetIterationId() {
180: return targetIterationId;
181: }
182:
183: public void setTargetIterationId(int targetIterationId) {
184: this .targetIterationId = targetIterationId;
185: }
186:
187: public int getOrderNo() {
188: return orderNo;
189: }
190:
191: public void setOrderNo(int orderNo) {
192: this.orderNo = orderNo;
193: }
194: }
|