1 package com.instantbank.component.parameter.ejb;
2
3 import java.util.*;
4 import javax.ejb.EJBException;
5
6
7 import java.io.Serializable;
8 import java.sql.Types;
9 import java.sql.Connection;
10 import java.sql.Statement;
11 import java.sql.PreparedStatement;
12 import java.sql.CallableStatement;
13 import java.sql.ResultSet;
14 import java.sql.SQLException;
15 import javax.sql.DataSource;
16
17
18 import java.io.StringWriter;
19 import java.io.PrintWriter;
20 import java.io.InputStream;
21 import java.io.ByteArrayInputStream;
22
23
24 import com.instantbank.component.parameter.util.*;
25
26
27 import com.instantbank.common.utilcomponents.CodeDescription;
28 import com.instantbank.common.utilcomponents.DatabaseNames;
29 import com.instantbank.common.utilcomponents.Debug;
30 import com.instantbank.common.utilcomponents.ServicingExceptionMessage;
31 import com.instantbank.common.utilcomponents.ServicingGlobals;
32 import com.instantbank.common.utilcomponents.JNDINames;
33 import com.instantbank.common.utilcomponents.DAOException;
34 import com.instantbank.common.utilcomponents.DAOUtil;
35 import com.instantbank.common.utilcomponents.CommonUtil;
36
37
38 import org.apache.regexp.RE;
39
40
41
48 public class ParameterDAO {
49
50
51
54 String companyId;
55
58 Long userId;
59
60
61
64 private Connection dbConnection = null;
65
68 private DataSource datasource = null;
69
70
71 private Debug debug = null;
72
73
76 private String expressionNumC = "^\\d{1,3}(,\\d{3})*\\.\\d{2}$";
77 private String expressionNumP = "^\\d+\\.\\d{6}$";
78 private String expressionNumInt = "^\\d{1,3}(,\\d{3})*$";
79 private String expressionSeqInt = "^\\d+,\\d+,\\d+,\\d+$";
80 private RE regularExpressionNumC = null;
81 private RE regularExpressionNumP = null;
82 private RE regularExpressionNumInt = null;
83 private RE regularExpressionSeqInt = null;
84
85
86
93 public ParameterDAO(String companyId, Long userId)
94 throws DAOException {
95 debug = new Debug();
96 debug.setDebugginOn(true);
97 debug.setPreMessage("** ParameterDAO");
98
99 this.companyId = companyId;
100 this.userId = userId;
101 datasource = DAOUtil.getDataSource(JNDINames.INSTANTBANKDB);
102 try {
103 this.regularExpressionNumC = new RE(this.expressionNumC);
104 this.regularExpressionNumP = new RE(this.expressionNumP);
105 this.regularExpressionNumInt = new RE(this.expressionNumInt);
106 this.regularExpressionSeqInt = new RE(this.expressionSeqInt);
107 }
108 catch(Exception ae) {
109 debug.println("Exception: " + ae.toString());
110 }
111 }
112
113
114
115
116
117
126 public ArrayList loadParamLevelsName() throws DAOException {
127
128 debug.println("loading parameters levels name");
129 PreparedStatement ps = null;
130 ResultSet rs = null;
131 String queryStr =
132 " SELECT cmp_sv_parm_level1_name, cmp_sv_parm_level2_name "
133 + " FROM " + DatabaseNames.COMPANIES
134 + " WHERE cmp_id = ? ";
135 ArrayList answer = new ArrayList(2);
136 String paramLevel1 = null;
137 String paramLevel2 = null;
138
139 try {
140 dbConnection = DAOUtil.getDBConnection(datasource);
141 ps = dbConnection.prepareStatement(queryStr);
142 ps.setLong(1, Long.parseLong(this.companyId));
143 ps.executeQuery();
144 rs = ps.getResultSet();
145 rs.next();
146 paramLevel1 = rs.getString(1);
147 paramLevel2 = rs.getString(2);
148 answer.add(paramLevel1);
149 answer.add(paramLevel2);
150 }
151 catch(Exception ae) {
152 debug.println("Exception: " + ae.toString());
153 throw new DAOException
154 (ServicingExceptionMessage.PROBLEM_LOAD_PARM_LEVELS_NAME
155 + ae.getMessage());
156 }
157 finally {
158 DAOUtil.closeResultSet(rs);
159 DAOUtil.closePreparedStatement(ps);
160 DAOUtil.closeConnection(dbConnection);
161 }
162 return answer;
163 }
164
165
166
178 public ArrayList updateParamLevelsName(ArrayList items)
179 throws DAOException {
180
181 debug.println("applying a set of updates to params levels of current company");
182 PreparedStatement ps = null;
183 ArrayList list = new ArrayList(2);
184 ArrayList answer = new ArrayList(2);
185 boolean successTransaction = false;
186 String updateStr = " UPDATE " + DatabaseNames.COMPANIES + " SET"
187 + " cmp_last_changed_by = ?,"
188 + " cmp_last_changed_date = SYSDATE,"
189 + " cmp_sv_parm_level1_name = ?,"
190 + " cmp_sv_parm_level2_name = ?"
191 + " WHERE cmp_id = ?";
192 String problem = ServicingGlobals.STR_UNDEF;
193 try {
194 dbConnection = DAOUtil.getDBConnection(datasource);
195 dbConnection.setAutoCommit(false);
196 ps = dbConnection.prepareStatement(updateStr);
197 ps.setLong(1, this.userId.longValue());
198 ps.setString(2, ((String)(items.get(0))));
199 ps.setString(3, ((String)(items.get(1))));
200 ps.setLong(4, Long.parseLong(this.companyId));
201 int num = ps.executeUpdate();
202 if(num == 0) {
203 throw new DAOException
204 (ServicingExceptionMessage.PROBLEM_APPLYING_UPDATES_PARM_NAMES);
205 }
206 successTransaction = true;
207 }
208 catch(Exception ae) {
209 debug.println("Exception applying item to DB in update "
210 + " : " + ae.toString());
211 StringWriter sw = new StringWriter();
212 PrintWriter pw = new PrintWriter(sw);
213 ae.printStackTrace(pw);
214 String paramName = (items != null) ? ((String)(items.get(0))) : "";
215 problem = "Current parameter level name: " + paramName
216 + " :" + ae.getMessage() + "|" + sw.toString();
217 }
218 finally {
219 try {
220 if(successTransaction) {
221 dbConnection.commit();
222 debug.println("commit done");
223 }
224 else {
225 dbConnection.rollback();
226 debug.println("rollback done");
227 }
228 }
229 catch(Exception e) {
230 debug.println("Exception resolving transaction: " + e.toString());
231 StringWriter sw = new StringWriter();
232 PrintWriter pw = new PrintWriter(sw);
233 e.printStackTrace(pw);
234 problem = ServicingExceptionMessage.PROBLEM_APPLYING_CHANGES_PARM_NAMES
235 + e.getMessage()
236 + "|" + sw.toString();
237 }
238 DAOUtil.closePreparedStatement(ps);
239 DAOUtil.closeConnection(dbConnection);
240 }
241
242 try {
243 list = this.loadParamLevelsName();
244 answer.add(problem);
245 answer.add(list);
246 }
247 catch(Exception ae) {
248 throw new DAOException
249 (ServicingExceptionMessage.PROBLEM_LOAD_PARM_LEVELS_NAME
250 + ae.getMessage());
251 }
252 return answer;
253 }
254
255
256
264 public CodeDescription[] listParamLevel1Points()
265 throws DAOException {
266 debug.println("loading parameters level 1 points of current company");
267
268 PreparedStatement ps = null;
269 ResultSet rs = null;
270 String queryStr = " SELECT code_l1_point, value "
271 + " FROM " + DatabaseNames.SV_LEVEL1_POINT
272 + " WHERE code_company = ?"
273 + " AND code_l1_point > 0 "
274 + " ORDER BY value ";
275 CodeDescription[] answer = null;
276
277 try {
278 dbConnection = DAOUtil.getDBConnection(datasource);
279 ps = dbConnection.prepareStatement(queryStr);
280 ps.setLong(1, Long.parseLong(companyId));
281 answer = DAOUtil.loadCodeDescription(ps, rs);
282 }
283 catch(Exception ae) {
284 debug.println("Exception: " + ae.toString());
285 throw new DAOException
286 (ServicingExceptionMessage.PROBLEM_LOAD_PARAM_LEVEL1_VALUES
287 + ae.getMessage());
288 }
289 finally {
290 DAOUtil.closeResultSet(rs);
291 DAOUtil.closePreparedStatement(ps);
292 DAOUtil.closeConnection(dbConnection);
293 }
294 return answer;
295 }
296
297
298
312 public ArrayList applyItemsParamLevel1Points(ArrayList items)
313 throws DAOException {
314
315 debug.println("applying a set of changes to points of parameter level 1 of current company");
316 PreparedStatement ps1;
317 PreparedStatement ps2;
318 PreparedStatement ps3;
319 ps1 = ps2 = ps3 = null;
320 boolean listsBuilted = false;
321 boolean successTransaction = false;
322 CodeDescription item = null;
323 ArrayList insertList = new ArrayList();
324 ArrayList deleteList = new ArrayList();
325 ArrayList updateList = new ArrayList();
326 int listSize;
327
328 String insertStr = " INSERT INTO " + DatabaseNames.SV_LEVEL1_POINT
329 + " (code_l1_point, code_company, value)"
330 + " VALUES ("
331 + DatabaseNames.SEQ_SVLEVEL1_POINT + ".nextval,"
332 + " ?, ?)";
333
334 String deleteStr = " DELETE " + DatabaseNames.SV_LEVEL1_POINT
335 + " WHERE code_l1_point = ?";
336
337 String updateStr = " UPDATE " + DatabaseNames.SV_LEVEL1_POINT
338 + " SET value = ?"
339 + " WHERE code_l1_point = ?";
340
341 String problem = ServicingGlobals.STR_UNDEF;
342 CodeDescription[] paramLevel1ValuesList = null;
343 ArrayList answer = null;
344
345
346
347 try {
348 String[] code = (String[])items.get(0);
349 String[] value = (String[])items.get(1);
350 String[] status = (String[])items.get(2);
351 int numItems = code.length;
352
353 for(int i = 0; i < numItems; i++) {
354 item = new CodeDescription(Long.parseLong(code[i]), value[i]);
355 if(status[i].equals(ServicingGlobals.INSERT)) {
356 insertList.add(item);
357 }
358 else if(status[i].equals(ServicingGlobals.DELETE)) {
359 deleteList.add(item);
360 }
361 else if(status[i].equals(ServicingGlobals.UPDATE)) {
362 updateList.add(item);
363 }
364 else {
365 throw new DAOException
366 (ServicingExceptionMessage.ITEM_STATUS_INVALID);
367 }
368 }
369 listsBuilted = true;
370 }
371 catch(Exception e) {
372 debug.println("Exception building lists: " + e.toString());
373 StringWriter sw = new StringWriter();
374 PrintWriter pw = new PrintWriter(sw);
375 e.printStackTrace(pw);
376 problem =
377 ServicingExceptionMessage.PROBLEM_APPLYING_CHANGES_PARAM_LEVEL1_VALUES
378 + e.getMessage()
379 + "|" + sw.toString();
380 }
381
382
383 if(listsBuilted) {
384 String phase = "";
385 try {
386 dbConnection = DAOUtil.getDBConnection(datasource);
387 dbConnection.setAutoCommit(false);
388
389
390 phase = "insert";
391 ps1 = dbConnection.prepareStatement(insertStr);
392 listSize = insertList.size();
393 for(int i = 0; i < listSize; i++) {
394 item = (CodeDescription)(insertList.get(i));
395 ps1.setLong(1, Long.parseLong(companyId));
396 ps1.setString(2, item.getDescription());
397 ps1.executeUpdate();
398 }
399
400
401 phase = "delete";
402 ps2 = dbConnection.prepareStatement(deleteStr);
403 listSize = deleteList.size();
404 for(int i = 0; i < listSize; i++) {
405 item = (CodeDescription)(deleteList.get(i));
406 ps2.setLong(1, item.getCode());
407 int num = ps2.executeUpdate();
408 if(num == 0) {
409 throw new DAOException(
410 ServicingExceptionMessage.PROBLEM_APPLYING_DELETES1_PARAM_LEVEL1_VALUES);
411 }
412 }
413
414
415 phase = "update";
416 ps3 = dbConnection.prepareStatement(updateStr);
417 listSize = updateList.size();
418 for(int i = 0; i < listSize; i++) {
419 item = (CodeDescription)(updateList.get(i));
420 ps3.setString(1, item.getDescription());
421 ps3.setLong(2, item.getCode());
422 int num = ps3.executeUpdate();
423 if(num == 0) {
424 throw new DAOException(
425 ServicingExceptionMessage.PROBLEM_APPLYING_UPDATES1_PARAM_LEVEL1_VALUES);
426 }
427 }
428 successTransaction = true;
429 }
430 catch(Exception ae) {
431 debug.println("Exception applying item to DB in phase " + phase
432 + " : " + ae.toString());
433 StringWriter sw = new StringWriter();
434 PrintWriter pw = new PrintWriter(sw);
435 ae.printStackTrace(pw);
436 String subproblem = null;
437 if(phase.equals("insert")) {
438 subproblem = ServicingExceptionMessage.PROBLEM_APPLYING_INSERTS_PARAM_LEVEL1_VALUES;
439 }
440 else if(phase.equals("delete")) {
441 subproblem = ServicingExceptionMessage.PROBLEM_APPLYING_DELETES2_PARAM_LEVEL1_VALUES;
442 }
443 else {
444 subproblem = ServicingExceptionMessage.PROBLEM_APPLYING_UPDATES2_PARAM_LEVEL1_VALUES;
445 }
446 String value = (item != null) ? item.getDescription() : "";
447 problem = subproblem
448 + "current parameter of level 1 value : " + value
449 + " :" + ae.getMessage() + "|" + sw.toString();
450 }
451 finally {
452 try {
453 if(successTransaction) {
454 dbConnection.commit();
455 debug.println("commit done");
456 }
457 else {
458 dbConnection.rollback();
459 debug.println("rollback done");
460 }
461 }
462 catch(Exception e) {
463 debug.println("Exception resolving transaction: " + e.toString());
464 StringWriter sw = new StringWriter();
465 PrintWriter pw = new PrintWriter(sw);
466 e.printStackTrace(pw);
467 problem = ServicingExceptionMessage.PROBLEM_APPLYING_CHANGES_PARAM_LEVEL1_VALUES
468 + e.getMessage()
469 + "|" + sw.toString();
470 }
471 DAOUtil.closePreparedStatement(ps1);
472 DAOUtil.closePreparedStatement(ps2);
473 DAOUtil.closePreparedStatement(ps3);
474 DAOUtil.closeConnection(dbConnection);
475 }
476 }
477
478
479 try {
480 answer = new ArrayList(3);
481 ArrayList paramLevelsNameList = new ArrayList(2);
482 paramLevelsNameList = this.loadParamLevelsName();
483 paramLevel1ValuesList = this.listParamLevel1Points();
484 answer.add(problem);
485 answer.add(paramLevelsNameList);
486 answer.add(paramLevel1ValuesList);
487 }
488 catch(Exception ae) {
489 throw new DAOException(
490 ServicingExceptionMessage.PROBLEM_LOAD_PARAM_LEVEL1_VALUES
491 + ae.getMessage());
492 }
493 return answer;
494 }
495
496
497
505 public CodeDescription[] listParamLevel2Points()
506 throws DAOException {
507 debug.println("loading parameters level 2 points of current company");
508
509 PreparedStatement ps = null;
510 ResultSet rs = null;
511 String queryStr = " SELECT code_l2_point, value "
512 + " FROM " + DatabaseNames.SV_LEVEL2_POINT
513 + " WHERE code_company = ?"
514 + " AND code_l2_point > 0 "
515 + " ORDER BY value ";
516 CodeDescription[] answer = null;
517
518 try {
519 dbConnection = DAOUtil.getDBConnection(datasource);
520 ps = dbConnection.prepareStatement(queryStr);
521 ps.setLong(1, Long.parseLong(companyId));
522 answer = DAOUtil.loadCodeDescription(ps, rs);
523 }
524 catch(Exception ae) {
525 debug.println("Exception: " + ae.toString());
526 throw new DAOException
527 (ServicingExceptionMessage.PROBLEM_LOAD_PARAM_LEVEL2_VALUES
528 + ae.getMessage());
529 }
530 finally {
531 DAOUtil.closeResultSet(rs);
532 DAOUtil.closePreparedStatement(ps);
533 DAOUtil.closeConnection(dbConnection);
534 }
535 return answer;
536 }
537
538
539
553 public ArrayList applyItemsParamLevel2Points(ArrayList items)
554 throws DAOException {
555
556 debug.println("applying a set of changes to points of parameter level 2 of current company");
557 PreparedStatement ps1;
558 PreparedStatement ps2;
559 PreparedStatement ps3;
560 ps1 = ps2 = ps3 = null;
561 boolean listsBuilted = false;
562 boolean successTransaction = false;
563 CodeDescription item = null;
564 ArrayList insertList = new ArrayList();
565 ArrayList deleteList = new ArrayList();
566 ArrayList updateList = new ArrayList();
567 int listSize;
568
569 String insertStr = " INSERT INTO " + DatabaseNames.SV_LEVEL2_POINT
570 + " (code_l2_point, code_company, value)"
571 + " VALUES ("
572 + DatabaseNames.SEQ_SVLEVEL2_POINT + ".nextval,"
573 + " ?, ?)";
574
575 String deleteStr = " DELETE " + DatabaseNames.SV_LEVEL2_POINT
576 + " WHERE code_l2_point = ?";
577
578 String updateStr = " UPDATE " + DatabaseNames.SV_LEVEL2_POINT
579 + " SET value = ?"
580 + " WHERE code_l2_point = ?";
581
582 String problem = ServicingGlobals.STR_UNDEF;
583 CodeDescription[] paramLevel2ValuesList = null;
584 ArrayList answer = null;
585
586
587
588 try {
589 String[] code = (String[])items.get(0);
590 String[] value = (String[])items.get(1);
591 String[] status = (String[])items.get(2);
592 int numItems = code.length;
593
594 for(int i = 0; i < numItems; i++) {
595 item = new CodeDescription(Long.parseLong(code[i]), value[i]);
596 if(status[i].equals(ServicingGlobals.INSERT)) {
597 insertList.add(item);
598 }
599 else if(status[i].equals(ServicingGlobals.DELETE)) {
600 deleteList.add(item);
601 }
602 else if(status[i].equals(ServicingGlobals.UPDATE)) {
603 updateList.add(item);
604 }
605 else {
606 throw new DAOException
607 (ServicingExceptionMessage.ITEM_STATUS_INVALID);
608 }
609 }
610 listsBuilted = true;
611 }
612 catch(Exception e) {
613 debug.println("Exception building lists: " + e.toString());
614 StringWriter sw = new StringWriter();
615 PrintWriter pw = new PrintWriter(sw);
616 e.printStackTrace(pw);
617 problem =
618 ServicingExceptionMessage.PROBLEM_APPLYING_CHANGES_PARAM_LEVEL2_VALUES
619 + e.getMessage()
620 + "|" + sw.toString();
621 }
622
623
624 if(listsBuilted) {
625 String phase = "";
626 try {
627 dbConnection = DAOUtil.getDBConnection(datasource);
628 dbConnection.setAutoCommit(false);
629
630
631 phase = "insert";
632 ps1 = dbConnection.prepareStatement(insertStr);
633 listSize = insertList.size();
634 for(int i = 0; i < listSize; i++) {
635 item = (CodeDescription)(insertList.get(i));
636 ps1.setLong(1, Long.parseLong(companyId));
637 ps1.setString(2, item.getDescription());
638 ps1.executeUpdate();
639 }
640
641
642 phase = "delete";
643 ps2 = dbConnection.prepareStatement(deleteStr);
644 listSize = deleteList.size();
645 for(int i = 0; i < listSize; i++) {
646 item = (CodeDescription)(deleteList.get(i));
647 ps2.setLong(1, item.getCode());
648 int num = ps2.executeUpdate();
649 if(num == 0) {
650 throw new DAOException(
651 ServicingExceptionMessage.PROBLEM_APPLYING_DELETES1_PARAM_LEVEL2_VALUES);
652 }
653 }
654
655
656 phase = "update";
657 ps3 = dbConnection.prepareStatement(updateStr);
658 listSize = updateList.size();
659 for(int i = 0; i < listSize; i++) {
660 item = (CodeDescription)(updateList.get(i));
661 ps3.setString(1, item.getDescription());
662 ps3.setLong(2, item.getCode());
663 int num = ps3.executeUpdate();
664 if(num == 0) {
665 throw new DAOException(
666 ServicingExceptionMessage.PROBLEM_APPLYING_UPDATES1_PARAM_LEVEL2_VALUES);
667 }
668 }
669 successTransaction = true;
670 }
671 catch(Exception ae) {
672 debug.println("Exception applying item to DB in phase " + phase
673 + " : " + ae.toString());
674 StringWriter sw = new StringWriter();
675 PrintWriter pw = new PrintWriter(sw);
676 ae.printStackTrace(pw);
677 String subproblem = null;
678 if(phase.equals("insert")) {
679 subproblem = ServicingExceptionMessage.PROBLEM_APPLYING_INSERTS_PARAM_LEVEL2_VALUES;
680 }
681 else if(phase.equals("delete")) {
682 subproblem = ServicingExceptionMessage.PROBLEM_APPLYING_DELETES2_PARAM_LEVEL2_VALUES;
683 }
684 else {
685 subproblem = ServicingExceptionMessage.PROBLEM_APPLYING_UPDATES2_PARAM_LEVEL2_VALUES;
686 }
687 String value = (item != null) ? item.getDescription() : "";
688 problem = subproblem
689 + "current parameter of level 2 value : " + value
690 + " :" + ae.getMessage() + "|" + sw.toString();
691 }
692 finally {
693 try {
694 if(successTransaction) {
695 dbConnection.commit();
696 debug.println("commit done");
697 }
698 else {
699 dbConnection.rollback();
700 debug.println("rollback done");
701 }
702 }
703 catch(Exception e) {
704 debug.println("Exception resolving transaction: " + e.toString());
705 StringWriter sw = new StringWriter();
706 PrintWriter pw = new PrintWriter(sw);
707 e.printStackTrace(pw);
708 problem = ServicingExceptionMessage.PROBLEM_APPLYING_CHANGES_PARAM_LEVEL2_VALUES
709 + e.getMessage()
710 + "|" + sw.toString();
711 }
712 DAOUtil.closePreparedStatement(ps1);
713 DAOUtil.closePreparedStatement(ps2);
714 DAOUtil.closePreparedStatement(ps3);
715 DAOUtil.closeConnection(dbConnection);
716 }
717 }
718
719
720 try {
721 answer = new ArrayList(3);
722 ArrayList paramLevelsNameList = new ArrayList(2);
723 paramLevelsNameList = this.loadParamLevelsName();
724 paramLevel2ValuesList = this.listParamLevel2Points();
725 answer.add(problem);
726 answer.add(paramLevelsNameList);
727 answer.add(paramLevel2ValuesList);
728 }
729 catch(Exception ae) {
730 throw new DAOException(
731 ServicingExceptionMessage.PROBLEM_LOAD_PARAM_LEVEL2_VALUES
732 + ae.getMessage());
733 }
734 return answer;
735 }
736
737
738
739
740
749 public ArrayList loadParamSearchValues() throws DAOException {
750
751 debug.println("loading parameters search values");
752 PreparedStatement ps = null;
753 ResultSet rs = null;
754 String queryStr =
755 " SELECT cmp_sv_parm_search2, cmp_sv_parm_skip2,"
756 + " cmp_sv_parm_search3, cmp_sv_parm_skip3"
757 + " FROM " + DatabaseNames.COMPANIES
758 + " WHERE cmp_id = ? ";
759 ArrayList answer = new ArrayList(2);
760 ArrayList order2 = new ArrayList(2);
761 ArrayList order3 = new ArrayList(2);
762 String paramsearch2 = null;
763 String paramsearch3 = null;
764 String skip2 = null;
765 String skip3 = null;
766
767 try {
768 dbConnection = DAOUtil.getDBConnection(datasource);
769 ps = dbConnection.prepareStatement(queryStr);
770 ps.setLong(1, Long.parseLong(this.companyId));
771 ps.executeQuery();
772 rs = ps.getResultSet();
773 rs.next();
774 paramsearch2 = rs.getString(1);
775 skip2 = rs.getString(2);
776 paramsearch3 = rs.getString(3);
777 skip3 = rs.getString(4);
778 order2.add(paramsearch2);
779 order2.add(skip2);
780 order3.add(paramsearch3);
781 order3.add(skip3);
782 answer.add(order2);
783 answer.add(order3);
784 }
785 catch(Exception ae) {
786 debug.println("Exception: " + ae.toString());
787 throw new DAOException
788 (ServicingExceptionMessage.PROBLEM_LOAD_PARM_SEARCH_VALUES
789 + ae.getMessage());
790 }
791 finally {
792 DAOUtil.closeResultSet(rs);
793 DAOUtil.closePreparedStatement(ps);
794 DAOUtil.closeConnection(dbConnection);
795 }
796 return answer;
797 }
798
799
800
812 public ArrayList updateParamSearchValues(ArrayList items)
813 throws DAOException {
814
815 debug.println("applying a set of updates to params search values of current company");
816 PreparedStatement ps = null;
817 ArrayList list = new ArrayList(2);
818 ArrayList answer = new ArrayList(2);
819 boolean successTransaction = false;
820 String updateStr = " UPDATE " + DatabaseNames.COMPANIES + " SET"
821 + " cmp_last_changed_by = ?,"
822 + " cmp_last_changed_date = SYSDATE,"
823 + " cmp_sv_parm_search2 = ?,"
824 + " cmp_sv_parm_skip2 = ?,"
825 + " cmp_sv_parm_search3 = ?,"
826 + " cmp_sv_parm_skip3 = ?"
827 + " WHERE cmp_id = ?";
828 String problem = ServicingGlobals.STR_UNDEF;
829 try {
830 dbConnection = DAOUtil.getDBConnection(datasource);
831 dbConnection.setAutoCommit(false);
832 ps = dbConnection.prepareStatement(updateStr);
833 ps.setLong(1, this.userId.longValue());
834 ps.setString(2, ((String)((ArrayList)items.get(0)).get(0)));
835 ps.setString(3, ((String)((ArrayList)items.get(0)).get(1)));
836 ps.setString(4, ((String)((ArrayList)items.get(1)).get(0)));
837 ps.setString(5, ((String)((ArrayList)items.get(1)).get(1)));
838 ps.setLong(6, Long.parseLong(this.companyId));
839 int num = ps.executeUpdate();
840 if(num == 0) {
841 throw new DAOException
842 (ServicingExceptionMessage.PROBLEM_APPLYING_UPDATES_PARM_SEARCH_VALUES);
843 }
844 successTransaction = true;
845 }
846 catch(Exception ae) {
847 debug.println("Exception applying item to DB in update "
848 + " : " + ae.toString());
849 StringWriter sw = new StringWriter();
850 PrintWriter pw = new PrintWriter(sw);
851 ae.printStackTrace(pw);
852 String searchvalue = "Search2 and Search3";
853 problem = "Current parameters search values: " + searchvalue
854 + " :" + ae.getMessage() + "|" + sw.toString();
855 }
856 finally {
857 try {
858 if(successTransaction) {
859 dbConnection.commit();
860 debug.println("commit done");
861 }
862 else {
863 dbConnection.rollback();
864 debug.println("rollback done");
865 }
866 }
867 catch(Exception e) {
868 debug.println("Exception resolving transaction: " + e.toString());
869 StringWriter sw = new StringWriter();
870 PrintWriter pw = new PrintWriter(sw);
871 e.printStackTrace(pw);
872 problem = ServicingExceptionMessage.PROBLEM_APPLYING_CHANGES_PARM_SEARCH_VALUES
873 + e.getMessage()
874 + "|" + sw.toString();
875 }
876 DAOUtil.closePreparedStatement(ps);
877 DAOUtil.closeConnection(dbConnection);
878 }
879
880 try {
881 list = this.loadParamSearchValues();
882 answer.add(problem);
883 answer.add(list);
884 }
885 catch(Exception ae) {
886 throw new DAOException
887 (ServicingExceptionMessage.PROBLEM_LOAD_PARM_SEARCH_VALUES
888 + ae.getMessage());
889 }
890 return answer;
891 }
892
893
894
895
896
909 public ArrayList listParamRestrictions() throws DAOException {
910
911 debug.println("list Param Restrictions of the current company");
912 PreparedStatement ps = null;
913 ResultSet rs = null;
914 String queryStr = "SELECT PG.name, P.code_parameter, "
915 + "P.name, P.description, "
916 + "PR.level_1_2, PR.level_1_any, "
917 + "PR.level_any_2, PR.level_any_any "
918 + "FROM " + DatabaseNames.SV_PARAMETER_GROUP + " PG, "
919 + DatabaseNames.SV_PARAMETER + " P, "
920 + DatabaseNames.SV_PARM_RESTRICTION + " PR "
921 + "WHERE PG.code_parm_group = P.code_parm_group "
922 + "AND P.code_parameter = PR.code_parameter "
923 + "AND PR.code_company = ? "
924 + "ORDER BY P.code_parameter";
925 ArrayList answer = new ArrayList();
926
927 try {
928 dbConnection = DAOUtil.getDBConnection(datasource);
929 ps = dbConnection.prepareStatement(queryStr);
930 ps.setLong(1, Long.parseLong(companyId));
931 answer = this.auxListParamRestrictions(ps, rs);
932 }
933 catch(Exception ae) {
934 debug.println("Exception: " + ae.toString());
935 throw new DAOException
936 (ServicingExceptionMessage.PROBLEM_LOAD_PARAM_RESTRICTIONS
937 + ae.getMessage());
938 }
939 finally {
940 DAOUtil.closeResultSet(rs);
941 DAOUtil.closePreparedStatement(ps);
942 DAOUtil.closeConnection(dbConnection);
943 }
944 return answer;
945 }
946
947
948
960 public ArrayList updateParamRestrictions(Hashtable items)
961 throws DAOException {
962 debug.println("applying a set of updates to parameters restrictions of current company");
963 PreparedStatement ps = null;
964 ArrayList answer = new ArrayList();
965 boolean successTransaction = false;
966 int size = 0;
967 int i = 0;
968 String updateStr = " UPDATE " + DatabaseNames.SV_PARM_RESTRICTION + " SET"
969 + " level_1_2 = ?,"
970 + " level_1_any = ?,"
971 + " level_any_2 = ?,"
972 + " level_any_any = ?"
973 + " WHERE code_parameter = ?"
974 + " AND code_company = ?";
975
976 try {
977 dbConnection = DAOUtil.getDBConnection(datasource);
978 dbConnection.setAutoCommit(false);
979 ps = dbConnection.prepareStatement(updateStr);
980 for(Enumeration e = items.keys(); e.hasMoreElements(); ) {
981 String code = (String)e.nextElement();
982 ParmRestrictionUpdate parmRestrictionUpdate =
983 new ParmRestrictionUpdate("", "", "", "");
984 parmRestrictionUpdate = ((ParmRestrictionUpdate)items.get(code));
985 ps.setString(1, parmRestrictionUpdate.getUpdateLevel_1_2());
986 ps.setString(2, parmRestrictionUpdate.getUpdateLevel_1_any());
987 ps.setString(3, parmRestrictionUpdate.getUpdateLevel_any_2());
988 ps.setString(4, parmRestrictionUpdate.getUpdateLevel_any_any());
989 ps.setLong(5, Long.parseLong(code));
990 ps.setLong(6, Long.parseLong(this.companyId));
991 int num = ps.executeUpdate();
992 if(num == 0) {
993 throw new DAOException
994 (ServicingExceptionMessage.PROBLEM_APPLYING_UPDATES_PARAM_RESTRICTIONS);
995 }
996 }
997 successTransaction = true;
998 }
999 catch(Exception ae) {
1000 debug.println("Exception applying item to DB in update "
1001 + " : " + ae.toString());
1002 }
1003 finally {
1004 try {
1005 if(successTransaction) {
1006 dbConnection.commit();
1007 debug.println("commit done");
1008 }
1009 else {
1010 dbConnection.rollback();
1011 debug.println("rollback done");
1012 }
1013 }
1014 catch(Exception e) {
1015 debug.println("Exception resolving transaction: " + e.toString());
1016 }
1017 DAOUtil.closePreparedStatement(ps);
1018 DAOUtil.closeConnection(dbConnection);
1019 }
1020
1021 try {
1022 answer = listParamRestrictions();
1023 }
1024 catch(Exception ae) {
1025 throw new DAOException
1026 (ServicingExceptionMessage.PROBLEM_LOAD_PARAM_RESTRICTIONS
1027 + ae.getMessage());
1028 }
1029 return answer;
1030 }
1031
1032
1033
1034
1035
1049 public ParameterModel listParamValues(String codeParameter)
1050 throws DAOException {
1051
1052 debug.println("list Param value of the current company");
1053 PreparedStatement ps = null;
1054 ResultSet rs = null;
1055 ParameterModel parameterModel = null;
1056 Header header[] = new Header[4];
1057 ValueRow valueRow = null;
1058 int order[] = new int[4];
1059 ArrayList level1Point = new ArrayList();
1060 ArrayList level2Point = new ArrayList();
1061 ArrayList possibleValue = new ArrayList();
1062 Hashtable parmValue = null;
1063 Hashtable pointValue = new Hashtable();
1064 int i;
1065
1066
1067 String queryparameter = " SELECT code_parameter, name, type, description"
1068 + " FROM " + DatabaseNames.SV_PARAMETER
1069 + " WHERE code_parameter = ? ";
1070
1071 String querycompanies =
1072 " SELECT cmp_sv_parm_level1_name, cmp_sv_parm_level2_name,"
1073 + " cmp_sv_parm_search2, cmp_sv_parm_skip2,"
1074 + " cmp_sv_parm_search3, cmp_sv_parm_skip3"
1075 + " FROM " + DatabaseNames.COMPANIES
1076 + " WHERE cmp_id = ? ";
1077
1078 String queryrestriction =
1079 " SELECT level_1_2, level_1_any, level_any_2, level_any_any"
1080 + " FROM " + DatabaseNames.SV_PARM_RESTRICTION
1081 + " WHERE code_company = ?"
1082 + " AND code_parameter = ?";
1083
1084 String querypoint1 = " SELECT value"
1085 + " FROM " + DatabaseNames.SV_LEVEL1_POINT
1086 + " WHERE code_company = ?"
1087 + " AND code_l1_point > 0"
1088 + " ORDER BY value ";
1089
1090 String querypoint2 = " SELECT value"
1091 + " FROM " + DatabaseNames.SV_LEVEL2_POINT
1092 + " WHERE code_company = ?"
1093 + " AND code_l2_point > 0 "
1094 + " ORDER BY value ";
1095
1096 String queryvalue = " SELECT L1.value, L2.value, PV.value"
1097 + " FROM " + DatabaseNames.SV_PARAMETER_VALUE + " PV, "
1098 + DatabaseNames.SV_LEVEL1_POINT + " L1, "
1099 + DatabaseNames.SV_LEVEL2_POINT + " L2 "
1100 + " WHERE PV.code_company = ?"
1101 + " AND PV.code_parameter = ?"
1102 + " AND PV.code_company = L1.code_company"
1103 + " AND PV.code_company = L2.code_company"
1104 + " AND PV.code_l1_point = L1.code_l1_point"
1105 + " AND PV.code_l2_point = L2.code_l2_point"
1106 + " ORDER BY L1.value, L2.value ";
1107
1108 String querypossible = " SELECT possible_value"
1109 + " FROM " + DatabaseNames.SV_PARM_POSSIBLE_VALUE
1110 + " WHERE code_company = ?"
1111 + " AND code_parameter = ?"
1112 + " ORDER BY possible_value ";
1113
1114 try {
1115 dbConnection = DAOUtil.getDBConnection(datasource);
1116
1117 ps = dbConnection.prepareStatement(queryparameter);
1118 ps.setLong(1, Long.parseLong(codeParameter));
1119 ps.executeQuery();
1120 rs = ps.getResultSet();
1121 rs.next();
1122 String codeParam = rs.getString(1);
1123 String parameterName = rs.getString(2);
1124 String parameterType = rs.getString(3);
1125 String parameterDescription = rs.getString(4);
1126 DAOUtil.closePreparedStatement(ps);
1127
1128 if(parameterType.equals("enum")) {
1129 possibleValue.add(ServicingGlobals.UNDEFINED);
1130 }
1131 ps = dbConnection.prepareStatement(querypossible);
1132 ps.setLong(1, Long.parseLong(companyId));
1133 ps.setLong(2, Long.parseLong(codeParameter));
1134 ps.executeQuery();
1135 rs = ps.getResultSet();
1136 for(i = 0; rs.next(); i++) {
1137 possibleValue.add(rs.getString(1));
1138 }
1139 DAOUtil.closePreparedStatement(ps);
1140
1141 ps = dbConnection.prepareStatement(querycompanies);
1142 ps.setLong(1, Long.parseLong(companyId));
1143 ps.executeQuery();
1144 rs = ps.getResultSet();
1145 rs.next();
1146 String level1Name = rs.getString(1);
1147 String level2Name = rs.getString(2);
1148 String order2 = rs.getString(3);
1149 String skip2 = rs.getString(4);
1150 String order3 = rs.getString(5);
1151 String skip3 = rs.getString(6);
1152 DAOUtil.closePreparedStatement(ps);
1153
1154 ps = dbConnection.prepareStatement(queryrestriction);
1155 ps.setLong(1, Long.parseLong(companyId));
1156 ps.setLong(2, Long.parseLong(codeParameter));
1157 ps.executeQuery();
1158 rs = ps.getResultSet();
1159 rs.next();
1160 String level_1_2 = rs.getString(1);
1161 String level_1_any = rs.getString(2);
1162 String level_any_2 = rs.getString(3);
1163 String level_any_any = rs.getString(4);
1164 DAOUtil.closePreparedStatement(ps);
1165
1166 ps = dbConnection.prepareStatement(querypoint1);
1167 ps.setLong(1, Long.parseLong(companyId));
1168 ps.executeQuery();
1169 rs = ps.getResultSet();
1170 for(i = 0; rs.next(); i++) {
1171 level1Point.add(rs.getString(1));
1172 }
1173 DAOUtil.closePreparedStatement(ps);
1174
1175 ps = dbConnection.prepareStatement(querypoint2);
1176 ps.setLong(1, Long.parseLong(companyId));
1177 ps.executeQuery();
1178 rs = ps.getResultSet();
1179 for(i = 0; rs.next(); i++) {
1180 level2Point.add(rs.getString(1));
1181 }
1182 DAOUtil.closePreparedStatement(ps);
1183
1184 order = this.buildOrder(order2);
1185 header = this.buildHeader(order2, skip2, skip3, level_1_2, level_1_any,
1186 level_any_2, level_any_any);
1187
1188 ps = dbConnection.prepareStatement(queryvalue);
1189 ps.setLong(1, Long.parseLong(companyId));
1190 ps.setLong(2, Long.parseLong(codeParameter));
1191 ps.executeQuery();
1192 rs = ps.getResultSet();
1193 for(i = 0; rs.next(); i++) {
1194 String point1 = rs.getString(1);
1195 String point2 = rs.getString(2);
1196 String cellValue = rs.getString(3);
1197 pointValue.put(point1 + "|" + point2, cellValue);
1198 }
1199 DAOUtil.closePreparedStatement(ps);
1200
1201 parmValue = buildParmValue(level1Point, level2Point, pointValue);
1202 parameterModel = new ParameterModel
1203 (codeParam, parameterType, parameterName,
1204 parameterDescription, possibleValue, level1Name,
1205 level2Name, level1Point, level2Point, header,
1206 order, parmValue);
1207
1208 parameterModel = this.setColor(parameterModel);
1209 }
1210 catch(Exception ae) {
1211 debug.println("Exception: " + ae.toString());
1212 throw new DAOException
1213 (ServicingExceptionMessage.PROBLEM_LOAD_PARAMETER_VALUE
1214 + ae.getMessage());
1215 }
1216 finally {
1217 DAOUtil.closeResultSet(rs);
1218 DAOUtil.closePreparedStatement(ps);
1219 DAOUtil.closeConnection(dbConnection);
1220 }
1221 return parameterModel;
1222 }
1223
1224
1225
1233 public Hashtable loadLevel1Code() throws DAOException {
1234
1235 debug.println("load value and code of level 1 point from the current company");
1236 PreparedStatement ps = null;
1237 ResultSet rs = null;
1238 Hashtable level1Code = new Hashtable();
1239 String querypoint1 = " SELECT value, code_l1_point"
1240 + " FROM " + DatabaseNames.SV_LEVEL1_POINT
1241 + " WHERE code_company = ?"
1242 + " ORDER BY value ";
1243 int i;
1244 try {
1245 dbConnection = DAOUtil.getDBConnection(datasource);
1246 ps = dbConnection.prepareStatement(querypoint1);
1247 ps.setLong(1, Long.parseLong(companyId));
1248 ps.executeQuery();
1249 rs = ps.getResultSet();
1250 for(i = 0; rs.next(); i++) {
1251 level1Code.put(rs.getString(1), rs.getString(2));
1252 }
1253 DAOUtil.closePreparedStatement(ps);
1254 }
1255 catch(Exception ae) {
1256 debug.println(CommonUtil.stackTraceToString(ae));
1257 throw new DAOException
1258 (ServicingExceptionMessage.PROBLEM_LOAD_PARAM_LEVEL1_VALUES
1259 + ae.getMessage());
1260 }
1261 finally {
1262 DAOUtil.closeResultSet(rs);
1263 DAOUtil.closePreparedStatement(ps);
1264 DAOUtil.closeConnection(dbConnection);
1265 }
1266 return level1Code;
1267 }
1268
1269
1270
1278 public Hashtable loadLevel2Code() throws DAOException {
1279
1280 debug.println("load value and code of level 2 point from the current company");
1281 PreparedStatement ps = null;
1282 ResultSet rs = null;
1283 Hashtable level2Code = new Hashtable();
1284 String querypoint2 = " SELECT value, code_l2_point"
1285 + " FROM " + DatabaseNames.SV_LEVEL2_POINT
1286 + " WHERE code_company = ?"
1287 + " ORDER BY value ";
1288 int i;
1289 try {
1290 dbConnection = DAOUtil.getDBConnection(datasource);
1291 ps = dbConnection.prepareStatement(querypoint2);
1292 ps.setLong(1, Long.parseLong(companyId));
1293 ps.executeQuery();
1294 rs = ps.getResultSet();
1295 for(i = 0; rs.next(); i++) {
1296 level2Code.put(rs.getString(1), rs.getString(2));
1297 }
1298 DAOUtil.closePreparedStatement(ps);
1299 }
1300 catch(Exception ae) {
1301 debug.println(CommonUtil.stackTraceToString(ae));
1302 throw new DAOException
1303 (ServicingExceptionMessage.PROBLEM_LOAD_PARAM_LEVEL2_VALUES
1304 + ae.getMessage());
1305 }
1306 finally {
1307 DAOUtil.closeResultSet(rs);
1308 DAOUtil.closePreparedStatement(ps);
1309 DAOUtil.closeConnection(dbConnection);
1310 }
1311 return level2Code;
1312 }
1313
1314
1315
1327 public String updateParamValues(ParameterValue items, Hashtable level1code,
1328 Hashtable level2code) throws DAOException {
1329
1330 debug.println("applying a set of updates to parameters values of current company");
1331 PreparedStatement ps = null;
1332 ResultSet rs = null;
1333 Hashtable parmValue = null;
1334 String answer = items.getValueCodeParameter();
1335 String coordinates = null;
1336 String point1 = null;
1337 String point2 = null;
1338 String value = null;
1339 String codep1 = null;
1340 String codep2 = null;
1341 boolean successTransaction = false;
1342 int index = 0;
1343
1344 String updateStr = " UPDATE " + DatabaseNames.SV_PARAMETER_VALUE + " SET"
1345 + " value = ?"
1346 + " WHERE code_company = ?"
1347 + " AND code_parameter = ?"
1348 + " AND code_l1_point = ?"
1349 + " AND code_l2_point = ?";
1350
1351 try {
1352 parmValue = items.getValueParmValue();
1353 dbConnection = DAOUtil.getDBConnection(datasource);
1354 dbConnection.setAutoCommit(false);
1355 ps = dbConnection.prepareStatement(updateStr);
1356 ps.setLong(2, Long.parseLong(this.companyId));
1357 ps.setLong(3, Long.parseLong(answer));
1358 int j = 0;
1359 for(Enumeration e = parmValue.keys(); e.hasMoreElements(); ) {
1360 j++;
1361 coordinates = (String)e.nextElement();
1362 index = coordinates.indexOf("|");
1363 point1 = coordinates.substring(0, index);
1364 point2 = coordinates.substring(index + 1, coordinates.length());
1365 value = ((String)parmValue.get(coordinates));
1366 codep1 = ((String)level1code.get(point1));
1367 codep2 = ((String)level2code.get(point2));
1368 value = verifyValue(value, items.getValueParameterType());
1369 ps.setString(1, value);
1370 ps.setLong(4, Long.parseLong(codep1));
1371 ps.setLong(5, Long.parseLong(codep2));
1372 int num = ps.executeUpdate();
1373 if(num == 0) {
1374 throw new DAOException
1375 (ServicingExceptionMessage.PROBLEM_APPLYING_UPDATES_PARAMETER_VALUE);
1376 }
1377 }
1378 successTransaction = true;
1379 }
1380 catch(Exception ae) {
1381 debug.println("Exception applying item to DB in update "
1382 + " : " + ae.toString());
1383 }
1384 finally {
1385 try {
1386 if(successTransaction) {
1387 dbConnection.commit();
1388 debug.println("commit done");
1389 }
1390 else {
1391 dbConnection.rollback();
1392 debug.println("rollback done");
1393 }
1394 }
1395 catch(Exception e) {
1396 debug.println("Exception resolving transaction: " + e.toString());
1397 }
1398 DAOUtil.closeResultSet(rs);
1399 DAOUtil.closePreparedStatement(ps);
1400 DAOUtil.closeConnection(dbConnection);
1401 }
1402 return answer;
1403 }
1404
1405
1406
1418 public ParameterModel verifyParamValues(ParameterValue items)
1419 throws DAOException {
1420
1421 debug.println("verify Param value of the current company");
1422 PreparedStatement ps = null;
1423 ResultSet rs = null;
1424 ParameterModel parameterModel = null;
1425 Header header[] = new Header[4];
1426 ValueRow valueRow = null;
1427 int order[] = new int[4];
1428 ArrayList level1Point = new ArrayList();
1429 ArrayList level2Point = new ArrayList();
1430 ArrayList possibleValue = new ArrayList();
1431 Hashtable parmValue = new Hashtable();
1432 Hashtable pointValue = new Hashtable();
1433 String codeParameter = items.getValueCodeParameter();
1434 int i;
1435
1436
1437 String queryparameter = " SELECT code_parameter, name, type, description"
1438 + " FROM " + DatabaseNames.SV_PARAMETER
1439 + " WHERE code_parameter = ? ";
1440
1441 String querycompanies =
1442 " SELECT cmp_sv_parm_level1_name, cmp_sv_parm_level2_name,"
1443 + " cmp_sv_parm_search2, cmp_sv_parm_skip2,"
1444 + " cmp_sv_parm_search3, cmp_sv_parm_skip3"
1445 + " FROM " + DatabaseNames.COMPANIES
1446 + " WHERE cmp_id = ? ";
1447
1448 String queryrestriction =
1449 " SELECT level_1_2, level_1_any, level_any_2, level_any_any"
1450 + " FROM " + DatabaseNames.SV_PARM_RESTRICTION
1451 + " WHERE code_company = ?"
1452 + " AND code_parameter = ?";
1453
1454 String querypoint1 = " SELECT value"
1455 + " FROM " + DatabaseNames.SV_LEVEL1_POINT
1456 + " WHERE code_company = ?"
1457 + " AND code_l1_point > 0"
1458 + " ORDER BY value ";
1459
1460 String querypoint2 = " SELECT value"
1461 + " FROM " + DatabaseNames.SV_LEVEL2_POINT
1462 + " WHERE code_company = ?"
1463 + " AND code_l2_point > 0"
1464 + " ORDER BY value ";
1465
1466 String querypossible = " SELECT possible_value"
1467 + " FROM " + DatabaseNames.SV_PARM_POSSIBLE_VALUE
1468 + " WHERE code_company = ?"
1469 + " AND code_parameter = ?"
1470 + " ORDER BY possible_value ";
1471
1472 try {
1473 dbConnection = DAOUtil.getDBConnection(datasource);
1474
1475 ps = dbConnection.prepareStatement(queryparameter);
1476 ps.setLong(1, Long.parseLong(codeParameter));
1477 ps.executeQuery();
1478 rs = ps.getResultSet();
1479 rs.next();
1480 String codeParam = rs.getString(1);
1481 String parameterName = rs.getString(2);
1482 String parameterType = rs.getString(3);
1483 String parameterDescription = rs.getString(4);
1484 DAOUtil.closePreparedStatement(ps);
1485
1486 if(parameterType.equals("enum")) {
1487 possibleValue.add(ServicingGlobals.UNDEFINED);
1488 }
1489 ps = dbConnection.prepareStatement(querypossible);
1490 ps.setLong(1, Long.parseLong(companyId));
1491 ps.setLong(2, Long.parseLong(codeParameter));
1492 ps.executeQuery();
1493 rs = ps.getResultSet();
1494 for(i = 0; rs.next(); i++) {
1495 possibleValue.add(rs.getString(1));
1496 }
1497 DAOUtil.closePreparedStatement(ps);
1498
1499 ps = dbConnection.prepareStatement(querycompanies);
1500 ps.setLong(1, Long.parseLong(companyId));
1501 ps.executeQuery();
1502 rs = ps.getResultSet();
1503 rs.next();
1504 String level1Name = rs.getString(1);
1505 String level2Name = rs.getString(2);
1506 String order2 = rs.getString(3);
1507 String skip2 = rs.getString(4);
1508 String order3 = rs.getString(5);
1509 String skip3 = rs.getString(6);
1510 DAOUtil.closePreparedStatement(ps);
1511
1512 ps = dbConnection.prepareStatement(queryrestriction);
1513 ps.setLong(1, Long.parseLong(companyId));
1514 ps.setLong(2, Long.parseLong(codeParameter));
1515 ps.executeQuery();
1516 rs = ps.getResultSet();
1517 rs.next();
1518 String level_1_2 = rs.getString(1);
1519 String level_1_any = rs.getString(2);
1520 String level_any_2 = rs.getString(3);
1521 String level_any_any = rs.getString(4);
1522 DAOUtil.closePreparedStatement(ps);
1523
1524 ps = dbConnection.prepareStatement(querypoint1);
1525 ps.setLong(1, Long.parseLong(companyId));
1526 ps.executeQuery();
1527 rs = ps.getResultSet();
1528 for(i = 0; rs.next(); i++) {
1529 level1Point.add(rs.getString(1));
1530 }
1531 DAOUtil.closePreparedStatement(ps);
1532
1533 ps = dbConnection.prepareStatement(querypoint2);
1534 ps.setLong(1, Long.parseLong(companyId));
1535 ps.executeQuery();
1536 rs = ps.getResultSet();
1537 for(i = 0; rs.next(); i++) {
1538 level2Point.add(rs.getString(1));
1539 }
1540 DAOUtil.closePreparedStatement(ps);
1541
1542 order = this.buildOrder(order2);
1543 header = this.buildHeader(order2, skip2, skip3, level_1_2, level_1_any,
1544 level_any_2, level_any_any);
1545
1546 pointValue = items.getValueParmValue();
1547 parmValue = buildParmValue(level1Point, level2Point, pointValue);
1548 parameterModel = new ParameterModel
1549 (codeParam, parameterType, parameterName,
1550 parameterDescription, possibleValue, level1Name,
1551 level2Name, level1Point, level2Point, header,
1552 order, parmValue);
1553
1554 parameterModel = this.setColor(parameterModel);
1555 }
1556 catch(Exception ae) {
1557 debug.println("Exception: " + ae.toString());
1558 throw new DAOException
1559 (ServicingExceptionMessage.PROBLEM_LOAD_PARAMETER_VALUE
1560 + ae.getMessage());
1561 }
1562 finally {
1563 DAOUtil.closeResultSet(rs);
1564 DAOUtil.closePreparedStatement(ps);
1565 DAOUtil.closeConnection(dbConnection);
1566 }
1567 return parameterModel;
1568 }
1569
1570
1571
1580 private ArrayList auxListParamRestrictions(PreparedStatement ps, ResultSet rs)
1581 throws Exception {
1582 ArrayList restrictions = new ArrayList();
1583 ArrayList answer = new ArrayList();
1584 ParmRestriction parmRestriction = null;
1585 GroupParm groupParm = null;
1586 String oldgrname = "";
1587 String warning = null;
1588 int i;
1589 int j;
1590 int numgroup = -1;
1591
1592 ps.executeQuery();
1593 rs = ps.getResultSet();
1594 for(i = 0; rs.next(); i++) {
1595 String grname = rs.getString(1);
1596 String codeParameter = rs.getString(2);
1597 String pname = rs.getString(3);
1598 String description = rs.getString(4);
1599 String level_1_2 = rs.getString(5);
1600 String level_1_any = rs.getString(6);
1601 String level_any_2 = rs.getString(7);
1602 String level_any_any = rs.getString(8);
1603 warning = verifyWarning(level_1_2, level_1_any, level_any_2, level_any_any);
1604 if(!oldgrname.equals(grname)) {
1605 groupParm = new GroupParm(grname);
1606 answer.add(groupParm);
1607 numgroup++;
1608 groupParm = ((GroupParm)(answer.get(numgroup)));
1609 }
1610 parmRestriction = new ParmRestriction
1611 (codeParameter, pname, description, warning,
1612 level_1_2, level_1_any, level_any_2, level_any_any);
1613 (groupParm.getGroup()).add(parmRestriction);
1614 oldgrname = grname;
1615 }
1616 return answer;
1617 }
1618
1619
1620
1635 private String verifyWarning(String level_1_2, String level_1_any,
1636 String level_any_2, String level_any_any) throws Exception {
1637
1638 String warning = ServicingGlobals.WARNING_0;
1639
1640
1641 if(ServicingGlobals.EXCLUDED.equals(level_1_2) &&
1642 ServicingGlobals.EXCLUDED.equals(level_1_any) &&
1643 ServicingGlobals.EXCLUDED.equals(level_any_2) &&
1644 ServicingGlobals.EXCLUDED.equals(level_any_any)) {
1645 warning = ServicingGlobals.WARNING_2;
1646 }
1647
1648
1649 if((ServicingGlobals.FORCED.equals(level_1_2))
1650 && (ServicingGlobals.FORCED.equals(level_1_any) ||
1651 ServicingGlobals.FORCED.equals(level_any_2) ||
1652 ServicingGlobals.FORCED.equals(level_any_any))) {
1653 warning = ServicingGlobals.WARNING_1;
1654 }
1655 else if((ServicingGlobals.FORCED.equals(level_1_any))
1656 && (ServicingGlobals.FORCED.equals(level_any_2) ||
1657 ServicingGlobals.FORCED.equals(level_any_any))) {
1658 warning = ServicingGlobals.WARNING_1;
1659 }
1660 else if((ServicingGlobals.FORCED.equals(level_any_2)) &&
1661 (ServicingGlobals.FORCED.equals(level_any_any))) {
1662 warning = ServicingGlobals.WARNING_1;
1663 }
1664 return warning;
1665 }
1666
1667
1668
1669
1677 private int[] buildOrder(String order2) throws Exception {
1678
1679 int order[] = {0, 0, 0, 3};
1680
1681 if(order2.equals("1,*")) {
1682 order[1] = 1;
1683 order[2] = 2;
1684 }
1685 else if(order2.equals("*,2")) {
1686 order[1] = 2;
1687 order[2] = 1;
1688 }
1689 return order;
1690 }
1691
1692
1693
1707 private Header[] buildHeader(String order2, String skip2, String skip3,
1708 String level_1_2, String level_1_any,
1709 String level_any_2, String level_any_any)
1710 throws Exception {
1711
1712 Header[] header = new Header[4];
1713 String color = ServicingGlobals.STR_UNDEF;
1714 String skipped = " ";
1715 String skipped1Any = " ";
1716 String skippedAny2 = " ";
1717
1718 if(order2.equals("1,*")) {
1719 if(skip2.equals("yes")) {
1720 skipped1Any = "[SKIP]";
1721 }
1722 if(skip3.equals("yes")) {
1723 skippedAny2 = "[SKIP]";
1724 }
1725 }
1726 else {
1727 if(skip3.equals("yes")) {
1728 skipped1Any = "[SKIP]";
1729 }
1730 if(skip2.equals("yes")) {
1731 skippedAny2 = "[SKIP]";
1732 }
1733 }
1734 header[0] = new Header(color, ServicingGlobals.LEVEL_1_2, skipped, level_1_2);
1735 header[1] = new Header(color, ServicingGlobals.LEVEL_1_ANY, skipped1Any, level_1_any);
1736 header[2] = new Header(color, ServicingGlobals.LEVEL_ANY_2, skippedAny2, level_any_2);
1737 header[3] = new Header(color, ServicingGlobals.LEVEL_ANY_ANY, skipped, level_any_any);
1738 return header;
1739 }
1740
1741
1742
1754 public Hashtable buildParmValue(ArrayList level1Point, ArrayList level2Point,
1755 Hashtable pointValue) throws Exception {
1756
1757 ValueRow valueRow = null;
1758 Hashtable parmValue = new Hashtable();
1759 ParmCell[] parmCell = null;
1760 ArrayList setValues = null;
1761 String firstColumnColor = ServicingGlobals.STR_UNDEF;
1762 String cellColor = ServicingGlobals.STR_UNDEF;
1763 String smallCellColor = ServicingGlobals.STR_UNDEF;
1764 String pointl1 = null;
1765 String pointl2 = null;
1766 String cellValue = null;
1767 int i;
1768 int j = 0;
1769
1770 for(i = 0; i < level1Point.size(); i++) {
1771 for(j = 0; j < level2Point.size(); j++) {
1772 parmCell = new ParmCell[4];
1773 pointl1 = ((String)level1Point.get(i));
1774 pointl2 = ((String)level2Point.get(j));
1775
1776 cellValue = (String)pointValue.get(pointl1 + "|" + pointl2);
1777 parmCell[0] =
1778 new ParmCell(cellColor, cellValue, setValues, smallCellColor);
1779
1780 cellValue = (String)pointValue.get(pointl1 + "|" + "*");
1781 parmCell[1] =
1782 new ParmCell(cellColor, cellValue, setValues, smallCellColor);
1783
1784 cellValue = (String)pointValue.get("*" + "|" + pointl2);
1785 parmCell[2] =
1786 new ParmCell(cellColor, cellValue, setValues, smallCellColor);
1787
1788 cellValue = (String)pointValue.get("*|*");
1789 parmCell[3] =
1790 new ParmCell(cellColor, cellValue, setValues, smallCellColor);
1791
1792
1793 valueRow = new ValueRow(firstColumnColor, parmCell);
1794 parmValue.put(pointl1 + "|" + pointl2, valueRow);
1795 }
1796 }
1797 return parmValue;
1798 }
1799
1800
1801
1813 private ParameterModel setColor(ParameterModel parameterModel)
1814 throws Exception {
1815
1816 Header header[] = new Header[4];
1817 Hashtable parmValue = new Hashtable();
1818
1819 debug.println("Set colors in the parameter ");
1820
1821 header = verifyHeaderColor(parameterModel.getHeader());
1822 parameterModel.setHeader(header);
1823
1824 parmValue = verifyColor(parameterModel.getParmValue(), header,
1825 parameterModel.getOrder());
1826 parameterModel.setParmValue(parmValue);
1827 return parameterModel;
1828 }
1829
1830
1831
1844 private Header[] verifyHeaderColor(Header header[]) throws Exception {
1845
1846 String color = null;
1847 int i;
1848
1849 for(i = 0; i < header.length; i++) {
1850 if(header[i].getHeaderNote().equals(ServicingGlobals.FORCED)) {
1851 color = ServicingGlobals.WARNING_0;
1852 }
1853 else if(header[i].getHeaderNote().equals(ServicingGlobals.ALLOWED)) {
1854 color = ServicingGlobals.WARNING_1;
1855 }
1856 else if(header[i].getHeaderNote().equals(ServicingGlobals.EXCLUDED)) {
1857 color = ServicingGlobals.WARNING_2;
1858 }
1859 header[i].setHeaderColor(color);
1860 }
1861 return header;
1862 }
1863
1864
1865
1878 private Hashtable verifyColor(Hashtable parmValue, Header header[],
1879 int order[]) throws Exception {
1880
1881 ValueRow valueRow = null;
1882 String coordinates = null;
1883
1884 for(Enumeration e = parmValue.keys(); e.hasMoreElements(); ) {
1885 coordinates = (String)e.nextElement();
1886 valueRow = ((ValueRow)parmValue.get(coordinates));
1887 valueRow = verifyCellsColor(order, valueRow, header);
1888 parmValue.put(coordinates, valueRow);
1889 }
1890 return parmValue;
1891 }
1892
1893
1894
1905 private ValueRow verifyCellsColor(int order[], ValueRow valueRow,
1906 Header header[]) throws Exception {
1907
1908 ParmCell[] parmCell = new ParmCell[4];
1909 String firstColumnColor = ServicingGlobals.WARNING_0;
1910 String cellColor = null;
1911 String smallCellColor = null;
1912 String cellValue = null;
1913 String restriction = null;
1914 String skip = null;
1915 boolean first = false;
1916 int i;
1917 int found = 0;
1918
1919 parmCell = valueRow.getValueRowParmCell();
1920 for(i = 0; i < parmCell.length; i++) {
1921 cellColor = ServicingGlobals.WARNING_0;
1922 smallCellColor = ServicingGlobals.WARNING_0;
1923 cellValue = parmCell[order[i]].getParmCellCellValue();
1924 skip = header[order[i]].getHeaderSkipped();
1925 restriction = header[order[i]].getHeaderNote();
1926
1927 if(!cellValue.equals(ServicingGlobals.UNDEFINED) && !first) {
1928 cellColor = ServicingGlobals.WARNING_1;
1929 first = true;
1930 }
1931 else if(!cellValue.equals(ServicingGlobals.UNDEFINED) && first) {
1932 cellColor = ServicingGlobals.WARNING_2;
1933 }
1934
1935 if(!cellValue.equals(ServicingGlobals.UNDEFINED) &&
1936 restriction.equals(ServicingGlobals.EXCLUDED)) {
1937 smallCellColor = ServicingGlobals.WARNING_1;
1938 }
1939 else if(cellValue.equals(ServicingGlobals.UNDEFINED) &&
1940 restriction.equals(ServicingGlobals.FORCED)) {
1941 smallCellColor = ServicingGlobals.WARNING_2;
1942 }
1943
1944 if((!cellValue.equals(ServicingGlobals.UNDEFINED) &&
1945 !skip.equals(ServicingGlobals.SKIP))) {
1946 found++;
1947 }
1948 if((i == parmCell.length - 1) && (found == 0)) {
1949 firstColumnColor = ServicingGlobals.WARNING_1;
1950 }
1951
1952 parmCell[order[i]].setParmCellCellColor(cellColor);
1953 parmCell[order[i]].setParmCellSmallCellColor(smallCellColor);
1954 }
1955 valueRow.setValueRowFirstColumnColor(firstColumnColor);
1956 valueRow.setValueRowParmCell(parmCell);
1957 return valueRow;
1958 }
1959
1960
1961
1972 private String verifyValue(String value, String type) throws Exception {
1973
1974
1975 if(type.equals(ServicingGlobals.NUMERIC_INT) &&
1976 !this.regularExpressionNumInt.match(value)) {
1977 value = ServicingGlobals.UNDEFINED;
1978 }
1979
1980 else if(type.equals(ServicingGlobals.NUMERIC_PCT) &&
1981 !this.regularExpressionNumP.match(value)) {
1982 value = ServicingGlobals.UNDEFINED;
1983 }
1984
1985 else if(type.equals(ServicingGlobals.NUMERIC_CUR) &&
1986 !this.regularExpressionNumC.match(value)) {
1987 value = ServicingGlobals.UNDEFINED;
1988 }
1989
1990 else if(type.equals(ServicingGlobals.SEQUENCE_INT) &&
1991 !this.regularExpressionSeqInt.match(value)) {
1992 value = ServicingGlobals.UNDEFINED;
1993 }
1994 return value;
1995 }
1996 }
1997