dahomee_69

GOSIBatchUtilities

Dec 21st, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 307.96 KB | None | 0 0
  1.  
  2. package gosi.common.batch.util;
  3.  
  4. import java.util.Hashtable;
  5. import java.io.FileInputStream;
  6. import javax.naming.Context;
  7. import javax.naming.directory.DirContext;
  8. import javax.naming.directory.BasicAttribute;
  9. import javax.naming.directory.ModificationItem;
  10. import javax.naming.ldap.InitialLdapContext;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13. import java.sql.Connection;
  14. import java.sql.ResultSet;
  15. import java.sql.PreparedStatement;
  16. import java.sql.DriverManager;
  17. import java.math.BigDecimal;
  18. import gosi.common.batch.util.beans.BatchError;
  19. import gosi.common.batch.util.beans.BatchMaster;
  20. import gosi.common.batch.util.beans.BatchParam;
  21. import gosi.common.batch.util.beans.BatchRestart;
  22. import gosi.common.batch.util.beans.BatchOnlineDependentTaskBean;
  23. import javax.crypto.*;
  24. import java.io.*;
  25. import javax.crypto.spec.*;
  26. import java.lang.reflect.Constructor;
  27. import java.util.HashMap;
  28. import java.io.File;
  29. import java.io.FileReader;
  30. import java.io.BufferedReader;
  31. import java.util.StringTokenizer;
  32. import java.util.GregorianCalendar;
  33. import java.util.Calendar;
  34. import java.io.IOException;
  35. import java.sql.Timestamp;
  36. import java.sql.SQLException;
  37. import java.sql.Types;
  38. import gosi.common.batch.util.GOSIBatchException;
  39. import gosi.common.batch.workflow.beans.BatchRangeCheckBean;
  40. import gosi.common.batch.workflow.beans.BatchTransactionEntityMap;
  41. import gosi.common.batch.workflow.beans.BatchWorkflowParamBean;
  42. import gosi.common.batch.util.beans.DomainBean;
  43. import javax.naming.directory.Attributes;
  44. import javax.naming.directory.BasicAttributes;
  45. import javax.naming.directory.Attribute;
  46. import javax.naming.directory.InitialDirContext;
  47. import java.util.Properties;
  48. import java.beans.XMLEncoder;
  49. import java.beans.XMLDecoder;
  50. import gosi.common.batch.util.beans.CorporateContactBean;
  51. import gosi.common.batch.util.beans.IndividualContactBean;
  52. import gosi.common.batch.util.beans.FieldOfficeVillageMapListBean;
  53.  
  54. /*Start : To place a request for a batch through a batch*/
  55. import gosi.common.batch.util.beans.BatchRequestBean;
  56. import gosi.common.batch.util.beans.BatchParametersBean;
  57. /*End : To place a request for a batch through a batch*/
  58.  
  59. // Import for checking the workflowtxn duplicate records.
  60. import gosi.common.batch.workflow.history.beans.WorkflowTxn;
  61.  
  62. // Import for sending a file over Https connection
  63. import weblogic.net.http.HttpsURLConnection;
  64. import java.net.MalformedURLException;
  65. import java.net.URL;
  66. //import java.net.*;
  67. //import java.security.KeyStore;
  68. //import javax.net.*;
  69. //import javax.net.ssl.*;
  70. //import java.security.cert.*;
  71.  
  72.  
  73. /**
  74.  * @CLASS NAME               : GOSIBatchUtilities
  75.  * @TYPE                     :
  76.  * @AUTHOR                  :TCS
  77.  * @VERSION                 : 1
  78.  * @EXTENDS                 :
  79.  * @INFORMATION             : This class provides interface functionality for other modules and
  80.                               basic frame work methods for the batch
  81.  * @IMPLEMENTS              :
  82.  * @LAST MODIFIED BY        :
  83.  * @LAST MODIFIED DATE      :
  84.  */
  85. public class GOSIBatchUtilities
  86. {
  87.     // Declaring the class level variable
  88.     private static Connection connectionForPk=null;
  89.     private static PreparedStatement psRead=null;
  90.     private static PreparedStatement psUpdate=null;
  91.     private static PreparedStatement psRestartKeyUpdate = null;
  92.     private static PreparedStatement psUserLocation = null;
  93.     private static ArrayList currencyList = null;
  94.     private static Timestamp currentSystemDate = null;
  95.  
  96. /**
  97.  * @METHOD NAME              : getResource
  98.  * @INFORMATION              : This method gets the common of CMN_USR for getting the primary keys
  99.  * @PARAM                    :
  100.  * @RETURN                   :
  101.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  102.  * @LAST MODIFIED BY         :
  103.  * @LAST MODIFIED DATE       :
  104. **/
  105.  
  106.     private static void getResource()
  107.     throws GOSIBatchException
  108.     {
  109.         try
  110.         {
  111.             connectionForPk=getDbConnection(GOSIBatchConstants.COMMON);
  112.         }
  113.         catch(GOSIBatchException e)
  114.         {
  115.             throw e;
  116.         }
  117.         catch(Exception e)
  118.         {
  119.             new GOSIBatchException(e,
  120.             "BatchCore",
  121.             "GOSIBatchUtilities",
  122.             "getResource",
  123.             "CMN_001_ERR_1000",
  124.             GOSIBatchConstants.SEVERITY_ONE);
  125.         }
  126.     }
  127.    
  128. /**
  129.  * @METHOD NAME              : getPrimaryKeys
  130.  * @INFORMATION              : This method returns primary key value and the logic same as online
  131.                             component and this is the private method
  132.  * @PARAM                    : tableName, noOfIds, lastModifiedBy
  133.  * @RETURN                   : class java.lang.Long[]
  134.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  135.  * @LAST MODIFIED BY         :
  136.  * @LAST MODIFIED DATE       :
  137. **/
  138.  
  139.     private static Long[] getPrimaryKeys(String tableName,
  140.                                     int noOfIds, long lastModifiedBy)
  141.     throws GOSIBatchException
  142.     {
  143.         Long[] pkList=new Long[noOfIds];
  144.         ResultSet rsRead=null;
  145.         long currnetId=0L;
  146.         long endValue=0L;
  147.         try
  148.         {
  149.             if(connectionForPk==null)
  150.             {
  151.                 getResource();
  152.             }
  153.             String sequenceName ="";
  154.             if("T_".equals(tableName.substring(0, 2)))
  155.             {
  156.                 sequenceName = "S"+tableName.substring(1, tableName.length());             
  157.             }
  158.             else
  159.             {
  160.                 sequenceName =tableName;
  161.             }
  162.  
  163.             //System.out.println("Sequence Numbe : "+sequenceName);
  164.            
  165.             String sequencequery ="SELECT "+sequenceName+".NEXTVAL FROM "+
  166.                             " DUAL ";
  167.                
  168.             psRead = connectionForPk.prepareStatement(sequencequery);
  169.            
  170.             for(int count=0;count<noOfIds;count++)
  171.             {
  172.                 rsRead = psRead.executeQuery();    
  173.                 if(rsRead.next())
  174.                 {
  175.                     pkList[count]=new Long(rsRead.getLong(1));
  176.                 }
  177.             }
  178.         }
  179.         catch(GOSIBatchException ge)
  180.         {
  181.             throw ge;
  182.         }
  183.         catch(Exception e)
  184.         {
  185.             new GOSIBatchException(e,
  186.             "BatchCore",
  187.             "GOSIBatchUtilities",
  188.             "getPrimaryKeys",
  189.             "CMN_001_ERR_1000",
  190.             GOSIBatchConstants.SEVERITY_ONE);
  191.         }
  192.         finally
  193.         {
  194.             GOSIBatchUtilities.cleanUp(rsRead);
  195.             GOSIBatchUtilities.cleanUp(psRead);
  196.         }
  197.         return pkList;
  198. }
  199.    
  200.     /**
  201.  * @METHOD NAME              : getPrimaryKey
  202.  * @INFORMATION              : For getting a single primary key for given table name and the logic is same as online component
  203.  * @PARAM                    : tableName, lastModifiedBy
  204.  * @RETURN                   : class java.lang.Long
  205.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  206.  * @LAST MODIFIED BY         :
  207.  * @LAST MODIFIED DATE       :
  208. **/
  209.  
  210.     public synchronized static Long getPrimaryKey(String tableName,
  211.     long lastModifiedBy) throws GOSIBatchException
  212.     {
  213.         Long primaryKey=null;
  214.         try
  215.         {
  216.             Long[] pysList=getPrimaryKeys(tableName,
  217.             1, lastModifiedBy);
  218.             primaryKey=pysList[0];
  219.         }
  220.         catch(GOSIBatchException ge)
  221.         {
  222.             throw ge;
  223.         }
  224.         return primaryKey;
  225.     }
  226.    
  227. /**
  228.  * @METHOD NAME              : getPrimaryKeyList
  229.  * @INFORMATION              : FOr getting the multiple no of keys
  230.  * @PARAM                    : tableName,noOfIds,lastModifiedBy
  231.  * @RETURN                   : Long[]
  232.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  233.  * @LAST MODIFIED BY         :
  234.  * @LAST MODIFIED DATE       :
  235. **/
  236.  
  237.     public synchronized static Long[] getPrimaryKeyList(String tableName,
  238.                                     int noOfIds, long lastModifiedBy)
  239.     throws GOSIBatchException
  240.     {
  241.         Long[] pysList=null;
  242.         try
  243.         {
  244.             pysList=getPrimaryKeys(tableName, noOfIds, lastModifiedBy);
  245.         }
  246.         catch(GOSIBatchException ge)
  247.         {
  248.             throw ge;
  249.         }
  250.         return pysList;
  251.     }
  252.     // Declaring public variables which are required at class level
  253.     // Batch Master bean to cache the data related to the current running batch
  254.     public static BatchMaster currentBatchMaster=null;
  255.     // User to store the current date
  256.     public static Timestamp currentDate=null;
  257.  
  258.     // declaring prepare statment which are required at class level
  259.     public static PreparedStatement psInsert=null;
  260.     public static PreparedStatement psDeleteError=null;
  261.     public static PreparedStatement psLogRestart=null;
  262.     public static PreparedStatement psInsertWorkflow=null;
  263.     public static PreparedStatement psInsertRangeCheck=null;
  264.     public static PreparedStatement psInsertTXNMap=null;
  265.     public static PreparedStatement psEmployeeNumber=null;
  266.     /*Start : To place a request for a batch through a batch*/
  267.     public static PreparedStatement psInsertBatchRequest=null;
  268.     public static PreparedStatement psInsertParamValues=null;
  269.     public static PreparedStatement psCheckIsHoliday = null;
  270.     public static PreparedStatement psFinalDate = null;
  271.     public static PreparedStatement psNoOfHolidays =null;
  272.     public static PreparedStatement psWeekEnds = null;
  273.     public static PreparedStatement psOtherHolidays = null;
  274.     public static PreparedStatement psTotalDiff = null;
  275.     public static PreparedStatement psNextWorkingDay = null;
  276.    
  277.     /*End : To place a request for a batch through a batch*/
  278.    
  279.     // Constructor of the GOSIBatchUtilities which is called by the BatchDriver
  280.     public GOSIBatchUtilities(String batchId)
  281.     throws GOSIBatchException
  282.     {
  283.         // Calls this method which loads the BatchMaster bean with the data related to the batch id passed
  284.         getBatchMaster(batchId);
  285.     }
  286.  
  287. /**
  288.  * @METHOD NAME              : getProcessor
  289.  * @INFORMATION              : This method return the processor for
  290.                                given batch id and the flag
  291.  * @PARAM                    : batchId, flag
  292.  * @RETURN                   : BatchProcessController
  293.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  294.  * @LAST MODIFIED BY         :
  295.  * @LAST MODIFIED DATE       :
  296. **/
  297.     public static BatchProcessController getProcessor
  298.     (String batchId, byte flag)
  299.     throws GOSIBatchException,Exception
  300.     {
  301.         BatchProcessController batchProcessController=null;
  302.         try
  303.         {
  304.            
  305.             String processorname =
  306.             currentBatchMaster.getProcessorName();
  307.             Constructor myClassConstructor = null;
  308.             Class[] paramTypes = new Class[1];
  309.             paramTypes[0] = byte.class;
  310.             Class myClass = Class.forName(processorname);
  311.             try
  312.             {
  313.                 // This is trying to the the processer constructor which has only the flag as parameter
  314.                 // I am not sure what is the case for it
  315.                 myClassConstructor =
  316.                 myClass.getConstructor(paramTypes);
  317.                 Object[] params = new Object[1];
  318.                 params[0] = new Byte(flag);
  319.                 batchProcessController =
  320.                 (BatchProcessController)
  321.                 myClassConstructor.newInstance(params);
  322.             }
  323.             catch(NoSuchMethodException nme)
  324.             {
  325.                 // This is teh normal processer constructur which take the batch id and the flag
  326.                 paramTypes = new Class[2];
  327.                 paramTypes[0]=String.class;
  328.                 paramTypes[1] = byte.class;
  329.                 myClassConstructor =
  330.                     myClass.getConstructor(paramTypes);
  331.                 Object[] params = new Object[2];
  332.                 params[0] = new String(batchId);
  333.                 params[1] = new Byte(flag);
  334.                 batchProcessController=(BatchProcessController)
  335.                 myClassConstructor.newInstance(params);
  336.             }
  337.         }catch(Exception e)
  338.         {
  339.                 throw e;
  340.         }
  341.         return batchProcessController;
  342.     }
  343. /**
  344.  * @METHOD NAME              : getProcessor
  345.  * @INFORMATION              : Returns the processor for batchId and the HashMap which holds the flags for each frequency
  346.                                 This is also same as above
  347.  * @PARAM                    : batchId, hashMap
  348.  * @RETURN                   : BatchProcessController
  349.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  350.  * @LAST MODIFIED BY         :
  351.  * @LAST MODIFIED DATE       :
  352. **/
  353.  
  354.     public static BatchProcessController getProcessor
  355.     (String batchId, HashMap hashMap)
  356.     throws GOSIBatchException,Exception
  357.     {
  358.         BatchProcessController batchProcessController=null;
  359.         try
  360.         {
  361.             String processorname =
  362.             currentBatchMaster.getProcessorName();
  363.             Constructor myClassConstructor = null;
  364.             Class[] paramTypes = new Class[1];
  365.             paramTypes[0] = HashMap.class;
  366.             Class myClass = Class.forName(processorname);
  367.             try
  368.             {
  369.                 myClassConstructor =
  370.                 myClass.getConstructor(paramTypes);
  371.                 Object[] params = new Object[1];
  372.                 params[0] = hashMap;
  373.                 batchProcessController =
  374.                 (BatchProcessController)
  375.                 myClassConstructor.newInstance(params);
  376.             }
  377.             catch(NoSuchMethodException nme)
  378.             {
  379.                 paramTypes = new Class[2];
  380.                 paramTypes[0]=String.class;
  381.                 paramTypes[1] = HashMap.class;
  382.                 myClassConstructor =
  383.                     myClass.getConstructor(paramTypes);
  384.                 Object[] params = new Object[2];
  385.                 params[0] = new String(batchId);
  386.                 params[1] = hashMap;
  387.                 batchProcessController=(BatchProcessController)
  388.                 myClassConstructor.newInstance(params);
  389.             }
  390.         }catch(Exception e)
  391.         {
  392.                 throw e;
  393.         }
  394.         return batchProcessController;
  395.     }
  396.  
  397. /**
  398.  * @METHOD NAME              : cleanUp
  399.  * @INFORMATION              : THis method cleans up the resources passing
  400.                               such as resultSet,preparedstatement, connection
  401.  * @PARAM                    : rs, statement, connection
  402.  * @RETURN                   :
  403.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  404.  * @LAST MODIFIED BY         :
  405.  * @LAST MODIFIED DATE       :
  406. **/
  407.    
  408.     public static void cleanUp(ResultSet rs,
  409.                         PreparedStatement statement,
  410.                         Connection connection)
  411.     {
  412.         try
  413.         {
  414.             if(rs!=null)
  415.             {
  416.                 rs.close();
  417.             }
  418.             if(statement!=null)
  419.             {
  420.                 statement.close();
  421.             }
  422.             if (connection!=null)
  423.             {
  424.                  if (!connection.isClosed())
  425.                 {
  426.                    connection.close();
  427.                 }              
  428.             }          
  429.  
  430.         }
  431.         catch(Exception e)
  432.         {
  433.                
  434.         }
  435.     }
  436.    
  437. /**
  438.  * @METHOD NAME              : cleanUp
  439.  * @INFORMATION              : THis method cleans up the resources passing
  440.                               such as resultSet,preparedstatement, connection
  441.  * @PARAM                    : statement, connection
  442.  * @RETURN                   :
  443.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  444.  * @LAST MODIFIED BY         :
  445.  * @LAST MODIFIED DATE       :
  446. **/
  447.  
  448.     public static void cleanUp(PreparedStatement statement
  449.                                ,Connection connection)
  450.     {
  451.         try
  452.         {
  453.             if(statement!=null)
  454.             {
  455.                 statement.close();
  456.             }
  457.             if (connection!=null)
  458.             {
  459.                  if (!connection.isClosed())
  460.                 {
  461.                    connection.close();
  462.                 }              
  463.             }          
  464.  
  465.         }
  466.         catch(Exception e)
  467.         {
  468.                
  469.         }
  470.     }
  471.  
  472. /**
  473.  * @METHOD NAME              : cleanUp
  474.  * @INFORMATION              : THis method cleans up the resources passing
  475.                               such as resultSet,preparedstatement, connection
  476.  * @PARAM                    : connection
  477.  * @RETURN                   :
  478.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  479.  * @LAST MODIFIED BY         :
  480.  * @LAST MODIFIED DATE       :
  481. **/
  482.  
  483.     public static void cleanUp(Connection connection)
  484.     {
  485.         try
  486.         {
  487.             if (connection!=null)
  488.             {
  489.                  if (!connection.isClosed())
  490.                 {
  491.                    connection.close();
  492.                 }              
  493.             }          
  494.  
  495.         }
  496.         catch(Exception e)
  497.         {
  498.                
  499.         }
  500.     }
  501.    
  502. /**
  503.  * @METHOD NAME              : cleanUp
  504.  * @INFORMATION              : THis method cleans up the resources passing
  505.                               such as resultSet,preparedstatement, connection
  506.  * @PARAM                    : statement
  507.  * @RETURN                   :
  508.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  509.  * @LAST MODIFIED BY         :
  510.  * @LAST MODIFIED DATE       :
  511. **/
  512.    
  513.     public static void cleanUp(PreparedStatement statement)
  514.     {
  515.         try
  516.         {
  517.             if(statement!=null)
  518.             {
  519.                 statement.close();
  520.             }
  521.         }
  522.         catch(Exception e)
  523.         {
  524.                
  525.         }
  526.     }
  527. /**
  528.  * @METHOD NAME              : cleanUp
  529.  * @INFORMATION              : THis method cleans up the resources passing
  530.                               such as resultSet,preparedstatement, connection
  531.  * @PARAM                    : rs
  532.  * @RETURN                   :
  533.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  534.  * @LAST MODIFIED BY         :
  535.  * @LAST MODIFIED DATE       :
  536. **/
  537.    
  538.     public static void cleanUp(ResultSet rs)
  539.     {
  540.         try
  541.         {
  542.             if(rs!=null)
  543.             {
  544.                 rs.close();
  545.             }
  546.         }
  547.         catch(Exception e)
  548.         {
  549.            
  550.         }
  551.     }
  552.  
  553. /**
  554.  * @METHOD NAME              : getDbConnection
  555.  * @INFORMATION              :  This method returns the connections for given
  556.                                 module Short name. creates connection for specific module
  557.                                 database. And it puts the AutoCommit as null in the created connection.
  558.  * @PARAM                    : moduleName
  559.  * @RETURN                   : class java.sql.Connection
  560.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  561.  * @LAST MODIFIED BY         :
  562.  * @LAST MODIFIED DATE       :
  563. **/
  564.    
  565.     public static Connection getDbConnection(String moduleName)
  566.     throws GOSIBatchException
  567.     {
  568.         Connection connection=null;
  569.         try
  570.         {
  571.             String userId=null;
  572.             String password=null;
  573.             if((GOSIBatchConstants.COMMON).equals(moduleName))
  574.             {
  575.                 userId=GOSIBatchProperties.COMMON_DB_USER_ID;
  576.                 password=GOSIBatchProperties.COMMON_DB_PASSWORD;
  577.             }
  578.             else if((GOSIBatchConstants.REGISTRATION).equals(moduleName))
  579.             {
  580.                 userId=GOSIBatchProperties.REGISTRATION_DB_USER_ID;
  581.                 password=GOSIBatchProperties.REGISTRATION_DB_PASSWORD;
  582.             }
  583.             else if((GOSIBatchConstants.CONTRIBUTION).equals(moduleName))
  584.             {
  585.                 userId=GOSIBatchProperties.CONTRIBUTION_DB_USER_ID;
  586.                 password=GOSIBatchProperties.CONTRIBUTION_DB_PASSWORD;
  587.             }
  588.             else if((GOSIBatchConstants.OCCUPATIONAL_HAZARDS).equals(moduleName))
  589.             {
  590.                 userId=GOSIBatchProperties.OCCUPATIONAL_HAZARDS_DB_USER_ID;
  591.                 password=GOSIBatchProperties.
  592.                             OCCUPATIONAL_HAZARDS_DB_PASSWORD;
  593.             }
  594.             else if((GOSIBatchConstants.ANNUITIES).equals(moduleName))
  595.             {
  596.                 userId=GOSIBatchProperties.ANNUITIES_DB_USER_ID;
  597.                 password=GOSIBatchProperties.ANNUITIES_DB_PASSWORD;
  598.             }
  599.             else if((GOSIBatchConstants.FINANCE).equals(moduleName))
  600.             {
  601.                 userId=GOSIBatchProperties.FINANCE_DB_USER_ID;
  602.                 password=GOSIBatchProperties.FINANCE_DB_PASSWORD;
  603.             }
  604.             else if((GOSIBatchConstants.BUDGET).equals(moduleName))
  605.             {
  606.                 userId=GOSIBatchProperties.BUDGET_DB_USER_ID;
  607.                 password=GOSIBatchProperties.BUDGET_DB_PASSWORD;
  608.             }
  609.             else if((GOSIBatchConstants.INVESTMENT).equals(moduleName))
  610.             {
  611.                 userId=GOSIBatchProperties.INVESTMENT_DB_USER_ID;
  612.                 password=GOSIBatchProperties.INVESTMENT_DB_PASSWORD;
  613.             }
  614.             else if((GOSIBatchConstants.FIXED_ASSET).equals(moduleName))
  615.             {
  616.                 userId=GOSIBatchProperties.FIXED_ASSET_DB_USER_ID;
  617.                 password=GOSIBatchProperties.FIXED_ASSET_DB_PASSWORD;
  618.             }
  619.             else if((GOSIBatchConstants.INVENTORY).equals(moduleName))
  620.             {
  621.                 userId=GOSIBatchProperties.INVENTORY_DB_USER_ID;
  622.                 password=GOSIBatchProperties.INVENTORY_DB_PASSWORD;
  623.             }
  624.             else if((GOSIBatchConstants.PURCHASE).equals(moduleName))
  625.             {
  626.                 userId=GOSIBatchProperties.PURCHASE_DB_USER_ID;
  627.                 password=GOSIBatchProperties.PURCHASE_DB_PASSWORD;
  628.             }
  629.             else if((GOSIBatchConstants.CONTRACT).equals(moduleName))
  630.             {
  631.                 userId=GOSIBatchProperties.CONTRACT_DB_USER_ID;
  632.                 password=GOSIBatchProperties.CONTRACT_DB_PASSWORD;
  633.             }
  634.             else if((GOSIBatchConstants.REAL_ESTATE).equals(moduleName))
  635.             {
  636.                 userId=GOSIBatchProperties.REAL_ESTATE_DB_USER_ID;
  637.                 password=GOSIBatchProperties.REAL_ESTATE_DB_PASSWORD;
  638.             }
  639.             else if((GOSIBatchConstants.PERSONNEL).equals(moduleName))
  640.             {
  641.                 userId=GOSIBatchProperties.PERSONNEL_DB_USER_ID;
  642.                 password=GOSIBatchProperties.PERSONNEL_DB_PASSWORD;
  643.             }
  644.             else if((GOSIBatchConstants.PROJECT).equals(moduleName))
  645.             {
  646.                 userId=GOSIBatchProperties.PROJECT_DB_USER_ID;
  647.                 password=GOSIBatchProperties.PROJECT_DB_PASSWORD;
  648.             }
  649.             else if((GOSIBatchConstants.DATAWAREHOUSING).equals(moduleName))
  650.             {              
  651.                 userId=GOSIBatchProperties.DATAWAREHOUSING_DB_USER_ID;
  652.                 //System.out.println("USERID : "+userId);
  653.                 password=GOSIBatchProperties.DATAWAREHOUSING_DB_PASSWORD;
  654.                 //System.out.println("Password : "+password);
  655.             }
  656.             else if((GOSIBatchConstants.COMMON_FUT).equals(moduleName))
  657.             {
  658.                 userId=GOSIBatchProperties.COMMON_FUT_DB_USER_ID;
  659.                 password=GOSIBatchProperties.COMMON_FUT_DB_PASSWORD;
  660.             }
  661.             else if((GOSIBatchConstants.INTERNET).equals(moduleName))
  662.             {
  663.                 userId=GOSIBatchProperties.INTERNET_DB_USER_ID;
  664.                 password=GOSIBatchProperties.INTERNET_DB_PASSWORD;
  665.             }
  666.             else if((GOSIBatchConstants.RPA).equals(moduleName))
  667.             {
  668.                 userId=GOSIBatchProperties.RPA_DB_USER_ID;
  669.                 password=GOSIBatchProperties.RPA_DB_PASSWORD;
  670.             }
  671.             else
  672.             {
  673.                     new GOSIBatchException(null,
  674.                                 "BatchCore",
  675.                                 "GOSIBatchUtilities",
  676.                                 "getConnection",
  677.                                 "CMN_001_ERR_1001",
  678.                                 GOSIBatchConstants.SEVERITY_ONE);                
  679.             }
  680.            
  681.             String databaseURL = GOSIBatchProperties.DATABASE_URL;
  682.  
  683.             Class.forName(GOSIBatchProperties.DRIVER_CLASS);
  684.                connection=
  685.               DriverManager.getConnection (databaseURL,
  686.                userId, password);
  687.             connection.setAutoCommit(false);               
  688.         }
  689.         catch(GOSIBatchException ge)
  690.         {
  691.             throw ge;
  692.         }
  693.         catch(Exception e)
  694.         {
  695.             new GOSIBatchException(e,
  696.                                 "BatchCore",
  697.                                 "GOSIBatchUtilities",
  698.                                 "getConnection",
  699.                                 "CMN_001_ERR_1000",
  700.                                 GOSIBatchConstants.SEVERITY_ONE);
  701.         }
  702.         return connection;
  703.     }
  704.    
  705.   /**
  706.  * @METHOD NAME              : getNoOfRequest
  707.  * @INFORMATION              : This method gets the no of request on the given day for the passed batchid.
  708.                                 This method is called when the batch type is adhoc or is the batch type is normal and requires parameter
  709.  * @PARAM                    : batchId, connection, batchType
  710.  * @RETURN                   : int
  711.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  712.  * @LAST MODIFIED BY         :
  713.  * @LAST MODIFIED DATE       :
  714. **/
  715.      
  716.     private static int getNoOfRequest(String batchId,Connection connection,
  717.     byte batchType)
  718.     throws GOSIBatchException
  719.     {
  720.         int noOfRequest=0;
  721.         PreparedStatement ps=null;
  722.         ResultSet rs=null;
  723.         try
  724.         {
  725.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1018");
  726.             //System.out.println("No of request query : "+query);
  727.             //System.out.println("System Date : "+getSystemDate());
  728.             ps=connection.prepareStatement(query);
  729.             ps.setString(1,batchId);
  730.             ps.setTimestamp(2,getSystemDate());
  731.             rs=ps.executeQuery();
  732.             if(rs.next())
  733.             {
  734.                 noOfRequest=rs.getInt(1);
  735.             }
  736.             else
  737.             {
  738.                 //System.out.println("there are nor requests");
  739.             }
  740.             // Checking the no of request
  741.             if(noOfRequest==0)
  742.             {
  743.                 // If the batch job is Scheduled job and no request means throwing exception with CMN_001_ERR_1009
  744.                 if(batchType==GOSIBatchConstants.NORMAL_JOB)
  745.                 {
  746.                     new GOSIBatchException(null,
  747.                         "BatchCore",
  748.                         "GOSIBatchUtilities",
  749.                         "getRequest",
  750.                         "CMN_001_ERR_1009",
  751.                         GOSIBatchConstants.SEVERITY_ONE);
  752.                 }
  753.                 // If the batch job is Adhoc job and no request means throwing exception with CMN_001_ERR_1065
  754.                 // So the error code is checked in the BatchDriver if the erro code is CMN_001_ERR_1065 is not throwing to the schedular so that will not be shown as failed
  755.                 else
  756.                 {
  757.                     new GOSIBatchException(null,
  758.                         "BatchCore",
  759.                         "GOSIBatchUtilities",
  760.                         "getRequest",
  761.                         "CMN_001_ERR_1065",
  762.                         GOSIBatchConstants.SEVERITY_TWO);
  763.                 }
  764.                    
  765.             }
  766.         }
  767.         catch(GOSIBatchException ge)
  768.         {
  769.             throw ge;
  770.         }
  771.         catch(Exception e)
  772.         {
  773.             new GOSIBatchException(e,
  774.                     "BatchCore",
  775.                     "GOSIBatchUtilities",
  776.                     "getRequest",
  777.                     "CMN_001_ERR_1000",
  778.                     GOSIBatchConstants.SEVERITY_ONE);
  779.         }
  780.         finally
  781.         {
  782.             GOSIBatchUtilities.cleanUp(rs);
  783.             GOSIBatchUtilities.cleanUp(ps);
  784.         }
  785.         return noOfRequest;
  786.     }
  787.    
  788. /**
  789.  * @METHOD NAME              : getBatchMaster
  790.  * @INFORMATION              : This method gets the batch master values for given batch id and populates in the  
  791.                                 batchMaster class variable.
  792.                                 This method does the following things.
  793.                                 1. Gets the data from T_BATCHMASTER for the given batch id
  794.                                 2. Gets the System user id
  795.                                 3. Gets the System role id
  796.                                 4. If the batch is adjoc or the no of parameter or >0 calls getNoOfRequest to get the no of requsts
  797.                                     As seen above in the getNoOfRequest if the request is not found exception is thrown
  798.                                 5. Populating all the values in the BatchMaster depending on the job type and no of parameters
  799.  * @PARAM                    : batchId
  800.  * @RETURN                   : NIL
  801.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  802.  * @LAST MODIFIED BY         :
  803.  * @LAST MODIFIED DATE       :
  804. **/
  805.  
  806.     public static void getBatchMaster(String batchId)
  807.     throws GOSIBatchException
  808.     {
  809.         Connection connection=null;
  810.         PreparedStatement ps=null;
  811.         ResultSet rs=null;
  812.         PreparedStatement psUser=null;
  813.         ResultSet rsUser=null;
  814.         PreparedStatement psRole=null;
  815.         ResultSet rsRole=null;
  816.         boolean invoke=false;
  817.         try
  818.         {
  819.             // Executing query for getting the data from T_BATCHMASTER
  820.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1001");
  821.             connection=GOSIBatchUtilities.
  822.             getDbConnection(GOSIBatchConstants.COMMON);
  823.             ps=connection.prepareStatement(query);
  824.             ps.setString(1,batchId);
  825.             rs=ps.executeQuery();
  826.             // Executing query for getting the system user id
  827.             query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1021");
  828.             psUser=connection.prepareStatement(query);
  829.             psUser.setString(1,GOSIBatchProperties.SYSTEM_USER+"%");
  830.             rsUser=psUser.executeQuery();
  831.             long userCode=0L;
  832.             long roleId=0L;
  833.            
  834.             //this if is no longer used
  835.             if(rsUser.next())
  836.             {
  837.                 userCode=rsUser.getLong("ID");
  838.             }
  839.             else
  840.             {
  841.                 new GOSIBatchException(null,
  842.                 "BatchCore",
  843.                 "GOSIBatchUtilities",
  844.                 "getBatchMaster",
  845.                 "CMN_001_ERR_1006",
  846.                 GOSIBatchConstants.SEVERITY_ONE);    
  847.             }
  848.             // Executing query for getting the system role id
  849.             query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1034");
  850.             psRole=connection.prepareStatement(query);
  851.             psRole.setString(1,GOSIBatchProperties.SYSTEM_ROLE+"%");
  852.             rsRole=psRole.executeQuery();
  853.             if(rsRole.next())
  854.             {
  855.                 roleId=rsRole.getLong("ROLEID");
  856.             }
  857.             else
  858.             {
  859.                 new GOSIBatchException(null,
  860.                 "BatchCore",
  861.                 "GOSIBatchUtilities",
  862.                 "getBatchMaster",
  863.                 "CMN_001_ERR_1006",
  864.                 GOSIBatchConstants.SEVERITY_ONE);    
  865.             }
  866.             // Taking the record from the query of T_BATCHMASTER
  867.             if(rs.next())
  868.             {
  869.                 // If the job is adhoc or have no of parameters more than 1 then calling getNoOfRequest to get the no of requests
  870.                 if((rs.getByte("BATCHTYPE")==GOSIBatchConstants.ADHOC_JOB)||
  871.                 (rs.getShort("NUMOFPARAMS")>0))
  872.                 {
  873.                     int noOfRequest = getNoOfRequest(batchId,connection,rs.getByte("BATCHTYPE"));
  874.                     // If batch is Adhoc or no of parameters or more than 1 then populating the batch details in
  875.                     // currentBatchMaster inclding the no of requests
  876.                     currentBatchMaster =
  877.                             new BatchMaster(rs.getString("BATCHID"),
  878.                             rs.getString("BATCHDESCRIPTION"),
  879.                             rs.getShort("NUMOFPARAMS"),
  880.                             rs.getShort("COMMITFREQUENCY"),
  881.                             rs.getString("PROCESSORNAME"),
  882.                             rs.getLong("ID"),
  883.                             roleId,rs.getByte("BATCHTYPE"),
  884.                             noOfRequest,rs.getByte("BUSINESSERRORFLAG"),
  885.                             rs.getString("BATCHRUNFREQUENCY"));                
  886.                  }
  887.                  else
  888.                  {
  889.                     // If batch is normal and not having any parametrs then populating the batch details in
  890.                     // currentBatchMaster with out no of parameters
  891.                     currentBatchMaster=
  892.                             new BatchMaster(rs.getString("BATCHID"),
  893.                             rs.getString("BATCHDESCRIPTION"),
  894.                             rs.getShort("NUMOFPARAMS"),
  895.                             rs.getShort("COMMITFREQUENCY"),
  896.                             rs.getString("PROCESSORNAME"),
  897.                             rs.getLong("ID"),roleId,
  898.                             rs.getByte("BATCHTYPE"),
  899.                             0,rs.getByte("BUSINESSERRORFLAG"),
  900.                             rs.getString("BATCHRUNFREQUENCY"));
  901.                  }
  902.             }
  903.             // If batch id T_BATCHMASTER is not found then throwing exception
  904.             else
  905.             {
  906.                 new GOSIBatchException(null,
  907.                 "BatchCore",
  908.                 "GOSIBatchUtilities",
  909.                 "getBatchMaster",
  910.                 "CMN_001_ERR_1002",
  911.                 GOSIBatchConstants.SEVERITY_ONE);    
  912.             }
  913.         }
  914.         catch(GOSIBatchException ge)
  915.         {
  916.             throw ge;
  917.         }
  918.         catch(Exception e)
  919.         {
  920.             new GOSIBatchException(e,
  921.             "BatchCore",
  922.             "GOSIBatchUtilities",
  923.             "Constructor",
  924.             "CMN_001_ERR_1000",
  925.             GOSIBatchConstants.SEVERITY_ONE);
  926.         }
  927.         finally
  928.         {
  929.             GOSIBatchUtilities.cleanUp(rs, ps, connection);
  930.             GOSIBatchUtilities.cleanUp(rsUser);
  931.             GOSIBatchUtilities.cleanUp(psUser);
  932.         }
  933.        
  934.         return;
  935.     }
  936. /**
  937.  * @METHOD NAME              : loadCurrencyDetails
  938.  * @INFORMATION              : This is for loading the currency details
  939.  * @PARAM                    : void
  940.  * @RETURN                   : void
  941.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  942.  * @LAST MODIFIED BY         :
  943.  * @LAST MODIFIED DATE       :
  944. **/
  945.    
  946.     public static void loadCurrencyDetails()
  947.     throws GOSIBatchException
  948.     {  
  949.            
  950.        currencyList = new ArrayList();     
  951.        PreparedStatement psForCurrency=null;
  952.        ResultSet rsForCurrency=null;
  953.        Connection connectionForFA=null;
  954.  
  955.         try
  956.         {
  957.             String query=GOSIBatchSQL.getSqlString("INT_FIN_SQL_4025");
  958.             connectionForFA=
  959.             getDbConnection(GOSIBatchConstants.FINANCE);            
  960.             psForCurrency=connectionForFA.prepareStatement(query);
  961.             rsForCurrency = psForCurrency.executeQuery();
  962.             currencyList=new ArrayList();
  963.             while(rsForCurrency.next())
  964.             {
  965.                 HashMap currencyDetails=new HashMap();
  966.                 currencyDetails.put("code", new Integer(
  967.                     rsForCurrency.getInt("CURRENCYCODE")));
  968.                 currencyDetails.put("nameEnglish", new String(
  969.                     rsForCurrency.getString("CURRENCYNAMEENGLISH")));                  
  970.                 currencyDetails.put("nameArabic", new String(
  971.                     rsForCurrency.getString("CURRENCYNAMEARABIC")));
  972.                 currencyDetails.put("country", new String(
  973.                     rsForCurrency.getString("COUNTRY")));                
  974.                 currencyDetails.put("type", new Integer(
  975.                     rsForCurrency.getInt("CURRENCYTYPE")));
  976.                 currencyDetails.put("symbol", new String(
  977.                     rsForCurrency.getString("SYMBOL")));
  978.                 currencyDetails.put("precision", new Integer(
  979.                     rsForCurrency.getInt("POSITIONAFTERDECIMAL")));                  
  980.                 currencyList.add(currencyDetails);
  981.             }
  982.         }
  983.         catch(GOSIBatchException ge)
  984.         {
  985.             throw ge;  
  986.         }    
  987.         catch(Exception e)
  988.         {
  989.             new GOSIBatchException(e,
  990.             "BatchCore",
  991.             "GOSIBatchUtilities",
  992.             "loadCurrencyDetails",
  993.             "CMN_001_ERR_1000",
  994.             GOSIBatchConstants.SEVERITY_ONE);    
  995.         }
  996.         finally
  997.         {
  998.             GOSIBatchUtilities.cleanUp(rsForCurrency);
  999.             GOSIBatchUtilities.cleanUp(psForCurrency,connectionForFA);
  1000.         }    
  1001.     }
  1002.  
  1003.    
  1004.     /**
  1005.  * @METHOD NAME              : round
  1006.  * @INFORMATION              :This method returns a String  which is
  1007.  *                            rounded to the given precision(scale).
  1008.  *                            Usual rounding convention is used.
  1009.  *                            NumberFormat.round(12345.234, 2)
  1010.  *                          will return the value 12345.12
  1011.  * @PARAM                    : amount, scale
  1012.  * @RETURN                   : String
  1013.  * @EXCEPTION                : class gosi.core.util.GOSIException
  1014.  * @LAST MODIFIED BY         :
  1015.  * @LAST MODIFIED DATE       :
  1016. **/
  1017.     public static String round(double amount, int scale)
  1018.     throws GOSIBatchException
  1019.     {
  1020.         String formatedData="";
  1021.    
  1022.         try
  1023.         {
  1024.             String amountStr=""+amount;
  1025.             int index=amountStr.indexOf(".");
  1026.             int amountlength=amountStr.length();
  1027.             int scaleLength=amountlength-(index+1);
  1028.             String decimalData=amountStr.substring(index+1);
  1029.             String scalePointData=null;
  1030.             if(scaleLength>scale)
  1031.             {
  1032.                 scalePointData=decimalData.substring(scale);
  1033.                 if("5".equals(scalePointData))
  1034.                 {
  1035.                     amountStr=amountStr+1;
  1036.                 }
  1037.             }
  1038.             formatedData=new BigDecimal(amountStr).setScale(scale, BigDecimal.
  1039.             ROUND_HALF_UP).toString();
  1040.            
  1041.         }
  1042.         catch(Exception e)
  1043.         {
  1044.             new GOSIBatchException(e,
  1045.             "BatchCore",
  1046.             "GOSIBatchUtilities",
  1047.             "round()",
  1048.             "CMN_001_ERR_1000",
  1049.             GOSIBatchConstants.SEVERITY_ONE);
  1050.          }
  1051.         return formatedData;
  1052.      }
  1053.    
  1054.    
  1055.     /**
  1056.  * @METHOD NAME              : roundToPrecision
  1057.  * @INFORMATION              : This method returns a String type which is
  1058.  *                              rounded for the given Currency Code.
  1059.  *                              This inturn calls the round method
  1060.  * @PARAM                    : amount, code
  1061.  * @RETURN                   : String
  1062.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  1063.  * @LAST MODIFIED BY         :
  1064.  * @LAST MODIFIED DATE       :
  1065. **/
  1066.  
  1067.     public static Double roundToPrecision(double amount,int code)
  1068.     throws GOSIBatchException
  1069.     {
  1070.         String rndAmount=null;
  1071.         Double retAmount=null;
  1072.         int prec=0;
  1073.         try
  1074.         {
  1075.            if(currencyList!=null)
  1076.            {
  1077.             int currSize=currencyList.size();
  1078.             for(int i=0; i<currSize;i++)
  1079.             {
  1080.                 HashMap curDet=(HashMap)currencyList.get(i);
  1081.                 int curCode=Integer.parseInt(""+curDet.get("code"));
  1082.                 if (curCode==code)
  1083.                 {
  1084.                     prec=Integer.parseInt(""+curDet.get("precision"));
  1085.                     //rndAmount=new BigDecimal(amount).setScale
  1086.                     //(prec,BigDecimal.ROUND_HALF_UP).toString();
  1087.                     rndAmount=round(amount, prec);
  1088.                     retAmount=new Double(rndAmount);
  1089.                     break;
  1090.                 }
  1091.             }
  1092.           }  
  1093.         }
  1094.         catch(Exception e)
  1095.         {
  1096.             throw new GOSIBatchException(e,
  1097.             "BatchCore",
  1098.             "GOSIBatchUtilities",
  1099.             "roundToPrecision",
  1100.             "CMN_001_ERR_1000",
  1101.             GOSIBatchConstants.SEVERITY_ONE);                              
  1102.         }
  1103.         return retAmount;        
  1104.     }
  1105.  
  1106. /**
  1107.  * @METHOD NAME              : getBatchRestart
  1108.  * @INFORMATION              : This method reads the data from the T_BATCHRESTARTKEYS for the given batch id
  1109.                                 Populates in the BatchRestart object and returns it
  1110.  * @PARAM                    : batchId
  1111.  * @RETURN                   : BatchRestart
  1112.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  1113.  * @LAST MODIFIED BY         :
  1114.  * @LAST MODIFIED DATE       :
  1115. **/
  1116.     public static BatchRestart getBatchRestart
  1117.     (String batchId)throws GOSIBatchException
  1118.     {
  1119.         BatchRestart batchRestart=null;
  1120.         Connection connection=null;
  1121.         PreparedStatement ps=null;
  1122.         ResultSet rs=null;
  1123.         try
  1124.         {
  1125.             // Exceuting the query for getting the details
  1126.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1002");
  1127.             connection=GOSIBatchUtilities.
  1128.             getDbConnection(GOSIBatchConstants.COMMON);
  1129.             ps=connection.prepareStatement(query);
  1130.             ps.setString(1, batchId);
  1131.             rs=ps.executeQuery();
  1132.             if(rs.next())
  1133.             {
  1134.                 batchRestart=new BatchRestart();
  1135.                 batchRestart.setRestartKeys(rs.getString("RESTARTKEY"));
  1136.                 batchRestart.setLastRunStatus(rs.getString("CURRENTSTATUS"));
  1137.                 batchRestart.setLastRunDate(rs.getTimestamp("LASTRUNDATE"));
  1138.                 batchRestart.setRequestNo(rs.getLong("REQUESTID"));
  1139.                 batchRestart.setSuccessDate(rs.getTimestamp("SUCCESSDATE"));
  1140.             }
  1141.         }
  1142.         catch(Exception e)
  1143.         {
  1144.              new GOSIBatchException(e,
  1145.                                 "BatchCore",
  1146.                                 "GOSIBatchUtilities",
  1147.                                 "getBatchRestart",
  1148.                                 "CMN_001_ERR_1000",
  1149.                                 GOSIBatchConstants.SEVERITY_ONE);    
  1150.         }
  1151.         finally
  1152.         {
  1153.             GOSIBatchUtilities.cleanUp(rs, ps, connection);
  1154.         }
  1155.  
  1156.         return batchRestart;
  1157.     }
  1158. /**
  1159.  * @METHOD NAME              : completeProcess
  1160.  * @INFORMATION              : This method called to complete the process
  1161.                                 This method updates the status of T_BATCHMASTER depending on the sucess or failure
  1162.  * @PARAM                    : batchId, flag
  1163.  * @RETURN                   : NIL
  1164.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  1165.  * @LAST MODIFIED BY         :
  1166.  * @LAST MODIFIED DATE       :
  1167. **/
  1168.    
  1169.     public static void completeProcess
  1170.     (String batchId,String flag)throws GOSIBatchException
  1171.     {
  1172.         Connection connection=null;
  1173.         PreparedStatement ps=null;
  1174.         try
  1175.         {
  1176.             connection=GOSIBatchUtilities.
  1177.             getDbConnection(GOSIBatchConstants.COMMON);
  1178.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1019");
  1179.             ps=connection.prepareStatement(query);
  1180.             ps.setString(1, flag);
  1181.             ps.setString(2, batchId);
  1182.             int result=ps.executeUpdate();
  1183.             connection.commit();
  1184.         }
  1185.         catch(Exception e)
  1186.         {
  1187.                 new GOSIBatchException(e,
  1188.                     "BatchCore",
  1189.                     "GOSIBatchUtilities",
  1190.                     "updateRunInstance",
  1191.                     "CMN_001_ERR_1000",
  1192.                     GOSIBatchConstants.SEVERITY_ONE);        
  1193.            
  1194.  
  1195.         }
  1196.         finally
  1197.         {
  1198.             GOSIBatchUtilities.cleanUp(ps,connection);
  1199.         }
  1200.     }
  1201.    
  1202. /**
  1203.  * @METHOD NAME              : getBatchError
  1204.  * @INFORMATION              : This method is called by the BathProcessController to
  1205.                                 get the list of the batch errors in the previous run
  1206.  * @PARAM                    : batchId
  1207.  * @RETURN                   : ArrayList
  1208.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  1209.  * @LAST MODIFIED BY         :
  1210.  * @LAST MODIFIED DATE       :
  1211. **/
  1212.  
  1213.     public static ArrayList getBatchError(String batchId)
  1214.     throws GOSIBatchException
  1215.     {
  1216.         ArrayList errorRecordsList=new ArrayList();
  1217.         Connection connection=null;
  1218.         PreparedStatement ps=null;
  1219.         ResultSet rs=null;
  1220.         try
  1221.         {
  1222.             //Executing the query to get the list of errors which are of severity 2
  1223.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1003");
  1224.             connection=GOSIBatchUtilities.
  1225.             getDbConnection(GOSIBatchConstants.COMMON);
  1226.             ps=connection.prepareStatement(query);
  1227.             ps.setString(1, batchId);
  1228.             ps.setString(2, GOSIBatchConstants.TO_BE_PROCESSED);
  1229.             ps.setInt(3,GOSIBatchConstants.SEVERITY_TWO);
  1230.             rs=ps.executeQuery();
  1231.             BatchError batchError=null;
  1232.             while(rs.next())
  1233.             {
  1234.                 if(errorRecordsList==null)
  1235.                 {
  1236.                     errorRecordsList=new ArrayList();
  1237.                 }
  1238.                 batchError=new BatchError();
  1239.                
  1240.                 batchError.setRecordIdentifiers(rs.getString("RECORDIDENTIFIERS"));
  1241.                 batchError.setStatus(GOSIBatchConstants.TO_BE_PROCESSED);
  1242.                 batchError.setErrorDate(rs.getTimestamp("ERRORDATE"));
  1243.                 batchError.setRequestNo(rs.getLong("REQUESTID"));
  1244.                 batchError.setLoopCount(rs.getByte("LOOPCOUNT"));
  1245.                 errorRecordsList.add(batchError);
  1246.             }
  1247.         }
  1248.         catch(GOSIBatchException ge)
  1249.         {
  1250.             throw ge;
  1251.         }
  1252.         catch(Exception e)
  1253.         {
  1254.                 new GOSIBatchException(e,
  1255.                     "BatchCore",
  1256.                     "GOSIBatchUtilities",
  1257.                     "getBatchEror",
  1258.                     "CMN_001_ERR_1000",
  1259.                     GOSIBatchConstants.SEVERITY_ONE);        
  1260.         }
  1261.         finally
  1262.         {
  1263.             GOSIBatchUtilities.cleanUp(rs, ps, connection);
  1264.         }
  1265.         return errorRecordsList;   
  1266.     }
  1267. /**
  1268.  * @METHOD NAME              : updateRunInstance
  1269.  * @INFORMATION              : This method updates the running instance of the batch
  1270.                                 is as in progress jux before the batch is started.
  1271.                                 This method is called by the BatchDriver jux before calling the individual
  1272.                                 batch controller
  1273.  * @PARAM                    : batchId
  1274.  * @RETURN                   : NIL
  1275.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  1276.  * @LAST MODIFIED BY         :
  1277.  * @LAST MODIFIED DATE       :
  1278. **/
  1279.    
  1280.     public static void updateRunInstance(String batchId)
  1281.     throws GOSIBatchException
  1282.     {
  1283.         Connection connection=null;
  1284.         PreparedStatement ps=null;
  1285.         ResultSet rs=null;
  1286.         try
  1287.         {
  1288.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1004");
  1289.             connection=GOSIBatchUtilities.
  1290.             getDbConnection(GOSIBatchConstants.COMMON);
  1291.             ps=connection.prepareStatement(query);
  1292.             ps.setTimestamp(1,getSystemDate());
  1293.             ps.setString(2, GOSIBatchConstants.BATCH_IN_PROGRESS);
  1294.             ps.setString(3, batchId);
  1295.             int result=ps.executeUpdate();
  1296.             connection.commit();
  1297.         }
  1298.         catch(Exception e)
  1299.         {
  1300.                 new GOSIBatchException(e,
  1301.                     "BatchCore",
  1302.                     "GOSIBatchUtilities",
  1303.                     "updateRunInstance",
  1304.                     "CMN_001_ERR_1000",
  1305.                     GOSIBatchConstants.SEVERITY_ONE);        
  1306.            
  1307.  
  1308.         }
  1309.         finally
  1310.         {
  1311.             GOSIBatchUtilities.cleanUp(rs, ps, connection);
  1312.         }
  1313.     }
  1314. /**
  1315.  * @METHOD NAME              : commitRecords
  1316.  * @INFORMATION              : This method commits all batch frame
  1317.  *                              work data base operation and as well as logs the error records and updates the restart keys
  1318.                                 This method is called when the batch is running for all the records
  1319.  * @PARAM                    : batchErrorList, batchRestart, batchMaster,
  1320.                                 connection
  1321.  * @RETURN                   : NIL
  1322.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  1323.  * @LAST MODIFIED BY         :
  1324.  * @LAST MODIFIED DATE       :
  1325. **/
  1326.  
  1327.     public static void commitRecords(ArrayList batchErrorList,
  1328.                                     BatchRestart batchRestart
  1329.                                     ,BatchMaster batchMaster,
  1330.                                     Connection connection)
  1331.     throws GOSIBatchException
  1332.     {
  1333.        
  1334.        
  1335.         try
  1336.         {
  1337.             // Executing the workflow insertions
  1338.             psInsertWorkflow.executeBatch();
  1339.             psInsertRangeCheck.executeBatch();
  1340.             psInsertTXNMap.executeBatch();
  1341.             // Executing the Batch run requests
  1342.             /*Start : To place a request for a batch through a batch*/
  1343.             psInsertBatchRequest.executeBatch();
  1344.             psInsertParamValues.executeBatch();
  1345.             /*End : To place a request for a batch through a batch*/
  1346.             // Calling logErrors to log error records if error list is not null
  1347.             if(batchErrorList!=null)
  1348.             {
  1349.                 logErrors(batchMaster,batchErrorList,connection);
  1350.             }
  1351.             // Calling logRestartKeys is the restart key bean is not null
  1352.             if(batchRestart!=null)
  1353.             {
  1354.                 logRestartKeys(batchMaster,batchRestart,connection);
  1355.             }
  1356.             connection.commit();
  1357.         }
  1358.         catch(GOSIBatchException ge)
  1359.         {
  1360.             throw ge;
  1361.         }
  1362.         catch(Exception e)
  1363.         {
  1364.             new GOSIBatchException(e,
  1365.                     "BatchCore",
  1366.                     "GOSIBatchUtilities",
  1367.                     "commitRecords",
  1368.                     "CMN_001_ERR_1000",
  1369.                     GOSIBatchConstants.SEVERITY_ONE);
  1370.         }
  1371.     }
  1372.  
  1373. /**
  1374.  * @METHOD NAME              : commitRecords
  1375.  * @INFORMATION              : This method commits all batch frame
  1376.  *                              work data base operation and as well as logs the error records
  1377.                                 This method is called when the batch is running for only errorrecords
  1378.  * @PARAM                    : batchErrorList, batchMaster, connection
  1379.  * @RETURN                   : NIL
  1380.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  1381.  * @LAST MODIFIED BY         :
  1382.  * @LAST MODIFIED DATE       :
  1383. **/
  1384.  
  1385.     public static void commitRecords(ArrayList batchErrorList,
  1386.                                     BatchMaster batchMaster,
  1387.                                     Connection connection)
  1388.     throws GOSIBatchException
  1389.     {
  1390.        
  1391.        
  1392.         try
  1393.         {
  1394.             if(batchErrorList!=null)
  1395.             {
  1396.                 // Calling logErrors to log the errors
  1397.                 logErrors(batchMaster,batchErrorList,connection);
  1398.                 // Executing the workflow prepare statments
  1399.                 psInsertWorkflow.executeBatch();
  1400.                 psInsertRangeCheck.executeBatch();
  1401.                 psInsertTXNMap.executeBatch();
  1402.                     /*Start : To place a request for a batch through a batch*/
  1403.                 // Executing the batch request prepare statments
  1404.                 psInsertBatchRequest.executeBatch();
  1405.                 psInsertParamValues.executeBatch();
  1406.                 /*End : To place a request for a batch through a batch*/
  1407.  
  1408.             }
  1409.             connection.commit();
  1410.         }
  1411.         catch(GOSIBatchException ge)
  1412.         {
  1413.             throw ge;
  1414.         }
  1415.         catch(Exception e)
  1416.         {
  1417.             new GOSIBatchException(e,
  1418.                     "BatchCore",
  1419.                     "GOSIBatchUtilities",
  1420.                     "commitRecords",
  1421.                     "CMN_001_ERR_1000",
  1422.                     GOSIBatchConstants.SEVERITY_ONE);
  1423.         }
  1424.     }
  1425.   /**
  1426.  * @METHOD NAME              : deleteProcessedErrors
  1427.  * @INFORMATION              : This method deletes the processed error records
  1428.  * @PARAM                    : batchMaster, batchError
  1429.  * @RETURN                   : NIL
  1430.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  1431.  * @LAST MODIFIED BY         :
  1432.  * @LAST MODIFIED DATE       :
  1433. **/
  1434.  
  1435.     public static void deleteProcessedErrors(BatchMaster batchMaster,
  1436.                                             BatchError batchError)
  1437.     throws GOSIBatchException
  1438.     {
  1439.         try
  1440.         {
  1441.             psDeleteError.setString(1,batchMaster.getBatchId());
  1442.             psDeleteError.setString(2,batchError.getRecordIdentifiers());
  1443.             int result=psDeleteError.executeUpdate();
  1444.             batchError.setStatus(GOSIBatchConstants.TO_BE_PROCESSED);
  1445.         }
  1446.         catch(Exception e)
  1447.         {
  1448.                      new GOSIBatchException(e,
  1449.                     "BatchCore",
  1450.                     "GOSIBatchUtilities",
  1451.                     "deleteProcessedRecords",
  1452.                     "CMN_001_ERR_1000",
  1453.                     GOSIBatchConstants.SEVERITY_ONE);    
  1454.         }
  1455.     }
  1456.    
  1457.   /**
  1458.  * @METHOD NAME              : logErrors
  1459.  * @INFORMATION              : This method logs the error occured in batch
  1460.                                 Deletes the processed error records
  1461.                                 Inserts the Error records occured in this run
  1462.  * @PARAM                    : batchMaster, batchErrorList, connectoin
  1463.  * @RETURN                   : NIL
  1464.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  1465.  * @LAST MODIFIED BY         :
  1466.  * @LAST MODIFIED DATE       :
  1467. **/
  1468.   private static void logErrors(BatchMaster batchMaster,
  1469.                                 ArrayList batchErrorList,
  1470.                                 Connection connection)
  1471.                                 throws GOSIBatchException
  1472.                                  
  1473.     {
  1474.         try
  1475.         {
  1476.             BatchError batchError=null;
  1477.             // Going in loop for the list of error records
  1478.             for(int i=0;i<batchErrorList.size();i++)
  1479.             {
  1480.                 // If the status is delete calling deleteProcessedErrors
  1481.                 batchError=(BatchError)batchErrorList.get(i);
  1482.                 if(GOSIBatchConstants.DELETE_PROCESSED_ERROR_RECORD.
  1483.                 equals(batchError.getStatus()))
  1484.                 {
  1485.                     // Calling deleteProcessedErrors to delete
  1486.                     deleteProcessedErrors(batchMaster,
  1487.                                           batchError);
  1488.                     // Setting the status as not to be processed as this is already finished deletion
  1489.                     batchError.setStatus(GOSIBatchConstants.NOT_TO_BE_PROCESSED);
  1490.                 }
  1491.                 // If the status is insert calling insertErrors
  1492.                 else if(GOSIBatchConstants.INSERT_ERROR_RECORD.
  1493.                 equals(batchError.getStatus()))
  1494.                 {
  1495.                     // Calling insert to create the error record
  1496.                     insertErrors(batchMaster,
  1497.                                 batchError);
  1498.                     // Setting the status as not to be processed as this is already finished deletion
  1499.                     batchError.setStatus(GOSIBatchConstants.TO_BE_PROCESSED);
  1500.                 }
  1501.             }
  1502.         }
  1503.         catch(GOSIBatchException ge)
  1504.         {
  1505.             throw ge;
  1506.         }
  1507.         catch(Exception e)
  1508.         {
  1509.             new GOSIBatchException(e,
  1510.                     "BatchCore",
  1511.                     "GOSIBatchUtilities",
  1512.                     "logErrors",
  1513.                     "CMN_001_ERR_1000",
  1514.                     GOSIBatchConstants.SEVERITY_ONE);            
  1515.         }
  1516.     }
  1517.  
  1518. /**
  1519.  * @METHOD NAME              : insertErrors
  1520.  * @INFORMATION              : This method inserts the error records in
  1521.                                 batch erroneous records
  1522.  * @PARAM                    : batchMaster, batchError
  1523.  * @RETURN                   : NIL
  1524.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  1525.  * @LAST MODIFIED BY         :
  1526.  * @LAST MODIFIED DATE       :
  1527. **/
  1528.     public static void insertErrors(BatchMaster batchMaster,
  1529.                                 BatchError batchError)
  1530.     throws GOSIBatchException
  1531.     {
  1532.         try
  1533.         {
  1534.  
  1535.            
  1536.             psInsert.setString(1, batchMaster.getBatchId());
  1537.             psInsert.setString(2, batchError.getRecordIdentifiers());
  1538.             psInsert.setString(3, batchError.getErrorCode());
  1539.             psInsert.setString(4, GOSIBatchConstants.TO_BE_PROCESSED);
  1540.             psInsert.setInt(5, batchError.getLoopCount());
  1541.             if(batchError.getRequestNo()!=0)
  1542.             {
  1543.                 psInsert.setLong(6, batchError.getRequestNo());
  1544.             }
  1545.             else
  1546.             {
  1547.                 psInsert.setNull(6,java.sql.Types.NUMERIC);
  1548.             }
  1549.             psInsert.setTimestamp(7, new Timestamp(System.currentTimeMillis()));
  1550.             int result=psInsert.executeUpdate();
  1551.             batchError.setStatus(GOSIBatchConstants.TO_BE_PROCESSED);
  1552.         }
  1553.         catch(Exception e)
  1554.         {
  1555.                 e.printStackTrace();
  1556.                 //System.out.println(e.toString());
  1557.                    new GOSIBatchException(e,
  1558.                     "BatchCore",
  1559.                     "GOSIBatchUtilities",
  1560.                     "logErrors",
  1561.                     "CMN_001_ERR_1000",
  1562.                     GOSIBatchConstants.SEVERITY_ONE);        
  1563.         }
  1564.     }
  1565. /**
  1566.  * @METHOD NAME              : logRestartKeys
  1567.  * @INFORMATION              : This method updates the batch restart key value for each commit with the last processed record
  1568.  * @PARAM                    : batchMaster, batchRestart, connection
  1569.  * @RETURN                   : void
  1570.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  1571.  * @LAST MODIFIED BY         :
  1572.  * @LAST MODIFIED DATE       :
  1573. **/
  1574.  
  1575.     public static void logRestartKeys(BatchMaster batchMaster,
  1576.                                       BatchRestart batchRestart,
  1577.                                       Connection connection)
  1578.     throws GOSIBatchException
  1579.     {
  1580.         try
  1581.         {
  1582.            
  1583.             psLogRestart.setString(1, batchRestart.getRestartKeys());
  1584.             psLogRestart.setLong(2, batchMaster.getNoOfRecordsProcessed());
  1585.             psLogRestart.setLong(3, batchRestart.getRequestNo());
  1586.             psLogRestart.setString(4, batchMaster.getBatchId());
  1587.            
  1588.             int result=psLogRestart.executeUpdate();
  1589.         }
  1590.         catch(Exception e)
  1591.         {
  1592.                    new GOSIBatchException(e,
  1593.                     "BatchCore",
  1594.                     "GOSIBatchUtilities",
  1595.                     "logRestartKeys",
  1596.                     "CMN_001_ERR_1000",
  1597.                     GOSIBatchConstants.SEVERITY_ONE);        
  1598.         }
  1599.     }
  1600.  
  1601.   /**
  1602.  * @METHOD NAME              : updateRestartKeys
  1603.  * @INFORMATION              : This method updates batch restart keys to null when the batch is successfully completed.
  1604.                                 This method is called by the BatchDriver when the batch is successfully finished
  1605.  * @PARAM                    : batchId
  1606.  * @RETURN                   : void
  1607.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  1608.  * @LAST MODIFIED BY         :
  1609.  * @LAST MODIFIED DATE       :
  1610. **/
  1611.   public static void updateRestartKeys(String batchId)
  1612.         throws GOSIBatchException
  1613.     {
  1614.        
  1615.         Connection connection=null;
  1616.         PreparedStatement ps=null;
  1617.         try
  1618.         {
  1619.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1012");
  1620.             connection=GOSIBatchUtilities.
  1621.             getDbConnection(GOSIBatchConstants.COMMON);
  1622.             ps=connection.prepareStatement(query);
  1623.             ps.setString(1, null);
  1624.             ps.setString(2, batchId);
  1625.             int result=ps.executeUpdate();
  1626.             connection.commit();
  1627.         }
  1628.         catch(GOSIBatchException ge)
  1629.         {
  1630.             throw ge;
  1631.         }
  1632.         catch(Exception e)
  1633.         {
  1634.                    new GOSIBatchException(e,
  1635.                     "BatchCore",
  1636.                     "GOSIBatchUtilities",
  1637.                     "updateRestartKeys",
  1638.                     "CMN_001_ERR_1000",
  1639.                     GOSIBatchConstants.SEVERITY_ONE);        
  1640.         }      
  1641.     }
  1642.     /**
  1643.  * @METHOD NAME              : getErrMessageHashMap
  1644.  * @INFORMATION              : This method returns error message hashmap for
  1645.                                given batch job. This error list is the core errors and the batch id errors which are of severity of 1
  1646.  * @PARAM                    : NIL
  1647.  * @RETURN                   : class java.util.HashMap
  1648.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  1649.  * @LAST MODIFIED BY         :
  1650.  * @LAST MODIFIED DATE       :
  1651. **/
  1652.  
  1653.     public static HashMap getErrMessageHashMap()
  1654.     throws GOSIBatchException
  1655.     {  
  1656.         String errErrFileName=null;
  1657.         Connection connection=null;
  1658.         PreparedStatement ps=null;
  1659.         ResultSet rs=null;
  1660.         HashMap errMessages = new HashMap();
  1661.         try
  1662.         {
  1663.             boolean bIsArabic=true;
  1664.             if("ENGLISH".equals(GOSIBatchProperties.LANGUAGE))
  1665.             {
  1666.                 bIsArabic=false;
  1667.             }
  1668.             // Preparing the query and executing it
  1669.             connection=GOSIBatchUtilities.
  1670.             getDbConnection(GOSIBatchConstants.COMMON);
  1671.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1020");
  1672.             //System.out.println("query : "+query);
  1673.             ps=connection.prepareStatement(query);
  1674.             //System.out.println("GOSIBATCHUTILITIES : Serverity"+GOSIBatchConstants.SEVERITY_ONE);
  1675.             ps.setInt(1,GOSIBatchConstants.SEVERITY_ONE);
  1676.             rs=ps.executeQuery();
  1677.             // Loading the messages in HashMap.
  1678.             // ErrorCode as key and the message as value
  1679.             while(rs.next())
  1680.             {              
  1681.                 if(bIsArabic)
  1682.                 {
  1683.                     errMessages.put(rs.getString("ERRORCODE"),
  1684.                     rs.getString("ERRORMESSAGEAR"));
  1685.                 }
  1686.                 else
  1687.                 {
  1688.                     errMessages.put(rs.getString("ERRORCODE"),
  1689.                     rs.getString("ERRORMESSAGEEN"));
  1690.                 }
  1691.             }
  1692.         }
  1693.         catch(GOSIBatchException ge)
  1694.         {
  1695.             throw ge;
  1696.         }
  1697.         catch(Exception e)
  1698.         {
  1699.             e.printStackTrace();
  1700.             throw new GOSIBatchException(e,
  1701.             "BatchCore",
  1702.             "GOSIBatchUtilities",
  1703.             "getErrMessageHashMap",
  1704.             "CMN_001_ERR_1000",
  1705.             GOSIBatchConstants.SEVERITY_ONE);        
  1706.            
  1707.         }
  1708.         finally
  1709.         {
  1710.             GOSIBatchUtilities.cleanUp(rs, ps, connection);
  1711.         }
  1712.         return errMessages;                                
  1713.     }// end of method getErrMessageHashMap
  1714.  
  1715. /**
  1716.  * @METHOD NAME              : getErrMessageHashMapByLang
  1717.  * @INFORMATION              : This method returns error message hashmap for
  1718.  *                             given batch job.
  1719.  *                             This error list is the core errors and the batch id errors
  1720.  *                             which are of severity of 1
  1721.  *                             This method takes boolean for isLoadArabic
  1722.  * @PARAM                    : NIL
  1723.  * @RETURN                   : class java.util.HashMap
  1724.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  1725.  * @LAST MODIFIED BY         :
  1726.  * @LAST MODIFIED DATE       :
  1727. **/
  1728.  
  1729.     public static HashMap getErrMessageHashMapByLang(boolean isLoadArabic)
  1730.     throws GOSIBatchException
  1731.     {  
  1732.         String errErrFileName=null;
  1733.         Connection connection=null;
  1734.         PreparedStatement ps=null;
  1735.         ResultSet rs=null;
  1736.         HashMap errMessages = new HashMap();
  1737.         try
  1738.         {
  1739.             boolean bIsArabic=isLoadArabic;
  1740.  
  1741.             // Preparing the query and executing it
  1742.             connection=GOSIBatchUtilities.
  1743.             getDbConnection(GOSIBatchConstants.COMMON);
  1744.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1020");
  1745.             //System.out.println("query : "+query);
  1746.             ps=connection.prepareStatement(query);
  1747.             //System.out.println("GOSIBATCHUTILITIES : Serverity"+GOSIBatchConstants.SEVERITY_ONE);
  1748.             ps.setInt(1,GOSIBatchConstants.SEVERITY_ONE);
  1749.             rs=ps.executeQuery();
  1750.             // Loading the messages in HashMap.
  1751.             // ErrorCode as key and the message as value
  1752.             while(rs.next())
  1753.             {              
  1754.                 if(bIsArabic)
  1755.                 {
  1756.                     errMessages.put(rs.getString("ERRORCODE"),
  1757.                     rs.getString("ERRORMESSAGEAR"));
  1758.                 }
  1759.                 else
  1760.                 {
  1761.                     errMessages.put(rs.getString("ERRORCODE"),
  1762.                     rs.getString("ERRORMESSAGEEN"));
  1763.                 }
  1764.             }
  1765.         }
  1766.         catch(GOSIBatchException ge)
  1767.         {
  1768.             throw ge;
  1769.         }
  1770.         catch(Exception e)
  1771.         {
  1772.             e.printStackTrace();
  1773.             throw new GOSIBatchException(e,
  1774.             "BatchCore",
  1775.             "GOSIBatchUtilities",
  1776.             "getErrMessageHashMap",
  1777.             "CMN_001_ERR_1000",
  1778.             GOSIBatchConstants.SEVERITY_ONE);        
  1779.            
  1780.         }
  1781.         finally
  1782.         {
  1783.             GOSIBatchUtilities.cleanUp(rs, ps, connection);
  1784.         }
  1785.         return errMessages;                                
  1786.     }// end of method getErrMessageHashMapByLang
  1787.  
  1788.  
  1789. /**
  1790.  * @METHOD NAME              : populateSQL
  1791.  * @INFORMATION              : This method populates the module specific sql
  1792.                                queries. For the passed module id and as well as batch identifier.
  1793.                                Module name is the 3 character short name of module like CMN,PER,etc..
  1794.                                batchIdentifier is the sequncy number of the batch which is 001,002..
  1795.  * @PARAM                    : moduleName, batchIdentifier
  1796.  * @RETURN                   : class java.util.HashMap
  1797.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  1798.  * @LAST MODIFIED BY         :
  1799.  * @LAST MODIFIED DATE       :
  1800. **/
  1801.    
  1802.     public static HashMap populateSQL(String moduleName,String batchIdentifier)
  1803.     {  
  1804.        
  1805.         short moduleId=0;
  1806.         String sqlFileName=null;
  1807.         //System.out.println(moduleName);
  1808.         // Getting the module id for the module name
  1809.         if((GOSIBatchConstants.COMMON).equals(moduleName))
  1810.         {
  1811.             moduleId=GOSIBatchConstants.COMMON_ID;
  1812.         }            
  1813.         else if((GOSIBatchConstants.REGISTRATION).equals(moduleName))
  1814.         {
  1815.             moduleId=GOSIBatchConstants.REGISTRATION_ID;
  1816.         }
  1817.         else if((GOSIBatchConstants.CONTRIBUTION).equals(moduleName))
  1818.         {
  1819.             moduleId=GOSIBatchConstants.CONTRIBUTION_ID;
  1820.         }
  1821.         else if((GOSIBatchConstants.OCCUPATIONAL_HAZARDS).equals(moduleName))
  1822.         {
  1823.                 moduleId=GOSIBatchConstants.OCCUPATIONAL_HAZARDS_ID;    
  1824.         }
  1825.         else if((GOSIBatchConstants.ANNUITIES).equals(moduleName))
  1826.         {
  1827.                 moduleId=GOSIBatchConstants.ANNUITIES_ID;
  1828.         }
  1829.         else if((GOSIBatchConstants.BUDGET).equals(moduleName))
  1830.         {
  1831.             moduleId=GOSIBatchConstants.BUDGET_ID;
  1832.         }
  1833.         else if((GOSIBatchConstants.FINANCE).equals(moduleName))
  1834.         {
  1835.             moduleId=GOSIBatchConstants.FINANCE_ID;
  1836.         }
  1837.         else if((GOSIBatchConstants.INVESTMENT).equals(moduleName))
  1838.         {
  1839.             moduleId=GOSIBatchConstants.INVESTMENT_ID;
  1840.         }
  1841.         else if((GOSIBatchConstants.FIXED_ASSET).equals(moduleName))
  1842.         {
  1843.             moduleId=GOSIBatchConstants.FIXED_ASSET_ID;
  1844.         }
  1845.         else if((GOSIBatchConstants.INVENTORY).equals(moduleName))
  1846.         {
  1847.             moduleId=GOSIBatchConstants.INVENTORY_ID;
  1848.         }
  1849.         else if((GOSIBatchConstants.PURCHASE).equals(moduleName))
  1850.         {
  1851.             moduleId=GOSIBatchConstants.PURCHASE_ID;
  1852.         }
  1853.         else if((GOSIBatchConstants.CONTRACT).equals(moduleName))
  1854.         {
  1855.             moduleId=GOSIBatchConstants.CONTRACT_ID;
  1856.         }
  1857.         else if((GOSIBatchConstants.REAL_ESTATE).equals(moduleName))
  1858.         {
  1859.             moduleId=GOSIBatchConstants.REAL_ESTATE_ID;
  1860.         }
  1861.         else if((GOSIBatchConstants.PERSONNEL).equals(moduleName))
  1862.         {
  1863.             moduleId=GOSIBatchConstants.PERSONNEL_ID;
  1864.         }
  1865.         else if((GOSIBatchConstants.PROJECT).equals(moduleName))
  1866.         {
  1867.             moduleId=GOSIBatchConstants.PROJECT_ID;
  1868.         }
  1869.         else if((GOSIBatchConstants.INTERFACE).equals(moduleName))
  1870.         {
  1871.             moduleId=GOSIBatchConstants.INTERFACE_ID;
  1872.         }
  1873.         else if((GOSIBatchConstants.DATAWAREHOUSING).equals(moduleName))
  1874.         {
  1875.             moduleId=GOSIBatchConstants.DATAWAREHOUSING_ID;
  1876.         }
  1877.         else if((GOSIBatchConstants.COMMON_FUT).equals(moduleName))
  1878.         {
  1879.             moduleId=GOSIBatchConstants.COMMON_FUT_ID;
  1880.         }
  1881.         else if((GOSIBatchConstants.INTERNET).equals(moduleName))
  1882.         {
  1883.             moduleId=GOSIBatchConstants.INTERNET_ID;
  1884.         }
  1885.         else if((GOSIBatchConstants.RPA).equals(moduleName))
  1886.         {
  1887.             moduleId=GOSIBatchConstants.RPA_ID;
  1888.         }
  1889.         // getting the SQL file name for the module id
  1890.         switch(moduleId)
  1891.         {  
  1892.             case(GOSIBatchConstants.COMMON_ID):
  1893.                    
  1894.                 sqlFileName =
  1895.                         GOSIBatchProperties.COMMON_SQL_FILE;
  1896.                 break;
  1897.  
  1898.              case(GOSIBatchConstants.REGISTRATION_ID):
  1899.                 sqlFileName =
  1900.                         GOSIBatchProperties.REGISTRATION_SQL_FILE;
  1901.                 break;
  1902.             case(GOSIBatchConstants.CONTRIBUTION_ID):
  1903.                 sqlFileName =
  1904.                         GOSIBatchProperties.CONTRIBUTION_SQL_FILE;
  1905.                 break;
  1906.             case(GOSIBatchConstants.OCCUPATIONAL_HAZARDS_ID):
  1907.                 sqlFileName =
  1908.                         GOSIBatchProperties.OCCUPATIONAL_HAZARDS_SQL_FILE;
  1909.                 break;
  1910.              case(GOSIBatchConstants.ANNUITIES_ID):
  1911.                 sqlFileName =
  1912.                         GOSIBatchProperties.ANNUITIES_SQL_FILE;
  1913.                 break;
  1914.              case(GOSIBatchConstants.BUDGET_ID):
  1915.                 sqlFileName =
  1916.                         GOSIBatchProperties.BUDGET_SQL_FILE;
  1917.                 break;
  1918.              case(GOSIBatchConstants.FINANCE_ID):
  1919.                 sqlFileName =
  1920.                         GOSIBatchProperties.FINANCE_SQL_FILE;
  1921.                 break;
  1922.              case(GOSIBatchConstants.INVESTMENT_ID):
  1923.                 sqlFileName =
  1924.                         GOSIBatchProperties.INVESTMENT_SQL_FILE;
  1925.                 break;
  1926.              case(GOSIBatchConstants.FIXED_ASSET_ID):
  1927.                 sqlFileName =
  1928.                         GOSIBatchProperties.FIXED_ASSET_SQL_FILE;
  1929.                 break;
  1930.              case(GOSIBatchConstants.INVENTORY_ID):
  1931.                 sqlFileName =
  1932.                         GOSIBatchProperties.INVENTORY_SQL_FILE;
  1933.                 break;
  1934.             case(GOSIBatchConstants.PURCHASE_ID):
  1935.                 sqlFileName =
  1936.                         GOSIBatchProperties.PURCHASE_SQL_FILE;
  1937.                 break;
  1938.             case(GOSIBatchConstants.CONTRACT_ID):
  1939.                 sqlFileName =
  1940.                         GOSIBatchProperties.CONTRACT_SQL_FILE;
  1941.                 break;
  1942.             case(GOSIBatchConstants.REAL_ESTATE_ID):
  1943.                 sqlFileName =
  1944.                         GOSIBatchProperties.REAL_ESTATE_SQL_FILE;
  1945.                 break;
  1946.             case(GOSIBatchConstants.PERSONNEL_ID):
  1947.                 sqlFileName =
  1948.                         GOSIBatchProperties.PERSONNEL_SQL_FILE;
  1949.                 break;
  1950.             case(GOSIBatchConstants.PROJECT_ID):
  1951.                 sqlFileName =
  1952.                         GOSIBatchProperties.PROJECT_SQL_FILE;
  1953.                 break;
  1954.             case(GOSIBatchConstants.INTERFACE_ID):
  1955.                 sqlFileName =
  1956.                 GOSIBatchProperties.INTERFACE_SQL_FILE;
  1957.                 break;
  1958.             case(GOSIBatchConstants.DATAWAREHOUSING_ID):
  1959.                 sqlFileName =
  1960.                 GOSIBatchProperties.DATAWAREHOUSING_SQL_FILE;                
  1961.                 break;
  1962.             case (GOSIBatchConstants.COMMON_FUT_ID):
  1963.                 sqlFileName =
  1964.                 GOSIBatchProperties.COMMON_FUT_SQL_FILE;                
  1965.                 break;
  1966.             case (GOSIBatchConstants.INTERNET_ID):
  1967.                 sqlFileName =
  1968.                 GOSIBatchProperties.INTERNET_SQL_FILE;                
  1969.                 break;        
  1970.             case (GOSIBatchConstants.RPA_ID):
  1971.                 sqlFileName =
  1972.                 GOSIBatchProperties.RPA_SQL_FILE;                
  1973.                 break;  
  1974.              default :
  1975.                 break ;
  1976.  
  1977.             }// end of switch for assigning Error input fileNames
  1978.  
  1979.             //System.out.println("SQL FILE NAME IS : "+sqlFileName);
  1980.             // Creating the haspmap for loading the data
  1981.             HashMap sqlStrings = new HashMap();
  1982.             try
  1983.             {  
  1984.                 // Opening the SQL file
  1985.                 File sqlFile = new File(sqlFileName);
  1986.                 if(!sqlFile.exists())
  1987.                 {  
  1988.                     return null; // returns null if no file exists
  1989.                                     // for any modules
  1990.                 }
  1991.                 else
  1992.                 {  
  1993.                     // Reading the data
  1994.                     FileReader fr = new FileReader(sqlFile);
  1995.                     BufferedReader br = new BufferedReader(fr);
  1996.                     String lineValue =null;                                                    
  1997.                     READNEWLINE:while((lineValue= br.readLine()) != null)
  1998.                     {
  1999.                         if("".equals(lineValue))
  2000.                         {
  2001.                             continue READNEWLINE;
  2002.                         }
  2003.                         // Taking the ling in StringTokenizer
  2004.                         StringTokenizer str =
  2005.                             new StringTokenizer(lineValue,"#");
  2006.                                                                                                                    
  2007.                         String sqlCode ="";
  2008.                         String sqlString    = "";
  2009.                         // Taking the sql code and sql from the StringTokenizer
  2010.                         if(str.hasMoreTokens())
  2011.                         {  
  2012.                             sqlCode = str.nextToken().trim();
  2013.                         }
  2014.                         if(str.hasMoreTokens())
  2015.                         {
  2016.                             sqlString     = str.nextToken().trim();
  2017.                         }                                                                                      
  2018.                         if((!("".equals(sqlCode)))
  2019.                             &&(!("".equals(sqlString)))
  2020.                           )
  2021.                         {
  2022.                                                
  2023.                             // putting the error numbers,messages
  2024.                             //into hashtabales
  2025.                             // If the module is common or INTERFACE then reading all the queries and loading in hash map
  2026.                         if((moduleName.equals(GOSIBatchConstants.COMMON))||
  2027.                         (moduleName.equals(GOSIBatchConstants.INTERFACE)))
  2028.                         {
  2029.                             sqlStrings.put(sqlCode,sqlString);
  2030.                         }
  2031.                         // If DATAWAREHOUSING_ID also reading all the quries
  2032.                         else if(moduleId == GOSIBatchConstants.DATAWAREHOUSING_ID)
  2033.                         {
  2034.                             sqlStrings.put(sqlCode, sqlString);
  2035.                         }
  2036.                         // If the module is any other module The sequency no of the BathId should match with the 4 to 7 character of the sqlCode
  2037.                         // Sql code are having the Batch id as the first 7 characters and the _SQL and then _Sequence number.
  2038.                         // So for other modules making shure that we are loading only those quries which are related to that batch id
  2039.                         else if((sqlCode.substring(4,7)).equals(batchIdentifier))
  2040.                         {
  2041.                             sqlStrings.put(sqlCode,sqlString);
  2042.                         }
  2043.                     }
  2044.                     }//end of while
  2045.                 }//end of else                                     
  2046.             }// end of try
  2047.             catch(IOException ie)
  2048.             {
  2049.                 ie.printStackTrace();
  2050.             }                                  
  2051.         return sqlStrings;                                 
  2052.     }// end of method getErrMessageHashMap
  2053.    
  2054. /**
  2055.  * @METHOD NAME              : getBatchParams
  2056.  * @INFORMATION              : This method returns batch param values for the given
  2057.                                 batch master which has the request ids list in that date
  2058.  * @PARAM                    : batchMaster
  2059.  * @RETURN                   : class java.util.ArrayList
  2060.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  2061.  * @LAST MODIFIED BY         :
  2062.  * @LAST MODIFIED DATE       :
  2063. **/
  2064.    
  2065.     public static ArrayList getBatchParams(BatchMaster batchMaster)
  2066.     throws GOSIBatchException
  2067.     {
  2068.         ArrayList paramList=null;
  2069.         Connection connection=null;
  2070.         try
  2071.         {
  2072.             connection=GOSIBatchUtilities.
  2073.             getDbConnection(GOSIBatchConstants.COMMON);
  2074.             Long[] requestNos=getBatchRequestNo(batchMaster,connection);
  2075.             // If the batch is normal batch only on request is taken even the batch has multiple requests
  2076.             // So the return arraylist will have the list of Param beans
  2077.             if(batchMaster.getBatchType()==GOSIBatchConstants.NORMAL_JOB)
  2078.             {
  2079.                 // If the batch is normal batch calling GOSIBatchUtilities.getBatchParams to get the paramaers for the given request id
  2080.                 paramList=GOSIBatchUtilities.getBatchParams
  2081.                 (requestNos[0].longValue(),connection);
  2082.             }
  2083.             // If the batch is Adhoc that may have more than one request in the given day.
  2084.             // So the return list will have lists of param bean for each request
  2085.             else
  2086.             {
  2087.                 paramList=new ArrayList();
  2088.                 // Going in loop for each request id
  2089.                 for(int i=0;i<batchMaster.getNoOfRequests();i++)
  2090.                 {
  2091.                     // Calling GOSIBatchUtilities.getBatchParams by pasiing request id and getting the list of param beans
  2092.                     ArrayList params=GOSIBatchUtilities.getBatchParams(requestNos[i].longValue(),connection);
  2093.                     // Adding that array list to paramList
  2094.                     paramList.add(params);
  2095.                 }
  2096.             }
  2097.         }
  2098.         catch(GOSIBatchException ge)
  2099.         {
  2100.             throw ge;
  2101.         }
  2102.         catch(Exception e)
  2103.         {
  2104.             new GOSIBatchException(e,
  2105.             "BatchCore",
  2106.             "GOSIBatchUtilities",
  2107.             "getBatchParams",
  2108.             "CMN_001_ERR_1000",
  2109.             GOSIBatchConstants.SEVERITY_ONE);        
  2110.            
  2111.         }
  2112.         finally
  2113.         {
  2114.             GOSIBatchUtilities.cleanUp(connection);
  2115.         }
  2116.         return paramList;
  2117.     }
  2118.    
  2119.   /**
  2120.  * @METHOD NAME              : getBatchRequestNo
  2121.  * @INFORMATION              : This method returns request id list for the given batch id in that day
  2122.  * @PARAM                    : batchMaster, connection
  2123.  * @RETURN                   : class java.lang.Long[]
  2124.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  2125.  * @LAST MODIFIED BY         :
  2126.  * @LAST MODIFIED DATE       :
  2127. **/
  2128.   private static Long[] getBatchRequestNo(BatchMaster batchMaster,
  2129.                                             Connection connection)
  2130.     throws GOSIBatchException
  2131.     {
  2132.         PreparedStatement ps=null;
  2133.         ResultSet rs=null;
  2134.         Long[] requestNo=new Long[batchMaster.getNoOfRequests()];
  2135.         try
  2136.         {
  2137.             // Executing the query get the list of the request ids
  2138.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1024");
  2139.             ps=connection.prepareStatement(query);
  2140.             ps.setString(1,batchMaster.getBatchId());
  2141.             ps.setTimestamp(2,getSystemDate());
  2142.             rs=ps.executeQuery();
  2143.             int i=0;
  2144.             while(rs.next())
  2145.             {
  2146.                 // Adding the request ids to an array list
  2147.                 requestNo[i]=new Long(rs.getLong("REQUESTID"));
  2148.                 i++;
  2149.             }
  2150.         }
  2151.         catch(GOSIBatchException ge)
  2152.         {
  2153.             throw ge;
  2154.         }
  2155.         catch(Exception e)
  2156.         {
  2157.             new GOSIBatchException(e,
  2158.             "BatchCore",
  2159.             "GOSIBatchUtilities",
  2160.             "getBatchRequestNo",
  2161.             "CMN_001_ERR_1000",
  2162.             GOSIBatchConstants.SEVERITY_ONE);        
  2163.            
  2164.         }
  2165.         finally
  2166.         {
  2167.             GOSIBatchUtilities.cleanUp(rs);
  2168.             GOSIBatchUtilities.cleanUp(ps);
  2169.         }
  2170.         return requestNo;
  2171.     }
  2172.  /**
  2173.  * @METHOD NAME              : getBatchParams
  2174.  * @INFORMATION              : This method returns the batch params for
  2175.                                 given request number this is called when a batch is running for error records.
  2176.                                 So the errors need to be run for the given request.
  2177.  * @PARAM                    :  requestNo, connection
  2178.  * @RETURN                   :  class java.util.ArrayList
  2179.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  2180.  * @LAST MODIFIED BY         :
  2181.  * @LAST MODIFIED DATE       :
  2182. **/
  2183.  
  2184.     public static ArrayList getBatchParams(long requestNo,
  2185.                                     Connection connection)
  2186.     throws GOSIBatchException
  2187.     {
  2188.         PreparedStatement ps=null;
  2189.         ArrayList params=new ArrayList();
  2190.         ResultSet rs=null;
  2191.         boolean notFound=true;
  2192.         short paramId=(short)0;
  2193.         byte paramType=(byte)0;
  2194.         String paramValue=null;
  2195.         String paramName=null;
  2196.         try
  2197.         {
  2198.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1025");
  2199.             ps=connection.prepareStatement(query);
  2200.             ps.setLong(1,requestNo);
  2201.             rs=ps.executeQuery();
  2202.             while(rs.next())
  2203.             {
  2204.                 notFound=false;
  2205.                 BatchParam batchParam=null;
  2206.                 paramId=rs.getShort("PARAMID");
  2207.                 paramType=rs.getByte("PARAMTYPE");
  2208.                 paramValue=rs.getString("PARAMVALUE");
  2209.                 paramName=rs.getString("PARAMNAME");
  2210.                 if((paramType==GOSIBatchConstants.PARAM_MANDETORY)&&
  2211.                     (paramValue==null))
  2212.                 {
  2213.                     new GOSIBatchException(null,
  2214.                         "BatchCore",
  2215.                         "GOSIBatchUtilities",
  2216.                         "getBatchParams",
  2217.                         "CMN_001_ERR_1011",
  2218.                         GOSIBatchConstants.SEVERITY_ONE);        
  2219.                 }
  2220.                 else
  2221.                 {
  2222.                     batchParam=new BatchParam(paramId,paramValue,
  2223.                                 requestNo,paramName);
  2224.                     params.add(batchParam);
  2225.                 }
  2226.             }
  2227.             if(notFound)
  2228.             {
  2229.                     new GOSIBatchException(null,
  2230.                         "BatchCore",
  2231.                         "GOSIUtilities",
  2232.                         "getBatchParams",
  2233.                         "CMN_001_ERR_1010",
  2234.                         GOSIBatchConstants.SEVERITY_ONE);        
  2235.             }
  2236.         }
  2237.         catch(GOSIBatchException ge)
  2238.         {
  2239.             throw ge;
  2240.         }
  2241.         catch(Exception e)
  2242.         {
  2243.             new GOSIBatchException(e,
  2244.             "BatchCore",
  2245.             "GOSIBatchUtilities",
  2246.             "getBatchParams",
  2247.             "CMN_001_ERR_1000",
  2248.             GOSIBatchConstants.SEVERITY_ONE);        
  2249.         }
  2250.         finally
  2251.         {
  2252.             GOSIBatchUtilities.cleanUp(rs);
  2253.             GOSIBatchUtilities.cleanUp(ps);
  2254.         }
  2255.         return params;
  2256.     }
  2257.  /**
  2258.  * @METHOD NAME              : prepareStatments
  2259.  * @INFORMATION              : This method prepares all the common required statement
  2260.                                to process the frame work components.
  2261.                                Which are workflow , error ,restart and batch request etc
  2262.  * @PARAM                    : conn
  2263.  * @RETURN                   : NIL
  2264.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  2265.  * @LAST MODIFIED BY         :
  2266.  * @LAST MODIFIED DATE       :
  2267. **/
  2268.  
  2269.     public static void prepareStatments(Connection conn)
  2270.     throws GOSIBatchException
  2271.     {
  2272.         try
  2273.         {
  2274.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1005");
  2275.             psInsert=conn.prepareStatement(query);
  2276.             query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1007");
  2277.             psDeleteError=conn.prepareStatement(query);
  2278.             query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1006");
  2279.             psLogRestart=conn.prepareStatement(query);
  2280.             //System.out.println("psLogRestart CREATED"+psLogRestart);
  2281.             query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1027");
  2282.             psInsertWorkflow=conn.prepareStatement(query);
  2283.             query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1028");
  2284.             psInsertRangeCheck=conn.prepareStatement(query);
  2285.             query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1029");
  2286.             psInsertTXNMap=conn.prepareStatement(query);
  2287.             query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1030");
  2288.             psEmployeeNumber=conn.prepareStatement(query);
  2289.             query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1038");
  2290.             psInsertBatchRequest=conn.prepareStatement(query);
  2291.             query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1039");
  2292.             psInsertParamValues=conn.prepareStatement(query);
  2293.             query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1042");
  2294.             psCheckIsHoliday = conn.prepareStatement(query);
  2295.             query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1043");
  2296.             psFinalDate = conn.prepareStatement(query);
  2297.             query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1044");
  2298.             psNoOfHolidays = conn.prepareStatement(query);
  2299.             query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1045");
  2300.             psWeekEnds = conn.prepareStatement(query);
  2301.             query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1046");
  2302.             psOtherHolidays = conn.prepareStatement(query);
  2303.             query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1047");
  2304.             //System.out.println("Total Diff QUery : "+query);
  2305.             psTotalDiff = conn.prepareStatement(query);
  2306.            
  2307.             query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1048");
  2308.             //System.out.println("Total Diff QUery : "+query);
  2309.             psNextWorkingDay = conn.prepareStatement(query);
  2310.            
  2311.             /*End : To place a request for a batch through a batch*/
  2312.  
  2313.         }
  2314.         catch(Exception e)
  2315.         {
  2316.             new GOSIBatchException(e,
  2317.             "BatchCore",
  2318.             "GOSIBatchUtilities",
  2319.             "prepareAllStatments",
  2320.             "CMN_001_ERR_1000",
  2321.             GOSIBatchConstants.SEVERITY_ONE);        
  2322.         }
  2323.     }
  2324.   /**
  2325.  * @METHOD NAME              : startBatchWorkflow
  2326.  * @INFORMATION              : This method is used to create the batch workflow
  2327.                                 records
  2328.  * @PARAM                    : batchWorkflowParamBean, conn
  2329.  * @RETURN                   : NIL
  2330.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  2331.  * @LAST MODIFIED BY         :
  2332.  * @LAST MODIFIED DATE       :
  2333. **/
  2334.  
  2335.     public static void startBatchWorkflow(BatchWorkflowParamBean
  2336.     batchWorkflowParamBean,
  2337.     Connection conn) throws GOSIBatchException
  2338.     {
  2339.         try
  2340.         {
  2341.             batchWorkflowParamBean.setWorkflowId(
  2342.             (getPrimaryKey("T_WORKFLOWTXN",
  2343.             getSystemUser())).longValue());
  2344.             psInsertWorkflow.setLong(1, batchWorkflowParamBean.
  2345.                                         getWorkflowId());
  2346.             psInsertWorkflow.setString(2, batchWorkflowParamBean.
  2347.                                           getPrimaryKey());
  2348.             psInsertWorkflow.setShort(3, batchWorkflowParamBean.
  2349.                                           getLocation());
  2350.             psInsertWorkflow.setString(4, batchWorkflowParamBean.
  2351.                                           getRoutingCriterion());
  2352.             psInsertWorkflow.setString(5, batchWorkflowParamBean.
  2353.                                           getRecordDescription());
  2354.             psInsertWorkflow.setString(6, batchWorkflowParamBean.
  2355.                                           getCompletedStepShortName());
  2356.             psInsertWorkflow.setByte(7, batchWorkflowParamBean.
  2357.                                           getPriority());
  2358.             psInsertWorkflow.setLong(8, batchWorkflowParamBean.
  2359.                                           getTargetUserId());
  2360.             psInsertWorkflow.setShort(9, batchWorkflowParamBean.
  2361.                                           getDestinationLoactionId());
  2362.             if(batchWorkflowParamBean.getRangeCheck()==null)
  2363.             {
  2364.                 psInsertWorkflow.setByte(10,(byte)0);
  2365.             }
  2366.             else
  2367.             {
  2368.                 psInsertWorkflow.setByte(10, (byte)1);
  2369.             }
  2370.            
  2371.             psInsertWorkflow.setTimestamp(11, batchWorkflowParamBean.
  2372.                                           getWorkflowStartDate());
  2373.             psInsertWorkflow.setString(12, batchWorkflowParamBean.
  2374.                                           getParentPrimaryKey());
  2375.             psInsertWorkflow.setString(13, batchWorkflowParamBean.
  2376.                                           getComments());
  2377.             if(batchWorkflowParamBean.getGroupId()!=null)
  2378.             {
  2379.                 psInsertWorkflow.setLong(14, batchWorkflowParamBean.
  2380.                                           getGroupId().longValue());
  2381.             }
  2382.             else
  2383.             {
  2384.                 psInsertWorkflow.setNull(14,java.sql.Types.NUMERIC);
  2385.             }
  2386.             psInsertWorkflow.setLong(15, batchWorkflowParamBean.
  2387.                                           getDmsDontCheckMandatoryFlag());
  2388.             // Set the Entry time for the Workflow item.
  2389.             // Here we set the current system time (not to be confused
  2390.             // with the batch current time, which always use the time 01.00.00 AM)
  2391.             psInsertWorkflow.setTimestamp(16, new Timestamp(System.currentTimeMillis()));
  2392.  
  2393.             psInsertWorkflow.setShort(17, batchWorkflowParamBean.
  2394.                                           getDepartment());
  2395.             psInsertWorkflow.addBatch();
  2396.             BatchTransactionEntityMap batchTransactionEntityMap=
  2397.                 batchWorkflowParamBean.getTransactionEntityMap();
  2398.             if(batchTransactionEntityMap.getKeyVal1()!=null)
  2399.             {
  2400.                
  2401.                 psInsertTXNMap.setLong(1,batchWorkflowParamBean.
  2402.                                         getWorkflowId());
  2403.                 psInsertTXNMap.setString(2,batchTransactionEntityMap.getKeyVal1());
  2404.                 psInsertTXNMap.setString(3,batchTransactionEntityMap.getKeyVal2());
  2405.                 psInsertTXNMap.setString(4,batchTransactionEntityMap.getKeyVal3());
  2406.                 psInsertTXNMap.setString(5,batchTransactionEntityMap.getKeyVal4());
  2407.                 psInsertTXNMap.setString(6,batchTransactionEntityMap.getKeyVal5());
  2408.                 psInsertTXNMap.setString(7,batchTransactionEntityMap.getKeyVal6());
  2409.                 psInsertTXNMap.addBatch();
  2410.             }
  2411.             ArrayList rangeCheck=batchWorkflowParamBean.getRangeCheck();
  2412.             if(rangeCheck!=null)
  2413.             {
  2414.                 int rangeCheckSize=rangeCheck.size();
  2415.                 short sequenceNo=(short)0;
  2416.                 for(int i=0;i<rangeCheckSize;i++)
  2417.                 {
  2418.                     sequenceNo++;
  2419.                     BatchRangeCheckBean batchRangeCheckBean=(BatchRangeCheckBean)rangeCheck.get(i);
  2420.                     psInsertRangeCheck.setLong(1, batchWorkflowParamBean.
  2421.                                         getWorkflowId());
  2422.                     psInsertRangeCheck.setShort(2, batchRangeCheckBean.
  2423.                                         getRangeType());                                        
  2424.                     psInsertRangeCheck.setLong(3, batchRangeCheckBean.
  2425.                                         getRangeValue());
  2426.                     psInsertRangeCheck.setShort(4,sequenceNo);  
  2427.                     psInsertRangeCheck.addBatch();                                                            
  2428.                 }
  2429.             }
  2430.                                          
  2431.         }
  2432.         catch(Exception e)
  2433.         {
  2434.            
  2435.             new GOSIBatchException(e,
  2436.             "BatchCore",
  2437.             "GOSIBatchUtilities",
  2438.             "startBatchWorkflow",
  2439.             "CMN_001_ERR_1000",
  2440.             GOSIBatchConstants.SEVERITY_ONE);        
  2441.         }
  2442.     }
  2443.   /**
  2444.  * @METHOD NAME              : startBatchWorkflow
  2445.  * @INFORMATION              : This method is used to create the batch workflow
  2446.                                records. It will pass array of batchworkflowParam
  2447.                                 beans.
  2448.  * @PARAM                    : batchWorkflowParamBeanList, conn
  2449.  * @RETURN                   : NIL
  2450.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  2451.  * @LAST MODIFIED BY         :
  2452.  * @LAST MODIFIED DATE       :
  2453. **/
  2454.     public static void startBatchWorkflow(ArrayList
  2455.     batchWorkflowParamBeanList,
  2456.     Connection conn) throws GOSIBatchException
  2457.     {
  2458.         BatchWorkflowParamBean batchWorkflowParamBean=null;
  2459.         try
  2460.         {
  2461.            
  2462.             Long[] ids=getPrimaryKeyList("T_WORKFLOWTXN",batchWorkflowParamBeanList.size(),
  2463.             getSystemUser());
  2464.             int listSize=batchWorkflowParamBeanList.size();
  2465.             for(int j=0;j<listSize;j++)
  2466.             {
  2467.                 batchWorkflowParamBean=(BatchWorkflowParamBean)
  2468.                 batchWorkflowParamBeanList.get(j);
  2469.                 batchWorkflowParamBean.setWorkflowId(ids[j].longValue());
  2470.                
  2471.                 psInsertWorkflow.setLong(1, batchWorkflowParamBean.
  2472.                                             getWorkflowId());
  2473.                 psInsertWorkflow.setString(2, batchWorkflowParamBean.
  2474.                                             getPrimaryKey());
  2475.                 psInsertWorkflow.setShort(3, batchWorkflowParamBean.
  2476.                                             getLocation());
  2477.                 psInsertWorkflow.setString(4, batchWorkflowParamBean.
  2478.                                             getRoutingCriterion());
  2479.                 //System.out.println("@@@@@@@@@@@@@ : "+batchWorkflowParamBean.
  2480.                   //                          getRecordDescription()+"%%%%%%%%%%%%%%%%%%%");                            
  2481.                 psInsertWorkflow.setString(5, batchWorkflowParamBean.
  2482.                                             getRecordDescription());
  2483.                 psInsertWorkflow.setString(6, batchWorkflowParamBean.
  2484.                                             getCompletedStepShortName());
  2485.                 psInsertWorkflow.setByte(7, batchWorkflowParamBean.
  2486.                                             getPriority());
  2487.                 psInsertWorkflow.setLong(8, batchWorkflowParamBean.
  2488.                                             getTargetUserId());
  2489.                 psInsertWorkflow.setShort(9, batchWorkflowParamBean.
  2490.                                             getDestinationLoactionId());
  2491.                 if(batchWorkflowParamBean.getRangeCheck()==null)
  2492.                 {
  2493.                     psInsertWorkflow.setByte(10,(byte)0);
  2494.                 }
  2495.                 else
  2496.                 {
  2497.                     psInsertWorkflow.setByte(10, (byte)1);
  2498.                 }
  2499.                
  2500.                 psInsertWorkflow.setTimestamp(11, batchWorkflowParamBean.
  2501.                                             getWorkflowStartDate());
  2502.                 psInsertWorkflow.setString(12, batchWorkflowParamBean.
  2503.                                             getParentPrimaryKey());
  2504.                 psInsertWorkflow.setString(13, batchWorkflowParamBean.
  2505.                                             getComments());
  2506.                 if(batchWorkflowParamBean.getGroupId()!=null)
  2507.                 {
  2508.                     psInsertWorkflow.setLong(14, batchWorkflowParamBean.
  2509.                                               getGroupId().longValue());
  2510.                 }
  2511.                 else
  2512.                 {
  2513.                     psInsertWorkflow.setNull(14,java.sql.Types.NUMERIC);
  2514.                 }
  2515.                 psInsertWorkflow.setLong(15, batchWorkflowParamBean.
  2516.                                           getDmsDontCheckMandatoryFlag());
  2517.                 // Set the Entry time for the Workflow item.
  2518.                 // Here we set the current system time (not to be confused
  2519.                 // with the batch current time, which always use the time 01.00.00 AM)
  2520.                 psInsertWorkflow.setTimestamp(16, new Timestamp(System.currentTimeMillis()));
  2521.                
  2522.                 psInsertWorkflow.setShort(17, batchWorkflowParamBean.
  2523.                                               getDepartment());
  2524.                
  2525.                 psInsertWorkflow.addBatch();
  2526.                 BatchTransactionEntityMap batchTransactionEntityMap=
  2527.                     batchWorkflowParamBean.getTransactionEntityMap();
  2528.                 if(batchTransactionEntityMap.getKeyVal1()!=null)
  2529.                 {
  2530.                    
  2531.                     psInsertTXNMap.setLong(1,batchWorkflowParamBean.
  2532.                                             getWorkflowId());
  2533.                     psInsertTXNMap.setString(2,batchTransactionEntityMap.getKeyVal1());
  2534.                     psInsertTXNMap.setString(3,batchTransactionEntityMap.getKeyVal2());
  2535.                     psInsertTXNMap.setString(4,batchTransactionEntityMap.getKeyVal3());
  2536.                     psInsertTXNMap.setString(5,batchTransactionEntityMap.getKeyVal4());
  2537.                     psInsertTXNMap.setString(6,batchTransactionEntityMap.getKeyVal5());
  2538.                     psInsertTXNMap.setString(7,batchTransactionEntityMap.getKeyVal6());
  2539.                     psInsertTXNMap.addBatch();
  2540.                 }
  2541.                 ArrayList rangeCheck=batchWorkflowParamBean.getRangeCheck();
  2542.                 if(rangeCheck!=null)
  2543.                 {
  2544.                     int rangeCheckSize=rangeCheck.size();
  2545.                     short sequenceNo=(short)0;
  2546.                     for(int i=0;i<rangeCheckSize;i++)
  2547.                     {
  2548.                         sequenceNo++;
  2549.                         BatchRangeCheckBean batchRangeCheckBean=(BatchRangeCheckBean)rangeCheck.get(i);
  2550.                         psInsertRangeCheck.setLong(1, batchWorkflowParamBean.
  2551.                                             getWorkflowId());
  2552.                         psInsertRangeCheck.setShort(2, batchRangeCheckBean.
  2553.                                             getRangeType());                                        
  2554.                         psInsertRangeCheck.setLong(3, batchRangeCheckBean.
  2555.                                             getRangeValue());
  2556.                         psInsertRangeCheck.setShort(4,sequenceNo);  
  2557.                         psInsertRangeCheck.addBatch();                                                            
  2558.                     }
  2559.                 }
  2560.             }
  2561.                                          
  2562.         }
  2563.         catch(Exception e)
  2564.         {
  2565.            
  2566.             new GOSIBatchException(e,
  2567.             "BatchCore",
  2568.             "GOSIBatchUtilities",
  2569.             "startBatchWorkflow",
  2570.             "CMN_001_ERR_1000",
  2571.             GOSIBatchConstants.SEVERITY_ONE);        
  2572.         }
  2573.     }
  2574.    /**
  2575.  * @METHOD NAME              : getUserIdForEmployee
  2576.  * @INFORMATION              : This method returns the user id for given
  2577.                                employee
  2578.  * @PARAM                    : employeeNumber
  2579.  * @RETURN                   : long
  2580.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  2581.  * @LAST MODIFIED BY         :
  2582.  * @LAST MODIFIED DATE       :
  2583. **/
  2584.  
  2585.     public static long getUserIdForEmployee(Long employeeNumber)
  2586.     throws GOSIBatchException
  2587.     {
  2588.         ResultSet rs=null;
  2589.         long userId=0L;
  2590.         try
  2591.         {
  2592.             psEmployeeNumber.setLong(1, employeeNumber.longValue());
  2593.             psEmployeeNumber.setShort(2, GOSIBatchConstants.EMPLOYEE);
  2594.             rs=psEmployeeNumber.executeQuery();
  2595.            
  2596.             if(rs.next())
  2597.             {
  2598.                 userId=rs.getLong("ID");
  2599.             }
  2600.             else
  2601.             {
  2602.                 new GOSIBatchException(null,
  2603.                 "BatchCore",
  2604.                 "GOSIBatchUtilities",
  2605.                 "startBatchWorkflow",
  2606.                 "CMN_001_ERR_1000",
  2607.                 GOSIBatchConstants.SEVERITY_TWO);        
  2608.             }
  2609.         }
  2610.         catch(GOSIBatchException ge)
  2611.         {
  2612.             throw ge;
  2613.         }
  2614.         catch(Exception e)
  2615.         {
  2616.             new GOSIBatchException(e,
  2617.             "BatchCore",
  2618.             "GOSIBatchUtilities",
  2619.             "startBatchWorkflow",
  2620.             "CMN_001_ERR_1000",
  2621.             GOSIBatchConstants.SEVERITY_ONE);        
  2622.         }
  2623.         finally
  2624.         {
  2625.             GOSIBatchUtilities.cleanUp(rs);
  2626.         }
  2627.         return userId;
  2628.     }
  2629.    
  2630.     public static ArrayList onlineTaskList=new ArrayList();
  2631.    
  2632.   /**
  2633.  * @METHOD NAME              : disableOnlineMenu
  2634.  * @INFORMATION              : This method will be called by batch driver
  2635.                                before executing the batch process, and this will
  2636.                                disable all the dependent online links to not
  2637.                                available till the completion of batch job
  2638.  * @PARAM                    : batchId
  2639.  * @RETURN                   : void
  2640.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  2641.  * @LAST MODIFIED BY         :
  2642.  * @LAST MODIFIED DATE       :
  2643. **/
  2644.   public static void disableOnlineMenu(String batchId)
  2645.     throws GOSIBatchException
  2646.     {
  2647.         Connection conn=null;
  2648.         ResultSet rs=null;
  2649.         PreparedStatement ps=null;
  2650.         long id=0L;
  2651.         byte type=(byte)0;
  2652.         BatchOnlineDependentTaskBean
  2653.         batchOnlineDependentTaskBean = null;
  2654.         try
  2655.         {
  2656.             // Executing the query to the list of task depends on the batch id
  2657.             // Which gets the task id and as well task type whether menu or work flow
  2658.             conn=GOSIBatchUtilities.getDbConnection(GOSIBatchConstants.COMMON);
  2659.             ps=conn.prepareStatement(GOSIBatchSQL.getSqlString("CMN_001_SQL_1031"));
  2660.             ps.setString(1,batchId);
  2661.             ps.setString(2,batchId);
  2662.             rs=ps.executeQuery();
  2663.            
  2664.             while(rs.next())
  2665.             {
  2666.                 // Populating them into batchOnlineDependentTaskBean
  2667.                 batchOnlineDependentTaskBean=
  2668.                 new BatchOnlineDependentTaskBean(rs.getLong("ID"),rs.getByte("TYPE"),rs.getShort("COUNTER"));
  2669.                 // Adding them to list
  2670.                 onlineTaskList.add(batchOnlineDependentTaskBean);
  2671.             }
  2672.             // If some task are dependent calling performActionOnLinks my sending theflag as DISABLELINKS
  2673.             if(onlineTaskList.size()!=0)
  2674.             {
  2675.                 performActionOnLinks(GOSIBatchConstants.DISABLELINKS,conn,batchId);
  2676.             }
  2677.         }
  2678.         catch(GOSIBatchException ge)
  2679.         {
  2680.             try
  2681.             {
  2682.               if (conn != null )
  2683.                 conn.rollback();
  2684.             }
  2685.             catch (Exception ex){ /* Ignore */}
  2686.  
  2687.        
  2688.             throw ge;
  2689.         }
  2690.         catch(Exception e)
  2691.         {
  2692.             try
  2693.             {
  2694.                 if (conn != null )
  2695.                 conn.rollback();
  2696.             }
  2697.             catch (Exception ex){ /* Ignore */}
  2698.  
  2699.            
  2700.  
  2701.             new GOSIBatchException(e,
  2702.             "BatchCore",
  2703.             "GOSIBatchUtilities",
  2704.             "startBatchWorkflow",
  2705.             "CMN_001_ERR_1000",
  2706.             GOSIBatchConstants.SEVERITY_ONE);        
  2707.         }
  2708.         finally
  2709.         {
  2710.             GOSIBatchUtilities.cleanUp(rs,ps,conn);
  2711.         }
  2712.     }
  2713.    /**
  2714.  * @METHOD NAME              : enableOnlineMenu
  2715.  * @INFORMATION              : This method will be called by batch driver once the
  2716.                                batch job completed. THis enables all the
  2717.                                dependent tasks.
  2718.  * @PARAM                    : batchId
  2719.  * @RETURN                   : NIL
  2720.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  2721.  * @LAST MODIFIED BY         :
  2722.  * @LAST MODIFIED DATE       :
  2723. **/
  2724.  
  2725.     public static void enableOnlineMenu(String batchId)
  2726.     throws GOSIBatchException
  2727.     {
  2728.  
  2729.         Connection conn=null;
  2730.         ResultSet rs=null;
  2731.         PreparedStatement ps=null;
  2732.         long id=0L;
  2733.         byte type=(byte)0;
  2734.         BatchOnlineDependentTaskBean
  2735.         batchOnlineDependentTaskBean = null;
  2736.         try
  2737.         {
  2738.             // Executing the query to the list of task depends on the batch id
  2739.             // Which gets the task id and as well task type whether menu or work flow
  2740.             conn=GOSIBatchUtilities.getDbConnection(GOSIBatchConstants.COMMON);
  2741.             ps=conn.prepareStatement(GOSIBatchSQL.getSqlString("CMN_001_SQL_1031"));
  2742.             ps.setString(1,batchId);
  2743.             ps.setString(2,batchId);
  2744.             rs=ps.executeQuery();
  2745.            
  2746.             while(rs.next())
  2747.             {
  2748.                 // Populating them into batchOnlineDependentTaskBean
  2749.                 batchOnlineDependentTaskBean=
  2750.                 new BatchOnlineDependentTaskBean(rs.getLong("ID"),rs.getByte("TYPE"),rs.getShort("COUNTER"));
  2751.                 // Adding them to list
  2752.                 onlineTaskList.add(batchOnlineDependentTaskBean);
  2753.             }
  2754.             // If some task are dependent calling performActionOnLinks my sending theflag as DISABLELINKS
  2755.             if(onlineTaskList.size()!=0)
  2756.             {
  2757.                 performActionOnLinks(GOSIBatchConstants.ENABLELINKS,conn,batchId);
  2758.             }
  2759.         }
  2760.         catch(GOSIBatchException ge)
  2761.         {
  2762.             try
  2763.             {
  2764.             if (conn != null )
  2765.                 conn.rollback();
  2766.             }
  2767.             catch (Exception ex){ /* Ignore */}
  2768.  
  2769.             throw ge;
  2770.         }
  2771.         catch(Exception e)
  2772.         {
  2773.             try
  2774.             {
  2775.             if (conn != null )
  2776.                 conn.rollback();
  2777.             }
  2778.             catch (Exception ex){ /* Ignore */}
  2779.  
  2780.             new GOSIBatchException(e,
  2781.             "BatchCore",
  2782.             "GOSIBatchUtilities",
  2783.             "startBatchWorkflow",
  2784.             "CMN_001_ERR_1000",
  2785.             GOSIBatchConstants.SEVERITY_ONE);        
  2786.         }
  2787.         finally
  2788.         {
  2789.             GOSIBatchUtilities.cleanUp(rs,ps,conn);
  2790.         }
  2791.     }
  2792.        
  2793.  /**
  2794.  * @METHOD NAME              : performActionOnLinks
  2795.  * @INFORMATION              : This method changes the status of task.
  2796.  * @PARAM                    : flag, conn, batchId
  2797.  * @RETURN                   : NIL
  2798.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  2799.  * @LAST MODIFIED BY         :
  2800.  * @LAST MODIFIED DATE       :
  2801. **/
  2802.    private static void performActionOnLinks(byte flag,
  2803.     Connection conn,String batchId) throws GOSIBatchException
  2804.     {
  2805.         PreparedStatement psMenu=null;
  2806.         PreparedStatement psWorkflow=null;
  2807.         try
  2808.         {
  2809.             // Getting intial context
  2810.             getDirContext();
  2811.             // Preaparing query to update workflow task in DB
  2812.             psWorkflow=conn.prepareStatement(GOSIBatchSQL.
  2813.             getSqlString("CMN_001_SQL_1032"));
  2814.             // Preaparing query to update menu task in DB
  2815.             psMenu=conn.prepareStatement(GOSIBatchSQL.
  2816.             getSqlString("CMN_001_SQL_1033"));
  2817.             int listSize=onlineTaskList.size();
  2818.             BatchOnlineDependentTaskBean batchOnlineDependentTaskBean=null;
  2819.             // Going in loop for updating the links in LDAP
  2820.             for(int i=0;i<listSize;i++)
  2821.             {
  2822.                 batchOnlineDependentTaskBean=(BatchOnlineDependentTaskBean)
  2823.                 onlineTaskList.get(i);
  2824.                
  2825.                 if(flag==GOSIBatchConstants.ENABLELINKS)
  2826.                 {
  2827.                     if (batchOnlineDependentTaskBean.getCounter()> 0)
  2828.                     {
  2829.                         if(batchOnlineDependentTaskBean.getType()==(byte)1)
  2830.                         {
  2831.                             psWorkflow.setShort(1,(short)(batchOnlineDependentTaskBean.getCounter()-1));
  2832.                             psWorkflow.setLong(2,batchOnlineDependentTaskBean.getId());
  2833.                             psWorkflow.executeQuery();
  2834.                             updateWorkflowItemInLDAP((short)(batchOnlineDependentTaskBean.getCounter()-1),
  2835.                                 batchOnlineDependentTaskBean.getId());             
  2836.                         }
  2837.                         else
  2838.                         {
  2839.                             psMenu.setShort(1,(short)(batchOnlineDependentTaskBean.getCounter()-1));
  2840.                             psMenu.setLong(2,batchOnlineDependentTaskBean.getId());
  2841.                             psMenu.executeQuery();
  2842.                             updateMenuItemInLDAP((short)(batchOnlineDependentTaskBean.getCounter()-1),
  2843.                                 batchOnlineDependentTaskBean.getId());                         
  2844.                         }
  2845.                     }
  2846.                 }
  2847.                 else
  2848.                 {
  2849.                     if(batchOnlineDependentTaskBean.getType()==(byte)1)
  2850.                     {
  2851.                         psWorkflow.setShort(1,(short)(batchOnlineDependentTaskBean.getCounter()+1));
  2852.                         psWorkflow.setLong(2,batchOnlineDependentTaskBean.getId());
  2853.                         psWorkflow.executeQuery();
  2854.                         updateWorkflowItemInLDAP((short)(batchOnlineDependentTaskBean.getCounter()+1),
  2855.                             batchOnlineDependentTaskBean.getId());
  2856.                        
  2857.                     }
  2858.                     else
  2859.                     {
  2860.                         psMenu.setShort(1,(short)(batchOnlineDependentTaskBean.getCounter()+1));
  2861.                         psMenu.setLong(2,batchOnlineDependentTaskBean.getId());
  2862.                         psMenu.executeQuery();
  2863.                         updateMenuItemInLDAP((short)(batchOnlineDependentTaskBean.getCounter()+1),
  2864.                             batchOnlineDependentTaskBean.getId());
  2865.                        
  2866.                     }
  2867.                 }
  2868.  
  2869.                 // Depending on the type of the link calling the appropriate method to update
  2870.                
  2871.             }
  2872.         }
  2873.         catch(Exception e)
  2874.         {
  2875.             new GOSIBatchException(e,
  2876.             "BatchCore",
  2877.             "GOSIBatchUtilities",
  2878.             "performActionOnLinks",
  2879.             "CMN_001_ERR_1000",
  2880.             GOSIBatchConstants.SEVERITY_ONE);        
  2881.         }
  2882.     }
  2883.   /**
  2884.  * @METHOD NAME              : updateWorkflowItemInLDAP
  2885.  * @INFORMATION              : This method updates the batch running status
  2886.                                flag of workflow task in LDAP
  2887.  * @PARAM                    : flag, id
  2888.  * @RETURN                   : NIL
  2889.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  2890.  * @LAST MODIFIED BY         :
  2891.  * @LAST MODIFIED DATE       :
  2892. **/
  2893.  
  2894.     private static void updateWorkflowItemInLDAP(short flag,long id)
  2895.     throws GOSIBatchException
  2896.     {
  2897.         try
  2898.         {
  2899.               String distinguishedName = "id="+id+
  2900.                                     ","+GOSIBatchProperties.GOSI_LDAP_ROOT_SUFFIX;
  2901.               ModificationItem mods[] = new ModificationItem[1];
  2902.               mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
  2903.               new BasicAttribute("batchrunningstatus", new Short(flag).toString()));
  2904.               ctx.modifyAttributes(distinguishedName, mods);
  2905.    
  2906.         }
  2907.         catch(Exception e)
  2908.         {
  2909.             new GOSIBatchException(e,
  2910.             "BatchCore",
  2911.             "GOSIBatchUtilities",
  2912.             "updateWorkflowItemInLDAP",
  2913.             "CMN_001_ERR_1000",
  2914.             GOSIBatchConstants.SEVERITY_ONE);        
  2915.         }
  2916.     }
  2917.    /**
  2918.  * @METHOD NAME              : updateWorkflowItemInLDAP
  2919.  * @INFORMATION              : This method updates the batch running status
  2920.                                flag of menu task in LDAP
  2921.  * @PARAM                    : flag, id
  2922.  * @RETURN                   : NIL
  2923.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  2924.  * @LAST MODIFIED BY         :
  2925.  * @LAST MODIFIED DATE       :
  2926. **/
  2927.    
  2928.     private static void updateMenuItemInLDAP(short flag,long id)
  2929.     throws GOSIBatchException
  2930.     {
  2931.         try
  2932.         {
  2933.               //System.out.println("ID IN menu TASK"+id);
  2934.               String distinguishedName = "menutaskid="+id+
  2935.                                     ","+GOSIBatchProperties.GOSI_LDAP_ROOT_SUFFIX;
  2936.               ModificationItem mods[] = new ModificationItem[1];
  2937.               mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
  2938.               new BasicAttribute("batchrunningstatus", new Short(flag).toString()));
  2939.               ctx.modifyAttributes(distinguishedName, mods);
  2940.    
  2941.         }
  2942.         catch(Exception e)
  2943.         {
  2944.             new GOSIBatchException(e,
  2945.             "BatchCore",
  2946.             "GOSIBatchUtilities",
  2947.             "updateMenuItemInLDAP",
  2948.             "CMN_001_ERR_1000",
  2949.             GOSIBatchConstants.SEVERITY_ONE);        
  2950.         }
  2951.     }
  2952.    
  2953.     private static InitialLdapContext ctx =  null;
  2954.   /**
  2955.  * @METHOD NAME              : getDirContext
  2956.  * @INFORMATION              : THis method sets the LDAP context to the processor
  2957.  * @PARAM                    : NIL
  2958.  * @RETURN                   : NIL
  2959.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  2960.  * @LAST MODIFIED BY         :
  2961.  * @LAST MODIFIED DATE       :
  2962. **/
  2963.  
  2964.     private static void getDirContext()
  2965.     throws GOSIBatchException
  2966.     {
  2967.        
  2968.         Hashtable env = null;
  2969.         Hashtable envAnonymous = null;
  2970.         try
  2971.         {
  2972.             env = new Hashtable();
  2973.             env.put(Context.INITIAL_CONTEXT_FACTORY,
  2974.             "com.sun.jndi.ldap.LdapCtxFactory");
  2975.             env.put(Context.PROVIDER_URL,
  2976.                 GOSIBatchProperties.GOSI_LDAP_URL);
  2977.             env.put(Context.SECURITY_AUTHENTICATION,"simple");
  2978.             env.put(Context.SECURITY_PRINCIPAL,
  2979.                 GOSIBatchProperties.GOSI_LDAP_ADMIN_UID);
  2980.             env.put(Context.SECURITY_CREDENTIALS,
  2981.                 GOSIBatchProperties.GOSI_LDAP_ADMIN_PASSWORD);
  2982.             ctx = new InitialLdapContext(env,null);
  2983.         }
  2984.         catch(Exception e)
  2985.         {
  2986.             new GOSIBatchException(e,
  2987.             "BatchCore",
  2988.             "GOSIBatchUtilities",
  2989.             "performActionOnLinks",
  2990.             "CMN_001_ERR_1000",
  2991.             GOSIBatchConstants.SEVERITY_ONE);        
  2992.         }
  2993.        
  2994.     }// END OF METHOD  getDirContext()        
  2995.    
  2996.     /**
  2997.  * @METHOD NAME              : setSuccessfulRunDate
  2998.  * @INFORMATION              : This method sets the successful rundate  to the current date.
  2999.                                 This method is called by the batch driver when the batch is completed successfully
  3000.  * @PARAM                    : batchId, connection
  3001.  * @RETURN                   : void
  3002.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  3003.  * @LAST MODIFIED BY         :
  3004.  * @LAST MODIFIED DATE       :
  3005. **/
  3006.  
  3007.     public static void setSuccessfulRunDate(String batchId,Connection connection)
  3008.     throws GOSIBatchException
  3009.     {
  3010.         try
  3011.         {
  3012.             String query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1011");            
  3013.             psRestartKeyUpdate = connection.prepareStatement(query);
  3014.             //System.out.println("GOSIBatchUtilities : setSuccessfulRundate :"+
  3015.             //  " called for Batch ID "+GOSIBatchUtilities.getSystemDate());
  3016.             psRestartKeyUpdate.setTimestamp(1,GOSIBatchUtilities.getSystemDate());
  3017.             psRestartKeyUpdate.setString(2,batchId);            
  3018.             int updated = psRestartKeyUpdate.executeUpdate();
  3019.             //System.out.println("Update the current date for successfulrundate"+updated);
  3020.         }catch(Exception e)
  3021.         {
  3022.             new GOSIBatchException(e,
  3023.             "BatchCore",
  3024.             "GOSIBatchUtilities",
  3025.             "setSuccessfulRunDate",
  3026.             "CMN_001_ERR_1000",
  3027.             GOSIBatchConstants.SEVERITY_ONE);                          
  3028.         }        
  3029.     }
  3030. /**
  3031.  * @METHOD NAME              : setDomainData
  3032.  * @INFORMATION              : This method creates the domain data this is the interface provided to finance to create domain data in the batch
  3033.  * @PARAM                    : domainBean, connection
  3034.  * @RETURN                   : void
  3035.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  3036.  * @LAST MODIFIED BY         :
  3037.  * @LAST MODIFIED DATE       :
  3038. **/
  3039.  
  3040.     public static void setDomainData(DomainBean domainBean,
  3041.     Connection connection)
  3042.     throws GOSIBatchException
  3043.     {
  3044.         PreparedStatement psDomain = null;
  3045.         PreparedStatement psSelectMaxSequenceNumber = null;
  3046.         ResultSet rsSequenceNumber = null;
  3047.         String tempSequenceNumber = null;
  3048.         int incrSequenceNumber = 0;
  3049.         String query = null;
  3050.         int col = 0;
  3051.         try
  3052.         {      
  3053.            
  3054.         //  Insertion in Domain Tables             
  3055.             query=GOSIBatchSQL.getSqlString("INT_CMN_SQL_4026");
  3056.             //System.out.println("query="+query);
  3057.             psDomain=connection.prepareStatement(query);
  3058.            
  3059.             query = GOSIBatchSQL.getSqlString("INT_CMN_SQL_4029");
  3060.             //System.out.println("query="+query);
  3061.             psSelectMaxSequenceNumber = connection.prepareStatement(query);
  3062.            
  3063.             psSelectMaxSequenceNumber.setString(1,domainBean.getDomainName());
  3064.             psSelectMaxSequenceNumber.setLong(2,domainBean.getCategoryCode());
  3065.            
  3066.             rsSequenceNumber = psSelectMaxSequenceNumber.executeQuery();
  3067.            
  3068.             if(rsSequenceNumber.next())
  3069.             {
  3070.                 if(rsSequenceNumber.getObject(1)!= null)
  3071.                 {
  3072.                     tempSequenceNumber = rsSequenceNumber.
  3073.                     getString(1);
  3074.                 }
  3075.  
  3076.             }
  3077.             GOSIBatchUtilities.cleanUp(psSelectMaxSequenceNumber);
  3078.             GOSIBatchUtilities.cleanUp(rsSequenceNumber);
  3079.            
  3080.             //System.out.println("db seq number ***" +
  3081.             //tempSequenceNumber);
  3082.             if(tempSequenceNumber != null)
  3083.             {
  3084.                 incrSequenceNumber = Integer.parseInt(tempSequenceNumber);
  3085.                 incrSequenceNumber += 1;
  3086.                 tempSequenceNumber = "" + incrSequenceNumber;
  3087.                 domainBean.setSequenceNumber
  3088.                 (new Short(tempSequenceNumber));
  3089.             }
  3090.            
  3091.             //System.out.println("seq number ****" +
  3092.             //domainBean.getSequenceNumber());
  3093.                    
  3094.             psDomain.setInt(++col,domainBean.getDomainId());
  3095.             psDomain.setInt(++col,domainBean.getCodeLength());
  3096.             psDomain.setInt(++col,domainBean.getCodeType());
  3097.             psDomain.setString(++col,domainBean.getDomainName());
  3098.             psDomain.setLong(++col,domainBean.getCategoryCode());
  3099.             psDomain.setInt(++col,domainBean.getCode());
  3100.             psDomain.setString(++col,domainBean.getShortNameArabic());
  3101.             psDomain.setString(++col,domainBean.getShortNameEnglish());
  3102.             psDomain.setString(++col,domainBean.getLongName());
  3103.             psDomain.setLong(++col,domainBean.getCreatedBy().longValue());
  3104.             psDomain.setTimestamp(++col,domainBean.getCreationTimestamp());
  3105.            
  3106.             if(domainBean.getSequenceNumber()!= null)
  3107.             {
  3108.                 psDomain.setShort(++col,domainBean.getSequenceNumber().
  3109.                 shortValue());
  3110.             }
  3111.             else
  3112.             {
  3113.                 psDomain.setString(++col,null);
  3114.             }
  3115.             psDomain.executeUpdate();
  3116.            
  3117.             //Insertion in LDAP
  3118.                
  3119.             DirContext ctx;
  3120.             Attributes myAttrs;
  3121.  
  3122.             String domainId=null;
  3123.             String domainName=null;
  3124.             String domainCode=null;
  3125.             String codeType=null;
  3126.             String codeLength=null;
  3127.             String categoryCode=null;
  3128.             String shortNameEng=null;
  3129.             String shortNameAr=null;
  3130.             String longName=null;
  3131.             String sequenceNumber = null;
  3132. /*         
  3133.             String LDAP_URL=;
  3134.             String LDAP_ADMIN_ID="cn=Directory Manager";
  3135.             String LDAP_ADMIN_PWD="gosioffshore";
  3136.             String LDAP_ROOT_SUFFIX="o=gosi.com";
  3137. */
  3138.             Hashtable env = new Hashtable();
  3139.             env.put(Context.INITIAL_CONTEXT_FACTORY,
  3140.                 "com.sun.jndi.ldap.LdapCtxFactory");
  3141.             env.put(Context.PROVIDER_URL,GOSIBatchProperties.GOSI_LDAP_URL);
  3142.             env.put(Context.SECURITY_AUTHENTICATION,"simple");
  3143.             env.put(Context.SECURITY_PRINCIPAL,GOSIBatchProperties.GOSI_LDAP_ADMIN_UID);
  3144.             env.put(Context.SECURITY_CREDENTIALS,GOSIBatchProperties.GOSI_LDAP_ADMIN_PASSWORD);
  3145.             ctx=new InitialDirContext(env);
  3146.  
  3147.             domainId=""+domainBean.getDomainId();
  3148.             domainName=domainBean.getDomainName();
  3149.             domainCode=""+domainBean.getCode();
  3150.             codeType=""+domainBean.getCodeType();
  3151.             codeLength=""+domainBean.getCodeLength();
  3152.             categoryCode=""+domainBean.getCategoryCode();
  3153.             if("0".equals(categoryCode))
  3154.             {
  3155.                 categoryCode="0000";
  3156.             }
  3157.             shortNameEng=domainBean.getShortNameEnglish();
  3158.             shortNameAr=domainBean.getShortNameArabic();
  3159.             if(domainBean.getLongName()!=null)
  3160.             {
  3161.                 longName=domainBean.getLongName();
  3162.             }
  3163.             sequenceNumber = domainBean.getSequenceNumber()+"";
  3164.             //Domain Detail
  3165.             myAttrs = new BasicAttributes(true);  // case ignore
  3166.             Attribute oc = new BasicAttribute("objectclass");
  3167.             oc.add(0,"domaindetails");
  3168.             oc.add(1,"top");
  3169.             myAttrs.put(oc);
  3170.             myAttrs.put("code", domainCode);
  3171.             if(longName!=null)
  3172.             {
  3173.                 myAttrs.put("longname", longName);
  3174.             }
  3175.             myAttrs.put("shortnamearabic", shortNameAr);
  3176.             myAttrs.put("shortnameenglish", shortNameEng);
  3177.             myAttrs.put("sequencenumber",sequenceNumber);
  3178.            
  3179.             ctx.bind("code="+domainCode+",categorycode="
  3180.             +categoryCode+",domainname="
  3181.             +domainName+","+GOSIBatchProperties.GOSI_LDAP_ROOT_SUFFIX,null,
  3182.             myAttrs);
  3183.            
  3184.         }
  3185.         catch(Exception e)
  3186.         {
  3187.             new GOSIBatchException(e,
  3188.             "BatchCore",
  3189.             "GOSIBatchUtilities",
  3190.             "setDomainData",
  3191.             "CMN_001_ERR_1000",
  3192.             GOSIBatchConstants.SEVERITY_ONE);                          
  3193.         }
  3194.     }
  3195.  
  3196.     /**
  3197.  * @METHOD NAME              : getBaseCurrency
  3198.  * @INFORMATION              : This method returns the Base Currency
  3199.  * @PARAM                    : NIL
  3200.  * @RETURN                   : int
  3201.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  3202.  * @LAST MODIFIED BY         :
  3203.  * @LAST MODIFIED DATE       :
  3204. **/
  3205.     public static int getBaseCurrency()
  3206.     throws GOSIBatchException
  3207.     {
  3208.         int baseCurCode=0;
  3209.         try
  3210.         {
  3211.            if(currencyList!=null)
  3212.            {
  3213.             int currSize=currencyList.size();
  3214.             //System.out.println("Getbase Currency"+currSize);
  3215.             for(int i=0; i<currSize;i++)
  3216.             {
  3217.                 HashMap curDet=(HashMap)currencyList.get(i);
  3218.                 int curType=Integer.parseInt(""+curDet.get("type"));
  3219.                 if (curType==1)
  3220.                 {
  3221.                     baseCurCode=Integer.parseInt(""+curDet.get("code"));
  3222.                     break;
  3223.                 }
  3224.             }
  3225.            }  
  3226.         }
  3227.         catch(Exception e)
  3228.         {
  3229.             throw new GOSIBatchException(e,
  3230.             "BatchCore",
  3231.             "GOSIBatchUtilities",
  3232.             "getBaseCurrency()",
  3233.             "CMN_001_ERR_1000",
  3234.             GOSIBatchConstants.SEVERITY_ONE);                              
  3235.         }
  3236.         return baseCurCode;        
  3237.     }  
  3238.    
  3239.    /**
  3240.  * @METHOD NAME              : getSystemDate
  3241.  * @INFORMATION              : This method will provide the System date for batch
  3242.  * @PARAM                    : void
  3243.  * @RETURN                   : class java.sql.Timestamp
  3244.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  3245.  * @LAST MODIFIED BY         :
  3246.  * @LAST MODIFIED DATE       :
  3247. **/
  3248.  
  3249.     public static Timestamp getSystemDate()
  3250.     throws GOSIBatchException
  3251.     {
  3252.         try
  3253.         {
  3254.             // If the currentSystemDate reading from file
  3255.             if(currentSystemDate==null)
  3256.             {
  3257.                 FileInputStream fis = new FileInputStream
  3258.                 //("/global/oracle/orabin/dbjdk/gosibatch/BatchCore/SystemTime.tim");
  3259.                 (GOSIBatchConstants.GOSI_SYSTEM_TIME_FILE_PATH);
  3260.                 Properties prop = new Properties();
  3261.                 prop.load(fis);
  3262.                 int date = Integer.parseInt(((String)prop.get("DATE")).trim());            
  3263.                 int month = Integer.parseInt(((String)prop.get("MONTH")).trim())-1;            
  3264.                 int year = Integer.parseInt(((String)prop.get("YEAR")).trim());
  3265.                 int hours = Integer.parseInt(((String)prop.get("HOURS")).trim());
  3266.                 int minutes = Integer.parseInt(((String)prop.get("MINUTES")).trim());
  3267.                 int seconds = Integer.parseInt(((String)prop.get("SECONDS")).trim());                          
  3268.                 currentSystemDate =new Timestamp(System.currentTimeMillis());
  3269.                 currentSystemDate.setYear(year-1900);
  3270.                 currentSystemDate.setMonth(month);
  3271.                 currentSystemDate.setDate(date);
  3272.                 currentSystemDate.setHours(hours);
  3273.                 currentSystemDate.setMinutes(minutes);
  3274.                 currentSystemDate.setSeconds(seconds);         
  3275.             }
  3276.         }catch(Exception e)
  3277.         {          
  3278.             throw new GOSIBatchException(e,
  3279.             "BatchCore",
  3280.             "GOSIBatchUtilities",
  3281.             "getBaseCurrency()",
  3282.             "CMN_001_ERR_1000",
  3283.             GOSIBatchConstants.SEVERITY_ONE);
  3284.         }
  3285.         return currentSystemDate;
  3286.     }
  3287.    
  3288.   /**
  3289.  * @METHOD NAME              : getLdapDateFromTimestamp
  3290.  * @INFORMATION              : This method gets the current date for LDAP format
  3291.      *                          returns the same
  3292.  * @PARAM                    : dateTimeStamp
  3293.  * @RETURN                   : class java.lang.String
  3294.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  3295.  * @LAST MODIFIED BY         :
  3296.  * @LAST MODIFIED DATE       :
  3297. **/
  3298.    
  3299.     public static String getLdapDateFromTimestamp(Timestamp dateTimeStamp)
  3300.     throws GOSIBatchException
  3301.     {
  3302.         String ldapDate=null;
  3303.         try
  3304.         {
  3305.             if(dateTimeStamp!=null)
  3306.             {
  3307.                 String timestamp=dateTimeStamp.toString();
  3308.                 StringBuffer stringBuffer=new StringBuffer();
  3309.                 stringBuffer.append(timestamp.substring(0,4));
  3310.                 stringBuffer.append(timestamp.substring(5,7));
  3311.                 stringBuffer.append(timestamp.substring(8,10));
  3312.                 ldapDate=stringBuffer.toString();
  3313.             }// end of if
  3314.         }
  3315.         catch(Exception e)
  3316.         {
  3317.             throw new GOSIBatchException(e,
  3318.             "BatchCore",
  3319.             "GOSIBatchUtilities",
  3320.             "getLdapDateFromTimestamp",
  3321.             "CMN_001_ERR_1000",
  3322.             GOSIBatchConstants.SEVERITY_ONE);
  3323.         }
  3324.         return ldapDate;
  3325.     }
  3326.    
  3327.   /**
  3328.  * @METHOD NAME              : decryptPassword
  3329.  * @INFORMATION              : This method gets the string and decrypt it.
  3330.  * @PARAM                    : password
  3331.  * @RETURN                   : class java.lang.String
  3332.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  3333.  * @LAST MODIFIED BY         :
  3334.  * @LAST MODIFIED DATE       :
  3335. **/
  3336.  
  3337.   public static String decryptPassword(String password)
  3338.     throws GOSIBatchException
  3339.     {
  3340.         String decstr="";
  3341.         try
  3342.         {
  3343.                // Create an array to hold the key
  3344.                 byte[] encryptKey = javax.xml.bind.DatatypeConverter.printBase64Binary(GOSIBatchProperties.GOSI_KEY.getBytes()).getBytes();
  3345.  
  3346. // Create a DESede key spec from the key
  3347.       DESedeKeySpec spec = new DESedeKeySpec(encryptKey);
  3348.  
  3349. // Get the secret key factor for generating DESede keys
  3350.       SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(
  3351.         "DESede");
  3352.  
  3353. // Generate a DESede SecretKey object
  3354.       SecretKey theKey = keyFactory.generateSecret(spec);
  3355.  
  3356. // Create a DESede Cipher
  3357.       Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
  3358.  
  3359. // Create the initialization vector required for CBC mode
  3360.       IvParameterSpec ivParameters = new IvParameterSpec(
  3361.         new byte[] { 12, 34, 56, 78, 90, 87, 65, 43 } );
  3362.  
  3363. // Initialize the cipher and put it in decrypt mode
  3364.       cipher.init(Cipher.DECRYPT_MODE, theKey, ivParameters);
  3365.  
  3366. byte[] encryptedText = javax.xml.bind.DatatypeConverter.printBase64Binary(password.getBytes()).getBytes();
  3367.       byte[] plaintext = cipher.doFinal(encryptedText);
  3368.  
  3369.       decstr = new String(plaintext);
  3370.  
  3371. //      System.out.println(plaintextStr);
  3372. /*                String astring=
  3373.                 ":aAb`BcVCd/eXDfEYg FZhi?jGk|HlmI,nJo@TKpqL.WMrsNt!uvwOx"+
  3374.                 "<yPz>0QR12~3S4;^567U89%$#*()-_=+نهىإةوئٍِضـلياٌر؛؟،";
  3375.  
  3376.             int strlen = password.length();
  3377.                 int aNum;
  3378.             for (int i=0;i<strlen;i++)
  3379.             {
  3380.                  aNum=astring.indexOf(password.substring(i,i+1),0);
  3381.                 aNum=aNum^15;
  3382.                 decstr=decstr+astring.substring(aNum,aNum+1);
  3383.             }
  3384.             */
  3385.         }catch(Exception e)
  3386.         {
  3387.           throw new GOSIBatchException(e,
  3388.             "BatchCore",
  3389.             "GOSIBatchUtilities",
  3390.             "decryptPassword",
  3391.             "CMN_001_ERR_1000",
  3392.             GOSIBatchConstants.SEVERITY_TWO);
  3393.         }
  3394.         return decstr;
  3395.     }
  3396.  
  3397. /**
  3398.  * @METHOD NAME              : updateUserInternetLocation
  3399.  * @INFORMATION              : This method updates Internet users location for the passed employer numbers in both DB as well LDAP
  3400.  * @PARAM                    : List of userReferenceIds, locationId, connection
  3401.  * @RETURN                   : void
  3402.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  3403.  * @LAST MODIFIED BY         : Majed Alkabeer
  3404.  * @LAST MODIFIED DATE       : 13/06/2010
  3405. **/
  3406.  
  3407.     public static void updateUserInternetLocation(ArrayList usersList,
  3408.     short locationId,Connection connection) throws GOSIBatchException
  3409.     {
  3410.         //System.out.println("UPDATION STARTS **********");
  3411.         String updateQuery =  null;  
  3412.         String updateRequestQuery =  null;
  3413.         String selectQuery = null;
  3414.         PreparedStatement psUpdate = null;  
  3415.         PreparedStatement psUpdateRequest = null;        
  3416.         PreparedStatement psSelect =null;
  3417.         ResultSet rs = null;
  3418.         BasicAttributes myAttrs = null;
  3419.  
  3420.         String refids="";
  3421.         if(usersList == null || usersList.size() ==0) return;
  3422.  
  3423.         refids=""+usersList.get(0).toString();
  3424.         for(int i=1;i<usersList.size();i++)
  3425.             refids+=", "+usersList.get(i).toString();
  3426.         try {  
  3427.                 updateQuery = "UPDATE T_USER_INTERNET SET LOCATION=? WHERE  USERREFERENCEID in ("+refids+")";
  3428.                 updateRequestQuery =  "UPDATE T_USERIDREQUEST SET LOCATION=? WHERE  REGISTRATIONNUMBER in ("+refids+")";
  3429.                 selectQuery = "SELECT * FROM T_USER_INTERNET WHERE USERREFERENCEID in ("+refids+")";
  3430.  
  3431.                 psUpdate=connection.prepareStatement(updateQuery);
  3432.                 psUpdate.setLong(1,locationId);        
  3433.                 psUpdate.executeUpdate();
  3434.                 psUpdateRequest=connection.prepareStatement(updateRequestQuery);
  3435.                 psUpdateRequest.setLong(1,locationId);          
  3436.                 psUpdateRequest.executeUpdate();
  3437.                 psSelect = connection.prepareStatement(selectQuery);            
  3438.                 rs = psSelect.executeQuery();
  3439.                
  3440.                 while(rs.next())
  3441.                 {
  3442.                     String id = null;
  3443.                     String password = null;
  3444.                     String userLoginId = null;
  3445.                     String userType = null;        
  3446.                     String accLockStatus = null;
  3447.                     String keyPersonFlag = null;
  3448.                     String defaultRoleId = null;        
  3449.                     String startDate = null;
  3450.                     String longNameArabic = null;
  3451.                     String location = null;
  3452.                     String passwordUpdatedBy = null;
  3453.                     String userRefId = null;    
  3454.                     String emailId = null;            
  3455.                     String endDate = null;
  3456.                     String firstLogonDate = null;
  3457.                     String lastPwdChgDate = null;        
  3458.                    
  3459.                     id = new Long(rs.getLong("ID")).toString();
  3460.                     password = decryptPassword(rs.getString("PASSWORD"));                
  3461.                     userLoginId = rs.getString("USERLOGINID");
  3462.                     userType = new Long(rs.getLong("USERTYPE")).toString();
  3463.                     accLockStatus = new Short(rs.getShort("ACCOUNTLOCKSTATUS")).toString();
  3464.                     keyPersonFlag = new Byte(rs.getByte("KEYPERSONFLAG")).toString();
  3465.                     defaultRoleId = new Long(rs.getLong("DEFAULTROLEID")).toString();
  3466.                     startDate =  GOSIBatchUtilities.getLdapDateFromTimestamp(rs.getTimestamp("STARTDATE"));
  3467.                     longNameArabic = rs.getString("LONGNAMEARABIC");
  3468.                     location = new Short(locationId).toString();
  3469.                     passwordUpdatedBy = new Byte(rs.getByte("PASSWORDUPDATEDBY")).toString();
  3470.                     userRefId = new Long(rs.getLong("USERREFERENCEID")).toString();                
  3471.                    
  3472.                     if(rs.getString("EMAILID")!=null)
  3473.                     {
  3474.                         emailId = rs.getString("EMAILID");
  3475.                     }
  3476.                     if(rs.getTimestamp("ENDDATE")!=null)
  3477.                     {
  3478.                         endDate = GOSIBatchUtilities.
  3479.                                   getLdapDateFromTimestamp(
  3480.                                  rs.getTimestamp("ENDDATE"));
  3481.                     }
  3482.                     if(rs.getTimestamp("FIRSTLOGONDATE")!=null)
  3483.                     {
  3484.                        firstLogonDate = GOSIBatchUtilities.
  3485.                                   getLdapDateFromTimestamp(
  3486.                                  rs.getTimestamp("FIRSTLOGONDATE"));
  3487.                     }
  3488.                     if(rs.getTimestamp("LASTPASSWORDCHANGEDATE")!=null)
  3489.                     {
  3490.                         lastPwdChgDate = GOSIBatchUtilities.
  3491.                                   getLdapDateFromTimestamp(
  3492.                                  rs.getTimestamp("LASTPASSWORDCHANGEDATE"));
  3493.                     }
  3494.                     myAttrs = new BasicAttributes(true);  // case ignore
  3495.                     Attribute oc = new BasicAttribute("objectclass");
  3496.                     oc.add(0,"user"); //objectclass
  3497.                     oc.add(1,"top"); // keep same
  3498.                     myAttrs.put(oc);// keep same                                   
  3499.                     myAttrs.put("userrecordid",id);            
  3500.                     myAttrs.put("userpassword",password);              
  3501.                     myAttrs.put("uid",userLoginId);
  3502.                     myAttrs.put("usertype",userType);              
  3503.                     myAttrs.put("accountlockstatus",accLockStatus);                
  3504.                     myAttrs.put("keypersonflag",keyPersonFlag);
  3505.                     myAttrs.put("defaultroleid",defaultRoleId);
  3506.                     myAttrs.put("startdate", startDate);
  3507.                     myAttrs.put("longnamearabic",longNameArabic);
  3508.                     myAttrs.put("location",location);
  3509.                     myAttrs.put("passwordupdatedby",passwordUpdatedBy);
  3510.                     myAttrs.put("userreferenceid",userRefId);
  3511.                     //Optional attributes
  3512.                     String lastPwdUpdateDate = null;              
  3513.                    
  3514.                     if(emailId!=null)
  3515.                     {
  3516.                         myAttrs.put("emailid", emailId);
  3517.                     }
  3518.                     if(endDate!=null)
  3519.                     {
  3520.                         myAttrs.put("enddate", endDate);
  3521.                     }
  3522.                     if(firstLogonDate!=null)
  3523.                     {
  3524.                         myAttrs.put("firstlogondate", firstLogonDate);
  3525.                     }              
  3526.                    
  3527.                     if(lastPwdChgDate!=null)
  3528.                     {
  3529.                         myAttrs.put("lastpasswordchangedate", lastPwdChgDate);
  3530.                     }              
  3531.                     getDirContext();           
  3532.                     //System.out.println("BINDING STARTED : ");
  3533.                     ctx.rebind("uid="+userLoginId+","+GOSIBatchProperties.
  3534.                     GOSI_LDAP_ROOT_SUFFIX,null,myAttrs);            
  3535.                     //System.out.println("REBIND DONE*************** ");
  3536.                    
  3537.                 }
  3538.             }catch(Exception e)
  3539.             {  
  3540.                 e.printStackTrace();
  3541.                 throw new GOSIBatchException(e,
  3542.                 "BatchCore",
  3543.                 "GOSIBatchUtilities",
  3544.                 "updateUserInternetLocation",
  3545.                 "CMN_001_ERR_1000",
  3546.                 GOSIBatchConstants.SEVERITY_ONE);
  3547.             }
  3548.             finally{
  3549.                 GOSIBatchUtilities.cleanUp(psUpdate);
  3550.                 GOSIBatchUtilities.cleanUp(psUpdateRequest);
  3551.                 GOSIBatchUtilities.cleanUp(psSelect);
  3552.                 GOSIBatchUtilities.cleanUp(rs);
  3553.             }
  3554.     }
  3555.  
  3556.     /**
  3557.  * @METHOD NAME              : updateUserLocation
  3558.  * @INFORMATION              : This method updates user location for the passed employee number in both DB as well LDAP
  3559.  * @PARAM                    : userReferenceId, locationId, connection
  3560.  * @RETURN                   : NIL
  3561.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  3562.  * @LAST MODIFIED BY         :
  3563.  * @LAST MODIFIED DATE       :
  3564. **/
  3565.  
  3566.     public static void updateUserLocation(long userReferenceId,
  3567.     short locationId,Connection connection) throws GOSIBatchException
  3568.     {
  3569.         //System.out.println("UPDATION STARTS **********");
  3570.         String updateQuery =  null;        
  3571.         String selectQuery = null;
  3572.         PreparedStatement psUpdate = null;        
  3573.         PreparedStatement psSelect =null;
  3574.         ResultSet rs = null;
  3575.         BasicAttributes myAttrs = null;
  3576.         try
  3577.         {  
  3578.             updateQuery = GOSIBatchSQL.getSqlString("CMN_001_SQL_1035");
  3579.             //System.out.println("UPDATE QUERY : "+updateQuery);
  3580.             selectQuery = GOSIBatchSQL.getSqlString("CMN_001_SQL_1036");
  3581.             //System.out.println("SELECT QUERY : "+selectQuery);
  3582.             psUpdate=connection.prepareStatement(updateQuery);          
  3583.             psUpdate.setLong(1,locationId);
  3584.             psUpdate.setLong(2,userReferenceId);
  3585.             psUpdate.setShort(3,GOSIBatchConstants.EMPLOYEE);            
  3586.             psUpdate.executeUpdate();
  3587.             psSelect = connection.prepareStatement(selectQuery);            
  3588.             psSelect.setLong(1,userReferenceId);
  3589.             psSelect.setShort(2,GOSIBatchConstants.EMPLOYEE);            
  3590.             rs = psSelect.executeQuery();
  3591.            
  3592.             while(rs.next())
  3593.             {
  3594.                 String id = null;
  3595.                 String password = null;
  3596.                 String userLoginId = null;
  3597.                 String userType = null;                
  3598.                 String accLockStatus = null;
  3599.                 String keyPersonFlag = null;
  3600.                 String defaultRoleId = null;                
  3601.                 String startDate = null;
  3602.                 String longNameArabic = null;
  3603.                 String location = null;
  3604.                 String passwordUpdatedBy = null;
  3605.                 String userRefId = null;                
  3606.                 String accessType = null;                
  3607.                 String departmentCode = null;
  3608.                 String emailId = null;                
  3609.                 String endDate = null;
  3610.                 String firstLogonDate = null;
  3611.                 String lastPwdChgDate = null;              
  3612.                 String longNameEnglish = null;
  3613.                 String shortNameArabic = null;
  3614.                 String shortNameEnglish = null;
  3615.                 String passwordValidUpto = null;        
  3616.                
  3617.                 id = new Long(rs.getLong("ID")).toString();
  3618.                 password = decryptPassword(rs.getString("PASSWORD"));                
  3619.                 userLoginId = rs.getString("USERLOGINID");
  3620.                 userType = new Long(rs.getLong("USERTYPE")).toString();
  3621.                 accLockStatus = new Short
  3622.                                 (rs.getShort("ACCOUNTLOCKSTATUS")).toString();
  3623.                 keyPersonFlag = new Byte(rs.getByte("KEYPERSONFLAG")).toString();
  3624.                 defaultRoleId = new Long(rs.getLong("DEFAULTROLEID")).toString();
  3625.                 startDate =  GOSIBatchUtilities.getLdapDateFromTimestamp(
  3626.                              rs.getTimestamp("STARTDATE"));
  3627.                 longNameArabic = rs.getString("LONGNAMEARABIC");
  3628.                 location = new Short(locationId).toString();
  3629.                 passwordUpdatedBy = new Byte(rs.getByte("PASSWORDUPDATEDBY")).toString();
  3630.                 userRefId = new Long(rs.getLong("USERREFERENCEID")).toString();                
  3631.                
  3632.                 if(rs.getString("EMAILID")!=null)
  3633.                 {
  3634.                     emailId = rs.getString("EMAILID");
  3635.                 }
  3636.                 if(rs.getTimestamp("ENDDATE")!=null)
  3637.                 {
  3638.                     endDate = GOSIBatchUtilities.
  3639.                               getLdapDateFromTimestamp(
  3640.                              rs.getTimestamp("ENDDATE"));
  3641.                 }
  3642.                 if(rs.getTimestamp("FIRSTLOGONDATE")!=null)
  3643.                 {
  3644.                    firstLogonDate = GOSIBatchUtilities.
  3645.                               getLdapDateFromTimestamp(
  3646.                              rs.getTimestamp("FIRSTLOGONDATE"));
  3647.                 }
  3648.                 if(rs.getTimestamp("LASTPASSWORDCHANGEDATE")!=null)
  3649.                 {
  3650.                     lastPwdChgDate = GOSIBatchUtilities.
  3651.                               getLdapDateFromTimestamp(
  3652.                              rs.getTimestamp("LASTPASSWORDCHANGEDATE"));
  3653.                 }
  3654.                 myAttrs = new BasicAttributes(true);  // case ignore
  3655.                 Attribute oc = new BasicAttribute("objectclass");
  3656.                 oc.add(0,"user"); //objectclass
  3657.                 oc.add(1,"top"); // keep same
  3658.                 myAttrs.put(oc);// keep same                                   
  3659.                 myAttrs.put("userrecordid",id);            
  3660.                 myAttrs.put("userpassword",password);              
  3661.                 myAttrs.put("uid",userLoginId);
  3662.                 myAttrs.put("usertype",userType);              
  3663.                 myAttrs.put("accountlockstatus",accLockStatus);                
  3664.                 myAttrs.put("keypersonflag",keyPersonFlag);
  3665.                 myAttrs.put("defaultroleid",defaultRoleId);
  3666.                 myAttrs.put("startdate", startDate);
  3667.                 myAttrs.put("longnamearabic",longNameArabic);
  3668.                 myAttrs.put("location",location);
  3669.                 myAttrs.put("passwordupdatedby",passwordUpdatedBy);
  3670.                 myAttrs.put("userreferenceid",userRefId);
  3671.                 //Optional attributes
  3672.                 String lastPwdUpdateDate = null;              
  3673.                
  3674.                 if(emailId!=null)
  3675.                 {
  3676.                     myAttrs.put("emailid", emailId);
  3677.                 }
  3678.                 if(endDate!=null)
  3679.                 {
  3680.                     myAttrs.put("enddate", endDate);
  3681.                 }
  3682.                 if(firstLogonDate!=null)
  3683.                 {
  3684.                     myAttrs.put("firstlogondate", firstLogonDate);
  3685.                 }              
  3686.                
  3687.                 if(lastPwdChgDate!=null)
  3688.                 {
  3689.                     myAttrs.put("lastpasswordchangedate", lastPwdChgDate);
  3690.                 }              
  3691.                 getDirContext();           
  3692.                 //System.out.println("BINDING STARTED : ");
  3693.                 ctx.rebind("uid="+userLoginId+","+GOSIBatchProperties.
  3694.                 GOSI_LDAP_ROOT_SUFFIX,null,myAttrs);            
  3695.                 //System.out.println("REBIND DONE*************** ");
  3696.                
  3697.             }
  3698.         }catch(Exception e)
  3699.         {  
  3700.             e.printStackTrace();
  3701.             throw new GOSIBatchException(e,
  3702.             "BatchCore",
  3703.             "GOSIBatchUtilities",
  3704.             "updateUserLocation",
  3705.             "CMN_001_ERR_1000",
  3706.             GOSIBatchConstants.SEVERITY_ONE);
  3707.         }        
  3708.     }
  3709.    
  3710.  
  3711.  
  3712.      /**
  3713.  * @METHOD NAME              : viewUserLocation
  3714.  * @INFORMATION              : This method views user location for the passed employee number in both DB as well LDAP
  3715.  * @PARAM                    : userReferenceId, locationId, connection
  3716.  * @RETURN                   : NIL
  3717.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  3718.  * @LAST MODIFIED BY         :
  3719.  * @LAST MODIFIED DATE       :
  3720. **/
  3721.  
  3722.     public static Short viewUserLocation(long userReferenceId,
  3723.     short locationId,Connection connection) throws GOSIBatchException
  3724.     {
  3725.         //System.out.println("UPDATION STARTS **********");
  3726.         String updateQuery =  null;        
  3727.         String selectQuery = null;
  3728.         PreparedStatement psUpdate = null;        
  3729.         PreparedStatement psSelect =null;
  3730.         ResultSet rs = null;
  3731.         BasicAttributes myAttrs = null;
  3732.         Short location = null;
  3733.         try
  3734.         {  
  3735.          //   updateQuery = GOSIBatchSQL.getSqlString("CMN_001_SQL_1035");
  3736.             //System.out.println("UPDATE QUERY : "+updateQuery);
  3737.             selectQuery = GOSIBatchSQL.getSqlString("CMN_001_SQL_1036");
  3738.             //System.out.println("SELECT QUERY : "+selectQuery);
  3739.          
  3740.             psSelect = connection.prepareStatement(selectQuery);            
  3741.             psSelect.setLong(1,userReferenceId);
  3742.             psSelect.setShort(2,GOSIBatchConstants.EMPLOYEE);            
  3743.             rs = psSelect.executeQuery();
  3744.            
  3745.             while(rs.next())
  3746.             {
  3747.    
  3748.                  
  3749.                
  3750.                 location = new Short(rs.getShort("LOCATION"));
  3751.                
  3752.             }
  3753.         }catch(Exception e)
  3754.         {  
  3755.             e.printStackTrace();
  3756.             throw new GOSIBatchException(e,
  3757.             "BatchCore",
  3758.             "GOSIBatchUtilities",
  3759.             "updateUserLocation",
  3760.             "CMN_001_ERR_1000",
  3761.             GOSIBatchConstants.SEVERITY_ONE);
  3762.         }    
  3763.         return location;
  3764.     }
  3765.  
  3766.    /**
  3767.  * @METHOD NAME              : getDateFullString
  3768.  * @INFORMATION              : This method gets Timestamp as single parameter
  3769.  *                          and returns String having date in dd/mm/yyyy format.
  3770.  * @PARAM                    : ts
  3771.  * @RETURN                   : class java.lang.String
  3772.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  3773.  * @LAST MODIFIED BY         :
  3774.  * @LAST MODIFIED DATE       :
  3775. **/
  3776.    
  3777.     public static String getDateFullString(Timestamp ts)
  3778.     throws GOSIBatchException
  3779.     {
  3780.            
  3781.         String dateString="";
  3782.         try
  3783.         {
  3784.             if(ts!=null)
  3785.             {
  3786.                 String dateStr = ts.toString();
  3787.                 dateStr =  dateStr.substring(0,10);
  3788.                 StringTokenizer strTok = new StringTokenizer(dateStr,"-");
  3789.                 String retStr[] = new String[3];
  3790.  
  3791.                 while(strTok.hasMoreTokens())
  3792.                 {
  3793.                     retStr[2] = (String) strTok.nextToken();
  3794.                     retStr[1] =  (String)strTok.nextToken();
  3795.                     retStr[0] =  (String) strTok.nextToken();
  3796.                 }
  3797.                 StringBuffer dd =  new StringBuffer(retStr[0]);
  3798.                 StringBuffer mm =  new StringBuffer(retStr[1]);
  3799.                 StringBuffer yyyy =  new StringBuffer(retStr[2]);
  3800.                 dd.append("/");
  3801.                 dd.append(mm);
  3802.                 dd.append("/");
  3803.                 dd.append(yyyy);
  3804.                 dateString =dd.toString();
  3805.             }
  3806.         }
  3807.         catch(Exception e)
  3808.         {
  3809.         throw new GOSIBatchException(e,
  3810.             "BatchCore",
  3811.             "GOSIBatchUtilities",
  3812.             "getDateFullString",
  3813.             "CMN_001_ERR_1000",
  3814.             GOSIBatchConstants.SEVERITY_ONE);
  3815.         }
  3816.         return  dateString;
  3817.     }
  3818.  
  3819. /**
  3820.  * @METHOD NAME              : getEmailListForRoleAndLocation
  3821.  * @INFORMATION              : This method returns the list of email list
  3822.  *                              for given employee number list
  3823.  * @PARAM                    : employeeNumberList
  3824.  * @RETURN                   : class java.util.HashMap
  3825.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  3826.  * @LAST MODIFIED BY         :
  3827.  * @LAST MODIFIED DATE       :
  3828. **/
  3829.  
  3830.     public static  ArrayList <String> getEmailListForRoleAndLocation(Short locationCode,
  3831.         Short roleId)
  3832.     throws GOSIBatchException
  3833.     {
  3834.         ArrayList <String>emailIdList =null;
  3835.         ResultSet rs=null;
  3836.         PreparedStatement ps = null;
  3837.         Connection cn =null;
  3838.         try
  3839.         {
  3840.             cn=getDbConnection(GOSIBatchConstants.COMMON);
  3841.  
  3842.             String query=
  3843.                 "SELECT emailid FROM t_user WHERE LOCATION = ? AND id IN "+
  3844.                 " (SELECT userrecordid FROM t_userrolemap WHERE roleid =? "+
  3845.                 " AND startdate <= SYSDATE AND NVL (enddate, SYSDATE) <= SYSDATE) ";
  3846.  
  3847.                 ps=cn.prepareStatement(query);
  3848.  
  3849.                 ps.setShort(1,locationCode);
  3850.                 ps.setShort(2,roleId);
  3851.  
  3852.                 rs=ps.executeQuery();
  3853.                 if (rs.next())
  3854.                 {
  3855.                     emailIdList =new ArrayList<String>();
  3856.                     do
  3857.                     {
  3858.                         String emailId=rs.getString("EMAILID");
  3859.                         emailIdList.add(emailId);
  3860.                     }
  3861.                     while(rs.next());  
  3862.                 }
  3863.        
  3864.             }
  3865.             catch(Exception e)
  3866.             {
  3867.                 throw new GOSIBatchException(e,
  3868.                 "BatchCore",
  3869.                 "GOSIBatchUtilities",
  3870.                 "getEmailListForRoleAndLocation",
  3871.                 "CMN_001_ERR_1000",
  3872.                 GOSIBatchConstants.SEVERITY_ONE);
  3873.             }
  3874.             finally
  3875.             {
  3876.                 GOSIBatchUtilities.cleanUp(rs,ps,cn);
  3877.             }
  3878.             return emailIdList;
  3879.     }
  3880.  
  3881.     /**
  3882.  * @METHOD NAME              : getEmailIdList
  3883.  * @INFORMATION              : This method returns the list of email list
  3884.  *                              for given employee number list
  3885.  * @PARAM                    : employeeNumberList
  3886.  * @RETURN                   : class java.util.HashMap
  3887.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  3888.  * @LAST MODIFIED BY         :
  3889.  * @LAST MODIFIED DATE       :
  3890. **/
  3891.  
  3892.     public static  HashMap getEmailIdList(ArrayList employeeNumberList)
  3893.     throws GOSIBatchException
  3894.     {          
  3895.         HashMap emailIdList=new HashMap();
  3896.         ResultSet rs=null;
  3897.         PreparedStatement ps = null;
  3898.         Connection cn =null;
  3899.         try
  3900.         {
  3901.             if(employeeNumberList!=null)
  3902.             {
  3903.                 short moduleId=
  3904.                     ((Short)employeeNumberList.get(0)).shortValue();
  3905.                 cn=getDbConnection(GOSIBatchConstants.COMMON);
  3906.             }
  3907.             String query=
  3908.                 "SELECT USERREFERENCEID,EMAILID FROM "+
  3909.                     " T_USER WHERE "+
  3910.                 " USERREFERENCEID in(";        
  3911.             if(
  3912.                 (employeeNumberList!=null)
  3913.                 &&(employeeNumberList.size()>0)
  3914.                 )
  3915.             {
  3916.                 for(int i=1;i<employeeNumberList.size();i++)
  3917.                 {
  3918.                     if(i==employeeNumberList.size()-1)
  3919.                     {
  3920.                         query=query+"?";
  3921.                     }
  3922.                     else
  3923.                     {
  3924.                         query=query+"?,";
  3925.                     }
  3926.                 }
  3927.                 query=query+") AND USERTYPE=?";
  3928.                 //System.out.println("query="+query);
  3929.                 ps=cn.prepareStatement(query);
  3930.                 Long employeeNumber=null;
  3931.                 String szEmployeeNumber =null;
  3932.                 for(int i=1;i<employeeNumberList.size();i++)
  3933.                 {
  3934.                     employeeNumber = (Long)employeeNumberList.get(i);
  3935.                     ps.setLong(i,employeeNumber.longValue());
  3936.                        
  3937.                 }  
  3938.                 int size=employeeNumberList.size();
  3939.                 ps.setShort(size,GOSIBatchConstants.EMPLOYEE);
  3940.                 rs=ps.executeQuery();
  3941.                 while(rs.next())
  3942.                 {
  3943.                     //System.out.println("Inside the result set");
  3944.                     String emailId=rs.getString("EMAILID");
  3945.                     String userReferenceid=rs.getString("USERREFERENCEID");
  3946.                     emailIdList.put(userReferenceid,emailId);  
  3947.                 }
  3948.             }              
  3949.             }catch(Exception e)
  3950.             {
  3951.                 throw new GOSIBatchException(e,
  3952.                 "BatchCore",
  3953.                 "GOSIBatchUtilities",
  3954.                 "getDateFullString",
  3955.                 "CMN_001_ERR_1000",
  3956.                 GOSIBatchConstants.SEVERITY_ONE);
  3957.             }
  3958.             finally
  3959.             {
  3960.                 GOSIBatchUtilities.cleanUp(rs,ps,cn);
  3961.             }
  3962.             return emailIdList;
  3963.     }  
  3964.    
  3965.  
  3966.  
  3967.     /**
  3968.  * @METHOD NAME              : getEmailIdListForUserRecord
  3969.  * @INFORMATION              : This method returns list of email list for
  3970.                                 given user record list
  3971.  * @PARAM                    : userRecordList
  3972.  * @RETURN                   : HashMap
  3973.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  3974.  * @LAST MODIFIED BY         :
  3975.  * @LAST MODIFIED DATE       :
  3976. **/
  3977. public static  HashMap getEmailIdListForUserRecord(ArrayList userRecordList)
  3978.     throws GOSIBatchException
  3979.     {          
  3980.         HashMap emailIdList=new HashMap();
  3981.         ResultSet rs=null;
  3982.         PreparedStatement ps = null;
  3983.         Connection cn =null;
  3984.         try
  3985.         {
  3986.             if(userRecordList!=null)
  3987.             {
  3988.                 long moduleId=
  3989.                     ((Long)userRecordList.get(0)).longValue();
  3990.                 cn=getDbConnection(GOSIBatchConstants.COMMON);
  3991.             }
  3992.             //System.out.println("User Record List size : "+userRecordList);
  3993.             String query=
  3994.                 "SELECT ID,EMAILID FROM "+
  3995.                     " T_USER WHERE "+
  3996.                 " ID in(";         
  3997.             if((userRecordList!=null)&&(userRecordList.size()>0))
  3998.             {
  3999.                 for(int i=0;i<userRecordList.size();i++)
  4000.                 {
  4001.                     if(i==userRecordList.size()-1)
  4002.                     {
  4003.                         query=query+"?";
  4004.                     }
  4005.                     else
  4006.                     {
  4007.                         query=query+"?,";
  4008.                     }
  4009.                 }
  4010.                 query=query+") AND USERTYPE=?";
  4011.                 //System.out.println("query="+query);
  4012.                 ps=cn.prepareStatement(query);
  4013.                 Long userRecordId=null;
  4014.                 String szEmployeeNumber =null;
  4015.                 int size=userRecordList.size();
  4016.                 //System.out.println("Size : "+size);
  4017.                 for(int i=1;i<=size;i++)
  4018.                 {
  4019.                     //System.out.println("setting : "+i);
  4020.                     userRecordId = (Long)userRecordList.get(i-1);
  4021.                     ps.setLong(i,userRecordId.longValue());                    
  4022.                 }  
  4023.                
  4024.                 ps.setShort(size+1,GOSIBatchConstants.EMPLOYEE);
  4025.                 rs=ps.executeQuery();
  4026.                 while(rs.next())
  4027.                 {
  4028.                     //System.out.println("Inside the result set");
  4029.                     String emailId=rs.getString("EMAILID");
  4030.                     Long userRecord=new Long(rs.getLong("ID"));
  4031.                     emailIdList.put(userRecord,emailId);   
  4032.                 }
  4033.             }              
  4034.             }catch(Exception e)
  4035.             {
  4036.                 throw new GOSIBatchException(e,
  4037.                 "BatchCore",
  4038.                 "GOSIBatchUtilities",
  4039.                 "getDateFullString",
  4040.                 "CMN_001_ERR_1000",
  4041.                 GOSIBatchConstants.SEVERITY_ONE);
  4042.             }
  4043.             finally
  4044.             {
  4045.                 GOSIBatchUtilities.cleanUp(rs,ps,cn);
  4046.             }
  4047.             return emailIdList;
  4048.     }  
  4049.  
  4050.     /**
  4051.  * @METHOD NAME              : getTimestamp
  4052.  * @INFORMATION              : This method gets three parameters namely day, month
  4053.  *                  and year and returns Timestamp object after formatting it.
  4054.  * @PARAM                    : day, mon, year
  4055.  * @RETURN                   : class java.sql.Timestamp
  4056.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  4057.  * @LAST MODIFIED BY         :
  4058.  * @LAST MODIFIED DATE       :
  4059. **/
  4060.  
  4061.     public static Timestamp getTimestamp(String  day,String mon,String year)
  4062.     throws GOSIBatchException
  4063.     {
  4064.    
  4065.         Timestamp timeStamp=null;
  4066.         try
  4067.         {
  4068.             if((day!=null)&&(mon!=null)&&(year!=null))
  4069.             {
  4070.                 // Fix a comatability with java 6
  4071.                 // Java 6 does not allow input not strictly
  4072.                 // complies to the format yyyy-mm-dd hh:mm:ss[.fffffffff]
  4073.                 // so we will make the necessary adjustment
  4074.                 if (day.length() == 1)
  4075.                     day = "0"+day;
  4076.                 if (mon.length() == 1)
  4077.                     mon = "0" +mon;
  4078.                 StringBuffer dd =  new StringBuffer(day);
  4079.                 StringBuffer mm =  new StringBuffer(mon);
  4080.                 StringBuffer yyyy =  new StringBuffer(year);
  4081.                 yyyy.append("-");
  4082.                 yyyy.append(mm);
  4083.                 yyyy.append("-");
  4084.                 yyyy.append(dd);
  4085.                 yyyy.append(" 0:0:0.0");
  4086.                 String str = yyyy.toString();
  4087.                 timeStamp=Timestamp.valueOf(str);
  4088.             }
  4089.         }
  4090.         catch(Exception e)
  4091.         {
  4092.             throw new GOSIBatchException(e,
  4093.             "BatchCore",
  4094.             "GOSIBatchUtilities",
  4095.             "getTimestamp",
  4096.             "CMN_001_ERR_1000",
  4097.             GOSIBatchConstants.SEVERITY_ONE);
  4098.         }
  4099.         return timeStamp;
  4100.     }
  4101. /**
  4102.  * @METHOD NAME              : getTimestamp
  4103.  * @INFORMATION              : This method gets the date in  String format as an
  4104.  *                  argument and returns Timestamp object after formatting it.
  4105.  * @PARAM                    : fullDate
  4106.  * @RETURN                   : class java.sql.Timestamp
  4107.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  4108.  * @LAST MODIFIED BY         :
  4109.  * @LAST MODIFIED DATE       :
  4110. **/
  4111.  
  4112.     public static Timestamp getTimestamp(String  fullDate)
  4113.     throws GOSIBatchException
  4114.     {
  4115.        
  4116.         Timestamp timeStamp=null;
  4117.         try
  4118.         {
  4119.             if(fullDate!=null)
  4120.             {
  4121.                 String year=null;
  4122.                 String month=null;
  4123.                 String date=null;
  4124.                 StringTokenizer st=new StringTokenizer(fullDate,"-/");
  4125.                 while(st.hasMoreTokens())
  4126.                         {  
  4127.                                 date=st.nextToken();
  4128.                                 month=st.nextToken();
  4129.                                 year=st.nextToken();
  4130.                         }
  4131.                 // Fix a comatability with java 6
  4132.                 // Java 6 does not allow input not strictly
  4133.                 // complies to the format yyyy-mm-dd hh:mm:ss[.fffffffff]
  4134.                 // so we will make the necessary adjustment
  4135.                 if (date.length() == 1)
  4136.                     date = "0"+date;
  4137.                 if (month.length() == 1)
  4138.                     month = "0" +month;
  4139.  
  4140.                 StringBuffer dd =  new StringBuffer(date);
  4141.                 StringBuffer mm =  new StringBuffer(month);
  4142.                 StringBuffer yyyy =  new StringBuffer(year);
  4143.                 yyyy.append("-");
  4144.                 yyyy.append(mm);
  4145.                 yyyy.append("-");
  4146.                 yyyy.append(dd);
  4147.                 yyyy.append(" 0:0:0.0");
  4148.                 String str = yyyy.toString();
  4149.                 timeStamp=Timestamp.valueOf(str);
  4150.             }
  4151.         }
  4152.         catch(Exception e)
  4153.         {
  4154.            
  4155.                 throw new GOSIBatchException(e,
  4156.                 "BatchCore",
  4157.                 "GOSIBatchUtilities",
  4158.                 "getTimestamp",
  4159.                 "CMN_001_ERR_1000",
  4160.                 GOSIBatchConstants.SEVERITY_ONE);
  4161.         }
  4162.         return timeStamp;
  4163.     }  
  4164.    
  4165.   /**
  4166.  * @METHOD NAME              : getSystemUserLocation
  4167.  * @INFORMATION              : This method takes the module name for getting the connection and returns the
  4168.  *                              location id of the system user   
  4169.  * @PARAM                    : moduleName
  4170.  * @RETURN                   : short
  4171.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  4172.  * @LAST MODIFIED BY         :
  4173.  * @LAST MODIFIED DATE       :
  4174. **/
  4175.    
  4176.     public static short getSystemUserLocation(String moduleName)
  4177.     throws GOSIBatchException
  4178.     {
  4179.         short locationId=0;
  4180.         Connection connection = null;
  4181.         PreparedStatement psUserLocation = null;
  4182.         ResultSet rsUserLocation  = null;
  4183.         try
  4184.         {
  4185.             String query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1051");          
  4186.             connection = getDbConnection(moduleName);
  4187.             psUserLocation = connection.prepareStatement(query);
  4188.             psUserLocation.setString(1, GOSIBatchProperties.SYSTEM_USER);
  4189.             rsUserLocation = psUserLocation.executeQuery();
  4190.             if(rsUserLocation.next())
  4191.             {                
  4192.                 locationId = rsUserLocation.getShort("LOCATION");
  4193.             }
  4194.         }catch(Exception e)
  4195.         {
  4196.               throw new GOSIBatchException(e,
  4197.                 "BatchCore",
  4198.                 "GOSIBatchUtilities",
  4199.                 "getTimestamp",
  4200.                 "CMN_001_ERR_1000",
  4201.                 GOSIBatchConstants.SEVERITY_ONE);
  4202.         }
  4203.         finally
  4204.         {
  4205.             GOSIBatchUtilities.cleanUp(rsUserLocation,
  4206.             psUserLocation, connection);        
  4207.         }
  4208.         return locationId;
  4209.     }
  4210.    
  4211.   /**
  4212.  * @METHOD NAME              : getFieldOfficeForVillage
  4213.  * @INFORMATION              : This method returns the fieldOffice code for the
  4214.                                given villageId
  4215.  * @PARAM                    : villageId, moduleName
  4216.  * @RETURN                   : Short
  4217.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  4218.  * @LAST MODIFIED BY         :
  4219.  * @LAST MODIFIED DATE       :
  4220. **/
  4221.  
  4222.     public Short getFieldOfficeForVillage
  4223.     (Long villageId,String moduleName)
  4224.     throws GOSIBatchException
  4225.     {
  4226.         Connection connection=null;
  4227.         PreparedStatement ps=null;
  4228.         ResultSet rs=null;
  4229.         Short foCode=null;
  4230.         String query=null;
  4231.                
  4232.         try
  4233.         {
  4234.             query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1037");
  4235.             connection = getDbConnection(moduleName);
  4236.             ps=connection.prepareStatement(query);
  4237.             ps.setLong(1,villageId.longValue());
  4238.             rs=ps.executeQuery();
  4239.             while(rs.next())
  4240.             {
  4241.                 foCode=new Short(rs.getShort("FOCODE"));
  4242.             }
  4243.         }
  4244.         catch(Exception e)
  4245.         {
  4246.               throw new GOSIBatchException(e,
  4247.                 "BatchCore",
  4248.                 "GOSIBatchUtilities",
  4249.                 "getFieldOfficeForVillage()",
  4250.                 "CMN_001_ERR_1000",
  4251.                 GOSIBatchConstants.SEVERITY_ONE);
  4252.         }
  4253.         finally
  4254.         {
  4255.             GOSIBatchUtilities.cleanUp(rs,ps,connection);
  4256.         }
  4257.         return foCode;
  4258.     }
  4259.  
  4260. /**
  4261.  * @METHOD NAME              : getModuleName
  4262.  * @INFORMATION              : This method returns the corresponding moduleName
  4263.                                for the moduleId passed
  4264.  * @PARAM                    : moduleId
  4265.  * @RETURN                   : class java.lang.String
  4266.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  4267.  * @LAST MODIFIED BY         :
  4268.  * @LAST MODIFIED DATE       :
  4269. **/
  4270.  
  4271.     public static String getModuleName
  4272.     (short moduleId)
  4273.     throws GOSIBatchException
  4274.     {
  4275.         String moduleName = null;
  4276.         try
  4277.         {
  4278.        
  4279.           switch(moduleId)
  4280.         {
  4281.             case GOSIBatchConstants.BUDGET_ID :
  4282.                 moduleName = GOSIBatchConstants.BUDGET;
  4283.             break;
  4284.  
  4285.             case GOSIBatchConstants.COMMON_ID :
  4286.                 moduleName =  GOSIBatchConstants.COMMON;
  4287.             break;
  4288.  
  4289.             case GOSIBatchConstants.CONTRACT_ID:
  4290.                 moduleName =  GOSIBatchConstants.CONTRACT;
  4291.             break;
  4292.  
  4293.             case GOSIBatchConstants.FINANCE_ID:
  4294.                 moduleName =  GOSIBatchConstants.FINANCE;
  4295.             break;
  4296.  
  4297.             case GOSIBatchConstants.INVESTMENT_ID:
  4298.                 moduleName =  GOSIBatchConstants.INVESTMENT;
  4299.             break;
  4300.  
  4301.             case GOSIBatchConstants.INVENTORY_ID:
  4302.                 moduleName =  GOSIBatchConstants.INVENTORY;
  4303.             break;
  4304.  
  4305.             case GOSIBatchConstants.PERSONNEL_ID:
  4306.                 moduleName =  GOSIBatchConstants.PERSONNEL;
  4307.             break;
  4308.  
  4309.             case GOSIBatchConstants.PURCHASE_ID:
  4310.                 moduleName =  GOSIBatchConstants.PURCHASE;
  4311.             break;
  4312.  
  4313.             case GOSIBatchConstants.REAL_ESTATE_ID :
  4314.                 moduleName =  GOSIBatchConstants.REAL_ESTATE;
  4315.             break;
  4316.  
  4317.             case GOSIBatchConstants.SECURITY_ID :
  4318.                 moduleName =  GOSIBatchConstants.SECURITY;
  4319.             break;
  4320.  
  4321.             case GOSIBatchConstants.SOCIAL_INSURANCE_ID :
  4322.                 moduleName =  GOSIBatchConstants.SOCIAL_INSURANCE;
  4323.             break;
  4324.  
  4325.             case GOSIBatchConstants.WORKFLOW_ID :
  4326.                 moduleName =  GOSIBatchConstants.WORKFLOW;
  4327.             break;
  4328.  
  4329.             case GOSIBatchConstants.FIXED_ASSET_ID :
  4330.                 moduleName =  GOSIBatchConstants.FIXED_ASSET;
  4331.             break;
  4332.  
  4333.             case GOSIBatchConstants.REGISTRATION_ID :
  4334.                 moduleName =  GOSIBatchConstants.REGISTRATION;
  4335.             break;
  4336.  
  4337.             case GOSIBatchConstants.ANNUITIES_ID :
  4338.                 moduleName =  GOSIBatchConstants.ANNUITIES;
  4339.             break;
  4340.  
  4341.             case GOSIBatchConstants.OCCUPATIONAL_HAZARDS_ID :
  4342.                 moduleName =  GOSIBatchConstants.OCCUPATIONAL_HAZARDS;
  4343.             break;
  4344.  
  4345.             case GOSIBatchConstants.CONTRIBUTION_ID :
  4346.                 moduleName =  GOSIBatchConstants.CONTRIBUTION;
  4347.             break;
  4348.  
  4349.             case GOSIBatchConstants.PROJECT_ID :
  4350.                 moduleName =  GOSIBatchConstants.PROJECT;
  4351.             break;
  4352.  
  4353.             case GOSIBatchConstants.DATAWAREHOUSING_ID:
  4354.                 moduleName =  GOSIBatchConstants.DATAWAREHOUSING;
  4355.             break;
  4356.  
  4357.             case GOSIBatchConstants.INTERFACE_ID:
  4358.                 moduleName =  GOSIBatchConstants.INTERFACE;
  4359.             break;
  4360.            
  4361.             default:
  4362.             break;
  4363.        
  4364.         }
  4365.         }
  4366.         catch(Exception e)
  4367.         {
  4368.               throw new GOSIBatchException(e,
  4369.                 "BatchCore",
  4370.                 "GOSIBatchUtilities",
  4371.                 "getModuleName()",
  4372.                 "CMN_001_ERR_1000",
  4373.                 GOSIBatchConstants.SEVERITY_ONE);
  4374.         }
  4375.         finally
  4376.         {
  4377.             return moduleName;
  4378.         }
  4379.     }
  4380.     /**
  4381.  * @METHOD NAME              : getDomainDetailsName
  4382.  * @INFORMATION              : This method returns the corresponding domaindetails shortname
  4383.                                  for  given domainname and domain code 
  4384.  * @PARAM                    : domainName, code, bIsArabic, moduleName
  4385.  * @RETURN                   : class java.lang.String
  4386.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  4387.  * @LAST MODIFIED BY         :
  4388.  * @LAST MODIFIED DATE       :
  4389. **/
  4390.  
  4391.     public static String getDomainDetailsName(String domainName,
  4392.     Short code, boolean bIsArabic, String moduleName)
  4393.     throws GOSIBatchException
  4394.     {
  4395.         Connection connection=null;
  4396.         PreparedStatement ps=null;
  4397.         ResultSet rs=null;
  4398.         String domainDetailsName = null;
  4399.         String queryEn=null;
  4400.         String queryAr=null;
  4401.        
  4402.         try
  4403.         {
  4404.             queryAr=GOSIBatchSQL.getSqlString("CMN_001_SQL_1052");
  4405.             queryEn=GOSIBatchSQL.getSqlString("CMN_001_SQL_1053");         
  4406.             connection = getDbConnection(moduleName);
  4407.             if(bIsArabic)
  4408.             {
  4409.                 ps=connection.prepareStatement(queryAr);
  4410.                 //System.out.println("query : "+ queryAr);
  4411.             }
  4412.             else
  4413.             {
  4414.                 ps=connection.prepareStatement(queryEn);
  4415.                 //System.out.println("query : "+queryEn);
  4416.             }
  4417.            
  4418.             //System.out.println("Utilities : domainName : "+domainName);
  4419.             //System.out.println("Utitities : code  "+code);
  4420. //            System.out.println("Utitities : code  "+code);
  4421.            
  4422.             ps.setString(1,domainName);
  4423.             ps.setShort(2,code.shortValue());
  4424.             rs=ps.executeQuery();
  4425.             //System.out.println("Executed : ");
  4426.             while(rs.next())
  4427.             {
  4428.                 if(bIsArabic)
  4429.                 {
  4430.                     domainDetailsName=rs.getString("SHORTNAMEARABIC");
  4431.                 }
  4432.                 else
  4433.                 {
  4434.                     domainDetailsName=rs.getString("SHORTNAMEENGLISH");
  4435.                 }
  4436.             }
  4437.            
  4438.         }
  4439.         catch(Exception e)
  4440.         {
  4441.               throw new GOSIBatchException(e,
  4442.                 "BatchCore",
  4443.                 "GOSIBatchUtilities",
  4444.                 "getDomainDetailsName()",
  4445.                 "CMN_001_ERR_1000",
  4446.                 GOSIBatchConstants.SEVERITY_ONE);
  4447.         }
  4448.         finally
  4449.         {
  4450.             GOSIBatchUtilities.cleanUp(rs,ps,connection);
  4451.         }
  4452.         return domainDetailsName;
  4453.     }
  4454.  
  4455.    
  4456.  /**
  4457.  * @METHOD NAME              : getCorporateContactDetails
  4458.  * @INFORMATION              : This method returns the Corporate contact details for the given contact id
  4459.  * @PARAM                    : contactid, moduleName
  4460.  * @RETURN                   :
  4461.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  4462.  * @LAST MODIFIED BY         :
  4463.  * @LAST MODIFIED DATE       :
  4464. **/
  4465.      
  4466.     public static CorporateContactBean getCorporateContactDetails(long contactId,
  4467.     String moduleName)throws GOSIBatchException
  4468.     {
  4469.         Connection connection=null;
  4470.         PreparedStatement ps=null;
  4471.         ResultSet rs=null;
  4472.         String domainDetailsName = null;
  4473.         String queryAr=null;
  4474.         CorporateContactBean corporateContactBean = null;
  4475.        
  4476.         try
  4477.         {
  4478.             queryAr=GOSIBatchSQL.getSqlString("CMN_001_SQL_1054");
  4479.             connection = getDbConnection(moduleName);
  4480.             ps=connection.prepareStatement(queryAr);          
  4481.             ps.setLong(1,contactId);            
  4482.             rs=ps.executeQuery();
  4483.             //System.out.println("Executed : ");
  4484.             if(rs.next())
  4485.             {
  4486.                 corporateContactBean = new CorporateContactBean();
  4487.                
  4488.                 corporateContactBean.setLanguageType(rs.getString("LANGUAGETYPE"));
  4489.                 corporateContactBean.setFreeTextDescription(rs.getString("FREETEXTDESCRIPTION"));
  4490.                 corporateContactBean.setBuildingNumber(rs.getString("BUILDINGNUMBER"));
  4491.                 corporateContactBean.setStreet(rs.getString("STREET"));
  4492.                 corporateContactBean.setArea(rs.getString("AREA"));
  4493.                 corporateContactBean.setCity(rs.getString("CITY"));
  4494.                 corporateContactBean.setCountry(rs.getShort("COUNTRY"));
  4495.                 corporateContactBean.setPoBox(rs.getString("POBOX"));
  4496.                 corporateContactBean.setZipCode(rs.getString("ZIPCODE"));
  4497.                 corporateContactBean.setExtension(rs.getString("EXTENSION"));
  4498.                 corporateContactBean.setFaxNumber(rs.getString("FAXNUMBER"));
  4499.                 corporateContactBean.setEmailId(rs.getString("EMAILID"));
  4500.                 corporateContactBean.setCurrentMailingAddrInd(rs.getByte("CURRENTMAILINGADDRIND"));
  4501.                 if(rs.getString("VILLAGEID")!=null)
  4502.                 {
  4503.                     corporateContactBean.setVillageId(new Long(rs.getLong("VILLAGEID")));
  4504.                 }
  4505.                 corporateContactBean.setFreeTextDescription2(rs.getString("FREETEXTDESCRIPTION2"));                
  4506.                 corporateContactBean.setExtension1(rs.getString("EXTENSION1"));
  4507.                 corporateContactBean.setExtension2(rs.getString("EXTENSION2"));
  4508.                 corporateContactBean.setExtension3(rs.getString("EXTENSION3"));
  4509.                 corporateContactBean.setExtension4(rs.getString("EXTENSION4"));                
  4510.                 corporateContactBean.setTelephoneNumber1(rs.getString("TELEPHONENUMBER1"));
  4511.                 corporateContactBean.setTelephoneNumber2(rs.getString("TELEPHONENUMBER2"));
  4512.                 corporateContactBean.setTelephoneNumber3(rs.getString("TELEPHONENUMBER3"));
  4513.                 corporateContactBean.setTelephoneNumber4(rs.getString("TELEPHONENUMBER4"));
  4514.                
  4515.    
  4516.            }
  4517.            
  4518.         }
  4519.         catch(Exception e)
  4520.         {
  4521.               throw new GOSIBatchException(e,
  4522.                 "BatchCore",
  4523.                 "GOSIBatchUtilities",
  4524.                 "getCorporateContactDetails()",
  4525.                 "CMN_001_ERR_1000",
  4526.                 GOSIBatchConstants.SEVERITY_ONE);
  4527.         }
  4528.         finally
  4529.         {
  4530.             GOSIBatchUtilities.cleanUp(rs,ps,connection);
  4531.         }
  4532.         return corporateContactBean;
  4533.     }
  4534.  
  4535. /**
  4536.  * @METHOD NAME              : getIndividualContactDetails
  4537.  * @INFORMATION              : This method returns the Individual contact details for the given contact id
  4538.  * @PARAM                    : contactid, moduleName
  4539.  * @RETURN                   :
  4540.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  4541.  * @LAST MODIFIED BY         :
  4542.  * @LAST MODIFIED DATE       :
  4543. **/
  4544.  
  4545.     public static IndividualContactBean getIndividualContactDetails(long contactId,
  4546.     String moduleName)throws GOSIBatchException
  4547.     {
  4548.         Connection connection=null;
  4549.         PreparedStatement ps=null;
  4550.         ResultSet rs=null;
  4551.         String domainDetailsName = null;
  4552.         String queryAr=null;
  4553.         IndividualContactBean individualContactBean = null;
  4554.        
  4555.         try
  4556.         {
  4557.             queryAr=GOSIBatchSQL.getSqlString("CMN_001_SQL_1055");
  4558.             connection = getDbConnection(moduleName);
  4559.             ps=connection.prepareStatement(queryAr);
  4560.             //System.out.println("Query is : "+queryAr+" Contact ID : "+contactId);
  4561.             ps.setLong(1,contactId);            
  4562.             rs=ps.executeQuery();
  4563.             //System.out.println("Executed : ");
  4564.             if(rs.next())
  4565.             {
  4566.                 //System.out.println("RECORD FOUND ");
  4567.                 individualContactBean = new IndividualContactBean();
  4568.                                              
  4569.                 individualContactBean.setLanguageType(rs.getString("LANGUAGETYPE"));
  4570.                 individualContactBean.setFreeTextDescription(rs.getString("FREETEXTDESCRIPTION"));
  4571.                 individualContactBean.setBuildingNumber(rs.getString("BUILDINGNUMBER"));
  4572.                 individualContactBean.setStreet(rs.getString("STREET"));
  4573.                 individualContactBean.setArea(rs.getString("AREA"));
  4574.                 individualContactBean.setCity(rs.getString("CITY"));
  4575.                 individualContactBean.setCountry(rs.getShort("COUNTRY"));
  4576.                 individualContactBean.setPoBox(rs.getString("POBOX"));
  4577.                 individualContactBean.setZipCode(rs.getString("ZIPCODE"));
  4578.                 individualContactBean.setTelephoneNumber(rs.getString("TELEPHONENUMBER"));
  4579.                 individualContactBean.setExtension(rs.getString("EXTENSION"));
  4580.                 individualContactBean.setFaxNumber(rs.getString("FAXNUMBER"));
  4581.                 individualContactBean.setEmailId(rs.getString("EMAILID"));
  4582.                 individualContactBean.setCurrentMailingAddrInd(rs.getByte("CURRENTMAILINGADDRIND"));
  4583.                 individualContactBean.setMobileNumber(rs.getString("MOBILENUMBER"));
  4584.                 if(rs.getString("VILLAGEID")!=null)
  4585.                 {
  4586.                     individualContactBean.setVillageId(new Long(rs.getLong("VILLAGEID")));
  4587.                 }
  4588.                 individualContactBean.setFreeTextDescription2(rs.getString("FREETEXTDESCRIPTION2"));
  4589.              
  4590.            }            
  4591.         }
  4592.         catch(Exception e)
  4593.         {
  4594.               throw new GOSIBatchException(e,
  4595.                 "BatchCore",
  4596.                 "GOSIBatchUtilities",
  4597.                 "getIndividualContactDetails()",
  4598.                 "CMN_001_ERR_1000",
  4599.                 GOSIBatchConstants.SEVERITY_ONE);
  4600.         }
  4601.         finally
  4602.         {
  4603.             GOSIBatchUtilities.cleanUp(rs,ps,connection);
  4604.         }
  4605.         return individualContactBean;
  4606.     }
  4607.  
  4608. /**
  4609.  * @METHOD NAME              : getFieldOfficeVillageMappingDetails
  4610.  * @INFORMATION              :This method returns
  4611.                              the field office village
  4612.                              mapping details with village start
  4613.                              date greater than the date passed
  4614.                              as a parameter  
  4615.  * @PARAM                    : startDate
  4616.  * @RETURN                   : class java.util.ArrayList
  4617.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  4618.  * @LAST MODIFIED BY         :
  4619.  * @LAST MODIFIED DATE       :
  4620. **/
  4621.    
  4622.     public static ArrayList getFieldOfficeVillageMappingDetails
  4623.     (Timestamp fieldOfficeMappingDate)throws GOSIBatchException
  4624.     {
  4625.         Connection          connection = null;
  4626.         PreparedStatement   ps = null;
  4627.         ResultSet           rs = null;
  4628.         String              query = null;
  4629.         ArrayList           fieldOfficeVillageMapList = new ArrayList();
  4630.         ArrayList           tempFieldOfficeVillageMapList = new ArrayList();
  4631.         Short               fieldOffice = null;
  4632.         Timestamp           startDate = null;
  4633.         Short               tempFieldOffice = null;
  4634.         Timestamp           tempStartDate = null;
  4635.         int                 index = 0;
  4636.         int                 counter = 0;
  4637.         int                 tempListSize = 0;
  4638.         int                 listSize = 0;
  4639.                
  4640.         try
  4641.         {
  4642.             //System.out.println("fieldOfficeMappingDate" + fieldOfficeMappingDate);
  4643.             query = GOSIBatchSQL.getSqlString("CMN_010_SQL_1001");
  4644.             //System.out.println(" query" + query);
  4645.             connection = getDbConnection(GOSIBatchConstants.COMMON);
  4646.             ps = connection.prepareStatement(query);
  4647.             ps.setTimestamp(1,fieldOfficeMappingDate);
  4648.             rs = ps.executeQuery();
  4649.             while(rs.next())
  4650.             {
  4651.                 FieldOfficeVillageMapListBean fieldOfficeBean =
  4652.                 new FieldOfficeVillageMapListBean();    
  4653.                
  4654.                 fieldOfficeBean.setFOCode
  4655.                 (new Short(rs.getShort(1)));
  4656.                                                
  4657.                 fieldOfficeBean.setStartDate
  4658.                 (rs.getTimestamp(2));
  4659.                
  4660.                 if(fieldOfficeBean.getStartDate()!= null)
  4661.                 {
  4662.                     fieldOfficeBean.setStartDateStr
  4663.                     (getDateFullString
  4664.                     (fieldOfficeBean.getStartDate()));
  4665.                 }
  4666.                                
  4667.                 tempFieldOfficeVillageMapList.
  4668.                 add(fieldOfficeBean);
  4669.                            
  4670.             }
  4671.                        
  4672.             //System.out.println(" temp fieldOfficeVillageMapList size" +
  4673.             //tempFieldOfficeVillageMapList.size());
  4674.            
  4675.             tempListSize = tempFieldOfficeVillageMapList.size();
  4676.            
  4677.             //System.out.println(" tempListSize" + tempListSize);
  4678.            
  4679.             if(tempListSize > 0)
  4680.             {
  4681.                 FieldOfficeVillageMapListBean tempFieldOfficeBean =
  4682.                 new FieldOfficeVillageMapListBean();    
  4683.                
  4684.                 FieldOfficeVillageMapListBean finalFieldOfficeBean =
  4685.                 new FieldOfficeVillageMapListBean();    
  4686.                    
  4687.                 for(index = 0;index < tempListSize;index ++)
  4688.                 {
  4689.                     finalFieldOfficeBean =
  4690.                     (FieldOfficeVillageMapListBean)
  4691.                     tempFieldOfficeVillageMapList.get(index);
  4692.                    
  4693.                     if(fieldOfficeVillageMapList.size() == 0)
  4694.                     {
  4695.                         //System.out.println(" in zero" );
  4696.                         fieldOfficeVillageMapList.add
  4697.                         (finalFieldOfficeBean);
  4698.                     }
  4699.                     else
  4700.                     {
  4701.                         boolean flag = true;
  4702.                         fieldOffice =
  4703.                         finalFieldOfficeBean.getFOCode();
  4704.                         //System.out.println("fieldOffice" +
  4705.                         //fieldOffice);
  4706.                         startDate =
  4707.                         finalFieldOfficeBean.getStartDate();
  4708.                         //System.out.println("start date" +
  4709.                         //startDate);
  4710.                        
  4711.                         listSize =
  4712.                         fieldOfficeVillageMapList.size();
  4713.                                                
  4714.                                            
  4715.                         for(counter = 0;counter < listSize;counter ++)
  4716.                         {
  4717.                             tempFieldOfficeBean =
  4718.                             (FieldOfficeVillageMapListBean)
  4719.                             fieldOfficeVillageMapList.get(counter);
  4720.                            
  4721.                             tempFieldOffice =
  4722.                             tempFieldOfficeBean.getFOCode();
  4723.                             //System.out.println("temp fieldOffice" +
  4724.                             //tempFieldOffice);
  4725.                             tempStartDate =
  4726.                             tempFieldOfficeBean.getStartDate();
  4727.                             //System.out.println(" temp start date" +
  4728.                             //tempStartDate);
  4729.                            
  4730.                             if((tempFieldOffice.equals(fieldOffice))
  4731.                             &&(tempStartDate.equals(startDate)))
  4732.                             {
  4733.                                 //System.out.println("inside equal");
  4734.                                 flag = false;
  4735.                                 break;
  4736.                                
  4737.                             }
  4738.                         }
  4739.                         if(flag)
  4740.                         {
  4741.                             //System.out.println(" inside");
  4742.                             fieldOfficeVillageMapList.
  4743.                             add(finalFieldOfficeBean);    
  4744.                         }
  4745.                     }
  4746.                 }
  4747.             }
  4748.             //System.out.println(" fieldOfficeVillageMapList size" +
  4749.             //fieldOfficeVillageMapList.size());
  4750.                      
  4751.         }
  4752.         catch(Exception e)
  4753.         {
  4754.             throw new GOSIBatchException(e,
  4755.             "BatchCore","GOSIBatchUtilities",
  4756.             "getFieldOfficeVillageMappingDetails()",
  4757.             "CMN_001_ERR_1000",
  4758.             GOSIBatchConstants.SEVERITY_ONE);
  4759.         }
  4760.         finally
  4761.         {
  4762.             GOSIBatchUtilities.cleanUp(rs,ps,connection);
  4763.         }
  4764.         return fieldOfficeVillageMapList;
  4765.     }
  4766.  
  4767.     protected static void setCurrentSystemTime(Timestamp currentDate)
  4768.     {
  4769.         currentSystemDate = currentDate;
  4770.     }
  4771.    
  4772.     public static void main(String a[])
  4773.     {
  4774.         try
  4775.         {
  4776.             String domainName = getDomainDetailsName("Location",
  4777.             new Short((short)1), true, GOSIBatchConstants.COMMON);
  4778.             //System.out.println("DOMAIN NAME : "+domainName);
  4779.         }catch(Exception e)
  4780.         {}
  4781.     }
  4782. /**
  4783.  * @METHOD NAME              : createRequest
  4784.  * @INFORMATION              : This method is used to create a batch request
  4785.  * @PARAM                    : batchRequestBean, conn
  4786.  * @RETURN                   : NIL
  4787.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  4788.  * @LAST MODIFIED BY         :
  4789.  * @LAST MODIFIED DATE       :
  4790. **/
  4791.  
  4792.  
  4793.     public static void createRequest(BatchRequestBean batchRequestBean,
  4794.     Connection conn, long requestedBy) throws GOSIBatchException
  4795.     {
  4796.  
  4797.         BatchParametersBean batchParametersBean = null;
  4798.  
  4799.         try
  4800.         {
  4801.             batchRequestBean.setRequestId(new Long((getPrimaryKey("T_BATCHREQUEST",
  4802.                 getSystemUser())).longValue()));
  4803.             //System.out.println(batchRequestBean.getRequestId()+"sss");
  4804.             //System.out.println(batchRequestBean.getBatchId()+"sss");
  4805.             //System.out.println(batchRequestBean.getRunDate()+"sss");
  4806.             //System.out.println(batchRequestBean.getRequestedBy()+"sss");
  4807.             //System.out.println(batchRequestBean.getRequestedTimeStamp()+"sss");
  4808.             psInsertBatchRequest.setLong(1,
  4809.                 batchRequestBean.getRequestId().longValue());
  4810.             psInsertBatchRequest.setTimestamp(2, batchRequestBean.getRunDate());
  4811.             psInsertBatchRequest.setString(3, batchRequestBean.getBatchId());
  4812.             psInsertBatchRequest.setLong(4,
  4813.                 requestedBy);
  4814.             psInsertBatchRequest.setTimestamp(5,
  4815.                 batchRequestBean.getRequestedTimeStamp());
  4816.             psInsertBatchRequest.addBatch();
  4817.             if(batchRequestBean.getParamValueList()!=null)
  4818.             {
  4819.                 ArrayList paramValueList = batchRequestBean.getParamValueList();
  4820.                 int size = paramValueList.size();
  4821.                 for(int i=0; i<size; i++)
  4822.                 {
  4823.                     batchParametersBean = (BatchParametersBean)
  4824.                         paramValueList.get(i);
  4825.                     psInsertParamValues.setLong(1,
  4826.                         batchRequestBean.getRequestId().longValue());
  4827.                     psInsertParamValues.setLong(2,
  4828.                         batchParametersBean.getParamId().longValue());
  4829.                     psInsertParamValues.setString(3,
  4830.                         batchParametersBean.getParamValue());
  4831.                     psInsertParamValues.addBatch();
  4832.                 }
  4833.             }
  4834.         }
  4835.         catch(Exception e)
  4836.         {
  4837.             new GOSIBatchException(e, "BatchCore", "GOSIUtilities",
  4838.                 "createRequest", "CMN_001_ERR_1000",
  4839.                     GOSIBatchConstants.SEVERITY_ONE);        
  4840.         }
  4841.     }
  4842.    
  4843.  
  4844.     /**
  4845.  * @METHOD NAME              : createRequest
  4846.  * @INFORMATION              : This method is used to create a batch request
  4847.  * @PARAM                    : batchRequestBean, conn
  4848.  * @RETURN                   : NIL
  4849.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  4850.  * @LAST MODIFIED BY         :
  4851.  * @LAST MODIFIED DATE       :
  4852. **/
  4853.  
  4854.  
  4855.     public static void createRequest(BatchRequestBean batchRequestBean,
  4856.     Connection conn) throws GOSIBatchException
  4857.     {
  4858.         createRequest(batchRequestBean, conn, getSystemUser());
  4859.     }
  4860.     /**
  4861.  * @METHOD NAME              : getDateDifference
  4862.  * @INFORMATION              : This method is used to find difference between
  4863.  *                             two Timestamps dates in number of days.
  4864.  * @PARAM                    : fromTimestamp, toTimestamp
  4865.  * @RETURN                   : int
  4866.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  4867.  * @LAST MODIFIED BY         :
  4868.  * @LAST MODIFIED DATE       :
  4869. **/
  4870.          
  4871.     public static int getDateDifference(Timestamp fromTimestamp,
  4872.     Timestamp toTimestamp) throws GOSIBatchException
  4873.     {
  4874.  
  4875.         int fromDay=0;
  4876.         int fromMonth=0;
  4877.         int fromYear=0;
  4878.  
  4879.         int toDay=0;
  4880.         int toMonth=0;
  4881.         int toYear=0;
  4882.  
  4883.         GregorianCalendar gc1 = null;
  4884.         GregorianCalendar gc2 = null;
  4885.         String fromDate=null;
  4886.         String toDate=null;
  4887.         int diffDays =0;
  4888.        
  4889.         try
  4890.         {
  4891.             if((fromTimestamp!=null)&&(toTimestamp!=null))
  4892.             {
  4893.                 fromDate=getDateFullString(fromTimestamp);
  4894.                 toDate=getDateFullString(toTimestamp);
  4895.                 StringTokenizer greStrDate =
  4896.                 new StringTokenizer(fromDate,"/-");
  4897.  
  4898.                 while(greStrDate .hasMoreTokens())
  4899.                 {
  4900.                     fromDay = Integer.
  4901.                     valueOf(greStrDate .nextToken()).intValue();
  4902.  
  4903.                     if(greStrDate.hasMoreTokens())
  4904.                     {
  4905.                         fromMonth = Integer.
  4906.                         valueOf(greStrDate.nextToken()).intValue();
  4907.                     }
  4908.                     if(greStrDate.hasMoreTokens())
  4909.                     {
  4910.                         fromYear = Integer.
  4911.                         valueOf(greStrDate.nextToken()).intValue();
  4912.                     }
  4913.  
  4914.                 }//while
  4915.  
  4916.                 gc1 = new GregorianCalendar(fromYear,fromMonth-1,fromDay);
  4917.                  
  4918.                 StringTokenizer greStrToDate = new StringTokenizer(toDate,"/-");
  4919.                
  4920.                 while(greStrToDate .hasMoreTokens())
  4921.                 {
  4922.                     toDay = Integer.valueOf(greStrToDate .nextToken()).intValue();
  4923.  
  4924.                     if(greStrToDate.hasMoreTokens())
  4925.                     {
  4926.                         toMonth = Integer.
  4927.                         valueOf(greStrToDate.nextToken()).intValue();
  4928.                     }
  4929.                     if(greStrToDate.hasMoreTokens())
  4930.                     {
  4931.                         toYear = Integer.
  4932.                         valueOf(greStrToDate.nextToken()).intValue();
  4933.                     }
  4934.                 }//while
  4935.                 gc2 = new GregorianCalendar(toYear,toMonth-1,toDay);
  4936.                 diffDays = gregorianDateDifference(gc1,gc2);
  4937.             }
  4938.         }//try
  4939.      
  4940.         catch(GOSIBatchException ge)
  4941.         {
  4942.         throw ge;
  4943.         }
  4944.         catch(Exception e)
  4945.         {
  4946.             new GOSIBatchException(e,
  4947.                                    "BatchCore",
  4948.                                    "GOSIUtilities",
  4949.                                    "getDateDifference",
  4950.                                    "CMN_001_ERR_1000",
  4951.                                    GOSIBatchConstants.SEVERITY_ONE);        
  4952.            
  4953.         }//catch
  4954.          
  4955.         return diffDays;
  4956.     }//method
  4957.  
  4958. /**
  4959.  * @METHOD NAME              : getGregorianDateDifference
  4960.  * @INFORMATION              : This method is used to find difference between
  4961.  *                              two gregorian dates in number of days.
  4962.  * @PARAM                    : fromDate, toDate
  4963.  * @RETURN                   : int
  4964.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  4965.  * @LAST MODIFIED BY         :
  4966.  * @LAST MODIFIED DATE       :
  4967. **/
  4968.  
  4969.     public static int getGregorianDateDifference(String fromDate,String toDate)
  4970.     throws GOSIBatchException
  4971.     {
  4972.            
  4973.         int fromDay=0;
  4974.         int fromMonth=0;
  4975.         int fromYear=0;
  4976.  
  4977.         int toDay=0;
  4978.         int toMonth=0;
  4979.         int toYear=0;
  4980.  
  4981.         GregorianCalendar gc1 = null;
  4982.         GregorianCalendar gc2 = null;
  4983.  
  4984.         int diffDays =0;
  4985.            
  4986.         try
  4987.         {
  4988.             validateGregorianDate(fromDate);
  4989.             validateGregorianDate(toDate);
  4990.             StringTokenizer greStrDate = new StringTokenizer(fromDate,"/-");
  4991.  
  4992.             while(greStrDate .hasMoreTokens())
  4993.             {
  4994.                 fromDay = Integer.valueOf(greStrDate .nextToken()).intValue();
  4995.  
  4996.                 if(greStrDate.hasMoreTokens())
  4997.                 {
  4998.                     fromMonth = Integer.valueOf(greStrDate.nextToken()).
  4999.                     intValue();
  5000.                 }
  5001.                 if(greStrDate.hasMoreTokens())
  5002.                 {
  5003.                     fromYear = Integer.valueOf(greStrDate.nextToken()).
  5004.                     intValue();
  5005.  
  5006.                 }
  5007.  
  5008.             }//while
  5009.  
  5010.             gc1 = new GregorianCalendar(fromYear,fromMonth-1,fromDay);
  5011.                        
  5012.             StringTokenizer greStrToDate = new StringTokenizer(toDate,"/-");
  5013.  
  5014.             while(greStrToDate .hasMoreTokens())
  5015.             {
  5016.                 toDay = Integer.valueOf(greStrToDate .nextToken()).intValue();
  5017.  
  5018.                 if(greStrToDate.hasMoreTokens())
  5019.                 {
  5020.                     toMonth = Integer.valueOf(greStrToDate.nextToken()).
  5021.                     intValue();
  5022.                 }
  5023.                 if(greStrToDate.hasMoreTokens())
  5024.                 {
  5025.                     toYear = Integer.valueOf(greStrToDate.nextToken()).
  5026.                     intValue();
  5027.                 }
  5028.             }//while
  5029.  
  5030.             gc2 = new GregorianCalendar(toYear,toMonth-1,toDay);
  5031.             diffDays = gregorianDateDifference(gc1,gc2);
  5032.             if(diffDays!=0)
  5033.             {
  5034.                 diffDays++;
  5035.             }
  5036.             else if((diffDays==0)&&(fromDate.equals(toDate)))
  5037.             {
  5038.                 diffDays++;
  5039.             }
  5040.  
  5041.         }//try
  5042.  
  5043.         catch(GOSIBatchException e)
  5044.         {
  5045.                 throw e;
  5046.         }
  5047.         catch(Exception e)
  5048.         {
  5049.                     new GOSIBatchException(e,
  5050.                     "BatchCore",
  5051.                     "GOSIUtilities",
  5052.                     "getGregorianDateDifference",
  5053.                     "CMN_001_ERR_1000",
  5054.                     GOSIBatchConstants.SEVERITY_ONE);        
  5055.         }//catch
  5056.  
  5057.         return diffDays;
  5058.     }//method
  5059.  
  5060.    
  5061. /**
  5062.  * @METHOD NAME              : validateGregorianDate
  5063.  * @INFORMATION              : This method takes the date in string (DD/MM/YYYY)
  5064.     *                       format and validates it against gregorian date.
  5065.     *                       If it is not valid gregorian date then, throws the
  5066.     *                       GOSIException
  5067.  * @PARAM                    : gDate
  5068.  * @RETURN                   : NIL
  5069.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  5070.  * @LAST MODIFIED BY         :
  5071.  * @LAST MODIFIED DATE       :
  5072. **/
  5073.  
  5074.     public static void validateGregorianDate(String gDate)
  5075.     throws GOSIBatchException
  5076.     {
  5077.         try
  5078.         {
  5079.             if((gDate == null)||(gDate.length()==0))
  5080.             {
  5081.                     new GOSIBatchException(new Exception(),
  5082.                     "BatchCore",
  5083.                     "GOSIUtilities",
  5084.                     "getGregorianDateDifference",
  5085.                     "CMN_001_ERR_1000",
  5086.                     GOSIBatchConstants.SEVERITY_ONE);        
  5087.  
  5088.             }
  5089.                    
  5090.             checkDateFormat(gDate);
  5091.            
  5092.             int count =0;
  5093.            
  5094.             for(int i=0;i< gDate.length();i++)
  5095.             {
  5096.                 char c = gDate.charAt(i);
  5097.                
  5098.                 if(Character.isDigit(c))
  5099.                 {}
  5100.                 else
  5101.                 {
  5102.                     if(c=='/')
  5103.                     {
  5104.                         count = count +1;
  5105.                         if(count<=2)
  5106.                         {
  5107.                             continue;
  5108.                         }
  5109.                         else
  5110.                         {
  5111.                             new GOSIBatchException(new Exception(),
  5112.                             "BatchCore",
  5113.                             "GOSIUtilities",
  5114.                             "getGregorianDateDifference",
  5115.                             "CMN_001_ERR_1000",
  5116.                             GOSIBatchConstants.SEVERITY_ONE);        
  5117.            
  5118.                         }
  5119.                     }
  5120.                     else
  5121.                     {
  5122.                             new GOSIBatchException(new Exception(),
  5123.                             "BatchCore",
  5124.                             "GOSIUtilities",
  5125.                             "getGregorianDateDifference",
  5126.                             "CMN_001_ERR_1000",
  5127.                             GOSIBatchConstants.SEVERITY_ONE);        
  5128.                     }
  5129.                 }//else
  5130.             }//for
  5131.            
  5132.             int fIndex = gDate.indexOf('/');
  5133.             int lIndex = gDate.lastIndexOf('/');
  5134.            
  5135.             int day = Integer.parseInt(gDate.substring(0,fIndex));
  5136.             int month = Integer.parseInt(gDate.substring((fIndex+1),lIndex));
  5137.             String yy = gDate.substring((lIndex+1),gDate.length());
  5138.             int year = Integer.parseInt(yy);
  5139.             if(yy.length() != 4)
  5140.             {
  5141.                     new GOSIBatchException(new Exception(),
  5142.                     "BatchCore",
  5143.                     "GOSIUtilities",
  5144.                     "getGregorianDateDifference",
  5145.                     "CMN_001_ERR_1000",
  5146.                     GOSIBatchConstants.SEVERITY_ONE);        
  5147.             }
  5148.            
  5149.                    
  5150.             if(month >12 || month < 1)
  5151.             {
  5152.                     new GOSIBatchException(new Exception(),
  5153.                     "BatchCore",
  5154.                     "GOSIUtilities",
  5155.                     "getGregorianDateDifference",
  5156.                     "CMN_001_ERR_1000",
  5157.                     GOSIBatchConstants.SEVERITY_ONE);        
  5158.             }
  5159.            
  5160.             if (((month == 1 )|| (month == 3 )|| (month == 5) || (month == 7 )||
  5161.             (month == 8 )|| (month == 10 )|| (month == 12)) && ((day > 31 )||
  5162.             (day < 1)))
  5163.             {
  5164.                     new GOSIBatchException(new Exception(),
  5165.                     "BatchCore",
  5166.                     "GOSIUtilities",
  5167.                     "getGregorianDateDifference",
  5168.                     "CMN_001_ERR_1000",
  5169.                     GOSIBatchConstants.SEVERITY_ONE);        
  5170.             }
  5171.             if (((month == 4) || (month == 6 )|| (month == 9 )|| (month == 11))
  5172.             && ((day > 30 )|| (day < 1)))
  5173.             {
  5174.                            
  5175.                     new GOSIBatchException(new Exception(),
  5176.                     "BatchCore",
  5177.                     "GOSIUtilities",
  5178.                     "getGregorianDateDifference",
  5179.                     "CMN_001_ERR_1000",
  5180.                     GOSIBatchConstants.SEVERITY_ONE);        
  5181.  
  5182.             }
  5183.  
  5184.             if (month == 2)
  5185.             {
  5186.                     if (day < 1)
  5187.                     {
  5188.                         new GOSIBatchException(new Exception(),
  5189.                         "BatchCore",
  5190.                         "GOSIUtilities",
  5191.                         "getGregorianDateDifference",
  5192.                         "CMN_001_ERR_1000",
  5193.                         GOSIBatchConstants.SEVERITY_ONE);        
  5194.                     }
  5195.                     if (isLeapYear(year) == true)
  5196.                     {
  5197.                         if (day > 29)
  5198.                         {
  5199.                             new GOSIBatchException(new Exception(),
  5200.                             "BatchCore",
  5201.                             "GOSIUtilities",
  5202.                             "getGregorianDateDifference",
  5203.                             "CMN_001_ERR_1000",
  5204.                             GOSIBatchConstants.SEVERITY_ONE);        
  5205.                         }
  5206.                     }
  5207.                     else
  5208.                     {
  5209.                         if (day > 28)
  5210.                         {
  5211.                             new GOSIBatchException(new Exception(),
  5212.                             "BatchCore",
  5213.                             "GOSIUtilities",
  5214.                             "getGregorianDateDifference",
  5215.                             "CMN_001_ERR_1000",
  5216.                             GOSIBatchConstants.SEVERITY_ONE);        
  5217.                         }
  5218.                     }
  5219.             }
  5220.            
  5221.         }//try
  5222.         catch(GOSIBatchException ge)
  5223.         {
  5224.             throw ge;
  5225.         }//GOSIEx
  5226.         catch(Exception e)
  5227.         {
  5228.             new GOSIBatchException(e,
  5229.             "BatchCore",
  5230.             "GOSIUtilities",
  5231.             "getGregorianDateDifference",
  5232.             "CMN_001_ERR_1000",
  5233.             GOSIBatchConstants.SEVERITY_ONE);        
  5234.  
  5235.         }
  5236.     }//method
  5237.  
  5238. /**
  5239.  * @METHOD NAME              : checkDateFormat
  5240.  * @INFORMATION              : This method takes the date, and check for date
  5241.     *                           formatin DD/MM/YYYY
  5242.  * @PARAM                    : date
  5243.  * @RETURN                   : NIL
  5244.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  5245.  * @LAST MODIFIED BY         :
  5246.  * @LAST MODIFIED DATE       :
  5247. **/
  5248.  
  5249.     public static void checkDateFormat(String date)
  5250.     throws GOSIBatchException
  5251.     {
  5252.         try
  5253.         {
  5254.             int count= date.length();
  5255.            
  5256.            
  5257.             if((count > 10)||(count < 8))
  5258.             {
  5259.                     new GOSIBatchException(new Exception(),
  5260.                     "BatchCore",
  5261.                     "GOSIUtilities",
  5262.                     "getGregorianDateDifference",
  5263.                     "CMN_001_ERR_1000",
  5264.                     GOSIBatchConstants.SEVERITY_ONE);        
  5265.  
  5266.             }//if
  5267.            
  5268.             else if(date.indexOf('.')> -1)
  5269.             {
  5270.                     new GOSIBatchException(new Exception(),
  5271.                     "BatchCore",
  5272.                     "GOSIUtilities",
  5273.                     "getGregorianDateDifference",
  5274.                     "CMN_001_ERR_1000",
  5275.                     GOSIBatchConstants.SEVERITY_ONE);        
  5276.             }//if
  5277.             else
  5278.             {
  5279.                 int fIndex=0;
  5280.                 int lIndex=0;
  5281.                
  5282.                 if (date.indexOf('/')!= -1)
  5283.                 {
  5284.                     fIndex=date.indexOf('/');
  5285.                     lIndex=date.lastIndexOf('/');
  5286.                    
  5287.                     if((fIndex==1)|| (fIndex==2))
  5288.                     {}
  5289.                     else
  5290.                     {
  5291.                             new GOSIBatchException(new Exception(),
  5292.                             "BatchCore",
  5293.                             "GOSIUtilities",
  5294.                             "getGregorianDateDifference",
  5295.                             "CMN_001_ERR_1000",
  5296.                             GOSIBatchConstants.SEVERITY_ONE);        
  5297.                     }
  5298.                     if((lIndex==3)||(lIndex==5)||(lIndex==4))
  5299.                     {} 
  5300.                     else
  5301.                     {
  5302.                             new GOSIBatchException(new Exception(),
  5303.                             "BatchCore",
  5304.                             "GOSIUtilities",
  5305.                             "getGregorianDateDifference",
  5306.                             "CMN_001_ERR_1000",
  5307.                             GOSIBatchConstants.SEVERITY_ONE);        
  5308.                     }
  5309.                    
  5310.                     if(fIndex==1)
  5311.                     {
  5312.                         if((lIndex==3)||(lIndex==4))
  5313.                         {}
  5314.                         else
  5315.                         {
  5316.                             new GOSIBatchException(new Exception(),
  5317.                             "BatchCore",
  5318.                             "GOSIUtilities",
  5319.                             "getGregorianDateDifference",
  5320.                             "CMN_001_ERR_1000",
  5321.                             GOSIBatchConstants.SEVERITY_ONE);        
  5322.                            
  5323.                         }
  5324.                     }
  5325.                     if(fIndex==2)
  5326.                     {
  5327.                         if((lIndex==5)||(lIndex==4))
  5328.                         {}
  5329.                         else
  5330.                         {
  5331.                             new GOSIBatchException(new Exception(),
  5332.                             "BatchCore",
  5333.                             "GOSIUtilities",
  5334.                             "getGregorianDateDifference",
  5335.                             "CMN_001_ERR_1000",
  5336.                             GOSIBatchConstants.SEVERITY_ONE);        
  5337.                         }
  5338.                     }
  5339.  
  5340.                 }//if-outer
  5341.                
  5342.                 else
  5343.                 {
  5344.                             new GOSIBatchException(new Exception(),
  5345.                             "BatchCore",
  5346.                             "GOSIUtilities",
  5347.                             "getGregorianDateDifference",
  5348.                             "CMN_001_ERR_1000",
  5349.                             GOSIBatchConstants.SEVERITY_ONE);        
  5350.                 }
  5351.                
  5352.                 if((lIndex==-1)||(lIndex==fIndex))
  5353.                 {
  5354.                             new GOSIBatchException(new Exception(),
  5355.                             "BatchCore",
  5356.                             "GOSIUtilities",
  5357.                             "getGregorianDateDifference",
  5358.                             "CMN_001_ERR_1000",
  5359.                             GOSIBatchConstants.SEVERITY_ONE);        
  5360.                 }  
  5361.  
  5362.                    
  5363.             }//else
  5364.         }//try
  5365.         catch(GOSIBatchException ge)
  5366.         {
  5367.             throw ge;
  5368.         }
  5369.         catch(Exception e)
  5370.         {
  5371.                             new GOSIBatchException(e,
  5372.                             "BatchCore",
  5373.                             "GOSIUtilities",
  5374.                             "getGregorianDateDifference",
  5375.                             "CMN_001_ERR_1000",
  5376.                             GOSIBatchConstants.SEVERITY_ONE);        
  5377.         }//catch
  5378.     }//method
  5379. /**
  5380.  * @METHOD NAME              : isLeapYear
  5381.  * @INFORMATION              : checks given year is leap year
  5382.  * @PARAM                    : year
  5383.  * @RETURN                   : boolean
  5384.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  5385.  * @LAST MODIFIED BY         :
  5386.  * @LAST MODIFIED DATE       :
  5387. **/
  5388.  
  5389. private static boolean isLeapYear(int year)  
  5390. throws GOSIBatchException
  5391. {                                                                                                                                                  
  5392.        
  5393.     try
  5394.     {
  5395.         if (year % 4 != 0)                                                                                                                 
  5396.         {                                                                                                                                              
  5397.             return false;                                                                                                                          
  5398.         }                                                                                                                                              
  5399.                                                                                                                                                                
  5400.         if (year % 400 == 0)                                                                                                               
  5401.         {                                                                                                                                              
  5402.             return true;                                                                                                                           
  5403.         }                                                                                                                                              
  5404.     }//try
  5405.     catch(Exception e)
  5406.     {
  5407.         new GOSIBatchException(e,
  5408.         "BatchCore",
  5409.         "GOSIUtilities",
  5410.         "isLeapYear()",
  5411.         "CMN_001_ERR_1000",
  5412.         GOSIBatchConstants.SEVERITY_ONE);        
  5413.     }//catch
  5414.    return (year % 100 != 0);                                                                                                       
  5415. }  
  5416.  
  5417. /**
  5418.  * @METHOD NAME              : gregorianDateDifference
  5419.  * @INFORMATION              : This method is used to find difference between two
  5420.  *                              gregorian dates in number of days.
  5421.  * @PARAM                    : g1, g2
  5422.  * @RETURN                   : int
  5423.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  5424.  * @LAST MODIFIED BY         :
  5425.  * @LAST MODIFIED DATE       :
  5426. **/
  5427.  
  5428.     private  static int gregorianDateDifference(GregorianCalendar g1,          
  5429.     GregorianCalendar g2)throws GOSIBatchException
  5430.     {                                                                                                                                                        
  5431.           int elapsed = 0;                                                                                                                           
  5432.           GregorianCalendar gc1, gc2;                                                                                                            
  5433.             try                                                                                                                                          
  5434.             {                                                                                                                                                
  5435.                   if (g2.after(g1))                                                                                    
  5436.                   {                                                                                                      
  5437.                      gc2 = (GregorianCalendar) g2.clone();                                             
  5438.                      gc1 = (GregorianCalendar) g1.clone();                                             
  5439.                   }                                                                                                        
  5440.                   else                                                                                                       
  5441.                   {                                                                                                                                                                                  
  5442.                      gc2 = (GregorianCalendar) g1.clone();                                             
  5443.                      gc1 = (GregorianCalendar) g2.clone();                                             
  5444.                   }                                                                                                        
  5445.                                                                                                                                
  5446.                   gc1.clear(Calendar.MILLISECOND);                                                     
  5447.                   gc1.clear(Calendar.SECOND);                                                              
  5448.                   gc1.clear(Calendar.MINUTE);                                                                  
  5449.                   gc1.clear(Calendar.HOUR_OF_DAY);                                                     
  5450.                                                                                                                                
  5451.                   gc2.clear(Calendar.MILLISECOND);                                                     
  5452.                   gc2.clear(Calendar.SECOND);                                                              
  5453.                   gc2.clear(Calendar.MINUTE);                                                                  
  5454.                   gc2.clear(Calendar.HOUR_OF_DAY);                                                     
  5455.                                                                                                                                
  5456.                   while ( gc1.before(gc2) )                                                                        
  5457.                   {                                                                                                        
  5458.                      gc1.add(Calendar.DATE, 1);                                    
  5459.                      elapsed++;                                                                
  5460.                   }                                                                                
  5461.             }//try                                                                                 
  5462.             catch(Exception e)
  5463.             {
  5464.                 new GOSIBatchException(e,
  5465.                 "BatchCore",
  5466.                 "GOSIUtilities",
  5467.                 "gregorianDateDifference()",
  5468.                 "CMN_001_ERR_1000",
  5469.                 GOSIBatchConstants.SEVERITY_ONE);        
  5470.    
  5471.             }
  5472.       return elapsed;
  5473.    }
  5474. /**
  5475.  * @METHOD NAME              : isAccidentalRerun
  5476.  * @INFORMATION              : checks whether the job is accidental rerun.
  5477.                                 Means the frequency should match witht the current date and as well the batch should not been run for this date
  5478.  * @PARAM                    : batchProcessController
  5479.  * @RETURN                   : NIL
  5480.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  5481.  * @LAST MODIFIED BY         :
  5482.  * @LAST MODIFIED DATE       :
  5483. **/
  5484.  
  5485.     public static void isAccidentalRerun(BatchProcessController batchProcessController)
  5486.     throws GOSIBatchException
  5487.     {
  5488.         try
  5489.         {
  5490.             BatchRestart batchRestartInLastRun = batchProcessController.getBatchRestartInLastRun();
  5491.             BatchMaster batchMaster= batchProcessController.getBatchMaster();
  5492.             //System.out.println("BatchRunFrequency : "+batchMaster.getBatchRunFrequency());
  5493.             String batchRunFrequency = batchMaster.getBatchRunFrequency();
  5494.  
  5495.             boolean isRunnable = false;
  5496.             String errorCode = "";
  5497.             // If the batchRunFrequency taking the each character in each position into different variables
  5498.             if(batchRunFrequency!=null)
  5499.             {
  5500.                 // No condition adhoc batch
  5501.                 String condition1=batchRunFrequency.substring(0,1);
  5502.                 // Daily
  5503.                 String condition2=batchRunFrequency.substring(1,2);
  5504.                 // weekly
  5505.                 String condition3=batchRunFrequency.substring(2,3);
  5506.                 // Hijira Month End
  5507.                 String condition4=batchRunFrequency.substring(3,4);
  5508.                 // Hijira Year End
  5509.                 String condition5=batchRunFrequency.substring(4,5);
  5510.                 // Gregorian Month End
  5511.                 String condition6=batchRunFrequency.substring(5,6);
  5512.                 // Gregorian Year End
  5513.                 String condition7=batchRunFrequency.substring(6,7);
  5514.                 // Hijira Month Start
  5515.                 String condition8=batchRunFrequency.substring(7,8);
  5516.                 // Gregorian Month Start
  5517.                 String condition9=batchRunFrequency.substring(8,9);
  5518.                 // Hijira Year Start
  5519.                 String condition10=batchRunFrequency.substring(9,10);
  5520.                 // Gregorian Year Start
  5521.                 String condition11=batchRunFrequency.substring(10,11);
  5522.                 // Fortnight
  5523.                 String condition12=batchRunFrequency.substring(11,12);
  5524.              
  5525. //                System.out.println("Last Run Date"+batchRestartInLastRun.getSuccessDate());          
  5526.                 // If the batchRestartInLastRun
  5527.                 if(batchRestartInLastRun!=null)
  5528.                 {
  5529. //                    Timestamp lastRunDate = batchRestartInLastRun.getLastRunDate();
  5530.                     // Taking the last successful run date
  5531.                     Timestamp lastRunDate = batchRestartInLastRun.getSuccessDate();
  5532.                     System.out.println("lastRunDate "+lastRunDate);
  5533.                 // If lastRunDate means the batch has run already
  5534.                   if(lastRunDate!=null)
  5535.                   {
  5536.                     //System.out.println("Condition2 : "+condition2);
  5537.                    
  5538.                     if("1".equals(condition1))
  5539.                     {
  5540.                         /*if(GOSIBatchUtilities.getTimestamp(
  5541.                           GOSIBatchUtilities.getDateFullString(lastRunDate)).
  5542.                           equals(GOSIBatchUtilities.getTimestamp(
  5543.                           GOSIBatchUtilities.getDateFullString(
  5544.                           getSystemDate()))))
  5545.                           {
  5546.                             isRunnable = false;                    
  5547.                           }
  5548.                           else
  5549.                           {*/
  5550.                             isRunnable = true;
  5551.                           //}
  5552.                     }
  5553.  
  5554.                     // Daily
  5555.                     if("1".equals(condition2))
  5556.                     {
  5557.                         // Checking the system date should be >= then last run date
  5558.                         if(Long.parseLong(GOSIBatchUtilities.getLdapDateFromTimestamp(
  5559.                          getSystemDate()))<=
  5560.                         Long.parseLong(GOSIBatchUtilities.getLdapDateFromTimestamp(
  5561.                             lastRunDate)))
  5562.                         {
  5563.                             // If not making isRunnable flase
  5564.                             isRunnable=false;
  5565.                             errorCode ="CMN_001_ERR_1051";
  5566.                         }
  5567.                         else
  5568.                         {
  5569.                             // else making isRunnable true mean it can run
  5570.                             isRunnable = true;
  5571.                         }
  5572.                     }
  5573.                     // Weekly
  5574.                     if("1".equals(condition3))
  5575.                     {
  5576.                         // Getting the date difference in an array on year, months and days
  5577.                         int[] array = GOSIBatchDateUtilities.getDateDiff
  5578.                                         (getDateFullString(lastRunDate),
  5579.                                         getDateFullString(getSystemDate()),
  5580.                             GOSIBatchConstants.GREG_CALENDARTYPE);
  5581.                         // If the total no days is<=7 then making isRunnable flase if it's not already true
  5582.                         if((array[0]+(array[1]*30)+(array[2]*365))<=7)
  5583.                         {
  5584.                             if(!isRunnable)
  5585.                             {
  5586.                                 isRunnable = false;
  5587.                                 errorCode ="CMN_001_ERR_1052";
  5588.                             }
  5589.                         }
  5590.                         else
  5591.                         {
  5592.                             // If greater than 7 days the making isRunnable true
  5593.                             isRunnable = true;
  5594.                         }
  5595.  
  5596.                     }
  5597.                     // Case for hijira month end                    
  5598.                     if("1".equals(condition4))
  5599.                     {  
  5600.                         // Checking whether the isHijMonthEndJob is true or not
  5601.                          if(batchProcessController.isHijMonthEndJob())
  5602.                          {
  5603.                            // CHecking if the lastRunDate and getSystemDate
  5604.                             if(getDateFullString(lastRunDate).equals(
  5605.                                 getDateFullString(getSystemDate())))                        
  5606.                             {
  5607.                                 // If they are same making isRunnable flase
  5608.                                 if(!isRunnable)
  5609.                                 {
  5610.                                     isRunnable = false;
  5611.                                     errorCode ="CMN_001_ERR_1053";
  5612.                                 }
  5613.                             }
  5614.                             else
  5615.                             {
  5616.                                 // If not making isRunnable true
  5617.                                 isRunnable = true;
  5618.                             }
  5619.                          }
  5620.                          else
  5621.                          {
  5622.                             // If isHijMonthEndJob not true then making isRunnable flase
  5623.                             if(!isRunnable)
  5624.                             {
  5625.                                 isRunnable = false;
  5626.                                 errorCode ="CMN_001_ERR_1054";
  5627.                             }
  5628.                          }                            
  5629.                     }
  5630.                     // Case for Hijira Year-end
  5631.                     if("1".equals(condition5))
  5632.                     {
  5633.                         // Checking isHijYearEndJob flag is true or not
  5634.                          if(batchProcessController.isHijYearEndJob())
  5635.                          {
  5636.                              // Checking the lastRunDate and system date or equal or not
  5637.                             if(getDateFullString(lastRunDate).equals(getDateFullString(getSystemDate())))
  5638.                             {
  5639.                                 if(!isRunnable)
  5640.                                 {
  5641.                                     isRunnable = false;
  5642.                                     errorCode ="CMN_001_ERR_1059";
  5643.                                 }
  5644.                              }
  5645.                              else
  5646.                              {
  5647.                                  isRunnable = true;
  5648.                              }
  5649.                          }
  5650.                          else
  5651.                          {
  5652.                                 if(!isRunnable)
  5653.                                 {
  5654.                                     isRunnable = false;
  5655.                                     errorCode ="CMN_001_ERR_1060";
  5656.                                 }
  5657.                          }
  5658.                     }                            
  5659.                     // Case for Gregorian Month-end
  5660.                     if("1".equals(condition6))
  5661.                     {
  5662.                         // Checking whether isGregMonthEndJob flag is true or not
  5663.                         if(batchProcessController.isGregMonthEndJob())
  5664.                          {
  5665.                             // Checking the lastRunDate and system date or equal or not
  5666.                             if(getDateFullString(lastRunDate).equals(getDateFullString(getSystemDate())))                        
  5667.                             {
  5668.                                 if(!isRunnable)
  5669.                                 {
  5670.                                     isRunnable = false;
  5671.                                     errorCode ="CMN_001_ERR_1055";
  5672.                                 }
  5673.                              }
  5674.                              else
  5675.                              {
  5676.                                  isRunnable = true;
  5677.                              }
  5678.                          }
  5679.                          else
  5680.                          {
  5681.                              if(!isRunnable)
  5682.                              {
  5683.                                 isRunnable = false;
  5684.                                 errorCode ="CMN_001_ERR_1056";
  5685.                              }
  5686.                          }
  5687.                     }
  5688.                     // Case for Gregorian Year-end
  5689.                     if("1".equals(condition7))
  5690.                     {
  5691.                         // Checking whether isGregYearEndJob is true or not
  5692.                          if(batchProcessController.isGregYearEndJob())
  5693.                          {
  5694.                              // Checking lastRunDate and system date or equal or not
  5695.                             if(getDateFullString(lastRunDate).equals(getDateFullString(getSystemDate())))
  5696.                             {
  5697.                                 if(!isRunnable)
  5698.                                 {
  5699.                                     errorCode ="CMN_001_ERR_1057";
  5700.                                 }
  5701.                              }
  5702.                              else
  5703.                              {
  5704.                                  isRunnable = true;
  5705.                              }
  5706.                          }
  5707.                          else
  5708.                          {
  5709.                              if(!isRunnable)
  5710.                              {
  5711.                                  errorCode ="CMN_001_ERR_1058";
  5712.                              }
  5713.                          }
  5714.                     }                    
  5715.                     // Case for hijira month start
  5716.                     if("1".equals(condition8))
  5717.                     {
  5718.                         // Checking whether the system date is HijiraMonthStartDate or not
  5719.                         boolean isHijiraMonthStartDate = isHijiraMonthStartDate
  5720.                                                         (getSystemDate());
  5721.                         if(isHijiraMonthStartDate)
  5722.                         {
  5723.                             // CHecking whether lastRunDate and getSystemDate are equal or not
  5724.                             if(getDateFullString(lastRunDate).equals(getDateFullString(getSystemDate())))
  5725.                             {
  5726.                                 if(!isRunnable)
  5727.                                 {
  5728.                                     errorCode ="CMN_001_ERR_1061";
  5729.                                 }
  5730.                              }  
  5731.                              else
  5732.                             {
  5733.                                  isRunnable = true;
  5734.                             }
  5735.                         }
  5736.                         else
  5737.                         {
  5738.    
  5739.                             if(!isRunnable)
  5740.                             {
  5741.                                 errorCode ="CMN_001_ERR_1062";
  5742.                             }                          
  5743.                         }
  5744.                     }
  5745.                     // Case for Gregorian Month-start
  5746.                     if("1".equals(condition9))
  5747.                     {
  5748.                         // Checking the whether the system date is GregMonthStartDate or not
  5749.                         boolean isGregMonthStartDate = isGregMonthStartDate
  5750.                                                         (getSystemDate());
  5751.                         if(isGregMonthStartDate)
  5752.                         {
  5753.                             // Checking the lastRunDate and system date or equal or not
  5754.                             if(getDateFullString(lastRunDate).equals(getDateFullString(getSystemDate())))
  5755.                             {
  5756.                                 if(!isRunnable)
  5757.                                 {
  5758.                                     errorCode ="CMN_001_ERR_1063";
  5759.                                 }
  5760.                              }    
  5761.                              else
  5762.                              {
  5763.                                  isRunnable = true;
  5764.                              }
  5765.                         }
  5766.                         else
  5767.                         {
  5768.                             if(!isRunnable)
  5769.                             {
  5770.                                 errorCode ="CMN_001_ERR_1064";
  5771.                             }
  5772.                         }
  5773.                     }
  5774.                     // Case for Hijira Year-start
  5775.                     if("1".equals(condition10))
  5776.                     {
  5777.                         // Checking whether the system date is GregMonthStartDate or not
  5778.                         boolean isHijiraYearStartDate = isHijraYearStartDate
  5779.                                                         (getSystemDate());
  5780.                         if(isHijiraYearStartDate)
  5781.                         {
  5782.                             // Checking the lastRunDate and system date or equal or not
  5783.                             if(getDateFullString(lastRunDate).equals(getDateFullString(getSystemDate())))
  5784.                             {
  5785.                                 if(!isRunnable)
  5786.                                 {
  5787.                                     errorCode ="CMN_001_ERR_1063";
  5788.                                 }
  5789.                              }                            
  5790.                              else
  5791.                             {
  5792.                                  isRunnable = true;
  5793.                             }
  5794.                         }
  5795.                         else
  5796.                         {
  5797.                             if(!isRunnable)
  5798.                             {
  5799.                                 errorCode ="CMN_001_ERR_1064";
  5800.                             }
  5801.                         }
  5802.                     }
  5803.                     // Case for Gregorian Year-start
  5804.                     if("1".equals(condition11))
  5805.                     {    
  5806.                         // CHecking whether the system date is GregMonthStartDate or not
  5807.                         boolean isGregYearStartDate = isGregYearStartDate
  5808.                                                         (getSystemDate());
  5809.                         if(isGregYearStartDate)
  5810.                         {
  5811.                             // Checking lastRunDate is equal to system date or not
  5812.                             if(getDateFullString(lastRunDate).equals(getDateFullString(getSystemDate())))
  5813.                             {
  5814.                                 if(!isRunnable)
  5815.                                 {
  5816.                                     errorCode ="CMN_001_ERR_1063";
  5817.                                 }
  5818.                              }                            
  5819.                              else
  5820.                             {
  5821.                                  isRunnable = true;
  5822.                             }
  5823.                         }
  5824.                         else
  5825.                         {
  5826.                             if(!isRunnable)
  5827.                             {
  5828.                                 errorCode ="CMN_001_ERR_1063";
  5829.                             }
  5830.                          }
  5831.                     }
  5832.                     // This is for biweekly
  5833.                     if("1".equals(condition12))
  5834.                     {
  5835.                         // Getting the no of days between the last run date and system date in yer,month and days array
  5836.                         int[] array = GOSIBatchDateUtilities.getDateDiff
  5837.                                         (getDateFullString(lastRunDate),
  5838.                                         getDateFullString(getSystemDate()),
  5839.                                         GOSIBatchConstants.GREG_CALENDARTYPE);
  5840.                         isRunnable = true;
  5841.                         // Checking the no days if no of days or <=14 days then batch can be run or not batch can be run
  5842.                         if((array[0]+(array[1]*30)+(array[2]*365))<=14)
  5843.                         {
  5844.                             if(!isRunnable)
  5845.                             {
  5846.                                 errorCode ="CMN_001_ERR_1063";
  5847.                             }
  5848.                            //System.out.println("Error Occured due to accidental run ");
  5849.                         }
  5850.                         else
  5851.                         {
  5852.                             isRunnable = true;
  5853.                         }
  5854.                     }
  5855.                   }
  5856.                     else
  5857.                     {
  5858.                         //System.out.println("in the else "+isRunnable );
  5859.                         // If lastRunDate is null the making isRunnable true
  5860.                         isRunnable=true;
  5861.                     }
  5862.                 }
  5863.                 else
  5864.                 {
  5865.                     // If batchRestartInLastRun is null the making isRunnable true
  5866.                     isRunnable=true;
  5867.                 }
  5868.                
  5869.  
  5870.                 if(!isRunnable)
  5871.                 {
  5872.                     //System.out.println("error code : "+errorCode);
  5873.  
  5874.                         new GOSIBatchException(new Exception(),
  5875.                              "BatchCore",
  5876.                               "GOSIUtilities",
  5877.                               "isAccidentalRe-run",
  5878.                               errorCode,
  5879.                               GOSIBatchConstants.SEVERITY_ONE);        
  5880.                 }
  5881.             }
  5882.         }catch(GOSIBatchException ge)
  5883.         {
  5884.          throw ge;      
  5885.         }catch(Exception e)
  5886.         {
  5887.             new GOSIBatchException(e,
  5888.                 "BatchCore",
  5889.                 "GOSIUtilities",
  5890.                 "isAccidentalRerun",
  5891.                 "CMN_001_ERR_1000",
  5892.                 GOSIBatchConstants.SEVERITY_ONE);        
  5893.         }
  5894.    }
  5895.    
  5896.    /**
  5897.  * @METHOD NAME              : isHijiraMonthStartDate
  5898.  * @INFORMATION              : checks whether given date is hijrah month start
  5899.                                  date  
  5900.  * @PARAM                    :
  5901.  * @RETURN                   :
  5902.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  5903.  * @LAST MODIFIED BY         :
  5904.  * @LAST MODIFIED DATE       :
  5905. **/
  5906.  
  5907.    private static boolean isHijiraMonthStartDate(Timestamp date)
  5908.    throws GOSIBatchException
  5909.    {
  5910.     boolean isHijraMonthStartDate = false;
  5911.     try
  5912.     {
  5913.         String hijiraDate = GOSIBatchDateUtilities.convertToHijra
  5914.                             (getDateFullString(date));
  5915.         //System.out.println("Hijira Date : "+hijiraDate);      
  5916.        
  5917.         if((new Byte(hijiraDate.substring(0,2))).byteValue()==1)
  5918.         {
  5919.             isHijraMonthStartDate = true;
  5920.         }
  5921.         //System.out.println("Is hijira Month start Date : "+
  5922.           //                  isHijraMonthStartDate);                            
  5923.     }catch(GOSIBatchException ge)
  5924.     {
  5925.         throw ge;
  5926.     }catch(Exception e)
  5927.     {
  5928.         new GOSIBatchException(e,
  5929.                 "BatchCore",
  5930.                 "GOSIUtilities",
  5931.                 "isHijiraMonthStartDate",
  5932.                 "CMN_001_ERR_1000",
  5933.                 GOSIBatchConstants.SEVERITY_ONE);        
  5934.     }
  5935.     return isHijraMonthStartDate;
  5936.    }
  5937.    
  5938.    /**
  5939.  * @METHOD NAME              : isGregMonthStartDate
  5940.  * @INFORMATION              : Checks whether entered date gregorian month start date
  5941.  * @PARAM                    : date
  5942.  * @RETURN                   : boolean
  5943.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  5944.  * @LAST MODIFIED BY         :
  5945.  * @LAST MODIFIED DATE       :
  5946. **/
  5947.  
  5948.    private static boolean isGregMonthStartDate(Timestamp date)
  5949.    throws GOSIBatchException
  5950.    {
  5951.     boolean isHijraMonthStartDate = false;
  5952.     try
  5953.     {
  5954.        
  5955.         String gregDate = getDateFullString(date);        
  5956.         if((new Byte(gregDate.substring(0,2))).byteValue()==1)
  5957.         {
  5958.             isHijraMonthStartDate = true;
  5959.         }
  5960.         //System.out.println("Is hijira Month start Date : "+
  5961.           //                  isHijraMonthStartDate);                            
  5962.     }catch(GOSIBatchException ge)
  5963.     {
  5964.         throw ge;
  5965.     }catch(Exception e)
  5966.     {
  5967.         new GOSIBatchException(e,
  5968.                 "BatchCore",
  5969.                 "GOSIUtilities",
  5970.                 "isGregMonthStartDate",
  5971.                 "CMN_001_ERR_1000",
  5972.                 GOSIBatchConstants.SEVERITY_ONE);        
  5973.     }
  5974.     return isHijraMonthStartDate;
  5975.    }
  5976.  
  5977.  /**
  5978.  * @METHOD NAME              : isHijraYearStartDate
  5979.  * @INFORMATION              : Checks whether given year is hijirah yeart start
  5980.  *                             date
  5981.  * @PARAM                    : date
  5982.  * @RETURN                   : boolean
  5983.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  5984.  * @LAST MODIFIED BY         :
  5985.  * @LAST MODIFIED DATE       :
  5986. **/
  5987.  
  5988.   private static boolean isHijraYearStartDate(Timestamp date)
  5989.    throws GOSIBatchException
  5990.    {
  5991.     boolean isHijraYearStartDate = false;
  5992.     try
  5993.     {
  5994.         String hijiraDate = GOSIBatchDateUtilities.convertToHijra
  5995.                             (getDateFullString(date));
  5996.         if(((new Byte(hijiraDate.substring(0,2))).byteValue()==1) &&
  5997.         ((new Byte(hijiraDate.substring(3,5))).byteValue()==1))
  5998.         {
  5999.             isHijraYearStartDate = true;
  6000.         }
  6001.         //System.out.println("Is Hijra year start Date : "+
  6002.           //                  isHijraYearStartDate);                            
  6003.     }catch(GOSIBatchException ge)
  6004.     {
  6005.         throw ge;
  6006.     }catch(Exception e)
  6007.     {
  6008.         new GOSIBatchException(e,
  6009.                 "BatchCore",
  6010.                 "GOSIUtilities",
  6011.                 "isHijiraYearStartDate",
  6012.                 "CMN_001_ERR_1000",
  6013.                 GOSIBatchConstants.SEVERITY_ONE);        
  6014.     }
  6015.     return isHijraYearStartDate;
  6016.    }
  6017.  
  6018.    /**
  6019.  * @METHOD NAME              : isGregYearStartDate
  6020.  * @INFORMATION              : Returns whether given date is greg year start date
  6021.  * @PARAM                    : date
  6022.  * @RETURN                   : boolean
  6023.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  6024.  * @LAST MODIFIED BY         :
  6025.  * @LAST MODIFIED DATE       :
  6026. **/
  6027.  
  6028.    private static boolean isGregYearStartDate(Timestamp date)
  6029.    throws GOSIBatchException
  6030.    {
  6031.     boolean isGregYearStartDate = false;
  6032.     try
  6033.     {
  6034.        
  6035.         String gregDate = getDateFullString(date);        
  6036.         if(((new Byte(gregDate.substring(0,2))).byteValue()==1) &&
  6037.         ((new Byte(gregDate.substring(3,5))).byteValue()==1))
  6038.         {
  6039.             isGregYearStartDate = true;
  6040.         }
  6041.         //System.out.println("Is greg year start Date : "+
  6042.           //                  isGregYearStartDate);                            
  6043.     }catch(GOSIBatchException ge)
  6044.     {
  6045.         throw ge;
  6046.     }catch(Exception e)
  6047.     {
  6048.         new GOSIBatchException(e,
  6049.                 "BatchCore",
  6050.                 "GOSIUtilities",
  6051.                 "isGregYearStartDate",
  6052.                 "CMN_001_ERR_1000",
  6053.                 GOSIBatchConstants.SEVERITY_ONE);        
  6054.     }
  6055.     return isGregYearStartDate;
  6056.    }
  6057.  
  6058.    /**
  6059.  * @METHOD NAME              : getCurrentBatchRunFrequency
  6060.  * @INFORMATION              : Returns current batches run frequencies
  6061.  * @PARAM                    : NIL
  6062.  * @RETURN                   : class java.lang.String
  6063.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  6064.  * @LAST MODIFIED BY         :
  6065.  * @LAST MODIFIED DATE       :
  6066. **/
  6067.  
  6068.  
  6069.    protected String getCurrentBatchRunFrequency()
  6070.    {
  6071.         return this.currentBatchMaster.getBatchRunFrequency();
  6072.    }
  6073.    
  6074.  /**
  6075.  * @METHOD NAME              : getWorkflowGroupId
  6076.  * @INFORMATION              : Returns workflowgroupId this a unique number which is generated from the sequence.
  6077.                                 Check the documentation of T_BATCHWORKFLOWTXN GRIOUPID attribute for details
  6078.  * @PARAM                    : NIL
  6079.  * @RETURN                   : class java.lang.Long
  6080.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  6081.  * @LAST MODIFIED BY         :
  6082.  * @LAST MODIFIED DATE       :
  6083. **/
  6084.  
  6085.     private static Long getWorkflowGroupId()
  6086.     throws GOSIBatchException
  6087.     {
  6088.         Long groupId=null;
  6089.         try
  6090.         {
  6091.             groupId=getPrimaryKey("WORKFLOWGROUPID",
  6092.             getSystemUser());
  6093.         }catch(GOSIBatchException ge)
  6094.         {
  6095.             throw ge;
  6096.         }catch(Exception e)
  6097.         {
  6098.             new GOSIBatchException(e,
  6099.                     "BatchCore",
  6100.                     "GOSIUtilities",
  6101.                     "getWorkflowGroupId",
  6102.                     "CMN_001_ERR_1000",
  6103.                     GOSIBatchConstants.SEVERITY_ONE);        
  6104.         }
  6105.         return groupId;
  6106.      }
  6107.    
  6108.     /**
  6109.  * @METHOD NAME              : isHoliday
  6110.  * @INFORMATION              : Returns whether entered day is holiday
  6111.  * @PARAM                    : inputDate
  6112.  * @RETURN                   : boolean
  6113.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  6114.  * @LAST MODIFIED BY         :
  6115.  * @LAST MODIFIED DATE       :
  6116. **/
  6117.      
  6118.     public static boolean isHoliday(Timestamp inputDate)
  6119.     throws GOSIBatchException
  6120.     {      
  6121.         ResultSet rs = null;
  6122.         boolean isHoliday = false;
  6123.         try
  6124.         {
  6125.             //System.out.println("Session : input Date "+inputDate);
  6126.  
  6127.             psCheckIsHoliday.setTimestamp(1, inputDate);
  6128.             psCheckIsHoliday.setTimestamp(2, inputDate);
  6129.             rs = psCheckIsHoliday.executeQuery();
  6130.             if (rs.next())
  6131.             {
  6132.                 isHoliday = true;
  6133.             }
  6134.             //System.out.println("Is Holiday :"+isHoliday);
  6135.            
  6136.         }      
  6137.         catch(Exception e)
  6138.         {
  6139.                     new GOSIBatchException(e,
  6140.                     "BatchCore",
  6141.                     "GOSIUtilities",
  6142.                     "isHoliday",
  6143.                     "CMN_001_ERR_1000",
  6144.                     GOSIBatchConstants.SEVERITY_ONE);        
  6145.         }
  6146.         finally
  6147.         {
  6148.             GOSIBatchUtilities.cleanUp(rs);
  6149.         }  
  6150.         return isHoliday;
  6151.     }
  6152.  /**
  6153.  * @METHOD NAME              : getPrevDate
  6154.  * @INFORMATION              : Returns the previous working date, considering no.
  6155.                                displacement apart from holidays
  6156.  * @PARAM                    : currentDate, displacement
  6157.  * @RETURN                   : class java.sql.Timestamp
  6158.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  6159.  * @LAST MODIFIED BY         :
  6160.  * @LAST MODIFIED DATE       :
  6161. **/
  6162.    
  6163.     public static Timestamp getPrevDate(Timestamp currentDate,
  6164.     int displacement)throws GOSIBatchException{
  6165.        
  6166.         Timestamp resultantDate=null;
  6167.         PreparedStatement ps = null;
  6168.         ResultSet rs = null;
  6169.  
  6170.         try
  6171.         {
  6172.             do
  6173.             {
  6174.                 psFinalDate.setTimestamp(1, currentDate);
  6175.                 psFinalDate.setInt(2,displacement);
  6176.  
  6177.                 rs = psFinalDate.executeQuery();
  6178.  
  6179.                 if(rs.next())
  6180.                 {
  6181.                     resultantDate = rs.getTimestamp("FINALDATE");
  6182.                     //System.out.println("Final Date : "+resultantDate);
  6183.                 }
  6184.                 displacement = getNoOfHolidays(resultantDate,currentDate);
  6185.                 currentDate = resultantDate;
  6186.             }while(displacement!=0);
  6187.             //System.out.println("Date is : "+resultantDate);
  6188.         }catch(Exception e)
  6189.         {
  6190.             new GOSIBatchException(e,
  6191.                     "BatchCore",
  6192.                     "GOSIUtilities",
  6193.                     "isHoliday",
  6194.                     "CMN_001_ERR_1000",
  6195.                     GOSIBatchConstants.SEVERITY_ONE);
  6196.         }
  6197.         finally
  6198.         {
  6199.             GOSIBatchUtilities.cleanUp(rs);
  6200.         }
  6201.         return resultantDate;
  6202.     }  
  6203.     /**
  6204.  * @METHOD NAME              : getNoOfHolidays
  6205.  * @INFORMATION              : Returns no. of holidays between two dates
  6206.  * @PARAM                    : startDate, endDate
  6207.  * @RETURN                   : int
  6208.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  6209.  * @LAST MODIFIED BY         :
  6210.  * @LAST MODIFIED DATE       :
  6211. **/
  6212.  
  6213.     private static int getNoOfHolidays(Timestamp startDate, Timestamp
  6214.     endDate) throws GOSIBatchException
  6215.     {
  6216.         int totalHolidays =0;      
  6217.         ResultSet rs =null;
  6218.        
  6219.         try
  6220.         {
  6221.             StringBuffer sb = new StringBuffer(" SELECT ");
  6222.  
  6223.             psNoOfHolidays.setTimestamp(1, startDate);
  6224.             psNoOfHolidays.setTimestamp(2, endDate);
  6225.  
  6226.             rs = psNoOfHolidays.executeQuery();
  6227.  
  6228.             if(rs.next())
  6229.             {
  6230.                 totalHolidays = rs.getInt("TOTAL");
  6231.             }
  6232.  
  6233.         }catch(Exception e)
  6234.         {
  6235.              new GOSIBatchException(e,
  6236.                     "BatchCore",
  6237.                     "GOSIUtilities",
  6238.                     "isHoliday",
  6239.                     "CMN_001_ERR_1000",
  6240.                     GOSIBatchConstants.SEVERITY_ONE);
  6241.         }
  6242.         finally
  6243.         {
  6244.             GOSIBatchUtilities.cleanUp(rs);
  6245.         }
  6246.         return totalHolidays;      
  6247.     }
  6248.  
  6249.     /**
  6250.  * @METHOD NAME              : getTotalNoOfHolidays
  6251.  * @INFORMATION              : Returns Total no. of holidays between two dates
  6252.                                (Any 2 dates can be given)  
  6253.                                counting weekend days inside the holiday
  6254.  * @PARAM                    : startDate, endDate
  6255.  * @RETURN                   : int
  6256.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  6257.  * @LAST MODIFIED BY         :
  6258.  * @LAST MODIFIED DATE       :
  6259. **/
  6260.  
  6261.     public static int getTotalNoOfHolidays(Timestamp tStartDate, Timestamp
  6262.     tEndDate) throws GOSIBatchException
  6263.     {
  6264.         //GOSIDebug.debugMessages("%%%%%%%%%%%%%%  HOLIDAYS COUNT QUERY %%%%%%%%");
  6265.         Connection connection=null;    
  6266.         PreparedStatement psNoOfHolidaysA =null;
  6267.         PreparedStatement psNoOfHolidaysB =null;
  6268.         PreparedStatement psNoOfHolidaysC =null;
  6269.         PreparedStatement psNoOfHolidaysD =null;
  6270.         int HolidaysA =0;
  6271.         int HolidaysB =0;
  6272.         int HolidaysC =0;
  6273.         int HolidaysD =0;
  6274.         ResultSet rsA =null;
  6275.         ResultSet rsB =null;
  6276.         ResultSet rsC =null;
  6277.         ResultSet rsD =null;
  6278.         int totalHolidays =0;
  6279.         String startDate="";
  6280.         String endDate="";
  6281.  
  6282.         try
  6283.         {
  6284.             // converting given Timestamp into String
  6285.             startDate = GOSIBatchDateUtilities.getDateFullString(tStartDate);
  6286.             //GOSIDebug.debugMessages("startDate = " + startDate);
  6287.             endDate = GOSIBatchDateUtilities.getDateFullString(tEndDate);
  6288.             //GOSIDebug.debugMessages("endDate = " + endDate);
  6289.            
  6290.             connection=GOSIBatchUtilities.getDbConnection(GOSIBatchConstants.COMMON);
  6291.            
  6292.             // -------------------------------------------------------------           
  6293.             // case A: Holiday contained within the 2 dates
  6294.             String sqlQueryA="SELECT SUM((HOLIDAYENDDATE-HOLIDAYSTARTDATE)+1) TOTAL "+
  6295.                                 " FROM T_HOLIDAYS "+
  6296.                                 " WHERE TRUNC(HOLIDAYSTARTDATE) >=TO_DATE('"+startDate+"','dd/mm/yyyy') "+
  6297.                                 " AND TRUNC(HOLIDAYENDDATE) <=TO_DATE('"+endDate+"','dd/mm/yyyy') "+
  6298.                                 " AND HOLIDAYTYPE!=? AND STATUS =1";
  6299.             psNoOfHolidaysA=connection.prepareStatement(sqlQueryA);
  6300.             //System.out.println("sqlQuery select columns "+sqlQuery);
  6301.             psNoOfHolidaysA.setShort(1, GOSIBatchConstants.HOLIDAY_WEEKEND);
  6302.             rsA=psNoOfHolidaysA.executeQuery();
  6303.             //GOSIDebug.debugMessages("After executing HolidaysA query ");
  6304.             if(rsA.next())
  6305.             {
  6306.                 HolidaysA = rsA.getInt("TOTAL");
  6307.                 //GOSIDebug.debugMessages("HolidaysA = " + HolidaysA);
  6308.             }
  6309.            
  6310.             // -------------------------------------------------------------
  6311.             // case B: Holiday ended during
  6312.             String sqlQueryB="SELECT SUM((HOLIDAYENDDATE-TO_DATE('"+startDate+"','dd/mm/yyyy') )+1) TOTAL "+
  6313.                                 " FROM T_HOLIDAYS "+
  6314.                                 " WHERE TRUNC(HOLIDAYENDDATE) >= TO_DATE('"+startDate+"','dd/mm/yyyy')  "+
  6315.                                 " AND TRUNC(HOLIDAYENDDATE) <= TO_DATE('"+endDate+"','dd/mm/yyyy')  "+
  6316.                                 " AND TRUNC(HOLIDAYSTARTDATE) < TO_DATE('"+startDate+"','dd/mm/yyyy')  "+
  6317.                                 " AND HOLIDAYTYPE!=? AND STATUS =1";
  6318.             psNoOfHolidaysB=connection.prepareStatement(sqlQueryB);
  6319.             //System.out.println("sqlQuery select columns "+sqlQuery);
  6320.             psNoOfHolidaysB.setShort(1, GOSIBatchConstants.HOLIDAY_WEEKEND);
  6321.             rsB=psNoOfHolidaysB.executeQuery();
  6322.             //GOSIDebug.debugMessages("After executing HolidaysB query ");
  6323.             if(rsB.next())
  6324.             {
  6325.                 HolidaysB = rsB.getInt("TOTAL");
  6326.                 //GOSIDebug.debugMessages("HolidaysB = " + HolidaysB);
  6327.             }
  6328.            
  6329.             // -------------------------------------------------------------
  6330.             // case C: Holiday started during
  6331.             String sqlQueryC="SELECT SUM((TO_DATE('"+endDate+"','dd/mm/yyyy') -HOLIDAYSTARTDATE)+1) TOTAL "+
  6332.                                 " FROM T_HOLIDAYS "+
  6333.                                 " WHERE TRUNC(HOLIDAYSTARTDATE) >= TO_DATE('"+startDate+"','dd/mm/yyyy')  "+
  6334.                                 " AND TRUNC(HOLIDAYSTARTDATE) <= TO_DATE('"+endDate+"','dd/mm/yyyy')  "+
  6335.                                 " AND TRUNC(HOLIDAYENDDATE) > TO_DATE('"+endDate+"','dd/mm/yyyy')  "+
  6336.                                 " AND HOLIDAYTYPE!=? AND STATUS =1";
  6337.             psNoOfHolidaysC=connection.prepareStatement(sqlQueryC);
  6338.             //System.out.println("sqlQuery select columns "+sqlQuery);
  6339.             psNoOfHolidaysC.setShort(1, GOSIBatchConstants.HOLIDAY_WEEKEND);
  6340.             rsC=psNoOfHolidaysC.executeQuery();
  6341.             //GOSIDebug.debugMessages("After executing HolidaysC query ");
  6342.             if(rsC.next())
  6343.             {
  6344.                 HolidaysC = rsC.getInt("TOTAL");
  6345.                 //GOSIDebug.debugMessages("HolidaysC = " + HolidaysC);
  6346.             }
  6347.  
  6348.             // -------------------------------------------------------------
  6349.             // case D: Holiday extends before and beyond
  6350.             String sqlQueryD="SELECT SUM((TO_DATE('"+endDate+"','dd/mm/yyyy') -TO_DATE('"+startDate+"','dd/mm/yyyy') )+1) TOTAL "+
  6351.                                 " FROM T_HOLIDAYS "+
  6352.                                 " WHERE TRUNC(HOLIDAYSTARTDATE) < TO_DATE('"+startDate+"','dd/mm/yyyy')  "+
  6353.                                 " AND TRUNC(HOLIDAYENDDATE) > TO_DATE('"+endDate+"','dd/mm/yyyy')  "+
  6354.                                 " AND HOLIDAYTYPE!=? AND STATUS =1";
  6355.             psNoOfHolidaysD=connection.prepareStatement(sqlQueryD);
  6356.             //System.out.println("sqlQuery select columns "+sqlQuery);
  6357.             psNoOfHolidaysD.setShort(1, GOSIBatchConstants.HOLIDAY_WEEKEND);
  6358.             rsD=psNoOfHolidaysD.executeQuery();
  6359.             //GOSIDebug.debugMessages("After executing HolidaysD query ");
  6360.             if(rsD.next())
  6361.             {
  6362.                 HolidaysD = rsD.getInt("TOTAL");
  6363.                 //GOSIDebug.debugMessages("HolidaysD = " + HolidaysD);
  6364.             }
  6365.  
  6366.             // -------------------------------------------------------------
  6367.  
  6368.             totalHolidays=HolidaysA + HolidaysB + HolidaysC + HolidaysD;
  6369.             //GOSIDebug.debugMessages("totalHolidays = " + totalHolidays);
  6370.  
  6371.            
  6372.         }catch(Exception e)
  6373.         {
  6374.              new GOSIBatchException(e,
  6375.                     "BatchCore",
  6376.                     "GOSIUtilities",
  6377.                     "getTotalNoOfHolidays",
  6378.                     "CMN_001_ERR_1000",
  6379.                     GOSIBatchConstants.SEVERITY_ONE);
  6380.         }
  6381.         finally
  6382.         {
  6383.             GOSIBatchUtilities.cleanUp(rsA);
  6384.             GOSIBatchUtilities.cleanUp(rsB);
  6385.             GOSIBatchUtilities.cleanUp(rsC);
  6386.             GOSIBatchUtilities.cleanUp(rsD);           
  6387.         }
  6388.         return totalHolidays;      
  6389.     }
  6390.    
  6391.     /**
  6392.  * @METHOD NAME              : getNoOfWeekEnds
  6393.  * @INFORMATION              : Returns no. of weekend days between two dates
  6394.                                not counting those inside other holidays
  6395.  * @PARAM                    : startDate, endDate
  6396.  * @RETURN                   : int
  6397.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  6398.  * @LAST MODIFIED BY         :
  6399.  * @LAST MODIFIED DATE       :
  6400. **/
  6401.     public static int getNoOfWeekEnds(Timestamp tStartDate, Timestamp
  6402.     tEndDate) throws GOSIBatchException
  6403.     {
  6404.         Connection connection=null;    
  6405.         PreparedStatement psNoOfWeekEndsA =null;
  6406.         PreparedStatement psNoOfWeekEndsB =null;
  6407.         int weekendsA =0;
  6408.         int weekendsB =0;
  6409.         ResultSet rsA =null;
  6410.         ResultSet rsB =null;
  6411.         String startDate="";
  6412.         String endDate="";             
  6413.         int totalWeekEnds =0;      
  6414.         ResultSet rs =null;
  6415.        
  6416.         try
  6417.         {
  6418.             //StringBuffer sb = new StringBuffer(" SELECT ");
  6419.  
  6420.             psWeekEnds.setShort(1,GOSIBatchConstants.HOLIDAY_WEEKEND);
  6421.             psWeekEnds.setByte(2,GOSIBatchConstants.HOLIDAY_VALID);
  6422.  
  6423.             psWeekEnds.setTimestamp(3, tStartDate);
  6424.             psWeekEnds.setTimestamp(4, tEndDate);
  6425.  
  6426.             rs = psWeekEnds.executeQuery();
  6427.  
  6428.             if(rs.next())
  6429.             {
  6430.                 totalWeekEnds = rs.getInt("TOTAL");
  6431.             }
  6432.  
  6433.             // converting given Timestamp into String
  6434.             startDate = GOSIBatchDateUtilities.getDateFullString(tStartDate);
  6435.             //GOSIDebug.debugMessages("startDate = " + startDate);
  6436.             endDate = GOSIBatchDateUtilities.getDateFullString(tEndDate);
  6437.             //GOSIDebug.debugMessages("endDate = " + endDate);
  6438.            
  6439.             connection=GOSIBatchUtilities.getDbConnection(GOSIBatchConstants.COMMON);          
  6440.             // case A: Period given ends on a Thursday
  6441.             String sqlQueryA="SELECT count (*) TOTAL "+
  6442.                                 " FROM T_HOLIDAYS "+
  6443.                                 " WHERE TRUNC(HOLIDAYSTARTDATE) =TO_DATE('"+endDate+"','dd/mm/yyyy') "+                            
  6444.                                 " AND HOLIDAYTYPE=? AND STATUS =1";
  6445.             psNoOfWeekEndsA=connection.prepareStatement(sqlQueryA);
  6446.             //System.out.println("sqlQuery select columns "+sqlQuery);
  6447.             psNoOfWeekEndsA.setShort(1, GOSIBatchConstants.HOLIDAY_WEEKEND);
  6448.             rsA=psNoOfWeekEndsA.executeQuery();
  6449.             //GOSIDebug.debugMessages("After executing HolidaysA query ");
  6450.             if(rsA.next())
  6451.             {
  6452.                 weekendsA = rsA.getInt("TOTAL");
  6453.                 //GOSIDebug.debugMessages("HolidaysA = " + HolidaysA);
  6454.             }
  6455.             totalWeekEnds += weekendsA;
  6456.                        
  6457.             // case B: Period given starts on a Friday
  6458.             String sqlQueryB="SELECT count (*) TOTAL "+
  6459.                                 " FROM T_HOLIDAYS "+
  6460.                                 " WHERE TRUNC(HOLIDAYENDDATE) = TO_DATE('"+startDate+"','dd/mm/yyyy')  "+
  6461.                                 " AND HOLIDAYTYPE=? AND STATUS =1";
  6462.             psNoOfWeekEndsB=connection.prepareStatement(sqlQueryB);
  6463.             //System.out.println("sqlQuery select columns "+sqlQuery);
  6464.             psNoOfWeekEndsB.setShort(1, GOSIBatchConstants.HOLIDAY_WEEKEND);
  6465.             rsB=psNoOfWeekEndsB.executeQuery();
  6466.             //GOSIDebug.debugMessages("After executing HolidaysB query ");
  6467.             if(rsB.next())
  6468.             {
  6469.                 weekendsB = rsB.getInt("TOTAL");
  6470.                 //GOSIDebug.debugMessages("HolidaysB = " + HolidaysB);
  6471.             }
  6472.             totalWeekEnds += weekendsB;                    
  6473.        
  6474.         }catch(Exception e)
  6475.         {
  6476.              new GOSIBatchException(e,
  6477.                     "BatchCore",
  6478.                     "GOSIUtilities",
  6479.                     "getNoOfWeekEnds",
  6480.                     "CMN_001_ERR_1000",
  6481.                     GOSIBatchConstants.SEVERITY_ONE);
  6482.         }
  6483.         finally
  6484.         {
  6485.             GOSIBatchUtilities.cleanUp(rs);
  6486.         }
  6487.         return totalWeekEnds;      
  6488.     }
  6489.  
  6490.  
  6491.   /**
  6492.  * @METHOD NAME              : getNextWorkingDay
  6493.  * @INFORMATION              : Returns next working day
  6494.  * @PARAM                    : inputDate
  6495.  * @RETURN                   : class java.sql.Timestamp
  6496.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  6497.  * @LAST MODIFIED BY         :
  6498.  * @LAST MODIFIED DATE       :
  6499. **/
  6500.   public static Timestamp getNextWorkingDay(Timestamp inputDate
  6501.     )throws GOSIBatchException{
  6502.        
  6503.         Timestamp nextWorkingDay = null;       
  6504.         boolean nextWorkingDayFound = false;
  6505.        
  6506.        
  6507.         PreparedStatement ps = null;
  6508.         ResultSet rs = null;
  6509.        
  6510.         try
  6511.         {
  6512.             while(!nextWorkingDayFound)
  6513.             {
  6514.                 if(!isHoliday(inputDate))
  6515.                 {
  6516.                     nextWorkingDay = inputDate;
  6517.                     nextWorkingDayFound = true;
  6518.                 }
  6519.                 else
  6520.                 {
  6521.                     psNextWorkingDay.setTimestamp(1,inputDate);
  6522.                     psNextWorkingDay.setTimestamp(2,inputDate);
  6523.                     psNextWorkingDay.setByte(3,GOSIBatchConstants.HOLIDAY_VALID);
  6524.  
  6525.                     rs = psNextWorkingDay.executeQuery();
  6526.  
  6527.                     if(rs.next())
  6528.                     {
  6529.                         inputDate = rs.getTimestamp("NEXTDATE");
  6530.                     }
  6531.                 }
  6532.             }
  6533.         }catch(Exception e)
  6534.         {
  6535.              new GOSIBatchException(e,
  6536.                     "BatchCore",
  6537.                     "GOSIUtilities",
  6538.                     "getNextWorkingDay",
  6539.                     "CMN_001_ERR_1000",
  6540.                     GOSIBatchConstants.SEVERITY_ONE);
  6541.         }
  6542.         //System.out.println("Next Working Day : "+nextWorkingDay);
  6543.         return nextWorkingDay;
  6544.     }
  6545.    
  6546.    
  6547.  
  6548.    // From here methods are releated to auditing the record for deletion these are all
  6549.    // Similar to the online components
  6550.  
  6551.  
  6552.      /**
  6553.  * @METHOD NAME              : insertRecord
  6554.  * @INFORMATION              : This methods inserts the records in the Audit tables
  6555.  * @PARAM                    :
  6556.  * @RETURN                   :
  6557.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  6558.  * @LAST MODIFIED BY         :
  6559.  * @LAST MODIFIED DATE       :
  6560. **/
  6561.  
  6562.     private static void insertRecord(String insertQuery, ArrayList columnsList,
  6563.                         HashMap data, HashMap dataType, Long
  6564.                             userId,Connection connection)
  6565.                         throws GOSIBatchException
  6566.     {
  6567.         PreparedStatement psInsert1=null;
  6568.         PreparedStatement psInsert2=null;
  6569.         String lastAction=null;
  6570.         String lastActionBy=null;
  6571.         String lastActionTimestamp=null;
  6572.         try
  6573.         {
  6574.             psInsert1=connection.prepareStatement(insertQuery);
  6575.             psInsert2=connection.prepareStatement(insertQuery);
  6576.             int position=1;
  6577.             int columnsSize=columnsList.size();
  6578.             for(int i=0;i<columnsSize;i++)
  6579.             {
  6580.                 if("DATE".equals((String)dataType.get(columnsList.get(i))))
  6581.                 {
  6582.                     //System.out.println("cloumnname : " +columnsList.get(
  6583.                       //  i)+ " data type ="+dataType.get(columnsList.get(i)));
  6584.  
  6585.                     if(data.get(columnsList.get(i))==null)
  6586.                     {
  6587.                         psInsert2.setString(position, null);
  6588.                         psInsert1.setString(position, null);
  6589.                         //System.out.println("assigning the values " +
  6590.                           //  "position : "+position+" and cloumnname : " +
  6591.                             //columnsList.get(i)+" = "+data.get(columnsList.
  6592.                            // get(i)));
  6593.                     }
  6594.                     else
  6595.                     {
  6596.                         psInsert1.setTimestamp(position,
  6597.                         Timestamp.valueOf((String)data.
  6598.                         get(columnsList.get(i))));
  6599.                         psInsert2.setTimestamp(position,
  6600.                         Timestamp.valueOf((String)data.
  6601.                         get(columnsList.get(i))));
  6602.                         //System.out.println("assigning the values " +
  6603.                           //  "position : "+position+" and cloumnname : " +
  6604.                             //columnsList.get(i)+" = "+data.get(columnsList.
  6605.                             //get(i)));
  6606.  
  6607.                     }
  6608.                 }
  6609.                 else
  6610.                 {
  6611.                     if(data.get(columnsList.get(i))==null)
  6612.                     {
  6613.                         psInsert1.setString(position, null);
  6614.                         psInsert2.setString(position, null);
  6615.                         //System.out.println("assigning the values " +
  6616.                          //   "position : "+position+" and cloumnname : " +
  6617.                           //  columnsList.get(i)+" = "+data.get(columnsList.
  6618.                             //get(i)));
  6619.                     }
  6620.                     else
  6621.                     {
  6622.                         psInsert2.setString(position,
  6623.                         (String)data.get(columnsList.get(i)));
  6624.                         psInsert1.setString(position,
  6625.                         (String)data.get(columnsList.get(i)));
  6626.                         //System.out.println("assigning the values " +
  6627.                             //"position : "+position+" and cloumnname : " +
  6628.                             //columnsList.get(i)+" = "+data.get(columnsList.
  6629.                             //get(i)));
  6630.  
  6631.                     }
  6632.                 }
  6633.                 position++;
  6634.             }
  6635.             //System.out.println("assigning the values position : "
  6636.             //+position+" and cloumnname : ACTIONBY value= "+
  6637.             //userId.longValue());
  6638.             psInsert1.setLong(position, userId.longValue());
  6639.             psInsert2.setString(position,
  6640.                         (String)data.get("LASTMODIFIEDBY"));
  6641.             position++;
  6642.             //System.out.println("assigning the values position : "+
  6643.             //position+" and cloumnname : ACTIONTIMESTAMP value= "+
  6644.             //System.currentTimeMillis());
  6645.             psInsert1.setTimestamp(position, new
  6646.             Timestamp(System.currentTimeMillis()));
  6647.             psInsert2.setTimestamp(position,
  6648.                         Timestamp.valueOf((String)data.
  6649.                         get("LASTMODIFIEDTIMESTAMP")));
  6650.             position++;
  6651.             //System.out.println("assigning the values position : "+
  6652.            // position+" and cloumnname : ACTIONTIMESTAMP value=D ");
  6653.             psInsert1.setString(position, "D");
  6654.             psInsert2.setString(position,
  6655.                         (String)data.get("LASTACTION"));
  6656.  
  6657.  
  6658.             psInsert1.executeUpdate();
  6659.             psInsert2.executeUpdate();
  6660.         }
  6661.         catch(Exception e)
  6662.         {
  6663.             new GOSIBatchException(e,
  6664.             "BatchCore",
  6665.             "GOSIBatchUtilities",
  6666.             "insertRecord",
  6667.             "CMN_001_ERR_1000",
  6668.             GOSIBatchConstants.SEVERITY_ONE);
  6669.         }
  6670.         finally
  6671.         {
  6672.             GOSIBatchUtilities.cleanUp(psInsert2);
  6673.             GOSIBatchUtilities.cleanUp(psInsert1);
  6674.         }
  6675.         return;
  6676.     }
  6677.  
  6678.       /**
  6679.      * @method name         :getColumnNames
  6680.      * @param               :String tableNames,COnnection connection
  6681.      * @returns             :ArrayList
  6682.      * @throws              :GOSIBatchException
  6683.      */
  6684.     /**
  6685.     * This method reads the columns name of the table passed
  6686.     * and returns the column list
  6687.     */
  6688.  
  6689.     private static ArrayList getColumnNames(String tableName,Connection connection)
  6690.     throws GOSIBatchException
  6691.     {
  6692.         ArrayList arrayList=new ArrayList();
  6693.         ArrayList columnList=new ArrayList();
  6694.         HashMap dataType=new HashMap();
  6695.         PreparedStatement psReadColumns=null;
  6696.         ResultSet rs=null;
  6697.         try
  6698.         {
  6699.             //System.out.println("tableName "+tableName);
  6700.             String sqlQuery="select distinct column_name,DATA_TYPE from "+
  6701.                                     " DBA_TAB_COLUMNS where table_name=? "+
  6702.                                     " AND column_name not"+
  6703.                                     " in('ACTIONBY','ACTIONTIMESTAMP', "+
  6704.                                     " 'ACTIONTYPE','PART_ID')";
  6705.             psReadColumns=connection.prepareStatement(sqlQuery);
  6706.             //System.out.println("sqlQuery select columns "+sqlQuery);
  6707.             psReadColumns.setString(1, tableName);
  6708.             rs=psReadColumns.executeQuery();
  6709.             while(rs.next())
  6710.             {
  6711.                 //System.out.println("rs.getString(column_name): "+rs.
  6712.                   //  getString("column_name"));
  6713.                 //System.out.println("rs.getString(DATA_TYPE): "+rs.
  6714.                   //  getString("DATA_TYPE"));
  6715.                 columnList.add(rs.getString("column_name"));
  6716.                 dataType.put(rs.getString("column_name"),
  6717.                                 rs.getString("DATA_TYPE"));
  6718.  
  6719.             }
  6720.             arrayList.add(columnList);
  6721.             arrayList.add(dataType);
  6722.             if(columnList.size()==0)
  6723.             {
  6724.                 new GOSIBatchException(null,
  6725.                 "BatchCore",
  6726.                 "GOSIBatchUtilities",
  6727.                 "getColumnNames",
  6728.                 "CMN_001_ERR_1000",
  6729.                 GOSIBatchConstants.SEVERITY_ONE);
  6730.             }
  6731.         }
  6732.         catch(GOSIBatchException ge)
  6733.         {
  6734.             throw ge;
  6735.         }
  6736.         catch(Exception e)
  6737.         {
  6738.             new GOSIBatchException(e,
  6739.                 "BatchCore",
  6740.                 "GOSIBatchUtilities",
  6741.                 "getColumnNames",
  6742.                 "CMN_001_ERR_1000",
  6743.                 GOSIBatchConstants.SEVERITY_ONE);
  6744.         }
  6745.         finally
  6746.         {
  6747.             GOSIBatchUtilities.cleanUp(rs);
  6748.             GOSIBatchUtilities.cleanUp(psReadColumns);
  6749.         }
  6750.         return arrayList;
  6751.     }
  6752.  
  6753.     /**
  6754.      * @method name         :getReadQuery
  6755.      * @param               :String tableNames, ArrayList columnsList
  6756.                             HashMap primaryKeys,Connection connection
  6757.      * @returns             :String
  6758.      * @throws              :GOSIBatchException
  6759.      */
  6760.     /**
  6761.     * This methods takes the table name, columnList and primarykeys values
  6762.     * HashMap and creats the query for the reading the record
  6763.     */
  6764.     private static String getReadQuery(String tableName, ArrayList columnsList,
  6765.                                 HashMap primaryKeyValues,Connection connection,
  6766.                                 HashMap dataType)
  6767.                                 throws GOSIBatchException
  6768.     {
  6769.         StringBuffer sb=new StringBuffer("select ");
  6770.         try
  6771.         {
  6772.             int columnsSize=columnsList.size();
  6773.  
  6774.             for(int i=0;i<columnsSize;i++)
  6775.             {
  6776.                 if(i==0)
  6777.                 {
  6778.                     sb.append(columnsList.get(i));
  6779.                 }
  6780.                 else
  6781.                 {
  6782.                     sb.append(",");
  6783.                     sb.append(columnsList.get(i));
  6784.                 }
  6785.             }
  6786.             sb.append(" ,DECODE(LASTMODIFIEDBY,NULL, "+
  6787.                 "CREATEDBY,LASTMODIFIEDBY) LASTMODIFIEDBY,  DECODE"+
  6788.                 "(LASTMODIFIEDTIMESTAMP ,NULL, CREATIONTIMESTAMP,"+
  6789.                 "LASTMODIFIEDTIMESTAMP )  LASTMODIFIEDTIMESTAMP, "+
  6790.                 "DECODE(LASTMODIFIEDTIMESTAMP  ,NULL,'A','C') LASTACTION");
  6791.             sb.append(" ");
  6792.             sb.append(" from ");
  6793.             sb.append(tableName);
  6794.             sb.append(" ");
  6795.             sb.append(" where ");
  6796.             sb.append(" ");
  6797.             java.util.Set set=primaryKeyValues.keySet();
  6798.             java.util.Iterator iterator= set.iterator();
  6799.             int flag=0;
  6800.              while(iterator.hasNext())
  6801.             {
  6802.                 boolean dateFlag=false;
  6803.  
  6804.                 String keyName=(String)iterator.next();
  6805.                 if((dataType.get(keyName)!=null)&&("DATE".equalsIgnoreCase((String)dataType.get(keyName))))
  6806.                 {
  6807.                     dateFlag=true;
  6808.                 }
  6809.                 if(flag==0)
  6810.                 {
  6811.                     if((primaryKeyValues.get(keyName))==null)
  6812.                     {
  6813.                         sb.append(keyName);
  6814.                         sb.append(" is null ");
  6815.                     }
  6816.                     else
  6817.                     {
  6818.                         if(dateFlag==false)
  6819.                         {
  6820.                             sb.append(keyName);
  6821.                             sb.append("='");
  6822.                             sb.append(primaryKeyValues.get(keyName));
  6823.                             sb.append("'");
  6824.                         }
  6825.                         else
  6826.                         {
  6827.                             sb.append("to_char("+keyName+",'DD/MM/YYYY')");
  6828.                             sb.append("='");
  6829.                             sb.append(primaryKeyValues.get(keyName));
  6830.                             sb.append("'");
  6831.                         }
  6832.                     }
  6833.                    
  6834.                     //System.out.println("Key : "+keyName);
  6835.                     //System.out.println("Key Value : "+primaryKeyValues.
  6836.                       //  get(keyName));
  6837.                 }
  6838.                 else
  6839.                 {
  6840.                     sb.append(" and ");
  6841.                     if((primaryKeyValues.get(keyName))==null)
  6842.                     {
  6843.                         sb.append(keyName);
  6844.                         sb.append(" is null ");
  6845.                     }
  6846.                     else
  6847.                     {
  6848.                        
  6849.                         if(dateFlag==false)
  6850.                         {
  6851.                             sb.append(keyName);
  6852.                             sb.append("='");
  6853.                             sb.append(primaryKeyValues.get(keyName));
  6854.                             sb.append("'");
  6855.                         }
  6856.                         else
  6857.                         {  
  6858.                             sb.append("to_char("+keyName+",'DD/MM/YYYY')");
  6859.                             sb.append("='");
  6860.                             sb.append(primaryKeyValues.get(keyName));
  6861.                             sb.append("'");
  6862.                         }
  6863.                     }
  6864.                    
  6865.                     //System.out.println("Key : "+keyName);
  6866.                     //System.out.println("Key Value : "+primaryKeyValues.
  6867.                       //  get(keyName));
  6868.  
  6869.                 }
  6870.                 flag=1;
  6871.             }
  6872.             //System.out.println("READ QUERY"+sb.toString());
  6873.  
  6874.         }
  6875.         catch(Exception e)
  6876.         {
  6877.             new GOSIBatchException(e,
  6878.                 "BatchCore",
  6879.                 "GOSIBatchUtilities",
  6880.                 "getReadQuery",
  6881.                 "CMN_001_ERR_1000",
  6882.                 GOSIBatchConstants.SEVERITY_ONE);
  6883.         }
  6884.         return sb.toString();
  6885.     }
  6886.  
  6887.     /**
  6888.      * @method name         :readRecord
  6889.      * @param               :String tableNames, ArrayList columnsList,Connection connection
  6890.      * @returns             :HashMap
  6891.      * @throws              :GOSIBatchException
  6892.      */
  6893.     /**
  6894.     * This methods takes query string and columnList and read the data
  6895.     * Retrived by the query and populates that in HashMap as
  6896.     * key value pair and returns them
  6897.     */
  6898.  
  6899.     private static HashMap readRecord(String query, ArrayList columnsList,Connection connection)
  6900.     throws GOSIBatchException
  6901.     {
  6902.         HashMap data=new HashMap();
  6903.         PreparedStatement psRead=null;
  6904.         ResultSet rs=null;
  6905.         try
  6906.         {
  6907.             int arraySize=columnsList.size();
  6908.             psRead=connection.prepareStatement(query);
  6909.             rs=psRead.executeQuery();
  6910.             if(rs.next())
  6911.             {
  6912.                 for(int i=0;i<arraySize;i++)
  6913.                 {
  6914.                     data.put(columnsList.get(i),
  6915.                     rs.getString((String)columnsList.get(i)));
  6916.                     //System.out.println(columnsList.get(i)+" = "+rs.
  6917.                       //  getString((String)columnsList.get(i)));
  6918.                 }
  6919.                 //System.out.println("rs.getString(LASTMODIFIEDBY)" +
  6920.                 //  rs.getString("LASTMODIFIEDBY"));
  6921.                 //System.out.println("rs.getString(LASTMODIFIEDTIMESTAMP)"
  6922.                 //  + rs.getString("LASTMODIFIEDTIMESTAMP"));
  6923.                 data.put("LASTMODIFIEDBY", rs.getString("LASTMODIFIEDBY"));
  6924.                 data.put("LASTMODIFIEDTIMESTAMP",
  6925.                     rs.getString("LASTMODIFIEDTIMESTAMP"));
  6926.                 //System.out.println("rs.getString(LASTACTION)" +
  6927.                 //  rs.getString("LASTACTION"));
  6928.                 data.put("LASTACTION",
  6929.                     rs.getString("LASTACTION"));
  6930.             }
  6931.             else
  6932.             {
  6933.                 new GOSIBatchException(null,
  6934.                 "BatchCore",
  6935.                 "GOSIBatchUtilities",
  6936.                 "readRecord",
  6937.                 "CMN_001_ERR_1000",
  6938.                 GOSIBatchConstants.SEVERITY_ONE);
  6939.             }
  6940.         }
  6941.         catch(GOSIBatchException ge)
  6942.         {
  6943.             throw ge;
  6944.         }
  6945.         catch(Exception e)
  6946.         {
  6947.             e.printStackTrace();
  6948.             new GOSIBatchException(e,
  6949.                 "BatchCore",
  6950.                 "GOSIBatchUtilities",
  6951.                 "readRecord",
  6952.                 "CMN_001_ERR_1000",
  6953.                 GOSIBatchConstants.SEVERITY_ONE);
  6954.         }
  6955.         finally
  6956.         {
  6957.             GOSIBatchUtilities.cleanUp(rs);
  6958.             GOSIBatchUtilities.cleanUp(psRead);
  6959.         }
  6960.         return data;
  6961.     }
  6962.  
  6963.     /**
  6964.      * @method name         :getInsertQuery
  6965.      * @param               :String tableNames, ArrayList columnsList,
  6966.                                 HashMap data,Connection connection
  6967.      * @returns             :String
  6968.      * @throws              :GOSIBatchException
  6969.      */
  6970.     /**
  6971.     * This methods takes tableName, columnList and data HaspMap
  6972.     * creats the insert query and returns the query
  6973.     */
  6974.  
  6975.     private static String getInsertQuery(String tableName, ArrayList
  6976.                                     columnsList, HashMap data,Connection connection)
  6977.                                     throws GOSIBatchException
  6978.     {
  6979.         StringBuffer sb=new StringBuffer("insert into ");
  6980.         try
  6981.         {
  6982.             String auditTableName="A"+tableName.substring(1);
  6983.             //String auditTableName="T_USER2";
  6984.             sb.append(auditTableName);
  6985.             sb.append(" ( ");
  6986.             int columnsSize=columnsList.size();
  6987.  
  6988.             for(int i=0;i<columnsSize;i++)
  6989.             {
  6990.                 if(i==0)
  6991.                 {
  6992.                     sb.append(columnsList.get(i));
  6993.                 }
  6994.                 else
  6995.                 {
  6996.                     sb.append(",");
  6997.                     sb.append(columnsList.get(i));
  6998.                 }
  6999.             }
  7000.             sb.append(",ACTIONBY");
  7001.             sb.append(",ACTIONTIMESTAMP");
  7002.             sb.append(",ACTIONTYPE ) values ( ");
  7003.             for(int i=0;i<columnsSize;i++)
  7004.             {
  7005.                 if(i==0)
  7006.                 {
  7007.                     sb.append("?");
  7008.                 }
  7009.                 else
  7010.                 {
  7011.                     sb.append(",?");
  7012.                 }
  7013.             }
  7014.             sb.append(" ,? ");
  7015.             sb.append(" ,? ");
  7016.             sb.append(" ,?) ");
  7017.             //System.out.println("insert query : "+sb.toString());
  7018.  
  7019.         }
  7020.         catch(Exception e)
  7021.         {
  7022.             new GOSIBatchException(e,
  7023.                 "BatchCore",
  7024.                 "GOSIBatchUtilities",
  7025.                 "getInsertQuery",
  7026.                 "CMN_001_ERR_1000",
  7027.                 GOSIBatchConstants.SEVERITY_ONE);
  7028.         }
  7029.         return sb.toString();
  7030.     }
  7031.  
  7032.     /**
  7033.      * @method name         :logDeleteAudit
  7034.      * @param               :String tableNames,
  7035.                                 HashMap primarykeys, long userId,Connection connection
  7036.      * @returns             :
  7037.      * @throws              :GOSIBatchException
  7038.      */
  7039.     /**
  7040.     * This method is the controller method for all the delete audit log
  7041.     */
  7042.  
  7043.     public static void logDeleteAudit(String tableName,
  7044.                                 HashMap primaryKeys, Long userId,Connection connection)
  7045.     throws GOSIBatchException
  7046.     {
  7047.         try
  7048.         {
  7049.             //System.out.println("tableName : "+tableName);
  7050.             //System.out.println("userId : "+userId);
  7051.             ArrayList arrayList=getColumnNames("A"+tableName.substring(1),connection);
  7052.             ArrayList columnsList=(ArrayList)arrayList.get(0);
  7053.             HashMap dataType=(HashMap)arrayList.get(1);
  7054.             String readQuery=getReadQuery(tableName, columnsList, primaryKeys,connection,dataType);
  7055.             HashMap data=readRecord(readQuery, columnsList,connection);
  7056.             String insertQuery=getInsertQuery(tableName, columnsList, data,connection);
  7057.             insertRecord(insertQuery, columnsList,
  7058.                                         data, dataType, userId,connection);
  7059.  
  7060.         }
  7061.         catch(GOSIBatchException ge)
  7062.         {
  7063.             throw ge;
  7064.         }
  7065.         catch(Exception e)
  7066.         {
  7067.                 new GOSIBatchException(e,
  7068.                 "BatchCore",
  7069.                 "GOSIBatchUtilities",
  7070.                 "logDeleteAudit",
  7071.                 "CMN_001_ERR_1000",
  7072.                 GOSIBatchConstants.SEVERITY_ONE);
  7073.         }      
  7074.         return;
  7075.     }
  7076. // Here ends the delete audit code
  7077.  
  7078. /**
  7079.  * @METHOD NAME              : updateRequest
  7080.  * @INFORMATION              : This method updates the Batch request for the passed request id as processed
  7081.  * @PARAM                    : requestId,con
  7082.  * @RETURN                   : NIL
  7083.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7084.  * @LAST MODIFIED BY         :
  7085.  * @LAST MODIFIED DATE       :
  7086. **/
  7087.     public static void updateRequest(long requestId,Connection con)
  7088.     throws GOSIBatchException
  7089.     {
  7090.         PreparedStatement psRequest=null;
  7091.         try
  7092.         {
  7093.             //System.out.println("requestId : "+requestId);
  7094.             //System.out.println("con : "+con);
  7095.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1057");
  7096.             psRequest=con.prepareStatement(query);
  7097.             psRequest.setLong(1,requestId);
  7098.             psRequest.executeUpdate();
  7099.         }
  7100.         catch(GOSIBatchException ge)
  7101.         {
  7102.             throw ge;
  7103.         }
  7104.         catch(Exception e)
  7105.         {
  7106.                 new GOSIBatchException(e,
  7107.                 "BatchCore",
  7108.                 "GOSIBatchUtilities",
  7109.                 "deleteRequest",
  7110.                 "CMN_001_ERR_1000",
  7111.                 GOSIBatchConstants.SEVERITY_ONE);
  7112.         }
  7113.         finally
  7114.         {
  7115.             GOSIBatchUtilities.cleanUp(psRequest);
  7116.         }
  7117.         return;
  7118.     }
  7119.  
  7120.     /**
  7121.  * @METHOD NAME              : getRequestedBy
  7122.  * @INFORMATION              : This method gets the request by user id for the given request id
  7123.  * @PARAM                    : requestId,con
  7124.  * @RETURN                   : NIL
  7125.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7126.  * @LAST MODIFIED BY         :
  7127.  * @LAST MODIFIED DATE       :
  7128. **/
  7129.  
  7130.     public static long getRequestedBy(long requestId,Connection con)
  7131.     throws GOSIBatchException
  7132.     {
  7133.         PreparedStatement psRequest=null;
  7134.         long  requestedBy=0;
  7135.         ResultSet rs = null;
  7136.         try
  7137.         {
  7138.             //System.out.println("requestId : "+requestId);
  7139.             //System.out.println("con : "+con);
  7140.             String query=GOSIBatchSQL.getSqlString("CMN_003_SQL_1038");
  7141.             psRequest=con.prepareStatement(query);
  7142.             psRequest.setLong(1,requestId);
  7143.             rs = psRequest.executeQuery();
  7144.             if(rs.next())
  7145.             {
  7146.                 requestedBy = rs.getLong("REQUESTEDBY");
  7147.             }
  7148.         }
  7149.         catch(GOSIBatchException ge)
  7150.         {
  7151.             throw ge;
  7152.         }
  7153.         catch(Exception e)
  7154.         {
  7155.                 new GOSIBatchException(e,
  7156.                 "BatchCore",
  7157.                 "GOSIBatchUtilities",
  7158.                 "getRequestedBy",
  7159.                 "CMN_001_ERR_1000",
  7160.                 GOSIBatchConstants.SEVERITY_ONE);
  7161.         }
  7162.         finally
  7163.         {
  7164.             GOSIBatchUtilities.cleanUp(rs);
  7165.             GOSIBatchUtilities.cleanUp(rs);
  7166.         }
  7167.         return requestedBy;
  7168.     }
  7169.  
  7170.     /**
  7171.  * @METHOD NAME              : getUserIdListForStep
  7172.  * @INFORMATION              : This method gets the list of user names who can perform the step short name passed.
  7173.                                 Takes the task for the step and gets the role for the task id and gets the user list for the role.
  7174.  * @PARAM                    : stepShortName,con
  7175.  * @RETURN                   : NIL
  7176.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7177.  * @LAST MODIFIED BY         :
  7178.  * @LAST MODIFIED DATE       :
  7179. **/
  7180.  
  7181.     public static ArrayList getUserIdListForStep(String stepShortName,Connection con)
  7182.     throws GOSIBatchException
  7183.     {
  7184.         PreparedStatement psRole=null;
  7185.         PreparedStatement psUser=null;
  7186.         long  roleId=0;
  7187.         long endDate=0;
  7188.         long currentDate=0;
  7189.         long employeeNumber=0;
  7190.         ResultSet rsRole = null;
  7191.         ResultSet rsUserList = null;
  7192.         ArrayList employeeNumbers=new ArrayList();
  7193.         try
  7194.         {
  7195.             currentDate=Long.parseLong(getLdapDateFromTimestamp(getSystemDate()));
  7196.  
  7197.             //System.out.println("currentDate : "+currentDate);
  7198.             //System.out.println("stepShortName : "+stepShortName);
  7199.             //System.out.println("con : "+con);
  7200.             String roleQuery=GOSIBatchSQL.getSqlString("CMN_001_SQL_1058");
  7201.             psRole=con.prepareStatement(roleQuery);
  7202.             psRole.setString(1,stepShortName);
  7203.             psRole.setLong(2,currentDate);
  7204.             rsRole = psRole.executeQuery();
  7205.             if(rsRole.next())
  7206.             {
  7207.                 roleId = rsRole.getLong("ROLEID");
  7208.                 //System.out.println("roleId "+roleId);
  7209.                 //System.out.println("ENDDATE"+rsRole.getTimestamp("ENDDATE"));
  7210.                 if(rsRole.getTimestamp("ENDDATE")!=null)
  7211.                 {
  7212.                     endDate=Long.parseLong(getLdapDateFromTimestamp(rsRole.getTimestamp("ENDDATE")));
  7213.                     if(endDate<=currentDate)
  7214.                     {
  7215.                         roleId=0;
  7216.                     }
  7217.                 }
  7218.                
  7219.             }
  7220.             if(roleId==0)
  7221.             {
  7222.                 new GOSIBatchException(null,
  7223.                 "BatchCore",
  7224.                 "GOSIBatchUtilities",
  7225.                 "getUserIdListForStep",
  7226.                 "CMN_001_ERR_1071",
  7227.                 GOSIBatchConstants.SEVERITY_ONE);
  7228.             }
  7229.             String roleUser=GOSIBatchSQL.getSqlString("CMN_001_SQL_1059");
  7230.             //System.out.println("roleUser "+roleUser);
  7231.             psUser=con.prepareStatement(roleUser);
  7232.             psUser.setLong(1,roleId);
  7233.             //System.out.println("roleId"+roleId);
  7234.             psUser.setLong(2,currentDate);
  7235.             psUser.setLong(3,currentDate);
  7236.             psUser.setLong(4,roleId);
  7237.             psUser.setLong(5,currentDate);
  7238.             psUser.setLong(6,currentDate);
  7239.             psUser.setLong(7,currentDate);
  7240.             psUser.setLong(8,currentDate);
  7241.             rsUserList = psUser.executeQuery();
  7242.             endDate=0;
  7243.             while(rsUserList.next())
  7244.             {
  7245.                 employeeNumber = rsUserList.getLong("USERREFERENCEID");
  7246.                 //System.out.println("employeeNumber"+employeeNumber);
  7247.                 if(rsRole.getTimestamp("ENDDATE")!=null)
  7248.                 {
  7249.                     endDate=Long.parseLong(getLdapDateFromTimestamp(rsRole.getTimestamp("ENDDATE")));
  7250.                     if(endDate<=currentDate)
  7251.                     {
  7252.                         employeeNumber=0;
  7253.                     }
  7254.                 }
  7255.                 if(employeeNumber!=0)
  7256.                 {
  7257.                     //System.out.println("employeeNumber"+employeeNumber);
  7258.                     employeeNumbers.add(new Long(employeeNumber));
  7259.                 }
  7260.             }
  7261.         }
  7262.         catch(GOSIBatchException ge)
  7263.         {
  7264.             throw ge;
  7265.         }
  7266.         catch(Exception e)
  7267.         {
  7268.                 new GOSIBatchException(e,
  7269.                 "BatchCore",
  7270.                 "GOSIBatchUtilities",
  7271.                 "getUserIdListForStep",
  7272.                 "CMN_001_ERR_1000",
  7273.                 GOSIBatchConstants.SEVERITY_ONE);
  7274.         }
  7275.         finally
  7276.         {
  7277.             GOSIBatchUtilities.cleanUp(rsRole);
  7278.             GOSIBatchUtilities.cleanUp(rsUserList);
  7279.             GOSIBatchUtilities.cleanUp(psRole);
  7280.             GOSIBatchUtilities.cleanUp(psUser);
  7281.         }
  7282.         return employeeNumbers;
  7283.     }
  7284.  
  7285. public static final short pending=1001;
  7286. public static final short filed=1002;
  7287. public static final short processedSuccessfully=1003;
  7288. public static final short processedWithErrors=1004;
  7289.     /**
  7290.  * @METHOD NAME              : getFilesUploaded
  7291.  * @INFORMATION              : This method gets the list fo file name requred
  7292.                                 to be processed for the file type sent
  7293.  * @PARAM                    : fileType, conn
  7294.  * @RETURN                   : NIL
  7295.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7296.  * @LAST MODIFIED BY         :
  7297.  * @LAST MODIFIED DATE       :
  7298. **/
  7299.  
  7300.     public static ArrayList getFilesUploaded(short fileType,Connection conn)
  7301.         throws GOSIBatchException
  7302.     {
  7303.         PreparedStatement psFileName = null;
  7304.         ResultSet rs=null;
  7305.         ArrayList fileList=new ArrayList();
  7306.         try
  7307.         {
  7308.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1064");
  7309.             psFileName=conn.prepareStatement(query);
  7310.             psFileName.setShort(1,fileType);
  7311.             psFileName.setShort(2,GOSIBatchUtilities.pending);
  7312.             psFileName.setShort(3,fileType);
  7313.             psFileName.setShort(4,GOSIBatchUtilities.pending);
  7314.             rs=psFileName.executeQuery();
  7315.             int count=0;
  7316.             while(rs.next())
  7317.             {
  7318.                 String data[]=new String[3];
  7319.                 data[0]=rs.getString("FILEUPLOADINFOID");
  7320.                 data[1]=rs.getString("FILENAME");
  7321.                 data[2]=rs.getString("USERREFERENCEID");
  7322.                 fileList.add(count++,data);
  7323.             }
  7324.         }
  7325.         catch(Exception e)
  7326.         {
  7327.            
  7328.             new GOSIBatchException(e,
  7329.             "BatchCore",
  7330.             "GOSIBatchUtilities",
  7331.             "getFilesUploaded",
  7332.             "CMN_001_ERR_1000",
  7333.             GOSIBatchConstants.SEVERITY_ONE);        
  7334.         }
  7335.         return fileList;
  7336.     }
  7337.  
  7338.     /**
  7339.  * @METHOD NAME              : updateFileStatus
  7340.  * @INFORMATION              : This method updates the file status as status passed for the file id passed
  7341.  * @PARAM                    : fileId, status,conn
  7342.  * @RETURN                   : NIL
  7343.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7344.  * @LAST MODIFIED BY         :
  7345.  * @LAST MODIFIED DATE       :
  7346. **/
  7347.  
  7348.     public static void updateFileStatus(String fileId,short status,Connection conn)
  7349.         throws GOSIBatchException
  7350.     {
  7351.         PreparedStatement psUpdate= null;
  7352.         try
  7353.         {
  7354.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1065");
  7355.             psUpdate=conn.prepareStatement(query);
  7356.             psUpdate.setShort(1,status);
  7357.             psUpdate.setString(2,fileId);
  7358.             psUpdate.executeUpdate();
  7359.         }
  7360.         catch(Exception e)
  7361.         {
  7362.            
  7363.             new GOSIBatchException(e,
  7364.             "BatchCore",
  7365.             "GOSIBatchUtilities",
  7366.             "updateFileStatus",
  7367.             "CMN_001_ERR_1000",
  7368.             GOSIBatchConstants.SEVERITY_ONE);        
  7369.         }
  7370.         finally
  7371.         {
  7372.             GOSIBatchUtilities.cleanUp(psUpdate);
  7373.         }
  7374.     }
  7375.  
  7376.     /**
  7377.  * @METHOD NAME              : updateYear
  7378.  * @INFORMATION              : This method updates the file year as year passed for the file id passed
  7379.  * @PARAM                    : fileId, year,conn
  7380.  * @RETURN                   : NIL
  7381.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7382.  * @LAST MODIFIED BY         :
  7383.  * @LAST MODIFIED DATE       :
  7384. **/
  7385.  
  7386.     public static void updateYear(String fileId,int year,Connection conn)
  7387.         throws GOSIBatchException
  7388.     {
  7389.         PreparedStatement psUpdate= null;
  7390.         try
  7391.         {
  7392.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1071");
  7393.             psUpdate=conn.prepareStatement(query);
  7394.             psUpdate.setInt(1,year);
  7395.             psUpdate.setString(2,fileId);
  7396.             psUpdate.executeUpdate();
  7397.         }
  7398.         catch(Exception e)
  7399.         {
  7400.            
  7401.             new GOSIBatchException(e,
  7402.             "BatchCore",
  7403.             "GOSIBatchUtilities",
  7404.             "updateFileStatus",
  7405.             "CMN_001_ERR_1000",
  7406.             GOSIBatchConstants.SEVERITY_ONE);        
  7407.         }
  7408.         finally
  7409.         {
  7410.             GOSIBatchUtilities.cleanUp(psUpdate);
  7411.         }
  7412.     }
  7413.  
  7414.     /**
  7415.  * @METHOD NAME              : updateMappingKey
  7416.  * @INFORMATION              : This method updates the file Mapping Key as mappingkey passed for the file id passed
  7417.  * @PARAM                    : fileId, mappingkey,conn
  7418.  * @RETURN                   : NIL
  7419.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7420.  * @LAST MODIFIED BY         :
  7421.  * @LAST MODIFIED DATE       :
  7422. **/
  7423.  
  7424.     public static void updateMappingKey(String fileId,String mappingkey,Connection conn)
  7425.         throws GOSIBatchException
  7426.     {
  7427.         PreparedStatement psUpdate= null;
  7428.         try
  7429.         {
  7430.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1072");
  7431.             psUpdate=conn.prepareStatement(query);
  7432.             psUpdate.setString(1,mappingkey);
  7433.             psUpdate.setString(2,fileId);
  7434.             psUpdate.executeUpdate();
  7435.         }
  7436.         catch(Exception e)
  7437.         {
  7438.            
  7439.             new GOSIBatchException(e,
  7440.             "BatchCore",
  7441.             "GOSIBatchUtilities",
  7442.             "updateFileStatus",
  7443.             "CMN_001_ERR_1000",
  7444.             GOSIBatchConstants.SEVERITY_ONE);        
  7445.         }
  7446.         finally
  7447.         {
  7448.             GOSIBatchUtilities.cleanUp(psUpdate);
  7449.         }
  7450.     }
  7451.  
  7452.  
  7453.     /**
  7454.  * @METHOD NAME              : getVilalgesForFo
  7455.  * @INFORMATION              : This method gets the villages mapped to filed office from the start date
  7456.  * @PARAM                    : foCode, startDate,conn
  7457.  * @RETURN                   : NIL
  7458.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7459.  * @LAST MODIFIED BY         :
  7460.  * @LAST MODIFIED DATE       :
  7461. **/
  7462.  
  7463.     public static ArrayList getVilalgesForFo(String foCode,String startDate,Connection conn)
  7464.         throws GOSIBatchException
  7465.     {
  7466.         PreparedStatement ps= null;
  7467.         ResultSet rs= null;
  7468.         ArrayList villageFoMap=new ArrayList();
  7469.         try
  7470.         {
  7471.             String dateInNumber=getLdapDateFromTimestamp(GOSIBatchDateUtilities.getTimestamp(startDate));
  7472.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1066");
  7473.             System.out.println("query "+query);
  7474.             ps=conn.prepareStatement(query);
  7475.             ps.setString(1,foCode);
  7476.             System.out.println("foCode "+foCode);
  7477.             ps.setString(2,dateInNumber);
  7478.             System.out.println("startDate "+dateInNumber);
  7479.             ps.setString(3,dateInNumber);
  7480.             System.out.println("startDate "+dateInNumber);
  7481.             ps.setString(4,dateInNumber);
  7482.             System.out.println("startDate "+dateInNumber);
  7483.             rs=ps.executeQuery();
  7484.             while(rs.next())
  7485.             {
  7486.                 String[] villageData=new String[2];
  7487.                 villageData[0]=rs.getString("VILLAGERECORDID");
  7488.                 System.out.println("villageData[0]"+villageData[0]);
  7489.                 villageData[1]=rs.getString("VILLAGEID");
  7490.                 System.out.println("villageData[1]"+villageData[1]);
  7491.                 villageFoMap.add(villageData);
  7492.             }
  7493.             System.out.println("villageFoMap.size()"+villageFoMap.size());
  7494.             //conn.commit();
  7495.         }
  7496.         catch(Exception e)
  7497.         {
  7498.            
  7499.             new GOSIBatchException(e,
  7500.             "BatchCore",
  7501.             "GOSIBatchUtilities",
  7502.             "getVilalgesForFo",
  7503.             "CMN_001_ERR_1000",
  7504.             GOSIBatchConstants.SEVERITY_ONE);        
  7505.         }
  7506.         finally
  7507.         {
  7508.             GOSIBatchUtilities.cleanUp(rs);
  7509.             GOSIBatchUtilities.cleanUp(ps);
  7510.         }
  7511.         return villageFoMap;
  7512.     }
  7513.  
  7514.     /**
  7515.  * @METHOD NAME              : getFOforVillage
  7516.  * @INFORMATION              : This method gets the FO code for the given village id
  7517.  * @PARAM                    : villageId,conn
  7518.  * @RETURN                   : NIL
  7519.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7520.  * @LAST MODIFIED BY         :
  7521.  * @LAST MODIFIED DATE       :
  7522. **/
  7523.  
  7524.     public static String getFOforVillage(String villageId,String startDate,Connection conn)
  7525.         throws GOSIBatchException
  7526.     {
  7527.         PreparedStatement ps= null;
  7528.         ResultSet rs= null;
  7529.         String foCode=null;
  7530.         try
  7531.         {
  7532.             String dateInNumber=getLdapDateFromTimestamp(GOSIBatchDateUtilities.getTimestamp(startDate));
  7533.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1067");
  7534.             System.out.println("query "+query);
  7535.             ps=conn.prepareStatement(query);
  7536.             ps.setString(1,villageId);
  7537.             System.out.println("villageId "+villageId);
  7538.             ps.setString(2,dateInNumber);
  7539.             System.out.println("dateInNumber "+dateInNumber);
  7540.             ps.setString(3,dateInNumber);
  7541.             ps.setString(4,dateInNumber);
  7542.             rs=ps.executeQuery();
  7543.             while(rs.next())
  7544.             {
  7545.                 foCode=rs.getString("FOCODE");
  7546.                 System.out.println("foCode : "+foCode);
  7547.             }
  7548.         }
  7549.         catch(Exception e)
  7550.         {
  7551.            
  7552.             new GOSIBatchException(e,
  7553.             "BatchCore",
  7554.             "GOSIBatchUtilities",
  7555.             "getFOforVillage",
  7556.             "CMN_001_ERR_1000",
  7557.             GOSIBatchConstants.SEVERITY_ONE);        
  7558.         }
  7559.         finally
  7560.         {
  7561.             GOSIBatchUtilities.cleanUp(rs);
  7562.             GOSIBatchUtilities.cleanUp(ps);
  7563.         }
  7564.         return foCode;
  7565.     }
  7566.  
  7567. /**
  7568.  * @METHOD NAME              : setByte
  7569.  * @INFORMATION              : This method checks whether the parameter
  7570.                                'attribute' is not null. If null, sets the null
  7571.                                in Prepared Statement at the given column number,
  7572.                                else sets its primitive value after converting
  7573.                                 to primitive data type.
  7574.  * @PARAM                    : prepareStatement,colNum,attribute
  7575.  * @RETURN                   : void
  7576.  * @EXCEPTION                : class java.sql.SQLException
  7577.  * @LAST MODIFIED BY         :
  7578.  * @LAST MODIFIED DATE       :
  7579. **/
  7580.     public static void setByte(PreparedStatement prepareStatement, int colNum,
  7581.         Byte attribute) throws SQLException
  7582.     {
  7583.         if(attribute != null)
  7584.         {
  7585.             prepareStatement.setByte(colNum, attribute.byteValue());
  7586.         }
  7587.         else
  7588.         {
  7589.             prepareStatement.setNull(colNum, Types.TINYINT);
  7590.         }
  7591.     }
  7592.  
  7593. /**
  7594.  * @METHOD NAME              : setShort
  7595.  * @INFORMATION              : This method checks whether the parameter
  7596.                                'attribute' is not null. If null, sets the null
  7597.                                in Prepared Statement at the given column number,
  7598.                                else sets its primitive value after converting
  7599.                                 to primitive data type.
  7600.  * @PARAM                    : prepareStatement,colNum,attribute
  7601.  * @RETURN                   : void
  7602.  * @EXCEPTION                : class java.sql.SQLException
  7603.  * @LAST MODIFIED BY         :
  7604.  * @LAST MODIFIED DATE       :
  7605. **/
  7606.     public static void setShort(PreparedStatement prepareStatement, int colNum,
  7607.         Short attribute) throws SQLException
  7608.     {
  7609.         if(attribute != null)
  7610.         {
  7611.             prepareStatement.setShort(colNum, attribute.shortValue());
  7612.         }
  7613.         else
  7614.         {
  7615.             prepareStatement.setNull(colNum, Types.SMALLINT);
  7616.         }
  7617.     }
  7618.  
  7619. /**
  7620.  * @METHOD NAME              : setInt
  7621.  * @INFORMATION              : This method checks whether the parameter
  7622.                                'attribute' is not null. If null, sets the null
  7623.                                in Prepared Statement at the given column number,
  7624.                                else sets its primitive value after converting
  7625.                                 to primitive data type.
  7626.  * @PARAM                    : prepareStatement,colNum,attribute
  7627.  * @RETURN                   : void
  7628.  * @EXCEPTION                : class java.sql.SQLException
  7629.  * @LAST MODIFIED BY         :
  7630.  * @LAST MODIFIED DATE       :
  7631. **/
  7632.     public static void setInt(PreparedStatement prepareStatement, int colNum,
  7633.         Integer attribute) throws SQLException
  7634.     {
  7635.         if(attribute != null)
  7636.         {
  7637.             prepareStatement.setInt(colNum, attribute.intValue());
  7638.         }
  7639.         else
  7640.         {
  7641.             prepareStatement.setNull(colNum, Types.INTEGER);
  7642.         }
  7643.     }
  7644.  
  7645. /**
  7646.  * @METHOD NAME              : setLong
  7647.  * @INFORMATION              : This method checks whether the parameter
  7648.                                'attribute' is not null. If null, sets the null
  7649.                                in Prepared Statement at the given column number,
  7650.                                else sets its primitive value after converting
  7651.                                 to primitive data type.
  7652.  * @PARAM                    : prepareStatement,colNum,attribute
  7653.  * @RETURN                   : void
  7654.  * @EXCEPTION                : class java.sql.SQLException
  7655.  * @LAST MODIFIED BY         :
  7656.  * @LAST MODIFIED DATE       :
  7657. **/
  7658.     public static void setLong(PreparedStatement prepareStatement, int colNum,
  7659.         Long attribute) throws SQLException
  7660.     {
  7661.         if(attribute != null)
  7662.         {
  7663.             prepareStatement.setLong(colNum, attribute.longValue());
  7664.         }
  7665.         else
  7666.         {
  7667.             prepareStatement.setNull(colNum, Types.BIGINT);
  7668.         }
  7669.     }
  7670.  
  7671. /**
  7672.  * @METHOD NAME              : setFloat
  7673.  * @INFORMATION              : This method checks whether the parameter
  7674.                                'attribute' is not null. If null, sets the null
  7675.                                in Prepared Statement at the given column number,
  7676.                                else sets its primitive value after converting
  7677.                                 to primitive data type.
  7678.  * @PARAM                    : prepareStatement,colNum,attribute
  7679.  * @RETURN                   : void
  7680.  * @EXCEPTION                : class java.sql.SQLException
  7681.  * @LAST MODIFIED BY         :
  7682.  * @LAST MODIFIED DATE       :
  7683. **/
  7684.     public static void setFloat(PreparedStatement prepareStatement, int colNum,
  7685.         Float attribute) throws SQLException
  7686.     {
  7687.         if(attribute != null)
  7688.         {
  7689.             prepareStatement.setFloat(colNum, attribute.floatValue());
  7690.         }
  7691.         else
  7692.         {
  7693.             prepareStatement.setNull(colNum, Types.FLOAT);
  7694.         }
  7695.     }
  7696.  
  7697. /**
  7698.  * @METHOD NAME              : setDouble
  7699.  * @INFORMATION              : This method checks whether the parameter
  7700.                                'attribute' is not null. If null, sets the null
  7701.                                in Prepared Statement at the given column number,
  7702.                                else sets its primitive value after converting
  7703.                                 to primitive data type.
  7704.  * @PARAM                    : prepareStatement,colNum,attribute
  7705.  * @RETURN                   : void
  7706.  * @EXCEPTION                : class java.sql.SQLException
  7707.  * @LAST MODIFIED BY         :
  7708.  * @LAST MODIFIED DATE       :
  7709. **/
  7710.     public static void setDouble(PreparedStatement prepareStatement, int colNum,
  7711.         Double attribute) throws SQLException
  7712.     {
  7713.         if(attribute != null)
  7714.         {
  7715.             prepareStatement.setDouble(colNum, attribute.doubleValue());
  7716.         }
  7717.         else
  7718.         {
  7719.             prepareStatement.setNull(colNum, Types.DOUBLE);
  7720.         }
  7721.     }
  7722.  
  7723. /**
  7724.  * @METHOD NAME              : setString
  7725.  * @INFORMATION              : This method checks whether the parameter
  7726.                                'attribute' is not null. If null, sets the null
  7727.                                in Prepared Statement at the given column number,
  7728.                                else sets its primitive value after converting
  7729.                                 to primitive data type.
  7730.  * @PARAM                    : prepareStatement,colNum,attribute
  7731.  * @RETURN                   : void
  7732.  * @EXCEPTION                : class java.sql.SQLException
  7733.  * @LAST MODIFIED BY         :
  7734.  * @LAST MODIFIED DATE       :
  7735. **/
  7736.     public static void setString(PreparedStatement prepareStatement, int colNum,
  7737.         String attribute) throws SQLException
  7738.     {
  7739.         if(attribute != null)
  7740.         {
  7741.             prepareStatement.setString(colNum, attribute);
  7742.         }
  7743.         else
  7744.         {
  7745.             prepareStatement.setNull(colNum, Types.VARCHAR);
  7746.         }
  7747.     }
  7748.  
  7749. /**
  7750.  * @METHOD NAME              : setTimestamp
  7751.  * @INFORMATION              : This method checks whether the parameter
  7752.                                'attribute' is not null. If null, sets the null
  7753.                                in Prepared Statement at the given column number,
  7754.                                else sets its primitive value after converting
  7755.                                 to primitive data type.
  7756.  * @PARAM                    : prepareStatement,colNum,attribute
  7757.  * @RETURN                   : void
  7758.  * @EXCEPTION                : class java.sql.SQLException
  7759.  * @LAST MODIFIED BY         :
  7760.  * @LAST MODIFIED DATE       :
  7761. **/
  7762.     public static void setTimestamp(PreparedStatement prepareStatement, int
  7763.         colNum, Timestamp attribute) throws SQLException
  7764.     {
  7765.         if(attribute != null)
  7766.         {
  7767.             prepareStatement.setTimestamp(colNum, attribute);
  7768.         }
  7769.         else
  7770.         {
  7771.             prepareStatement.setNull(colNum, Types.TIMESTAMP);
  7772.         }
  7773.     }
  7774.  
  7775. /**
  7776.  * @METHOD NAME              : getShort
  7777.  * @INFORMATION              : This method converts passed parameter to Short
  7778.                                and returns Short, if the parameter is not null
  7779.                                else returns null.
  7780.  * @PARAM                    : stringData
  7781.  * @RETURN                   : class java.lang.Short
  7782.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7783.  * @LAST MODIFIED BY         :
  7784.  * @LAST MODIFIED DATE       :
  7785. **/
  7786.     public static Short getShort(String stringData) throws GOSIBatchException
  7787.     {
  7788.         Short shortConvert=null;
  7789.         try
  7790.         {
  7791.             if(stringData != null && !(stringData.equals("")))
  7792.             {
  7793.                 shortConvert = new Short(stringData);
  7794.             }
  7795.         }
  7796.         catch(Exception e)
  7797.         {
  7798.             throw new GOSIBatchException(e,
  7799.                         GOSIBatchConstants.REAL_ESTATE,
  7800.                         "GOSIBatchUtilities",
  7801.                         "getShort()",
  7802.                         "CMN_001_ERR_1000",
  7803.                         GOSIBatchConstants.SEVERITY_ONE);
  7804.         }
  7805.         return shortConvert;
  7806.     }
  7807.  
  7808.  
  7809.  
  7810. /**
  7811.  * @METHOD NAME              : getLong
  7812.  * @INFORMATION              : This method converts passed parameter to Long
  7813.                                and returns Long, if the parameter is not null
  7814.                                else returns null.
  7815.  * @PARAM                    : stringData
  7816.  * @RETURN                   : class java.lang.Long
  7817.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7818.  * @LAST MODIFIED BY         :
  7819.  * @LAST MODIFIED DATE       :
  7820. **/
  7821.     public static Long getLong(String stringData) throws GOSIBatchException
  7822.     {
  7823.         Long longConvert=null;
  7824.         try
  7825.         {
  7826.             if(stringData != null && !(stringData.equals("")))
  7827.             {
  7828.                 longConvert = new Long(stringData);
  7829.             }
  7830.         }
  7831.         catch(Exception e)
  7832.         {
  7833.             throw new GOSIBatchException(e,
  7834.                         GOSIBatchConstants.REAL_ESTATE,
  7835.                         "GOSIBatchUtilities",
  7836.                         "getLong()",
  7837.                         "CMN_001_ERR_1000",
  7838.                         GOSIBatchConstants.SEVERITY_ONE);
  7839.         }
  7840.         return longConvert;
  7841.     }
  7842.  
  7843.  
  7844.  
  7845. /**
  7846.  * @METHOD NAME              : getInteger
  7847.  * @INFORMATION              : This method converts passed parameter to Integer
  7848.                                and returns Integer, if the parameter is not null
  7849.                                else returns null.
  7850.  * @PARAM                    : stringData
  7851.  * @RETURN                   : class java.lang.Integer
  7852.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7853.  * @LAST MODIFIED BY         :
  7854.  * @LAST MODIFIED DATE       :
  7855. **/
  7856.     public static Integer getInteger(String stringData) throws GOSIBatchException
  7857.     {
  7858.         Integer integer=null;
  7859.         try
  7860.         {
  7861.             if(stringData != null && !(stringData.equals("")))
  7862.             {
  7863.                 integer = new Integer(stringData);
  7864.             }
  7865.         }
  7866.         catch(Exception e)
  7867.         {
  7868.             throw new GOSIBatchException(e,
  7869.                         GOSIBatchConstants.REAL_ESTATE,
  7870.                         "GOSIBatchUtilities",
  7871.                         "getInteger()",
  7872.                         "CMN_001_ERR_1000",
  7873.                         GOSIBatchConstants.SEVERITY_ONE);
  7874.         }
  7875.         return integer;
  7876.     }
  7877.  
  7878. /**
  7879.  * @METHOD NAME              : getByte
  7880.  * @INFORMATION              : This method converts passed parameter to Byte
  7881.                                and returns Byte, if the parameter is not null
  7882.                                else returns null.
  7883.  * @PARAM                    : stringData
  7884.  * @RETURN                   : class java.lang.Byte
  7885.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7886.  * @LAST MODIFIED BY         :
  7887.  * @LAST MODIFIED DATE       :
  7888. **/
  7889.     public static Byte getByte(String stringData) throws GOSIBatchException
  7890.     {
  7891.         Byte byteConvert=null;
  7892.         try
  7893.         {
  7894.             if(stringData != null && !(stringData.equals("")))
  7895.             {
  7896.                 byteConvert = new Byte(stringData);
  7897.             }
  7898.         }
  7899.         catch(Exception e)
  7900.         {
  7901.             throw new GOSIBatchException(e,
  7902.                         GOSIBatchConstants.REAL_ESTATE,
  7903.                         "GOSIBatchUtilities",
  7904.                         "getByte()",
  7905.                         "CMN_001_ERR_1000",
  7906.                         GOSIBatchConstants.SEVERITY_ONE);
  7907.         }
  7908.         return byteConvert;
  7909.     }
  7910.  
  7911. /**
  7912.  * @METHOD NAME              : getFloat
  7913.  * @INFORMATION              : This method converts passed parameter to Float
  7914.                                and returns Float, if the parameter is not null
  7915.                                else returns null.
  7916.  * @PARAM                    : stringData
  7917.  * @RETURN                   : class java.lang.Float
  7918.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7919.  * @LAST MODIFIED BY         :
  7920.  * @LAST MODIFIED DATE       :
  7921. **/
  7922.     public static Float getFloat(String stringData) throws GOSIBatchException
  7923.     {
  7924.         Float floatConvert=null;
  7925.         try
  7926.         {
  7927.             if(stringData != null && !(stringData.equals("")))
  7928.             {
  7929.                 return new Float(stringData);
  7930.             }
  7931.         }
  7932.         catch(Exception e)
  7933.         {
  7934.             throw new GOSIBatchException(e,
  7935.                         GOSIBatchConstants.REAL_ESTATE,
  7936.                         "GOSIBatchUtilities",
  7937.                         "getFloat()",
  7938.                         "CMN_001_ERR_1000",
  7939.                         GOSIBatchConstants.SEVERITY_ONE);
  7940.         }
  7941.         return floatConvert;
  7942.     }
  7943.  
  7944. /**
  7945.  * @METHOD NAME              : getDouble
  7946.  * @INFORMATION              : This method converts passed parameter to Double
  7947.                                and returns Double, if the parameter is not null
  7948.                                else returns null.
  7949.  * @PARAM                    : stringData
  7950.  * @RETURN                   : class java.lang.Double
  7951.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7952.  * @LAST MODIFIED BY         :
  7953.  * @LAST MODIFIED DATE       :
  7954. **/
  7955.     public static Double getDouble(String stringData) throws GOSIBatchException
  7956.     {
  7957.         Double doubleConvert=null;
  7958.         try
  7959.         {
  7960.             if(stringData != null && !(stringData.equals("")))
  7961.             {
  7962.                 doubleConvert = new Double(stringData);
  7963.             }
  7964.         }
  7965.         catch(Exception e)
  7966.         {
  7967.             throw new GOSIBatchException(e,
  7968.                         GOSIBatchConstants.REAL_ESTATE,
  7969.                         "GOSIBatchUtilities",
  7970.                         "getDouble()",
  7971.                         "CMN_001_ERR_1000",
  7972.                         GOSIBatchConstants.SEVERITY_ONE);
  7973.         }
  7974.         return doubleConvert;
  7975.     }
  7976.  
  7977. /**
  7978.  * @METHOD NAME              : getString
  7979.  * @INFORMATION              : This method converts passed parameter to String
  7980.                                and returns String, if the parameter is not null
  7981.                                else returns null.
  7982.  * @PARAM                    : stringData
  7983.  * @RETURN                   : class java.lang.String
  7984.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  7985.  * @LAST MODIFIED BY         :
  7986.  * @LAST MODIFIED DATE       :
  7987. **/
  7988.     public static String getString(String stringData) throws GOSIBatchException
  7989.     {
  7990.         String stringConvert=null;
  7991.         try
  7992.         {
  7993.             if(stringData != null && !(stringData.equals("")))
  7994.             {
  7995.                 stringConvert = stringData;
  7996.             }
  7997.         }
  7998.         catch(Exception e)
  7999.         {
  8000.             throw new GOSIBatchException(e,
  8001.                         GOSIBatchConstants.REAL_ESTATE,
  8002.                         "GOSIBatchUtilities",
  8003.                         "getString()",
  8004.                         "CMN_001_ERR_1000",
  8005.                         GOSIBatchConstants.SEVERITY_ONE);
  8006.         }
  8007.         return stringConvert;
  8008.     }
  8009.  
  8010.  
  8011. /**
  8012.  * @METHOD NAME              : getSystemUser
  8013.  * @INFORMATION              : This method gets the user id for the system
  8014.  * @RETURN                   : systemuserid
  8015.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  8016.  * @LAST MODIFIED BY         :
  8017.  * @LAST MODIFIED DATE       :
  8018. **/
  8019.  
  8020.     public static long getSystemUser()
  8021.     throws GOSIBatchException
  8022.     {
  8023.         Connection connection=null;
  8024.         PreparedStatement psUser=null;
  8025.         ResultSet rsUser=null;
  8026.         boolean invoke=false;
  8027.         long userCode=0L;
  8028.         try
  8029.         {
  8030.            
  8031.             // Executing query for getting the system user id
  8032.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1021");
  8033.             connection=GOSIBatchUtilities.
  8034.             getDbConnection(GOSIBatchConstants.COMMON);
  8035.             psUser=connection.prepareStatement(query);
  8036.             psUser.setString(1,GOSIBatchProperties.SYSTEM_USER+"%");
  8037.             rsUser=psUser.executeQuery();
  8038.            
  8039.             //this if is no longer used
  8040.             if(rsUser.next())
  8041.             {
  8042.                 userCode=rsUser.getLong("ID");
  8043.             }
  8044.             else
  8045.             {
  8046.                 new GOSIBatchException(null,
  8047.                 "BatchCore",
  8048.                 "GOSIBatchUtilities",
  8049.                 "getBatchMaster",
  8050.                 "CMN_001_ERR_1006",
  8051.                 GOSIBatchConstants.SEVERITY_ONE);    
  8052.             }
  8053.         }
  8054.         catch(GOSIBatchException ge)
  8055.         {
  8056.             throw ge;
  8057.         }
  8058.         catch(Exception e)
  8059.         {
  8060.             new GOSIBatchException(e,
  8061.             "BatchCore",
  8062.             "GOSIBatchUtilities",
  8063.             "Constructor",
  8064.             "CMN_001_ERR_1000",
  8065.             GOSIBatchConstants.SEVERITY_ONE);
  8066.         }
  8067.         finally
  8068.         {
  8069.             GOSIBatchUtilities.cleanUp(rsUser, psUser, connection);
  8070.         }
  8071.         return userCode;
  8072.     }
  8073.  
  8074. /**
  8075.  * @METHOD NAME              : getTaskId
  8076.  * @INFORMATION              : This method is used to get the Task id based on
  8077.                                the workflow task short name passed as a parameter.
  8078.  * @PARAM                    : shortName
  8079.  * @RETURN                   : long
  8080.  * @EXCEPTION                : class gosi.core.util.GOSIException
  8081.  * @LAST MODIFIED BY         :
  8082.  * @LAST MODIFIED DATE       :
  8083. **/
  8084.     private long getTaskId(String shortName)
  8085.     throws GOSIBatchException
  8086.     {
  8087.         Connection connection=null;
  8088.         PreparedStatement ps=null;
  8089.         ResultSet rs=null;
  8090.         long taskId=0L;
  8091.         try
  8092.         {            
  8093.             connection=GOSIBatchUtilities.
  8094.             getDbConnection(GOSIBatchConstants.COMMON);
  8095.             String query=GOSIBatchSQL.getSqlString("CMN_030_SQL_1001");
  8096.             //Getting taskId for the ShortName Passed                      
  8097.             ps=connection.prepareStatement(query);
  8098.             ps.setString(1, shortName);
  8099.             rs=ps.executeQuery();
  8100.             if(rs.next())
  8101.             {
  8102.                 taskId=rs.getLong("TASKID");
  8103.             }
  8104.             else
  8105.             {                
  8106.                 throw new GOSIBatchException(null,
  8107.                         GOSIBatchConstants.WORKFLOW,
  8108.                         "GOSIBatchUtilities",
  8109.                         "getTaskId()",
  8110.                         "CMN_001_ERR_1000",
  8111.                         GOSIBatchConstants.SEVERITY_ONE);
  8112.             }
  8113.  
  8114.         }
  8115.         catch(GOSIBatchException ge)
  8116.         {
  8117.             throw ge;
  8118.         }
  8119.         catch(Exception e)
  8120.         {
  8121.                 throw new GOSIBatchException(e,
  8122.                         GOSIBatchConstants.WORKFLOW,
  8123.                         "GOSIBatchUtilities",
  8124.                         "getTaskId()",
  8125.                         "CMN_001_ERR_1000",
  8126.                         GOSIBatchConstants.SEVERITY_ONE);
  8127.         }
  8128.         finally
  8129.         {
  8130.             GOSIBatchUtilities.cleanUp(rs, ps, connection);
  8131.         }
  8132.         return taskId;
  8133.     }
  8134.            
  8135. /**
  8136.  * @METHOD NAME              : cancelWorkflow
  8137.  * @INFORMATION              : This method is used to cancel workflow record (e.g. child)
  8138.                              : and Update parent record description if parent is present
  8139.                              : and it has only this child
  8140.  * @PARAM                    :
  8141.  * @RETURN                   : ArrayList
  8142.  * @EXCEPTION                : class gosi.core.util.GOSIException
  8143.  * @LAST MODIFIED BY         :
  8144.  * @LAST MODIFIED DATE       :
  8145. **/
  8146.     public ArrayList cancelWorkflow (String actionName, Timestamp fromDate)
  8147.     throws GOSIBatchException
  8148.     {
  8149.         ArrayList workflowtxnList=new ArrayList();
  8150.         Connection connection=null;
  8151.         PreparedStatement ps = null;
  8152.         ResultSet rs = null;
  8153.         long taskId=0L;
  8154.  
  8155.         try
  8156.         {      
  8157.             // get taskid using actionName         
  8158.             taskId=getTaskId(actionName);
  8159.            
  8160.             connection=GOSIBatchUtilities.
  8161.             getDbConnection(GOSIBatchConstants.COMMON);
  8162.             String query=GOSIBatchSQL.getSqlString("CMN_030_SQL_1002");
  8163.             // get arraylist of records to be cancelled                                    
  8164.             ps = connection.prepareStatement(query);
  8165.             ps.setLong(1, taskId);
  8166.             ps.setTimestamp(2, fromDate);
  8167.             rs = ps.executeQuery();
  8168.            
  8169.             while(rs.next())
  8170.             {
  8171.                 BatchWorkflowParamBean workflowBean = new BatchWorkflowParamBean();
  8172.                 workflowBean.setWorkflowId(rs.getLong("WORKFLOWTXNID"));
  8173.                 workflowBean.setTransactionId(rs.getLong("TRANSACTIONID"));
  8174.                 workflowBean.setPrimaryKey(rs.getString("PRIMARYKEY"));
  8175.                 workflowBean.setParentPrimaryKey(rs.getString("PARENTPRIMARYKEY"));
  8176.  
  8177.                 // add to the list of beans
  8178.                 workflowtxnList.add(workflowBean);
  8179.  
  8180.                 // Update as deleted in workflowTXN
  8181.                 updateDeleted(workflowBean);
  8182.                
  8183.                 // Update parent record description if parent is present
  8184.                 updateParentOfDeleted(workflowBean);           
  8185.             }
  8186.        
  8187.         }catch(Exception e)
  8188.         {
  8189.             throw new GOSIBatchException(e,
  8190.             GOSIBatchConstants.WORKFLOW,
  8191.             "GOSIBatchUtilities",
  8192.             "cancelWorkflow()",
  8193.             "CMN_001_ERR_1000",
  8194.             GOSIBatchConstants.SEVERITY_ONE);
  8195.  
  8196.         }
  8197.         finally
  8198.         {
  8199.             GOSIBatchUtilities.cleanUp(rs, ps, connection);
  8200.         }
  8201.        
  8202.         return workflowtxnList;
  8203.     }
  8204.  
  8205. /**
  8206.  * @METHOD NAME              : updateDeleted
  8207.  * @INFORMATION              : This method is to update workflowTxn records as cancelled
  8208.                              :
  8209.  * @PARAM                    :
  8210.  * @RETURN                   : ArrayList
  8211.  * @EXCEPTION                : class gosi.core.util.GOSIException
  8212.  * @LAST MODIFIED BY         :
  8213.  * @LAST MODIFIED DATE       :
  8214. **/
  8215.     private void updateDeleted (BatchWorkflowParamBean workflowBean)
  8216.     throws GOSIBatchException
  8217.     {
  8218.         Connection connection=null;
  8219.         PreparedStatement ps = null;
  8220.         ResultSet rs = null;
  8221.  
  8222.         long workflowId=0L;            
  8223.  
  8224.         try
  8225.         {                      
  8226.             workflowId=workflowBean.getWorkflowId();           
  8227.  
  8228.             connection=GOSIBatchUtilities.
  8229.             getDbConnection(GOSIBatchConstants.COMMON);
  8230.             String update=GOSIBatchSQL.getSqlString("CMN_030_SQL_1003");
  8231.  
  8232.             //check if parent exists
  8233.             //Get parent TransactionId for the record Passed
  8234.             ps = connection.prepareStatement(update);
  8235.             ps.setTimestamp(1,getSystemDate());
  8236.             ps.setString(2, GOSIBatchConstants.CANCELLED);
  8237.             ps.setLong(3, workflowId);            
  8238.             int result=ps.executeUpdate();
  8239.             connection.commit();
  8240.                                                
  8241.         }catch(Exception e)
  8242.         {                      
  8243.             throw new GOSIBatchException(e,
  8244.             GOSIBatchConstants.WORKFLOW,
  8245.             "GOSIBatchUtilities",
  8246.             "updateDeleted()",
  8247.             "CMN_001_ERR_1000",
  8248.             GOSIBatchConstants.SEVERITY_ONE);
  8249.            
  8250.         }
  8251.         finally
  8252.         {
  8253.             GOSIBatchUtilities.cleanUp(rs, ps, connection);
  8254.         }
  8255.        
  8256.     }
  8257.  
  8258. /**
  8259.  * @METHOD NAME              : updateParentOfDeleted
  8260.  * @INFORMATION              : This method is used to update Parent record Of Canceled workflow
  8261.                              : so that parent could be moved from workflowTemp
  8262.  * @PARAM                    :
  8263.  * @RETURN                   :
  8264.  * @EXCEPTION                : class gosi.core.util.GOSIException
  8265.  * @LAST MODIFIED BY         :
  8266.  * @LAST MODIFIED DATE       :
  8267. **/
  8268.     private void updateParentOfDeleted (BatchWorkflowParamBean workflowBean)
  8269.     throws GOSIBatchException
  8270.     {
  8271.         Connection connection=null;
  8272.         PreparedStatement ps = null;
  8273.         ResultSet rs = null;
  8274.  
  8275.         long workflowId=0L;
  8276.         long transactionId=0L;
  8277.         String ParentPrimaryKey=null;
  8278.         long parentTransactionId=0L;
  8279.  
  8280.         try
  8281.         {                      
  8282.             workflowId=workflowBean.getWorkflowId();           
  8283.             transactionId=workflowBean.getTransactionId();
  8284.             ParentPrimaryKey=workflowBean.getParentPrimaryKey();
  8285.  
  8286.             connection=GOSIBatchUtilities.
  8287.             getDbConnection(GOSIBatchConstants.COMMON);
  8288.             String query=GOSIBatchSQL.getSqlString("CMN_030_SQL_1004");
  8289.  
  8290.             //check if parent exists
  8291.             //Get parent TransactionId for the record Passed
  8292.             ps = connection.prepareStatement(query);
  8293.             ps.setLong(1, transactionId);
  8294.             ps.setByte(2, GOSIBatchConstants.CHILD);
  8295.             rs = ps.executeQuery();
  8296.                                    
  8297.             if(rs.next())
  8298.             {
  8299.                 parentTransactionId=rs.getLong("ID");            
  8300.            
  8301.                 // Update parent record description in workflowTemp
  8302.                 String update=GOSIBatchSQL.getSqlString("CMN_030_SQL_1005");
  8303.                 ps = connection.prepareStatement(update);
  8304.                 ps.setByte(1, GOSIBatchConstants.PROCESS);             
  8305.                 ps.setString(2, GOSIBatchConstants.CHILD_CANCELLED);
  8306.                 ps.setLong(3, parentTransactionId);
  8307.                 ps.setString(4, ParentPrimaryKey);
  8308.                 int result=ps.executeUpdate();
  8309.                 connection.commit();
  8310.             }
  8311.            
  8312.  
  8313.         }catch(Exception e)
  8314.         {                      
  8315.             throw new GOSIBatchException(e,
  8316.             GOSIBatchConstants.WORKFLOW,
  8317.             "GOSIBatchUtilities",
  8318.             "updateParentOfDeleted()",
  8319.             "CMN_001_ERR_1000",
  8320.             GOSIBatchConstants.SEVERITY_ONE);
  8321.            
  8322.         }
  8323.         finally
  8324.         {
  8325.             GOSIBatchUtilities.cleanUp(rs, ps, connection);
  8326.         }
  8327.        
  8328.     }
  8329.  
  8330.  
  8331. /**
  8332.  * @METHOD NAME              : isArabNation
  8333.  * @INFORMATION              : This method is used to update Parent record Of Canceled workflow
  8334.                              : so that parent could be moved from workflowTemp
  8335.  * @PARAM                    :
  8336.  * @RETURN                   : boolean
  8337.  * @EXCEPTION                : class gosi.core.util.GOSIException
  8338.  * @LAST MODIFIED BY         :
  8339.  * @LAST MODIFIED DATE       :
  8340. **/
  8341. public static boolean isArabNation(short countryCode)
  8342.  
  8343. {
  8344.  
  8345.             boolean isNatArabic = false;
  8346.  
  8347.             List arbNationCodeList = GOSIBatchConstants.arbNationCodeList;
  8348.  
  8349.             ArrayList arbNationCodeArrayList =new  ArrayList(arbNationCodeList);
  8350.  
  8351.  
  8352.  
  8353.             if(!arbNationCodeArrayList.contains(""+countryCode))
  8354.  
  8355.             {
  8356.  
  8357.                         isNatArabic=false;
  8358.  
  8359.             }
  8360.  
  8361.             else
  8362.  
  8363.             {
  8364.  
  8365.                         isNatArabic=true;
  8366.  
  8367.             }
  8368.  
  8369.             return isNatArabic;
  8370.  
  8371. }
  8372.  
  8373. /**
  8374.  * @METHOD NAME              : getPendingWSRequests
  8375.  * @INFORMATION              : returns a hashmap of all pending requests that are of type wsname
  8376.  * @RETURN                   : HashMap
  8377.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  8378.  * @LAST MODIFIED BY         :
  8379.  * @LAST MODIFIED DATE       :
  8380. **/
  8381.  
  8382.     public static ArrayList getPendingWSRequests(String WSName)
  8383.     throws GOSIBatchException
  8384.     {
  8385.         //get all ids for the pending requests from T_WSTRANSACTION that belongs to the passed WSName
  8386.         //decode all objects, coresponding to the returned ids, stored as files to java objects
  8387.         // store objects as the value of the hashmap and the ids as the keys
  8388.         //reurn this hashmap to be casted to any type depending on the caller. who will return the same keys and values to stored
  8389.  
  8390.         Connection connection=null;
  8391.         PreparedStatement psWSReq=null;
  8392.         ResultSet rsWSReq=null;
  8393.         ArrayList reqs=new ArrayList();
  8394.         HashMap idsObjs=null;
  8395.         try
  8396.         {      
  8397.             // Executing query to get pending requests
  8398.             // SELECT a.ID, a.USERID, i.USERREFERENCEID  
  8399.             // from T_WSTRANSACTION a , T_WSTASK b, T_USER_INTERNET i  
  8400.             // where a.TASKID = b.TASKID  and a.USERID = i.ID  and a.STATUS = 1003 and b.WSNAME = ?;
  8401.  
  8402.             String query= GOSIBatchSQL.getSqlString("CMN_001_SQL_1068");
  8403.             connection=GOSIBatchUtilities.getDbConnection(GOSIBatchConstants.COMMON);
  8404.             psWSReq=connection.prepareStatement(query);
  8405.             psWSReq.setInt(1,GOSIBatchConstants.PENDING);
  8406.             psWSReq.setString(2,WSName);
  8407.             rsWSReq=psWSReq.executeQuery();
  8408.            
  8409.            
  8410.             while(rsWSReq.next())
  8411.             {
  8412.                 long wsId=rsWSReq.getLong("ID");
  8413.                 System.out.println("wsId : "+wsId);
  8414.                 XMLDecoder d = new XMLDecoder(
  8415.                           new BufferedInputStream(
  8416.                               new FileInputStream(GOSIBatchConstants.FILEPATH_WS_REQUEST+wsId+".xml")));
  8417.                 Object result = d.readObject();
  8418.                 d.close();
  8419.                 idsObjs = new HashMap();
  8420.                 idsObjs.put("ID", new Long(wsId));
  8421.                 idsObjs.put("OBJECT", result);
  8422.                 idsObjs.put("USERID", new Long(rsWSReq.getLong("USERID")));
  8423.                 idsObjs.put("USERREFERENCEID", new Long(rsWSReq.getLong("USERREFERENCEID")));
  8424.                 reqs.add(idsObjs);
  8425.             }
  8426.            
  8427.             // This will only be executed on Preprod and never executed on Production.
  8428.             // It will return the pending requests that was received without passing certificate.
  8429.             // Those pending requests has user id = 1 thus the above query doesn't return them back.
  8430.             // See Registration MonthlyMovementWS documentation for detailed design and info.
  8431.             // SELECT a.ID, a.USERID from T_WSTRANSACTION a , T_WSTASK b
  8432.             // where a.TASKID = b.TASKID and a.USERID = 1 and a.STATUS = 1003 and b.WSNAME = ?
  8433.  
  8434.            
  8435.             long system = 1;
  8436.             query= GOSIBatchSQL.getSqlString("CMN_001_SQL_1073");
  8437.             psWSReq=connection.prepareStatement(query);
  8438.             psWSReq.setLong(1,new Long (system));
  8439.             psWSReq.setInt(2,GOSIBatchConstants.PENDING);
  8440.             psWSReq.setString(3,WSName);
  8441.             rsWSReq=psWSReq.executeQuery();
  8442.  
  8443.             while(rsWSReq.next())
  8444.             {
  8445.                 long wsId=rsWSReq.getLong("ID");
  8446.                 System.out.println("wsId : "+wsId);
  8447.                 XMLDecoder d = new XMLDecoder(
  8448.                            new BufferedInputStream(
  8449.                                new FileInputStream(GOSIBatchConstants.FILEPATH_WS_REQUEST+wsId+".xml")));
  8450.                 Object result = d.readObject();
  8451.                 d.close();
  8452.                 idsObjs = new HashMap();
  8453.                 idsObjs.put("ID", new Long(wsId));
  8454.                 idsObjs.put("OBJECT", result);
  8455.                 idsObjs.put("USERID", new Long(rsWSReq.getLong("USERID")));
  8456.                 reqs.add(idsObjs);
  8457.             }
  8458.         }
  8459.         catch(GOSIBatchException ge)
  8460.         {
  8461.             throw ge;
  8462.         }
  8463.         catch(Exception e)
  8464.         {
  8465.             throw new GOSIBatchException(e,
  8466.             "BatchCore",
  8467.             "GOSIBatchUtilities",
  8468.             "getPendingWSRequests",
  8469.             "CMN_001_ERR_1000",
  8470.             GOSIBatchConstants.SEVERITY_ONE);
  8471.         }
  8472.         finally
  8473.         {
  8474.             GOSIBatchUtilities.cleanUp(rsWSReq, psWSReq, connection);
  8475.         }
  8476.         return reqs;
  8477.     }
  8478.  
  8479.  
  8480.     /**
  8481.  * @METHOD NAME              : updateWSRequests
  8482.  * @INFORMATION              : updates all web services requests that are passed
  8483.  * @RETURN                   : void
  8484.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  8485.  * @LAST MODIFIED BY         :
  8486.  * @LAST MODIFIED DATE       :
  8487. **/
  8488.  
  8489.     public static void updateWSRequests(ArrayList processedReqs)
  8490.     throws GOSIBatchException
  8491.     {
  8492.         //loop thru the hashmap and update the status of each id (key) in the hashmap to processed
  8493.         //encode each object (value) in the hashmap to xml file in the output dir.
  8494.         Connection connection=null;
  8495.         PreparedStatement psWSReq=null;
  8496.         try
  8497.         {
  8498.            
  8499.         System.out.println("The size of ArrayList = "+processedReqs.size());
  8500.         System.out.println("If ArrayList empty = "+processedReqs.isEmpty());
  8501.        
  8502.         System.out.println("The elements of ArrayList are");
  8503.        
  8504.         while(!processedReqs.isEmpty()){
  8505.             HashMap idsObjs = (HashMap)processedReqs.remove(0);
  8506.             Long wsId = (Long)idsObjs.get("ID");
  8507.             Object procObject = idsObjs.get("OBJECT");
  8508.  
  8509.             //Long wsId=(Long)iter.next();
  8510.             System.out.println("wsId : "+wsId);
  8511.             //Object procObject = processedReqs.get(wsId);
  8512.             System.out.println("Object " + procObject);
  8513.  
  8514.             //CMN_001_SQL_1069
  8515.             String query= GOSIBatchSQL.getSqlString("CMN_001_SQL_1069");
  8516.             //"UPDATE T_WSTRANSACTION  SET STATUS = "+GOSIBatchConstants.PROCESSED+" where ID = ? ";
  8517.                 //GOSIBatchSQL.getSqlString("CMN_001_SQL_1021");
  8518.             connection=GOSIBatchUtilities.
  8519.             getDbConnection(GOSIBatchConstants.COMMON);
  8520.             psWSReq=connection.prepareStatement(query);
  8521.             psWSReq.setLong(1,GOSIBatchConstants.PROCESSED);
  8522.             psWSReq.setLong(2,wsId.longValue());
  8523.             int result=psWSReq.executeUpdate();
  8524.             connection.commit();
  8525.  
  8526.             XMLEncoder e = new XMLEncoder(
  8527.                           new BufferedOutputStream(
  8528.                               new FileOutputStream(GOSIBatchConstants.FILEPATH_WS_RESPONSE+wsId+".xml")));
  8529.             e.writeObject(procObject);
  8530.             e.close();
  8531.             }
  8532.  
  8533.         }
  8534.         catch(GOSIBatchException ge)
  8535.         {
  8536.             throw ge;
  8537.         }
  8538.         catch(Exception e)
  8539.         {
  8540.             throw new GOSIBatchException(e,
  8541.             "BatchCore",
  8542.             "GOSIBatchUtilities",
  8543.             "updateWSRequests",
  8544.             "CMN_001_ERR_1000",
  8545.             GOSIBatchConstants.SEVERITY_ONE);
  8546.         }
  8547.         finally
  8548.         {
  8549.             GOSIBatchUtilities.cleanUp(psWSReq, connection);
  8550.         }
  8551.                
  8552.  
  8553.     }
  8554.  
  8555.     /**
  8556.  * @METHOD NAME              : createSMSRequest
  8557.  * @INFORMATION              : This method calls the method that creates sms requests for batches without defining a sending date.
  8558.  * @PARAM                    : smsShortName: represents shortname for the SMSMaster table
  8559.  * @PARAM                    : primaryKey: represents the primary key that will be inserted as a primary key for the query stored in the table SMSMaster
  8560.  * @PARAM                    : requestedBy: represents the person id who requested the service
  8561.  * @PARAM                    : connection: connection to the database
  8562.  * @RETURN                   : void
  8563.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  8564.  * @LAST MODIFIED BY         :
  8565.  * @LAST MODIFIED DATE       :
  8566. **/
  8567.  
  8568.    
  8569.     public static void createSMSRequest(String smsShortName, String primaryKey, long requestedBy, Connection connection)
  8570.     throws GOSIBatchException
  8571.     {
  8572.         createSMSRequest( smsShortName, primaryKey, requestedBy, connection, null);
  8573.     }
  8574.  
  8575.         /**
  8576.  * @METHOD NAME              : createSMSRequest
  8577.  * @INFORMATION              : This method creates sms requests for batches. This method creates only one record per call
  8578.  * @PARAM                    : smsShortName: represents shortname for the SMSMaster table
  8579.  * @PARAM                    : primaryKey: represents the primary key that will be inserted as a primary key for the query stored in the table SMSMaster
  8580.  * @PARAM                    : requestedBy: represents the person id who requested the service
  8581.  * @PARAM                    : connection: connection to the database
  8582.  * @RETURN                   : void
  8583.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  8584.  * @LAST MODIFIED BY         :
  8585.  * @LAST MODIFIED DATE       :
  8586. **/
  8587.  
  8588.     public static void createSMSRequest(String smsShortName, String primaryKey, long requestedBy, Connection connection, Timestamp sendingDate)
  8589.     throws GOSIBatchException
  8590.     {
  8591.         PreparedStatement psSMSId=null;
  8592.         ResultSet rsSMSId=null;
  8593.         try
  8594.         {
  8595.             long smsId = 0;
  8596.             String query= GOSIBatchSQL.getSqlString("CMN_030_SQL_1008");
  8597.             psSMSId=connection.prepareStatement(query);
  8598.             psSMSId.setString(1,smsShortName);
  8599.             rsSMSId=psSMSId.executeQuery();
  8600.            
  8601.            
  8602.             if(rsSMSId.next())
  8603.             {
  8604.                 smsId=rsSMSId.getLong("ID");
  8605.  
  8606.             GOSIBatchUtilities.cleanUp(psSMSId);
  8607.             Long recordId = getPrimaryKey("T_SMSREQUEST", requestedBy);
  8608.             query= GOSIBatchSQL.getSqlString("CMN_030_SQL_1009");
  8609.             psSMSId=connection.prepareStatement(query);
  8610.             psSMSId.setLong(1,smsId);
  8611.             psSMSId.setString(2,primaryKey);
  8612.             psSMSId.setInt(3,0);
  8613.             psSMSId.setTimestamp(4,getSystemDate());
  8614.             psSMSId.setLong(5,requestedBy);
  8615.             psSMSId.setLong(6,recordId.longValue());
  8616.             if (sendingDate != null)
  8617.             {
  8618.                 psSMSId.setTimestamp(7,sendingDate);
  8619.             }
  8620.             else
  8621.                 {
  8622.                     psSMSId.setNull(7,java.sql.Types.TIMESTAMP);                   
  8623.                 }
  8624.             int result=psSMSId.executeUpdate();
  8625.             }
  8626.  
  8627.         }
  8628.         catch(GOSIBatchException ge)
  8629.         {
  8630.             throw ge;
  8631.         }
  8632.         catch(Exception e)
  8633.         {
  8634.             throw new GOSIBatchException(e,
  8635.             "BatchCore",
  8636.             "GOSIBatchUtilities",
  8637.             "createSMSRequest",
  8638.             "CMN_001_ERR_1000",
  8639.             GOSIBatchConstants.SEVERITY_ONE);
  8640.         }
  8641.         finally
  8642.         {
  8643.             GOSIBatchUtilities.cleanUp(rsSMSId);
  8644.             GOSIBatchUtilities.cleanUp(psSMSId);
  8645.         }
  8646.                
  8647.  
  8648.     }
  8649.  
  8650.  
  8651.     /**
  8652.  * @METHOD NAME              : createSMSRequest
  8653.  * @INFORMATION              : This method calls the method that creates sms requests for batches without defining a sending date.
  8654.  * @PARAM                    : smsShortName: represents shortname for the SMSMaster table
  8655.  * @PARAM                    : primaryKeys: represent the primary keys that will be inserted as a primary key for the query stored in the table SMSMaster
  8656.  * @PARAM                    : requestedBy: represents the person id who requested the service
  8657.  * @PARAM                    : connection: connection to the database
  8658.  * @RETURN                   : void
  8659.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  8660.  * @LAST MODIFIED BY         :
  8661.  * @LAST MODIFIED DATE       :
  8662. **/
  8663.  
  8664.     public static void createSMSRequest(String smsShortName, ArrayList primaryKeys, long requestedBy, Connection connection)
  8665.     throws GOSIBatchException
  8666.     {
  8667.         createSMSRequest( smsShortName, primaryKeys, requestedBy, connection, null);
  8668.     }
  8669.  
  8670.    
  8671. /**
  8672.  * @METHOD NAME              : createSMSRequest
  8673.  * @INFORMATION              : This method creates sms requests for batches, it takes list of primary keys
  8674.  * @PARAM                    : smsShortName: represents shortname for the SMSMaster table
  8675.  * @PARAM                    : primaryKeys: represent the primary keys that will be inserted as a primary key for the query stored in the table SMSMaster
  8676.  * @PARAM                    : requestedBy: represents the person id who requested the service
  8677.  * @PARAM                    : connection: connection to the database
  8678.  * @RETURN                   : void
  8679.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  8680.  * @LAST MODIFIED BY         :
  8681.  * @LAST MODIFIED DATE       :
  8682. **/
  8683.  
  8684.  
  8685.     public static void createSMSRequest(String smsShortName, ArrayList primaryKeys, long requestedBy, Connection connection, ArrayList sendingDate)
  8686.     throws GOSIBatchException
  8687.     {
  8688.         PreparedStatement psSMSId=null;
  8689.         ResultSet rsSMSId=null;
  8690.         try
  8691.         {
  8692.             long smsId = 0;
  8693.             String query= GOSIBatchSQL.getSqlString("CMN_030_SQL_1008");
  8694.             psSMSId=connection.prepareStatement(query);
  8695.             psSMSId.setString(1,smsShortName);
  8696.             rsSMSId=psSMSId.executeQuery();
  8697.            
  8698.             //retrieve the master id for the message from the SMSMaster table based on the parameter smsShortName
  8699.             if(rsSMSId.next())
  8700.             {
  8701.                 smsId=rsSMSId.getLong("ID");
  8702.            
  8703.  
  8704.             GOSIBatchUtilities.cleanUp(psSMSId);
  8705.            
  8706.             query= GOSIBatchSQL.getSqlString("CMN_030_SQL_1009");
  8707.             psSMSId=connection.prepareStatement(query);
  8708.  
  8709.  
  8710.             //iterate through all the provided primary keys then update the table SMSRequest
  8711.             for (int i=0; i< primaryKeys.size() ;i++ )
  8712.             {
  8713.                 Long recordId = getPrimaryKey("T_SMSREQUEST", requestedBy);
  8714.                 psSMSId.setLong(1,smsId);
  8715.                 psSMSId.setString(2,primaryKeys.get(i).toString());
  8716.                 psSMSId.setInt(3,0);
  8717.                 psSMSId.setTimestamp(4,getSystemDate());
  8718.                 psSMSId.setLong(5,requestedBy);
  8719.                 psSMSId.setLong(6,recordId.longValue());
  8720.                 if(sendingDate != null)
  8721.                 {
  8722.                     if(sendingDate.get(i) != null)
  8723.                     {
  8724.                         psSMSId.setTimestamp(7,(Timestamp) sendingDate.get(i));
  8725.                     }
  8726.                     else
  8727.                     {
  8728.                         psSMSId.setNull(7,java.sql.Types.TIMESTAMP);
  8729.                     }
  8730.                 }
  8731.                 else
  8732.                 {
  8733.                     psSMSId.setNull(7,java.sql.Types.TIMESTAMP);
  8734.                 }
  8735.                 psSMSId.addBatch();
  8736.             }
  8737.  
  8738.             // Execute the SQL satement.
  8739.             psSMSId.executeBatch();
  8740.             psSMSId.clearBatch();
  8741.             }
  8742.         }
  8743.  
  8744.  
  8745.         catch(GOSIBatchException ge)
  8746.         {
  8747.             throw ge;
  8748.         }
  8749.         catch(Exception e)
  8750.         {
  8751.             throw new GOSIBatchException(e,
  8752.             "BatchCore",
  8753.             "GOSIBatchUtilities",
  8754.             "createSMSRequest",
  8755.             "CMN_001_ERR_1000",
  8756.             GOSIBatchConstants.SEVERITY_ONE);
  8757.         }
  8758.         finally
  8759.         {
  8760.             GOSIBatchUtilities.cleanUp(rsSMSId);
  8761.             GOSIBatchUtilities.cleanUp(psSMSId);
  8762.         }
  8763.                
  8764.  
  8765.     }
  8766.  
  8767.  
  8768.  
  8769.  
  8770.  
  8771.     /**
  8772.  * @METHOD NAME              : checkDuplicateRecord
  8773.  * @INFORMATION              : This method checks for duplicate in workflowtxn
  8774.                              : it accepts workflowparambean and check the constraint
  8775.                              : of the WorkflowTexn with the parametrs of workflowParambean
  8776.                              :
  8777.  * @PARAM                    : workflowParambean
  8778.  * @RETURN                   : True if the there is a duplicate record, false otherwise
  8779.  * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  8780.  * @LAST MODIFIED BY         :
  8781.  * @LAST MODIFIED DATE       :
  8782. **/
  8783.     public static boolean checkDuplicateRecord(WorkflowTxn workflowTxn)
  8784.     throws GOSIBatchException
  8785.     {
  8786.         Connection connection=null;
  8787.         PreparedStatement ps=null;
  8788.         ResultSet rs=null;
  8789.         boolean duplicate = true;
  8790.         try
  8791.         {
  8792.             String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1070");
  8793.            
  8794.            // This is a workround to solve the problem of  setting a DBNULL value
  8795.            // it seems that PreparedSatement.setNull(...,..) is not working, maybe due to
  8796.            // driver support problem. I could use the oracle type but it will not be portable then
  8797.            // This is just a workround for current situation and should be changed later on.
  8798.            // here if the value is null then I change the dynamic parameter to static parameter
  8799.            // [Colmun Name] IS NULL
  8800.             if (workflowTxn.getStatus() == null)
  8801.             {
  8802.                 query = query.replaceAll("STATUS =\\?", " STATUS IS NULL ");
  8803.             }
  8804.             if (workflowTxn.getTimeOfCompletion() == null)
  8805.             {
  8806.                 query = query.replaceAll("COMPLETIONTIME = \\?", " COMPLETIONTIME IS NULL ");
  8807.             }
  8808.             // Obtain the connection
  8809.             connection=GOSIBatchUtilities.getDbConnection(GOSIBatchConstants.COMMON);
  8810.             // Create a prepared statement.
  8811.             ps=connection.prepareStatement(query);
  8812.  
  8813.             // set the parameters.
  8814.             // These parameters are the constrait parameters
  8815.             // if these parameters found then there is a duplicate.
  8816.             ps.setLong(1,workflowTxn.getCreatedUserId());
  8817.             ps.setLong(2,workflowTxn.getTargetUserId());
  8818.             ps.setLong(3,workflowTxn.getTransactionId());
  8819.             ps.setLong(4,workflowTxn.getCompletedStepId());
  8820.             ps.setLong(5,workflowTxn.getPendingStepId());
  8821.             ps.setString(6,workflowTxn.getPrimaryKeys());
  8822.             ps.setLong(7,workflowTxn.getTargetRoleId());
  8823.          
  8824.             // Set the values if they are not equal to null.
  8825.             if (workflowTxn.getStatus() != null)
  8826.             {
  8827.                 setString(ps,8,workflowTxn.getStatus());
  8828.             }
  8829.             if (workflowTxn.getTimeOfCompletion() != null)
  8830.             {
  8831.                 setTimestamp(ps,9,workflowTxn.getTimeOfCompletion());
  8832.             }
  8833.             System.out.println("Query: "+query);
  8834.  
  8835.             // Exceute the query
  8836.             rs = ps.executeQuery();
  8837.  
  8838.             duplicate = rs.next();
  8839.         }
  8840.         catch(Exception e)
  8841.         {
  8842.             e.printStackTrace();
  8843.             // Throw exception if the parameters not complete.
  8844.              new GOSIBatchException(e,
  8845.                     "BatchCore",
  8846.                     "GOSIBatchUtilities",
  8847.                     "checkDuplicateRecord",
  8848.                     "CMN_001_ERR_1000",
  8849.                     GOSIBatchConstants.SEVERITY_ONE);        
  8850.         }
  8851.         finally
  8852.         {
  8853.             GOSIBatchUtilities.cleanUp(rs, ps, connection);
  8854.         }  
  8855.        
  8856.         // reutn the result.
  8857.         return duplicate;
  8858.     }
  8859.         /**
  8860.      * @METHOD NAME              : sendFileToEndPoint
  8861.      * @INFORMATION              : This method open https connection and send a file to an end point
  8862.      * @PARAM                    : File, string, long
  8863.      * @RETURN                   : void
  8864.      * @EXCEPTION                : class gosi.common.batch.util.GOSIBatchException
  8865.      * @LAST MODIFIED BY         :
  8866.      * @LAST MODIFIED DATE       :
  8867.     **/
  8868.     public static boolean  sendFileToEndPoint(File file,String endPoint,int timeOutInMillseconds)
  8869.     throws GOSIBatchException
  8870.     {
  8871.  
  8872.         HttpsURLConnection conn = null;
  8873.         BufferedReader inStream = null;
  8874.         /*String lineEnd = "\r\n";
  8875.         String twoHyphens = "--";
  8876.         String boundary = "*****";
  8877.         int bytesRead, bytesAvailable, bufferSize;     
  8878.         byte[] buffer;     
  8879.         int maxBufferSize = 1*1024*1024; */
  8880.         String urlString = endPoint;
  8881.         boolean status=false;
  8882.         try
  8883.         {
  8884.             //------------------ CLIENT REQUEST---------------------\\
  8885.            
  8886.        
  8887.             // open a URL connection to the Servlet
  8888.             System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
  8889.             java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
  8890.             URL url = new URL(urlString);
  8891.                
  8892.             // Open HTTP connection to the URL
  8893.             try
  8894.             {
  8895.                  conn.setConnectTimeout(timeOutInMillseconds);
  8896.                  conn.setReadTimeout(timeOutInMillseconds);
  8897.                  conn = (HttpsURLConnection) url.openConnection();
  8898.             }
  8899.             catch(Exception e)
  8900.             {
  8901.                 System.out.println("Exception in connection");
  8902.                 e.printStackTrace();
  8903.             }
  8904.             // setup SSL-configuration
  8905.            
  8906.             // Allow Inputs
  8907.             conn.setDoInput(true);
  8908.            
  8909.             // Allow Outputs
  8910.             conn.setDoOutput(true);
  8911.            
  8912.             // Don't use a cached copy.
  8913.             conn.setUseCaches(false);
  8914.            
  8915.             // Don't ask the user.
  8916.             conn.setAllowUserInteraction(false);
  8917.            
  8918.             // Use a post method.
  8919.             conn.setRequestMethod("POST");
  8920.            
  8921.             conn.setRequestProperty("Connection", "Keep-Alive");
  8922.            
  8923.             //  conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
  8924.             conn.setRequestProperty("Content-Type", "application/octet-stream");
  8925.            
  8926.             //connect
  8927.             conn.connect();
  8928.  
  8929.             DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
  8930.             dumpFile(file, dos);
  8931.            
  8932.            
  8933.             /*dos.writeBytes(twoHyphens + boundary + lineEnd);
  8934.             dos.writeBytes("Content-Disposition: form-data; name=\"upload\";"
  8935.             + " filename=\"" + exsistingFileName +"\"" + lineEnd);
  8936.             dos.writeBytes(lineEnd);
  8937.            
  8938.            
  8939.             // create a buffer of maximum size
  8940.            
  8941.             bytesAvailable = fileInputStream.available();
  8942.             bufferSize = Math.min(bytesAvailable, maxBufferSize);
  8943.             buffer = new byte[bufferSize];
  8944.            
  8945.             // read file and write it into form...
  8946.            
  8947.             bytesRead = fileInputStream.read(buffer, 0, bufferSize);
  8948.            
  8949.             while (bytesRead > 0)
  8950.             {
  8951.                 dos.write(buffer, 0, bufferSize);
  8952.                 bytesAvailable = fileInputStream.available();
  8953.                 bufferSize = Math.min(bytesAvailable, maxBufferSize);
  8954.                 bytesRead = fileInputStream.read(buffer, 0, bufferSize);
  8955.             }
  8956.            
  8957.             // send multipart form data necesssary after file data...
  8958.            
  8959.             dos.writeBytes(lineEnd);
  8960.             dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
  8961.             */
  8962.            
  8963.             // close streams
  8964.             dos.flush();
  8965.             dos.close();
  8966.            
  8967.  
  8968.        
  8969.         }
  8970.         catch (MalformedURLException ex)
  8971.         {
  8972.             System.out.println(" CLIENT REQUEST:"+ex);
  8973.             new GOSIBatchException(ex,
  8974.                     "BatchCore",
  8975.                     "GOSIBatchUtilities",
  8976.                     "sendFileToEndPoint",
  8977.                     "CMN_001_ERR_1000",
  8978.                     GOSIBatchConstants.SEVERITY_ONE);  
  8979.         }
  8980.        
  8981.         catch (IOException ioe)
  8982.         {
  8983.             System.out.println(" CLIENT REQUEST:"+ioe);
  8984.             new GOSIBatchException(ioe,
  8985.                     "BatchCore",
  8986.                     "GOSIBatchUtilities",
  8987.                     "sendFileToEndPoint",
  8988.                     "CMN_001_ERR_1000",
  8989.                     GOSIBatchConstants.SEVERITY_ONE);
  8990.         }
  8991.        
  8992.         catch (Exception e)
  8993.         {
  8994.             System.out.println(" CLIENT REQUEST e:"+e);
  8995.             e.printStackTrace();
  8996.             new GOSIBatchException(e,
  8997.                     "BatchCore",
  8998.                     "GOSIBatchUtilities",
  8999.                     "sendFileToEndPoint",
  9000.                     "CMN_001_ERR_1000",
  9001.                     GOSIBatchConstants.SEVERITY_ONE);
  9002.         }
  9003.  
  9004.         //------------------ read the SERVER RESPONSE -------------------\\
  9005.         try
  9006.         {
  9007.             if(conn.getResponseCode() == HttpsURLConnection.HTTP_OK)
  9008.             {
  9009.                 inStream = new BufferedReader  ( new InputStreamReader(conn.getInputStream()));
  9010.                 System.setProperty("sun.net.client.defaultReadTimeout","30000");
  9011.                 String str;
  9012.                 while (( str = inStream.readLine()) != null)
  9013.                 {
  9014.                     System.out.println("Server response is: "+str);
  9015.                     System.out.println("");
  9016.                 }
  9017.                 if(inStream.readLine()!=null)
  9018.                 {
  9019.                     status=true;
  9020.                 }
  9021.                 inStream.close();
  9022.             }
  9023.             else
  9024.             {
  9025.                 System.out.println("\n\n-----sorry connetion failed-----");
  9026.                 System.out.println("\n\nHTTP Response: " + conn.getResponseCode());
  9027.                
  9028.             }
  9029.                 conn.disconnect();
  9030.         }
  9031.         catch (IOException ioex)
  9032.         {
  9033.             System.out.println("From (ServerResponse): "+ioex);
  9034.             throw new GOSIBatchException(ioex,
  9035.                     "BatchCore",
  9036.                     "GOSIBatchUtilities",
  9037.                     "sendFileToEndPoint",
  9038.                     "CMN_001_ERR_1000",
  9039.                     GOSIBatchConstants.SEVERITY_ONE);
  9040.         }
  9041.         catch (Exception e)
  9042.         {
  9043.             System.out.println("From (ServerResponse): e"+e);
  9044.             e.printStackTrace();   
  9045.             throw new GOSIBatchException(e,
  9046.                     "BatchCore",
  9047.                     "GOSIBatchUtilities",
  9048.                     "sendFileToEndPoint",
  9049.                     "CMN_001_ERR_1000",
  9050.                     GOSIBatchConstants.SEVERITY_ONE);
  9051.         }  
  9052.         return status;
  9053.     }
  9054.     /**
  9055.      * @METHOD NAME              : dumpFile
  9056.      * @INFORMATION              : This method wrtites the file data in  to the given outputstream
  9057.      * @PARAM                    : String,OutputStream
  9058.      * @RETURN                   :
  9059.      * @EXCEPTION                : class gosi.core.util.GOSIException
  9060.      * @LAST MODIFIED BY         :
  9061.      * @LAST MODIFIED DATE       :
  9062.     **/
  9063.         private static void dumpFile(File file, OutputStream outputstream)
  9064.         throws GOSIBatchException
  9065.         {
  9066.             byte abyte0[] = new byte[4096];
  9067.             try
  9068.             {
  9069.                 BufferedInputStream bufferedinputstream = new BufferedInputStream(new FileInputStream(file));
  9070.                 int i;
  9071.                 while((i = bufferedinputstream.read(abyte0, 0, 4096)) != -1)
  9072.                     outputstream.write(abyte0, 0, i);
  9073.                 bufferedinputstream.close();
  9074.             }
  9075.             catch(Exception e)
  9076.             {
  9077.                 e.printStackTrace();
  9078.                 throw new GOSIBatchException(e,
  9079.                         "BatchCore",
  9080.                         "GOSIBatchUtilities",
  9081.                         "dumpFile()",
  9082.                         "CMN_001_ERR_1000",
  9083.                         GOSIBatchConstants.SEVERITY_ONE);
  9084.  
  9085.             }
  9086.         }
  9087.        
  9088. /**
  9089.  * @METHOD NAME              : updateFieldOfficeVillageMap
  9090.  * @INFORMATION              : This methods is used to update column (PROCESSED)
  9091.                                in table T_FIELDOFFICEVILLAGEMAP
  9092.  * @PARAM                    :
  9093.  * @RETURN                   :
  9094.  * @EXCEPTION                : class gosi.core.util.GOSIException
  9095.  * @LAST MODIFIED BY         :
  9096.  * @LAST MODIFIED DATE       :
  9097. **/    
  9098.     public static void updateFieldOfficeVillageMap()
  9099.     throws GOSIBatchException
  9100.     {
  9101.         Connection connection=null;
  9102.         PreparedStatement ps = null;
  9103.         String update = null;
  9104.  
  9105.         try
  9106.         {          
  9107.             update = GOSIBatchSQL.getSqlString("CMN_001_SQL_1074");
  9108.             connection = getDbConnection(GOSIBatchConstants.COMMON);            
  9109.  
  9110.             ps = connection.prepareStatement(update);          
  9111.             ps.executeUpdate();
  9112.             connection.commit();           
  9113.  
  9114.         }catch(Exception e)
  9115.         {                      
  9116.             throw new GOSIBatchException(e,
  9117.             "BatchCore",
  9118.             "GOSIBatchUtilities",
  9119.             "updateFieldOfficeVillageMap()",
  9120.             "CMN_001_ERR_1000",
  9121.             GOSIBatchConstants.SEVERITY_ONE);
  9122.            
  9123.         }
  9124.         finally
  9125.         {
  9126.             GOSIBatchUtilities.cleanUp(ps, connection);
  9127.         }      
  9128.     }
  9129. }
Add Comment
Please, Sign In to add comment