01 /*
02 * Created on Sep 21, 2007
03 */
04 package com.x8ing.mc.web;
05
06 import javax.servlet.http.HttpServletRequest;
07 import javax.servlet.http.HttpServletResponse;
08
09 import org.apache.struts.action.Action;
10 import org.apache.struts.action.ActionForm;
11 import org.apache.struts.action.ActionForward;
12 import org.apache.struts.action.ActionMapping;
13
14 import com.x8ing.mc.Configuration;
15 import com.x8ing.mc.MonteCarloControler;
16
17 /**
18 * @author pheusser
19 *
20 */
21 public class ProcessMCAction extends Action {
22
23 public static final String SESSION_KEY_MONTE_CARLO_CONTRLOER = "session_key_mcc";
24
25 public static final String REQ_PARAM_BUTTON_START = "buttonStart";
26
27 public static final String REQ_PARAM_BUTTON_RESET = "buttonReset";
28
29 public ActionForward execute(ActionMapping mapping, ActionForm inForm, HttpServletRequest request,
30 HttpServletResponse response) throws Exception {
31
32 MCForm form = (MCForm) inForm;
33
34 if (request.getParameter(REQ_PARAM_BUTTON_START) != null) {
35
36 // start simulation
37
38 String msg = "Start simulation with params: " + form.getConfiguration().toString();
39 System.out.println(msg);
40
41 MonteCarloControler mcc = new MonteCarloControler(form.getConfiguration());
42 mcc.runBusinessProcessSimulation();
43
44 // add it to form, as the controler can be regarded as the result
45 form.setMonteCarloControlerResult(mcc);
46
47 // add a reference directly to session: for image servlet
48 request.getSession().setAttribute(SESSION_KEY_MONTE_CARLO_CONTRLOER, mcc);
49
50 return mapping.findForward("success");
51
52 } else if (request.getParameter(REQ_PARAM_BUTTON_RESET) != null) {
53
54 String msg = "reset configuration";
55 System.out.println(msg);
56
57 form.setConfiguration(new Configuration());
58
59 return mapping.findForward("reset");
60
61 } else {
62
63 // command not understood
64 return mapping.getInputForward();
65
66 }
67 }
68
69 }
|