1
2
3
4
5
6
7
8
9
10 package com.sri.emo.wizard.completion.management;
11
12 import com.jcorporate.expresso.core.controller.*;
13 import com.jcorporate.expresso.core.db.DBException;
14 import com.sri.common.controller.StateHandler;
15 import com.sri.emo.wizard.completion.model.CompletionBean;
16 import com.sri.emo.wizard.completion.model.CompletionPartsBean;
17 import com.sri.emo.wizard.completion.model.FieldCompletion;
18
19 import java.util.Iterator;
20
21 /***
22 * @author Michael Rimov
23 */
24 public class DoChooseParts implements StateHandler {
25
26 /***
27 * The name of this state as referred to by the Expresso Controller
28 */
29 public static final String STATE_NAME = "doChooseParts";
30
31 /***
32 * The description of this state as referred to by the Expresso Controller.
33 */
34 public static final String STATE_DESCRIPTION = "Process Parts Choices";
35
36 /***
37 * Parent controller backreference.
38 */
39 private final Controller owner;
40
41 /***
42 * Delegating helper methods.
43 */
44 private final CompletionBeanManager beanManager;
45
46 public DoChooseParts(final Controller stateOwner) {
47 this.owner = stateOwner;
48 beanManager = new CompletionBeanManager();
49 }
50
51
52 /***
53 * Called to handle the request.
54 *
55 * @param request ControllerRequest The Function's ControllerRequest
56 * object.
57 * @param response ControllerResponse The Function's ControllerResponse
58 * object.
59 * @throws DBException upon underlying database exception error.
60 * @throws ControllerException upon underlying ControllerException error.
61 */
62 public void handleRequest(final ExpressoRequest request, final ExpressoResponse response) throws DBException,
63 ControllerException {
64
65 if (beanManager.handleSessionTimeout(request, response)) {
66 return;
67 }
68
69 ErrorCollection ec = request.getErrorCollection();
70 if (ec == null) {
71 ec = new ErrorCollection();
72 }
73
74 CompletionBean wizardBean = beanManager.getActionForm(request);
75 boolean foundAtLeastOneWizardSetting = false;
76 for (Iterator i = wizardBean.getCompletionParts().iterator(); i.hasNext();) {
77 final CompletionPartsBean onePart = (CompletionPartsBean) i.next();
78 String parameterValue = request.getParameter(onePart.getPart().getPartNum());
79 if (parameterValue == null || parameterValue.length() == 0) {
80 parameterValue = FieldCompletion.FIXED.toString();
81 }
82
83 if (parameterValue.equalsIgnoreCase(FieldCompletion.WIZARD.toString())) {
84 onePart.setFieldCompletion(FieldCompletion.WIZARD);
85 foundAtLeastOneWizardSetting = true;
86 } else if (parameterValue.equalsIgnoreCase(FieldCompletion.FIXED.toString())) {
87 onePart.setFieldCompletion(FieldCompletion.FIXED);
88 } else {
89 throw new ControllerException("Unknown radio position: " + parameterValue + " for part number: "
90 + onePart.getPart().getPartNum());
91 }
92 }
93
94 if (!foundAtLeastOneWizardSetting) {
95 ec.addError("Select at least one value that the wizard will complete, or cancel this wizard.");
96 }
97
98 ec = beanManager.validate(request, ec);
99 if (ec.size() > 0) {
100 response.saveErrors(ec);
101 Transition prompt = new Transition(PromptChooseParts.STATE_NAME, owner);
102 prompt.executeTransition(request, response);
103 return;
104 }
105
106 Transition redirect = new Transition(PromptChooseCriteria.STATE_NAME, owner);
107 redirect.redirectTransition(request, response);
108 }
109 }