Commit 09f77f13 authored by ssalve's avatar ssalve

source code for GSTRegNoPosEJB , GSTRegNoPosEJBLocal and GSTRegNoPosEJBRemote


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@105881 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 6aaeb47d
/*
* Author:Wasim Ansari
* Date:03-05-2017
* Request ID:F17BBAS001 (GST Wizard Post Save Component for Reconciliation Trace)
*/
package ibase.webitm.ejb.gst;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless
public class GSTRegNoPosEJB extends ValidatorEJB implements GSTRegNoPosEJBRemote,GSTRegNoPosEJBLocal
{
E12GenericUtility genericUtility = new E12GenericUtility();
ITMDBAccessEJB itmDBAccessLocal = new ITMDBAccessEJB();
/**
* Default constructor.
*/
public GSTRegNoPosEJB() {
// TODO Auto-generated constructor stub
}
@Override
public String postSave(String xmlStringAll, String tranID, String editFlag, String xtraParams, Connection conn) throws RemoteException, ITMException
{
String retString="";
try
{
retString = postSave(xmlStringAll, xtraParams, "", conn);
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
public String postSave(String xmlstring, String xtraParams, String forcedFlag, Connection conn) throws RemoteException,ITMException
{
System.out.println("Inside GSTRegNoPosEJB Post Save ["+xmlstring+"] \n xtraParams ["+xtraParams+"] \n forcedFlag["+forcedFlag+"]");
String finEntity="",finDescr="",siteCode="",siteDescr="",regNo="",regNo1="",regNo2="";
String validUpto=null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Timestamp currDate = null;
Timestamp validUptoDate = null;
boolean isError = false,isLocCon = false;
Document dom = null;
String sql = "",retString = "",tranID = "", tranIdGSTN = "";
String gstInNo = "GSTIN_NO";
String gstUserName = "GST_UNAME";
String gstGT = "GST_GT";
int cnt = 0;
String gstRefCode = "";
String loginSite = "";
java.sql.Date chg_date=null;
String val = "";
try
{
if(conn == null || conn.isClosed())
{
System.out.println("@@Connection is null");
conn = getConnection();
isLocCon = true;
}
else
{
System.out.println("@@Connection is not null");
}
if(xmlstring != null && (xmlstring.indexOf("Detail1") != -1))
{
currDate = new java.sql.Timestamp(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getDBDateFormat());
SimpleDateFormat sdfAppl = new SimpleDateFormat(genericUtility.getApplDateFormat());
String currDateStr = sdfAppl.format(currDate.getTime());
currDate = Timestamp.valueOf(genericUtility.getValidDateString(currDateStr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
//currDate = Timestamp.valueOf(genericUtility.getValidDateString(currDateStr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()));
System.out.println("currDate:::::::::"+currDate);
dom = genericUtility.parseString(xmlstring);
NodeList detail1NodeList =dom.getElementsByTagName("Detail1");
int detail3NodeListlen = detail1NodeList.getLength();
loginSite = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
System.out.println("loginSite>>>>>>>>>>"+loginSite);
for(int ctrH = 0; ctrH < detail3NodeListlen ; ctrH++)
{
NodeList childNodeList = detail1NodeList.item(ctrH).getChildNodes();
int childNodeListlen = childNodeList.getLength();
System.out.println("childNodeListlen>>>>>"+childNodeListlen);
for(int ctrD = 0; ctrD < childNodeListlen ; ctrD++)
{
Node childNode = childNodeList.item(ctrD);
if(childNode != null && "fin_entity".equalsIgnoreCase(childNode.getNodeName()) && childNode.getFirstChild() != null)
{
finEntity = checkNullAndTrim(childNode.getFirstChild().getNodeValue());
}
else if(childNode != null && "finent_descr".equalsIgnoreCase(childNode.getNodeName()) && childNode.getFirstChild() != null)
{
finDescr = checkNullAndTrim(childNode.getFirstChild().getNodeValue());
}
else if(childNode != null && "site_code".equalsIgnoreCase(childNode.getNodeName()) && childNode.getFirstChild() != null)
{
siteCode = checkNullAndTrim(childNode.getFirstChild().getNodeValue());
}
else if(childNode != null && "site_descr".equalsIgnoreCase(childNode.getNodeName()) && childNode.getFirstChild() != null)
{
siteDescr = checkNullAndTrim(childNode.getFirstChild().getNodeValue());
}
else if(childNode != null && "reg_no".equalsIgnoreCase(childNode.getNodeName()) && childNode.getFirstChild() != null)
{
regNo = checkNullAndTrim(childNode.getFirstChild().getNodeValue());
}
else if(childNode != null && "reg_no1".equalsIgnoreCase(childNode.getNodeName()) && childNode.getFirstChild() != null)
{
regNo1 = checkNullAndTrim(childNode.getFirstChild().getNodeValue());
}
else if(childNode != null && "reg_no2".equalsIgnoreCase(childNode.getNodeName()) && childNode.getFirstChild() != null)
{
regNo2 = checkNullAndTrim(childNode.getFirstChild().getNodeValue());
}
else if(childNode != null && "valid_upto".equalsIgnoreCase(childNode.getNodeName()) && childNode.getFirstChild() != null)
{
validUpto = checkNullAndTrim(childNode.getFirstChild().getNodeValue());
}
}
}
System.out.println("finEntity["+finEntity+"]"+"finDescr["+finDescr+"]"+"siteCode["+siteCode+"]"+"siteDescr["+siteDescr+"]"+"regNo["+regNo+"]"+"regNo1["+regNo1+"]"+"regNo2["+regNo2+"]"+"validUpto["+validUpto+"]");
validUptoDate = Timestamp.valueOf(genericUtility.getValidDateString(validUpto, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
System.out.println("validUptoDate["+validUptoDate+"]");
ArrayList gstList = new ArrayList();
gstList.add(regNo);
gstList.add(regNo1);
gstList.add(regNo2);
HashMap map = new HashMap();
map.put(regNo, "GSTIN_NO");
map.put(regNo1, "GST_UNAME");
map.put(regNo2, "GST_GT");
sql = "select count(*) as cnt from siteregno where fin_entity=? AND site_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,finEntity);
pstmt.setString(2,siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
cnt = rs.getInt("cnt");
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(cnt>0)
{
sql = "update siteregno set reg_no=?, valid_upto=? where fin_entity=? AND site_code=? AND ref_code=?";
pstmt = conn.prepareStatement(sql);
for(int x =0 ; x< gstList.size(); x++)
{
gstRefCode = (String) gstList.get(x);
val = (String) map.get(gstRefCode);
pstmt.setString(1,gstRefCode.trim());
pstmt.setTimestamp(2,validUptoDate);
pstmt.setString(3,finEntity);
pstmt.setString(4,siteCode);
pstmt.setString(5,val);
pstmt.executeUpdate();
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
else
{
sql = " insert into siteregno (fin_entity,site_code,ref_code,reg_no,valid_upto,chg_date,chg_user,eff_from) values(?,?,?,?,?,?,?,?)";
pstmt = conn.prepareStatement(sql);
for(int y =0 ; y< gstList.size(); y++)
{
gstRefCode = (String) gstList.get(y);
val = (String) map.get(gstRefCode);
pstmt.setString(1,finEntity);
pstmt.setString(2,siteCode);
pstmt.setString(3,val);
pstmt.setString(4, gstRefCode);
pstmt.setTimestamp(5,validUptoDate);
pstmt.setTimestamp(6,currDate);
pstmt.setString(7,loginSite);
pstmt.setTimestamp(8,currDate);
pstmt.addBatch();
}
pstmt.executeBatch();
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
}//End if Detail1 not found
else
{
System.out.println("Detail1 not found");
retString = itmDBAccessLocal.getErrorString("","VTBLNKDTL","","",conn);
return retString;
}
}
catch(Exception e)
{
System.out.println("Exception GSTRegNoPosEJB ==>"+e.getMessage());
isError = true;
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
System.out.println("Inside finally GSTRegNoPosEJB isError["+isError+"] connStatus["+isLocCon+"]");
if (rs != null )
{
rs.close();rs = null;
}
if( pstmt != null )
{
pstmt.close();pstmt = null;
}
if(isLocCon)
{
if(isError)
{
System.out.println("Inside rollbacking....");
conn.rollback();
}
else
{
System.out.println("Inside committing....");
conn.commit();
}
if (conn != null )
{
conn.close();conn = null;
}
}
}
catch( Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
System.out.println("errString from post save GSTRegNoPosEJB =["+retString+"]");
return retString;
}
private static String checkNullAndTrim(String input)
{
if (input==null)
{
input="";
}
return input.trim();
}
}
/*
* Author:Wasim Ansari
* Date:03-05-2017
* Request ID:S16EBAS006 (GST Wizard)
*/
package ibase.webitm.ejb.gst;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import javax.ejb.Local;
@Local
public interface GSTRegNoPosEJBLocal extends ValidatorLocal
{
public String postSave(String xmlStringAll, String tranId, String editFlag, String xtraParams, Connection conn) throws RemoteException,ITMException;
}
/*
* Author:Wasim Ansari
* Date:03-05-2017
* Request ID:S16EBAS006 (GST Wizard)
*/
package ibase.webitm.ejb.gst;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import javax.ejb.Remote;
@Remote
public interface GSTRegNoPosEJBRemote extends ValidatorRemote
{
public String postSave(String xmlStringAll, String tranId, String editFlag, String xtraParams, Connection conn) throws RemoteException,ITMException;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment