1 package com.instantbank.collections.basicInfo.ejb;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.IOException;
5 import java.io.PrintWriter;
6 import java.io.StringWriter;
7 import java.sql.Connection;
8 import java.sql.PreparedStatement;
9 import java.sql.ResultSet;
10 import java.sql.SQLException;
11 import javax.ejb.CreateException;
12 import javax.ejb.EJBContext;
13 import javax.ejb.SessionBean;
14 import javax.ejb.SessionContext;
15 import oracle.xml.parser.v2.DOMParser;
16 import oracle.xml.parser.v2.XMLDocument;
17 import oracle.xml.parser.v2.XMLParseException;
18 import oracle.xml.parser.v2.XSLException;
19 import org.w3c.dom.NodeList;
20 import org.xml.sax.SAXException;
21 import com.instantbank.collections.util.InstantbankException;
22 import com.instantbank.collections.util.ServiceLocator;
23 import com.instantbank.collections.util.UniqueIDGenerator;
24 import com.instantbank.collections.util.XMLDataAccess;
25
26 public class BasicInfoServicesBean
27 implements SessionBean {
28 private String[] allowMultiple;
29 private long changedBy;
30 private String[] code;
31 private String[] comments;
32 private EJBContext context;
33 private String[] id;
34 private String[] name;
35 private NodeList nlAllowMultiple;
36 private NodeList nlCode;
37 private NodeList nlComment;
38 private NodeList nlid;
39 private int nlLength;
40 private NodeList nlName;
41 private NodeList nlNum;
42 private NodeList nlorgCode;
43 private NodeList nlStatus;
44 private NodeList nlsttCoun;
45 private NodeList nlScreenType;
46 private String[] orgcode;
47 private String prData;
48 private String[] screenType;
49 private String[] status;
50 private String[] sttCoun;
51 private XMLDocument xmlDoc;
52
53
54
55 public BasicInfoServicesBean() { }
56
57
58
59 private void createAccommodationStatus(String statusCode, String statusName) throws InstantbankException {
60 Connection con = null;
61 PreparedStatement ps = null;
62 ResultSet result = null;
63 String sql;
64
65 try {
66 con = ServiceLocator.instance().getConnection();
67 sql = "insert into ";
68 sql += "accommodation_statuses(";
69 sql += "ast_code, ";
70 sql += "ast_description, ";
71 sql += "ast_last_changed_by, ";
72 sql += "ast_last_changed_date) ";
73 sql += "values (?,?,?,sysdate)";
74 ps = con.prepareStatement(sql);
75 ps.setString(1, statusCode);
76 ps.setString(2, statusName);
77 ps.setLong(3, changedBy);
78 int n = ps.executeUpdate();
79 if(n != 1) {
80 throw new InstantbankException("111001", "Failed to update accommodation status to the database");
81 }
82 }
83 catch(Exception e) {
84 this.context.setRollbackOnly();
85 throw new InstantbankException(e, "111002", "Failed to add accommodation status to the database");
86 }
87 finally {
88 try {
89 if(ps != null) {
90 ps.close();
91 }
92 if(con != null) {
93 con.close();
94 }
95 }
96 catch(SQLException se) {
97 se.printStackTrace();
98 }
99 }
100 }
101
102
103 private void createAddressType(String typeCode, String typeName) throws InstantbankException {
104 Connection con = null;
105 PreparedStatement ps = null;
106 ResultSet result = null;
107 String sql;
108
109 try {
110 con = ServiceLocator.instance().getConnection();
111 sql = "insert into ";
112 sql += "address_types( ";
113 sql += "adt_code, ";
114 sql += "adt_description, ";
115 sql += "adt_last_changed_by, ";
116 sql += "adt_last_changed_date ) ";
117 sql += "values (?,?,?,sysdate)";
118 ps = con.prepareStatement(sql);
119 ps.setString(1, typeCode);
120 ps.setString(2, typeName);
121 ps.setLong(3, changedBy);
122 int n = ps.executeUpdate();
123 if(n != 1) {
124 throw new InstantbankException("111003", "Failed to update address type to the database");
125 }
126 }
127 catch(Exception e) {
128 this.context.setRollbackOnly();
129 throw new InstantbankException(e, "111004", "Failed to add address type to the database");
130 }
131 finally {
132 try {
133 if(ps != null) {
134 ps.close();
135 }
136 if(con != null) {
137 con.close();
138 }
139 }
140 catch(SQLException se) {
141 se.printStackTrace();
142 }
143 }
144 }
145
146
147 private void createCountry(String counCode, String counName, String counComment) throws InstantbankException {
148 Connection con = null;
149 PreparedStatement ps = null;
150 ResultSet result = null;
151 String sql;
152
153 try {
154 con = ServiceLocator.instance().getConnection();
155 sql = "insert into ";
156 sql += "countries( ";
157 sql += "coun_id, ";
158 sql += "coun_name, ";
159 sql += "coun_comment, ";
160 sql += "coun_last_changed_by, ";
161 sql += "coun_last_changed_date ) ";
162 sql += "values (?,?,?,?,sysdate)";
163 ps = con.prepareStatement(sql);
164 ps.setString(1, counCode);
165 ps.setString(2, counName);
166 ps.setString(3, counComment);
167 ps.setLong(4, changedBy);
168 int n = ps.executeUpdate();
169 if(n != 1) {
170 throw new InstantbankException("111005", "Failed to update country to the database");
171 }
172 }
173 catch(Exception e) {
174 this.context.setRollbackOnly();
175 throw new InstantbankException(e, "111006", "Failed to add country to the database");
176 }
177 finally {
178 try {
179 if(ps != null) {
180 ps.close();
181 }
182 if(con != null) {
183 con.close();
184 }
185 }
186 catch(SQLException se) {
187 se.printStackTrace();
188 }
189 }
190 }
191
192
193 private void createCustomerRole(String roleCode, String roleName, String roleScreenType, String roleAllowMultiple) throws InstantbankException {
194 Connection con = null;
195 PreparedStatement ps = null;
196 ResultSet result = null;
197 String sql;
198
199 try {
200 con = ServiceLocator.instance().getConnection();
201 sql = "insert into ";
202 sql += "customer_roles( ";
203 sql += "csr_code, ";
204 sql += "csr_description, ";
205 sql += "csr_screen_type, ";
206 sql += "csr_allow_multiple, ";
207 sql += "csr_last_changed_by, ";
208 sql += "csr_last_changed_date ) ";
209 sql += "values (?,?,?,?,?,sysdate)";
210 ps = con.prepareStatement(sql);
211 ps.setString(1, roleCode);
212 ps.setString(2, roleName);
213 ps.setString(3, roleScreenType);
214 ps.setString(4, roleAllowMultiple);
215 ps.setLong(5, changedBy);
216 int n = ps.executeUpdate();
217 if(n != 1) {
218 throw new InstantbankException("111007", "Failed to update customer role to the database");
219 }
220 }
221 catch(Exception e) {
222 this.context.setRollbackOnly();
223 throw new InstantbankException(e, "111008", "Failed to add customer role to the database");
224 }
225 finally {
226 try {
227 if(ps != null) {
228 ps.close();
229 }
230 if(con != null) {
231 con.close();
232 }
233 }
234 catch(SQLException se) {
235 se.printStackTrace();
236 }
237 }
238 }
239
240
241 private void createPhoneType(String typeCode, String typeName) throws InstantbankException {
242 Connection con = null;
243 PreparedStatement ps = null;
244 ResultSet result = null;
245 String sql;
246 try {
247 con = ServiceLocator.instance().getConnection();
248 sql = "insert into ";
249 sql += "phone_types( ";
250 sql += "pht_code, ";
251 sql += "pht_description, ";
252 sql += "pht_last_changed_by, ";
253 sql += "pht_last_changed_date ) ";
254 sql += "values (?,?,?,sysdate)";
255
256 ps = con.prepareStatement(sql);
257 ps.setString(1, typeCode);
258 ps.setString(2, typeName);
259 ps.setLong(3, changedBy);
260 int n = ps.executeUpdate();
261 if(n != 1) {
262 throw new InstantbankException("111009", "Failed to update phone type to the database");
263 }
264 }
265 catch(Exception e) {
266 this.context.setRollbackOnly();
267 throw new InstantbankException(e, "111010", "Failed to add phone type to the database");
268 }
269 finally {
270 try {
271 if(ps != null) {
272 ps.close();
273 }
274 if(con != null) {
275 con.close();
276 }
277 }
278 catch(SQLException se) {
279 se.printStackTrace();
280 }
281 }
282 }
283
284
285 private void createState(long sttId, String sttCode, String sttName, String sttCountry) throws InstantbankException {
286 Connection con = null;
287 PreparedStatement ps = null;
288 ResultSet result = null;
289 String sql;
290
291 try {
292 con = ServiceLocator.instance().getConnection();
293 sql = "insert into ";
294 sql += "states( ";
295 sql += "stt_id, ";
296 sql += "stt_code, ";
297 sql += "stt_name, ";
298 sql += "stt_last_changed_date, ";
299 sql += "stt_last_changed_by, ";
300 sql += "stt_coun_id ) ";
301 sql += "values (?,?,?,sysdate,?,?)";
302 ps = con.prepareStatement(sql);
303 ps.setLong(1, sttId);
304 ps.setString(2, sttCode);
305 ps.setString(3, sttName);
306 ps.setLong(4, changedBy);
307 ps.setString(5, sttCountry);
308 int n = ps.executeUpdate();
309 if(n != 1) {
310 throw new InstantbankException("111011", "Failed to update state to the database");
311 }
312 }
313 catch(Exception e) {
314 this.context.setRollbackOnly();
315 throw new InstantbankException(e, "111012", "Failed to add state to the database");
316 }
317 finally {
318 try {
319 if(ps != null) {
320 ps.close();
321 }
322 if(con != null) {
323 con.close();
324 }
325 }
326 catch(SQLException se) {
327 se.printStackTrace();
328 }
329 }
330 }
331
332
333 private void deleteAccommodationStatus(String statusCode) throws InstantbankException {
334 Connection con = null;
335 PreparedStatement ps = null;
336 ResultSet result = null;
337 String sql;
338
339 try {
340 con = ServiceLocator.instance().getConnection();
341 sql = "delete ";
342 sql += "accommodation_statuses ";
343 sql += "where ";
344 sql += "ast_code = ?";
345 ps = con.prepareStatement(sql);
346 ps.setString(1, statusCode);
347 int n = ps.executeUpdate();
348 if(n != 1) {
349 throw new InstantbankException("111013", "Failed to update accommodation status in the database");
350 }
351 }
352 catch(Exception e) {
353 this.context.setRollbackOnly();
354 throw new InstantbankException(e, "111014", "Failed to delete accommodation status in the database");
355 }
356 finally {
357 try {
358 if(ps != null) {
359 ps.close();
360 }
361 if(con != null) {
362 con.close();
363 }
364 }
365 catch(SQLException se) {
366 se.printStackTrace();
367 }
368 }
369 }
370
371
372 private void deleteAddressType(String typeCode) throws InstantbankException {
373 Connection con = null;
374 PreparedStatement ps = null;
375 ResultSet result = null;
376 String sql;
377
378 try {
379 con = ServiceLocator.instance().getConnection();
380 sql = "delete ";
381 sql += "address_types ";
382 sql += "where ";
383 sql += "adt_code = ?";
384 ps = con.prepareStatement(sql);
385 ps.setString(1, typeCode);
386 int n = ps.executeUpdate();
387 if(n != 1) {
388 throw new InstantbankException("111015", "Failed to update address type in the database");
389 }
390 }
391 catch(Exception e) {
392 this.context.setRollbackOnly();
393 throw new InstantbankException(e, "111016", "Failed to delete address type in the database");
394 }
395 finally {
396 try {
397 if(ps != null) {
398 ps.close();
399 }
400 if(con != null) {
401 con.close();
402 }
403 }
404 catch(SQLException se) {
405 se.printStackTrace();
406 }
407 }
408 }
409
410
411 private void deleteCountry(String counCode) throws InstantbankException {
412 Connection con = null;
413 PreparedStatement ps = null;
414 ResultSet result = null;
415 String sql;
416
417 try {
418 con = ServiceLocator.instance().getConnection();
419 sql = "delete ";
420 sql += "countries ";
421 sql += "where ";
422 sql += "coun_id = ?";
423 ps = con.prepareStatement(sql);
424 ps.setString(1, counCode);
425 int n = ps.executeUpdate();
426 if(n != 1) {
427 throw new InstantbankException("111017", "Failed to update country in the database");
428 }
429 }
430 catch(Exception e) {
431 this.context.setRollbackOnly();
432 throw new InstantbankException(e, "111018", "Failed to delete country in the database");
433 }
434 finally {
435 try {
436 if(ps != null) {
437 ps.close();
438 }
439 if(con != null) {
440 con.close();
441 }
442 }
443 catch(SQLException se) {
444 se.printStackTrace();
445 }
446 }
447 }
448
449
450 private void deleteCustomerRole(String roleCode) throws InstantbankException {
451 Connection con = null;
452 PreparedStatement ps = null;
453 ResultSet result = null;
454 String sql;
455
456 try {
457 con = ServiceLocator.instance().getConnection();
458 sql = "delete ";
459 sql += "customer_roles ";
460 sql += "where ";
461 sql += "csr_code = ?";
462 ps = con.prepareStatement(sql);
463 ps.setString(1, roleCode);
464 int n = ps.executeUpdate();
465 if(n != 1) {
466 throw new InstantbankException("111019", "Failed to update customer role in the database");
467 }
468 }
469 catch(Exception e) {
470 this.context.setRollbackOnly();
471 throw new InstantbankException(e, "111020", "Failed to delete customer role in the database");
472 }
473 finally {
474 try {
475 if(ps != null) {
476 ps.close();
477 }
478 if(con != null) {
479 con.close();
480 }
481 }
482 catch(SQLException se) {
483 se.printStackTrace();
484 }
485 }
486 }
487
488
489 private void deletePhoneType(String typeCode) throws InstantbankException {
490 Connection con = null;
491 PreparedStatement ps = null;
492 ResultSet result = null;
493 String sql;
494
495 try {
496 con = ServiceLocator.instance().getConnection();
497 sql = "delete ";
498 sql += "phone_types ";
499 sql += "where ";
500 sql += "pht_code = ?";
501 ps = con.prepareStatement(sql);
502 ps.setString(1, typeCode);
503 int n = ps.executeUpdate();
504 if(n != 1) {
505 throw new InstantbankException("111021", "Failed to update phone type to the database");
506 }
507 }
508 catch(Exception e) {
509 this.context.setRollbackOnly();
510 throw new InstantbankException(e, "111022", "Failed to delete phone type to the database");
511 }
512 finally {
513 try {
514 if(ps != null) {
515 ps.close();
516 }
517 if(con != null) {
518 con.close();
519 }
520 }
521 catch(SQLException se) {
522 se.printStackTrace();
523 }
524 }
525 }
526
527
528 private void deleteState(String sttId) throws InstantbankException {
529 Connection con = null;
530 PreparedStatement ps = null;
531 ResultSet result = null;
532 String sql;
533
534 try {
535 con = ServiceLocator.instance().getConnection();
536 sql = "delete ";
537 sql += "states ";
538 sql += "where ";
539 sql += "stt_id = ?";
540 ps = con.prepareStatement(sql);
541 ps.setString(1, sttId);
542 int n = ps.executeUpdate();
543 if(n != 1) {
544 throw new InstantbankException("111023", "Failed to update state to the database");
545 }
546 }
547 catch(Exception e) {
548 this.context.setRollbackOnly();
549 throw new InstantbankException(e, "111024", "Failed to delete state to the database");
550 }
551 finally {
552 try {
553 if(ps != null) {
554 ps.close();
555 }
556 if(con != null) {
557 con.close();
558 }
559 }
560 catch(SQLException se) {
561 se.printStackTrace();
562 }
563 }
564 }
565
566
567 public String getAccommodationStatuses() throws InstantbankException {
568 String accommodationStatusesXmlString = "";
569 String query;
570 StringWriter sw = new StringWriter();
571 XMLDataAccess xda = new XMLDataAccess("database.properties");
572 XMLDocument xmlDoc;
573
574 try {
575 PrintWriter pw = new PrintWriter(sw);
576 query = " SELECT ";
577 query += "ast_code Code, ";
578 query += "ast_description Description ";
579 query += "FROM ";
580 query += "accommodation_statuses ";
581 query += "order by ";
582 query += "upper(ast_description)";
583 xda.connect();
584 xmlDoc = xda.makeXMLSelect(query, "AccommodationStatusesList", "AccommodationStatus");
585 xmlDoc.print(pw);
586 accommodationStatusesXmlString = sw.toString();
587 return accommodationStatusesXmlString;
588 }
589 catch(Exception e) {
590 this.context.setRollbackOnly();
591 throw new InstantbankException(e, "111025", "Failed to read accommodation statuses from the database");
592 }
593 finally {
594 try {
595 if(xda != null) {
596 xda.disconnect();
597 }
598 }
599 catch(Exception e) {
600 }
601 }
602 }
603
604
605 public String getAddressTypes() throws InstantbankException {
606 String addressTypesXmlString = "";
607 String query;
608 StringWriter sw = new StringWriter();
609 XMLDataAccess xda = new XMLDataAccess("database.properties");
610 XMLDocument xmlDoc;
611
612 try {
613 PrintWriter pw = new PrintWriter(sw);
614 query = " SELECT ";
615 query += "adt_code code,";
616 query += "adt_description description ";
617 query += "FROM ";
618 query += "address_types ";
619 query += "order by ";
620 query += "upper(adt_description)";
621 xda.connect();
622 xmlDoc = xda.makeXMLSelect(query, "AddressTypesList", "AddressType");
623 xmlDoc.print(pw);
624 addressTypesXmlString = sw.toString();
625 return addressTypesXmlString;
626 }
627 catch(Exception e) {
628 this.context.setRollbackOnly();
629 throw new InstantbankException(e, "111026", "Failed to read address types from the database");
630 }
631 finally {
632 try {
633 if(xda != null) {
634 xda.disconnect();
635 }
636 }
637 catch(Exception e) {
638 }
639 }
640 }
641
642
643 public String getCountries() throws InstantbankException {
644 String xml;
645 String sql;
646 XMLDataAccess da = null;
647 XMLDocument doc;
648
649 try {
650 da = new XMLDataAccess("");
651 sql = "SELECT ";
652 sql += "coun_id Code,";
653 sql += "coun_name Name,";
654 sql += "nvl(coun_comment, '_') Comments ";
655 sql += "FROM ";
656 sql += "countries ";
657 sql += "ORDER BY ";
658 sql += "upper(COUN_NAME)";
659 da.connect();
660 doc = da.makeXMLSelect(sql, "CountriesList", "Country");
661 StringWriter sw = new StringWriter();
662 PrintWriter pw = new PrintWriter(sw);
663 doc.print(pw);
664 return sw.toString();
665 }
666 catch(Exception e) {
667 this.context.setRollbackOnly();
668 throw new InstantbankException(e, "111027", "Failed to read countries from the database");
669 }
670 finally {
671 try {
672 if(da != null) {
673 da.disconnect();
674 }
675 }
676 catch(Exception e) {
677 }
678 }
679 }
680
681
682 public String getCountryName(String counId) throws InstantbankException {
683 Connection con = null;
684 String counName = null;
685 PreparedStatement ps = null;
686 ResultSet result = null;
687 String sql;
688
689 try {
690 con = ServiceLocator.instance().getConnection();
691 sql = "SELECT ";
692 sql += "coun_name ";
693 sql += "FROM ";
694 sql += "countries ";
695 sql += "WHERE ";
696 sql += "coun_id = ? ";
697 sql += "ORDER BY ";
698 sql += "upper(coun_name)";
699 ps = con.prepareStatement(sql);
700 ps.setString(1, counId);
701 result = ps.executeQuery();
702 if(result.next()) {
703 counName = result.getString("coun_name");
704 }
705 return counName;
706 }
707 catch(Exception e) {
708 this.context.setRollbackOnly();
709 throw new InstantbankException(e, "111028", "Failed to read the country name from the database");
710 }
711 finally {
712 try {
713 if(result != null) {
714 result.close();
715 }
716 if(ps != null) {
717 ps.close();
718 }
719 if(con != null) {
720 con.close();
721 }
722 }
723 catch(SQLException se) {
724 se.printStackTrace();
725 }
726 }
727 }
728
729
730 public String getCustomerRoles() throws InstantbankException {
731 String customersRolesXmlString = "";
732 String query;
733 StringWriter sw = new StringWriter();
734 XMLDataAccess xda = new XMLDataAccess("database.properties");
735 XMLDocument xmlDoc;
736
737 try {
738 PrintWriter pw = new PrintWriter(sw);
739 xda.connect();
740 query = " SELECT ";
741 query += "csr_code Code, ";
742 query += "csr_description Description, ";
743 query += "csr_screen_type ScreenType, ";
744 query += "csr_allow_multiple AllowMultiple ";
745 query += "FROM ";
746 query += "customer_roles ";
747 query += "order by ";
748 query += "upper(csr_description)";
749 xmlDoc = xda.makeXMLSelect(query, "CustomerRolesList", "CustomerRole");
750 xmlDoc.print(pw);
751 customersRolesXmlString = sw.toString();
752 return customersRolesXmlString;
753 }
754 catch(Exception e) {
755 this.context.setRollbackOnly();
756 throw new InstantbankException("111029", "Failed to read customer roles from the database");
757 }
758 finally {
759 try {
760 if(xda != null) {
761 xda.disconnect();
762 }
763 }
764 catch(Exception e) {
765 }
766 }
767 }
768
769
770 public String getGenerationCodes() throws InstantbankException {
771 String generationCodesXmlString = "";
772 String query;
773 StringWriter sw = new StringWriter();
774 XMLDataAccess xda = new XMLDataAccess("database.properties");
775 XMLDocument xmlDoc;
776
777 try {
778 PrintWriter pw = new PrintWriter(sw);
779 xda.connect();
780 query = "SELECT ";
781 query += "gen_code code ";
782 query += "FROM ";
783 query += "generation_codes";
784 xmlDoc = xda.makeXMLSelect(query, "GenerationCodesList", "GenerationCode");
785 xmlDoc.print(pw);
786 generationCodesXmlString = sw.toString();
787 return generationCodesXmlString;
788 }
789 catch(Exception e) {
790 this.context.setRollbackOnly();
791 throw new InstantbankException("111030", "Failed to read generation codes from the database");
792 }
793 finally {
794 try {
795 if(xda != null) {
796 xda.disconnect();
797 }
798 }
799 catch(Exception e) {
800 }
801 }
802 }
803
804
805 public String getPhoneTypes() throws InstantbankException {
806 String phoneTypesXmlString = "";
807 String query;
808 StringWriter sw = new StringWriter();
809 XMLDataAccess xda = new XMLDataAccess("database.properties");
810 XMLDocument xmlDoc;
811
812 try {
813 PrintWriter pw = new PrintWriter(sw);
814 xda.connect();
815 query = "SELECT ";
816 query += "pht_code code, ";
817 query += "pht_description description ";
818 query += "FROM ";
819 query += "phone_types ";
820 query += "order by ";
821 query += "upper(pht_description)";
822 xmlDoc = xda.makeXMLSelect(query, "PhoneTypesList", "PhoneType");
823 xmlDoc.print(pw);
824 phoneTypesXmlString = sw.toString();
825 return phoneTypesXmlString;
826 }
827 catch(Exception e) {
828 this.context.setRollbackOnly();
829 throw new InstantbankException("111031", "Failed to read phone types from the database");
830 }
831 finally {
832 try {
833 if(xda != null) {
834 xda.disconnect();
835 }
836 }
837 catch(Exception e) {
838 }
839 }
840 }
841
842
843 public String getStates(String stateCounId) throws InstantbankException {
844 String xml;
845 String sql;
846 XMLDataAccess da = null;
847 XMLDocument doc;
848
849 try {
850 da = new XMLDataAccess("");
851 sql = "SELECT ";
852 sql += "stt_id id, ";
853 sql += "stt_code Code, ";
854 sql += "stt_name Name, ";
855 sql += "stt_coun_id ";
856 sql += "Country ";
857 sql += "FROM ";
858 sql += "states ";
859 sql += "WHERE ";
860 sql += "stt_coun_id = '" + stateCounId + "' ";
861 sql += "order by ";
862 sql += "upper(stt_name)";
863 da.connect();
864 doc = da.makeXMLSelect(sql, "StatesList", "State");
865 StringWriter sw = new StringWriter();
866 PrintWriter pw = new PrintWriter(sw);
867 doc.print(pw);
868
869 return sw.toString();
870 }
871 catch(Exception e) {
872 this.context.setRollbackOnly();
873 throw new InstantbankException("111032", "Failed to read states from the database");
874 }
875 finally {
876 try {
877 if(da != null) {
878 da.disconnect();
879 }
880 }
881 catch(Exception e) {
882 }
883 }
884 }
885
886
887 private void modifyAccommodationStatus(String orgCode, String statusCode, String statusName) throws InstantbankException {
888 Connection con = null;
889 PreparedStatement ps = null;
890 ResultSet result = null;
891 String sql;
892 try {
893 con = ServiceLocator.instance().getConnection();
894 sql = "update ";
895 sql += "accommodation_statuses ";
896 sql += "set ";
897 sql += "ast_code = ?, ";
898 sql += "ast_description = ?, ";
899 sql += "ast_last_changed_by = ?, ";
900 sql += "ast_last_changed_date = sysdate ";
901 sql += "where ";
902 sql += "ast_code = ?";
903 ps = con.prepareStatement(sql);
904 ps.setString(1, statusCode);
905 ps.setString(2, statusName);
906 ps.setLong(3, changedBy);
907 ps.setString(4, orgCode);
908 int n = ps.executeUpdate();
909 if(n != 1) {
910 throw new InstantbankException("111033", "Failed to update accommodation statuses to the database");
911 }
912 }
913 catch(Exception e) {
914 this.context.setRollbackOnly();
915 throw new InstantbankException(e, "111034", "Failed to modify accommodation statuses to the database");
916 }
917 finally {
918 try {
919 if(ps != null) {
920 ps.close();
921 }
922 if(con != null) {
923 con.close();
924 }
925 }
926 catch(SQLException se) {
927 se.printStackTrace();
928 }
929 }
930 }
931
932
933 private void modifyAddTypes(String orgCode, String typeCode, String typeName) throws InstantbankException {
934 Connection con = null;
935 PreparedStatement ps = null;
936 ResultSet result = null;
937 String sql;
938
939 try {
940 con = ServiceLocator.instance().getConnection();
941 sql = "update ";
942 sql += "address_types ";
943 sql += "set adt_code = ?, ";
944 sql += "adt_description = ?, ";
945 sql += "adt_last_changed_by = ?, ";
946 sql += "adt_last_changed_date = sysdate ";
947 sql += "where ";
948 sql += "adt_code = ?";
949 ps = con.prepareStatement(sql);
950 ps.setString(1, typeCode);
951 ps.setString(2, typeName);
952 ps.setLong(3, changedBy);
953 ps.setString(4, orgCode);
954 int n = ps.executeUpdate();
955 if(n != 1) {
956 throw new InstantbankException("111035", "Failed to update address type to the database");
957 }
958 }
959 catch(Exception e) {
960 this.context.setRollbackOnly();
961 throw new InstantbankException(e, "111036", "Failed to modify address type to the database");
962 }
963 finally {
964 try {
965 if(ps != null) {
966 ps.close();
967 }
968 if(con != null) {
969 con.close();
970 }
971 }
972 catch(SQLException se) {
973 se.printStackTrace();
974 }
975 }
976 }
977
978
979 private void modifyCountry(String orgCode, String counCode, String counName, String counComment) throws InstantbankException {
980 Connection con = null;
981 PreparedStatement ps = null;
982 String sql = "";
983 ResultSet result = null;
984
985 try {
986 con = ServiceLocator.instance().getConnection();
987 sql = "update ";
988 sql += "countries ";
989 sql += "set coun_id = ?, ";
990 sql += "coun_name = ?, ";
991 sql += "coun_comment = ?, ";
992 sql += "coun_last_changed_by = ?, ";
993 sql += "coun_last_changed_date = sysdate ";
994 sql += "where ";
995 sql += "coun_id = ?";
996 ps = con.prepareStatement(sql);
997 ps.setString(1, counCode);
998 ps.setString(2, counName);
999 ps.setString(3, counComment);
1000 ps.setLong(4, changedBy);
1001 ps.setString(5, orgCode);
1002 int n = ps.executeUpdate();
1003 if(n != 1) {
1004 throw new InstantbankException("111037", "Failed to update country to the database");
1005 }
1006 }
1007 catch(Exception e) {
1008 this.context.setRollbackOnly();
1009 InstantbankException ie = new InstantbankException(e, "111038", "Failed to modify country to the database");
1010 ie.setTechnicalMessage("sql=" + sql);
1011 throw ie;
1012 }
1013 finally {
1014 try {
1015 if(ps != null) {
1016 ps.close();
1017 }
1018 if(con != null) {
1019 con.close();
1020 }
1021 }
1022 catch(SQLException se) {
1023 se.printStackTrace();
1024 }
1025 }
1026 }
1027
1028
1029 private void modifyCustomerRole(String orgCode, String roleCode, String roleName, String roleScreenType, String roleAllowMultiple) throws InstantbankException {
1030 Connection con = null;
1031 PreparedStatement ps = null;
1032 ResultSet result = null;
1033 String sql;
1034
1035 try {
1036 con = ServiceLocator.instance().getConnection();
1037 sql = "update ";
1038 sql += "customer_roles ";
1039 sql += "set csr_code = ?, ";
1040 sql += "csr_description = ?, ";
1041 sql += "csr_screen_type = ?, ";
1042 sql += "csr_allow_multiple = ?, ";
1043 sql += "csr_last_changed_by = ?, ";
1044 sql += "csr_last_changed_date = sysdate ";
1045 sql += "where ";
1046 sql += "csr_code = ?";
1047 ps = con.prepareStatement(sql);
1048 ps.setString(1, roleCode);
1049 ps.setString(2, roleName);
1050 ps.setString(3, roleScreenType);
1051 ps.setString(4, roleAllowMultiple);
1052 ps.setLong(5, changedBy);
1053 ps.setString(6, orgCode);
1054 int n = ps.executeUpdate();
1055 if(n != 1) {
1056 throw new InstantbankException("111039", "Failed to update customer role to the database");
1057 }
1058 }
1059 catch(Exception e) {
1060 this.context.setRollbackOnly();
1061 throw new InstantbankException(e, "111040", "Failed to modify customer role to the database");
1062 }
1063 finally {
1064 try {
1065 if(ps != null) {
1066 ps.close();
1067 }
1068 if(con != null) {
1069 con.close();
1070 }
1071 }
1072 catch(SQLException se) {
1073 se.printStackTrace();
1074 }
1075 }
1076 }
1077
1078
1079 private void modifyPhoneType(String orgCode, String typeCode, String typeName) throws InstantbankException {
1080 Connection con = null;
1081 PreparedStatement ps = null;
1082 ResultSet result = null;
1083 String sql;
1084 try {
1085 con = ServiceLocator.instance().getConnection();
1086 sql = "update ";
1087 sql += "phone_types ";
1088 sql += "set pht_code = ?, ";
1089 sql += "pht_description = ?, ";
1090 sql += "pht_last_changed_by = ?, ";
1091 sql += "pht_last_changed_date = sysdate ";
1092 sql += "where ";
1093 sql += "pht_code = ?";
1094 ps = con.prepareStatement(sql);
1095 ps.setString(1, typeCode);
1096 ps.setString(2, typeName);
1097 ps.setLong(3, changedBy);
1098 ps.setString(4, orgCode);
1099 int n = ps.executeUpdate();
1100 if(n != 1) {
1101 throw new InstantbankException("111041", "Failed to update phone type to the database");
1102 }
1103 }
1104 catch(Exception e) {
1105 this.context.setRollbackOnly();
1106 throw new InstantbankException(e, "111042", "Failed to modify phone type to the database");
1107 }
1108 finally {
1109 try {
1110 if(ps != null) {
1111 ps.close();
1112 }
1113 if(con != null) {
1114 con.close();
1115 }
1116 }
1117 catch(SQLException se) {
1118 se.printStackTrace();
1119 }
1120 }
1121 }
1122
1123
1124 private void modifyState(String sttId, String sttCode, String sttName, String sttCountry) throws InstantbankException {
1125 Connection con = null;
1126 PreparedStatement ps = null;
1127 ResultSet result = null;
1128 String sql;
1129
1130 try {
1131 con = ServiceLocator.instance().getConnection();
1132 sql = "update ";
1133 sql += "states ";
1134 sql += "set stt_code = ?, ";
1135 sql += "stt_name = ?, ";
1136 sql += "stt_coun_id = ?, ";
1137 sql += "stt_last_changed_by = ?, ";
1138 sql += "stt_last_changed_date = sysdate ";
1139 sql += "where ";
1140 sql += "stt_id = ?";
1141 ps = con.prepareStatement(sql);
1142 ps.setString(1, sttCode);
1143 ps.setString(2, sttName);
1144 ps.setString(3, sttCountry);
1145 ps.setLong(4, changedBy);
1146 ps.setString(5, sttId);
1147 int n = ps.executeUpdate();
1148 if(n != 1) {
1149 throw new InstantbankException("111043", "Failed to update state to the database");
1150 }
1151 }
1152 catch(Exception e) {
1153 this.context.setRollbackOnly();
1154 throw new InstantbankException(e, "111044", "Failed to modify state to the database");
1155 }
1156 finally {
1157 try {
1158 if(ps != null) {
1159 ps.close();
1160 }
1161 if(con != null) {
1162 con.close();
1163 }
1164 }
1165 catch(SQLException se) {
1166 se.printStackTrace();
1167 }
1168 }
1169 }
1170
1171
1172 private void parseAccommodationStatuses(String data) throws InstantbankException {
1173 try {
1174 parseInfo(data);
1175 nlorgCode = xmlDoc.selectNodes("/AccStatusList/AccStatus/orgcode/text()");
1176 nlCode = xmlDoc.selectNodes("/AccStatusList/AccStatus/code/text()");
1177 nlName = xmlDoc.selectNodes("/AccStatusList/AccStatus/description/text()");
1178 nlStatus = xmlDoc.selectNodes("/AccStatusList/AccStatus/status/text()");
1179 nlLength = nlCode.getLength();
1180 orgcode = new String[nlLength];
1181 code = new String[nlLength];
1182 name = new String[nlLength];
1183 status = new String[nlLength];
1184 for(int i = 0; i < nlLength; i++) {
1185 orgcode[i] = nlorgCode.item(i).getNodeValue();
1186 code[i] = nlCode.item(i).getNodeValue();
1187 name[i] = nlName.item(i).getNodeValue();
1188 status[i] = nlStatus.item(i).getNodeValue();
1189 }
1190 }
1191 catch(Exception e) {
1192 this.context.setRollbackOnly();
1193 throw new InstantbankException(e, "111045", "Failed to parse accommodation Statuses");
1194 }
1195 }
1196
1197
1198 private void parseAddressTypes(String data) throws InstantbankException {
1199 try {
1200 parseInfo(data);
1201 nlorgCode = xmlDoc.selectNodes("/AddTypesList/AddType/orgcode/text()");
1202 nlCode = xmlDoc.selectNodes("/AddTypesList/AddType/code/text()");
1203 nlName = xmlDoc.selectNodes("/AddTypesList/AddType/description/text()");
1204 nlStatus = xmlDoc.selectNodes("/AddTypesList/AddType/status/text()");
1205 nlLength = nlCode.getLength();
1206 orgcode = new String[nlLength];
1207 code = new String[nlLength];
1208 name = new String[nlLength];
1209 status = new String[nlLength];
1210 for(int i = 0; i < nlLength; i++) {
1211 orgcode[i] = nlorgCode.item(i).getNodeValue();
1212 code[i] = nlCode.item(i).getNodeValue();
1213 name[i] = nlName.item(i).getNodeValue();
1214 status[i] = nlStatus.item(i).getNodeValue();
1215 }
1216 }
1217 catch(Exception e) {
1218 this.context.setRollbackOnly();
1219 throw new InstantbankException(e, "111046", "Failed to parse address types");
1220 }
1221 }
1222
1223
1224 private void parseCountries(String data) throws InstantbankException {
1225 try {
1226 parseInfo(data);
1227 nlorgCode = xmlDoc.selectNodes("/CountriesList/Country/orgcode/text()");
1228 nlCode = xmlDoc.selectNodes("/CountriesList/Country/code/text()");
1229 nlName = xmlDoc.selectNodes("/CountriesList/Country/name/text()");
1230 nlComment = xmlDoc.selectNodes("/CountriesList/Country/comment/text()");
1231 nlStatus = xmlDoc.selectNodes("/CountriesList/Country/status/text()");
1232 nlLength = nlCode.getLength();
1233 orgcode = new String[nlLength];
1234 code = new String[nlLength];
1235 name = new String[nlLength];
1236 comments = new String[nlLength];
1237 status = new String[nlLength];
1238 for(int i = 0; i < nlLength; i++) {
1239 orgcode[i] = nlorgCode.item(i).getNodeValue();
1240 code[i] = nlCode.item(i).getNodeValue();
1241 name[i] = nlName.item(i).getNodeValue();
1242 if(nlComment.item(i).getNodeValue().equals("_")) {
1243 comments[i] = "";
1244 }
1245 else {
1246 comments[i] = nlComment.item(i).getNodeValue();
1247 }
1248 status[i] = nlStatus.item(i).getNodeValue();
1249 }
1250 }
1251 catch(Exception e) {
1252 this.context.setRollbackOnly();
1253 throw new InstantbankException(e, "111047", "Failed to parse Countries");
1254 }
1255 }
1256
1257
1258 private void parseCustomerRoles(String data) throws InstantbankException {
1259 try {
1260 parseInfo(data);
1261 nlorgCode = xmlDoc.selectNodes("/CustomerRolesList/CustomerRole/orgcode/text()");
1262 nlCode = xmlDoc.selectNodes("/CustomerRolesList/CustomerRole/code/text()");
1263 nlName = xmlDoc.selectNodes("/CustomerRolesList/CustomerRole/description/text()");
1264 nlScreenType = xmlDoc.selectNodes("/CustomerRolesList/CustomerRole/screentype/text()");
1265 nlAllowMultiple = xmlDoc.selectNodes("/CustomerRolesList/CustomerRole/allowmultiple/text()");
1266 nlStatus = xmlDoc.selectNodes("/CustomerRolesList/CustomerRole/status/text()");
1267 nlLength = nlCode.getLength();
1268 orgcode = new String[nlLength];
1269 code = new String[nlLength];
1270 name = new String[nlLength];
1271 screenType = new String[nlLength];
1272 allowMultiple = new String[nlLength];
1273 status = new String[nlLength];
1274 for(int i = 0; i < nlLength; i++) {
1275 orgcode[i] = nlorgCode.item(i).getNodeValue();
1276 code[i] = nlCode.item(i).getNodeValue();
1277 name[i] = nlName.item(i).getNodeValue();
1278 screenType[i] = nlScreenType.item(i).getNodeValue();
1279 allowMultiple[i] = nlAllowMultiple.item(i).getNodeValue();
1280 status[i] = nlStatus.item(i).getNodeValue();
1281 }
1282 }
1283 catch(Exception e) {
1284 this.context.setRollbackOnly();
1285 throw new InstantbankException(e, "111048", "Failed to parse customer roles");
1286 }
1287 }
1288
1289
1290 private void parseInfo(String data) throws XMLParseException, XSLException, SAXException, IOException {
1291 DOMParser docParser = new DOMParser();
1292 ByteArrayInputStream stream;
1293
1294 xmlDoc = null;
1295 prData = data;
1296 stream = new ByteArrayInputStream(data.getBytes());
1297 docParser.setValidationMode(false);
1298 docParser.parse(stream);
1299 xmlDoc = docParser.getDocument();
1300 }
1301
1302
1303 private void parsePhoneTypes(String data) throws InstantbankException {
1304 try {
1305 parseInfo(data);
1306 nlorgCode = xmlDoc.selectNodes("/PhoneTypesList/PhoneType/orgcode/text()");
1307 nlCode = xmlDoc.selectNodes("/PhoneTypesList/PhoneType/code/text()");
1308 nlName = xmlDoc.selectNodes("/PhoneTypesList/PhoneType/description/text()");
1309 nlStatus = xmlDoc.selectNodes("/PhoneTypesList/PhoneType/status/text()");
1310 nlLength = nlCode.getLength();
1311 orgcode = new String[nlLength];
1312 code = new String[nlLength];
1313 name = new String[nlLength];
1314 status = new String[nlLength];
1315 for(int i = 0; i < nlLength; i++) {
1316 orgcode[i] = nlorgCode.item(i).getNodeValue();
1317 code[i] = nlCode.item(i).getNodeValue();
1318 name[i] = nlName.item(i).getNodeValue();
1319 status[i] = nlStatus.item(i).getNodeValue();
1320 }
1321 }
1322 catch(Exception e) {
1323 this.context.setRollbackOnly();
1324 throw new InstantbankException(e, "111049", "Failed to parse phone types");
1325 }
1326 }
1327
1328
1329 private void parseStates(String data) throws InstantbankException {
1330 try {
1331 parseInfo(data);
1332 nlid = xmlDoc.selectNodes("/StatesList/State/id/text()");
1333 nlCode = xmlDoc.selectNodes("/StatesList/State/code/text()");
1334 nlName = xmlDoc.selectNodes("/StatesList/State/name/text()");
1335 nlsttCoun = xmlDoc.selectNodes("/StatesList/State/sttCoun/text()");
1336 nlStatus = xmlDoc.selectNodes("/StatesList/State/status/text()");
1337 nlLength = nlCode.getLength();
1338 id = new String[nlLength];
1339 code = new String[nlLength];
1340 name = new String[nlLength];
1341 sttCoun = new String[nlLength];
1342 status = new String[nlLength];
1343 for(int i = 0; i < nlLength; i++) {
1344 id[i] = nlid.item(i).getNodeValue();
1345 code[i] = nlCode.item(i).getNodeValue();
1346 name[i] = nlName.item(i).getNodeValue();
1347 sttCoun[i] = nlsttCoun.item(i).getNodeValue();
1348 status[i] = nlStatus.item(i).getNodeValue();
1349 }
1350 }
1351 catch(Exception e) {
1352 this.context.setRollbackOnly();
1353 throw new InstantbankException(e, "111050", "Failed to parse states");
1354 }
1355 }
1356
1357
1358 public void saveAccommodationStatuses(Long userId, String xmlData) throws InstantbankException {
1359 parseAccommodationStatuses(xmlData);
1360 changedBy = userId.longValue();
1361 for(int i = 0; i < nlLength; i++) {
1362 if(status[i].equals("A")) {
1363 createAccommodationStatus(code[i], name[i]);
1364 }
1365 if(status[i].equals("D")) {
1366 deleteAccommodationStatus(orgcode[i]);
1367 }
1368 if(status[i].equals("M")) {
1369 modifyAccommodationStatus(orgcode[i], code[i], name[i]);
1370 }
1371 }
1372 }
1373
1374
1375 public void saveAddressTypes(Long userId, String xmlData) throws InstantbankException {
1376 parseAddressTypes(xmlData);
1377 changedBy = userId.longValue();
1378 for(int i = 0; i < nlLength; i++) {
1379 if(status[i].equals("A")) {
1380 createAddressType(code[i], name[i]);
1381 }
1382 if(status[i].equals("D")) {
1383 deleteAddressType(orgcode[i]);
1384 }
1385 if(status[i].equals("M")) {
1386 modifyAddTypes(orgcode[i], code[i], name[i]);
1387 }
1388 }
1389 }
1390
1391
1392 public void saveCountries(Long userId, String xmlData) throws InstantbankException {
1393 parseCountries(xmlData);
1394 changedBy = userId.longValue();
1395 for(int i = 0; i < nlLength; i++) {
1396 if(status[i].equals("A")) {
1397 createCountry(code[i], name[i], comments[i]);
1398 }
1399 if(status[i].equals("D")) {
1400 deleteCountry(orgcode[i]);
1401 }
1402 if(status[i].equals("M")) {
1403 modifyCountry(orgcode[i], code[i], name[i], comments[i]);
1404 }
1405 }
1406 }
1407
1408
1409 public void saveCustomerRoles(Long userId, String xmlData) throws InstantbankException {
1410 parseCustomerRoles(xmlData);
1411 changedBy = userId.longValue();
1412 for(int i = 0; i < nlLength; i++) {
1413 if(status[i].equals("A")) {
1414 createCustomerRole(code[i], name[i], screenType[i], allowMultiple[i]);
1415 }
1416 if(status[i].equals("D")) {
1417 deleteCustomerRole(orgcode[i]);
1418 }
1419 if(status[i].equals("M")) {
1420 modifyCustomerRole(orgcode[i], code[i], name[i], screenType[i], allowMultiple[i]);
1421 }
1422 }
1423 }
1424
1425
1426 public void savePhoneTypes(Long userId, String xmlData) throws InstantbankException {
1427 parsePhoneTypes(xmlData);
1428 changedBy = userId.longValue();
1429 for(int i = 0; i < nlLength; i++) {
1430 if(status[i].equals("A")) {
1431 createPhoneType(code[i], name[i]);
1432 }
1433 if(status[i].equals("D")) {
1434 deletePhoneType(orgcode[i]);
1435 }
1436 if(status[i].equals("M")) {
1437 modifyPhoneType(orgcode[i], code[i], name[i]);
1438 }
1439 }
1440 }
1441
1442
1443 public void saveStates(Long userId, String xmlData) throws InstantbankException {
1444 long id_state;
1445
1446 try {
1447 parseStates(xmlData);
1448 changedBy = userId.longValue();
1449 for(int i = 0; i < nlLength; i++) {
1450 if(status[i].equals("A")) {
1451 id_state = UniqueIDGenerator.instance().getNextId();
1452 createState(id_state, code[i], name[i], sttCoun[i]);
1453 }
1454 if(status[i].equals("D")) {
1455 deleteState(id[i]);
1456 }
1457 if(status[i].equals("M")) {
1458 modifyState(id[i], code[i], name[i], sttCoun[i]);
1459 }
1460 }
1461 }
1462 catch(Exception e) {
1463 this.context.setRollbackOnly();
1464 throw new InstantbankException(e, "111051", "Failed to save states");
1465 }
1466 }
1467
1468
1469
1470 public void ejbCreate() throws CreateException { }
1471
1472
1473 public void ejbActivate() { }
1474
1475
1476 public void ejbPassivate() { }
1477
1478
1479 public void ejbRemove() { }
1480
1481
1482 public void setSessionContext(SessionContext ctx) {
1483 this.context = ctx;
1484 }
1485 }
1486
1487