1    package com.instantbank.servicing.control.ejb.handlers;
2    
3    import java.util.ArrayList;
4    import java.util.Hashtable;
5    import java.rmi.RemoteException;
6    import javax.naming.InitialContext;
7    import javax.naming.NamingException;
8    import javax.ejb.CreateException;
9    import javax.ejb.DuplicateKeyException;
10   import javax.ejb.FinderException;
11   
12   import com.instantbank.common.utilcomponents.CodeDescription;
13   import com.instantbank.servicing.control.event.SetParameterXValueEvent;
14   import com.instantbank.common.utilcomponents.Debug;
15   import com.instantbank.component.parameter.ejb.Parameter;
16   import com.instantbank.servicing.control.ServicingEventException;
17   import com.instantbank.servicing.control.event.ServicingEvent;
18   import com.instantbank.component.parameter.util.*;
19   
20   /**
21    *  SetParameterXValue  usecase: handler of user requests in the Services layer
22    *
23    * @author Instant-bank (Roberto Contreras)
24    * @created October 26,  2002
25    */
26   public class SetParameterXValueHandler extends StateHandlerSupport {
27   
28     private Debug debug = null;
29   
30   
31     /**
32      *  Principal method that process a user request invoking Model EJBs methods
33      *
34      * @param event request data
35      * @return answer to request
36      * @exception ServicingEventException
37      */
38     public Object perform(ServicingEvent event)
39        throws ServicingEventException {
40       debug = new Debug();
41       debug.setDebugginOn(true);
42       debug.setPreMessage("** SetParameterXValue-services tier: ");
43       Object answer = "";
44       SetParameterXValueEvent ce = (SetParameterXValueEvent)event;
45   
46       switch (ce.getActionType()) {
47   
48         case SetParameterXValueEvent.LIST_PARAM_XVALUE:
49         {
50           debug.println("LIST_PARAM_XVALUE event");
51           try {
52             // obtaining EJB reference:
53             Parameter parameter = machine.getServicingControllerEJB()
54               .getParameter(ce.getCompanyId(), ce.getUserId());
55   
56             // invoking EJB methods :
57   
58             ParameterModel parameterModel = null;
59             parameterModel = parameter.listParamValues(ce.getCodeParameter());
60             answer = parameterModel;
61           }
62           catch(Exception e) {
63             // podrian distinguirse: RemoteException,
64             // CreateException, FinderException, NamingException, ...
65             throw new ServicingEventException(e.getMessage());
66           }
67         }
68           break;
69         case SetParameterXValueEvent.UPDATE_PARAM_XVALUE:
70         {
71           debug.println("UPDATE_PARAM_XVALUE event");
72           try {
73             Parameter parameter = machine.getServicingControllerEJB()
74               .getParameter(ce.getCompanyId(), ce.getUserId());
75   
76             Hashtable level1Code = parameter.loadLevel1Code();
77             Hashtable level2Code = parameter.loadLevel2Code();
78             String codeParameter
79                = parameter.updateParamValues
80               (ce.getItemsUpdate(), level1Code, level2Code);
81   
82             ParameterModel parameterModel = null;
83             parameterModel = parameter.listParamValues(codeParameter);
84             answer = parameterModel;
85   
86           }
87           catch(Exception e) {
88             throw new ServicingEventException(e.getMessage());
89           }
90         }
91           break;
92         case SetParameterXValueEvent.VERIFY_PARAM_XVALUE:
93         {
94           debug.println("VERIFY_PARAM_XVALUE event");
95           try {
96             Parameter parameter = machine.getServicingControllerEJB()
97               .getParameter(ce.getCompanyId(), ce.getUserId());
98   
99             ParameterModel parameterModel = null;
100            parameterModel = parameter.verifyParamValues(ce.getItemsUpdate());
101            answer = parameterModel;
102  
103          }
104          catch(Exception e) {
105            throw new ServicingEventException(e.getMessage());
106          }
107        }
108          break;
109  
110        default:
111          debug.println("Error: not implemented yet");
112          break;
113      }
114      return answer;
115    }
116  }
117  
118