Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gosi.common.batch.util;
- import java.util.Hashtable;
- import java.io.FileInputStream;
- import javax.naming.Context;
- import javax.naming.directory.DirContext;
- import javax.naming.directory.BasicAttribute;
- import javax.naming.directory.ModificationItem;
- import javax.naming.ldap.InitialLdapContext;
- import java.util.ArrayList;
- import java.util.List;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.PreparedStatement;
- import java.sql.DriverManager;
- import java.math.BigDecimal;
- import gosi.common.batch.util.beans.BatchError;
- import gosi.common.batch.util.beans.BatchMaster;
- import gosi.common.batch.util.beans.BatchParam;
- import gosi.common.batch.util.beans.BatchRestart;
- import gosi.common.batch.util.beans.BatchOnlineDependentTaskBean;
- import javax.crypto.*;
- import java.io.*;
- import javax.crypto.spec.*;
- import java.lang.reflect.Constructor;
- import java.util.HashMap;
- import java.io.File;
- import java.io.FileReader;
- import java.io.BufferedReader;
- import java.util.StringTokenizer;
- import java.util.GregorianCalendar;
- import java.util.Calendar;
- import java.io.IOException;
- import java.sql.Timestamp;
- import java.sql.SQLException;
- import java.sql.Types;
- import gosi.common.batch.util.GOSIBatchException;
- import gosi.common.batch.workflow.beans.BatchRangeCheckBean;
- import gosi.common.batch.workflow.beans.BatchTransactionEntityMap;
- import gosi.common.batch.workflow.beans.BatchWorkflowParamBean;
- import gosi.common.batch.util.beans.DomainBean;
- import javax.naming.directory.Attributes;
- import javax.naming.directory.BasicAttributes;
- import javax.naming.directory.Attribute;
- import javax.naming.directory.InitialDirContext;
- import java.util.Properties;
- import java.beans.XMLEncoder;
- import java.beans.XMLDecoder;
- import gosi.common.batch.util.beans.CorporateContactBean;
- import gosi.common.batch.util.beans.IndividualContactBean;
- import gosi.common.batch.util.beans.FieldOfficeVillageMapListBean;
- /*Start : To place a request for a batch through a batch*/
- import gosi.common.batch.util.beans.BatchRequestBean;
- import gosi.common.batch.util.beans.BatchParametersBean;
- /*End : To place a request for a batch through a batch*/
- // Import for checking the workflowtxn duplicate records.
- import gosi.common.batch.workflow.history.beans.WorkflowTxn;
- // Import for sending a file over Https connection
- import weblogic.net.http.HttpsURLConnection;
- import java.net.MalformedURLException;
- import java.net.URL;
- //import java.net.*;
- //import java.security.KeyStore;
- //import javax.net.*;
- //import javax.net.ssl.*;
- //import java.security.cert.*;
- /**
- * @CLASS NAME : GOSIBatchUtilities
- * @TYPE :
- * @AUTHOR :TCS
- * @VERSION : 1
- * @EXTENDS :
- * @INFORMATION : This class provides interface functionality for other modules and
- basic frame work methods for the batch
- * @IMPLEMENTS :
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- */
- public class GOSIBatchUtilities
- {
- // Declaring the class level variable
- private static Connection connectionForPk=null;
- private static PreparedStatement psRead=null;
- private static PreparedStatement psUpdate=null;
- private static PreparedStatement psRestartKeyUpdate = null;
- private static PreparedStatement psUserLocation = null;
- private static ArrayList currencyList = null;
- private static Timestamp currentSystemDate = null;
- /**
- * @METHOD NAME : getResource
- * @INFORMATION : This method gets the common of CMN_USR for getting the primary keys
- * @PARAM :
- * @RETURN :
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static void getResource()
- throws GOSIBatchException
- {
- try
- {
- connectionForPk=getDbConnection(GOSIBatchConstants.COMMON);
- }
- catch(GOSIBatchException e)
- {
- throw e;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getResource",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : getPrimaryKeys
- * @INFORMATION : This method returns primary key value and the logic same as online
- component and this is the private method
- * @PARAM : tableName, noOfIds, lastModifiedBy
- * @RETURN : class java.lang.Long[]
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static Long[] getPrimaryKeys(String tableName,
- int noOfIds, long lastModifiedBy)
- throws GOSIBatchException
- {
- Long[] pkList=new Long[noOfIds];
- ResultSet rsRead=null;
- long currnetId=0L;
- long endValue=0L;
- try
- {
- if(connectionForPk==null)
- {
- getResource();
- }
- String sequenceName ="";
- if("T_".equals(tableName.substring(0, 2)))
- {
- sequenceName = "S"+tableName.substring(1, tableName.length());
- }
- else
- {
- sequenceName =tableName;
- }
- //System.out.println("Sequence Numbe : "+sequenceName);
- String sequencequery ="SELECT "+sequenceName+".NEXTVAL FROM "+
- " DUAL ";
- psRead = connectionForPk.prepareStatement(sequencequery);
- for(int count=0;count<noOfIds;count++)
- {
- rsRead = psRead.executeQuery();
- if(rsRead.next())
- {
- pkList[count]=new Long(rsRead.getLong(1));
- }
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getPrimaryKeys",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rsRead);
- GOSIBatchUtilities.cleanUp(psRead);
- }
- return pkList;
- }
- /**
- * @METHOD NAME : getPrimaryKey
- * @INFORMATION : For getting a single primary key for given table name and the logic is same as online component
- * @PARAM : tableName, lastModifiedBy
- * @RETURN : class java.lang.Long
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public synchronized static Long getPrimaryKey(String tableName,
- long lastModifiedBy) throws GOSIBatchException
- {
- Long primaryKey=null;
- try
- {
- Long[] pysList=getPrimaryKeys(tableName,
- 1, lastModifiedBy);
- primaryKey=pysList[0];
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- return primaryKey;
- }
- /**
- * @METHOD NAME : getPrimaryKeyList
- * @INFORMATION : FOr getting the multiple no of keys
- * @PARAM : tableName,noOfIds,lastModifiedBy
- * @RETURN : Long[]
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public synchronized static Long[] getPrimaryKeyList(String tableName,
- int noOfIds, long lastModifiedBy)
- throws GOSIBatchException
- {
- Long[] pysList=null;
- try
- {
- pysList=getPrimaryKeys(tableName, noOfIds, lastModifiedBy);
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- return pysList;
- }
- // Declaring public variables which are required at class level
- // Batch Master bean to cache the data related to the current running batch
- public static BatchMaster currentBatchMaster=null;
- // User to store the current date
- public static Timestamp currentDate=null;
- // declaring prepare statment which are required at class level
- public static PreparedStatement psInsert=null;
- public static PreparedStatement psDeleteError=null;
- public static PreparedStatement psLogRestart=null;
- public static PreparedStatement psInsertWorkflow=null;
- public static PreparedStatement psInsertRangeCheck=null;
- public static PreparedStatement psInsertTXNMap=null;
- public static PreparedStatement psEmployeeNumber=null;
- /*Start : To place a request for a batch through a batch*/
- public static PreparedStatement psInsertBatchRequest=null;
- public static PreparedStatement psInsertParamValues=null;
- public static PreparedStatement psCheckIsHoliday = null;
- public static PreparedStatement psFinalDate = null;
- public static PreparedStatement psNoOfHolidays =null;
- public static PreparedStatement psWeekEnds = null;
- public static PreparedStatement psOtherHolidays = null;
- public static PreparedStatement psTotalDiff = null;
- public static PreparedStatement psNextWorkingDay = null;
- /*End : To place a request for a batch through a batch*/
- // Constructor of the GOSIBatchUtilities which is called by the BatchDriver
- public GOSIBatchUtilities(String batchId)
- throws GOSIBatchException
- {
- // Calls this method which loads the BatchMaster bean with the data related to the batch id passed
- getBatchMaster(batchId);
- }
- /**
- * @METHOD NAME : getProcessor
- * @INFORMATION : This method return the processor for
- given batch id and the flag
- * @PARAM : batchId, flag
- * @RETURN : BatchProcessController
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static BatchProcessController getProcessor
- (String batchId, byte flag)
- throws GOSIBatchException,Exception
- {
- BatchProcessController batchProcessController=null;
- try
- {
- String processorname =
- currentBatchMaster.getProcessorName();
- Constructor myClassConstructor = null;
- Class[] paramTypes = new Class[1];
- paramTypes[0] = byte.class;
- Class myClass = Class.forName(processorname);
- try
- {
- // This is trying to the the processer constructor which has only the flag as parameter
- // I am not sure what is the case for it
- myClassConstructor =
- myClass.getConstructor(paramTypes);
- Object[] params = new Object[1];
- params[0] = new Byte(flag);
- batchProcessController =
- (BatchProcessController)
- myClassConstructor.newInstance(params);
- }
- catch(NoSuchMethodException nme)
- {
- // This is teh normal processer constructur which take the batch id and the flag
- paramTypes = new Class[2];
- paramTypes[0]=String.class;
- paramTypes[1] = byte.class;
- myClassConstructor =
- myClass.getConstructor(paramTypes);
- Object[] params = new Object[2];
- params[0] = new String(batchId);
- params[1] = new Byte(flag);
- batchProcessController=(BatchProcessController)
- myClassConstructor.newInstance(params);
- }
- }catch(Exception e)
- {
- throw e;
- }
- return batchProcessController;
- }
- /**
- * @METHOD NAME : getProcessor
- * @INFORMATION : Returns the processor for batchId and the HashMap which holds the flags for each frequency
- This is also same as above
- * @PARAM : batchId, hashMap
- * @RETURN : BatchProcessController
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static BatchProcessController getProcessor
- (String batchId, HashMap hashMap)
- throws GOSIBatchException,Exception
- {
- BatchProcessController batchProcessController=null;
- try
- {
- String processorname =
- currentBatchMaster.getProcessorName();
- Constructor myClassConstructor = null;
- Class[] paramTypes = new Class[1];
- paramTypes[0] = HashMap.class;
- Class myClass = Class.forName(processorname);
- try
- {
- myClassConstructor =
- myClass.getConstructor(paramTypes);
- Object[] params = new Object[1];
- params[0] = hashMap;
- batchProcessController =
- (BatchProcessController)
- myClassConstructor.newInstance(params);
- }
- catch(NoSuchMethodException nme)
- {
- paramTypes = new Class[2];
- paramTypes[0]=String.class;
- paramTypes[1] = HashMap.class;
- myClassConstructor =
- myClass.getConstructor(paramTypes);
- Object[] params = new Object[2];
- params[0] = new String(batchId);
- params[1] = hashMap;
- batchProcessController=(BatchProcessController)
- myClassConstructor.newInstance(params);
- }
- }catch(Exception e)
- {
- throw e;
- }
- return batchProcessController;
- }
- /**
- * @METHOD NAME : cleanUp
- * @INFORMATION : THis method cleans up the resources passing
- such as resultSet,preparedstatement, connection
- * @PARAM : rs, statement, connection
- * @RETURN :
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void cleanUp(ResultSet rs,
- PreparedStatement statement,
- Connection connection)
- {
- try
- {
- if(rs!=null)
- {
- rs.close();
- }
- if(statement!=null)
- {
- statement.close();
- }
- if (connection!=null)
- {
- if (!connection.isClosed())
- {
- connection.close();
- }
- }
- }
- catch(Exception e)
- {
- }
- }
- /**
- * @METHOD NAME : cleanUp
- * @INFORMATION : THis method cleans up the resources passing
- such as resultSet,preparedstatement, connection
- * @PARAM : statement, connection
- * @RETURN :
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void cleanUp(PreparedStatement statement
- ,Connection connection)
- {
- try
- {
- if(statement!=null)
- {
- statement.close();
- }
- if (connection!=null)
- {
- if (!connection.isClosed())
- {
- connection.close();
- }
- }
- }
- catch(Exception e)
- {
- }
- }
- /**
- * @METHOD NAME : cleanUp
- * @INFORMATION : THis method cleans up the resources passing
- such as resultSet,preparedstatement, connection
- * @PARAM : connection
- * @RETURN :
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void cleanUp(Connection connection)
- {
- try
- {
- if (connection!=null)
- {
- if (!connection.isClosed())
- {
- connection.close();
- }
- }
- }
- catch(Exception e)
- {
- }
- }
- /**
- * @METHOD NAME : cleanUp
- * @INFORMATION : THis method cleans up the resources passing
- such as resultSet,preparedstatement, connection
- * @PARAM : statement
- * @RETURN :
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void cleanUp(PreparedStatement statement)
- {
- try
- {
- if(statement!=null)
- {
- statement.close();
- }
- }
- catch(Exception e)
- {
- }
- }
- /**
- * @METHOD NAME : cleanUp
- * @INFORMATION : THis method cleans up the resources passing
- such as resultSet,preparedstatement, connection
- * @PARAM : rs
- * @RETURN :
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void cleanUp(ResultSet rs)
- {
- try
- {
- if(rs!=null)
- {
- rs.close();
- }
- }
- catch(Exception e)
- {
- }
- }
- /**
- * @METHOD NAME : getDbConnection
- * @INFORMATION : This method returns the connections for given
- module Short name. creates connection for specific module
- database. And it puts the AutoCommit as null in the created connection.
- * @PARAM : moduleName
- * @RETURN : class java.sql.Connection
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static Connection getDbConnection(String moduleName)
- throws GOSIBatchException
- {
- Connection connection=null;
- try
- {
- String userId=null;
- String password=null;
- if((GOSIBatchConstants.COMMON).equals(moduleName))
- {
- userId=GOSIBatchProperties.COMMON_DB_USER_ID;
- password=GOSIBatchProperties.COMMON_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.REGISTRATION).equals(moduleName))
- {
- userId=GOSIBatchProperties.REGISTRATION_DB_USER_ID;
- password=GOSIBatchProperties.REGISTRATION_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.CONTRIBUTION).equals(moduleName))
- {
- userId=GOSIBatchProperties.CONTRIBUTION_DB_USER_ID;
- password=GOSIBatchProperties.CONTRIBUTION_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.OCCUPATIONAL_HAZARDS).equals(moduleName))
- {
- userId=GOSIBatchProperties.OCCUPATIONAL_HAZARDS_DB_USER_ID;
- password=GOSIBatchProperties.
- OCCUPATIONAL_HAZARDS_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.ANNUITIES).equals(moduleName))
- {
- userId=GOSIBatchProperties.ANNUITIES_DB_USER_ID;
- password=GOSIBatchProperties.ANNUITIES_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.FINANCE).equals(moduleName))
- {
- userId=GOSIBatchProperties.FINANCE_DB_USER_ID;
- password=GOSIBatchProperties.FINANCE_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.BUDGET).equals(moduleName))
- {
- userId=GOSIBatchProperties.BUDGET_DB_USER_ID;
- password=GOSIBatchProperties.BUDGET_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.INVESTMENT).equals(moduleName))
- {
- userId=GOSIBatchProperties.INVESTMENT_DB_USER_ID;
- password=GOSIBatchProperties.INVESTMENT_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.FIXED_ASSET).equals(moduleName))
- {
- userId=GOSIBatchProperties.FIXED_ASSET_DB_USER_ID;
- password=GOSIBatchProperties.FIXED_ASSET_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.INVENTORY).equals(moduleName))
- {
- userId=GOSIBatchProperties.INVENTORY_DB_USER_ID;
- password=GOSIBatchProperties.INVENTORY_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.PURCHASE).equals(moduleName))
- {
- userId=GOSIBatchProperties.PURCHASE_DB_USER_ID;
- password=GOSIBatchProperties.PURCHASE_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.CONTRACT).equals(moduleName))
- {
- userId=GOSIBatchProperties.CONTRACT_DB_USER_ID;
- password=GOSIBatchProperties.CONTRACT_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.REAL_ESTATE).equals(moduleName))
- {
- userId=GOSIBatchProperties.REAL_ESTATE_DB_USER_ID;
- password=GOSIBatchProperties.REAL_ESTATE_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.PERSONNEL).equals(moduleName))
- {
- userId=GOSIBatchProperties.PERSONNEL_DB_USER_ID;
- password=GOSIBatchProperties.PERSONNEL_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.PROJECT).equals(moduleName))
- {
- userId=GOSIBatchProperties.PROJECT_DB_USER_ID;
- password=GOSIBatchProperties.PROJECT_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.DATAWAREHOUSING).equals(moduleName))
- {
- userId=GOSIBatchProperties.DATAWAREHOUSING_DB_USER_ID;
- //System.out.println("USERID : "+userId);
- password=GOSIBatchProperties.DATAWAREHOUSING_DB_PASSWORD;
- //System.out.println("Password : "+password);
- }
- else if((GOSIBatchConstants.COMMON_FUT).equals(moduleName))
- {
- userId=GOSIBatchProperties.COMMON_FUT_DB_USER_ID;
- password=GOSIBatchProperties.COMMON_FUT_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.INTERNET).equals(moduleName))
- {
- userId=GOSIBatchProperties.INTERNET_DB_USER_ID;
- password=GOSIBatchProperties.INTERNET_DB_PASSWORD;
- }
- else if((GOSIBatchConstants.RPA).equals(moduleName))
- {
- userId=GOSIBatchProperties.RPA_DB_USER_ID;
- password=GOSIBatchProperties.RPA_DB_PASSWORD;
- }
- else
- {
- new GOSIBatchException(null,
- "BatchCore",
- "GOSIBatchUtilities",
- "getConnection",
- "CMN_001_ERR_1001",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- String databaseURL = GOSIBatchProperties.DATABASE_URL;
- Class.forName(GOSIBatchProperties.DRIVER_CLASS);
- connection=
- DriverManager.getConnection (databaseURL,
- userId, password);
- connection.setAutoCommit(false);
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getConnection",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return connection;
- }
- /**
- * @METHOD NAME : getNoOfRequest
- * @INFORMATION : This method gets the no of request on the given day for the passed batchid.
- This method is called when the batch type is adhoc or is the batch type is normal and requires parameter
- * @PARAM : batchId, connection, batchType
- * @RETURN : int
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static int getNoOfRequest(String batchId,Connection connection,
- byte batchType)
- throws GOSIBatchException
- {
- int noOfRequest=0;
- PreparedStatement ps=null;
- ResultSet rs=null;
- try
- {
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1018");
- //System.out.println("No of request query : "+query);
- //System.out.println("System Date : "+getSystemDate());
- ps=connection.prepareStatement(query);
- ps.setString(1,batchId);
- ps.setTimestamp(2,getSystemDate());
- rs=ps.executeQuery();
- if(rs.next())
- {
- noOfRequest=rs.getInt(1);
- }
- else
- {
- //System.out.println("there are nor requests");
- }
- // Checking the no of request
- if(noOfRequest==0)
- {
- // If the batch job is Scheduled job and no request means throwing exception with CMN_001_ERR_1009
- if(batchType==GOSIBatchConstants.NORMAL_JOB)
- {
- new GOSIBatchException(null,
- "BatchCore",
- "GOSIBatchUtilities",
- "getRequest",
- "CMN_001_ERR_1009",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- // If the batch job is Adhoc job and no request means throwing exception with CMN_001_ERR_1065
- // 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
- else
- {
- new GOSIBatchException(null,
- "BatchCore",
- "GOSIBatchUtilities",
- "getRequest",
- "CMN_001_ERR_1065",
- GOSIBatchConstants.SEVERITY_TWO);
- }
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getRequest",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs);
- GOSIBatchUtilities.cleanUp(ps);
- }
- return noOfRequest;
- }
- /**
- * @METHOD NAME : getBatchMaster
- * @INFORMATION : This method gets the batch master values for given batch id and populates in the
- batchMaster class variable.
- This method does the following things.
- 1. Gets the data from T_BATCHMASTER for the given batch id
- 2. Gets the System user id
- 3. Gets the System role id
- 4. If the batch is adjoc or the no of parameter or >0 calls getNoOfRequest to get the no of requsts
- As seen above in the getNoOfRequest if the request is not found exception is thrown
- 5. Populating all the values in the BatchMaster depending on the job type and no of parameters
- * @PARAM : batchId
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void getBatchMaster(String batchId)
- throws GOSIBatchException
- {
- Connection connection=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- PreparedStatement psUser=null;
- ResultSet rsUser=null;
- PreparedStatement psRole=null;
- ResultSet rsRole=null;
- boolean invoke=false;
- try
- {
- // Executing query for getting the data from T_BATCHMASTER
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1001");
- connection=GOSIBatchUtilities.
- getDbConnection(GOSIBatchConstants.COMMON);
- ps=connection.prepareStatement(query);
- ps.setString(1,batchId);
- rs=ps.executeQuery();
- // Executing query for getting the system user id
- query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1021");
- psUser=connection.prepareStatement(query);
- psUser.setString(1,GOSIBatchProperties.SYSTEM_USER+"%");
- rsUser=psUser.executeQuery();
- long userCode=0L;
- long roleId=0L;
- //this if is no longer used
- if(rsUser.next())
- {
- userCode=rsUser.getLong("ID");
- }
- else
- {
- new GOSIBatchException(null,
- "BatchCore",
- "GOSIBatchUtilities",
- "getBatchMaster",
- "CMN_001_ERR_1006",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- // Executing query for getting the system role id
- query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1034");
- psRole=connection.prepareStatement(query);
- psRole.setString(1,GOSIBatchProperties.SYSTEM_ROLE+"%");
- rsRole=psRole.executeQuery();
- if(rsRole.next())
- {
- roleId=rsRole.getLong("ROLEID");
- }
- else
- {
- new GOSIBatchException(null,
- "BatchCore",
- "GOSIBatchUtilities",
- "getBatchMaster",
- "CMN_001_ERR_1006",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- // Taking the record from the query of T_BATCHMASTER
- if(rs.next())
- {
- // If the job is adhoc or have no of parameters more than 1 then calling getNoOfRequest to get the no of requests
- if((rs.getByte("BATCHTYPE")==GOSIBatchConstants.ADHOC_JOB)||
- (rs.getShort("NUMOFPARAMS")>0))
- {
- int noOfRequest = getNoOfRequest(batchId,connection,rs.getByte("BATCHTYPE"));
- // If batch is Adhoc or no of parameters or more than 1 then populating the batch details in
- // currentBatchMaster inclding the no of requests
- currentBatchMaster =
- new BatchMaster(rs.getString("BATCHID"),
- rs.getString("BATCHDESCRIPTION"),
- rs.getShort("NUMOFPARAMS"),
- rs.getShort("COMMITFREQUENCY"),
- rs.getString("PROCESSORNAME"),
- rs.getLong("ID"),
- roleId,rs.getByte("BATCHTYPE"),
- noOfRequest,rs.getByte("BUSINESSERRORFLAG"),
- rs.getString("BATCHRUNFREQUENCY"));
- }
- else
- {
- // If batch is normal and not having any parametrs then populating the batch details in
- // currentBatchMaster with out no of parameters
- currentBatchMaster=
- new BatchMaster(rs.getString("BATCHID"),
- rs.getString("BATCHDESCRIPTION"),
- rs.getShort("NUMOFPARAMS"),
- rs.getShort("COMMITFREQUENCY"),
- rs.getString("PROCESSORNAME"),
- rs.getLong("ID"),roleId,
- rs.getByte("BATCHTYPE"),
- 0,rs.getByte("BUSINESSERRORFLAG"),
- rs.getString("BATCHRUNFREQUENCY"));
- }
- }
- // If batch id T_BATCHMASTER is not found then throwing exception
- else
- {
- new GOSIBatchException(null,
- "BatchCore",
- "GOSIBatchUtilities",
- "getBatchMaster",
- "CMN_001_ERR_1002",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "Constructor",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs, ps, connection);
- GOSIBatchUtilities.cleanUp(rsUser);
- GOSIBatchUtilities.cleanUp(psUser);
- }
- return;
- }
- /**
- * @METHOD NAME : loadCurrencyDetails
- * @INFORMATION : This is for loading the currency details
- * @PARAM : void
- * @RETURN : void
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void loadCurrencyDetails()
- throws GOSIBatchException
- {
- currencyList = new ArrayList();
- PreparedStatement psForCurrency=null;
- ResultSet rsForCurrency=null;
- Connection connectionForFA=null;
- try
- {
- String query=GOSIBatchSQL.getSqlString("INT_FIN_SQL_4025");
- connectionForFA=
- getDbConnection(GOSIBatchConstants.FINANCE);
- psForCurrency=connectionForFA.prepareStatement(query);
- rsForCurrency = psForCurrency.executeQuery();
- currencyList=new ArrayList();
- while(rsForCurrency.next())
- {
- HashMap currencyDetails=new HashMap();
- currencyDetails.put("code", new Integer(
- rsForCurrency.getInt("CURRENCYCODE")));
- currencyDetails.put("nameEnglish", new String(
- rsForCurrency.getString("CURRENCYNAMEENGLISH")));
- currencyDetails.put("nameArabic", new String(
- rsForCurrency.getString("CURRENCYNAMEARABIC")));
- currencyDetails.put("country", new String(
- rsForCurrency.getString("COUNTRY")));
- currencyDetails.put("type", new Integer(
- rsForCurrency.getInt("CURRENCYTYPE")));
- currencyDetails.put("symbol", new String(
- rsForCurrency.getString("SYMBOL")));
- currencyDetails.put("precision", new Integer(
- rsForCurrency.getInt("POSITIONAFTERDECIMAL")));
- currencyList.add(currencyDetails);
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "loadCurrencyDetails",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rsForCurrency);
- GOSIBatchUtilities.cleanUp(psForCurrency,connectionForFA);
- }
- }
- /**
- * @METHOD NAME : round
- * @INFORMATION :This method returns a String which is
- * rounded to the given precision(scale).
- * Usual rounding convention is used.
- * NumberFormat.round(12345.234, 2)
- * will return the value 12345.12
- * @PARAM : amount, scale
- * @RETURN : String
- * @EXCEPTION : class gosi.core.util.GOSIException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static String round(double amount, int scale)
- throws GOSIBatchException
- {
- String formatedData="";
- try
- {
- String amountStr=""+amount;
- int index=amountStr.indexOf(".");
- int amountlength=amountStr.length();
- int scaleLength=amountlength-(index+1);
- String decimalData=amountStr.substring(index+1);
- String scalePointData=null;
- if(scaleLength>scale)
- {
- scalePointData=decimalData.substring(scale);
- if("5".equals(scalePointData))
- {
- amountStr=amountStr+1;
- }
- }
- formatedData=new BigDecimal(amountStr).setScale(scale, BigDecimal.
- ROUND_HALF_UP).toString();
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "round()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return formatedData;
- }
- /**
- * @METHOD NAME : roundToPrecision
- * @INFORMATION : This method returns a String type which is
- * rounded for the given Currency Code.
- * This inturn calls the round method
- * @PARAM : amount, code
- * @RETURN : String
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static Double roundToPrecision(double amount,int code)
- throws GOSIBatchException
- {
- String rndAmount=null;
- Double retAmount=null;
- int prec=0;
- try
- {
- if(currencyList!=null)
- {
- int currSize=currencyList.size();
- for(int i=0; i<currSize;i++)
- {
- HashMap curDet=(HashMap)currencyList.get(i);
- int curCode=Integer.parseInt(""+curDet.get("code"));
- if (curCode==code)
- {
- prec=Integer.parseInt(""+curDet.get("precision"));
- //rndAmount=new BigDecimal(amount).setScale
- //(prec,BigDecimal.ROUND_HALF_UP).toString();
- rndAmount=round(amount, prec);
- retAmount=new Double(rndAmount);
- break;
- }
- }
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "roundToPrecision",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return retAmount;
- }
- /**
- * @METHOD NAME : getBatchRestart
- * @INFORMATION : This method reads the data from the T_BATCHRESTARTKEYS for the given batch id
- Populates in the BatchRestart object and returns it
- * @PARAM : batchId
- * @RETURN : BatchRestart
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static BatchRestart getBatchRestart
- (String batchId)throws GOSIBatchException
- {
- BatchRestart batchRestart=null;
- Connection connection=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- try
- {
- // Exceuting the query for getting the details
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1002");
- connection=GOSIBatchUtilities.
- getDbConnection(GOSIBatchConstants.COMMON);
- ps=connection.prepareStatement(query);
- ps.setString(1, batchId);
- rs=ps.executeQuery();
- if(rs.next())
- {
- batchRestart=new BatchRestart();
- batchRestart.setRestartKeys(rs.getString("RESTARTKEY"));
- batchRestart.setLastRunStatus(rs.getString("CURRENTSTATUS"));
- batchRestart.setLastRunDate(rs.getTimestamp("LASTRUNDATE"));
- batchRestart.setRequestNo(rs.getLong("REQUESTID"));
- batchRestart.setSuccessDate(rs.getTimestamp("SUCCESSDATE"));
- }
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getBatchRestart",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs, ps, connection);
- }
- return batchRestart;
- }
- /**
- * @METHOD NAME : completeProcess
- * @INFORMATION : This method called to complete the process
- This method updates the status of T_BATCHMASTER depending on the sucess or failure
- * @PARAM : batchId, flag
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void completeProcess
- (String batchId,String flag)throws GOSIBatchException
- {
- Connection connection=null;
- PreparedStatement ps=null;
- try
- {
- connection=GOSIBatchUtilities.
- getDbConnection(GOSIBatchConstants.COMMON);
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1019");
- ps=connection.prepareStatement(query);
- ps.setString(1, flag);
- ps.setString(2, batchId);
- int result=ps.executeUpdate();
- connection.commit();
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "updateRunInstance",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(ps,connection);
- }
- }
- /**
- * @METHOD NAME : getBatchError
- * @INFORMATION : This method is called by the BathProcessController to
- get the list of the batch errors in the previous run
- * @PARAM : batchId
- * @RETURN : ArrayList
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static ArrayList getBatchError(String batchId)
- throws GOSIBatchException
- {
- ArrayList errorRecordsList=new ArrayList();
- Connection connection=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- try
- {
- //Executing the query to get the list of errors which are of severity 2
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1003");
- connection=GOSIBatchUtilities.
- getDbConnection(GOSIBatchConstants.COMMON);
- ps=connection.prepareStatement(query);
- ps.setString(1, batchId);
- ps.setString(2, GOSIBatchConstants.TO_BE_PROCESSED);
- ps.setInt(3,GOSIBatchConstants.SEVERITY_TWO);
- rs=ps.executeQuery();
- BatchError batchError=null;
- while(rs.next())
- {
- if(errorRecordsList==null)
- {
- errorRecordsList=new ArrayList();
- }
- batchError=new BatchError();
- batchError.setRecordIdentifiers(rs.getString("RECORDIDENTIFIERS"));
- batchError.setStatus(GOSIBatchConstants.TO_BE_PROCESSED);
- batchError.setErrorDate(rs.getTimestamp("ERRORDATE"));
- batchError.setRequestNo(rs.getLong("REQUESTID"));
- batchError.setLoopCount(rs.getByte("LOOPCOUNT"));
- errorRecordsList.add(batchError);
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getBatchEror",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs, ps, connection);
- }
- return errorRecordsList;
- }
- /**
- * @METHOD NAME : updateRunInstance
- * @INFORMATION : This method updates the running instance of the batch
- is as in progress jux before the batch is started.
- This method is called by the BatchDriver jux before calling the individual
- batch controller
- * @PARAM : batchId
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void updateRunInstance(String batchId)
- throws GOSIBatchException
- {
- Connection connection=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- try
- {
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1004");
- connection=GOSIBatchUtilities.
- getDbConnection(GOSIBatchConstants.COMMON);
- ps=connection.prepareStatement(query);
- ps.setTimestamp(1,getSystemDate());
- ps.setString(2, GOSIBatchConstants.BATCH_IN_PROGRESS);
- ps.setString(3, batchId);
- int result=ps.executeUpdate();
- connection.commit();
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "updateRunInstance",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs, ps, connection);
- }
- }
- /**
- * @METHOD NAME : commitRecords
- * @INFORMATION : This method commits all batch frame
- * work data base operation and as well as logs the error records and updates the restart keys
- This method is called when the batch is running for all the records
- * @PARAM : batchErrorList, batchRestart, batchMaster,
- connection
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void commitRecords(ArrayList batchErrorList,
- BatchRestart batchRestart
- ,BatchMaster batchMaster,
- Connection connection)
- throws GOSIBatchException
- {
- try
- {
- // Executing the workflow insertions
- psInsertWorkflow.executeBatch();
- psInsertRangeCheck.executeBatch();
- psInsertTXNMap.executeBatch();
- // Executing the Batch run requests
- /*Start : To place a request for a batch through a batch*/
- psInsertBatchRequest.executeBatch();
- psInsertParamValues.executeBatch();
- /*End : To place a request for a batch through a batch*/
- // Calling logErrors to log error records if error list is not null
- if(batchErrorList!=null)
- {
- logErrors(batchMaster,batchErrorList,connection);
- }
- // Calling logRestartKeys is the restart key bean is not null
- if(batchRestart!=null)
- {
- logRestartKeys(batchMaster,batchRestart,connection);
- }
- connection.commit();
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "commitRecords",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : commitRecords
- * @INFORMATION : This method commits all batch frame
- * work data base operation and as well as logs the error records
- This method is called when the batch is running for only errorrecords
- * @PARAM : batchErrorList, batchMaster, connection
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void commitRecords(ArrayList batchErrorList,
- BatchMaster batchMaster,
- Connection connection)
- throws GOSIBatchException
- {
- try
- {
- if(batchErrorList!=null)
- {
- // Calling logErrors to log the errors
- logErrors(batchMaster,batchErrorList,connection);
- // Executing the workflow prepare statments
- psInsertWorkflow.executeBatch();
- psInsertRangeCheck.executeBatch();
- psInsertTXNMap.executeBatch();
- /*Start : To place a request for a batch through a batch*/
- // Executing the batch request prepare statments
- psInsertBatchRequest.executeBatch();
- psInsertParamValues.executeBatch();
- /*End : To place a request for a batch through a batch*/
- }
- connection.commit();
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "commitRecords",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : deleteProcessedErrors
- * @INFORMATION : This method deletes the processed error records
- * @PARAM : batchMaster, batchError
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void deleteProcessedErrors(BatchMaster batchMaster,
- BatchError batchError)
- throws GOSIBatchException
- {
- try
- {
- psDeleteError.setString(1,batchMaster.getBatchId());
- psDeleteError.setString(2,batchError.getRecordIdentifiers());
- int result=psDeleteError.executeUpdate();
- batchError.setStatus(GOSIBatchConstants.TO_BE_PROCESSED);
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "deleteProcessedRecords",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : logErrors
- * @INFORMATION : This method logs the error occured in batch
- Deletes the processed error records
- Inserts the Error records occured in this run
- * @PARAM : batchMaster, batchErrorList, connectoin
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static void logErrors(BatchMaster batchMaster,
- ArrayList batchErrorList,
- Connection connection)
- throws GOSIBatchException
- {
- try
- {
- BatchError batchError=null;
- // Going in loop for the list of error records
- for(int i=0;i<batchErrorList.size();i++)
- {
- // If the status is delete calling deleteProcessedErrors
- batchError=(BatchError)batchErrorList.get(i);
- if(GOSIBatchConstants.DELETE_PROCESSED_ERROR_RECORD.
- equals(batchError.getStatus()))
- {
- // Calling deleteProcessedErrors to delete
- deleteProcessedErrors(batchMaster,
- batchError);
- // Setting the status as not to be processed as this is already finished deletion
- batchError.setStatus(GOSIBatchConstants.NOT_TO_BE_PROCESSED);
- }
- // If the status is insert calling insertErrors
- else if(GOSIBatchConstants.INSERT_ERROR_RECORD.
- equals(batchError.getStatus()))
- {
- // Calling insert to create the error record
- insertErrors(batchMaster,
- batchError);
- // Setting the status as not to be processed as this is already finished deletion
- batchError.setStatus(GOSIBatchConstants.TO_BE_PROCESSED);
- }
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "logErrors",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : insertErrors
- * @INFORMATION : This method inserts the error records in
- batch erroneous records
- * @PARAM : batchMaster, batchError
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void insertErrors(BatchMaster batchMaster,
- BatchError batchError)
- throws GOSIBatchException
- {
- try
- {
- psInsert.setString(1, batchMaster.getBatchId());
- psInsert.setString(2, batchError.getRecordIdentifiers());
- psInsert.setString(3, batchError.getErrorCode());
- psInsert.setString(4, GOSIBatchConstants.TO_BE_PROCESSED);
- psInsert.setInt(5, batchError.getLoopCount());
- if(batchError.getRequestNo()!=0)
- {
- psInsert.setLong(6, batchError.getRequestNo());
- }
- else
- {
- psInsert.setNull(6,java.sql.Types.NUMERIC);
- }
- psInsert.setTimestamp(7, new Timestamp(System.currentTimeMillis()));
- int result=psInsert.executeUpdate();
- batchError.setStatus(GOSIBatchConstants.TO_BE_PROCESSED);
- }
- catch(Exception e)
- {
- e.printStackTrace();
- //System.out.println(e.toString());
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "logErrors",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : logRestartKeys
- * @INFORMATION : This method updates the batch restart key value for each commit with the last processed record
- * @PARAM : batchMaster, batchRestart, connection
- * @RETURN : void
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void logRestartKeys(BatchMaster batchMaster,
- BatchRestart batchRestart,
- Connection connection)
- throws GOSIBatchException
- {
- try
- {
- psLogRestart.setString(1, batchRestart.getRestartKeys());
- psLogRestart.setLong(2, batchMaster.getNoOfRecordsProcessed());
- psLogRestart.setLong(3, batchRestart.getRequestNo());
- psLogRestart.setString(4, batchMaster.getBatchId());
- int result=psLogRestart.executeUpdate();
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "logRestartKeys",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : updateRestartKeys
- * @INFORMATION : This method updates batch restart keys to null when the batch is successfully completed.
- This method is called by the BatchDriver when the batch is successfully finished
- * @PARAM : batchId
- * @RETURN : void
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void updateRestartKeys(String batchId)
- throws GOSIBatchException
- {
- Connection connection=null;
- PreparedStatement ps=null;
- try
- {
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1012");
- connection=GOSIBatchUtilities.
- getDbConnection(GOSIBatchConstants.COMMON);
- ps=connection.prepareStatement(query);
- ps.setString(1, null);
- ps.setString(2, batchId);
- int result=ps.executeUpdate();
- connection.commit();
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "updateRestartKeys",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : getErrMessageHashMap
- * @INFORMATION : This method returns error message hashmap for
- given batch job. This error list is the core errors and the batch id errors which are of severity of 1
- * @PARAM : NIL
- * @RETURN : class java.util.HashMap
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static HashMap getErrMessageHashMap()
- throws GOSIBatchException
- {
- String errErrFileName=null;
- Connection connection=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- HashMap errMessages = new HashMap();
- try
- {
- boolean bIsArabic=true;
- if("ENGLISH".equals(GOSIBatchProperties.LANGUAGE))
- {
- bIsArabic=false;
- }
- // Preparing the query and executing it
- connection=GOSIBatchUtilities.
- getDbConnection(GOSIBatchConstants.COMMON);
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1020");
- //System.out.println("query : "+query);
- ps=connection.prepareStatement(query);
- //System.out.println("GOSIBATCHUTILITIES : Serverity"+GOSIBatchConstants.SEVERITY_ONE);
- ps.setInt(1,GOSIBatchConstants.SEVERITY_ONE);
- rs=ps.executeQuery();
- // Loading the messages in HashMap.
- // ErrorCode as key and the message as value
- while(rs.next())
- {
- if(bIsArabic)
- {
- errMessages.put(rs.getString("ERRORCODE"),
- rs.getString("ERRORMESSAGEAR"));
- }
- else
- {
- errMessages.put(rs.getString("ERRORCODE"),
- rs.getString("ERRORMESSAGEEN"));
- }
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- e.printStackTrace();
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getErrMessageHashMap",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs, ps, connection);
- }
- return errMessages;
- }// end of method getErrMessageHashMap
- /**
- * @METHOD NAME : getErrMessageHashMapByLang
- * @INFORMATION : This method returns error message hashmap for
- * given batch job.
- * This error list is the core errors and the batch id errors
- * which are of severity of 1
- * This method takes boolean for isLoadArabic
- * @PARAM : NIL
- * @RETURN : class java.util.HashMap
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static HashMap getErrMessageHashMapByLang(boolean isLoadArabic)
- throws GOSIBatchException
- {
- String errErrFileName=null;
- Connection connection=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- HashMap errMessages = new HashMap();
- try
- {
- boolean bIsArabic=isLoadArabic;
- // Preparing the query and executing it
- connection=GOSIBatchUtilities.
- getDbConnection(GOSIBatchConstants.COMMON);
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1020");
- //System.out.println("query : "+query);
- ps=connection.prepareStatement(query);
- //System.out.println("GOSIBATCHUTILITIES : Serverity"+GOSIBatchConstants.SEVERITY_ONE);
- ps.setInt(1,GOSIBatchConstants.SEVERITY_ONE);
- rs=ps.executeQuery();
- // Loading the messages in HashMap.
- // ErrorCode as key and the message as value
- while(rs.next())
- {
- if(bIsArabic)
- {
- errMessages.put(rs.getString("ERRORCODE"),
- rs.getString("ERRORMESSAGEAR"));
- }
- else
- {
- errMessages.put(rs.getString("ERRORCODE"),
- rs.getString("ERRORMESSAGEEN"));
- }
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- e.printStackTrace();
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getErrMessageHashMap",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs, ps, connection);
- }
- return errMessages;
- }// end of method getErrMessageHashMapByLang
- /**
- * @METHOD NAME : populateSQL
- * @INFORMATION : This method populates the module specific sql
- queries. For the passed module id and as well as batch identifier.
- Module name is the 3 character short name of module like CMN,PER,etc..
- batchIdentifier is the sequncy number of the batch which is 001,002..
- * @PARAM : moduleName, batchIdentifier
- * @RETURN : class java.util.HashMap
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static HashMap populateSQL(String moduleName,String batchIdentifier)
- {
- short moduleId=0;
- String sqlFileName=null;
- //System.out.println(moduleName);
- // Getting the module id for the module name
- if((GOSIBatchConstants.COMMON).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.COMMON_ID;
- }
- else if((GOSIBatchConstants.REGISTRATION).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.REGISTRATION_ID;
- }
- else if((GOSIBatchConstants.CONTRIBUTION).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.CONTRIBUTION_ID;
- }
- else if((GOSIBatchConstants.OCCUPATIONAL_HAZARDS).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.OCCUPATIONAL_HAZARDS_ID;
- }
- else if((GOSIBatchConstants.ANNUITIES).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.ANNUITIES_ID;
- }
- else if((GOSIBatchConstants.BUDGET).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.BUDGET_ID;
- }
- else if((GOSIBatchConstants.FINANCE).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.FINANCE_ID;
- }
- else if((GOSIBatchConstants.INVESTMENT).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.INVESTMENT_ID;
- }
- else if((GOSIBatchConstants.FIXED_ASSET).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.FIXED_ASSET_ID;
- }
- else if((GOSIBatchConstants.INVENTORY).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.INVENTORY_ID;
- }
- else if((GOSIBatchConstants.PURCHASE).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.PURCHASE_ID;
- }
- else if((GOSIBatchConstants.CONTRACT).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.CONTRACT_ID;
- }
- else if((GOSIBatchConstants.REAL_ESTATE).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.REAL_ESTATE_ID;
- }
- else if((GOSIBatchConstants.PERSONNEL).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.PERSONNEL_ID;
- }
- else if((GOSIBatchConstants.PROJECT).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.PROJECT_ID;
- }
- else if((GOSIBatchConstants.INTERFACE).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.INTERFACE_ID;
- }
- else if((GOSIBatchConstants.DATAWAREHOUSING).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.DATAWAREHOUSING_ID;
- }
- else if((GOSIBatchConstants.COMMON_FUT).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.COMMON_FUT_ID;
- }
- else if((GOSIBatchConstants.INTERNET).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.INTERNET_ID;
- }
- else if((GOSIBatchConstants.RPA).equals(moduleName))
- {
- moduleId=GOSIBatchConstants.RPA_ID;
- }
- // getting the SQL file name for the module id
- switch(moduleId)
- {
- case(GOSIBatchConstants.COMMON_ID):
- sqlFileName =
- GOSIBatchProperties.COMMON_SQL_FILE;
- break;
- case(GOSIBatchConstants.REGISTRATION_ID):
- sqlFileName =
- GOSIBatchProperties.REGISTRATION_SQL_FILE;
- break;
- case(GOSIBatchConstants.CONTRIBUTION_ID):
- sqlFileName =
- GOSIBatchProperties.CONTRIBUTION_SQL_FILE;
- break;
- case(GOSIBatchConstants.OCCUPATIONAL_HAZARDS_ID):
- sqlFileName =
- GOSIBatchProperties.OCCUPATIONAL_HAZARDS_SQL_FILE;
- break;
- case(GOSIBatchConstants.ANNUITIES_ID):
- sqlFileName =
- GOSIBatchProperties.ANNUITIES_SQL_FILE;
- break;
- case(GOSIBatchConstants.BUDGET_ID):
- sqlFileName =
- GOSIBatchProperties.BUDGET_SQL_FILE;
- break;
- case(GOSIBatchConstants.FINANCE_ID):
- sqlFileName =
- GOSIBatchProperties.FINANCE_SQL_FILE;
- break;
- case(GOSIBatchConstants.INVESTMENT_ID):
- sqlFileName =
- GOSIBatchProperties.INVESTMENT_SQL_FILE;
- break;
- case(GOSIBatchConstants.FIXED_ASSET_ID):
- sqlFileName =
- GOSIBatchProperties.FIXED_ASSET_SQL_FILE;
- break;
- case(GOSIBatchConstants.INVENTORY_ID):
- sqlFileName =
- GOSIBatchProperties.INVENTORY_SQL_FILE;
- break;
- case(GOSIBatchConstants.PURCHASE_ID):
- sqlFileName =
- GOSIBatchProperties.PURCHASE_SQL_FILE;
- break;
- case(GOSIBatchConstants.CONTRACT_ID):
- sqlFileName =
- GOSIBatchProperties.CONTRACT_SQL_FILE;
- break;
- case(GOSIBatchConstants.REAL_ESTATE_ID):
- sqlFileName =
- GOSIBatchProperties.REAL_ESTATE_SQL_FILE;
- break;
- case(GOSIBatchConstants.PERSONNEL_ID):
- sqlFileName =
- GOSIBatchProperties.PERSONNEL_SQL_FILE;
- break;
- case(GOSIBatchConstants.PROJECT_ID):
- sqlFileName =
- GOSIBatchProperties.PROJECT_SQL_FILE;
- break;
- case(GOSIBatchConstants.INTERFACE_ID):
- sqlFileName =
- GOSIBatchProperties.INTERFACE_SQL_FILE;
- break;
- case(GOSIBatchConstants.DATAWAREHOUSING_ID):
- sqlFileName =
- GOSIBatchProperties.DATAWAREHOUSING_SQL_FILE;
- break;
- case (GOSIBatchConstants.COMMON_FUT_ID):
- sqlFileName =
- GOSIBatchProperties.COMMON_FUT_SQL_FILE;
- break;
- case (GOSIBatchConstants.INTERNET_ID):
- sqlFileName =
- GOSIBatchProperties.INTERNET_SQL_FILE;
- break;
- case (GOSIBatchConstants.RPA_ID):
- sqlFileName =
- GOSIBatchProperties.RPA_SQL_FILE;
- break;
- default :
- break ;
- }// end of switch for assigning Error input fileNames
- //System.out.println("SQL FILE NAME IS : "+sqlFileName);
- // Creating the haspmap for loading the data
- HashMap sqlStrings = new HashMap();
- try
- {
- // Opening the SQL file
- File sqlFile = new File(sqlFileName);
- if(!sqlFile.exists())
- {
- return null; // returns null if no file exists
- // for any modules
- }
- else
- {
- // Reading the data
- FileReader fr = new FileReader(sqlFile);
- BufferedReader br = new BufferedReader(fr);
- String lineValue =null;
- READNEWLINE:while((lineValue= br.readLine()) != null)
- {
- if("".equals(lineValue))
- {
- continue READNEWLINE;
- }
- // Taking the ling in StringTokenizer
- StringTokenizer str =
- new StringTokenizer(lineValue,"#");
- String sqlCode ="";
- String sqlString = "";
- // Taking the sql code and sql from the StringTokenizer
- if(str.hasMoreTokens())
- {
- sqlCode = str.nextToken().trim();
- }
- if(str.hasMoreTokens())
- {
- sqlString = str.nextToken().trim();
- }
- if((!("".equals(sqlCode)))
- &&(!("".equals(sqlString)))
- )
- {
- // putting the error numbers,messages
- //into hashtabales
- // If the module is common or INTERFACE then reading all the queries and loading in hash map
- if((moduleName.equals(GOSIBatchConstants.COMMON))||
- (moduleName.equals(GOSIBatchConstants.INTERFACE)))
- {
- sqlStrings.put(sqlCode,sqlString);
- }
- // If DATAWAREHOUSING_ID also reading all the quries
- else if(moduleId == GOSIBatchConstants.DATAWAREHOUSING_ID)
- {
- sqlStrings.put(sqlCode, sqlString);
- }
- // If the module is any other module The sequency no of the BathId should match with the 4 to 7 character of the sqlCode
- // Sql code are having the Batch id as the first 7 characters and the _SQL and then _Sequence number.
- // So for other modules making shure that we are loading only those quries which are related to that batch id
- else if((sqlCode.substring(4,7)).equals(batchIdentifier))
- {
- sqlStrings.put(sqlCode,sqlString);
- }
- }
- }//end of while
- }//end of else
- }// end of try
- catch(IOException ie)
- {
- ie.printStackTrace();
- }
- return sqlStrings;
- }// end of method getErrMessageHashMap
- /**
- * @METHOD NAME : getBatchParams
- * @INFORMATION : This method returns batch param values for the given
- batch master which has the request ids list in that date
- * @PARAM : batchMaster
- * @RETURN : class java.util.ArrayList
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static ArrayList getBatchParams(BatchMaster batchMaster)
- throws GOSIBatchException
- {
- ArrayList paramList=null;
- Connection connection=null;
- try
- {
- connection=GOSIBatchUtilities.
- getDbConnection(GOSIBatchConstants.COMMON);
- Long[] requestNos=getBatchRequestNo(batchMaster,connection);
- // If the batch is normal batch only on request is taken even the batch has multiple requests
- // So the return arraylist will have the list of Param beans
- if(batchMaster.getBatchType()==GOSIBatchConstants.NORMAL_JOB)
- {
- // If the batch is normal batch calling GOSIBatchUtilities.getBatchParams to get the paramaers for the given request id
- paramList=GOSIBatchUtilities.getBatchParams
- (requestNos[0].longValue(),connection);
- }
- // If the batch is Adhoc that may have more than one request in the given day.
- // So the return list will have lists of param bean for each request
- else
- {
- paramList=new ArrayList();
- // Going in loop for each request id
- for(int i=0;i<batchMaster.getNoOfRequests();i++)
- {
- // Calling GOSIBatchUtilities.getBatchParams by pasiing request id and getting the list of param beans
- ArrayList params=GOSIBatchUtilities.getBatchParams(requestNos[i].longValue(),connection);
- // Adding that array list to paramList
- paramList.add(params);
- }
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getBatchParams",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(connection);
- }
- return paramList;
- }
- /**
- * @METHOD NAME : getBatchRequestNo
- * @INFORMATION : This method returns request id list for the given batch id in that day
- * @PARAM : batchMaster, connection
- * @RETURN : class java.lang.Long[]
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static Long[] getBatchRequestNo(BatchMaster batchMaster,
- Connection connection)
- throws GOSIBatchException
- {
- PreparedStatement ps=null;
- ResultSet rs=null;
- Long[] requestNo=new Long[batchMaster.getNoOfRequests()];
- try
- {
- // Executing the query get the list of the request ids
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1024");
- ps=connection.prepareStatement(query);
- ps.setString(1,batchMaster.getBatchId());
- ps.setTimestamp(2,getSystemDate());
- rs=ps.executeQuery();
- int i=0;
- while(rs.next())
- {
- // Adding the request ids to an array list
- requestNo[i]=new Long(rs.getLong("REQUESTID"));
- i++;
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getBatchRequestNo",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs);
- GOSIBatchUtilities.cleanUp(ps);
- }
- return requestNo;
- }
- /**
- * @METHOD NAME : getBatchParams
- * @INFORMATION : This method returns the batch params for
- given request number this is called when a batch is running for error records.
- So the errors need to be run for the given request.
- * @PARAM : requestNo, connection
- * @RETURN : class java.util.ArrayList
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static ArrayList getBatchParams(long requestNo,
- Connection connection)
- throws GOSIBatchException
- {
- PreparedStatement ps=null;
- ArrayList params=new ArrayList();
- ResultSet rs=null;
- boolean notFound=true;
- short paramId=(short)0;
- byte paramType=(byte)0;
- String paramValue=null;
- String paramName=null;
- try
- {
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1025");
- ps=connection.prepareStatement(query);
- ps.setLong(1,requestNo);
- rs=ps.executeQuery();
- while(rs.next())
- {
- notFound=false;
- BatchParam batchParam=null;
- paramId=rs.getShort("PARAMID");
- paramType=rs.getByte("PARAMTYPE");
- paramValue=rs.getString("PARAMVALUE");
- paramName=rs.getString("PARAMNAME");
- if((paramType==GOSIBatchConstants.PARAM_MANDETORY)&&
- (paramValue==null))
- {
- new GOSIBatchException(null,
- "BatchCore",
- "GOSIBatchUtilities",
- "getBatchParams",
- "CMN_001_ERR_1011",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- else
- {
- batchParam=new BatchParam(paramId,paramValue,
- requestNo,paramName);
- params.add(batchParam);
- }
- }
- if(notFound)
- {
- new GOSIBatchException(null,
- "BatchCore",
- "GOSIUtilities",
- "getBatchParams",
- "CMN_001_ERR_1010",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getBatchParams",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs);
- GOSIBatchUtilities.cleanUp(ps);
- }
- return params;
- }
- /**
- * @METHOD NAME : prepareStatments
- * @INFORMATION : This method prepares all the common required statement
- to process the frame work components.
- Which are workflow , error ,restart and batch request etc
- * @PARAM : conn
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void prepareStatments(Connection conn)
- throws GOSIBatchException
- {
- try
- {
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1005");
- psInsert=conn.prepareStatement(query);
- query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1007");
- psDeleteError=conn.prepareStatement(query);
- query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1006");
- psLogRestart=conn.prepareStatement(query);
- //System.out.println("psLogRestart CREATED"+psLogRestart);
- query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1027");
- psInsertWorkflow=conn.prepareStatement(query);
- query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1028");
- psInsertRangeCheck=conn.prepareStatement(query);
- query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1029");
- psInsertTXNMap=conn.prepareStatement(query);
- query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1030");
- psEmployeeNumber=conn.prepareStatement(query);
- query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1038");
- psInsertBatchRequest=conn.prepareStatement(query);
- query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1039");
- psInsertParamValues=conn.prepareStatement(query);
- query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1042");
- psCheckIsHoliday = conn.prepareStatement(query);
- query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1043");
- psFinalDate = conn.prepareStatement(query);
- query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1044");
- psNoOfHolidays = conn.prepareStatement(query);
- query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1045");
- psWeekEnds = conn.prepareStatement(query);
- query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1046");
- psOtherHolidays = conn.prepareStatement(query);
- query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1047");
- //System.out.println("Total Diff QUery : "+query);
- psTotalDiff = conn.prepareStatement(query);
- query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1048");
- //System.out.println("Total Diff QUery : "+query);
- psNextWorkingDay = conn.prepareStatement(query);
- /*End : To place a request for a batch through a batch*/
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "prepareAllStatments",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : startBatchWorkflow
- * @INFORMATION : This method is used to create the batch workflow
- records
- * @PARAM : batchWorkflowParamBean, conn
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void startBatchWorkflow(BatchWorkflowParamBean
- batchWorkflowParamBean,
- Connection conn) throws GOSIBatchException
- {
- try
- {
- batchWorkflowParamBean.setWorkflowId(
- (getPrimaryKey("T_WORKFLOWTXN",
- getSystemUser())).longValue());
- psInsertWorkflow.setLong(1, batchWorkflowParamBean.
- getWorkflowId());
- psInsertWorkflow.setString(2, batchWorkflowParamBean.
- getPrimaryKey());
- psInsertWorkflow.setShort(3, batchWorkflowParamBean.
- getLocation());
- psInsertWorkflow.setString(4, batchWorkflowParamBean.
- getRoutingCriterion());
- psInsertWorkflow.setString(5, batchWorkflowParamBean.
- getRecordDescription());
- psInsertWorkflow.setString(6, batchWorkflowParamBean.
- getCompletedStepShortName());
- psInsertWorkflow.setByte(7, batchWorkflowParamBean.
- getPriority());
- psInsertWorkflow.setLong(8, batchWorkflowParamBean.
- getTargetUserId());
- psInsertWorkflow.setShort(9, batchWorkflowParamBean.
- getDestinationLoactionId());
- if(batchWorkflowParamBean.getRangeCheck()==null)
- {
- psInsertWorkflow.setByte(10,(byte)0);
- }
- else
- {
- psInsertWorkflow.setByte(10, (byte)1);
- }
- psInsertWorkflow.setTimestamp(11, batchWorkflowParamBean.
- getWorkflowStartDate());
- psInsertWorkflow.setString(12, batchWorkflowParamBean.
- getParentPrimaryKey());
- psInsertWorkflow.setString(13, batchWorkflowParamBean.
- getComments());
- if(batchWorkflowParamBean.getGroupId()!=null)
- {
- psInsertWorkflow.setLong(14, batchWorkflowParamBean.
- getGroupId().longValue());
- }
- else
- {
- psInsertWorkflow.setNull(14,java.sql.Types.NUMERIC);
- }
- psInsertWorkflow.setLong(15, batchWorkflowParamBean.
- getDmsDontCheckMandatoryFlag());
- // Set the Entry time for the Workflow item.
- // Here we set the current system time (not to be confused
- // with the batch current time, which always use the time 01.00.00 AM)
- psInsertWorkflow.setTimestamp(16, new Timestamp(System.currentTimeMillis()));
- psInsertWorkflow.setShort(17, batchWorkflowParamBean.
- getDepartment());
- psInsertWorkflow.addBatch();
- BatchTransactionEntityMap batchTransactionEntityMap=
- batchWorkflowParamBean.getTransactionEntityMap();
- if(batchTransactionEntityMap.getKeyVal1()!=null)
- {
- psInsertTXNMap.setLong(1,batchWorkflowParamBean.
- getWorkflowId());
- psInsertTXNMap.setString(2,batchTransactionEntityMap.getKeyVal1());
- psInsertTXNMap.setString(3,batchTransactionEntityMap.getKeyVal2());
- psInsertTXNMap.setString(4,batchTransactionEntityMap.getKeyVal3());
- psInsertTXNMap.setString(5,batchTransactionEntityMap.getKeyVal4());
- psInsertTXNMap.setString(6,batchTransactionEntityMap.getKeyVal5());
- psInsertTXNMap.setString(7,batchTransactionEntityMap.getKeyVal6());
- psInsertTXNMap.addBatch();
- }
- ArrayList rangeCheck=batchWorkflowParamBean.getRangeCheck();
- if(rangeCheck!=null)
- {
- int rangeCheckSize=rangeCheck.size();
- short sequenceNo=(short)0;
- for(int i=0;i<rangeCheckSize;i++)
- {
- sequenceNo++;
- BatchRangeCheckBean batchRangeCheckBean=(BatchRangeCheckBean)rangeCheck.get(i);
- psInsertRangeCheck.setLong(1, batchWorkflowParamBean.
- getWorkflowId());
- psInsertRangeCheck.setShort(2, batchRangeCheckBean.
- getRangeType());
- psInsertRangeCheck.setLong(3, batchRangeCheckBean.
- getRangeValue());
- psInsertRangeCheck.setShort(4,sequenceNo);
- psInsertRangeCheck.addBatch();
- }
- }
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "startBatchWorkflow",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : startBatchWorkflow
- * @INFORMATION : This method is used to create the batch workflow
- records. It will pass array of batchworkflowParam
- beans.
- * @PARAM : batchWorkflowParamBeanList, conn
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void startBatchWorkflow(ArrayList
- batchWorkflowParamBeanList,
- Connection conn) throws GOSIBatchException
- {
- BatchWorkflowParamBean batchWorkflowParamBean=null;
- try
- {
- Long[] ids=getPrimaryKeyList("T_WORKFLOWTXN",batchWorkflowParamBeanList.size(),
- getSystemUser());
- int listSize=batchWorkflowParamBeanList.size();
- for(int j=0;j<listSize;j++)
- {
- batchWorkflowParamBean=(BatchWorkflowParamBean)
- batchWorkflowParamBeanList.get(j);
- batchWorkflowParamBean.setWorkflowId(ids[j].longValue());
- psInsertWorkflow.setLong(1, batchWorkflowParamBean.
- getWorkflowId());
- psInsertWorkflow.setString(2, batchWorkflowParamBean.
- getPrimaryKey());
- psInsertWorkflow.setShort(3, batchWorkflowParamBean.
- getLocation());
- psInsertWorkflow.setString(4, batchWorkflowParamBean.
- getRoutingCriterion());
- //System.out.println("@@@@@@@@@@@@@ : "+batchWorkflowParamBean.
- // getRecordDescription()+"%%%%%%%%%%%%%%%%%%%");
- psInsertWorkflow.setString(5, batchWorkflowParamBean.
- getRecordDescription());
- psInsertWorkflow.setString(6, batchWorkflowParamBean.
- getCompletedStepShortName());
- psInsertWorkflow.setByte(7, batchWorkflowParamBean.
- getPriority());
- psInsertWorkflow.setLong(8, batchWorkflowParamBean.
- getTargetUserId());
- psInsertWorkflow.setShort(9, batchWorkflowParamBean.
- getDestinationLoactionId());
- if(batchWorkflowParamBean.getRangeCheck()==null)
- {
- psInsertWorkflow.setByte(10,(byte)0);
- }
- else
- {
- psInsertWorkflow.setByte(10, (byte)1);
- }
- psInsertWorkflow.setTimestamp(11, batchWorkflowParamBean.
- getWorkflowStartDate());
- psInsertWorkflow.setString(12, batchWorkflowParamBean.
- getParentPrimaryKey());
- psInsertWorkflow.setString(13, batchWorkflowParamBean.
- getComments());
- if(batchWorkflowParamBean.getGroupId()!=null)
- {
- psInsertWorkflow.setLong(14, batchWorkflowParamBean.
- getGroupId().longValue());
- }
- else
- {
- psInsertWorkflow.setNull(14,java.sql.Types.NUMERIC);
- }
- psInsertWorkflow.setLong(15, batchWorkflowParamBean.
- getDmsDontCheckMandatoryFlag());
- // Set the Entry time for the Workflow item.
- // Here we set the current system time (not to be confused
- // with the batch current time, which always use the time 01.00.00 AM)
- psInsertWorkflow.setTimestamp(16, new Timestamp(System.currentTimeMillis()));
- psInsertWorkflow.setShort(17, batchWorkflowParamBean.
- getDepartment());
- psInsertWorkflow.addBatch();
- BatchTransactionEntityMap batchTransactionEntityMap=
- batchWorkflowParamBean.getTransactionEntityMap();
- if(batchTransactionEntityMap.getKeyVal1()!=null)
- {
- psInsertTXNMap.setLong(1,batchWorkflowParamBean.
- getWorkflowId());
- psInsertTXNMap.setString(2,batchTransactionEntityMap.getKeyVal1());
- psInsertTXNMap.setString(3,batchTransactionEntityMap.getKeyVal2());
- psInsertTXNMap.setString(4,batchTransactionEntityMap.getKeyVal3());
- psInsertTXNMap.setString(5,batchTransactionEntityMap.getKeyVal4());
- psInsertTXNMap.setString(6,batchTransactionEntityMap.getKeyVal5());
- psInsertTXNMap.setString(7,batchTransactionEntityMap.getKeyVal6());
- psInsertTXNMap.addBatch();
- }
- ArrayList rangeCheck=batchWorkflowParamBean.getRangeCheck();
- if(rangeCheck!=null)
- {
- int rangeCheckSize=rangeCheck.size();
- short sequenceNo=(short)0;
- for(int i=0;i<rangeCheckSize;i++)
- {
- sequenceNo++;
- BatchRangeCheckBean batchRangeCheckBean=(BatchRangeCheckBean)rangeCheck.get(i);
- psInsertRangeCheck.setLong(1, batchWorkflowParamBean.
- getWorkflowId());
- psInsertRangeCheck.setShort(2, batchRangeCheckBean.
- getRangeType());
- psInsertRangeCheck.setLong(3, batchRangeCheckBean.
- getRangeValue());
- psInsertRangeCheck.setShort(4,sequenceNo);
- psInsertRangeCheck.addBatch();
- }
- }
- }
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "startBatchWorkflow",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : getUserIdForEmployee
- * @INFORMATION : This method returns the user id for given
- employee
- * @PARAM : employeeNumber
- * @RETURN : long
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static long getUserIdForEmployee(Long employeeNumber)
- throws GOSIBatchException
- {
- ResultSet rs=null;
- long userId=0L;
- try
- {
- psEmployeeNumber.setLong(1, employeeNumber.longValue());
- psEmployeeNumber.setShort(2, GOSIBatchConstants.EMPLOYEE);
- rs=psEmployeeNumber.executeQuery();
- if(rs.next())
- {
- userId=rs.getLong("ID");
- }
- else
- {
- new GOSIBatchException(null,
- "BatchCore",
- "GOSIBatchUtilities",
- "startBatchWorkflow",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_TWO);
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "startBatchWorkflow",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs);
- }
- return userId;
- }
- public static ArrayList onlineTaskList=new ArrayList();
- /**
- * @METHOD NAME : disableOnlineMenu
- * @INFORMATION : This method will be called by batch driver
- before executing the batch process, and this will
- disable all the dependent online links to not
- available till the completion of batch job
- * @PARAM : batchId
- * @RETURN : void
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void disableOnlineMenu(String batchId)
- throws GOSIBatchException
- {
- Connection conn=null;
- ResultSet rs=null;
- PreparedStatement ps=null;
- long id=0L;
- byte type=(byte)0;
- BatchOnlineDependentTaskBean
- batchOnlineDependentTaskBean = null;
- try
- {
- // Executing the query to the list of task depends on the batch id
- // Which gets the task id and as well task type whether menu or work flow
- conn=GOSIBatchUtilities.getDbConnection(GOSIBatchConstants.COMMON);
- ps=conn.prepareStatement(GOSIBatchSQL.getSqlString("CMN_001_SQL_1031"));
- ps.setString(1,batchId);
- ps.setString(2,batchId);
- rs=ps.executeQuery();
- while(rs.next())
- {
- // Populating them into batchOnlineDependentTaskBean
- batchOnlineDependentTaskBean=
- new BatchOnlineDependentTaskBean(rs.getLong("ID"),rs.getByte("TYPE"),rs.getShort("COUNTER"));
- // Adding them to list
- onlineTaskList.add(batchOnlineDependentTaskBean);
- }
- // If some task are dependent calling performActionOnLinks my sending theflag as DISABLELINKS
- if(onlineTaskList.size()!=0)
- {
- performActionOnLinks(GOSIBatchConstants.DISABLELINKS,conn,batchId);
- }
- }
- catch(GOSIBatchException ge)
- {
- try
- {
- if (conn != null )
- conn.rollback();
- }
- catch (Exception ex){ /* Ignore */}
- throw ge;
- }
- catch(Exception e)
- {
- try
- {
- if (conn != null )
- conn.rollback();
- }
- catch (Exception ex){ /* Ignore */}
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "startBatchWorkflow",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs,ps,conn);
- }
- }
- /**
- * @METHOD NAME : enableOnlineMenu
- * @INFORMATION : This method will be called by batch driver once the
- batch job completed. THis enables all the
- dependent tasks.
- * @PARAM : batchId
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void enableOnlineMenu(String batchId)
- throws GOSIBatchException
- {
- Connection conn=null;
- ResultSet rs=null;
- PreparedStatement ps=null;
- long id=0L;
- byte type=(byte)0;
- BatchOnlineDependentTaskBean
- batchOnlineDependentTaskBean = null;
- try
- {
- // Executing the query to the list of task depends on the batch id
- // Which gets the task id and as well task type whether menu or work flow
- conn=GOSIBatchUtilities.getDbConnection(GOSIBatchConstants.COMMON);
- ps=conn.prepareStatement(GOSIBatchSQL.getSqlString("CMN_001_SQL_1031"));
- ps.setString(1,batchId);
- ps.setString(2,batchId);
- rs=ps.executeQuery();
- while(rs.next())
- {
- // Populating them into batchOnlineDependentTaskBean
- batchOnlineDependentTaskBean=
- new BatchOnlineDependentTaskBean(rs.getLong("ID"),rs.getByte("TYPE"),rs.getShort("COUNTER"));
- // Adding them to list
- onlineTaskList.add(batchOnlineDependentTaskBean);
- }
- // If some task are dependent calling performActionOnLinks my sending theflag as DISABLELINKS
- if(onlineTaskList.size()!=0)
- {
- performActionOnLinks(GOSIBatchConstants.ENABLELINKS,conn,batchId);
- }
- }
- catch(GOSIBatchException ge)
- {
- try
- {
- if (conn != null )
- conn.rollback();
- }
- catch (Exception ex){ /* Ignore */}
- throw ge;
- }
- catch(Exception e)
- {
- try
- {
- if (conn != null )
- conn.rollback();
- }
- catch (Exception ex){ /* Ignore */}
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "startBatchWorkflow",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs,ps,conn);
- }
- }
- /**
- * @METHOD NAME : performActionOnLinks
- * @INFORMATION : This method changes the status of task.
- * @PARAM : flag, conn, batchId
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static void performActionOnLinks(byte flag,
- Connection conn,String batchId) throws GOSIBatchException
- {
- PreparedStatement psMenu=null;
- PreparedStatement psWorkflow=null;
- try
- {
- // Getting intial context
- getDirContext();
- // Preaparing query to update workflow task in DB
- psWorkflow=conn.prepareStatement(GOSIBatchSQL.
- getSqlString("CMN_001_SQL_1032"));
- // Preaparing query to update menu task in DB
- psMenu=conn.prepareStatement(GOSIBatchSQL.
- getSqlString("CMN_001_SQL_1033"));
- int listSize=onlineTaskList.size();
- BatchOnlineDependentTaskBean batchOnlineDependentTaskBean=null;
- // Going in loop for updating the links in LDAP
- for(int i=0;i<listSize;i++)
- {
- batchOnlineDependentTaskBean=(BatchOnlineDependentTaskBean)
- onlineTaskList.get(i);
- if(flag==GOSIBatchConstants.ENABLELINKS)
- {
- if (batchOnlineDependentTaskBean.getCounter()> 0)
- {
- if(batchOnlineDependentTaskBean.getType()==(byte)1)
- {
- psWorkflow.setShort(1,(short)(batchOnlineDependentTaskBean.getCounter()-1));
- psWorkflow.setLong(2,batchOnlineDependentTaskBean.getId());
- psWorkflow.executeQuery();
- updateWorkflowItemInLDAP((short)(batchOnlineDependentTaskBean.getCounter()-1),
- batchOnlineDependentTaskBean.getId());
- }
- else
- {
- psMenu.setShort(1,(short)(batchOnlineDependentTaskBean.getCounter()-1));
- psMenu.setLong(2,batchOnlineDependentTaskBean.getId());
- psMenu.executeQuery();
- updateMenuItemInLDAP((short)(batchOnlineDependentTaskBean.getCounter()-1),
- batchOnlineDependentTaskBean.getId());
- }
- }
- }
- else
- {
- if(batchOnlineDependentTaskBean.getType()==(byte)1)
- {
- psWorkflow.setShort(1,(short)(batchOnlineDependentTaskBean.getCounter()+1));
- psWorkflow.setLong(2,batchOnlineDependentTaskBean.getId());
- psWorkflow.executeQuery();
- updateWorkflowItemInLDAP((short)(batchOnlineDependentTaskBean.getCounter()+1),
- batchOnlineDependentTaskBean.getId());
- }
- else
- {
- psMenu.setShort(1,(short)(batchOnlineDependentTaskBean.getCounter()+1));
- psMenu.setLong(2,batchOnlineDependentTaskBean.getId());
- psMenu.executeQuery();
- updateMenuItemInLDAP((short)(batchOnlineDependentTaskBean.getCounter()+1),
- batchOnlineDependentTaskBean.getId());
- }
- }
- // Depending on the type of the link calling the appropriate method to update
- }
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "performActionOnLinks",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : updateWorkflowItemInLDAP
- * @INFORMATION : This method updates the batch running status
- flag of workflow task in LDAP
- * @PARAM : flag, id
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static void updateWorkflowItemInLDAP(short flag,long id)
- throws GOSIBatchException
- {
- try
- {
- String distinguishedName = "id="+id+
- ","+GOSIBatchProperties.GOSI_LDAP_ROOT_SUFFIX;
- ModificationItem mods[] = new ModificationItem[1];
- mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
- new BasicAttribute("batchrunningstatus", new Short(flag).toString()));
- ctx.modifyAttributes(distinguishedName, mods);
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "updateWorkflowItemInLDAP",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : updateWorkflowItemInLDAP
- * @INFORMATION : This method updates the batch running status
- flag of menu task in LDAP
- * @PARAM : flag, id
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static void updateMenuItemInLDAP(short flag,long id)
- throws GOSIBatchException
- {
- try
- {
- //System.out.println("ID IN menu TASK"+id);
- String distinguishedName = "menutaskid="+id+
- ","+GOSIBatchProperties.GOSI_LDAP_ROOT_SUFFIX;
- ModificationItem mods[] = new ModificationItem[1];
- mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
- new BasicAttribute("batchrunningstatus", new Short(flag).toString()));
- ctx.modifyAttributes(distinguishedName, mods);
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "updateMenuItemInLDAP",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- private static InitialLdapContext ctx = null;
- /**
- * @METHOD NAME : getDirContext
- * @INFORMATION : THis method sets the LDAP context to the processor
- * @PARAM : NIL
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static void getDirContext()
- throws GOSIBatchException
- {
- Hashtable env = null;
- Hashtable envAnonymous = null;
- try
- {
- env = new Hashtable();
- env.put(Context.INITIAL_CONTEXT_FACTORY,
- "com.sun.jndi.ldap.LdapCtxFactory");
- env.put(Context.PROVIDER_URL,
- GOSIBatchProperties.GOSI_LDAP_URL);
- env.put(Context.SECURITY_AUTHENTICATION,"simple");
- env.put(Context.SECURITY_PRINCIPAL,
- GOSIBatchProperties.GOSI_LDAP_ADMIN_UID);
- env.put(Context.SECURITY_CREDENTIALS,
- GOSIBatchProperties.GOSI_LDAP_ADMIN_PASSWORD);
- ctx = new InitialLdapContext(env,null);
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "performActionOnLinks",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }// END OF METHOD getDirContext()
- /**
- * @METHOD NAME : setSuccessfulRunDate
- * @INFORMATION : This method sets the successful rundate to the current date.
- This method is called by the batch driver when the batch is completed successfully
- * @PARAM : batchId, connection
- * @RETURN : void
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void setSuccessfulRunDate(String batchId,Connection connection)
- throws GOSIBatchException
- {
- try
- {
- String query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1011");
- psRestartKeyUpdate = connection.prepareStatement(query);
- //System.out.println("GOSIBatchUtilities : setSuccessfulRundate :"+
- // " called for Batch ID "+GOSIBatchUtilities.getSystemDate());
- psRestartKeyUpdate.setTimestamp(1,GOSIBatchUtilities.getSystemDate());
- psRestartKeyUpdate.setString(2,batchId);
- int updated = psRestartKeyUpdate.executeUpdate();
- //System.out.println("Update the current date for successfulrundate"+updated);
- }catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "setSuccessfulRunDate",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : setDomainData
- * @INFORMATION : This method creates the domain data this is the interface provided to finance to create domain data in the batch
- * @PARAM : domainBean, connection
- * @RETURN : void
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void setDomainData(DomainBean domainBean,
- Connection connection)
- throws GOSIBatchException
- {
- PreparedStatement psDomain = null;
- PreparedStatement psSelectMaxSequenceNumber = null;
- ResultSet rsSequenceNumber = null;
- String tempSequenceNumber = null;
- int incrSequenceNumber = 0;
- String query = null;
- int col = 0;
- try
- {
- // Insertion in Domain Tables
- query=GOSIBatchSQL.getSqlString("INT_CMN_SQL_4026");
- //System.out.println("query="+query);
- psDomain=connection.prepareStatement(query);
- query = GOSIBatchSQL.getSqlString("INT_CMN_SQL_4029");
- //System.out.println("query="+query);
- psSelectMaxSequenceNumber = connection.prepareStatement(query);
- psSelectMaxSequenceNumber.setString(1,domainBean.getDomainName());
- psSelectMaxSequenceNumber.setLong(2,domainBean.getCategoryCode());
- rsSequenceNumber = psSelectMaxSequenceNumber.executeQuery();
- if(rsSequenceNumber.next())
- {
- if(rsSequenceNumber.getObject(1)!= null)
- {
- tempSequenceNumber = rsSequenceNumber.
- getString(1);
- }
- }
- GOSIBatchUtilities.cleanUp(psSelectMaxSequenceNumber);
- GOSIBatchUtilities.cleanUp(rsSequenceNumber);
- //System.out.println("db seq number ***" +
- //tempSequenceNumber);
- if(tempSequenceNumber != null)
- {
- incrSequenceNumber = Integer.parseInt(tempSequenceNumber);
- incrSequenceNumber += 1;
- tempSequenceNumber = "" + incrSequenceNumber;
- domainBean.setSequenceNumber
- (new Short(tempSequenceNumber));
- }
- //System.out.println("seq number ****" +
- //domainBean.getSequenceNumber());
- psDomain.setInt(++col,domainBean.getDomainId());
- psDomain.setInt(++col,domainBean.getCodeLength());
- psDomain.setInt(++col,domainBean.getCodeType());
- psDomain.setString(++col,domainBean.getDomainName());
- psDomain.setLong(++col,domainBean.getCategoryCode());
- psDomain.setInt(++col,domainBean.getCode());
- psDomain.setString(++col,domainBean.getShortNameArabic());
- psDomain.setString(++col,domainBean.getShortNameEnglish());
- psDomain.setString(++col,domainBean.getLongName());
- psDomain.setLong(++col,domainBean.getCreatedBy().longValue());
- psDomain.setTimestamp(++col,domainBean.getCreationTimestamp());
- if(domainBean.getSequenceNumber()!= null)
- {
- psDomain.setShort(++col,domainBean.getSequenceNumber().
- shortValue());
- }
- else
- {
- psDomain.setString(++col,null);
- }
- psDomain.executeUpdate();
- //Insertion in LDAP
- DirContext ctx;
- Attributes myAttrs;
- String domainId=null;
- String domainName=null;
- String domainCode=null;
- String codeType=null;
- String codeLength=null;
- String categoryCode=null;
- String shortNameEng=null;
- String shortNameAr=null;
- String longName=null;
- String sequenceNumber = null;
- /*
- String LDAP_URL=;
- String LDAP_ADMIN_ID="cn=Directory Manager";
- String LDAP_ADMIN_PWD="gosioffshore";
- String LDAP_ROOT_SUFFIX="o=gosi.com";
- */
- Hashtable env = new Hashtable();
- env.put(Context.INITIAL_CONTEXT_FACTORY,
- "com.sun.jndi.ldap.LdapCtxFactory");
- env.put(Context.PROVIDER_URL,GOSIBatchProperties.GOSI_LDAP_URL);
- env.put(Context.SECURITY_AUTHENTICATION,"simple");
- env.put(Context.SECURITY_PRINCIPAL,GOSIBatchProperties.GOSI_LDAP_ADMIN_UID);
- env.put(Context.SECURITY_CREDENTIALS,GOSIBatchProperties.GOSI_LDAP_ADMIN_PASSWORD);
- ctx=new InitialDirContext(env);
- domainId=""+domainBean.getDomainId();
- domainName=domainBean.getDomainName();
- domainCode=""+domainBean.getCode();
- codeType=""+domainBean.getCodeType();
- codeLength=""+domainBean.getCodeLength();
- categoryCode=""+domainBean.getCategoryCode();
- if("0".equals(categoryCode))
- {
- categoryCode="0000";
- }
- shortNameEng=domainBean.getShortNameEnglish();
- shortNameAr=domainBean.getShortNameArabic();
- if(domainBean.getLongName()!=null)
- {
- longName=domainBean.getLongName();
- }
- sequenceNumber = domainBean.getSequenceNumber()+"";
- //Domain Detail
- myAttrs = new BasicAttributes(true); // case ignore
- Attribute oc = new BasicAttribute("objectclass");
- oc.add(0,"domaindetails");
- oc.add(1,"top");
- myAttrs.put(oc);
- myAttrs.put("code", domainCode);
- if(longName!=null)
- {
- myAttrs.put("longname", longName);
- }
- myAttrs.put("shortnamearabic", shortNameAr);
- myAttrs.put("shortnameenglish", shortNameEng);
- myAttrs.put("sequencenumber",sequenceNumber);
- ctx.bind("code="+domainCode+",categorycode="
- +categoryCode+",domainname="
- +domainName+","+GOSIBatchProperties.GOSI_LDAP_ROOT_SUFFIX,null,
- myAttrs);
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "setDomainData",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : getBaseCurrency
- * @INFORMATION : This method returns the Base Currency
- * @PARAM : NIL
- * @RETURN : int
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static int getBaseCurrency()
- throws GOSIBatchException
- {
- int baseCurCode=0;
- try
- {
- if(currencyList!=null)
- {
- int currSize=currencyList.size();
- //System.out.println("Getbase Currency"+currSize);
- for(int i=0; i<currSize;i++)
- {
- HashMap curDet=(HashMap)currencyList.get(i);
- int curType=Integer.parseInt(""+curDet.get("type"));
- if (curType==1)
- {
- baseCurCode=Integer.parseInt(""+curDet.get("code"));
- break;
- }
- }
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getBaseCurrency()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return baseCurCode;
- }
- /**
- * @METHOD NAME : getSystemDate
- * @INFORMATION : This method will provide the System date for batch
- * @PARAM : void
- * @RETURN : class java.sql.Timestamp
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static Timestamp getSystemDate()
- throws GOSIBatchException
- {
- try
- {
- // If the currentSystemDate reading from file
- if(currentSystemDate==null)
- {
- FileInputStream fis = new FileInputStream
- //("/global/oracle/orabin/dbjdk/gosibatch/BatchCore/SystemTime.tim");
- (GOSIBatchConstants.GOSI_SYSTEM_TIME_FILE_PATH);
- Properties prop = new Properties();
- prop.load(fis);
- int date = Integer.parseInt(((String)prop.get("DATE")).trim());
- int month = Integer.parseInt(((String)prop.get("MONTH")).trim())-1;
- int year = Integer.parseInt(((String)prop.get("YEAR")).trim());
- int hours = Integer.parseInt(((String)prop.get("HOURS")).trim());
- int minutes = Integer.parseInt(((String)prop.get("MINUTES")).trim());
- int seconds = Integer.parseInt(((String)prop.get("SECONDS")).trim());
- currentSystemDate =new Timestamp(System.currentTimeMillis());
- currentSystemDate.setYear(year-1900);
- currentSystemDate.setMonth(month);
- currentSystemDate.setDate(date);
- currentSystemDate.setHours(hours);
- currentSystemDate.setMinutes(minutes);
- currentSystemDate.setSeconds(seconds);
- }
- }catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getBaseCurrency()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return currentSystemDate;
- }
- /**
- * @METHOD NAME : getLdapDateFromTimestamp
- * @INFORMATION : This method gets the current date for LDAP format
- * returns the same
- * @PARAM : dateTimeStamp
- * @RETURN : class java.lang.String
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static String getLdapDateFromTimestamp(Timestamp dateTimeStamp)
- throws GOSIBatchException
- {
- String ldapDate=null;
- try
- {
- if(dateTimeStamp!=null)
- {
- String timestamp=dateTimeStamp.toString();
- StringBuffer stringBuffer=new StringBuffer();
- stringBuffer.append(timestamp.substring(0,4));
- stringBuffer.append(timestamp.substring(5,7));
- stringBuffer.append(timestamp.substring(8,10));
- ldapDate=stringBuffer.toString();
- }// end of if
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getLdapDateFromTimestamp",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return ldapDate;
- }
- /**
- * @METHOD NAME : decryptPassword
- * @INFORMATION : This method gets the string and decrypt it.
- * @PARAM : password
- * @RETURN : class java.lang.String
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static String decryptPassword(String password)
- throws GOSIBatchException
- {
- String decstr="";
- try
- {
- // Create an array to hold the key
- byte[] encryptKey = javax.xml.bind.DatatypeConverter.printBase64Binary(GOSIBatchProperties.GOSI_KEY.getBytes()).getBytes();
- // Create a DESede key spec from the key
- DESedeKeySpec spec = new DESedeKeySpec(encryptKey);
- // Get the secret key factor for generating DESede keys
- SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(
- "DESede");
- // Generate a DESede SecretKey object
- SecretKey theKey = keyFactory.generateSecret(spec);
- // Create a DESede Cipher
- Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
- // Create the initialization vector required for CBC mode
- IvParameterSpec ivParameters = new IvParameterSpec(
- new byte[] { 12, 34, 56, 78, 90, 87, 65, 43 } );
- // Initialize the cipher and put it in decrypt mode
- cipher.init(Cipher.DECRYPT_MODE, theKey, ivParameters);
- byte[] encryptedText = javax.xml.bind.DatatypeConverter.printBase64Binary(password.getBytes()).getBytes();
- byte[] plaintext = cipher.doFinal(encryptedText);
- decstr = new String(plaintext);
- // System.out.println(plaintextStr);
- /* String astring=
- ":aAb`BcVCd/eXDfEYg FZhi?jGk|HlmI,nJo@TKpqL.WMrsNt!uvwOx"+
- "<yPz>0QR12~3S4;^567U89%$#*()-_=+نهىإةوئٍِضـلياٌر؛؟،";
- int strlen = password.length();
- int aNum;
- for (int i=0;i<strlen;i++)
- {
- aNum=astring.indexOf(password.substring(i,i+1),0);
- aNum=aNum^15;
- decstr=decstr+astring.substring(aNum,aNum+1);
- }
- */
- }catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "decryptPassword",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_TWO);
- }
- return decstr;
- }
- /**
- * @METHOD NAME : updateUserInternetLocation
- * @INFORMATION : This method updates Internet users location for the passed employer numbers in both DB as well LDAP
- * @PARAM : List of userReferenceIds, locationId, connection
- * @RETURN : void
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY : Majed Alkabeer
- * @LAST MODIFIED DATE : 13/06/2010
- **/
- public static void updateUserInternetLocation(ArrayList usersList,
- short locationId,Connection connection) throws GOSIBatchException
- {
- //System.out.println("UPDATION STARTS **********");
- String updateQuery = null;
- String updateRequestQuery = null;
- String selectQuery = null;
- PreparedStatement psUpdate = null;
- PreparedStatement psUpdateRequest = null;
- PreparedStatement psSelect =null;
- ResultSet rs = null;
- BasicAttributes myAttrs = null;
- String refids="";
- if(usersList == null || usersList.size() ==0) return;
- refids=""+usersList.get(0).toString();
- for(int i=1;i<usersList.size();i++)
- refids+=", "+usersList.get(i).toString();
- try {
- updateQuery = "UPDATE T_USER_INTERNET SET LOCATION=? WHERE USERREFERENCEID in ("+refids+")";
- updateRequestQuery = "UPDATE T_USERIDREQUEST SET LOCATION=? WHERE REGISTRATIONNUMBER in ("+refids+")";
- selectQuery = "SELECT * FROM T_USER_INTERNET WHERE USERREFERENCEID in ("+refids+")";
- psUpdate=connection.prepareStatement(updateQuery);
- psUpdate.setLong(1,locationId);
- psUpdate.executeUpdate();
- psUpdateRequest=connection.prepareStatement(updateRequestQuery);
- psUpdateRequest.setLong(1,locationId);
- psUpdateRequest.executeUpdate();
- psSelect = connection.prepareStatement(selectQuery);
- rs = psSelect.executeQuery();
- while(rs.next())
- {
- String id = null;
- String password = null;
- String userLoginId = null;
- String userType = null;
- String accLockStatus = null;
- String keyPersonFlag = null;
- String defaultRoleId = null;
- String startDate = null;
- String longNameArabic = null;
- String location = null;
- String passwordUpdatedBy = null;
- String userRefId = null;
- String emailId = null;
- String endDate = null;
- String firstLogonDate = null;
- String lastPwdChgDate = null;
- id = new Long(rs.getLong("ID")).toString();
- password = decryptPassword(rs.getString("PASSWORD"));
- userLoginId = rs.getString("USERLOGINID");
- userType = new Long(rs.getLong("USERTYPE")).toString();
- accLockStatus = new Short(rs.getShort("ACCOUNTLOCKSTATUS")).toString();
- keyPersonFlag = new Byte(rs.getByte("KEYPERSONFLAG")).toString();
- defaultRoleId = new Long(rs.getLong("DEFAULTROLEID")).toString();
- startDate = GOSIBatchUtilities.getLdapDateFromTimestamp(rs.getTimestamp("STARTDATE"));
- longNameArabic = rs.getString("LONGNAMEARABIC");
- location = new Short(locationId).toString();
- passwordUpdatedBy = new Byte(rs.getByte("PASSWORDUPDATEDBY")).toString();
- userRefId = new Long(rs.getLong("USERREFERENCEID")).toString();
- if(rs.getString("EMAILID")!=null)
- {
- emailId = rs.getString("EMAILID");
- }
- if(rs.getTimestamp("ENDDATE")!=null)
- {
- endDate = GOSIBatchUtilities.
- getLdapDateFromTimestamp(
- rs.getTimestamp("ENDDATE"));
- }
- if(rs.getTimestamp("FIRSTLOGONDATE")!=null)
- {
- firstLogonDate = GOSIBatchUtilities.
- getLdapDateFromTimestamp(
- rs.getTimestamp("FIRSTLOGONDATE"));
- }
- if(rs.getTimestamp("LASTPASSWORDCHANGEDATE")!=null)
- {
- lastPwdChgDate = GOSIBatchUtilities.
- getLdapDateFromTimestamp(
- rs.getTimestamp("LASTPASSWORDCHANGEDATE"));
- }
- myAttrs = new BasicAttributes(true); // case ignore
- Attribute oc = new BasicAttribute("objectclass");
- oc.add(0,"user"); //objectclass
- oc.add(1,"top"); // keep same
- myAttrs.put(oc);// keep same
- myAttrs.put("userrecordid",id);
- myAttrs.put("userpassword",password);
- myAttrs.put("uid",userLoginId);
- myAttrs.put("usertype",userType);
- myAttrs.put("accountlockstatus",accLockStatus);
- myAttrs.put("keypersonflag",keyPersonFlag);
- myAttrs.put("defaultroleid",defaultRoleId);
- myAttrs.put("startdate", startDate);
- myAttrs.put("longnamearabic",longNameArabic);
- myAttrs.put("location",location);
- myAttrs.put("passwordupdatedby",passwordUpdatedBy);
- myAttrs.put("userreferenceid",userRefId);
- //Optional attributes
- String lastPwdUpdateDate = null;
- if(emailId!=null)
- {
- myAttrs.put("emailid", emailId);
- }
- if(endDate!=null)
- {
- myAttrs.put("enddate", endDate);
- }
- if(firstLogonDate!=null)
- {
- myAttrs.put("firstlogondate", firstLogonDate);
- }
- if(lastPwdChgDate!=null)
- {
- myAttrs.put("lastpasswordchangedate", lastPwdChgDate);
- }
- getDirContext();
- //System.out.println("BINDING STARTED : ");
- ctx.rebind("uid="+userLoginId+","+GOSIBatchProperties.
- GOSI_LDAP_ROOT_SUFFIX,null,myAttrs);
- //System.out.println("REBIND DONE*************** ");
- }
- }catch(Exception e)
- {
- e.printStackTrace();
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "updateUserInternetLocation",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally{
- GOSIBatchUtilities.cleanUp(psUpdate);
- GOSIBatchUtilities.cleanUp(psUpdateRequest);
- GOSIBatchUtilities.cleanUp(psSelect);
- GOSIBatchUtilities.cleanUp(rs);
- }
- }
- /**
- * @METHOD NAME : updateUserLocation
- * @INFORMATION : This method updates user location for the passed employee number in both DB as well LDAP
- * @PARAM : userReferenceId, locationId, connection
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void updateUserLocation(long userReferenceId,
- short locationId,Connection connection) throws GOSIBatchException
- {
- //System.out.println("UPDATION STARTS **********");
- String updateQuery = null;
- String selectQuery = null;
- PreparedStatement psUpdate = null;
- PreparedStatement psSelect =null;
- ResultSet rs = null;
- BasicAttributes myAttrs = null;
- try
- {
- updateQuery = GOSIBatchSQL.getSqlString("CMN_001_SQL_1035");
- //System.out.println("UPDATE QUERY : "+updateQuery);
- selectQuery = GOSIBatchSQL.getSqlString("CMN_001_SQL_1036");
- //System.out.println("SELECT QUERY : "+selectQuery);
- psUpdate=connection.prepareStatement(updateQuery);
- psUpdate.setLong(1,locationId);
- psUpdate.setLong(2,userReferenceId);
- psUpdate.setShort(3,GOSIBatchConstants.EMPLOYEE);
- psUpdate.executeUpdate();
- psSelect = connection.prepareStatement(selectQuery);
- psSelect.setLong(1,userReferenceId);
- psSelect.setShort(2,GOSIBatchConstants.EMPLOYEE);
- rs = psSelect.executeQuery();
- while(rs.next())
- {
- String id = null;
- String password = null;
- String userLoginId = null;
- String userType = null;
- String accLockStatus = null;
- String keyPersonFlag = null;
- String defaultRoleId = null;
- String startDate = null;
- String longNameArabic = null;
- String location = null;
- String passwordUpdatedBy = null;
- String userRefId = null;
- String accessType = null;
- String departmentCode = null;
- String emailId = null;
- String endDate = null;
- String firstLogonDate = null;
- String lastPwdChgDate = null;
- String longNameEnglish = null;
- String shortNameArabic = null;
- String shortNameEnglish = null;
- String passwordValidUpto = null;
- id = new Long(rs.getLong("ID")).toString();
- password = decryptPassword(rs.getString("PASSWORD"));
- userLoginId = rs.getString("USERLOGINID");
- userType = new Long(rs.getLong("USERTYPE")).toString();
- accLockStatus = new Short
- (rs.getShort("ACCOUNTLOCKSTATUS")).toString();
- keyPersonFlag = new Byte(rs.getByte("KEYPERSONFLAG")).toString();
- defaultRoleId = new Long(rs.getLong("DEFAULTROLEID")).toString();
- startDate = GOSIBatchUtilities.getLdapDateFromTimestamp(
- rs.getTimestamp("STARTDATE"));
- longNameArabic = rs.getString("LONGNAMEARABIC");
- location = new Short(locationId).toString();
- passwordUpdatedBy = new Byte(rs.getByte("PASSWORDUPDATEDBY")).toString();
- userRefId = new Long(rs.getLong("USERREFERENCEID")).toString();
- if(rs.getString("EMAILID")!=null)
- {
- emailId = rs.getString("EMAILID");
- }
- if(rs.getTimestamp("ENDDATE")!=null)
- {
- endDate = GOSIBatchUtilities.
- getLdapDateFromTimestamp(
- rs.getTimestamp("ENDDATE"));
- }
- if(rs.getTimestamp("FIRSTLOGONDATE")!=null)
- {
- firstLogonDate = GOSIBatchUtilities.
- getLdapDateFromTimestamp(
- rs.getTimestamp("FIRSTLOGONDATE"));
- }
- if(rs.getTimestamp("LASTPASSWORDCHANGEDATE")!=null)
- {
- lastPwdChgDate = GOSIBatchUtilities.
- getLdapDateFromTimestamp(
- rs.getTimestamp("LASTPASSWORDCHANGEDATE"));
- }
- myAttrs = new BasicAttributes(true); // case ignore
- Attribute oc = new BasicAttribute("objectclass");
- oc.add(0,"user"); //objectclass
- oc.add(1,"top"); // keep same
- myAttrs.put(oc);// keep same
- myAttrs.put("userrecordid",id);
- myAttrs.put("userpassword",password);
- myAttrs.put("uid",userLoginId);
- myAttrs.put("usertype",userType);
- myAttrs.put("accountlockstatus",accLockStatus);
- myAttrs.put("keypersonflag",keyPersonFlag);
- myAttrs.put("defaultroleid",defaultRoleId);
- myAttrs.put("startdate", startDate);
- myAttrs.put("longnamearabic",longNameArabic);
- myAttrs.put("location",location);
- myAttrs.put("passwordupdatedby",passwordUpdatedBy);
- myAttrs.put("userreferenceid",userRefId);
- //Optional attributes
- String lastPwdUpdateDate = null;
- if(emailId!=null)
- {
- myAttrs.put("emailid", emailId);
- }
- if(endDate!=null)
- {
- myAttrs.put("enddate", endDate);
- }
- if(firstLogonDate!=null)
- {
- myAttrs.put("firstlogondate", firstLogonDate);
- }
- if(lastPwdChgDate!=null)
- {
- myAttrs.put("lastpasswordchangedate", lastPwdChgDate);
- }
- getDirContext();
- //System.out.println("BINDING STARTED : ");
- ctx.rebind("uid="+userLoginId+","+GOSIBatchProperties.
- GOSI_LDAP_ROOT_SUFFIX,null,myAttrs);
- //System.out.println("REBIND DONE*************** ");
- }
- }catch(Exception e)
- {
- e.printStackTrace();
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "updateUserLocation",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : viewUserLocation
- * @INFORMATION : This method views user location for the passed employee number in both DB as well LDAP
- * @PARAM : userReferenceId, locationId, connection
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static Short viewUserLocation(long userReferenceId,
- short locationId,Connection connection) throws GOSIBatchException
- {
- //System.out.println("UPDATION STARTS **********");
- String updateQuery = null;
- String selectQuery = null;
- PreparedStatement psUpdate = null;
- PreparedStatement psSelect =null;
- ResultSet rs = null;
- BasicAttributes myAttrs = null;
- Short location = null;
- try
- {
- // updateQuery = GOSIBatchSQL.getSqlString("CMN_001_SQL_1035");
- //System.out.println("UPDATE QUERY : "+updateQuery);
- selectQuery = GOSIBatchSQL.getSqlString("CMN_001_SQL_1036");
- //System.out.println("SELECT QUERY : "+selectQuery);
- psSelect = connection.prepareStatement(selectQuery);
- psSelect.setLong(1,userReferenceId);
- psSelect.setShort(2,GOSIBatchConstants.EMPLOYEE);
- rs = psSelect.executeQuery();
- while(rs.next())
- {
- location = new Short(rs.getShort("LOCATION"));
- }
- }catch(Exception e)
- {
- e.printStackTrace();
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "updateUserLocation",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return location;
- }
- /**
- * @METHOD NAME : getDateFullString
- * @INFORMATION : This method gets Timestamp as single parameter
- * and returns String having date in dd/mm/yyyy format.
- * @PARAM : ts
- * @RETURN : class java.lang.String
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static String getDateFullString(Timestamp ts)
- throws GOSIBatchException
- {
- String dateString="";
- try
- {
- if(ts!=null)
- {
- String dateStr = ts.toString();
- dateStr = dateStr.substring(0,10);
- StringTokenizer strTok = new StringTokenizer(dateStr,"-");
- String retStr[] = new String[3];
- while(strTok.hasMoreTokens())
- {
- retStr[2] = (String) strTok.nextToken();
- retStr[1] = (String)strTok.nextToken();
- retStr[0] = (String) strTok.nextToken();
- }
- StringBuffer dd = new StringBuffer(retStr[0]);
- StringBuffer mm = new StringBuffer(retStr[1]);
- StringBuffer yyyy = new StringBuffer(retStr[2]);
- dd.append("/");
- dd.append(mm);
- dd.append("/");
- dd.append(yyyy);
- dateString =dd.toString();
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getDateFullString",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return dateString;
- }
- /**
- * @METHOD NAME : getEmailListForRoleAndLocation
- * @INFORMATION : This method returns the list of email list
- * for given employee number list
- * @PARAM : employeeNumberList
- * @RETURN : class java.util.HashMap
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static ArrayList <String> getEmailListForRoleAndLocation(Short locationCode,
- Short roleId)
- throws GOSIBatchException
- {
- ArrayList <String>emailIdList =null;
- ResultSet rs=null;
- PreparedStatement ps = null;
- Connection cn =null;
- try
- {
- cn=getDbConnection(GOSIBatchConstants.COMMON);
- String query=
- "SELECT emailid FROM t_user WHERE LOCATION = ? AND id IN "+
- " (SELECT userrecordid FROM t_userrolemap WHERE roleid =? "+
- " AND startdate <= SYSDATE AND NVL (enddate, SYSDATE) <= SYSDATE) ";
- ps=cn.prepareStatement(query);
- ps.setShort(1,locationCode);
- ps.setShort(2,roleId);
- rs=ps.executeQuery();
- if (rs.next())
- {
- emailIdList =new ArrayList<String>();
- do
- {
- String emailId=rs.getString("EMAILID");
- emailIdList.add(emailId);
- }
- while(rs.next());
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getEmailListForRoleAndLocation",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs,ps,cn);
- }
- return emailIdList;
- }
- /**
- * @METHOD NAME : getEmailIdList
- * @INFORMATION : This method returns the list of email list
- * for given employee number list
- * @PARAM : employeeNumberList
- * @RETURN : class java.util.HashMap
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static HashMap getEmailIdList(ArrayList employeeNumberList)
- throws GOSIBatchException
- {
- HashMap emailIdList=new HashMap();
- ResultSet rs=null;
- PreparedStatement ps = null;
- Connection cn =null;
- try
- {
- if(employeeNumberList!=null)
- {
- short moduleId=
- ((Short)employeeNumberList.get(0)).shortValue();
- cn=getDbConnection(GOSIBatchConstants.COMMON);
- }
- String query=
- "SELECT USERREFERENCEID,EMAILID FROM "+
- " T_USER WHERE "+
- " USERREFERENCEID in(";
- if(
- (employeeNumberList!=null)
- &&(employeeNumberList.size()>0)
- )
- {
- for(int i=1;i<employeeNumberList.size();i++)
- {
- if(i==employeeNumberList.size()-1)
- {
- query=query+"?";
- }
- else
- {
- query=query+"?,";
- }
- }
- query=query+") AND USERTYPE=?";
- //System.out.println("query="+query);
- ps=cn.prepareStatement(query);
- Long employeeNumber=null;
- String szEmployeeNumber =null;
- for(int i=1;i<employeeNumberList.size();i++)
- {
- employeeNumber = (Long)employeeNumberList.get(i);
- ps.setLong(i,employeeNumber.longValue());
- }
- int size=employeeNumberList.size();
- ps.setShort(size,GOSIBatchConstants.EMPLOYEE);
- rs=ps.executeQuery();
- while(rs.next())
- {
- //System.out.println("Inside the result set");
- String emailId=rs.getString("EMAILID");
- String userReferenceid=rs.getString("USERREFERENCEID");
- emailIdList.put(userReferenceid,emailId);
- }
- }
- }catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getDateFullString",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs,ps,cn);
- }
- return emailIdList;
- }
- /**
- * @METHOD NAME : getEmailIdListForUserRecord
- * @INFORMATION : This method returns list of email list for
- given user record list
- * @PARAM : userRecordList
- * @RETURN : HashMap
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static HashMap getEmailIdListForUserRecord(ArrayList userRecordList)
- throws GOSIBatchException
- {
- HashMap emailIdList=new HashMap();
- ResultSet rs=null;
- PreparedStatement ps = null;
- Connection cn =null;
- try
- {
- if(userRecordList!=null)
- {
- long moduleId=
- ((Long)userRecordList.get(0)).longValue();
- cn=getDbConnection(GOSIBatchConstants.COMMON);
- }
- //System.out.println("User Record List size : "+userRecordList);
- String query=
- "SELECT ID,EMAILID FROM "+
- " T_USER WHERE "+
- " ID in(";
- if((userRecordList!=null)&&(userRecordList.size()>0))
- {
- for(int i=0;i<userRecordList.size();i++)
- {
- if(i==userRecordList.size()-1)
- {
- query=query+"?";
- }
- else
- {
- query=query+"?,";
- }
- }
- query=query+") AND USERTYPE=?";
- //System.out.println("query="+query);
- ps=cn.prepareStatement(query);
- Long userRecordId=null;
- String szEmployeeNumber =null;
- int size=userRecordList.size();
- //System.out.println("Size : "+size);
- for(int i=1;i<=size;i++)
- {
- //System.out.println("setting : "+i);
- userRecordId = (Long)userRecordList.get(i-1);
- ps.setLong(i,userRecordId.longValue());
- }
- ps.setShort(size+1,GOSIBatchConstants.EMPLOYEE);
- rs=ps.executeQuery();
- while(rs.next())
- {
- //System.out.println("Inside the result set");
- String emailId=rs.getString("EMAILID");
- Long userRecord=new Long(rs.getLong("ID"));
- emailIdList.put(userRecord,emailId);
- }
- }
- }catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getDateFullString",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs,ps,cn);
- }
- return emailIdList;
- }
- /**
- * @METHOD NAME : getTimestamp
- * @INFORMATION : This method gets three parameters namely day, month
- * and year and returns Timestamp object after formatting it.
- * @PARAM : day, mon, year
- * @RETURN : class java.sql.Timestamp
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static Timestamp getTimestamp(String day,String mon,String year)
- throws GOSIBatchException
- {
- Timestamp timeStamp=null;
- try
- {
- if((day!=null)&&(mon!=null)&&(year!=null))
- {
- // Fix a comatability with java 6
- // Java 6 does not allow input not strictly
- // complies to the format yyyy-mm-dd hh:mm:ss[.fffffffff]
- // so we will make the necessary adjustment
- if (day.length() == 1)
- day = "0"+day;
- if (mon.length() == 1)
- mon = "0" +mon;
- StringBuffer dd = new StringBuffer(day);
- StringBuffer mm = new StringBuffer(mon);
- StringBuffer yyyy = new StringBuffer(year);
- yyyy.append("-");
- yyyy.append(mm);
- yyyy.append("-");
- yyyy.append(dd);
- yyyy.append(" 0:0:0.0");
- String str = yyyy.toString();
- timeStamp=Timestamp.valueOf(str);
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getTimestamp",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return timeStamp;
- }
- /**
- * @METHOD NAME : getTimestamp
- * @INFORMATION : This method gets the date in String format as an
- * argument and returns Timestamp object after formatting it.
- * @PARAM : fullDate
- * @RETURN : class java.sql.Timestamp
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static Timestamp getTimestamp(String fullDate)
- throws GOSIBatchException
- {
- Timestamp timeStamp=null;
- try
- {
- if(fullDate!=null)
- {
- String year=null;
- String month=null;
- String date=null;
- StringTokenizer st=new StringTokenizer(fullDate,"-/");
- while(st.hasMoreTokens())
- {
- date=st.nextToken();
- month=st.nextToken();
- year=st.nextToken();
- }
- // Fix a comatability with java 6
- // Java 6 does not allow input not strictly
- // complies to the format yyyy-mm-dd hh:mm:ss[.fffffffff]
- // so we will make the necessary adjustment
- if (date.length() == 1)
- date = "0"+date;
- if (month.length() == 1)
- month = "0" +month;
- StringBuffer dd = new StringBuffer(date);
- StringBuffer mm = new StringBuffer(month);
- StringBuffer yyyy = new StringBuffer(year);
- yyyy.append("-");
- yyyy.append(mm);
- yyyy.append("-");
- yyyy.append(dd);
- yyyy.append(" 0:0:0.0");
- String str = yyyy.toString();
- timeStamp=Timestamp.valueOf(str);
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getTimestamp",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return timeStamp;
- }
- /**
- * @METHOD NAME : getSystemUserLocation
- * @INFORMATION : This method takes the module name for getting the connection and returns the
- * location id of the system user
- * @PARAM : moduleName
- * @RETURN : short
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static short getSystemUserLocation(String moduleName)
- throws GOSIBatchException
- {
- short locationId=0;
- Connection connection = null;
- PreparedStatement psUserLocation = null;
- ResultSet rsUserLocation = null;
- try
- {
- String query = GOSIBatchSQL.getSqlString("CMN_001_SQL_1051");
- connection = getDbConnection(moduleName);
- psUserLocation = connection.prepareStatement(query);
- psUserLocation.setString(1, GOSIBatchProperties.SYSTEM_USER);
- rsUserLocation = psUserLocation.executeQuery();
- if(rsUserLocation.next())
- {
- locationId = rsUserLocation.getShort("LOCATION");
- }
- }catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getTimestamp",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rsUserLocation,
- psUserLocation, connection);
- }
- return locationId;
- }
- /**
- * @METHOD NAME : getFieldOfficeForVillage
- * @INFORMATION : This method returns the fieldOffice code for the
- given villageId
- * @PARAM : villageId, moduleName
- * @RETURN : Short
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public Short getFieldOfficeForVillage
- (Long villageId,String moduleName)
- throws GOSIBatchException
- {
- Connection connection=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- Short foCode=null;
- String query=null;
- try
- {
- query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1037");
- connection = getDbConnection(moduleName);
- ps=connection.prepareStatement(query);
- ps.setLong(1,villageId.longValue());
- rs=ps.executeQuery();
- while(rs.next())
- {
- foCode=new Short(rs.getShort("FOCODE"));
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getFieldOfficeForVillage()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs,ps,connection);
- }
- return foCode;
- }
- /**
- * @METHOD NAME : getModuleName
- * @INFORMATION : This method returns the corresponding moduleName
- for the moduleId passed
- * @PARAM : moduleId
- * @RETURN : class java.lang.String
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static String getModuleName
- (short moduleId)
- throws GOSIBatchException
- {
- String moduleName = null;
- try
- {
- switch(moduleId)
- {
- case GOSIBatchConstants.BUDGET_ID :
- moduleName = GOSIBatchConstants.BUDGET;
- break;
- case GOSIBatchConstants.COMMON_ID :
- moduleName = GOSIBatchConstants.COMMON;
- break;
- case GOSIBatchConstants.CONTRACT_ID:
- moduleName = GOSIBatchConstants.CONTRACT;
- break;
- case GOSIBatchConstants.FINANCE_ID:
- moduleName = GOSIBatchConstants.FINANCE;
- break;
- case GOSIBatchConstants.INVESTMENT_ID:
- moduleName = GOSIBatchConstants.INVESTMENT;
- break;
- case GOSIBatchConstants.INVENTORY_ID:
- moduleName = GOSIBatchConstants.INVENTORY;
- break;
- case GOSIBatchConstants.PERSONNEL_ID:
- moduleName = GOSIBatchConstants.PERSONNEL;
- break;
- case GOSIBatchConstants.PURCHASE_ID:
- moduleName = GOSIBatchConstants.PURCHASE;
- break;
- case GOSIBatchConstants.REAL_ESTATE_ID :
- moduleName = GOSIBatchConstants.REAL_ESTATE;
- break;
- case GOSIBatchConstants.SECURITY_ID :
- moduleName = GOSIBatchConstants.SECURITY;
- break;
- case GOSIBatchConstants.SOCIAL_INSURANCE_ID :
- moduleName = GOSIBatchConstants.SOCIAL_INSURANCE;
- break;
- case GOSIBatchConstants.WORKFLOW_ID :
- moduleName = GOSIBatchConstants.WORKFLOW;
- break;
- case GOSIBatchConstants.FIXED_ASSET_ID :
- moduleName = GOSIBatchConstants.FIXED_ASSET;
- break;
- case GOSIBatchConstants.REGISTRATION_ID :
- moduleName = GOSIBatchConstants.REGISTRATION;
- break;
- case GOSIBatchConstants.ANNUITIES_ID :
- moduleName = GOSIBatchConstants.ANNUITIES;
- break;
- case GOSIBatchConstants.OCCUPATIONAL_HAZARDS_ID :
- moduleName = GOSIBatchConstants.OCCUPATIONAL_HAZARDS;
- break;
- case GOSIBatchConstants.CONTRIBUTION_ID :
- moduleName = GOSIBatchConstants.CONTRIBUTION;
- break;
- case GOSIBatchConstants.PROJECT_ID :
- moduleName = GOSIBatchConstants.PROJECT;
- break;
- case GOSIBatchConstants.DATAWAREHOUSING_ID:
- moduleName = GOSIBatchConstants.DATAWAREHOUSING;
- break;
- case GOSIBatchConstants.INTERFACE_ID:
- moduleName = GOSIBatchConstants.INTERFACE;
- break;
- default:
- break;
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getModuleName()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- return moduleName;
- }
- }
- /**
- * @METHOD NAME : getDomainDetailsName
- * @INFORMATION : This method returns the corresponding domaindetails shortname
- for given domainname and domain code
- * @PARAM : domainName, code, bIsArabic, moduleName
- * @RETURN : class java.lang.String
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static String getDomainDetailsName(String domainName,
- Short code, boolean bIsArabic, String moduleName)
- throws GOSIBatchException
- {
- Connection connection=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- String domainDetailsName = null;
- String queryEn=null;
- String queryAr=null;
- try
- {
- queryAr=GOSIBatchSQL.getSqlString("CMN_001_SQL_1052");
- queryEn=GOSIBatchSQL.getSqlString("CMN_001_SQL_1053");
- connection = getDbConnection(moduleName);
- if(bIsArabic)
- {
- ps=connection.prepareStatement(queryAr);
- //System.out.println("query : "+ queryAr);
- }
- else
- {
- ps=connection.prepareStatement(queryEn);
- //System.out.println("query : "+queryEn);
- }
- //System.out.println("Utilities : domainName : "+domainName);
- //System.out.println("Utitities : code "+code);
- // System.out.println("Utitities : code "+code);
- ps.setString(1,domainName);
- ps.setShort(2,code.shortValue());
- rs=ps.executeQuery();
- //System.out.println("Executed : ");
- while(rs.next())
- {
- if(bIsArabic)
- {
- domainDetailsName=rs.getString("SHORTNAMEARABIC");
- }
- else
- {
- domainDetailsName=rs.getString("SHORTNAMEENGLISH");
- }
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getDomainDetailsName()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs,ps,connection);
- }
- return domainDetailsName;
- }
- /**
- * @METHOD NAME : getCorporateContactDetails
- * @INFORMATION : This method returns the Corporate contact details for the given contact id
- * @PARAM : contactid, moduleName
- * @RETURN :
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static CorporateContactBean getCorporateContactDetails(long contactId,
- String moduleName)throws GOSIBatchException
- {
- Connection connection=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- String domainDetailsName = null;
- String queryAr=null;
- CorporateContactBean corporateContactBean = null;
- try
- {
- queryAr=GOSIBatchSQL.getSqlString("CMN_001_SQL_1054");
- connection = getDbConnection(moduleName);
- ps=connection.prepareStatement(queryAr);
- ps.setLong(1,contactId);
- rs=ps.executeQuery();
- //System.out.println("Executed : ");
- if(rs.next())
- {
- corporateContactBean = new CorporateContactBean();
- corporateContactBean.setLanguageType(rs.getString("LANGUAGETYPE"));
- corporateContactBean.setFreeTextDescription(rs.getString("FREETEXTDESCRIPTION"));
- corporateContactBean.setBuildingNumber(rs.getString("BUILDINGNUMBER"));
- corporateContactBean.setStreet(rs.getString("STREET"));
- corporateContactBean.setArea(rs.getString("AREA"));
- corporateContactBean.setCity(rs.getString("CITY"));
- corporateContactBean.setCountry(rs.getShort("COUNTRY"));
- corporateContactBean.setPoBox(rs.getString("POBOX"));
- corporateContactBean.setZipCode(rs.getString("ZIPCODE"));
- corporateContactBean.setExtension(rs.getString("EXTENSION"));
- corporateContactBean.setFaxNumber(rs.getString("FAXNUMBER"));
- corporateContactBean.setEmailId(rs.getString("EMAILID"));
- corporateContactBean.setCurrentMailingAddrInd(rs.getByte("CURRENTMAILINGADDRIND"));
- if(rs.getString("VILLAGEID")!=null)
- {
- corporateContactBean.setVillageId(new Long(rs.getLong("VILLAGEID")));
- }
- corporateContactBean.setFreeTextDescription2(rs.getString("FREETEXTDESCRIPTION2"));
- corporateContactBean.setExtension1(rs.getString("EXTENSION1"));
- corporateContactBean.setExtension2(rs.getString("EXTENSION2"));
- corporateContactBean.setExtension3(rs.getString("EXTENSION3"));
- corporateContactBean.setExtension4(rs.getString("EXTENSION4"));
- corporateContactBean.setTelephoneNumber1(rs.getString("TELEPHONENUMBER1"));
- corporateContactBean.setTelephoneNumber2(rs.getString("TELEPHONENUMBER2"));
- corporateContactBean.setTelephoneNumber3(rs.getString("TELEPHONENUMBER3"));
- corporateContactBean.setTelephoneNumber4(rs.getString("TELEPHONENUMBER4"));
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getCorporateContactDetails()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs,ps,connection);
- }
- return corporateContactBean;
- }
- /**
- * @METHOD NAME : getIndividualContactDetails
- * @INFORMATION : This method returns the Individual contact details for the given contact id
- * @PARAM : contactid, moduleName
- * @RETURN :
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static IndividualContactBean getIndividualContactDetails(long contactId,
- String moduleName)throws GOSIBatchException
- {
- Connection connection=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- String domainDetailsName = null;
- String queryAr=null;
- IndividualContactBean individualContactBean = null;
- try
- {
- queryAr=GOSIBatchSQL.getSqlString("CMN_001_SQL_1055");
- connection = getDbConnection(moduleName);
- ps=connection.prepareStatement(queryAr);
- //System.out.println("Query is : "+queryAr+" Contact ID : "+contactId);
- ps.setLong(1,contactId);
- rs=ps.executeQuery();
- //System.out.println("Executed : ");
- if(rs.next())
- {
- //System.out.println("RECORD FOUND ");
- individualContactBean = new IndividualContactBean();
- individualContactBean.setLanguageType(rs.getString("LANGUAGETYPE"));
- individualContactBean.setFreeTextDescription(rs.getString("FREETEXTDESCRIPTION"));
- individualContactBean.setBuildingNumber(rs.getString("BUILDINGNUMBER"));
- individualContactBean.setStreet(rs.getString("STREET"));
- individualContactBean.setArea(rs.getString("AREA"));
- individualContactBean.setCity(rs.getString("CITY"));
- individualContactBean.setCountry(rs.getShort("COUNTRY"));
- individualContactBean.setPoBox(rs.getString("POBOX"));
- individualContactBean.setZipCode(rs.getString("ZIPCODE"));
- individualContactBean.setTelephoneNumber(rs.getString("TELEPHONENUMBER"));
- individualContactBean.setExtension(rs.getString("EXTENSION"));
- individualContactBean.setFaxNumber(rs.getString("FAXNUMBER"));
- individualContactBean.setEmailId(rs.getString("EMAILID"));
- individualContactBean.setCurrentMailingAddrInd(rs.getByte("CURRENTMAILINGADDRIND"));
- individualContactBean.setMobileNumber(rs.getString("MOBILENUMBER"));
- if(rs.getString("VILLAGEID")!=null)
- {
- individualContactBean.setVillageId(new Long(rs.getLong("VILLAGEID")));
- }
- individualContactBean.setFreeTextDescription2(rs.getString("FREETEXTDESCRIPTION2"));
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getIndividualContactDetails()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs,ps,connection);
- }
- return individualContactBean;
- }
- /**
- * @METHOD NAME : getFieldOfficeVillageMappingDetails
- * @INFORMATION :This method returns
- the field office village
- mapping details with village start
- date greater than the date passed
- as a parameter
- * @PARAM : startDate
- * @RETURN : class java.util.ArrayList
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static ArrayList getFieldOfficeVillageMappingDetails
- (Timestamp fieldOfficeMappingDate)throws GOSIBatchException
- {
- Connection connection = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- String query = null;
- ArrayList fieldOfficeVillageMapList = new ArrayList();
- ArrayList tempFieldOfficeVillageMapList = new ArrayList();
- Short fieldOffice = null;
- Timestamp startDate = null;
- Short tempFieldOffice = null;
- Timestamp tempStartDate = null;
- int index = 0;
- int counter = 0;
- int tempListSize = 0;
- int listSize = 0;
- try
- {
- //System.out.println("fieldOfficeMappingDate" + fieldOfficeMappingDate);
- query = GOSIBatchSQL.getSqlString("CMN_010_SQL_1001");
- //System.out.println(" query" + query);
- connection = getDbConnection(GOSIBatchConstants.COMMON);
- ps = connection.prepareStatement(query);
- ps.setTimestamp(1,fieldOfficeMappingDate);
- rs = ps.executeQuery();
- while(rs.next())
- {
- FieldOfficeVillageMapListBean fieldOfficeBean =
- new FieldOfficeVillageMapListBean();
- fieldOfficeBean.setFOCode
- (new Short(rs.getShort(1)));
- fieldOfficeBean.setStartDate
- (rs.getTimestamp(2));
- if(fieldOfficeBean.getStartDate()!= null)
- {
- fieldOfficeBean.setStartDateStr
- (getDateFullString
- (fieldOfficeBean.getStartDate()));
- }
- tempFieldOfficeVillageMapList.
- add(fieldOfficeBean);
- }
- //System.out.println(" temp fieldOfficeVillageMapList size" +
- //tempFieldOfficeVillageMapList.size());
- tempListSize = tempFieldOfficeVillageMapList.size();
- //System.out.println(" tempListSize" + tempListSize);
- if(tempListSize > 0)
- {
- FieldOfficeVillageMapListBean tempFieldOfficeBean =
- new FieldOfficeVillageMapListBean();
- FieldOfficeVillageMapListBean finalFieldOfficeBean =
- new FieldOfficeVillageMapListBean();
- for(index = 0;index < tempListSize;index ++)
- {
- finalFieldOfficeBean =
- (FieldOfficeVillageMapListBean)
- tempFieldOfficeVillageMapList.get(index);
- if(fieldOfficeVillageMapList.size() == 0)
- {
- //System.out.println(" in zero" );
- fieldOfficeVillageMapList.add
- (finalFieldOfficeBean);
- }
- else
- {
- boolean flag = true;
- fieldOffice =
- finalFieldOfficeBean.getFOCode();
- //System.out.println("fieldOffice" +
- //fieldOffice);
- startDate =
- finalFieldOfficeBean.getStartDate();
- //System.out.println("start date" +
- //startDate);
- listSize =
- fieldOfficeVillageMapList.size();
- for(counter = 0;counter < listSize;counter ++)
- {
- tempFieldOfficeBean =
- (FieldOfficeVillageMapListBean)
- fieldOfficeVillageMapList.get(counter);
- tempFieldOffice =
- tempFieldOfficeBean.getFOCode();
- //System.out.println("temp fieldOffice" +
- //tempFieldOffice);
- tempStartDate =
- tempFieldOfficeBean.getStartDate();
- //System.out.println(" temp start date" +
- //tempStartDate);
- if((tempFieldOffice.equals(fieldOffice))
- &&(tempStartDate.equals(startDate)))
- {
- //System.out.println("inside equal");
- flag = false;
- break;
- }
- }
- if(flag)
- {
- //System.out.println(" inside");
- fieldOfficeVillageMapList.
- add(finalFieldOfficeBean);
- }
- }
- }
- }
- //System.out.println(" fieldOfficeVillageMapList size" +
- //fieldOfficeVillageMapList.size());
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore","GOSIBatchUtilities",
- "getFieldOfficeVillageMappingDetails()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs,ps,connection);
- }
- return fieldOfficeVillageMapList;
- }
- protected static void setCurrentSystemTime(Timestamp currentDate)
- {
- currentSystemDate = currentDate;
- }
- public static void main(String a[])
- {
- try
- {
- String domainName = getDomainDetailsName("Location",
- new Short((short)1), true, GOSIBatchConstants.COMMON);
- //System.out.println("DOMAIN NAME : "+domainName);
- }catch(Exception e)
- {}
- }
- /**
- * @METHOD NAME : createRequest
- * @INFORMATION : This method is used to create a batch request
- * @PARAM : batchRequestBean, conn
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void createRequest(BatchRequestBean batchRequestBean,
- Connection conn, long requestedBy) throws GOSIBatchException
- {
- BatchParametersBean batchParametersBean = null;
- try
- {
- batchRequestBean.setRequestId(new Long((getPrimaryKey("T_BATCHREQUEST",
- getSystemUser())).longValue()));
- //System.out.println(batchRequestBean.getRequestId()+"sss");
- //System.out.println(batchRequestBean.getBatchId()+"sss");
- //System.out.println(batchRequestBean.getRunDate()+"sss");
- //System.out.println(batchRequestBean.getRequestedBy()+"sss");
- //System.out.println(batchRequestBean.getRequestedTimeStamp()+"sss");
- psInsertBatchRequest.setLong(1,
- batchRequestBean.getRequestId().longValue());
- psInsertBatchRequest.setTimestamp(2, batchRequestBean.getRunDate());
- psInsertBatchRequest.setString(3, batchRequestBean.getBatchId());
- psInsertBatchRequest.setLong(4,
- requestedBy);
- psInsertBatchRequest.setTimestamp(5,
- batchRequestBean.getRequestedTimeStamp());
- psInsertBatchRequest.addBatch();
- if(batchRequestBean.getParamValueList()!=null)
- {
- ArrayList paramValueList = batchRequestBean.getParamValueList();
- int size = paramValueList.size();
- for(int i=0; i<size; i++)
- {
- batchParametersBean = (BatchParametersBean)
- paramValueList.get(i);
- psInsertParamValues.setLong(1,
- batchRequestBean.getRequestId().longValue());
- psInsertParamValues.setLong(2,
- batchParametersBean.getParamId().longValue());
- psInsertParamValues.setString(3,
- batchParametersBean.getParamValue());
- psInsertParamValues.addBatch();
- }
- }
- }
- catch(Exception e)
- {
- new GOSIBatchException(e, "BatchCore", "GOSIUtilities",
- "createRequest", "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : createRequest
- * @INFORMATION : This method is used to create a batch request
- * @PARAM : batchRequestBean, conn
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void createRequest(BatchRequestBean batchRequestBean,
- Connection conn) throws GOSIBatchException
- {
- createRequest(batchRequestBean, conn, getSystemUser());
- }
- /**
- * @METHOD NAME : getDateDifference
- * @INFORMATION : This method is used to find difference between
- * two Timestamps dates in number of days.
- * @PARAM : fromTimestamp, toTimestamp
- * @RETURN : int
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static int getDateDifference(Timestamp fromTimestamp,
- Timestamp toTimestamp) throws GOSIBatchException
- {
- int fromDay=0;
- int fromMonth=0;
- int fromYear=0;
- int toDay=0;
- int toMonth=0;
- int toYear=0;
- GregorianCalendar gc1 = null;
- GregorianCalendar gc2 = null;
- String fromDate=null;
- String toDate=null;
- int diffDays =0;
- try
- {
- if((fromTimestamp!=null)&&(toTimestamp!=null))
- {
- fromDate=getDateFullString(fromTimestamp);
- toDate=getDateFullString(toTimestamp);
- StringTokenizer greStrDate =
- new StringTokenizer(fromDate,"/-");
- while(greStrDate .hasMoreTokens())
- {
- fromDay = Integer.
- valueOf(greStrDate .nextToken()).intValue();
- if(greStrDate.hasMoreTokens())
- {
- fromMonth = Integer.
- valueOf(greStrDate.nextToken()).intValue();
- }
- if(greStrDate.hasMoreTokens())
- {
- fromYear = Integer.
- valueOf(greStrDate.nextToken()).intValue();
- }
- }//while
- gc1 = new GregorianCalendar(fromYear,fromMonth-1,fromDay);
- StringTokenizer greStrToDate = new StringTokenizer(toDate,"/-");
- while(greStrToDate .hasMoreTokens())
- {
- toDay = Integer.valueOf(greStrToDate .nextToken()).intValue();
- if(greStrToDate.hasMoreTokens())
- {
- toMonth = Integer.
- valueOf(greStrToDate.nextToken()).intValue();
- }
- if(greStrToDate.hasMoreTokens())
- {
- toYear = Integer.
- valueOf(greStrToDate.nextToken()).intValue();
- }
- }//while
- gc2 = new GregorianCalendar(toYear,toMonth-1,toDay);
- diffDays = gregorianDateDifference(gc1,gc2);
- }
- }//try
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "getDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }//catch
- return diffDays;
- }//method
- /**
- * @METHOD NAME : getGregorianDateDifference
- * @INFORMATION : This method is used to find difference between
- * two gregorian dates in number of days.
- * @PARAM : fromDate, toDate
- * @RETURN : int
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static int getGregorianDateDifference(String fromDate,String toDate)
- throws GOSIBatchException
- {
- int fromDay=0;
- int fromMonth=0;
- int fromYear=0;
- int toDay=0;
- int toMonth=0;
- int toYear=0;
- GregorianCalendar gc1 = null;
- GregorianCalendar gc2 = null;
- int diffDays =0;
- try
- {
- validateGregorianDate(fromDate);
- validateGregorianDate(toDate);
- StringTokenizer greStrDate = new StringTokenizer(fromDate,"/-");
- while(greStrDate .hasMoreTokens())
- {
- fromDay = Integer.valueOf(greStrDate .nextToken()).intValue();
- if(greStrDate.hasMoreTokens())
- {
- fromMonth = Integer.valueOf(greStrDate.nextToken()).
- intValue();
- }
- if(greStrDate.hasMoreTokens())
- {
- fromYear = Integer.valueOf(greStrDate.nextToken()).
- intValue();
- }
- }//while
- gc1 = new GregorianCalendar(fromYear,fromMonth-1,fromDay);
- StringTokenizer greStrToDate = new StringTokenizer(toDate,"/-");
- while(greStrToDate .hasMoreTokens())
- {
- toDay = Integer.valueOf(greStrToDate .nextToken()).intValue();
- if(greStrToDate.hasMoreTokens())
- {
- toMonth = Integer.valueOf(greStrToDate.nextToken()).
- intValue();
- }
- if(greStrToDate.hasMoreTokens())
- {
- toYear = Integer.valueOf(greStrToDate.nextToken()).
- intValue();
- }
- }//while
- gc2 = new GregorianCalendar(toYear,toMonth-1,toDay);
- diffDays = gregorianDateDifference(gc1,gc2);
- if(diffDays!=0)
- {
- diffDays++;
- }
- else if((diffDays==0)&&(fromDate.equals(toDate)))
- {
- diffDays++;
- }
- }//try
- catch(GOSIBatchException e)
- {
- throw e;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }//catch
- return diffDays;
- }//method
- /**
- * @METHOD NAME : validateGregorianDate
- * @INFORMATION : This method takes the date in string (DD/MM/YYYY)
- * format and validates it against gregorian date.
- * If it is not valid gregorian date then, throws the
- * GOSIException
- * @PARAM : gDate
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void validateGregorianDate(String gDate)
- throws GOSIBatchException
- {
- try
- {
- if((gDate == null)||(gDate.length()==0))
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- checkDateFormat(gDate);
- int count =0;
- for(int i=0;i< gDate.length();i++)
- {
- char c = gDate.charAt(i);
- if(Character.isDigit(c))
- {}
- else
- {
- if(c=='/')
- {
- count = count +1;
- if(count<=2)
- {
- continue;
- }
- else
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- else
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }//else
- }//for
- int fIndex = gDate.indexOf('/');
- int lIndex = gDate.lastIndexOf('/');
- int day = Integer.parseInt(gDate.substring(0,fIndex));
- int month = Integer.parseInt(gDate.substring((fIndex+1),lIndex));
- String yy = gDate.substring((lIndex+1),gDate.length());
- int year = Integer.parseInt(yy);
- if(yy.length() != 4)
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- if(month >12 || month < 1)
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- if (((month == 1 )|| (month == 3 )|| (month == 5) || (month == 7 )||
- (month == 8 )|| (month == 10 )|| (month == 12)) && ((day > 31 )||
- (day < 1)))
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- if (((month == 4) || (month == 6 )|| (month == 9 )|| (month == 11))
- && ((day > 30 )|| (day < 1)))
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- if (month == 2)
- {
- if (day < 1)
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- if (isLeapYear(year) == true)
- {
- if (day > 29)
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- else
- {
- if (day > 28)
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- }
- }//try
- catch(GOSIBatchException ge)
- {
- throw ge;
- }//GOSIEx
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }//method
- /**
- * @METHOD NAME : checkDateFormat
- * @INFORMATION : This method takes the date, and check for date
- * formatin DD/MM/YYYY
- * @PARAM : date
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void checkDateFormat(String date)
- throws GOSIBatchException
- {
- try
- {
- int count= date.length();
- if((count > 10)||(count < 8))
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }//if
- else if(date.indexOf('.')> -1)
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }//if
- else
- {
- int fIndex=0;
- int lIndex=0;
- if (date.indexOf('/')!= -1)
- {
- fIndex=date.indexOf('/');
- lIndex=date.lastIndexOf('/');
- if((fIndex==1)|| (fIndex==2))
- {}
- else
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- if((lIndex==3)||(lIndex==5)||(lIndex==4))
- {}
- else
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- if(fIndex==1)
- {
- if((lIndex==3)||(lIndex==4))
- {}
- else
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- if(fIndex==2)
- {
- if((lIndex==5)||(lIndex==4))
- {}
- else
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- }//if-outer
- else
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- if((lIndex==-1)||(lIndex==fIndex))
- {
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }//else
- }//try
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "getGregorianDateDifference",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }//catch
- }//method
- /**
- * @METHOD NAME : isLeapYear
- * @INFORMATION : checks given year is leap year
- * @PARAM : year
- * @RETURN : boolean
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static boolean isLeapYear(int year)
- throws GOSIBatchException
- {
- try
- {
- if (year % 4 != 0)
- {
- return false;
- }
- if (year % 400 == 0)
- {
- return true;
- }
- }//try
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "isLeapYear()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }//catch
- return (year % 100 != 0);
- }
- /**
- * @METHOD NAME : gregorianDateDifference
- * @INFORMATION : This method is used to find difference between two
- * gregorian dates in number of days.
- * @PARAM : g1, g2
- * @RETURN : int
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static int gregorianDateDifference(GregorianCalendar g1,
- GregorianCalendar g2)throws GOSIBatchException
- {
- int elapsed = 0;
- GregorianCalendar gc1, gc2;
- try
- {
- if (g2.after(g1))
- {
- gc2 = (GregorianCalendar) g2.clone();
- gc1 = (GregorianCalendar) g1.clone();
- }
- else
- {
- gc2 = (GregorianCalendar) g1.clone();
- gc1 = (GregorianCalendar) g2.clone();
- }
- gc1.clear(Calendar.MILLISECOND);
- gc1.clear(Calendar.SECOND);
- gc1.clear(Calendar.MINUTE);
- gc1.clear(Calendar.HOUR_OF_DAY);
- gc2.clear(Calendar.MILLISECOND);
- gc2.clear(Calendar.SECOND);
- gc2.clear(Calendar.MINUTE);
- gc2.clear(Calendar.HOUR_OF_DAY);
- while ( gc1.before(gc2) )
- {
- gc1.add(Calendar.DATE, 1);
- elapsed++;
- }
- }//try
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "gregorianDateDifference()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return elapsed;
- }
- /**
- * @METHOD NAME : isAccidentalRerun
- * @INFORMATION : checks whether the job is accidental rerun.
- Means the frequency should match witht the current date and as well the batch should not been run for this date
- * @PARAM : batchProcessController
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void isAccidentalRerun(BatchProcessController batchProcessController)
- throws GOSIBatchException
- {
- try
- {
- BatchRestart batchRestartInLastRun = batchProcessController.getBatchRestartInLastRun();
- BatchMaster batchMaster= batchProcessController.getBatchMaster();
- //System.out.println("BatchRunFrequency : "+batchMaster.getBatchRunFrequency());
- String batchRunFrequency = batchMaster.getBatchRunFrequency();
- boolean isRunnable = false;
- String errorCode = "";
- // If the batchRunFrequency taking the each character in each position into different variables
- if(batchRunFrequency!=null)
- {
- // No condition adhoc batch
- String condition1=batchRunFrequency.substring(0,1);
- // Daily
- String condition2=batchRunFrequency.substring(1,2);
- // weekly
- String condition3=batchRunFrequency.substring(2,3);
- // Hijira Month End
- String condition4=batchRunFrequency.substring(3,4);
- // Hijira Year End
- String condition5=batchRunFrequency.substring(4,5);
- // Gregorian Month End
- String condition6=batchRunFrequency.substring(5,6);
- // Gregorian Year End
- String condition7=batchRunFrequency.substring(6,7);
- // Hijira Month Start
- String condition8=batchRunFrequency.substring(7,8);
- // Gregorian Month Start
- String condition9=batchRunFrequency.substring(8,9);
- // Hijira Year Start
- String condition10=batchRunFrequency.substring(9,10);
- // Gregorian Year Start
- String condition11=batchRunFrequency.substring(10,11);
- // Fortnight
- String condition12=batchRunFrequency.substring(11,12);
- // System.out.println("Last Run Date"+batchRestartInLastRun.getSuccessDate());
- // If the batchRestartInLastRun
- if(batchRestartInLastRun!=null)
- {
- // Timestamp lastRunDate = batchRestartInLastRun.getLastRunDate();
- // Taking the last successful run date
- Timestamp lastRunDate = batchRestartInLastRun.getSuccessDate();
- System.out.println("lastRunDate "+lastRunDate);
- // If lastRunDate means the batch has run already
- if(lastRunDate!=null)
- {
- //System.out.println("Condition2 : "+condition2);
- if("1".equals(condition1))
- {
- /*if(GOSIBatchUtilities.getTimestamp(
- GOSIBatchUtilities.getDateFullString(lastRunDate)).
- equals(GOSIBatchUtilities.getTimestamp(
- GOSIBatchUtilities.getDateFullString(
- getSystemDate()))))
- {
- isRunnable = false;
- }
- else
- {*/
- isRunnable = true;
- //}
- }
- // Daily
- if("1".equals(condition2))
- {
- // Checking the system date should be >= then last run date
- if(Long.parseLong(GOSIBatchUtilities.getLdapDateFromTimestamp(
- getSystemDate()))<=
- Long.parseLong(GOSIBatchUtilities.getLdapDateFromTimestamp(
- lastRunDate)))
- {
- // If not making isRunnable flase
- isRunnable=false;
- errorCode ="CMN_001_ERR_1051";
- }
- else
- {
- // else making isRunnable true mean it can run
- isRunnable = true;
- }
- }
- // Weekly
- if("1".equals(condition3))
- {
- // Getting the date difference in an array on year, months and days
- int[] array = GOSIBatchDateUtilities.getDateDiff
- (getDateFullString(lastRunDate),
- getDateFullString(getSystemDate()),
- GOSIBatchConstants.GREG_CALENDARTYPE);
- // If the total no days is<=7 then making isRunnable flase if it's not already true
- if((array[0]+(array[1]*30)+(array[2]*365))<=7)
- {
- if(!isRunnable)
- {
- isRunnable = false;
- errorCode ="CMN_001_ERR_1052";
- }
- }
- else
- {
- // If greater than 7 days the making isRunnable true
- isRunnable = true;
- }
- }
- // Case for hijira month end
- if("1".equals(condition4))
- {
- // Checking whether the isHijMonthEndJob is true or not
- if(batchProcessController.isHijMonthEndJob())
- {
- // CHecking if the lastRunDate and getSystemDate
- if(getDateFullString(lastRunDate).equals(
- getDateFullString(getSystemDate())))
- {
- // If they are same making isRunnable flase
- if(!isRunnable)
- {
- isRunnable = false;
- errorCode ="CMN_001_ERR_1053";
- }
- }
- else
- {
- // If not making isRunnable true
- isRunnable = true;
- }
- }
- else
- {
- // If isHijMonthEndJob not true then making isRunnable flase
- if(!isRunnable)
- {
- isRunnable = false;
- errorCode ="CMN_001_ERR_1054";
- }
- }
- }
- // Case for Hijira Year-end
- if("1".equals(condition5))
- {
- // Checking isHijYearEndJob flag is true or not
- if(batchProcessController.isHijYearEndJob())
- {
- // Checking the lastRunDate and system date or equal or not
- if(getDateFullString(lastRunDate).equals(getDateFullString(getSystemDate())))
- {
- if(!isRunnable)
- {
- isRunnable = false;
- errorCode ="CMN_001_ERR_1059";
- }
- }
- else
- {
- isRunnable = true;
- }
- }
- else
- {
- if(!isRunnable)
- {
- isRunnable = false;
- errorCode ="CMN_001_ERR_1060";
- }
- }
- }
- // Case for Gregorian Month-end
- if("1".equals(condition6))
- {
- // Checking whether isGregMonthEndJob flag is true or not
- if(batchProcessController.isGregMonthEndJob())
- {
- // Checking the lastRunDate and system date or equal or not
- if(getDateFullString(lastRunDate).equals(getDateFullString(getSystemDate())))
- {
- if(!isRunnable)
- {
- isRunnable = false;
- errorCode ="CMN_001_ERR_1055";
- }
- }
- else
- {
- isRunnable = true;
- }
- }
- else
- {
- if(!isRunnable)
- {
- isRunnable = false;
- errorCode ="CMN_001_ERR_1056";
- }
- }
- }
- // Case for Gregorian Year-end
- if("1".equals(condition7))
- {
- // Checking whether isGregYearEndJob is true or not
- if(batchProcessController.isGregYearEndJob())
- {
- // Checking lastRunDate and system date or equal or not
- if(getDateFullString(lastRunDate).equals(getDateFullString(getSystemDate())))
- {
- if(!isRunnable)
- {
- errorCode ="CMN_001_ERR_1057";
- }
- }
- else
- {
- isRunnable = true;
- }
- }
- else
- {
- if(!isRunnable)
- {
- errorCode ="CMN_001_ERR_1058";
- }
- }
- }
- // Case for hijira month start
- if("1".equals(condition8))
- {
- // Checking whether the system date is HijiraMonthStartDate or not
- boolean isHijiraMonthStartDate = isHijiraMonthStartDate
- (getSystemDate());
- if(isHijiraMonthStartDate)
- {
- // CHecking whether lastRunDate and getSystemDate are equal or not
- if(getDateFullString(lastRunDate).equals(getDateFullString(getSystemDate())))
- {
- if(!isRunnable)
- {
- errorCode ="CMN_001_ERR_1061";
- }
- }
- else
- {
- isRunnable = true;
- }
- }
- else
- {
- if(!isRunnable)
- {
- errorCode ="CMN_001_ERR_1062";
- }
- }
- }
- // Case for Gregorian Month-start
- if("1".equals(condition9))
- {
- // Checking the whether the system date is GregMonthStartDate or not
- boolean isGregMonthStartDate = isGregMonthStartDate
- (getSystemDate());
- if(isGregMonthStartDate)
- {
- // Checking the lastRunDate and system date or equal or not
- if(getDateFullString(lastRunDate).equals(getDateFullString(getSystemDate())))
- {
- if(!isRunnable)
- {
- errorCode ="CMN_001_ERR_1063";
- }
- }
- else
- {
- isRunnable = true;
- }
- }
- else
- {
- if(!isRunnable)
- {
- errorCode ="CMN_001_ERR_1064";
- }
- }
- }
- // Case for Hijira Year-start
- if("1".equals(condition10))
- {
- // Checking whether the system date is GregMonthStartDate or not
- boolean isHijiraYearStartDate = isHijraYearStartDate
- (getSystemDate());
- if(isHijiraYearStartDate)
- {
- // Checking the lastRunDate and system date or equal or not
- if(getDateFullString(lastRunDate).equals(getDateFullString(getSystemDate())))
- {
- if(!isRunnable)
- {
- errorCode ="CMN_001_ERR_1063";
- }
- }
- else
- {
- isRunnable = true;
- }
- }
- else
- {
- if(!isRunnable)
- {
- errorCode ="CMN_001_ERR_1064";
- }
- }
- }
- // Case for Gregorian Year-start
- if("1".equals(condition11))
- {
- // CHecking whether the system date is GregMonthStartDate or not
- boolean isGregYearStartDate = isGregYearStartDate
- (getSystemDate());
- if(isGregYearStartDate)
- {
- // Checking lastRunDate is equal to system date or not
- if(getDateFullString(lastRunDate).equals(getDateFullString(getSystemDate())))
- {
- if(!isRunnable)
- {
- errorCode ="CMN_001_ERR_1063";
- }
- }
- else
- {
- isRunnable = true;
- }
- }
- else
- {
- if(!isRunnable)
- {
- errorCode ="CMN_001_ERR_1063";
- }
- }
- }
- // This is for biweekly
- if("1".equals(condition12))
- {
- // Getting the no of days between the last run date and system date in yer,month and days array
- int[] array = GOSIBatchDateUtilities.getDateDiff
- (getDateFullString(lastRunDate),
- getDateFullString(getSystemDate()),
- GOSIBatchConstants.GREG_CALENDARTYPE);
- isRunnable = true;
- // Checking the no days if no of days or <=14 days then batch can be run or not batch can be run
- if((array[0]+(array[1]*30)+(array[2]*365))<=14)
- {
- if(!isRunnable)
- {
- errorCode ="CMN_001_ERR_1063";
- }
- //System.out.println("Error Occured due to accidental run ");
- }
- else
- {
- isRunnable = true;
- }
- }
- }
- else
- {
- //System.out.println("in the else "+isRunnable );
- // If lastRunDate is null the making isRunnable true
- isRunnable=true;
- }
- }
- else
- {
- // If batchRestartInLastRun is null the making isRunnable true
- isRunnable=true;
- }
- if(!isRunnable)
- {
- //System.out.println("error code : "+errorCode);
- new GOSIBatchException(new Exception(),
- "BatchCore",
- "GOSIUtilities",
- "isAccidentalRe-run",
- errorCode,
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- }catch(GOSIBatchException ge)
- {
- throw ge;
- }catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "isAccidentalRerun",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : isHijiraMonthStartDate
- * @INFORMATION : checks whether given date is hijrah month start
- date
- * @PARAM :
- * @RETURN :
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static boolean isHijiraMonthStartDate(Timestamp date)
- throws GOSIBatchException
- {
- boolean isHijraMonthStartDate = false;
- try
- {
- String hijiraDate = GOSIBatchDateUtilities.convertToHijra
- (getDateFullString(date));
- //System.out.println("Hijira Date : "+hijiraDate);
- if((new Byte(hijiraDate.substring(0,2))).byteValue()==1)
- {
- isHijraMonthStartDate = true;
- }
- //System.out.println("Is hijira Month start Date : "+
- // isHijraMonthStartDate);
- }catch(GOSIBatchException ge)
- {
- throw ge;
- }catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "isHijiraMonthStartDate",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return isHijraMonthStartDate;
- }
- /**
- * @METHOD NAME : isGregMonthStartDate
- * @INFORMATION : Checks whether entered date gregorian month start date
- * @PARAM : date
- * @RETURN : boolean
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static boolean isGregMonthStartDate(Timestamp date)
- throws GOSIBatchException
- {
- boolean isHijraMonthStartDate = false;
- try
- {
- String gregDate = getDateFullString(date);
- if((new Byte(gregDate.substring(0,2))).byteValue()==1)
- {
- isHijraMonthStartDate = true;
- }
- //System.out.println("Is hijira Month start Date : "+
- // isHijraMonthStartDate);
- }catch(GOSIBatchException ge)
- {
- throw ge;
- }catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "isGregMonthStartDate",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return isHijraMonthStartDate;
- }
- /**
- * @METHOD NAME : isHijraYearStartDate
- * @INFORMATION : Checks whether given year is hijirah yeart start
- * date
- * @PARAM : date
- * @RETURN : boolean
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static boolean isHijraYearStartDate(Timestamp date)
- throws GOSIBatchException
- {
- boolean isHijraYearStartDate = false;
- try
- {
- String hijiraDate = GOSIBatchDateUtilities.convertToHijra
- (getDateFullString(date));
- if(((new Byte(hijiraDate.substring(0,2))).byteValue()==1) &&
- ((new Byte(hijiraDate.substring(3,5))).byteValue()==1))
- {
- isHijraYearStartDate = true;
- }
- //System.out.println("Is Hijra year start Date : "+
- // isHijraYearStartDate);
- }catch(GOSIBatchException ge)
- {
- throw ge;
- }catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "isHijiraYearStartDate",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return isHijraYearStartDate;
- }
- /**
- * @METHOD NAME : isGregYearStartDate
- * @INFORMATION : Returns whether given date is greg year start date
- * @PARAM : date
- * @RETURN : boolean
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static boolean isGregYearStartDate(Timestamp date)
- throws GOSIBatchException
- {
- boolean isGregYearStartDate = false;
- try
- {
- String gregDate = getDateFullString(date);
- if(((new Byte(gregDate.substring(0,2))).byteValue()==1) &&
- ((new Byte(gregDate.substring(3,5))).byteValue()==1))
- {
- isGregYearStartDate = true;
- }
- //System.out.println("Is greg year start Date : "+
- // isGregYearStartDate);
- }catch(GOSIBatchException ge)
- {
- throw ge;
- }catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "isGregYearStartDate",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return isGregYearStartDate;
- }
- /**
- * @METHOD NAME : getCurrentBatchRunFrequency
- * @INFORMATION : Returns current batches run frequencies
- * @PARAM : NIL
- * @RETURN : class java.lang.String
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- protected String getCurrentBatchRunFrequency()
- {
- return this.currentBatchMaster.getBatchRunFrequency();
- }
- /**
- * @METHOD NAME : getWorkflowGroupId
- * @INFORMATION : Returns workflowgroupId this a unique number which is generated from the sequence.
- Check the documentation of T_BATCHWORKFLOWTXN GRIOUPID attribute for details
- * @PARAM : NIL
- * @RETURN : class java.lang.Long
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static Long getWorkflowGroupId()
- throws GOSIBatchException
- {
- Long groupId=null;
- try
- {
- groupId=getPrimaryKey("WORKFLOWGROUPID",
- getSystemUser());
- }catch(GOSIBatchException ge)
- {
- throw ge;
- }catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "getWorkflowGroupId",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return groupId;
- }
- /**
- * @METHOD NAME : isHoliday
- * @INFORMATION : Returns whether entered day is holiday
- * @PARAM : inputDate
- * @RETURN : boolean
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static boolean isHoliday(Timestamp inputDate)
- throws GOSIBatchException
- {
- ResultSet rs = null;
- boolean isHoliday = false;
- try
- {
- //System.out.println("Session : input Date "+inputDate);
- psCheckIsHoliday.setTimestamp(1, inputDate);
- psCheckIsHoliday.setTimestamp(2, inputDate);
- rs = psCheckIsHoliday.executeQuery();
- if (rs.next())
- {
- isHoliday = true;
- }
- //System.out.println("Is Holiday :"+isHoliday);
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "isHoliday",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs);
- }
- return isHoliday;
- }
- /**
- * @METHOD NAME : getPrevDate
- * @INFORMATION : Returns the previous working date, considering no.
- displacement apart from holidays
- * @PARAM : currentDate, displacement
- * @RETURN : class java.sql.Timestamp
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static Timestamp getPrevDate(Timestamp currentDate,
- int displacement)throws GOSIBatchException{
- Timestamp resultantDate=null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- try
- {
- do
- {
- psFinalDate.setTimestamp(1, currentDate);
- psFinalDate.setInt(2,displacement);
- rs = psFinalDate.executeQuery();
- if(rs.next())
- {
- resultantDate = rs.getTimestamp("FINALDATE");
- //System.out.println("Final Date : "+resultantDate);
- }
- displacement = getNoOfHolidays(resultantDate,currentDate);
- currentDate = resultantDate;
- }while(displacement!=0);
- //System.out.println("Date is : "+resultantDate);
- }catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "isHoliday",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs);
- }
- return resultantDate;
- }
- /**
- * @METHOD NAME : getNoOfHolidays
- * @INFORMATION : Returns no. of holidays between two dates
- * @PARAM : startDate, endDate
- * @RETURN : int
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static int getNoOfHolidays(Timestamp startDate, Timestamp
- endDate) throws GOSIBatchException
- {
- int totalHolidays =0;
- ResultSet rs =null;
- try
- {
- StringBuffer sb = new StringBuffer(" SELECT ");
- psNoOfHolidays.setTimestamp(1, startDate);
- psNoOfHolidays.setTimestamp(2, endDate);
- rs = psNoOfHolidays.executeQuery();
- if(rs.next())
- {
- totalHolidays = rs.getInt("TOTAL");
- }
- }catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "isHoliday",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs);
- }
- return totalHolidays;
- }
- /**
- * @METHOD NAME : getTotalNoOfHolidays
- * @INFORMATION : Returns Total no. of holidays between two dates
- (Any 2 dates can be given)
- counting weekend days inside the holiday
- * @PARAM : startDate, endDate
- * @RETURN : int
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static int getTotalNoOfHolidays(Timestamp tStartDate, Timestamp
- tEndDate) throws GOSIBatchException
- {
- //GOSIDebug.debugMessages("%%%%%%%%%%%%%% HOLIDAYS COUNT QUERY %%%%%%%%");
- Connection connection=null;
- PreparedStatement psNoOfHolidaysA =null;
- PreparedStatement psNoOfHolidaysB =null;
- PreparedStatement psNoOfHolidaysC =null;
- PreparedStatement psNoOfHolidaysD =null;
- int HolidaysA =0;
- int HolidaysB =0;
- int HolidaysC =0;
- int HolidaysD =0;
- ResultSet rsA =null;
- ResultSet rsB =null;
- ResultSet rsC =null;
- ResultSet rsD =null;
- int totalHolidays =0;
- String startDate="";
- String endDate="";
- try
- {
- // converting given Timestamp into String
- startDate = GOSIBatchDateUtilities.getDateFullString(tStartDate);
- //GOSIDebug.debugMessages("startDate = " + startDate);
- endDate = GOSIBatchDateUtilities.getDateFullString(tEndDate);
- //GOSIDebug.debugMessages("endDate = " + endDate);
- connection=GOSIBatchUtilities.getDbConnection(GOSIBatchConstants.COMMON);
- // -------------------------------------------------------------
- // case A: Holiday contained within the 2 dates
- String sqlQueryA="SELECT SUM((HOLIDAYENDDATE-HOLIDAYSTARTDATE)+1) TOTAL "+
- " FROM T_HOLIDAYS "+
- " WHERE TRUNC(HOLIDAYSTARTDATE) >=TO_DATE('"+startDate+"','dd/mm/yyyy') "+
- " AND TRUNC(HOLIDAYENDDATE) <=TO_DATE('"+endDate+"','dd/mm/yyyy') "+
- " AND HOLIDAYTYPE!=? AND STATUS =1";
- psNoOfHolidaysA=connection.prepareStatement(sqlQueryA);
- //System.out.println("sqlQuery select columns "+sqlQuery);
- psNoOfHolidaysA.setShort(1, GOSIBatchConstants.HOLIDAY_WEEKEND);
- rsA=psNoOfHolidaysA.executeQuery();
- //GOSIDebug.debugMessages("After executing HolidaysA query ");
- if(rsA.next())
- {
- HolidaysA = rsA.getInt("TOTAL");
- //GOSIDebug.debugMessages("HolidaysA = " + HolidaysA);
- }
- // -------------------------------------------------------------
- // case B: Holiday ended during
- String sqlQueryB="SELECT SUM((HOLIDAYENDDATE-TO_DATE('"+startDate+"','dd/mm/yyyy') )+1) TOTAL "+
- " FROM T_HOLIDAYS "+
- " WHERE TRUNC(HOLIDAYENDDATE) >= TO_DATE('"+startDate+"','dd/mm/yyyy') "+
- " AND TRUNC(HOLIDAYENDDATE) <= TO_DATE('"+endDate+"','dd/mm/yyyy') "+
- " AND TRUNC(HOLIDAYSTARTDATE) < TO_DATE('"+startDate+"','dd/mm/yyyy') "+
- " AND HOLIDAYTYPE!=? AND STATUS =1";
- psNoOfHolidaysB=connection.prepareStatement(sqlQueryB);
- //System.out.println("sqlQuery select columns "+sqlQuery);
- psNoOfHolidaysB.setShort(1, GOSIBatchConstants.HOLIDAY_WEEKEND);
- rsB=psNoOfHolidaysB.executeQuery();
- //GOSIDebug.debugMessages("After executing HolidaysB query ");
- if(rsB.next())
- {
- HolidaysB = rsB.getInt("TOTAL");
- //GOSIDebug.debugMessages("HolidaysB = " + HolidaysB);
- }
- // -------------------------------------------------------------
- // case C: Holiday started during
- String sqlQueryC="SELECT SUM((TO_DATE('"+endDate+"','dd/mm/yyyy') -HOLIDAYSTARTDATE)+1) TOTAL "+
- " FROM T_HOLIDAYS "+
- " WHERE TRUNC(HOLIDAYSTARTDATE) >= TO_DATE('"+startDate+"','dd/mm/yyyy') "+
- " AND TRUNC(HOLIDAYSTARTDATE) <= TO_DATE('"+endDate+"','dd/mm/yyyy') "+
- " AND TRUNC(HOLIDAYENDDATE) > TO_DATE('"+endDate+"','dd/mm/yyyy') "+
- " AND HOLIDAYTYPE!=? AND STATUS =1";
- psNoOfHolidaysC=connection.prepareStatement(sqlQueryC);
- //System.out.println("sqlQuery select columns "+sqlQuery);
- psNoOfHolidaysC.setShort(1, GOSIBatchConstants.HOLIDAY_WEEKEND);
- rsC=psNoOfHolidaysC.executeQuery();
- //GOSIDebug.debugMessages("After executing HolidaysC query ");
- if(rsC.next())
- {
- HolidaysC = rsC.getInt("TOTAL");
- //GOSIDebug.debugMessages("HolidaysC = " + HolidaysC);
- }
- // -------------------------------------------------------------
- // case D: Holiday extends before and beyond
- String sqlQueryD="SELECT SUM((TO_DATE('"+endDate+"','dd/mm/yyyy') -TO_DATE('"+startDate+"','dd/mm/yyyy') )+1) TOTAL "+
- " FROM T_HOLIDAYS "+
- " WHERE TRUNC(HOLIDAYSTARTDATE) < TO_DATE('"+startDate+"','dd/mm/yyyy') "+
- " AND TRUNC(HOLIDAYENDDATE) > TO_DATE('"+endDate+"','dd/mm/yyyy') "+
- " AND HOLIDAYTYPE!=? AND STATUS =1";
- psNoOfHolidaysD=connection.prepareStatement(sqlQueryD);
- //System.out.println("sqlQuery select columns "+sqlQuery);
- psNoOfHolidaysD.setShort(1, GOSIBatchConstants.HOLIDAY_WEEKEND);
- rsD=psNoOfHolidaysD.executeQuery();
- //GOSIDebug.debugMessages("After executing HolidaysD query ");
- if(rsD.next())
- {
- HolidaysD = rsD.getInt("TOTAL");
- //GOSIDebug.debugMessages("HolidaysD = " + HolidaysD);
- }
- // -------------------------------------------------------------
- totalHolidays=HolidaysA + HolidaysB + HolidaysC + HolidaysD;
- //GOSIDebug.debugMessages("totalHolidays = " + totalHolidays);
- }catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "getTotalNoOfHolidays",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rsA);
- GOSIBatchUtilities.cleanUp(rsB);
- GOSIBatchUtilities.cleanUp(rsC);
- GOSIBatchUtilities.cleanUp(rsD);
- }
- return totalHolidays;
- }
- /**
- * @METHOD NAME : getNoOfWeekEnds
- * @INFORMATION : Returns no. of weekend days between two dates
- not counting those inside other holidays
- * @PARAM : startDate, endDate
- * @RETURN : int
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static int getNoOfWeekEnds(Timestamp tStartDate, Timestamp
- tEndDate) throws GOSIBatchException
- {
- Connection connection=null;
- PreparedStatement psNoOfWeekEndsA =null;
- PreparedStatement psNoOfWeekEndsB =null;
- int weekendsA =0;
- int weekendsB =0;
- ResultSet rsA =null;
- ResultSet rsB =null;
- String startDate="";
- String endDate="";
- int totalWeekEnds =0;
- ResultSet rs =null;
- try
- {
- //StringBuffer sb = new StringBuffer(" SELECT ");
- psWeekEnds.setShort(1,GOSIBatchConstants.HOLIDAY_WEEKEND);
- psWeekEnds.setByte(2,GOSIBatchConstants.HOLIDAY_VALID);
- psWeekEnds.setTimestamp(3, tStartDate);
- psWeekEnds.setTimestamp(4, tEndDate);
- rs = psWeekEnds.executeQuery();
- if(rs.next())
- {
- totalWeekEnds = rs.getInt("TOTAL");
- }
- // converting given Timestamp into String
- startDate = GOSIBatchDateUtilities.getDateFullString(tStartDate);
- //GOSIDebug.debugMessages("startDate = " + startDate);
- endDate = GOSIBatchDateUtilities.getDateFullString(tEndDate);
- //GOSIDebug.debugMessages("endDate = " + endDate);
- connection=GOSIBatchUtilities.getDbConnection(GOSIBatchConstants.COMMON);
- // case A: Period given ends on a Thursday
- String sqlQueryA="SELECT count (*) TOTAL "+
- " FROM T_HOLIDAYS "+
- " WHERE TRUNC(HOLIDAYSTARTDATE) =TO_DATE('"+endDate+"','dd/mm/yyyy') "+
- " AND HOLIDAYTYPE=? AND STATUS =1";
- psNoOfWeekEndsA=connection.prepareStatement(sqlQueryA);
- //System.out.println("sqlQuery select columns "+sqlQuery);
- psNoOfWeekEndsA.setShort(1, GOSIBatchConstants.HOLIDAY_WEEKEND);
- rsA=psNoOfWeekEndsA.executeQuery();
- //GOSIDebug.debugMessages("After executing HolidaysA query ");
- if(rsA.next())
- {
- weekendsA = rsA.getInt("TOTAL");
- //GOSIDebug.debugMessages("HolidaysA = " + HolidaysA);
- }
- totalWeekEnds += weekendsA;
- // case B: Period given starts on a Friday
- String sqlQueryB="SELECT count (*) TOTAL "+
- " FROM T_HOLIDAYS "+
- " WHERE TRUNC(HOLIDAYENDDATE) = TO_DATE('"+startDate+"','dd/mm/yyyy') "+
- " AND HOLIDAYTYPE=? AND STATUS =1";
- psNoOfWeekEndsB=connection.prepareStatement(sqlQueryB);
- //System.out.println("sqlQuery select columns "+sqlQuery);
- psNoOfWeekEndsB.setShort(1, GOSIBatchConstants.HOLIDAY_WEEKEND);
- rsB=psNoOfWeekEndsB.executeQuery();
- //GOSIDebug.debugMessages("After executing HolidaysB query ");
- if(rsB.next())
- {
- weekendsB = rsB.getInt("TOTAL");
- //GOSIDebug.debugMessages("HolidaysB = " + HolidaysB);
- }
- totalWeekEnds += weekendsB;
- }catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "getNoOfWeekEnds",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs);
- }
- return totalWeekEnds;
- }
- /**
- * @METHOD NAME : getNextWorkingDay
- * @INFORMATION : Returns next working day
- * @PARAM : inputDate
- * @RETURN : class java.sql.Timestamp
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static Timestamp getNextWorkingDay(Timestamp inputDate
- )throws GOSIBatchException{
- Timestamp nextWorkingDay = null;
- boolean nextWorkingDayFound = false;
- PreparedStatement ps = null;
- ResultSet rs = null;
- try
- {
- while(!nextWorkingDayFound)
- {
- if(!isHoliday(inputDate))
- {
- nextWorkingDay = inputDate;
- nextWorkingDayFound = true;
- }
- else
- {
- psNextWorkingDay.setTimestamp(1,inputDate);
- psNextWorkingDay.setTimestamp(2,inputDate);
- psNextWorkingDay.setByte(3,GOSIBatchConstants.HOLIDAY_VALID);
- rs = psNextWorkingDay.executeQuery();
- if(rs.next())
- {
- inputDate = rs.getTimestamp("NEXTDATE");
- }
- }
- }
- }catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIUtilities",
- "getNextWorkingDay",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- //System.out.println("Next Working Day : "+nextWorkingDay);
- return nextWorkingDay;
- }
- // From here methods are releated to auditing the record for deletion these are all
- // Similar to the online components
- /**
- * @METHOD NAME : insertRecord
- * @INFORMATION : This methods inserts the records in the Audit tables
- * @PARAM :
- * @RETURN :
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static void insertRecord(String insertQuery, ArrayList columnsList,
- HashMap data, HashMap dataType, Long
- userId,Connection connection)
- throws GOSIBatchException
- {
- PreparedStatement psInsert1=null;
- PreparedStatement psInsert2=null;
- String lastAction=null;
- String lastActionBy=null;
- String lastActionTimestamp=null;
- try
- {
- psInsert1=connection.prepareStatement(insertQuery);
- psInsert2=connection.prepareStatement(insertQuery);
- int position=1;
- int columnsSize=columnsList.size();
- for(int i=0;i<columnsSize;i++)
- {
- if("DATE".equals((String)dataType.get(columnsList.get(i))))
- {
- //System.out.println("cloumnname : " +columnsList.get(
- // i)+ " data type ="+dataType.get(columnsList.get(i)));
- if(data.get(columnsList.get(i))==null)
- {
- psInsert2.setString(position, null);
- psInsert1.setString(position, null);
- //System.out.println("assigning the values " +
- // "position : "+position+" and cloumnname : " +
- //columnsList.get(i)+" = "+data.get(columnsList.
- // get(i)));
- }
- else
- {
- psInsert1.setTimestamp(position,
- Timestamp.valueOf((String)data.
- get(columnsList.get(i))));
- psInsert2.setTimestamp(position,
- Timestamp.valueOf((String)data.
- get(columnsList.get(i))));
- //System.out.println("assigning the values " +
- // "position : "+position+" and cloumnname : " +
- //columnsList.get(i)+" = "+data.get(columnsList.
- //get(i)));
- }
- }
- else
- {
- if(data.get(columnsList.get(i))==null)
- {
- psInsert1.setString(position, null);
- psInsert2.setString(position, null);
- //System.out.println("assigning the values " +
- // "position : "+position+" and cloumnname : " +
- // columnsList.get(i)+" = "+data.get(columnsList.
- //get(i)));
- }
- else
- {
- psInsert2.setString(position,
- (String)data.get(columnsList.get(i)));
- psInsert1.setString(position,
- (String)data.get(columnsList.get(i)));
- //System.out.println("assigning the values " +
- //"position : "+position+" and cloumnname : " +
- //columnsList.get(i)+" = "+data.get(columnsList.
- //get(i)));
- }
- }
- position++;
- }
- //System.out.println("assigning the values position : "
- //+position+" and cloumnname : ACTIONBY value= "+
- //userId.longValue());
- psInsert1.setLong(position, userId.longValue());
- psInsert2.setString(position,
- (String)data.get("LASTMODIFIEDBY"));
- position++;
- //System.out.println("assigning the values position : "+
- //position+" and cloumnname : ACTIONTIMESTAMP value= "+
- //System.currentTimeMillis());
- psInsert1.setTimestamp(position, new
- Timestamp(System.currentTimeMillis()));
- psInsert2.setTimestamp(position,
- Timestamp.valueOf((String)data.
- get("LASTMODIFIEDTIMESTAMP")));
- position++;
- //System.out.println("assigning the values position : "+
- // position+" and cloumnname : ACTIONTIMESTAMP value=D ");
- psInsert1.setString(position, "D");
- psInsert2.setString(position,
- (String)data.get("LASTACTION"));
- psInsert1.executeUpdate();
- psInsert2.executeUpdate();
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "insertRecord",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(psInsert2);
- GOSIBatchUtilities.cleanUp(psInsert1);
- }
- return;
- }
- /**
- * @method name :getColumnNames
- * @param :String tableNames,COnnection connection
- * @returns :ArrayList
- * @throws :GOSIBatchException
- */
- /**
- * This method reads the columns name of the table passed
- * and returns the column list
- */
- private static ArrayList getColumnNames(String tableName,Connection connection)
- throws GOSIBatchException
- {
- ArrayList arrayList=new ArrayList();
- ArrayList columnList=new ArrayList();
- HashMap dataType=new HashMap();
- PreparedStatement psReadColumns=null;
- ResultSet rs=null;
- try
- {
- //System.out.println("tableName "+tableName);
- String sqlQuery="select distinct column_name,DATA_TYPE from "+
- " DBA_TAB_COLUMNS where table_name=? "+
- " AND column_name not"+
- " in('ACTIONBY','ACTIONTIMESTAMP', "+
- " 'ACTIONTYPE','PART_ID')";
- psReadColumns=connection.prepareStatement(sqlQuery);
- //System.out.println("sqlQuery select columns "+sqlQuery);
- psReadColumns.setString(1, tableName);
- rs=psReadColumns.executeQuery();
- while(rs.next())
- {
- //System.out.println("rs.getString(column_name): "+rs.
- // getString("column_name"));
- //System.out.println("rs.getString(DATA_TYPE): "+rs.
- // getString("DATA_TYPE"));
- columnList.add(rs.getString("column_name"));
- dataType.put(rs.getString("column_name"),
- rs.getString("DATA_TYPE"));
- }
- arrayList.add(columnList);
- arrayList.add(dataType);
- if(columnList.size()==0)
- {
- new GOSIBatchException(null,
- "BatchCore",
- "GOSIBatchUtilities",
- "getColumnNames",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getColumnNames",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs);
- GOSIBatchUtilities.cleanUp(psReadColumns);
- }
- return arrayList;
- }
- /**
- * @method name :getReadQuery
- * @param :String tableNames, ArrayList columnsList
- HashMap primaryKeys,Connection connection
- * @returns :String
- * @throws :GOSIBatchException
- */
- /**
- * This methods takes the table name, columnList and primarykeys values
- * HashMap and creats the query for the reading the record
- */
- private static String getReadQuery(String tableName, ArrayList columnsList,
- HashMap primaryKeyValues,Connection connection,
- HashMap dataType)
- throws GOSIBatchException
- {
- StringBuffer sb=new StringBuffer("select ");
- try
- {
- int columnsSize=columnsList.size();
- for(int i=0;i<columnsSize;i++)
- {
- if(i==0)
- {
- sb.append(columnsList.get(i));
- }
- else
- {
- sb.append(",");
- sb.append(columnsList.get(i));
- }
- }
- sb.append(" ,DECODE(LASTMODIFIEDBY,NULL, "+
- "CREATEDBY,LASTMODIFIEDBY) LASTMODIFIEDBY, DECODE"+
- "(LASTMODIFIEDTIMESTAMP ,NULL, CREATIONTIMESTAMP,"+
- "LASTMODIFIEDTIMESTAMP ) LASTMODIFIEDTIMESTAMP, "+
- "DECODE(LASTMODIFIEDTIMESTAMP ,NULL,'A','C') LASTACTION");
- sb.append(" ");
- sb.append(" from ");
- sb.append(tableName);
- sb.append(" ");
- sb.append(" where ");
- sb.append(" ");
- java.util.Set set=primaryKeyValues.keySet();
- java.util.Iterator iterator= set.iterator();
- int flag=0;
- while(iterator.hasNext())
- {
- boolean dateFlag=false;
- String keyName=(String)iterator.next();
- if((dataType.get(keyName)!=null)&&("DATE".equalsIgnoreCase((String)dataType.get(keyName))))
- {
- dateFlag=true;
- }
- if(flag==0)
- {
- if((primaryKeyValues.get(keyName))==null)
- {
- sb.append(keyName);
- sb.append(" is null ");
- }
- else
- {
- if(dateFlag==false)
- {
- sb.append(keyName);
- sb.append("='");
- sb.append(primaryKeyValues.get(keyName));
- sb.append("'");
- }
- else
- {
- sb.append("to_char("+keyName+",'DD/MM/YYYY')");
- sb.append("='");
- sb.append(primaryKeyValues.get(keyName));
- sb.append("'");
- }
- }
- //System.out.println("Key : "+keyName);
- //System.out.println("Key Value : "+primaryKeyValues.
- // get(keyName));
- }
- else
- {
- sb.append(" and ");
- if((primaryKeyValues.get(keyName))==null)
- {
- sb.append(keyName);
- sb.append(" is null ");
- }
- else
- {
- if(dateFlag==false)
- {
- sb.append(keyName);
- sb.append("='");
- sb.append(primaryKeyValues.get(keyName));
- sb.append("'");
- }
- else
- {
- sb.append("to_char("+keyName+",'DD/MM/YYYY')");
- sb.append("='");
- sb.append(primaryKeyValues.get(keyName));
- sb.append("'");
- }
- }
- //System.out.println("Key : "+keyName);
- //System.out.println("Key Value : "+primaryKeyValues.
- // get(keyName));
- }
- flag=1;
- }
- //System.out.println("READ QUERY"+sb.toString());
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getReadQuery",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return sb.toString();
- }
- /**
- * @method name :readRecord
- * @param :String tableNames, ArrayList columnsList,Connection connection
- * @returns :HashMap
- * @throws :GOSIBatchException
- */
- /**
- * This methods takes query string and columnList and read the data
- * Retrived by the query and populates that in HashMap as
- * key value pair and returns them
- */
- private static HashMap readRecord(String query, ArrayList columnsList,Connection connection)
- throws GOSIBatchException
- {
- HashMap data=new HashMap();
- PreparedStatement psRead=null;
- ResultSet rs=null;
- try
- {
- int arraySize=columnsList.size();
- psRead=connection.prepareStatement(query);
- rs=psRead.executeQuery();
- if(rs.next())
- {
- for(int i=0;i<arraySize;i++)
- {
- data.put(columnsList.get(i),
- rs.getString((String)columnsList.get(i)));
- //System.out.println(columnsList.get(i)+" = "+rs.
- // getString((String)columnsList.get(i)));
- }
- //System.out.println("rs.getString(LASTMODIFIEDBY)" +
- // rs.getString("LASTMODIFIEDBY"));
- //System.out.println("rs.getString(LASTMODIFIEDTIMESTAMP)"
- // + rs.getString("LASTMODIFIEDTIMESTAMP"));
- data.put("LASTMODIFIEDBY", rs.getString("LASTMODIFIEDBY"));
- data.put("LASTMODIFIEDTIMESTAMP",
- rs.getString("LASTMODIFIEDTIMESTAMP"));
- //System.out.println("rs.getString(LASTACTION)" +
- // rs.getString("LASTACTION"));
- data.put("LASTACTION",
- rs.getString("LASTACTION"));
- }
- else
- {
- new GOSIBatchException(null,
- "BatchCore",
- "GOSIBatchUtilities",
- "readRecord",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- e.printStackTrace();
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "readRecord",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs);
- GOSIBatchUtilities.cleanUp(psRead);
- }
- return data;
- }
- /**
- * @method name :getInsertQuery
- * @param :String tableNames, ArrayList columnsList,
- HashMap data,Connection connection
- * @returns :String
- * @throws :GOSIBatchException
- */
- /**
- * This methods takes tableName, columnList and data HaspMap
- * creats the insert query and returns the query
- */
- private static String getInsertQuery(String tableName, ArrayList
- columnsList, HashMap data,Connection connection)
- throws GOSIBatchException
- {
- StringBuffer sb=new StringBuffer("insert into ");
- try
- {
- String auditTableName="A"+tableName.substring(1);
- //String auditTableName="T_USER2";
- sb.append(auditTableName);
- sb.append(" ( ");
- int columnsSize=columnsList.size();
- for(int i=0;i<columnsSize;i++)
- {
- if(i==0)
- {
- sb.append(columnsList.get(i));
- }
- else
- {
- sb.append(",");
- sb.append(columnsList.get(i));
- }
- }
- sb.append(",ACTIONBY");
- sb.append(",ACTIONTIMESTAMP");
- sb.append(",ACTIONTYPE ) values ( ");
- for(int i=0;i<columnsSize;i++)
- {
- if(i==0)
- {
- sb.append("?");
- }
- else
- {
- sb.append(",?");
- }
- }
- sb.append(" ,? ");
- sb.append(" ,? ");
- sb.append(" ,?) ");
- //System.out.println("insert query : "+sb.toString());
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getInsertQuery",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return sb.toString();
- }
- /**
- * @method name :logDeleteAudit
- * @param :String tableNames,
- HashMap primarykeys, long userId,Connection connection
- * @returns :
- * @throws :GOSIBatchException
- */
- /**
- * This method is the controller method for all the delete audit log
- */
- public static void logDeleteAudit(String tableName,
- HashMap primaryKeys, Long userId,Connection connection)
- throws GOSIBatchException
- {
- try
- {
- //System.out.println("tableName : "+tableName);
- //System.out.println("userId : "+userId);
- ArrayList arrayList=getColumnNames("A"+tableName.substring(1),connection);
- ArrayList columnsList=(ArrayList)arrayList.get(0);
- HashMap dataType=(HashMap)arrayList.get(1);
- String readQuery=getReadQuery(tableName, columnsList, primaryKeys,connection,dataType);
- HashMap data=readRecord(readQuery, columnsList,connection);
- String insertQuery=getInsertQuery(tableName, columnsList, data,connection);
- insertRecord(insertQuery, columnsList,
- data, dataType, userId,connection);
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "logDeleteAudit",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return;
- }
- // Here ends the delete audit code
- /**
- * @METHOD NAME : updateRequest
- * @INFORMATION : This method updates the Batch request for the passed request id as processed
- * @PARAM : requestId,con
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void updateRequest(long requestId,Connection con)
- throws GOSIBatchException
- {
- PreparedStatement psRequest=null;
- try
- {
- //System.out.println("requestId : "+requestId);
- //System.out.println("con : "+con);
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1057");
- psRequest=con.prepareStatement(query);
- psRequest.setLong(1,requestId);
- psRequest.executeUpdate();
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "deleteRequest",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(psRequest);
- }
- return;
- }
- /**
- * @METHOD NAME : getRequestedBy
- * @INFORMATION : This method gets the request by user id for the given request id
- * @PARAM : requestId,con
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static long getRequestedBy(long requestId,Connection con)
- throws GOSIBatchException
- {
- PreparedStatement psRequest=null;
- long requestedBy=0;
- ResultSet rs = null;
- try
- {
- //System.out.println("requestId : "+requestId);
- //System.out.println("con : "+con);
- String query=GOSIBatchSQL.getSqlString("CMN_003_SQL_1038");
- psRequest=con.prepareStatement(query);
- psRequest.setLong(1,requestId);
- rs = psRequest.executeQuery();
- if(rs.next())
- {
- requestedBy = rs.getLong("REQUESTEDBY");
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getRequestedBy",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs);
- GOSIBatchUtilities.cleanUp(rs);
- }
- return requestedBy;
- }
- /**
- * @METHOD NAME : getUserIdListForStep
- * @INFORMATION : This method gets the list of user names who can perform the step short name passed.
- Takes the task for the step and gets the role for the task id and gets the user list for the role.
- * @PARAM : stepShortName,con
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static ArrayList getUserIdListForStep(String stepShortName,Connection con)
- throws GOSIBatchException
- {
- PreparedStatement psRole=null;
- PreparedStatement psUser=null;
- long roleId=0;
- long endDate=0;
- long currentDate=0;
- long employeeNumber=0;
- ResultSet rsRole = null;
- ResultSet rsUserList = null;
- ArrayList employeeNumbers=new ArrayList();
- try
- {
- currentDate=Long.parseLong(getLdapDateFromTimestamp(getSystemDate()));
- //System.out.println("currentDate : "+currentDate);
- //System.out.println("stepShortName : "+stepShortName);
- //System.out.println("con : "+con);
- String roleQuery=GOSIBatchSQL.getSqlString("CMN_001_SQL_1058");
- psRole=con.prepareStatement(roleQuery);
- psRole.setString(1,stepShortName);
- psRole.setLong(2,currentDate);
- rsRole = psRole.executeQuery();
- if(rsRole.next())
- {
- roleId = rsRole.getLong("ROLEID");
- //System.out.println("roleId "+roleId);
- //System.out.println("ENDDATE"+rsRole.getTimestamp("ENDDATE"));
- if(rsRole.getTimestamp("ENDDATE")!=null)
- {
- endDate=Long.parseLong(getLdapDateFromTimestamp(rsRole.getTimestamp("ENDDATE")));
- if(endDate<=currentDate)
- {
- roleId=0;
- }
- }
- }
- if(roleId==0)
- {
- new GOSIBatchException(null,
- "BatchCore",
- "GOSIBatchUtilities",
- "getUserIdListForStep",
- "CMN_001_ERR_1071",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- String roleUser=GOSIBatchSQL.getSqlString("CMN_001_SQL_1059");
- //System.out.println("roleUser "+roleUser);
- psUser=con.prepareStatement(roleUser);
- psUser.setLong(1,roleId);
- //System.out.println("roleId"+roleId);
- psUser.setLong(2,currentDate);
- psUser.setLong(3,currentDate);
- psUser.setLong(4,roleId);
- psUser.setLong(5,currentDate);
- psUser.setLong(6,currentDate);
- psUser.setLong(7,currentDate);
- psUser.setLong(8,currentDate);
- rsUserList = psUser.executeQuery();
- endDate=0;
- while(rsUserList.next())
- {
- employeeNumber = rsUserList.getLong("USERREFERENCEID");
- //System.out.println("employeeNumber"+employeeNumber);
- if(rsRole.getTimestamp("ENDDATE")!=null)
- {
- endDate=Long.parseLong(getLdapDateFromTimestamp(rsRole.getTimestamp("ENDDATE")));
- if(endDate<=currentDate)
- {
- employeeNumber=0;
- }
- }
- if(employeeNumber!=0)
- {
- //System.out.println("employeeNumber"+employeeNumber);
- employeeNumbers.add(new Long(employeeNumber));
- }
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getUserIdListForStep",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rsRole);
- GOSIBatchUtilities.cleanUp(rsUserList);
- GOSIBatchUtilities.cleanUp(psRole);
- GOSIBatchUtilities.cleanUp(psUser);
- }
- return employeeNumbers;
- }
- public static final short pending=1001;
- public static final short filed=1002;
- public static final short processedSuccessfully=1003;
- public static final short processedWithErrors=1004;
- /**
- * @METHOD NAME : getFilesUploaded
- * @INFORMATION : This method gets the list fo file name requred
- to be processed for the file type sent
- * @PARAM : fileType, conn
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static ArrayList getFilesUploaded(short fileType,Connection conn)
- throws GOSIBatchException
- {
- PreparedStatement psFileName = null;
- ResultSet rs=null;
- ArrayList fileList=new ArrayList();
- try
- {
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1064");
- psFileName=conn.prepareStatement(query);
- psFileName.setShort(1,fileType);
- psFileName.setShort(2,GOSIBatchUtilities.pending);
- psFileName.setShort(3,fileType);
- psFileName.setShort(4,GOSIBatchUtilities.pending);
- rs=psFileName.executeQuery();
- int count=0;
- while(rs.next())
- {
- String data[]=new String[3];
- data[0]=rs.getString("FILEUPLOADINFOID");
- data[1]=rs.getString("FILENAME");
- data[2]=rs.getString("USERREFERENCEID");
- fileList.add(count++,data);
- }
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getFilesUploaded",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return fileList;
- }
- /**
- * @METHOD NAME : updateFileStatus
- * @INFORMATION : This method updates the file status as status passed for the file id passed
- * @PARAM : fileId, status,conn
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void updateFileStatus(String fileId,short status,Connection conn)
- throws GOSIBatchException
- {
- PreparedStatement psUpdate= null;
- try
- {
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1065");
- psUpdate=conn.prepareStatement(query);
- psUpdate.setShort(1,status);
- psUpdate.setString(2,fileId);
- psUpdate.executeUpdate();
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "updateFileStatus",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(psUpdate);
- }
- }
- /**
- * @METHOD NAME : updateYear
- * @INFORMATION : This method updates the file year as year passed for the file id passed
- * @PARAM : fileId, year,conn
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void updateYear(String fileId,int year,Connection conn)
- throws GOSIBatchException
- {
- PreparedStatement psUpdate= null;
- try
- {
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1071");
- psUpdate=conn.prepareStatement(query);
- psUpdate.setInt(1,year);
- psUpdate.setString(2,fileId);
- psUpdate.executeUpdate();
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "updateFileStatus",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(psUpdate);
- }
- }
- /**
- * @METHOD NAME : updateMappingKey
- * @INFORMATION : This method updates the file Mapping Key as mappingkey passed for the file id passed
- * @PARAM : fileId, mappingkey,conn
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void updateMappingKey(String fileId,String mappingkey,Connection conn)
- throws GOSIBatchException
- {
- PreparedStatement psUpdate= null;
- try
- {
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1072");
- psUpdate=conn.prepareStatement(query);
- psUpdate.setString(1,mappingkey);
- psUpdate.setString(2,fileId);
- psUpdate.executeUpdate();
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "updateFileStatus",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(psUpdate);
- }
- }
- /**
- * @METHOD NAME : getVilalgesForFo
- * @INFORMATION : This method gets the villages mapped to filed office from the start date
- * @PARAM : foCode, startDate,conn
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static ArrayList getVilalgesForFo(String foCode,String startDate,Connection conn)
- throws GOSIBatchException
- {
- PreparedStatement ps= null;
- ResultSet rs= null;
- ArrayList villageFoMap=new ArrayList();
- try
- {
- String dateInNumber=getLdapDateFromTimestamp(GOSIBatchDateUtilities.getTimestamp(startDate));
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1066");
- System.out.println("query "+query);
- ps=conn.prepareStatement(query);
- ps.setString(1,foCode);
- System.out.println("foCode "+foCode);
- ps.setString(2,dateInNumber);
- System.out.println("startDate "+dateInNumber);
- ps.setString(3,dateInNumber);
- System.out.println("startDate "+dateInNumber);
- ps.setString(4,dateInNumber);
- System.out.println("startDate "+dateInNumber);
- rs=ps.executeQuery();
- while(rs.next())
- {
- String[] villageData=new String[2];
- villageData[0]=rs.getString("VILLAGERECORDID");
- System.out.println("villageData[0]"+villageData[0]);
- villageData[1]=rs.getString("VILLAGEID");
- System.out.println("villageData[1]"+villageData[1]);
- villageFoMap.add(villageData);
- }
- System.out.println("villageFoMap.size()"+villageFoMap.size());
- //conn.commit();
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getVilalgesForFo",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs);
- GOSIBatchUtilities.cleanUp(ps);
- }
- return villageFoMap;
- }
- /**
- * @METHOD NAME : getFOforVillage
- * @INFORMATION : This method gets the FO code for the given village id
- * @PARAM : villageId,conn
- * @RETURN : NIL
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static String getFOforVillage(String villageId,String startDate,Connection conn)
- throws GOSIBatchException
- {
- PreparedStatement ps= null;
- ResultSet rs= null;
- String foCode=null;
- try
- {
- String dateInNumber=getLdapDateFromTimestamp(GOSIBatchDateUtilities.getTimestamp(startDate));
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1067");
- System.out.println("query "+query);
- ps=conn.prepareStatement(query);
- ps.setString(1,villageId);
- System.out.println("villageId "+villageId);
- ps.setString(2,dateInNumber);
- System.out.println("dateInNumber "+dateInNumber);
- ps.setString(3,dateInNumber);
- ps.setString(4,dateInNumber);
- rs=ps.executeQuery();
- while(rs.next())
- {
- foCode=rs.getString("FOCODE");
- System.out.println("foCode : "+foCode);
- }
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getFOforVillage",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs);
- GOSIBatchUtilities.cleanUp(ps);
- }
- return foCode;
- }
- /**
- * @METHOD NAME : setByte
- * @INFORMATION : This method checks whether the parameter
- 'attribute' is not null. If null, sets the null
- in Prepared Statement at the given column number,
- else sets its primitive value after converting
- to primitive data type.
- * @PARAM : prepareStatement,colNum,attribute
- * @RETURN : void
- * @EXCEPTION : class java.sql.SQLException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void setByte(PreparedStatement prepareStatement, int colNum,
- Byte attribute) throws SQLException
- {
- if(attribute != null)
- {
- prepareStatement.setByte(colNum, attribute.byteValue());
- }
- else
- {
- prepareStatement.setNull(colNum, Types.TINYINT);
- }
- }
- /**
- * @METHOD NAME : setShort
- * @INFORMATION : This method checks whether the parameter
- 'attribute' is not null. If null, sets the null
- in Prepared Statement at the given column number,
- else sets its primitive value after converting
- to primitive data type.
- * @PARAM : prepareStatement,colNum,attribute
- * @RETURN : void
- * @EXCEPTION : class java.sql.SQLException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void setShort(PreparedStatement prepareStatement, int colNum,
- Short attribute) throws SQLException
- {
- if(attribute != null)
- {
- prepareStatement.setShort(colNum, attribute.shortValue());
- }
- else
- {
- prepareStatement.setNull(colNum, Types.SMALLINT);
- }
- }
- /**
- * @METHOD NAME : setInt
- * @INFORMATION : This method checks whether the parameter
- 'attribute' is not null. If null, sets the null
- in Prepared Statement at the given column number,
- else sets its primitive value after converting
- to primitive data type.
- * @PARAM : prepareStatement,colNum,attribute
- * @RETURN : void
- * @EXCEPTION : class java.sql.SQLException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void setInt(PreparedStatement prepareStatement, int colNum,
- Integer attribute) throws SQLException
- {
- if(attribute != null)
- {
- prepareStatement.setInt(colNum, attribute.intValue());
- }
- else
- {
- prepareStatement.setNull(colNum, Types.INTEGER);
- }
- }
- /**
- * @METHOD NAME : setLong
- * @INFORMATION : This method checks whether the parameter
- 'attribute' is not null. If null, sets the null
- in Prepared Statement at the given column number,
- else sets its primitive value after converting
- to primitive data type.
- * @PARAM : prepareStatement,colNum,attribute
- * @RETURN : void
- * @EXCEPTION : class java.sql.SQLException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void setLong(PreparedStatement prepareStatement, int colNum,
- Long attribute) throws SQLException
- {
- if(attribute != null)
- {
- prepareStatement.setLong(colNum, attribute.longValue());
- }
- else
- {
- prepareStatement.setNull(colNum, Types.BIGINT);
- }
- }
- /**
- * @METHOD NAME : setFloat
- * @INFORMATION : This method checks whether the parameter
- 'attribute' is not null. If null, sets the null
- in Prepared Statement at the given column number,
- else sets its primitive value after converting
- to primitive data type.
- * @PARAM : prepareStatement,colNum,attribute
- * @RETURN : void
- * @EXCEPTION : class java.sql.SQLException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void setFloat(PreparedStatement prepareStatement, int colNum,
- Float attribute) throws SQLException
- {
- if(attribute != null)
- {
- prepareStatement.setFloat(colNum, attribute.floatValue());
- }
- else
- {
- prepareStatement.setNull(colNum, Types.FLOAT);
- }
- }
- /**
- * @METHOD NAME : setDouble
- * @INFORMATION : This method checks whether the parameter
- 'attribute' is not null. If null, sets the null
- in Prepared Statement at the given column number,
- else sets its primitive value after converting
- to primitive data type.
- * @PARAM : prepareStatement,colNum,attribute
- * @RETURN : void
- * @EXCEPTION : class java.sql.SQLException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void setDouble(PreparedStatement prepareStatement, int colNum,
- Double attribute) throws SQLException
- {
- if(attribute != null)
- {
- prepareStatement.setDouble(colNum, attribute.doubleValue());
- }
- else
- {
- prepareStatement.setNull(colNum, Types.DOUBLE);
- }
- }
- /**
- * @METHOD NAME : setString
- * @INFORMATION : This method checks whether the parameter
- 'attribute' is not null. If null, sets the null
- in Prepared Statement at the given column number,
- else sets its primitive value after converting
- to primitive data type.
- * @PARAM : prepareStatement,colNum,attribute
- * @RETURN : void
- * @EXCEPTION : class java.sql.SQLException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void setString(PreparedStatement prepareStatement, int colNum,
- String attribute) throws SQLException
- {
- if(attribute != null)
- {
- prepareStatement.setString(colNum, attribute);
- }
- else
- {
- prepareStatement.setNull(colNum, Types.VARCHAR);
- }
- }
- /**
- * @METHOD NAME : setTimestamp
- * @INFORMATION : This method checks whether the parameter
- 'attribute' is not null. If null, sets the null
- in Prepared Statement at the given column number,
- else sets its primitive value after converting
- to primitive data type.
- * @PARAM : prepareStatement,colNum,attribute
- * @RETURN : void
- * @EXCEPTION : class java.sql.SQLException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void setTimestamp(PreparedStatement prepareStatement, int
- colNum, Timestamp attribute) throws SQLException
- {
- if(attribute != null)
- {
- prepareStatement.setTimestamp(colNum, attribute);
- }
- else
- {
- prepareStatement.setNull(colNum, Types.TIMESTAMP);
- }
- }
- /**
- * @METHOD NAME : getShort
- * @INFORMATION : This method converts passed parameter to Short
- and returns Short, if the parameter is not null
- else returns null.
- * @PARAM : stringData
- * @RETURN : class java.lang.Short
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static Short getShort(String stringData) throws GOSIBatchException
- {
- Short shortConvert=null;
- try
- {
- if(stringData != null && !(stringData.equals("")))
- {
- shortConvert = new Short(stringData);
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- GOSIBatchConstants.REAL_ESTATE,
- "GOSIBatchUtilities",
- "getShort()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return shortConvert;
- }
- /**
- * @METHOD NAME : getLong
- * @INFORMATION : This method converts passed parameter to Long
- and returns Long, if the parameter is not null
- else returns null.
- * @PARAM : stringData
- * @RETURN : class java.lang.Long
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static Long getLong(String stringData) throws GOSIBatchException
- {
- Long longConvert=null;
- try
- {
- if(stringData != null && !(stringData.equals("")))
- {
- longConvert = new Long(stringData);
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- GOSIBatchConstants.REAL_ESTATE,
- "GOSIBatchUtilities",
- "getLong()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return longConvert;
- }
- /**
- * @METHOD NAME : getInteger
- * @INFORMATION : This method converts passed parameter to Integer
- and returns Integer, if the parameter is not null
- else returns null.
- * @PARAM : stringData
- * @RETURN : class java.lang.Integer
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static Integer getInteger(String stringData) throws GOSIBatchException
- {
- Integer integer=null;
- try
- {
- if(stringData != null && !(stringData.equals("")))
- {
- integer = new Integer(stringData);
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- GOSIBatchConstants.REAL_ESTATE,
- "GOSIBatchUtilities",
- "getInteger()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return integer;
- }
- /**
- * @METHOD NAME : getByte
- * @INFORMATION : This method converts passed parameter to Byte
- and returns Byte, if the parameter is not null
- else returns null.
- * @PARAM : stringData
- * @RETURN : class java.lang.Byte
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static Byte getByte(String stringData) throws GOSIBatchException
- {
- Byte byteConvert=null;
- try
- {
- if(stringData != null && !(stringData.equals("")))
- {
- byteConvert = new Byte(stringData);
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- GOSIBatchConstants.REAL_ESTATE,
- "GOSIBatchUtilities",
- "getByte()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return byteConvert;
- }
- /**
- * @METHOD NAME : getFloat
- * @INFORMATION : This method converts passed parameter to Float
- and returns Float, if the parameter is not null
- else returns null.
- * @PARAM : stringData
- * @RETURN : class java.lang.Float
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static Float getFloat(String stringData) throws GOSIBatchException
- {
- Float floatConvert=null;
- try
- {
- if(stringData != null && !(stringData.equals("")))
- {
- return new Float(stringData);
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- GOSIBatchConstants.REAL_ESTATE,
- "GOSIBatchUtilities",
- "getFloat()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return floatConvert;
- }
- /**
- * @METHOD NAME : getDouble
- * @INFORMATION : This method converts passed parameter to Double
- and returns Double, if the parameter is not null
- else returns null.
- * @PARAM : stringData
- * @RETURN : class java.lang.Double
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static Double getDouble(String stringData) throws GOSIBatchException
- {
- Double doubleConvert=null;
- try
- {
- if(stringData != null && !(stringData.equals("")))
- {
- doubleConvert = new Double(stringData);
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- GOSIBatchConstants.REAL_ESTATE,
- "GOSIBatchUtilities",
- "getDouble()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return doubleConvert;
- }
- /**
- * @METHOD NAME : getString
- * @INFORMATION : This method converts passed parameter to String
- and returns String, if the parameter is not null
- else returns null.
- * @PARAM : stringData
- * @RETURN : class java.lang.String
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static String getString(String stringData) throws GOSIBatchException
- {
- String stringConvert=null;
- try
- {
- if(stringData != null && !(stringData.equals("")))
- {
- stringConvert = stringData;
- }
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- GOSIBatchConstants.REAL_ESTATE,
- "GOSIBatchUtilities",
- "getString()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return stringConvert;
- }
- /**
- * @METHOD NAME : getSystemUser
- * @INFORMATION : This method gets the user id for the system
- * @RETURN : systemuserid
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static long getSystemUser()
- throws GOSIBatchException
- {
- Connection connection=null;
- PreparedStatement psUser=null;
- ResultSet rsUser=null;
- boolean invoke=false;
- long userCode=0L;
- try
- {
- // Executing query for getting the system user id
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1021");
- connection=GOSIBatchUtilities.
- getDbConnection(GOSIBatchConstants.COMMON);
- psUser=connection.prepareStatement(query);
- psUser.setString(1,GOSIBatchProperties.SYSTEM_USER+"%");
- rsUser=psUser.executeQuery();
- //this if is no longer used
- if(rsUser.next())
- {
- userCode=rsUser.getLong("ID");
- }
- else
- {
- new GOSIBatchException(null,
- "BatchCore",
- "GOSIBatchUtilities",
- "getBatchMaster",
- "CMN_001_ERR_1006",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "Constructor",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rsUser, psUser, connection);
- }
- return userCode;
- }
- /**
- * @METHOD NAME : getTaskId
- * @INFORMATION : This method is used to get the Task id based on
- the workflow task short name passed as a parameter.
- * @PARAM : shortName
- * @RETURN : long
- * @EXCEPTION : class gosi.core.util.GOSIException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private long getTaskId(String shortName)
- throws GOSIBatchException
- {
- Connection connection=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- long taskId=0L;
- try
- {
- connection=GOSIBatchUtilities.
- getDbConnection(GOSIBatchConstants.COMMON);
- String query=GOSIBatchSQL.getSqlString("CMN_030_SQL_1001");
- //Getting taskId for the ShortName Passed
- ps=connection.prepareStatement(query);
- ps.setString(1, shortName);
- rs=ps.executeQuery();
- if(rs.next())
- {
- taskId=rs.getLong("TASKID");
- }
- else
- {
- throw new GOSIBatchException(null,
- GOSIBatchConstants.WORKFLOW,
- "GOSIBatchUtilities",
- "getTaskId()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- GOSIBatchConstants.WORKFLOW,
- "GOSIBatchUtilities",
- "getTaskId()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs, ps, connection);
- }
- return taskId;
- }
- /**
- * @METHOD NAME : cancelWorkflow
- * @INFORMATION : This method is used to cancel workflow record (e.g. child)
- : and Update parent record description if parent is present
- : and it has only this child
- * @PARAM :
- * @RETURN : ArrayList
- * @EXCEPTION : class gosi.core.util.GOSIException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public ArrayList cancelWorkflow (String actionName, Timestamp fromDate)
- throws GOSIBatchException
- {
- ArrayList workflowtxnList=new ArrayList();
- Connection connection=null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- long taskId=0L;
- try
- {
- // get taskid using actionName
- taskId=getTaskId(actionName);
- connection=GOSIBatchUtilities.
- getDbConnection(GOSIBatchConstants.COMMON);
- String query=GOSIBatchSQL.getSqlString("CMN_030_SQL_1002");
- // get arraylist of records to be cancelled
- ps = connection.prepareStatement(query);
- ps.setLong(1, taskId);
- ps.setTimestamp(2, fromDate);
- rs = ps.executeQuery();
- while(rs.next())
- {
- BatchWorkflowParamBean workflowBean = new BatchWorkflowParamBean();
- workflowBean.setWorkflowId(rs.getLong("WORKFLOWTXNID"));
- workflowBean.setTransactionId(rs.getLong("TRANSACTIONID"));
- workflowBean.setPrimaryKey(rs.getString("PRIMARYKEY"));
- workflowBean.setParentPrimaryKey(rs.getString("PARENTPRIMARYKEY"));
- // add to the list of beans
- workflowtxnList.add(workflowBean);
- // Update as deleted in workflowTXN
- updateDeleted(workflowBean);
- // Update parent record description if parent is present
- updateParentOfDeleted(workflowBean);
- }
- }catch(Exception e)
- {
- throw new GOSIBatchException(e,
- GOSIBatchConstants.WORKFLOW,
- "GOSIBatchUtilities",
- "cancelWorkflow()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs, ps, connection);
- }
- return workflowtxnList;
- }
- /**
- * @METHOD NAME : updateDeleted
- * @INFORMATION : This method is to update workflowTxn records as cancelled
- :
- * @PARAM :
- * @RETURN : ArrayList
- * @EXCEPTION : class gosi.core.util.GOSIException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private void updateDeleted (BatchWorkflowParamBean workflowBean)
- throws GOSIBatchException
- {
- Connection connection=null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- long workflowId=0L;
- try
- {
- workflowId=workflowBean.getWorkflowId();
- connection=GOSIBatchUtilities.
- getDbConnection(GOSIBatchConstants.COMMON);
- String update=GOSIBatchSQL.getSqlString("CMN_030_SQL_1003");
- //check if parent exists
- //Get parent TransactionId for the record Passed
- ps = connection.prepareStatement(update);
- ps.setTimestamp(1,getSystemDate());
- ps.setString(2, GOSIBatchConstants.CANCELLED);
- ps.setLong(3, workflowId);
- int result=ps.executeUpdate();
- connection.commit();
- }catch(Exception e)
- {
- throw new GOSIBatchException(e,
- GOSIBatchConstants.WORKFLOW,
- "GOSIBatchUtilities",
- "updateDeleted()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs, ps, connection);
- }
- }
- /**
- * @METHOD NAME : updateParentOfDeleted
- * @INFORMATION : This method is used to update Parent record Of Canceled workflow
- : so that parent could be moved from workflowTemp
- * @PARAM :
- * @RETURN :
- * @EXCEPTION : class gosi.core.util.GOSIException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private void updateParentOfDeleted (BatchWorkflowParamBean workflowBean)
- throws GOSIBatchException
- {
- Connection connection=null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- long workflowId=0L;
- long transactionId=0L;
- String ParentPrimaryKey=null;
- long parentTransactionId=0L;
- try
- {
- workflowId=workflowBean.getWorkflowId();
- transactionId=workflowBean.getTransactionId();
- ParentPrimaryKey=workflowBean.getParentPrimaryKey();
- connection=GOSIBatchUtilities.
- getDbConnection(GOSIBatchConstants.COMMON);
- String query=GOSIBatchSQL.getSqlString("CMN_030_SQL_1004");
- //check if parent exists
- //Get parent TransactionId for the record Passed
- ps = connection.prepareStatement(query);
- ps.setLong(1, transactionId);
- ps.setByte(2, GOSIBatchConstants.CHILD);
- rs = ps.executeQuery();
- if(rs.next())
- {
- parentTransactionId=rs.getLong("ID");
- // Update parent record description in workflowTemp
- String update=GOSIBatchSQL.getSqlString("CMN_030_SQL_1005");
- ps = connection.prepareStatement(update);
- ps.setByte(1, GOSIBatchConstants.PROCESS);
- ps.setString(2, GOSIBatchConstants.CHILD_CANCELLED);
- ps.setLong(3, parentTransactionId);
- ps.setString(4, ParentPrimaryKey);
- int result=ps.executeUpdate();
- connection.commit();
- }
- }catch(Exception e)
- {
- throw new GOSIBatchException(e,
- GOSIBatchConstants.WORKFLOW,
- "GOSIBatchUtilities",
- "updateParentOfDeleted()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs, ps, connection);
- }
- }
- /**
- * @METHOD NAME : isArabNation
- * @INFORMATION : This method is used to update Parent record Of Canceled workflow
- : so that parent could be moved from workflowTemp
- * @PARAM :
- * @RETURN : boolean
- * @EXCEPTION : class gosi.core.util.GOSIException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static boolean isArabNation(short countryCode)
- {
- boolean isNatArabic = false;
- List arbNationCodeList = GOSIBatchConstants.arbNationCodeList;
- ArrayList arbNationCodeArrayList =new ArrayList(arbNationCodeList);
- if(!arbNationCodeArrayList.contains(""+countryCode))
- {
- isNatArabic=false;
- }
- else
- {
- isNatArabic=true;
- }
- return isNatArabic;
- }
- /**
- * @METHOD NAME : getPendingWSRequests
- * @INFORMATION : returns a hashmap of all pending requests that are of type wsname
- * @RETURN : HashMap
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static ArrayList getPendingWSRequests(String WSName)
- throws GOSIBatchException
- {
- //get all ids for the pending requests from T_WSTRANSACTION that belongs to the passed WSName
- //decode all objects, coresponding to the returned ids, stored as files to java objects
- // store objects as the value of the hashmap and the ids as the keys
- //reurn this hashmap to be casted to any type depending on the caller. who will return the same keys and values to stored
- Connection connection=null;
- PreparedStatement psWSReq=null;
- ResultSet rsWSReq=null;
- ArrayList reqs=new ArrayList();
- HashMap idsObjs=null;
- try
- {
- // Executing query to get pending requests
- // SELECT a.ID, a.USERID, i.USERREFERENCEID
- // from T_WSTRANSACTION a , T_WSTASK b, T_USER_INTERNET i
- // where a.TASKID = b.TASKID and a.USERID = i.ID and a.STATUS = 1003 and b.WSNAME = ?;
- String query= GOSIBatchSQL.getSqlString("CMN_001_SQL_1068");
- connection=GOSIBatchUtilities.getDbConnection(GOSIBatchConstants.COMMON);
- psWSReq=connection.prepareStatement(query);
- psWSReq.setInt(1,GOSIBatchConstants.PENDING);
- psWSReq.setString(2,WSName);
- rsWSReq=psWSReq.executeQuery();
- while(rsWSReq.next())
- {
- long wsId=rsWSReq.getLong("ID");
- System.out.println("wsId : "+wsId);
- XMLDecoder d = new XMLDecoder(
- new BufferedInputStream(
- new FileInputStream(GOSIBatchConstants.FILEPATH_WS_REQUEST+wsId+".xml")));
- Object result = d.readObject();
- d.close();
- idsObjs = new HashMap();
- idsObjs.put("ID", new Long(wsId));
- idsObjs.put("OBJECT", result);
- idsObjs.put("USERID", new Long(rsWSReq.getLong("USERID")));
- idsObjs.put("USERREFERENCEID", new Long(rsWSReq.getLong("USERREFERENCEID")));
- reqs.add(idsObjs);
- }
- // This will only be executed on Preprod and never executed on Production.
- // It will return the pending requests that was received without passing certificate.
- // Those pending requests has user id = 1 thus the above query doesn't return them back.
- // See Registration MonthlyMovementWS documentation for detailed design and info.
- // SELECT a.ID, a.USERID from T_WSTRANSACTION a , T_WSTASK b
- // where a.TASKID = b.TASKID and a.USERID = 1 and a.STATUS = 1003 and b.WSNAME = ?
- long system = 1;
- query= GOSIBatchSQL.getSqlString("CMN_001_SQL_1073");
- psWSReq=connection.prepareStatement(query);
- psWSReq.setLong(1,new Long (system));
- psWSReq.setInt(2,GOSIBatchConstants.PENDING);
- psWSReq.setString(3,WSName);
- rsWSReq=psWSReq.executeQuery();
- while(rsWSReq.next())
- {
- long wsId=rsWSReq.getLong("ID");
- System.out.println("wsId : "+wsId);
- XMLDecoder d = new XMLDecoder(
- new BufferedInputStream(
- new FileInputStream(GOSIBatchConstants.FILEPATH_WS_REQUEST+wsId+".xml")));
- Object result = d.readObject();
- d.close();
- idsObjs = new HashMap();
- idsObjs.put("ID", new Long(wsId));
- idsObjs.put("OBJECT", result);
- idsObjs.put("USERID", new Long(rsWSReq.getLong("USERID")));
- reqs.add(idsObjs);
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "getPendingWSRequests",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rsWSReq, psWSReq, connection);
- }
- return reqs;
- }
- /**
- * @METHOD NAME : updateWSRequests
- * @INFORMATION : updates all web services requests that are passed
- * @RETURN : void
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void updateWSRequests(ArrayList processedReqs)
- throws GOSIBatchException
- {
- //loop thru the hashmap and update the status of each id (key) in the hashmap to processed
- //encode each object (value) in the hashmap to xml file in the output dir.
- Connection connection=null;
- PreparedStatement psWSReq=null;
- try
- {
- System.out.println("The size of ArrayList = "+processedReqs.size());
- System.out.println("If ArrayList empty = "+processedReqs.isEmpty());
- System.out.println("The elements of ArrayList are");
- while(!processedReqs.isEmpty()){
- HashMap idsObjs = (HashMap)processedReqs.remove(0);
- Long wsId = (Long)idsObjs.get("ID");
- Object procObject = idsObjs.get("OBJECT");
- //Long wsId=(Long)iter.next();
- System.out.println("wsId : "+wsId);
- //Object procObject = processedReqs.get(wsId);
- System.out.println("Object " + procObject);
- //CMN_001_SQL_1069
- String query= GOSIBatchSQL.getSqlString("CMN_001_SQL_1069");
- //"UPDATE T_WSTRANSACTION SET STATUS = "+GOSIBatchConstants.PROCESSED+" where ID = ? ";
- //GOSIBatchSQL.getSqlString("CMN_001_SQL_1021");
- connection=GOSIBatchUtilities.
- getDbConnection(GOSIBatchConstants.COMMON);
- psWSReq=connection.prepareStatement(query);
- psWSReq.setLong(1,GOSIBatchConstants.PROCESSED);
- psWSReq.setLong(2,wsId.longValue());
- int result=psWSReq.executeUpdate();
- connection.commit();
- XMLEncoder e = new XMLEncoder(
- new BufferedOutputStream(
- new FileOutputStream(GOSIBatchConstants.FILEPATH_WS_RESPONSE+wsId+".xml")));
- e.writeObject(procObject);
- e.close();
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "updateWSRequests",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(psWSReq, connection);
- }
- }
- /**
- * @METHOD NAME : createSMSRequest
- * @INFORMATION : This method calls the method that creates sms requests for batches without defining a sending date.
- * @PARAM : smsShortName: represents shortname for the SMSMaster table
- * @PARAM : primaryKey: represents the primary key that will be inserted as a primary key for the query stored in the table SMSMaster
- * @PARAM : requestedBy: represents the person id who requested the service
- * @PARAM : connection: connection to the database
- * @RETURN : void
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void createSMSRequest(String smsShortName, String primaryKey, long requestedBy, Connection connection)
- throws GOSIBatchException
- {
- createSMSRequest( smsShortName, primaryKey, requestedBy, connection, null);
- }
- /**
- * @METHOD NAME : createSMSRequest
- * @INFORMATION : This method creates sms requests for batches. This method creates only one record per call
- * @PARAM : smsShortName: represents shortname for the SMSMaster table
- * @PARAM : primaryKey: represents the primary key that will be inserted as a primary key for the query stored in the table SMSMaster
- * @PARAM : requestedBy: represents the person id who requested the service
- * @PARAM : connection: connection to the database
- * @RETURN : void
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void createSMSRequest(String smsShortName, String primaryKey, long requestedBy, Connection connection, Timestamp sendingDate)
- throws GOSIBatchException
- {
- PreparedStatement psSMSId=null;
- ResultSet rsSMSId=null;
- try
- {
- long smsId = 0;
- String query= GOSIBatchSQL.getSqlString("CMN_030_SQL_1008");
- psSMSId=connection.prepareStatement(query);
- psSMSId.setString(1,smsShortName);
- rsSMSId=psSMSId.executeQuery();
- if(rsSMSId.next())
- {
- smsId=rsSMSId.getLong("ID");
- GOSIBatchUtilities.cleanUp(psSMSId);
- Long recordId = getPrimaryKey("T_SMSREQUEST", requestedBy);
- query= GOSIBatchSQL.getSqlString("CMN_030_SQL_1009");
- psSMSId=connection.prepareStatement(query);
- psSMSId.setLong(1,smsId);
- psSMSId.setString(2,primaryKey);
- psSMSId.setInt(3,0);
- psSMSId.setTimestamp(4,getSystemDate());
- psSMSId.setLong(5,requestedBy);
- psSMSId.setLong(6,recordId.longValue());
- if (sendingDate != null)
- {
- psSMSId.setTimestamp(7,sendingDate);
- }
- else
- {
- psSMSId.setNull(7,java.sql.Types.TIMESTAMP);
- }
- int result=psSMSId.executeUpdate();
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "createSMSRequest",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rsSMSId);
- GOSIBatchUtilities.cleanUp(psSMSId);
- }
- }
- /**
- * @METHOD NAME : createSMSRequest
- * @INFORMATION : This method calls the method that creates sms requests for batches without defining a sending date.
- * @PARAM : smsShortName: represents shortname for the SMSMaster table
- * @PARAM : primaryKeys: represent the primary keys that will be inserted as a primary key for the query stored in the table SMSMaster
- * @PARAM : requestedBy: represents the person id who requested the service
- * @PARAM : connection: connection to the database
- * @RETURN : void
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void createSMSRequest(String smsShortName, ArrayList primaryKeys, long requestedBy, Connection connection)
- throws GOSIBatchException
- {
- createSMSRequest( smsShortName, primaryKeys, requestedBy, connection, null);
- }
- /**
- * @METHOD NAME : createSMSRequest
- * @INFORMATION : This method creates sms requests for batches, it takes list of primary keys
- * @PARAM : smsShortName: represents shortname for the SMSMaster table
- * @PARAM : primaryKeys: represent the primary keys that will be inserted as a primary key for the query stored in the table SMSMaster
- * @PARAM : requestedBy: represents the person id who requested the service
- * @PARAM : connection: connection to the database
- * @RETURN : void
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void createSMSRequest(String smsShortName, ArrayList primaryKeys, long requestedBy, Connection connection, ArrayList sendingDate)
- throws GOSIBatchException
- {
- PreparedStatement psSMSId=null;
- ResultSet rsSMSId=null;
- try
- {
- long smsId = 0;
- String query= GOSIBatchSQL.getSqlString("CMN_030_SQL_1008");
- psSMSId=connection.prepareStatement(query);
- psSMSId.setString(1,smsShortName);
- rsSMSId=psSMSId.executeQuery();
- //retrieve the master id for the message from the SMSMaster table based on the parameter smsShortName
- if(rsSMSId.next())
- {
- smsId=rsSMSId.getLong("ID");
- GOSIBatchUtilities.cleanUp(psSMSId);
- query= GOSIBatchSQL.getSqlString("CMN_030_SQL_1009");
- psSMSId=connection.prepareStatement(query);
- //iterate through all the provided primary keys then update the table SMSRequest
- for (int i=0; i< primaryKeys.size() ;i++ )
- {
- Long recordId = getPrimaryKey("T_SMSREQUEST", requestedBy);
- psSMSId.setLong(1,smsId);
- psSMSId.setString(2,primaryKeys.get(i).toString());
- psSMSId.setInt(3,0);
- psSMSId.setTimestamp(4,getSystemDate());
- psSMSId.setLong(5,requestedBy);
- psSMSId.setLong(6,recordId.longValue());
- if(sendingDate != null)
- {
- if(sendingDate.get(i) != null)
- {
- psSMSId.setTimestamp(7,(Timestamp) sendingDate.get(i));
- }
- else
- {
- psSMSId.setNull(7,java.sql.Types.TIMESTAMP);
- }
- }
- else
- {
- psSMSId.setNull(7,java.sql.Types.TIMESTAMP);
- }
- psSMSId.addBatch();
- }
- // Execute the SQL satement.
- psSMSId.executeBatch();
- psSMSId.clearBatch();
- }
- }
- catch(GOSIBatchException ge)
- {
- throw ge;
- }
- catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "createSMSRequest",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rsSMSId);
- GOSIBatchUtilities.cleanUp(psSMSId);
- }
- }
- /**
- * @METHOD NAME : checkDuplicateRecord
- * @INFORMATION : This method checks for duplicate in workflowtxn
- : it accepts workflowparambean and check the constraint
- : of the WorkflowTexn with the parametrs of workflowParambean
- :
- * @PARAM : workflowParambean
- * @RETURN : True if the there is a duplicate record, false otherwise
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static boolean checkDuplicateRecord(WorkflowTxn workflowTxn)
- throws GOSIBatchException
- {
- Connection connection=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- boolean duplicate = true;
- try
- {
- String query=GOSIBatchSQL.getSqlString("CMN_001_SQL_1070");
- // This is a workround to solve the problem of setting a DBNULL value
- // it seems that PreparedSatement.setNull(...,..) is not working, maybe due to
- // driver support problem. I could use the oracle type but it will not be portable then
- // This is just a workround for current situation and should be changed later on.
- // here if the value is null then I change the dynamic parameter to static parameter
- // [Colmun Name] IS NULL
- if (workflowTxn.getStatus() == null)
- {
- query = query.replaceAll("STATUS =\\?", " STATUS IS NULL ");
- }
- if (workflowTxn.getTimeOfCompletion() == null)
- {
- query = query.replaceAll("COMPLETIONTIME = \\?", " COMPLETIONTIME IS NULL ");
- }
- // Obtain the connection
- connection=GOSIBatchUtilities.getDbConnection(GOSIBatchConstants.COMMON);
- // Create a prepared statement.
- ps=connection.prepareStatement(query);
- // set the parameters.
- // These parameters are the constrait parameters
- // if these parameters found then there is a duplicate.
- ps.setLong(1,workflowTxn.getCreatedUserId());
- ps.setLong(2,workflowTxn.getTargetUserId());
- ps.setLong(3,workflowTxn.getTransactionId());
- ps.setLong(4,workflowTxn.getCompletedStepId());
- ps.setLong(5,workflowTxn.getPendingStepId());
- ps.setString(6,workflowTxn.getPrimaryKeys());
- ps.setLong(7,workflowTxn.getTargetRoleId());
- // Set the values if they are not equal to null.
- if (workflowTxn.getStatus() != null)
- {
- setString(ps,8,workflowTxn.getStatus());
- }
- if (workflowTxn.getTimeOfCompletion() != null)
- {
- setTimestamp(ps,9,workflowTxn.getTimeOfCompletion());
- }
- System.out.println("Query: "+query);
- // Exceute the query
- rs = ps.executeQuery();
- duplicate = rs.next();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- // Throw exception if the parameters not complete.
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "checkDuplicateRecord",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(rs, ps, connection);
- }
- // reutn the result.
- return duplicate;
- }
- /**
- * @METHOD NAME : sendFileToEndPoint
- * @INFORMATION : This method open https connection and send a file to an end point
- * @PARAM : File, string, long
- * @RETURN : void
- * @EXCEPTION : class gosi.common.batch.util.GOSIBatchException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static boolean sendFileToEndPoint(File file,String endPoint,int timeOutInMillseconds)
- throws GOSIBatchException
- {
- HttpsURLConnection conn = null;
- BufferedReader inStream = null;
- /*String lineEnd = "\r\n";
- String twoHyphens = "--";
- String boundary = "*****";
- int bytesRead, bytesAvailable, bufferSize;
- byte[] buffer;
- int maxBufferSize = 1*1024*1024; */
- String urlString = endPoint;
- boolean status=false;
- try
- {
- //------------------ CLIENT REQUEST---------------------\\
- // open a URL connection to the Servlet
- System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
- java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
- URL url = new URL(urlString);
- // Open HTTP connection to the URL
- try
- {
- conn.setConnectTimeout(timeOutInMillseconds);
- conn.setReadTimeout(timeOutInMillseconds);
- conn = (HttpsURLConnection) url.openConnection();
- }
- catch(Exception e)
- {
- System.out.println("Exception in connection");
- e.printStackTrace();
- }
- // setup SSL-configuration
- // Allow Inputs
- conn.setDoInput(true);
- // Allow Outputs
- conn.setDoOutput(true);
- // Don't use a cached copy.
- conn.setUseCaches(false);
- // Don't ask the user.
- conn.setAllowUserInteraction(false);
- // Use a post method.
- conn.setRequestMethod("POST");
- conn.setRequestProperty("Connection", "Keep-Alive");
- // conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
- conn.setRequestProperty("Content-Type", "application/octet-stream");
- //connect
- conn.connect();
- DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
- dumpFile(file, dos);
- /*dos.writeBytes(twoHyphens + boundary + lineEnd);
- dos.writeBytes("Content-Disposition: form-data; name=\"upload\";"
- + " filename=\"" + exsistingFileName +"\"" + lineEnd);
- dos.writeBytes(lineEnd);
- // create a buffer of maximum size
- bytesAvailable = fileInputStream.available();
- bufferSize = Math.min(bytesAvailable, maxBufferSize);
- buffer = new byte[bufferSize];
- // read file and write it into form...
- bytesRead = fileInputStream.read(buffer, 0, bufferSize);
- while (bytesRead > 0)
- {
- dos.write(buffer, 0, bufferSize);
- bytesAvailable = fileInputStream.available();
- bufferSize = Math.min(bytesAvailable, maxBufferSize);
- bytesRead = fileInputStream.read(buffer, 0, bufferSize);
- }
- // send multipart form data necesssary after file data...
- dos.writeBytes(lineEnd);
- dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
- */
- // close streams
- dos.flush();
- dos.close();
- }
- catch (MalformedURLException ex)
- {
- System.out.println(" CLIENT REQUEST:"+ex);
- new GOSIBatchException(ex,
- "BatchCore",
- "GOSIBatchUtilities",
- "sendFileToEndPoint",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- catch (IOException ioe)
- {
- System.out.println(" CLIENT REQUEST:"+ioe);
- new GOSIBatchException(ioe,
- "BatchCore",
- "GOSIBatchUtilities",
- "sendFileToEndPoint",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- catch (Exception e)
- {
- System.out.println(" CLIENT REQUEST e:"+e);
- e.printStackTrace();
- new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "sendFileToEndPoint",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- //------------------ read the SERVER RESPONSE -------------------\\
- try
- {
- if(conn.getResponseCode() == HttpsURLConnection.HTTP_OK)
- {
- inStream = new BufferedReader ( new InputStreamReader(conn.getInputStream()));
- System.setProperty("sun.net.client.defaultReadTimeout","30000");
- String str;
- while (( str = inStream.readLine()) != null)
- {
- System.out.println("Server response is: "+str);
- System.out.println("");
- }
- if(inStream.readLine()!=null)
- {
- status=true;
- }
- inStream.close();
- }
- else
- {
- System.out.println("\n\n-----sorry connetion failed-----");
- System.out.println("\n\nHTTP Response: " + conn.getResponseCode());
- }
- conn.disconnect();
- }
- catch (IOException ioex)
- {
- System.out.println("From (ServerResponse): "+ioex);
- throw new GOSIBatchException(ioex,
- "BatchCore",
- "GOSIBatchUtilities",
- "sendFileToEndPoint",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- catch (Exception e)
- {
- System.out.println("From (ServerResponse): e"+e);
- e.printStackTrace();
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "sendFileToEndPoint",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- return status;
- }
- /**
- * @METHOD NAME : dumpFile
- * @INFORMATION : This method wrtites the file data in to the given outputstream
- * @PARAM : String,OutputStream
- * @RETURN :
- * @EXCEPTION : class gosi.core.util.GOSIException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- private static void dumpFile(File file, OutputStream outputstream)
- throws GOSIBatchException
- {
- byte abyte0[] = new byte[4096];
- try
- {
- BufferedInputStream bufferedinputstream = new BufferedInputStream(new FileInputStream(file));
- int i;
- while((i = bufferedinputstream.read(abyte0, 0, 4096)) != -1)
- outputstream.write(abyte0, 0, i);
- bufferedinputstream.close();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "dumpFile()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- }
- /**
- * @METHOD NAME : updateFieldOfficeVillageMap
- * @INFORMATION : This methods is used to update column (PROCESSED)
- in table T_FIELDOFFICEVILLAGEMAP
- * @PARAM :
- * @RETURN :
- * @EXCEPTION : class gosi.core.util.GOSIException
- * @LAST MODIFIED BY :
- * @LAST MODIFIED DATE :
- **/
- public static void updateFieldOfficeVillageMap()
- throws GOSIBatchException
- {
- Connection connection=null;
- PreparedStatement ps = null;
- String update = null;
- try
- {
- update = GOSIBatchSQL.getSqlString("CMN_001_SQL_1074");
- connection = getDbConnection(GOSIBatchConstants.COMMON);
- ps = connection.prepareStatement(update);
- ps.executeUpdate();
- connection.commit();
- }catch(Exception e)
- {
- throw new GOSIBatchException(e,
- "BatchCore",
- "GOSIBatchUtilities",
- "updateFieldOfficeVillageMap()",
- "CMN_001_ERR_1000",
- GOSIBatchConstants.SEVERITY_ONE);
- }
- finally
- {
- GOSIBatchUtilities.cleanUp(ps, connection);
- }
- }
- }
Add Comment
Please, Sign In to add comment