1 package com.instantbank.lettertemplate.control.web.handlers;
2
3 import java.util.HashMap;
4 import java.util.ArrayList;
5 import java.util.Enumeration;
6 import java.util.Hashtable;
7 import java.util.StringTokenizer;
8
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpSession;
11 import javax.servlet.ServletContext;
12
13 import com.instantbank.lettertemplate.control.event.SetLetterJobEvent;
14 import com.instantbank.lettertemplate.control.util.JSPUtil;
15 import com.instantbank.lettertemplate.control.util.WebKeys;
16 import com.instantbank.common.utilcomponents.Debug;
17 import com.instantbank.common.utilcomponents.CommonUtil;
18 import com.instantbank.common.utilcomponents.LetterTemplateGlobals;
19 import com.instantbank.lettertemplate.control.LetterTemplateEventException;
20 import com.instantbank.component.lettertemplate.util.Template;
21 import com.instantbank.lettertemplate.editor.web.TemplateTransformer;
22
23
24
31 public class SetLetterJobFlowHandler
32 implements FlowHandler {
33 private Debug debug = null;
34
35
36
41 public void doStart(HttpServletRequest request) { }
42
43
44
53 public String processFlow(HttpServletRequest request, Object answer,
54 ServletContext context)
55 throws LetterTemplateEventException {
56 debug = new Debug();
57 debug.setDebugginOn(true);
58 debug.setPreMessage("** SetLetterJobFlowHandler: ");
59 debug.println("processFlow");
60
61 String nextScreen = null;
62 SetLetterJobEvent ce = null;
63 HttpSession session = request.getSession();
64
65 String companyId
66 = (String)request.getSession().getAttribute(WebKeys.CompanyId);
67
68 if(request.getAttribute(WebKeys.SetLetterJobEvent) != null) {
69 ce = (SetLetterJobEvent)request.getAttribute(WebKeys.SetLetterJobEvent);
70 }
71
72 if(request.getAttribute(WebKeys.ExceptionOcurred) != null) {
73 nextScreen = "1";
74
75 }
76
77 else if(ce.getActionType() == SetLetterJobEvent.LIST_JOBS) {
78
79
80
81
82
83
84
85
86 session.setAttribute(WebKeys.LetterJobsList,
87 ((ArrayList)answer).get(0));
88 session.setAttribute(WebKeys.LocationsList,
89 ((ArrayList)answer).get(1));
90 session.setAttribute(WebKeys.CompanyFields,
91 ((ArrayList)answer).get(2));
92 session.setAttribute(WebKeys.FieldMenus,
93 ((ArrayList)answer).get(3));
94 session.setAttribute(WebKeys.TemplatesDescriptors,
95 ((ArrayList)answer).get(4));
96
97
98 JobWebImpl jobView
99 = (JobWebImpl)session.getAttribute(WebKeys.JobModelKey);
100 jobView.clean();
101 nextScreen = "2";
102 }
103
104 else if(ce.getActionType() == SetLetterJobEvent.GET_TEMPLATE_FIELDS
105 || ce.getActionType() == SetLetterJobEvent.GET_JOB
106 || ce.getActionType() == SetLetterJobEvent.SAVE_JOB) {
107
108
109
110
111
112
113
114
115 session.setAttribute(WebKeys.LetterJobsList,
116 ((ArrayList)answer).get(2));
117 session.setAttribute(WebKeys.LocationsList,
118 ((ArrayList)answer).get(3));
119 session.setAttribute(WebKeys.TemplatesDescriptors,
120 ((ArrayList)answer).get(4));
121 debug.println("WebKeys.TemplatesDescriptors refreshed in web session");
122
123
124 String problem = (String)(((ArrayList)answer).get(0));
125 if(problem.equals(LetterTemplateGlobals.STR_UNDEF)) {
126 Template templ = (Template)(((ArrayList)answer).get(1));
127 ArrayList[] setOfVars = templ.setOfVariables();
128 Long[] templateVarsCodes
129 = TemplateTransformer.varCodesFromSet(setOfVars);
130
131 request.setAttribute(WebKeys.TemplateFields, templateVarsCodes);
132 debug.println("WebKeys.TemplateFields put in web request");
133 if(ce.getActionType() == SetLetterJobEvent.GET_TEMPLATE_FIELDS) {
134 request.setAttribute(WebKeys.NewJobTemplate, "true");
135 }
136
137 nextScreen = "2";
138 }
139 else {
140 JSPUtil.putProblemInRequest(request, problem);
141 debug.println("JSPUtil.putProblemInRequest");
142 if(ce.getActionType() == SetLetterJobEvent.GET_TEMPLATE_FIELDS) {
143
144 JobWebImpl jobView
145 = (JobWebImpl)session.getAttribute(WebKeys.JobModelKey);
146 jobView.clean();
147 }
148 nextScreen = "1";
149 }
150 }
151
152 else if(ce.getActionType() == SetLetterJobEvent.REMOVE_JOB) {
153
154
155
156
157
158
159
160 session.setAttribute(WebKeys.LetterJobsList,
161 ((ArrayList)answer).get(1));
162 session.setAttribute(WebKeys.LocationsList,
163 ((ArrayList)answer).get(2));
164 session.setAttribute(WebKeys.TemplatesDescriptors,
165 ((ArrayList)answer).get(3));
166
167
168 String problem = (String)(((ArrayList)answer).get(0));
169 if(problem.equals(LetterTemplateGlobals.STR_UNDEF)) {
170
171 JobWebImpl jobView
172 = (JobWebImpl)session.getAttribute(WebKeys.JobModelKey);
173 jobView.clean();
174 nextScreen = "2";
175 }
176 else {
177 JSPUtil.putProblemInRequest(request, problem);
178 nextScreen = "1";
179 }
180 }
181
182 return nextScreen;
183 }
184
185
186
191 public void doEnd(HttpServletRequest request) { }
192 }
193
194