1 package com.instantbank.servicing.control.web.handlers;
2
3 import java.util.HashMap;
4 import java.util.ArrayList;
5 import java.util.Enumeration;
6 import java.util.Locale;
7 import java.util.Hashtable;
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.ServletContext;
10
11 import oracle.xml.parser.v2.*;
12 import org.w3c.dom.*;
13 import org.xml.sax.*;
14
15 import com.instantbank.servicing.control.event.ParmLevel1ValuesEvent;
16 import com.instantbank.servicing.control.util.JSPUtil;
17 import com.instantbank.servicing.control.util.WebKeys;
18 import com.instantbank.common.utilcomponents.Debug;
19 import com.instantbank.common.utilcomponents.CommonUtil;
20 import com.instantbank.common.utilcomponents.ServicingExceptionMessage;
21 import com.instantbank.servicing.control.ServicingEventException;
22 import com.instantbank.servicing.control.event.ServicingEvent;
23
24
30 public class ParmLevel1ValuesHandler extends RequestHandlerSupport {
31
32 private Debug debug = null;
33 ServletContext context;
34
35
36
46 public ServicingEvent processRequest(HttpServletRequest request,
47 ServletContext context)
48 throws ServicingEventException {
49 debug = new Debug();
50 debug.setDebugginOn(true);
51 debug.setPreMessage("** ParmLevel1ValuesHandler-application tier: ");
52
53 this.context = context;
54 String action = request.getParameter("action");
55 debug.println("Creation of an ParmLevel1Values Event; "
56 + "ParmLevel1ValuesHandler (web): action=" + action);
57
58 if(action == null) {
59 throw new ServicingEventException
60 (ServicingExceptionMessage.SERVICE_NOT_SELECTED);
61 }
62 else if(action.equals("listParmLevel1Values")) {
63 return createListParmLevel1ValuesEvent(request);
64 }
65 else if(action.equals("updateParmLevel1Values")) {
66 return createUpdateParmLevel1ValuesEvent(request);
67 }
68 return null;
69 }
70
71
72
80 private ServicingEvent createListParmLevel1ValuesEvent
81 (HttpServletRequest request)
82 throws ServicingEventException {
83
84 try {
85
86
87 ParmLevel1ValuesEvent event
88 = new ParmLevel1ValuesEvent
89 (ParmLevel1ValuesEvent.LIST_PARM_LEVEL1_VALUES,
90 (String)request.getSession()
91 .getAttribute(WebKeys.CompanyId),
92 (Long)request.getSession().
93 getAttribute(WebKeys.UserId),
94 null);
95 request.setAttribute(WebKeys.ParmLevel1ValuesEvent, event);
96 return event;
97 }
98 catch(Exception e) {
99 throw new ServicingEventException
100 (ServicingExceptionMessage.PROBLEM_PARSING + e.getMessage()
101 + ServicingExceptionMessage.RETRY);
102 }
103 }
104
105
106
114 private ServicingEvent createUpdateParmLevel1ValuesEvent
115 (HttpServletRequest request)
116 throws ServicingEventException {
117
118 ArrayList items = null;
119 debug.println("****Entro al Update****");
120
121 try {
122
123
124 String xmlParmLevel1ValuesItems = request.getParameter("xmlParmLevel1ValuesItems").trim();
125 debug.println("xmlParmLevel1ValuesItems=" + xmlParmLevel1ValuesItems);
126
127
128
129 items = parseXMLParmLevel1Values(xmlParmLevel1ValuesItems);
130
131
132 ParmLevel1ValuesEvent event
133 = new ParmLevel1ValuesEvent
134 (ParmLevel1ValuesEvent.UPDATE_PARM_LEVEL1_VALUES,
135 (String)request.getSession().
136 getAttribute(WebKeys.CompanyId),
137 (Long)request.getSession().
138 getAttribute(WebKeys.UserId),
139 items);
140 request.setAttribute(WebKeys.ParmLevel1ValuesEvent, event);
141 return event;
142 }
143 catch(Exception e) {
144 throw new ServicingEventException
145 (ServicingExceptionMessage.PROBLEM_PARSING + e.getMessage()
146 + ServicingExceptionMessage.RETRY);
147 }
148 }
149
150
151
160
161 private ArrayList parseXMLParmLevel1Values(String xmlParmLevel1Values) throws Exception {
162 XMLDocument xmlDoc = CommonUtil.parseInfo(xmlParmLevel1Values);
163
164 NodeList nlCode = xmlDoc.selectNodes("/ParmLevel1ValuesList/ParmLevel1Values/code/text()");
165 NodeList nlName = xmlDoc.selectNodes("/ParmLevel1ValuesList/ParmLevel1Values/name/text()");
166 NodeList nlStatus = xmlDoc.selectNodes("/ParmLevel1ValuesList/ParmLevel1Values/status/text()");
167 int nlLength = nlCode.getLength();
168
169 String[] code = new String[nlLength];
170 String[] name = new String[nlLength];
171 String[] status = new String[nlLength];
172 for(int i = 0; i < nlLength; i++) {
173 code[i] = nlCode.item(i).getNodeValue();
174 name[i] = nlName.item(i).getNodeValue();
175 status[i] = nlStatus.item(i).getNodeValue();
176 debug.println("code, name, status of item i="
177 + code[i] + "--" + name[i] + "--" + status[i]);
178 }
179
180 ArrayList items = new ArrayList(3);
181 items.add(code);
182 items.add(name);
183 items.add(status);
184 return items;
185 }
186 }
187
188