1    package com.instantbank.component.parameter.ejb;
2    
3    import java.util.ArrayList;
4    import java.util.Hashtable;
5    import java.rmi.RemoteException;
6    import javax.ejb.SessionBean;
7    import javax.ejb.SessionContext;
8    import javax.ejb.EJBException;
9    import javax.ejb.ObjectNotFoundException;
10   import com.instantbank.common.utilcomponents.CodeDescription;
11   import com.instantbank.component.parameter.util.*;
12   import com.instantbank.common.utilcomponents.Debug;
13   import com.instantbank.common.utilcomponents.DAOException;
14   
15   /**
16    *  Session Stateful EJB for for servicing ear : managamente of parameters
17    *
18    * @author Instant-bank (Roberto Contreras)
19    * @created September 2002
20    */
21   public class ParameterEJB
22       implements SessionBean {
23   
24     // attributes corresponding to EJB state:
25     /**
26      *  current company
27      */
28     String companyId;
29     /**
30      *  current user
31      */
32     Long userId;
33   
34     // others attributes: context, DAO, debug
35     /**
36      *  session context
37      */
38     private SessionContext context;
39     /**
40      *  ParameterDAO object for interacting with the database
41      */
42     private ParameterDAO parameterDao;
43     private Debug debug = null;
44   
45   
46     // CONSTRUCTOR :
47     /**
48      *  Constructor
49      */
50     public ParameterEJB() { }
51   
52   
53     // CONTEXT METHODS:
54     /**
55      *  Set session context
56      *
57      * @param sc The new sessionContext value
58      */
59     public void setSessionContext(SessionContext sc) {
60       debug = new Debug();
61       debug.setDebugginOn(true);
62       debug.setPreMessage("** ParameterEJB");
63       this.context = sc;
64     }
65   
66   
67     /**
68      *  Actions after swapping
69      */
70     public void ejbActivate() {
71       try {
72         getDao();
73       }
74       catch(DAOException se) {
75         throw new RuntimeException(se.getMessage());
76       }
77       debug = new Debug();
78       debug.setDebugginOn(true);
79       debug.setPreMessage("** ParameterEJB");
80     }
81   
82   
83     /**
84      *  Actions before swapping
85      */
86     public void ejbPassivate() {
87       parameterDao = null;
88       debug = null;
89     }
90   
91   
92     // EJB METHODS:
93   
94     /**
95      *  Get attribute values: companyId, userId and ParameterDAO
96      *  object (parameterDao attribute)
97      *
98      * @param companyId current company
99      * @param userId current user
100     */
101    public void ejbCreate(String companyId, Long userId) {
102      // set the instance data:
103      this.companyId = companyId;
104      this.userId = userId;
105      try {
106        getDao();
107      }
108      catch(DAOException se) {
109        throw new RuntimeException(se.getMessage());
110      }
111    }
112  
113  
114    /**
115     *  Action before removing EJB instance
116     */
117    public void ejbRemove() { }
118  
119  
120    // BUSINESS METHODS FOR MANAGEMENT PARAMETERS OF LEVELS:
121  
122    /**
123     * Loads parameters levels names of the current company.
124     *
125     * @return ArrayList object with 2 elements:
126     *         (0) parameter level 1  name.
127     *         (1) parameter level 2  name.
128     * @throws DAOException Description of the Exception
129     */
130    public ArrayList loadParamLevelsName() throws DAOException {
131      debug.println("load ParamLevelsName service");
132      ArrayList answer = null;
133      try {
134        getDao();
135        answer = parameterDao.loadParamLevelsName();
136      }
137      catch(DAOException se) {
138        debug.println("DAOException " + se);
139        throw new DAOException(se.getMessage());
140      }
141      catch(Exception ex) {
142        throw new EJBException(ex.getMessage());
143      }
144      return answer;
145    }
146  
147  
148    /**
149     * Applies a set of updates in the parameters levels names of the current
150     * company.
151     *
152     * @param items ArrayList with 2 elements of type String
153     *         representing the attributes of items to apply param name of
154     *         level 1 and level 2.
155     * @return ArrayList object with 2 elements:
156     *         (0) probabily problem.
157     *         (1) ArrayList with a set of parameters levels names.
158     * @throws DAOException Description of the Exception
159     */
160    public ArrayList updateParamLevelsName(ArrayList items)
161       throws DAOException {
162      debug.println("updateParamLevelsName service");
163      ArrayList answer = null;
164      try {
165        getDao();
166        answer = parameterDao.updateParamLevelsName(items);
167      }
168      catch(DAOException se) {
169        debug.println("DAOException: " + se);
170        throw new DAOException(se.getMessage());
171      }
172      catch(Exception ex) {
173        throw new EJBException(ex.getMessage());
174      }
175      return answer;
176    }
177  
178  
179    /**
180     * Loads all [code, value] of the values of parameter level 1
181     * of the current company.
182     *
183     * @return CodeDescription[] object with
184     *         [code, value] of the values of parameter level 1.
185     * @throws DAOException Description of the Exception
186     */
187    public CodeDescription[] listParamLevel1Points()
188       throws DAOException {
189      debug.println("list ParamLevel1Points service");
190      CodeDescription[] answer = null;
191      try {
192        getDao();
193        answer = parameterDao.listParamLevel1Points();
194      }
195      catch(DAOException se) {
196        debug.println("DAOException " + se);
197        throw new DAOException(se.getMessage());
198      }
199      catch(Exception ex) {
200        throw new EJBException(ex.getMessage());
201      }
202      return answer;
203    }
204  
205  
206    /**
207     * Applies a set of changes in the values of parameter level 1
208     * of the current company.
209     *
210     * @param items ArrayList with 3 elements of
211     *      type String[] representing the attributes of items to apply code,
212     *      value and status. Status indicates if the item is for inserting,
213     *      deleting or updating (ServicingGlobals.INSERT,
214     *      ServicingGlobals.DELETE, ServicingGlobals.UPDATE)
215     * @return ArrayList with 2 elements:
216     *      (0) possible problem (String),
217     *      (1) current values of parameter level 1 list (CodeDescription[])
218     * @throws DAOException Description of the Exception
219     */
220    public ArrayList applyItemsParamLevel1Points(ArrayList items)
221       throws DAOException {
222      debug.println("applyItemsParamLevel1Points service");
223      ArrayList answer = null;
224      try {
225        getDao();
226        answer = parameterDao.applyItemsParamLevel1Points(items);
227      }
228      catch(DAOException se) {
229        debug.println("DAOException: " + se);
230        throw new DAOException(se.getMessage());
231      }
232      catch(Exception ex) {
233        throw new EJBException(ex.getMessage());
234      }
235      return answer;
236    }
237  
238  
239    /**
240     * Loads all [code, value] of the values of parameter level 2
241     * of the current company.
242     *
243     * @return CodeDescription[] object with
244     *         [code, value] of the values of parameter level 2.
245     * @throws DAOException Description of the Exception
246     */
247    public CodeDescription[] listParamLevel2Points()
248       throws DAOException {
249      debug.println("list ParamLevel2Points service");
250      CodeDescription[] answer = null;
251      try {
252        getDao();
253        answer = parameterDao.listParamLevel2Points();
254      }
255      catch(DAOException se) {
256        debug.println("DAOException " + se);
257        throw new DAOException(se.getMessage());
258      }
259      catch(Exception ex) {
260        throw new EJBException(ex.getMessage());
261      }
262      return answer;
263    }
264  
265  
266    /**
267     * Applies a set of changes in the values of parameter level 2
268     * of the current company.
269     *
270     * @param items ArrayList with 3 elements of
271     *      type String[] representing the attributes of items to apply code,
272     *      value and status. Status indicates if the item is for inserting,
273     *      deleting or updating (ServicingGlobals.INSERT,
274     *      ServicingGlobals.DELETE, ServicingGlobals.UPDATE)
275     * @return ArrayList with 2 elements:
276     *      (0) possible problem (String),
277     *      (1) current values of parameter level 2 list (CodeDescription[])
278     * @throws DAOException Description of the Exception
279     */
280    public ArrayList applyItemsParamLevel2Points(ArrayList items)
281       throws DAOException {
282      debug.println("applyItemsParamLevel2Points service");
283      ArrayList answer = null;
284      try {
285        getDao();
286        answer = parameterDao.applyItemsParamLevel2Points(items);
287      }
288      catch(DAOException se) {
289        debug.println("DAOException: " + se);
290        throw new DAOException(se.getMessage());
291      }
292      catch(Exception ex) {
293        throw new EJBException(ex.getMessage());
294      }
295      return answer;
296    }
297  
298  
299    // BUSINESS METHODS FOR MANAGEMENT PARAMETER SEARH ORDER:
300  
301    /**
302     * Loads parameters search order of the current company.
303     *
304     * @return ArrayList object with 2 elements:
305     *         (0) parameter search 2  value.
306     *         (1) parameter search 3  value.
307     * @throws DAOException Description of the Exception
308     */
309    public ArrayList loadParamSearchValues() throws DAOException {
310      debug.println("load ParamSearchValues service");
311      ArrayList answer = null;
312      try {
313        getDao();
314        answer = parameterDao.loadParamSearchValues();
315      }
316      catch(DAOException se) {
317        debug.println("DAOException " + se);
318        throw new DAOException(se.getMessage());
319      }
320      catch(Exception ex) {
321        throw new EJBException(ex.getMessage());
322      }
323      return answer;
324    }
325  
326  
327    /**
328     * Applies a set of updates in the parameters search order of the current
329     * company.
330     *
331     * @param items ArrayList with 2 elements of type String
332     *         representing the attributes of items to apply
333     *         parameters search order.
334     * @return ArrayList object with 2 elements:
335     *         (0) probabily problem.
336     *         (1) ArrayList with a set of parameters search order.
337     * @throws DAOException Description of the Exception
338     */
339    public ArrayList updateParamSearchValues(ArrayList items)
340       throws DAOException {
341      debug.println("update ParamSearchValues service");
342      ArrayList answer = null;
343      try {
344        getDao();
345        answer = parameterDao.updateParamSearchValues(items);
346      }
347      catch(DAOException se) {
348        debug.println("DAOException: " + se);
349        throw new DAOException(se.getMessage());
350      }
351      catch(Exception ex) {
352        throw new EJBException(ex.getMessage());
353      }
354      return answer;
355    }
356  
357    // BUSINESS METHODS FOR MANAGEMENT PARAMETER RESTRICTIONS
358  
359    /**
360     * Loads the set parameters restrictions of the current company
361     * for each group parameter.
362     *
363     * @return ArrayList object with (n) elements. When each element is
364     * representing a group parameter and its parameters restrictions of
365     * type GroupParam.
366     * @throws DAOException Description of the Exception
367     */
368    public ArrayList listParamRestrictions() throws DAOException {
369  
370      debug.println("listParamRestrictions service");
371      ArrayList answer = null;
372      try {
373        getDao();
374        answer = parameterDao.listParamRestrictions();
375      }
376      catch(DAOException se) {
377        debug.println("DAOException: " + se);
378        throw new DAOException(se.getMessage());
379      }
380      catch(Exception ex) {
381        throw new EJBException(ex.getMessage());
382      }
383      return answer;
384    }
385  
386  
387    /**
388     * Applies a set of updates in the parameters restrictions in the current
389     * company.
390     *
391     * @param items Hashtable with (n) elements of type ParmRestrictionUpdate.
392     *         When each element is representing the attributes of parameter
393     *         restrictions.
394     * @return ArrayList object with (n) elements. When each element is
395     * representing a group parameter and its parameters restrictions of
396     * type GroupParam.
397     * @throws DAOException Description of the Exception
398     */
399    public ArrayList updateParamRestrictions(Hashtable items)
400       throws DAOException {
401  
402      debug.println("updateParamRestrictions service");
403      ArrayList answer = null;
404      try {
405        getDao();
406        answer = parameterDao.updateParamRestrictions(items);
407      }
408      catch(DAOException se) {
409        debug.println("DAOException: " + se);
410        throw new DAOException(se.getMessage());
411      }
412      catch(Exception ex) {
413        throw new EJBException(ex.getMessage());
414      }
415      return answer;
416    }
417  
418    // BUSINESS METHODS FOR MANAGEMENT SET PARAMETER VALUES
419  
420    /**
421     * Loads the set parameters values of the current company
422     * for the parameter without warning colors.
423     *
424     * @param codeParamater Description of the Parameter
425     * @return ParameterModel object. When its atributes are
426     *         representing the all values and warning colors for the parameter.
427     * @throws DAOException Description of the Exception
428     */
429    public ParameterModel listParamValues(String codeParamater)
430       throws DAOException {
431  
432      debug.println("listParamValues service");
433      ParameterModel answer = null;
434      try {
435        getDao();
436        answer = parameterDao.listParamValues(codeParamater);
437      }
438      catch(DAOException se) {
439        debug.println("DAOException: " + se);
440        throw new DAOException(se.getMessage());
441      }
442      catch(Exception ex) {
443        throw new EJBException(ex.getMessage());
444      }
445      return answer;
446    }
447  
448  
449    /**
450     * Loads the value an code of level 1 point
451     *
452     * @return level1Code The Hashtable object with value of level 1 point as
453     *        the key and the code of point 1 as value.
454     * @throws DAOException Description of the Exception
455     */
456    public Hashtable loadLevel1Code() throws DAOException {
457  
458      debug.println("loadLevel1Code service");
459      Hashtable level1Code = null;
460      try {
461        getDao();
462        level1Code = parameterDao.loadLevel1Code();
463      }
464      catch(DAOException se) {
465        debug.println("DAOException: " + se);
466        throw new DAOException(se.getMessage());
467      }
468      catch(Exception ex) {
469        throw new EJBException(ex.getMessage());
470      }
471      return level1Code;
472    }
473  
474  
475    /**
476     * Loads the value an code of level 2 point
477     *
478     * @return level1Code The Hashtable object with value of level 2 point as
479     *        the key and the code of point 2 as value.
480     * @throws DAOException Description of the Exception
481     */
482    public Hashtable loadLevel2Code() throws DAOException {
483  
484      debug.println("loadLevel2Code service");
485      Hashtable level2Code = null;
486      try {
487        getDao();
488        level2Code = parameterDao.loadLevel2Code();
489      }
490      catch(DAOException se) {
491        debug.println("DAOException: " + se);
492        throw new DAOException(se.getMessage());
493      }
494      catch(Exception ex) {
495        throw new EJBException(ex.getMessage());
496      }
497      return level2Code;
498    }
499  
500  
501    /**
502     * Applies a set of updates in the parameters values in the current
503     * company.
504     *
505     * @param items ParameterValue object with the value of code parameter,
506     *         type of parameter and a Hashtable with the point1+"|"+point2 as
507     *         the Key and the value of parameter as the Value.
508     * @param level1Code The Hashtable object with value of level 1 point as
509     *        the key and the code of point 1 as value.
510     * @param level2Code The Hashtable object with value of level 2 point as
511     *        the key and the code of point 2 as value.
512     * @return codeParameter The value of code parameter.
513     * @throws DAOException Description of the Exception
514     */
515    public String updateParamValues(ParameterValue items, Hashtable level1Code,
516                                    Hashtable level2Code) throws DAOException {
517  
518      debug.println("updateParamValues service");
519      String answer = null;
520      try {
521        getDao();
522        answer = parameterDao.updateParamValues(items, level1Code, level2Code);
523      }
524      catch(DAOException se) {
525        debug.println("DAOException: " + se);
526        throw new DAOException(se.getMessage());
527      }
528      catch(Exception ex) {
529        throw new EJBException(ex.getMessage());
530      }
531      return answer;
532    }
533  
534  
535    /**
536     * Check the parameters values and set warning colors to ParameterModel
537     * object of the current company for the parameter. This service doesn't
538     * save parameters values in the data base. Only verify warning colors.
539     *
540     * @param items ParameterValue object with the value of code parameter,
541     *         type of parameter and a Hashtable with the point1+"|"+point2 as
542     *         the Key and the value of parameter as the Value.
543     * @return ParameterModel object. When its atributes are
544     *         representing the all values and warning colors for the parameter.
545     * @throws DAOException Description of the Exception
546     */
547    public ParameterModel verifyParamValues(ParameterValue items)
548       throws DAOException {
549  
550      debug.println("verifyParamValues service");
551      ParameterModel answer = null;
552      try {
553        getDao();
554        answer = parameterDao.verifyParamValues(items);
555      }
556      catch(DAOException se) {
557        debug.println("DAOException: " + se);
558        throw new DAOException(se.getMessage());
559      }
560      catch(Exception ex) {
561        throw new EJBException(ex.getMessage());
562      }
563      return answer;
564    }
565  
566    // AUXILIARY METHODS
567  
568    /**
569     * Obtains a DAO instance assigning to parameterDao attribute
570     *
571     * @return The dao value
572     * @exception DAOException
573     */
574    private ParameterDAO getDao()
575       throws DAOException {
576      if(parameterDao == null) {
577        parameterDao =
578          new ParameterDAO(companyId, userId);
579      }
580      return parameterDao;
581    }
582  }
583