1
2
3
4
5
6
7
8
9
10 package com.sri.emo.wizard.creation.management;
11
12 import com.jcorporate.expresso.core.controller.Controller;
13 import com.jcorporate.expresso.core.controller.ControllerException;
14 import com.jcorporate.expresso.core.controller.ExpressoRequest;
15 import com.jcorporate.expresso.core.controller.ExpressoResponse;
16 import com.jcorporate.expresso.core.controller.Transition;
17 import com.jcorporate.expresso.core.db.DBException;
18 import com.sri.common.controller.StateHandler;
19 import com.sri.common.dbobj.ObjectNotFoundException;
20 import com.sri.emo.wizard.creation.CreationRepository;
21 import com.sri.emo.wizard.creation.model.CreationBean;
22 import com.sri.emo.wizard.expressoimpl.WizardController;
23 import com.sri.emo.wizard.creation.model.*;
24
25
26 /***
27 * @author Michael Rimov
28 */
29 public class PromptEditWizard implements StateHandler {
30
31 /***
32 * The name of this state as referred to by the Expresso Controller
33 */
34 public static final String STATE_NAME = "promptEditWizard";
35
36 /***
37 * The description of this state as referred to by the Expresso Controller.
38 */
39 public static final String STATE_DESCRIPTION = "Edit Completion Wizard";
40
41 /***
42 * Parent controller backreference.
43 */
44 private final Controller parent;
45
46 /***
47 * The completion session manager.
48 */
49 private final ICreationBeanManager beanManager;
50
51
52 /***
53 * Interface to the internal repository.
54 */
55 private final CreationRepository completionRepository;
56
57
58 /***
59 * Constructor. Assembles the parent controller, the completion repository
60 * and the state bean manager.
61 *
62 * @param stateOwner Controller
63 * @param repository CompletionRepository
64 * @param stateBeanManager ICompletionBeanManager
65 */
66 public PromptEditWizard(final Controller stateOwner, final CreationRepository repository,
67 final ICreationBeanManager stateBeanManager) {
68 parent = stateOwner;
69 beanManager = stateBeanManager;
70 completionRepository = repository;
71 }
72
73 /***
74 * Called to handle the request.
75 *
76 * @param request ControllerRequest The Function's ControllerRequest
77 * object.
78 * @param response ControllerResponse The Function's ControllerResponse
79 * object.
80 * @throws DBException upon underlying database exception error.
81 * @throws ControllerException upon underlying ControllerException error.
82 */
83 public void handleRequest(final ExpressoRequest request, final ExpressoResponse response) throws DBException,
84 ControllerException {
85
86 int wizardId = Integer.parseInt(request.getParameter(WizardController.WIZ_PARAMETER_ID));
87 if (wizardId < 0) {
88 throw new ControllerException("Illegal Paramter for wizard id: " + wizardId);
89 }
90
91 try {
92 CreationBeans completionBean = completionRepository.findById(wizardId);
93 beanManager.setCompletionBean(request, completionBean);
94 } catch (ObjectNotFoundException ex) {
95 throw new ControllerException("Unable to locate wizard by id: " + wizardId
96 + " it may have been deleted by someone else.");
97 }
98
99 Transition redirect = new Transition("", "", parent.getClass(), PromptChooseNode.STATE_NAME);
100 redirect.redirectTransition(request, response);
101 }
102 }