Commit 978b333b authored by steurwadkar's avatar steurwadkar

F17ABAS001 source code commit


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@106419 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 7a1b14ea
......@@ -866,29 +866,6 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
rs.close();
rs = null;
}
/*sql = "SELECT COUNT(1) AS CNT FROM GST_DATA_HDR WHERE REC_TYPE = '1' AND SUBMIT_STATUS = 'P' AND PRD_CODE = ? AND SITE_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, periodCode);
pstmt.setString(2, loginSiteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
if(rs.getInt("CNT") > 0)
{
errList.add( "VTPENGSREC" );
errFields.add("returns_type");
}
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(rs!=null)
{
rs.close();
rs = null;
}*/
}
if("FILE".equalsIgnoreCase(action))
{
......
......@@ -7,7 +7,6 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Calendar;
......@@ -234,10 +233,6 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
String loginCode = "", chgTerm = "", callStatus = "", responseId = "", responseJsonStr= "";
byte[] authSEK = null;
String sql = "", tokenStr = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
APICallData apiCallData = null;
boolean isDataLogged = false;
......@@ -363,40 +358,6 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
appKeyInBytes = aesEncryption.decodeBase64StringTOByte(appKey);
appKeyEncryptedAndCoded = pubKeyEncryption.encrypt(appKeyInBytes);
/*sql ="SELECT RESPONSE_INFO FROM API_CALL_LOG WHERE CALL_TYPE='AUTHTOKEN' AND CALL_STATUS = '1' AND SITE_CODE = ? ORDER BY CALL_DATE DESC";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
tokenStr = checkNullandTrim((rs.getString("RESPONSE_INFO")));
System.out.println("560101.inside if auth token found in table["+tokenStr+"]");
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(tokenStr.split(":").length > 0)
{
authToken = tokenStr.split(":")[0];
sek = tokenStr.split(":")[1];
}
if(authToken!=null && authToken.trim().length()>0 && sek!=null && sek.trim().length()>0)
{
System.out.println("560101.authtoken and sek found database");
System.out.println("560101.authTokenDB["+authToken+"]");
System.out.println("560101.sekDB["+sek+"]");
}*/
if(authToken.trim().length() > 0 && sek.trim().length() > 0)
{
System.out.println("authToken and authSEK from detail2");
......@@ -552,6 +513,14 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{
retString = saveGstr2(authToken, siteCode, stateCode, userName, gstin, periodCode, grossTurnover, currentYearTurnover, authSEK, xtraParams, conn);
}
else if ("FILE".equalsIgnoreCase(action))
{
retString = fileGstr2(authToken, stateCode, userName, gstin, periodCode, authSEK, summaryData, signedData, panNo, aadhaarNo, signMethod, xtraParams, conn);
}
else if ("SUBMIT".equalsIgnoreCase(action))
{
retString = submitGstr2(authToken, stateCode, userName, gstin, periodCode, authSEK, xtraParams, conn);
}
}
}
}
......@@ -1670,7 +1639,6 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
try
{
siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
......@@ -1696,24 +1664,29 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
System.out.println("RETSUBMIT request url ["+String.format("%s%s", GSP_API_URL, GSTR1_URL_V3)+"]");
HttpRequest gstr1SubmitReq = Unirest.post(String.format("%s%s", GSP_API_URL, GSTR1_URL_V3))
.header("Content-Type", APPLICATION_JSON)
.header("action", "RETSUBMIT")
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress)
.header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(reqBody.toString()))
.getHttpRequest();
HttpResponse<JsonNode> gstr1SubmitResp = Unirest.post(String.format("%s%s", GSP_API_URL, GSTR1_URL_V3))
.header("Content-Type", APPLICATION_JSON)
.header("action", "RETSUBMIT")
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress)
.header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(reqBody.toString()))
.asJson();
System.out.println("RETSUBMIT GSTR1 url["+gstr1SubmitReq.getUrl()+"]");
System.out.println("RETSUBMIT GSTR1 method["+gstr1SubmitReq.getHttpMethod()+"]");
System.out.println("RETSUBMIT GSTR1 request header["+gstr1SubmitReq.getHeaders()+"]");
System.out.println("RETSUBMIT GSTR1 request payload["+IOUtils.toString(gstr1SubmitReq.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> gstr1SubmitResp = gstr1SubmitReq.asJson();
System.out.println(String.format("gstr1SubmitResp Request : Status[%s] Response[%s]", gstr1SubmitResp.getStatus(), gstr1SubmitResp.getBody()));
......@@ -1736,11 +1709,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
responseId = transId;
System.out.println("transId to getStatus after SUBMIT call["+transId+"]");
sql = "UPDATE GST_DATA_HDR SET SUBMIT_STATUS = ? AND SUBMIT_DATE = ? WHERE PRD_CODE = ? AND SITE_CODE = ?";
sql = "UPDATE GST_DATA_HDR SET SUBMIT_STATUS = ? AND SUBMIT_DATE = ? WHERE PRD_CODE = ? AND SITE_CODE = ? AND REC_TYPE = '1'";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "S");
pstmt.setString(2, new SimpleDateFormat(new E12GenericUtility().getApplDateFormat()).format(new Date()));
pstmt.setTimestamp(2, java.sql.Timestamp.valueOf(e12GenericUtility.getValidDateString(new Date(), e12GenericUtility.getDBDateTimeFormat())));
pstmt.setString(3, periodCode);
pstmt.setString(4, siteCode);
......@@ -1810,7 +1783,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "", signType = "",signId = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
String loginCode = "", chgTerm = "", siteCode = "", callStatus = "", responseJsonStr = "";
String loginCode = "", chgTerm = "", siteCode = "", callStatus = "", responseJsonStr = "", responseId = "";
try
{
......@@ -1891,6 +1864,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
byte[] fileGstr1JsonInBytes = aesEncryption.decodeBase64StringTOByte(fileGstr1JsoninBase64);
System.out.println(new String(fileGstr1JsonInBytes));
responseId = new String(fileGstr1JsonInBytes);
}
else
{
......@@ -1919,7 +1894,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
apiCallData.setRecType("1");
apiCallData.setNoOfRecords(0);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId("");
apiCallData.setResponseId(responseId);
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date());
......@@ -2351,6 +2326,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
udfStr1 = checkNullandTrim(lineRs.getString("UDF_STR1"));
udfStr2 = checkNullandTrim(lineRs.getString("UDF_STR2"));
udfStr3 = checkNullandTrim(lineRs.getString("UDF_STR3"));
System.out.println("udfStr1["+udfStr1+"] udfStr2["+udfStr2+"] udfStr3["+udfStr3+"]");
}
if(linePstmt!=null)
{
......@@ -3237,9 +3214,291 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
}
return retString;
}
private String submitGstr2(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSEK, String xtraParams,Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
String loginCode = "", chgTerm = "", siteCode = "", callStatus = "", responseJsonStr = "", responseId = "";
String sql = "";
PreparedStatement pstmt = null;
int updateCnt = 0;
try
{
siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
String json = "{\"gstin\":\""+gstin+"\",\"ret_period\":\""+periodCode+"\"}";
byte[] jsonBase64 = Base64.getEncoder().encode(json.getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSEK);
HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSEK));
hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0);
JSONObject reqBody = new JSONObject();
reqBody.put("action", "RETSUBMIT");
reqBody.put("data", encryptedPayload);
reqBody.put("hmac", new String(Base64.getEncoder().encode(resBuf)));
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpRequest gstr2SubmitReq = Unirest.post(String.format("%s%s", GSP_API_URL, GSTR2_URL_V3))
.header("Content-Type", APPLICATION_JSON)
.header("action", "RETSUBMIT")
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress)
.header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(reqBody.toString()))
.getHttpRequest();
System.out.println("RETSUBMIT GSTR2 url["+gstr2SubmitReq.getUrl()+"]");
System.out.println("RETSUBMIT GSTR2 method["+gstr2SubmitReq.getHttpMethod()+"]");
System.out.println("RETSUBMIT GSTR2 request header["+gstr2SubmitReq.getHeaders()+"]");
System.out.println("RETSUBMIT GSTR2 request payload["+IOUtils.toString(gstr2SubmitReq.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> gstr2SubmitResp = gstr2SubmitReq.asJson();
System.out.println(String.format("gstr2SubmitResp Request : Status[%s] Response[%s]", gstr2SubmitResp.getStatus(), gstr2SubmitResp.getBody()));
if (gstr2SubmitResp.getStatus() == 200)
{
JSONObject gstr2SubmitRespObj = gstr2SubmitResp.getBody().getObject();
if(gstr2SubmitRespObj.has("data") && gstr2SubmitRespObj.has("rek"))
{
callStatus = "1";
String gstr2Submitdata = gstr2SubmitRespObj.getString("data");
String gstr2Submitrek = gstr2SubmitRespObj.getString("rek");
byte[] apiEK = aesEncryption.decrypt(gstr2Submitrek, authSEK);
String respJsoninBase64 = new String(aesEncryption.decrypt(gstr2Submitdata, apiEK));
byte[] respJsonInBytes = aesEncryption.decodeBase64StringTOByte(respJsoninBase64);
JSONObject gstr2SubmitObj = new JSONObject(new String(respJsonInBytes));
String transId = gstr2SubmitObj.getString("reference_id");
responseId = transId;
System.out.println("transId to getStatus after SUBMIT call["+transId+"]");
sql = "UPDATE GST_DATA_HDR SET SUBMIT_STATUS = ? AND SUBMIT_DATE = ? WHERE PRD_CODE = ? AND SITE_CODE = ? AND REC_TYPE = '2'";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "S");
pstmt.setTimestamp(2, java.sql.Timestamp.valueOf(e12GenericUtility.getValidDateString(new Date(), e12GenericUtility.getDBDateTimeFormat())));
pstmt.setString(3, periodCode);
pstmt.setString(4, siteCode);
updateCnt = pstmt.executeUpdate();
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
System.out.println("submit status updated of ["+siteCode+"] for ["+periodCode+"] update count ["+updateCnt+"]");
}
else
{
callStatus = "2";
JSONObject errorJSON = gstr2SubmitResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else if(gstr2SubmitResp.getStatus() == 500)
{
callStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+gstr2SubmitResp.getStatus();
responseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
}
else
{
callStatus = "2";
JSONObject errorJSON = gstr2SubmitResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("RETSUBMIT");
apiCallData.setRecType("2");
apiCallData.setNoOfRecords(0);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId(responseId);
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.submitGstr2()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
private String fileGstr2(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSek, String summaryData, String signedData, String panNo, String aadhaarNo, String signMethod, String xtraParams, Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "", signType = "",signId = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
String loginCode = "", chgTerm = "", siteCode = "", callStatus = "", responseJsonStr = "";
try
{
siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
byte[] jsonBase64 = Base64.getEncoder().encode(summaryData.toString().getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSek);
HMac hmac = new HMac(new SHA256Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
hmac.init(new KeyParameter(authSek));
hmac.update(jsonBase64, 0, jsonBase64.length);
hmac.doFinal(resBuf, 0);
if("D".equalsIgnoreCase(signMethod))
{
signType = "DSC";
signId = panNo;
}
else if("E".equalsIgnoreCase(signMethod))
{
signType = "ESIGN";
signId = aadhaarNo;
}
JSONObject fileGstr2DataJsonObj = new JSONObject();
fileGstr2DataJsonObj.put("action", "RETFILE");
fileGstr2DataJsonObj.put("data", encryptedPayload);
fileGstr2DataJsonObj.put("hmac", new String(Base64.getEncoder().encode(resBuf)));
fileGstr2DataJsonObj.put("sign", signedData);
fileGstr2DataJsonObj.put("st", signType);
fileGstr2DataJsonObj.put("sid", signId);
HttpRequest fileGstr2Req = Unirest.post(String.format("%s%s", GSP_API_URL, GSTR2_URL_V3))
.header("Content-Type", APPLICATION_JSON)
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress)
.header("username", userName)
.header("auth-token", authToken)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(fileGstr2DataJsonObj.toString()))
.getHttpRequest();
System.out.println("FILE GSTR2 url["+fileGstr2Req.getUrl()+"]");
System.out.println("FILE GSTR2 method["+fileGstr2Req.getHttpMethod()+"]");
System.out.println("FILE GSTR2 request header["+fileGstr2Req.getHeaders()+"]");
System.out.println("FILE GSTR2 request payload["+IOUtils.toString(fileGstr2Req.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> fileGstr2Resp = fileGstr2Req.asJson();
System.out.println(String.format("fileGstr2Resp Request : Status[%s] Response[%s]", fileGstr2Resp.getStatus(), fileGstr2Resp.getBody()));
if (fileGstr2Resp.getStatus() == 200)
{
JSONObject fileGstr2RespObj = fileGstr2Resp.getBody().getObject();
if(fileGstr2RespObj.has("data") && fileGstr2RespObj.has("rek"))
{
callStatus = "1";
String fileGstr2Data = fileGstr2RespObj.getString("data");
String fileGstr2Rek = fileGstr2RespObj.getString("rek");
byte[] fileGstr2ApiEK = aesEncryption.decrypt(fileGstr2Rek, authSek);
String fileGstr2JsoninBase64 = new String(aesEncryption.decrypt(fileGstr2Data, fileGstr2ApiEK));
byte[] fileGstr2JsonInBytes = aesEncryption.decodeBase64StringTOByte(fileGstr2JsoninBase64);
System.out.println(new String(fileGstr2JsonInBytes));
}
else
{
callStatus = "2";
JSONObject errorJSON = fileGstr2Resp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
}
else
{
callStatus = "2";
JSONObject errorJSON = fileGstr2Resp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
retString = getError(errMsg, "GSTAPIERR", conn);
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("RETFILE");
apiCallData.setRecType("2");
apiCallData.setNoOfRecords(0);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId("");
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(chgTerm);
gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizPos.fileGstr2()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
private void insertB2BInvoiceData(String stateCode, String periodCode, String siteCode, JSONObject gstr2InvoiceJsonObj, String xtraParams, Connection conn) throws ITMException
{
JSONArray b2bInvArry = new JSONArray();
......@@ -4269,7 +4528,6 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
throw new ITMException(e);
}
}
private void updateSubmissionStatus(ArrayList<String> tranIdList, Connection conn) throws ITMException
{
String updateSql = "";
......
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