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.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   import com.instantbank.common.utilcomponents.CodeDescription;
13   import com.instantbank.servicing.control.event.ParmRestrictionsEvent;
14   import com.instantbank.servicing.control.util.JSPUtil;
15   import com.instantbank.servicing.control.util.WebKeys;
16   import com.instantbank.common.utilcomponents.Debug;
17   import com.instantbank.common.utilcomponents.ServicingGlobals;
18   import com.instantbank.servicing.control.ServicingEventException;
19   import com.instantbank.component.parameter.util.*;
20   
21   
22   /**
23    *  Set Parameter Restrictions: flow handler for deciding output screen after
24    *  processing an action
25    *
26    * @author Instant-bank (Jorge Cardenas)
27    * @created October 2002
28    */
29   public class ParmRestrictionsFlowHandler
30       implements FlowHandler {
31     private Debug debug = null;
32   
33   
34     /**
35      *  optional execution before processFlow method
36      *
37      * @param request HTTP request
38      */
39     public void doStart(HttpServletRequest request) { }
40   
41   
42     /**
43      *  principal method for deciding output screen after processing an action
44      *
45      * @param request of MainServlet
46      * @param answer of the action
47      * @param context web context
48      * @return String with the number of the  output screen
49      * @exception ServicingEventException
50      */
51     public String processFlow(HttpServletRequest request, Object answer,
52                               ServletContext context)
53        throws ServicingEventException {
54   
55       debug = new Debug();
56       debug.setDebugginOn(true);
57       debug.setPreMessage("** ParmRestrictionsFlowHandler: ");
58       debug.println("processFlow");
59   
60       HttpSession session = request.getSession();
61   
62       String nextScreen = null;
63       ParmRestrictionsEvent ce = null;
64   
65       if(request.getAttribute(WebKeys.ParmRestrictionsEvent) != null) {
66         ce = (ParmRestrictionsEvent)request.getAttribute(WebKeys.ParmRestrictionsEvent);
67       }
68   
69       if(request.getAttribute(WebKeys.ExceptionOcurred) != null) {
70         nextScreen = "1";  // RESTRICTIONS_PROBLEM
71   
72       }
73       else if(ce.getActionType() == ParmRestrictionsEvent.LIST_PARM_RESTRICTIONS) {
74         // answer is the current parameter restrictions: ArrayList()
75         // puts current parameter restrictions  in the web request :
76         int i;
77         // answer is the current parameter restrictions: ArrayList()
78         // puts current parameter restrictions  in the web request :
79         int j;
80         Hashtable tableCodes = new Hashtable();
81         ArrayList listCodes = new ArrayList();
82   
83         listCodes = (ArrayList)answer;
84         for(i = 0; i < listCodes.size(); i++) {
85           ArrayList parm = new ArrayList(((GroupParm)(listCodes.get(i))).getGroup());
86           for(j = 0; j < parm.size(); j++) {
87             ParmRestriction parmCode = null;
88             ParmRestrictionUpdate parmUpdate = new ParmRestrictionUpdate("", "", "", "");
89             parmCode = (ParmRestriction)parm.get(j);
90   
91             String code = parmCode.getCodeParameter();
92             tableCodes.put(code, parmUpdate);
93           }
94         }
95         // puts currents parameter codes in the web session :
96         session.setAttribute(WebKeys.ParmRestrictionsTable, tableCodes);
97   
98         // puts current parameter restrictions in the web request :
99         request.setAttribute(WebKeys.ParmRestrictionsList, answer);
100  
101        nextScreen = "2";  // RESTRICTIONS_MAIN
102  
103      }
104      else if(ce.getActionType() == ParmRestrictionsEvent.UPDATE_PARM_RESTRICTIONS) {
105        // answer is an ArrayList with 1 element:
106        // 0: current parameter restrictions: ArrayList()
107  
108        // puts current parameter restrictions in the web request :
109        request.setAttribute
110          (WebKeys.ParmRestrictionsList, answer);
111  
112        nextScreen = "2";  // RESTRICTIONS_MAIN
113  
114      }
115      return nextScreen;
116    }
117  
118  
119    /**
120     * optional execution after processFlow method
121     *
122     * @param request Description of the Parameter
123     */
124    public void doEnd(HttpServletRequest request) { }
125  }
126  
127