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 org.apache.log4j.Logger;
17
18 /***
19 * @author Michael Rimov
20 * @version 1.0
21 */
22 public class DoChooseNodeStep implements StateHandler {
23
24 /***
25 * The name of this state as referred to by the Expresso Controller
26 */
27 public static final String STATE_NAME = "DoChooseNode";
28
29 /***
30 * The description of this state as referred to by the Expresso Controller.
31 */
32 public static final String STATE_DESCRIPTION = "Handle Choose Node";
33
34 /***
35 * Parent controller backreference.
36 */
37 private final Controller owner;
38
39 /***
40 * Delegating helper methods.
41 */
42 private final CompletionBeanManager beanManager;
43
44 /***
45 * Constructor that takes the owner controller as a paramter.
46 *
47 * @param parent Controller the owning controller.
48 */
49 public DoChooseNodeStep(Controller parent) {
50 owner = parent;
51 beanManager = new CompletionBeanManager();
52 }
53
54 /***
55 * Called to handle the request.
56 *
57 * @param request ControllerRequest The Function's ControllerRequest
58 * object.
59 * @param response ControllerResponse The Function's ControllerResponse
60 * object.
61 * @throws DBException upon underlying database exception error.
62 * @throws ControllerException upon underlying ControllerException error.
63 */
64 public void handleRequest(final ExpressoRequest request, final ExpressoResponse response) throws DBException,
65 ControllerException {
66
67 ErrorCollection ec = request.getErrorCollection();
68 if (ec == null) {
69 ec = new ErrorCollection();
70 }
71
72 CompletionBean bean = beanManager.createOrRetrieveActionForm(request);
73 String value = request.getParameter("targetId");
74 if (value != null && value.length() > 0) {
75 try {
76 bean.setTargetId(Integer.parseInt(value));
77 bean.setDynamicTarget(true);
78 } catch (NumberFormatException ex1) {
79 ec.addError("Field 'Target Id' must be a valid integer.");
80 }
81 }
82
83 value = request.getParameter("Title");
84 if (value != null && value.length() > 0) {
85 bean.setWizardTitle(value);
86 }
87
88 bean.setSummary(request.getParameter("Summary"));
89
90 String wizardClass = request.getParameter("WizardClass");
91 if (wizardClass == null || wizardClass.length() == 0) {
92 ec.addError("You need to specify a Wizard Class.");
93 } else {
94 try {
95 bean.setWizardClass(wizardClass);
96 } catch (ClassNotFoundException ex2) {
97 Logger.getLogger(DoChooseNodeStep.class).error("Error setting wizard class.", ex2);
98 ec.addError("The wizard class: " + wizardClass + " appears to be invalid. "
99 + "Contact your system administrator if this is in error. (The entire error has been logged)");
100 }
101 }
102
103 ec = beanManager.validate(request, ec);
104 if (ec.size() > 0) {
105 response.saveErrors(ec);
106 Transition prompt = new Transition(PromptChooseNode.STATE_NAME, owner);
107 prompt.executeTransition(request, response);
108 return;
109 }
110
111 Transition redirect = new Transition(PromptChooseParts.STATE_NAME, owner);
112 redirect.redirectTransition(request, response);
113 }
114 }