View Javadoc

1   package com.sri.emo.controller;
2   
3   import com.jcorporate.expresso.core.controller.ControllerException;
4   import com.jcorporate.expresso.core.controller.ExpressoRequest;
5   import com.jcorporate.expresso.core.controller.ExpressoResponse;
6   import com.jcorporate.expresso.core.controller.Transition;
7   import com.jcorporate.expresso.core.db.DBException;
8   import com.sri.emo.dbobj.Node;
9   import com.sri.emo.wizard.Wizard;
10  import com.sri.emo.wizard.WizardException;
11  import com.sri.emo.wizard.WizardMementoConverter;
12  import com.sri.emo.wizard.WizardPage;
13  import com.sri.emo.wizard.completion.CustomPartHandlerPage;
14  import com.sri.emo.wizard.completion.EmoCompletionWizard;
15  import com.sri.emo.wizard.completion.RelationWizardPage;
16  import com.sri.emo.wizard.expressoimpl.WizardController;
17  import com.sri.emo.wizard.wizardgateway.ListWizards;
18  import com.sri.emo.wizard.wizardgateway.WizardGatewayController;
19  import org.apache.log4j.Logger;
20  
21  import java.io.Serializable;
22  
23  /***
24   * Controller that runs the completion controller.
25   *
26   * @author Michael Rimov
27   * @version 1.0
28   */
29  public class CompletionWizardAction extends WizardController {
30  
31  
32      /***
33  	 * 
34  	 */
35  	private static final long serialVersionUID = 1L;
36  	public static final String PARAM_TARGET_ID = "targetId";
37  
38      /***
39       * Default constructor -- no added state.s
40       */
41      public CompletionWizardAction() {
42          super();
43      }
44  
45      /***
46       * Override to provide backlink to list wizards page in EMO.
47       *
48       * @return Transition.
49       */
50      protected Transition getCancelTransition() {
51          return new Transition("cancel", "cancel", WizardGatewayController.class, ListWizards.STATE_NAME);
52      }
53  
54      /***
55       * Override of WizardController to provide for the unique capabilities
56       * and requirements of an ExpressoAwareWizardRepository as defined in
57       * the Schema.
58       *
59       * @param request The <code>ExpressoRequest</code>Object
60       * @return Wizard instance
61       * @throws com.sri.emo.wizard.WizardException
62       *          upon
63       *          wizard related construction error
64       * @throws com.jcorporate.expresso.core.controller.ControllerException
65       *          upon
66       *          parameter retrieval error.
67       */
68      protected Wizard newWizard(final ExpressoRequest request) throws WizardException, ControllerException {
69          EmoCompletionWizard theNewWizard = (EmoCompletionWizard) super.newWizard(request);
70          if (request.getParameter(PARAM_TARGET_ID) != null && request.getParameter(PARAM_TARGET_ID).length() > 0) {
71              theNewWizard.setTargetNodeId(request.getParameter(PARAM_TARGET_ID));
72          }
73  
74          return theNewWizard;
75      }
76  
77  
78      /***
79       * <tt>Template Method</tt>.  Retrieves/Constructs the WizardMementoConverter
80       * appropriate for the current run.
81       *
82       * @return WizardMementoConverter or null if none is defined.
83       */
84      protected WizardMementoConverter getMementoConverter() {
85          return (WizardMementoConverter) this.locate("CompletionMementoConverter");
86      }
87  
88      /***
89       * For relation pages, this version extracts the entire request paramter
90       * map because the relation wizard needs all that nasty hard-to-read checkbox
91       * data.  Otherwise, we hand it up to the default behavior.
92       *
93       * @param request ExpressoRequest
94       * @return Serializable may be null if the data is not found or
95       *         incomplete.
96       */
97      protected Serializable extractPostedWizardData(ExpressoRequest request) {
98          try {
99              WizardPage currentPage = this.getCurrentPage(request, this.getCurrentWizard(request));
100             assert currentPage != null;
101 
102             if (currentPage instanceof RelationWizardPage) {
103                 return (Serializable) request.getAllParameters();
104             } else if (currentPage instanceof CustomPartHandlerPage) {
105                 return (Serializable) request.getAllParameters();
106             } else {
107                 return super.extractPostedWizardData(request);
108             }
109         } catch (ControllerException ex) {
110             Logger.getLogger(CompletionWizardAction.class).error(
111                     "Error extracting wizard and page from requested session.", ex);
112             throw new IllegalStateException(
113                     "Error extracting wizard and page from requested session. (Details have been logged) Message: " + ex.getMessage());
114         }
115 
116     }
117 
118     /***
119      * Template method.
120      *
121      * @param request  ExpressoRequest Expresso Request object
122      * @param response ExpressoResponse ExpressoResponse object
123      * @throws ControllerException upon errors.
124      * @todo Implement this com.sri.emo.wizard.expressoimpl.WizardController
125      * method
126      */
127     protected void afterFinishState(ExpressoRequest request, ExpressoResponse response) throws ControllerException {
128         try {
129             Node finalNode = (Node) request.getSession().getAttribute(WIZ_RESULT_ID);
130             Transition editTransition = new Transition();
131             editTransition.setControllerObject(AddNodeAction.class);
132             editTransition.setState(AddNodeAction.VIEW_NODE);
133             editTransition.addParam(Node.NODE_ID, finalNode.getNodeId());
134             editTransition.redirectTransition(request, response);
135         } catch (DBException ex) {
136             throw new ControllerException(ex);
137         }
138 
139     }
140 
141 
142 }