Commit e938a3d0 authored by steurwadkar's avatar steurwadkar

F17ABAS001 GST API integration wizard source code commit

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@165102 ce508802-f39f-4f6c-b175-0d175dae99d5
parent da685ed9
......@@ -260,7 +260,16 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
break;
}
}
closeResources(rs, pstmt);
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
System.out.println("BASE_API_URL["+BASE_API_URL+"]");
System.out.println("AUTH_TOKEN_URL["+AUTH_TOKEN_URL+"]");
......@@ -349,6 +358,8 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
byte[] authSEK = null;
String loginCode = "", chgTerm = "", callStatus = "", responseId = "", responseJsonStr= "", recType = "";
String signDataXML = "", summaryDataJsonStr = "";
ArrayList<HashMap<String,String>> getGstrDataList = new ArrayList<HashMap<String,String>>();
ArrayList<String> byPassSectionList = new ArrayList<String>();
System.out.println(" -------- Inside itemchange case 2222222 ------------ ");
if( currentColumn.trim().equalsIgnoreCase( "itm_default" ))
......@@ -397,6 +408,45 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
}
}
if("GETINV".equalsIgnoreCase(action))
{
sql = " SELECT TRAN_ID, RESPONSE_ID, CALL_DATE,CALL_TYPE"
+ " FROM API_CALL_LOG"
+ " WHERE SITE_CODE = ? AND REC_TYPE = ? AND PRD_CODE = ?"
+ " AND CALL_STATUS = ? AND CALL_TYPE LIKE '%GET%' AND RESPONSE_ID IS NOT NULL"
+ " ORDER BY CALL_DATE DESC";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
pstmt.setString(2, recType);
pstmt.setString(3, periodCode);
pstmt.setString(4, "0");
rs = pstmt.executeQuery();
while(rs.next())
{
HashMap<String,String> tempHMap = new HashMap<String,String>();
tempHMap.put("api_tranid", rs.getString("TRAN_ID"));
tempHMap.put("token", rs.getString("RESPONSE_ID"));
String tempStr = rs.getString("CALL_TYPE");
String section = tempStr.substring(tempStr.indexOf("_")+1);
tempHMap.put("section", section);
byPassSectionList.add(section);
getGstrDataList.add(tempHMap);
}
if(rs!=null)
{
rs.close();
rs = null;
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
}
transactionId = UUID.randomUUID().toString().replaceAll("-", "");
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
......@@ -511,7 +561,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
{
retXML += summaryDataJsonStr;
}
retXML += downloadGstr1Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
retXML += downloadGstr1Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK, byPassSectionList);
}
else if("FILE".equalsIgnoreCase(action))
{
......@@ -527,7 +577,61 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
}
else if("GETINV".equalsIgnoreCase(action))
{
retXML += downloadGstr1Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
if(getGstrDataList.size() > 0)
{
for(HashMap<String,String> eachDataHamp : getGstrDataList)
{
String sectionName = eachDataHamp.get("section");
JSONObject dataJSONObject = new JSONObject();
dataJSONObject.put("token", eachDataHamp.get("token"));
dataJSONObject.put("est", "");
dataJSONObject.put("api_tranid", eachDataHamp.get("api_tranid"));
String retDataXML = getDataFromFileServer(gstinNo, recType, periodCode, authToken, userName, stateCode, authSEK, dataJSONObject, sectionName, xtraParams);
if("B2B".equalsIgnoreCase(sectionName))
{
retXML += "<b2b_invoices>" + retDataXML + "</b2b_invoices>";
}
else if("B2CL".equalsIgnoreCase(action))
{
retXML += "<b2cl_invoices>" + retDataXML + "</b2cl_invoices>";
}
else if("B2CS".equalsIgnoreCase(action))
{
retXML += "<b2cs_invoices>" + retDataXML + "</b2cs_invoices>";
}
else if("CDNR".equalsIgnoreCase(action))
{
retXML += "<cdnr_data>" + retDataXML + "</cdnr_data>";
}
else if("CDNUR".equalsIgnoreCase(action))
{
retXML += "<cdnur_data>" + retDataXML + "</cdnur_data>";
}
else if("AT".equalsIgnoreCase(action))
{
retXML += "<at_data>" + retDataXML +"</at_data>";
}
else if("TXP".equalsIgnoreCase(action))
{
retXML += "<txp_data>" + retDataXML + "</txp_data>";
}
else if("NIL".equalsIgnoreCase(action))
{
retXML += "<nil_data>" + retDataXML + "</nil_data>";
}
else if("EXP".equalsIgnoreCase(action))
{
retXML += "<exp_data>" + retDataXML + "</exp_data>";
}
else if("HSNSUM".equalsIgnoreCase(action))
{
retXML += "<hsnsum_data>" + retDataXML + "</hsnsum_data>";
}
}
}
retXML += downloadGstr1Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK, byPassSectionList);
}
}
if("GSTR2".equalsIgnoreCase(returnType))
......@@ -543,7 +647,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
{
retXML += summaryDataJsonStr;
}
retXML += downloadGstr2Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
retXML += downloadGstr2Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK, byPassSectionList);
}
else if("FILE".equalsIgnoreCase(action))
{
......@@ -559,7 +663,65 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
}
else if("GETINV".equalsIgnoreCase(action))
{
retXML += downloadGstr2Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
if(getGstrDataList.size() > 0)
{
for(HashMap<String,String> eachDataHamp : getGstrDataList)
{
String sectionName = eachDataHamp.get("section");
JSONObject dataJSONObject = new JSONObject();
dataJSONObject.put("token", eachDataHamp.get("token"));
dataJSONObject.put("est", "");
dataJSONObject.put("api_tranid", eachDataHamp.get("api_tranid"));
String retDataXML = getDataFromFileServer(gstinNo, recType, periodCode, authToken, userName, stateCode, authSEK, dataJSONObject, sectionName, xtraParams);
if("B2B".equalsIgnoreCase(sectionName))
{
retXML += "<b2b_invoices>" + retDataXML + "</b2b_invoices>";
}
else if("IMPG".equalsIgnoreCase(action))
{
retXML += "<impg_data>" + retDataXML + "</impg_data>";
}
else if("IMPS".equalsIgnoreCase(action))
{
retXML += "<imps_data>" + retDataXML + "</imps_data>";
}
else if("CDN".equalsIgnoreCase(action))
{
retXML += "<cdnr_data>" + retDataXML + "</cdnr_data>";
}
else if("CDNUR".equalsIgnoreCase(action))
{
retXML += "<cdnur_data>" + retDataXML + "</cdnur_data>";
}
else if("NIL".equalsIgnoreCase(action))
{
retXML += "<nil_data>" + retDataXML + "</nil_data>";
}
else if("TXLI".equalsIgnoreCase(action))
{
retXML += "<txli_data>" + retDataXML + "</txli_data>";
}
else if("TXP".equalsIgnoreCase(action))
{
retXML += "<txp_data>" + retDataXML + "</txp_data>";
}
else if("HSNSUM".equalsIgnoreCase(action))
{
retXML += "<hsnsum_data>" + retDataXML + "</hsnsum_data>";
}
else if("B2BUR".equalsIgnoreCase(action))
{
retXML += "<b2bur_data>" + retDataXML + "</b2bur_data>";
}
else if("ITCRVSL".equalsIgnoreCase(action))
{
retXML += "<itcrvsl_data>" + retDataXML + "</itcrvsl_data>";
}
}
}
retXML += downloadGstr2Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK, byPassSectionList);
}
}
if("GSTR3B".equalsIgnoreCase(returnType))
......@@ -1658,7 +1820,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("final retResonseXML ["+retResponseXML+"]");
return retResponseXML;
}
private String downloadGstr1Data (String gstinNo, String periodCode, String authToken, String userName, String stateCode, String appKeyEncryptedAndCoded, String xtraParams, byte[] authSek) throws ITMException
private String downloadGstr1Data (String gstinNo, String periodCode, String authToken, String userName, String stateCode, String appKeyEncryptedAndCoded, String xtraParams, byte[] authSek, ArrayList<String> byPassSectionList) throws ITMException
{
StringBuffer retStringBuff = new StringBuffer();
String[] gstr1Section = {"B2B","B2CL","B2CS","CDNR","AT","TXP","NIL","EXP","HSNSUM","CDNUR"};
......@@ -1673,171 +1835,174 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
for(String action : gstr1Section)
{
long timeStamp = new Timestamp().getDateTime();
System.out.println("calling for ["+action+"]");
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpRequest getDataReq = Unirest.get(String.format("%s%s", BASE_API_URL, GSTR1_URL))
.queryString("action", action)
.queryString("gstin", gstinNo)
.queryString("ret_period", periodCode)
.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("app_key", appKeyEncryptedAndCoded)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstinNo)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.getHttpRequest();
System.out.println("get GSTR1 ["+action+"] invoices url["+getDataReq.getUrl()+"]");
System.out.println("get GSTR1 ["+action+"] invoices method["+getDataReq.getHttpMethod()+"]");
System.out.println("get GSTR1 ["+action+"] invoices request header["+getDataReq.getHeaders()+"]");
HttpResponse<JsonNode> getDataResp = getDataReq.asJson();
System.out.println("getDataResp.getStatus()["+getDataResp.getStatus()+"]");
if(getDataResp.getStatus() == 200)
if(byPassSectionList != null && !byPassSectionList.contains(action))
{
JSONObject getDataRespObj = getDataResp.getBody().getObject();
if(getDataRespObj.has("data") && getDataRespObj.has("rek"))
{
callStatus = "1";
String getdata = getDataRespObj.getString("data");
String getrek = getDataRespObj.getString("rek");
byte[] getapiEK = aesEncryption.decrypt(getrek, authSek);
String getrespJsoninBase64 = new String(aesEncryption.decrypt(getdata, getapiEK));
byte[] getrespJsonInBytes = aesEncryption.decodeBase64StringTOByte(getrespJsoninBase64);
String getjsonData = new String(getrespJsonInBytes);
System.out.println("json response["+getjsonData+"] for ["+action+"]");
JSONObject getJsonDataJsonObj = new JSONObject(getjsonData);
if(getJsonDataJsonObj.has("est") && getJsonDataJsonObj.has("token"))
{
dataXML = getDataFromFileServer(gstinNo, "1", periodCode, authToken, userName, stateCode, authSek, getJsonDataJsonObj, action, xtraParams);
}
else
{
dataXML = XML.toString(getJsonDataJsonObj);
//writeDatatoJsonFile(getJsonDataJsonObj.toString(), action);
}
if("B2B".equalsIgnoreCase(action))
{
retStringBuff.append("<b2b_invoices>");
retStringBuff.append(dataXML);
retStringBuff.append("</b2b_invoices>");
}
else if("B2CL".equalsIgnoreCase(action))
{
retStringBuff.append("<b2cl_invoices>");
retStringBuff.append(dataXML);
retStringBuff.append("</b2cl_invoices>");
}
else if("B2CS".equalsIgnoreCase(action))
{
retStringBuff.append("<b2cs_invoices>");
retStringBuff.append(dataXML);
retStringBuff.append("</b2cs_invoices>");
}
else if("CDNR".equalsIgnoreCase(action))
{
retStringBuff.append("<cdnr_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</cdnr_data>");
}
else if("CDNUR".equalsIgnoreCase(action))
{
retStringBuff.append("<cdnur_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</cdnur_data>");
}
else if("AT".equalsIgnoreCase(action))
{
retStringBuff.append("<at_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</at_data>");
}
else if("TXP".equalsIgnoreCase(action))
{
retStringBuff.append("<txp_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</txp_data>");
}
else if("NIL".equalsIgnoreCase(action))
{
retStringBuff.append("<nil_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</nil_data>");
}
else if("EXP".equalsIgnoreCase(action))
{
retStringBuff.append("<exp_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</exp_data>");
}
else if("HSNSUM".equalsIgnoreCase(action))
{
retStringBuff.append("<hsnsum_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</hsnsum_data>");
}
long timeStamp = new Timestamp().getDateTime();
System.out.println("calling for ["+action+"]");
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpRequest getDataReq = Unirest.get(String.format("%s%s", BASE_API_URL, GSTR1_URL))
.queryString("action", action)
.queryString("gstin", gstinNo)
.queryString("ret_period", periodCode)
.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("app_key", appKeyEncryptedAndCoded)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstinNo)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.getHttpRequest();
System.out.println("get GSTR1 ["+action+"] invoices url["+getDataReq.getUrl()+"]");
System.out.println("get GSTR1 ["+action+"] invoices method["+getDataReq.getHttpMethod()+"]");
System.out.println("get GSTR1 ["+action+"] invoices request header["+getDataReq.getHeaders()+"]");
HttpResponse<JsonNode> getDataResp = getDataReq.asJson();
System.out.println("getDataResp.getStatus()["+getDataResp.getStatus()+"]");
if(getDataResp.getStatus() == 200)
{
JSONObject getDataRespObj = getDataResp.getBody().getObject();
if(getDataRespObj.has("data") && getDataRespObj.has("rek"))
{
String getdata = getDataRespObj.getString("data");
String getrek = getDataRespObj.getString("rek");
byte[] getapiEK = aesEncryption.decrypt(getrek, authSek);
String getrespJsoninBase64 = new String(aesEncryption.decrypt(getdata, getapiEK));
byte[] getrespJsonInBytes = aesEncryption.decodeBase64StringTOByte(getrespJsoninBase64);
String getjsonData = new String(getrespJsonInBytes);
System.out.println("json response["+getjsonData+"] for ["+action+"]");
JSONObject getJsonDataJsonObj = new JSONObject(getjsonData);
if(getJsonDataJsonObj.has("est") && getJsonDataJsonObj.has("token"))
{
responseId = getJsonDataJsonObj.getString("token");
callStatus = "0";
dataXML = getDataFromFileServer(gstinNo, "1", periodCode, authToken, userName, stateCode, authSek, getJsonDataJsonObj, action, xtraParams);
}
else
{
callStatus = "1";
dataXML = XML.toString(getJsonDataJsonObj);
}
if("B2B".equalsIgnoreCase(action))
{
retStringBuff.append("<b2b_invoices>");
retStringBuff.append(dataXML);
retStringBuff.append("</b2b_invoices>");
}
else if("B2CL".equalsIgnoreCase(action))
{
retStringBuff.append("<b2cl_invoices>");
retStringBuff.append(dataXML);
retStringBuff.append("</b2cl_invoices>");
}
else if("B2CS".equalsIgnoreCase(action))
{
retStringBuff.append("<b2cs_invoices>");
retStringBuff.append(dataXML);
retStringBuff.append("</b2cs_invoices>");
}
else if("CDNR".equalsIgnoreCase(action))
{
retStringBuff.append("<cdnr_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</cdnr_data>");
}
else if("CDNUR".equalsIgnoreCase(action))
{
retStringBuff.append("<cdnur_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</cdnur_data>");
}
else if("AT".equalsIgnoreCase(action))
{
retStringBuff.append("<at_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</at_data>");
}
else if("TXP".equalsIgnoreCase(action))
{
retStringBuff.append("<txp_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</txp_data>");
}
else if("NIL".equalsIgnoreCase(action))
{
retStringBuff.append("<nil_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</nil_data>");
}
else if("EXP".equalsIgnoreCase(action))
{
retStringBuff.append("<exp_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</exp_data>");
}
else if("HSNSUM".equalsIgnoreCase(action))
{
retStringBuff.append("<hsnsum_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</hsnsum_data>");
}
}
else
{
callStatus = "2";
JSONObject errorJSON = getDataResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
System.out.println("errorJSON["+errorJSON+"]");
}
}
else if(getDataResp.getStatus() == 500)
{
callStatus = "2";
String errMsg = "Message : Error occurred at GSTN server \nResponse code : "+getDataResp.getStatus();
responseJsonStr = errMsg;
System.out.println("errMsg["+errMsg+"]");
}
else
{
{
callStatus = "2";
JSONObject errorJSON = getDataResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
System.out.println("errorJSON["+errorJSON+"]");
}
JSONObject errorJSON = getDataResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
System.out.println("errorJSON["+errorJSON+"]");
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("GET_"+action);
apiCallData.setRecType("1");
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);
}
else if(getDataResp.getStatus() == 500)
{
callStatus = "2";
String errMsg = "Message : Error occurred at GSTN server \nResponse code : "+getDataResp.getStatus();
responseJsonStr = errMsg;
System.out.println("errMsg["+errMsg+"]");
}
else
{
callStatus = "2";
JSONObject errorJSON = getDataResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
System.out.println("errorJSON["+errorJSON+"]");
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("GET_"+action);
apiCallData.setRecType("1");
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)
......@@ -1849,7 +2014,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("final retStringBuff.toSting["+retStringBuff.toString()+"]");
return retStringBuff.toString();
}
private String downloadGstr2Data (String gstinNo, String periodCode, String authToken, String userName, String stateCode, String appKeyEncryptedAndCoded, String xtraParams, byte[] authSek) throws ITMException
private String downloadGstr2Data (String gstinNo, String periodCode, String authToken, String userName, String stateCode, String appKeyEncryptedAndCoded, String xtraParams, byte[] authSek, ArrayList<String> byPassSectionList) throws ITMException
{
StringBuffer retStringBuff = new StringBuffer();
String[] gstr2Section = {"B2B","IMPG","IMPS","CDN","NIL","TXLI","TXP","HSNSUM","B2BUR","ITCRVSL","CDNUR"};
......@@ -1864,175 +2029,178 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
for(String action : gstr2Section)
{
long timeStamp = new Timestamp().getDateTime();
System.out.println("calling for ["+action+"]");
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpRequest getDataReq = Unirest.get(String.format("%s%s", BASE_API_URL,GSTR2_URL))
.queryString("action", action)
.queryString("gstin", gstinNo)
.queryString("ret_period", periodCode)
.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("app_key", appKeyEncryptedAndCoded)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstinNo)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.getHttpRequest();
System.out.println("get GSTR2 ["+action+"] invoices url["+getDataReq.getUrl()+"]");
System.out.println("get GSTR2 ["+action+"] invoices method["+getDataReq.getHttpMethod()+"]");
System.out.println("get GSTR2 ["+action+"] invoices request header["+getDataReq.getHeaders()+"]");
HttpResponse<JsonNode> getDataResp = getDataReq.asJson();
System.out.println("getDataResp.getStatus()["+getDataResp.getStatus()+"]");
if(getDataResp.getStatus() == 200)
if(byPassSectionList != null && !byPassSectionList.contains(action))
{
JSONObject getDataRespObj = getDataResp.getBody().getObject();
if(getDataRespObj.has("data") && getDataRespObj.has("rek"))
{
callStatus = "1";
String getdata = getDataRespObj.getString("data");
String getrek = getDataRespObj.getString("rek");
byte[] getapiEK = aesEncryption.decrypt(getrek, authSek);
String getrespJsoninBase64 = new String(aesEncryption.decrypt(getdata, getapiEK));
byte[] getrespJsonInBytes = aesEncryption.decodeBase64StringTOByte(getrespJsoninBase64);
String getjsonData = new String(getrespJsonInBytes);
System.out.println("json response["+getjsonData+"] for ["+action+"]");
if("B2B".equalsIgnoreCase(action))
{
String b2bXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<b2b_invoices>");
retStringBuff.append(b2bXML);
retStringBuff.append("</b2b_invoices>");
}
else if("IMPG".equalsIgnoreCase(action))
{
String impgXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<impg_data>");
retStringBuff.append(impgXML);
retStringBuff.append("</impg_data>");
}
else if("IMPS".equalsIgnoreCase(action))
{
String impsXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<imps_data>");
retStringBuff.append(impsXML);
retStringBuff.append("</imps_data>");
}
else if("CDN".equalsIgnoreCase(action))
{
String cdnrXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<cdnr_data>");
retStringBuff.append(cdnrXML);
retStringBuff.append("</cdnr_data>");
}
else if("CDNUR".equalsIgnoreCase(action))
{
String cdnurXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<cdnur_data>");
retStringBuff.append(cdnurXML);
retStringBuff.append("</cdnur_data>");
}
else if("NIL".equalsIgnoreCase(action))
{
String nilData = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<nil_data>");
retStringBuff.append(nilData);
retStringBuff.append("</nil_data>");
}
else if("TXLI".equalsIgnoreCase(action))
{
String taxLiabXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<txli_data>");
retStringBuff.append(taxLiabXML);
retStringBuff.append("</txli_data>");
}
else if("TXP".equalsIgnoreCase(action))
{
String taxPaidXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<txp_data>");
retStringBuff.append(taxPaidXML);
retStringBuff.append("</txp_data>");
}
else if("HSNSUM".equalsIgnoreCase(action))
{
String hsnSumXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<hsnsum_data>");
retStringBuff.append(hsnSumXML);
retStringBuff.append("</hsnsum_data>");
}
else if("B2BUR".equalsIgnoreCase(action))
{
String b2burXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<b2bur_data>");
retStringBuff.append(b2burXML);
retStringBuff.append("</b2bur_data>");
}
else if("ITCRVSL".equalsIgnoreCase(action))
{
String itcRverslXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<itcrvsl_data>");
retStringBuff.append(itcRverslXML);
retStringBuff.append("</itcrvsl_data>");
}
long timeStamp = new Timestamp().getDateTime();
System.out.println("calling for ["+action+"]");
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpRequest getDataReq = Unirest.get(String.format("%s%s", BASE_API_URL,GSTR2_URL))
.queryString("action", action)
.queryString("gstin", gstinNo)
.queryString("ret_period", periodCode)
.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("app_key", appKeyEncryptedAndCoded)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstinNo)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.getHttpRequest();
System.out.println("get GSTR2 ["+action+"] invoices url["+getDataReq.getUrl()+"]");
System.out.println("get GSTR2 ["+action+"] invoices method["+getDataReq.getHttpMethod()+"]");
System.out.println("get GSTR2 ["+action+"] invoices request header["+getDataReq.getHeaders()+"]");
HttpResponse<JsonNode> getDataResp = getDataReq.asJson();
System.out.println("getDataResp.getStatus()["+getDataResp.getStatus()+"]");
if(getDataResp.getStatus() == 200)
{
JSONObject getDataRespObj = getDataResp.getBody().getObject();
if(getDataRespObj.has("data") && getDataRespObj.has("rek"))
{
callStatus = "1";
String getdata = getDataRespObj.getString("data");
String getrek = getDataRespObj.getString("rek");
byte[] getapiEK = aesEncryption.decrypt(getrek, authSek);
String getrespJsoninBase64 = new String(aesEncryption.decrypt(getdata, getapiEK));
byte[] getrespJsonInBytes = aesEncryption.decodeBase64StringTOByte(getrespJsoninBase64);
String getjsonData = new String(getrespJsonInBytes);
System.out.println("json response["+getjsonData+"] for ["+action+"]");
if("B2B".equalsIgnoreCase(action))
{
String b2bXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<b2b_invoices>");
retStringBuff.append(b2bXML);
retStringBuff.append("</b2b_invoices>");
}
else if("IMPG".equalsIgnoreCase(action))
{
String impgXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<impg_data>");
retStringBuff.append(impgXML);
retStringBuff.append("</impg_data>");
}
else if("IMPS".equalsIgnoreCase(action))
{
String impsXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<imps_data>");
retStringBuff.append(impsXML);
retStringBuff.append("</imps_data>");
}
else if("CDN".equalsIgnoreCase(action))
{
String cdnrXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<cdnr_data>");
retStringBuff.append(cdnrXML);
retStringBuff.append("</cdnr_data>");
}
else if("CDNUR".equalsIgnoreCase(action))
{
String cdnurXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<cdnur_data>");
retStringBuff.append(cdnurXML);
retStringBuff.append("</cdnur_data>");
}
else if("NIL".equalsIgnoreCase(action))
{
String nilData = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<nil_data>");
retStringBuff.append(nilData);
retStringBuff.append("</nil_data>");
}
else if("TXLI".equalsIgnoreCase(action))
{
String taxLiabXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<txli_data>");
retStringBuff.append(taxLiabXML);
retStringBuff.append("</txli_data>");
}
else if("TXP".equalsIgnoreCase(action))
{
String taxPaidXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<txp_data>");
retStringBuff.append(taxPaidXML);
retStringBuff.append("</txp_data>");
}
else if("HSNSUM".equalsIgnoreCase(action))
{
String hsnSumXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<hsnsum_data>");
retStringBuff.append(hsnSumXML);
retStringBuff.append("</hsnsum_data>");
}
else if("B2BUR".equalsIgnoreCase(action))
{
String b2burXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<b2bur_data>");
retStringBuff.append(b2burXML);
retStringBuff.append("</b2bur_data>");
}
else if("ITCRVSL".equalsIgnoreCase(action))
{
String itcRverslXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<itcrvsl_data>");
retStringBuff.append(itcRverslXML);
retStringBuff.append("</itcrvsl_data>");
}
}
else
{
callStatus = "2";
JSONObject errorJSON = getDataResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
System.out.println("errorJSON["+errorJSON+"]");
}
}
else if(getDataResp.getStatus() == 500)
{
callStatus = "2";
String errMsg = "Message : Error occurred at GSTN server \nResponse code : "+getDataResp.getStatus();
responseJsonStr = errMsg;
System.out.println("errMsg["+errMsg+"]");
}
else
{
{
callStatus = "2";
JSONObject errorJSON = getDataResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
System.out.println("errorJSON["+errorJSON+"]");
}
JSONObject errorJSON = getDataResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
System.out.println("errorJSON["+errorJSON+"]");
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("GET_"+action);
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);
}
else if(getDataResp.getStatus() == 500)
{
callStatus = "2";
String errMsg = "Message : Error occurred at GSTN server \nResponse code : "+getDataResp.getStatus();
responseJsonStr = errMsg;
System.out.println("errMsg["+errMsg+"]");
}
else
{
callStatus = "2";
JSONObject errorJSON = getDataResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
System.out.println("errorJSON["+errorJSON+"]");
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("GET_"+action);
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)
......@@ -2867,6 +3035,13 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
String transactionId = "", retFolderPath = "", gspAuthString = "", gspAuthSignature = "";
String siteCode = "", loginCode = "", chgTerm = "", responseId = "", responseJsonStr = "", callStatus = "";
String sep = File.separator;
String sql = "", apiTranId = "";
PreparedStatement pstmt = null;
Connection conn = null;
int updateCnt = 0;
boolean isError = false;
try
{
siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
......@@ -2951,7 +3126,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
if(tempJsonObj.has("ul"))
{
String fileUrl = tempJsonObj.getString("ul");
fileUrl = BASE_API_URL + fileUrl;
fileUrl = FILEDET_URL + fileUrl;
System.out.println("fileUrl["+fileUrl+"]");
URL url = new URL(fileUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
......@@ -3014,8 +3189,28 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
tarInput.close();
}
}
}
if(dataJSONObject.has("api_tranid"))
{
conn = getConnection();
apiTranId = dataJSONObject.getString("api_tranid");
sql = "UPDATE API_CALL_LOG SET CALL_STATUS = ? WHERE TRAN_ID = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "1");
pstmt.setString(2, apiTranId);
updateCnt = pstmt.executeUpdate();
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
//retString = getDataXMLFromJsonFile(sectionName);
System.out.println("api call log update["+updateCnt+"] apiTranId["+apiTranId+"]");
}
}
else
......@@ -3050,6 +3245,28 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
retString = "<data_error><![CDATA["+errMsg+"]]></data_error>";
}
}
if(dataJSONObject.has("api_tranid"))
{
conn = getConnection();
apiTranId = dataJSONObject.getString("api_tranid");
sql = "UPDATE API_CALL_LOG SET CALL_STATUS = ? WHERE TRAN_ID = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "1");
pstmt.setString(2, apiTranId);
updateCnt = pstmt.executeUpdate();
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
System.out.println("api call log update["+updateCnt+"] apiTranId["+apiTranId+"]");
}
}
APICallData apiCallData = new APICallData();
......@@ -3071,10 +3288,47 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
}
catch(Exception e)
{
isError = true;
System.out.println("GSTCommonUtil.getDataFromFileServer()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(isError)
{
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
if(conn!=null)
{
conn.rollback();
}
}
else
{
if(conn!=null)
{
conn.commit();
}
}
if(conn!=null && !conn.isClosed())
{
conn.close();
}
}
catch(Exception se)
{
System.out.println("GSTDataSubmitWizEJB.getDataFromFileServer().finally["+se.getMessage()+"]");
se.printStackTrace();
throw new ITMException(se);
}
}
System.out.println("final retString["+retString+"]");
return retString;
}
......
......@@ -212,6 +212,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
String loginCode = "", chgTerm = "", callStatus = "", responseId = "", responseJsonStr= "";
ArrayList<String> tranIdList = new ArrayList<String>();
ArrayList<HashMap<String,String>> getGstrDataList = new ArrayList<HashMap<String,String>>();
ArrayList<String> byPassSectionList = new ArrayList<String>();
APICallData apiCallData = null;
boolean isDataLogged = false;
......@@ -592,6 +594,45 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("tranIdList.size()["+tranIdList.size()+"]");
}
if("GETINV".equalsIgnoreCase(action))
{
sql = " SELECT TRAN_ID, RESPONSE_ID, CALL_DATE,CALL_TYPE"
+ " FROM API_CALL_LOG"
+ " WHERE SITE_CODE = ? AND REC_TYPE = ? AND PRD_CODE = ?"
+ " AND CALL_STATUS = ? AND CALL_TYPE LIKE '%GET%' AND RESPONSE_ID IS NOT NULL"
+ " ORDER BY CALL_DATE DESC";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
pstmt.setString(2, "4");
pstmt.setString(3, periodCode);
pstmt.setString(4, "0");
rs = pstmt.executeQuery();
while(rs.next())
{
HashMap<String,String> tempHMap = new HashMap<String,String>();
tempHMap.put("api_tranid", rs.getString("TRAN_ID"));
tempHMap.put("token", rs.getString("RESPONSE_ID"));
String tempStr = rs.getString("CALL_TYPE");
String section = tempStr.substring(tempStr.indexOf("_")+1);
tempHMap.put("section", section);
byPassSectionList.add(section);
getGstrDataList.add(tempHMap);
}
if(rs!=null)
{
rs.close();
rs = null;
}
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
}
if(authToken != null && authToken.trim().length() > 0 && authSEK != null)
{
if("GSTR1".equalsIgnoreCase(returnsType))
......@@ -621,7 +662,20 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{
if("GETINV".equalsIgnoreCase(action))
{
retString = downloadGstr2AData(siteCode, xtraParams, conn);
if(getGstrDataList.size() > 0)
{
for(HashMap<String,String> eachDataHamp : getGstrDataList)
{
String sectionName = eachDataHamp.get("section");
JSONObject dataJSONObject = new JSONObject();
dataJSONObject.put("token", eachDataHamp.get("token"));
dataJSONObject.put("est", "");
dataJSONObject.put("api_tranid", eachDataHamp.get("api_tranid"));
retString = getDataFromFileServer("4", dataJSONObject, sectionName, xtraParams, conn);
}
}
retString = downloadGstr2AData(siteCode, xtraParams, byPassSectionList, conn);
}
}
else if("GSTR2".equalsIgnoreCase(returnsType))
......@@ -3389,7 +3443,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
}
return retString;
}*/
private String downloadGstr2AData(String siteCode, String xtraParams, Connection conn) throws ITMException
private String downloadGstr2AData(String siteCode, String xtraParams, ArrayList<String> byPassSectionList, Connection conn) throws ITMException
{
String retString = "";
String errMsg = "", gspAuthString = "", gspAuthSignature = "";
......@@ -3405,70 +3459,90 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
for(String action : gstr2Section)
{
System.out.println("calling for ["+action+"]");
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpRequest getGstr2InvoicesReq = Unirest.get(String.format("%s%s", BASE_API_URL, GSTR2A_URL))
.queryString("action", action)
.queryString("gstin", gstin)
.queryString("ret_period", periodCode)
.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)
.getHttpRequest();
System.out.println("get GSTR2A ["+action+"] invoices url["+getGstr2InvoicesReq.getUrl()+"]");
System.out.println("get GSTR2A ["+action+"] invoices method["+getGstr2InvoicesReq.getHttpMethod()+"]");
System.out.println("get GSTR2A ["+action+"] invoices request header["+getGstr2InvoicesReq.getHeaders()+"]");
HttpResponse<JsonNode> getGstr2InvoicesResp = getGstr2InvoicesReq.asJson();
System.out.println(String.format("getGstr2InvoicesResp Request : Status[%s] Response[%s]", getGstr2InvoicesResp.getStatus(), getGstr2InvoicesResp.getBody()));
if (getGstr2InvoicesResp.getStatus() == 200)
if(byPassSectionList != null && !byPassSectionList.contains(action))
{
JSONObject getGstr2InvoicesRespObj = getGstr2InvoicesResp.getBody().getObject();
if(getGstr2InvoicesRespObj.has("data") && getGstr2InvoicesRespObj.has("rek"))
{
callStatus = "1";
String gstr2InvoicesData = getGstr2InvoicesRespObj.getString("data");
String gstr2InvoicesRek = getGstr2InvoicesRespObj.getString("rek");
System.out.println("calling for ["+action+"]");
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpRequest getGstr2InvoicesReq = Unirest.get(String.format("%s%s", BASE_API_URL, GSTR2A_URL))
.queryString("action", action)
.queryString("gstin", gstin)
.queryString("ret_period", periodCode)
.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)
.getHttpRequest();
System.out.println("get GSTR2A ["+action+"] invoices url["+getGstr2InvoicesReq.getUrl()+"]");
System.out.println("get GSTR2A ["+action+"] invoices method["+getGstr2InvoicesReq.getHttpMethod()+"]");
System.out.println("get GSTR2A ["+action+"] invoices request header["+getGstr2InvoicesReq.getHeaders()+"]");
HttpResponse<JsonNode> getGstr2InvoicesResp = getGstr2InvoicesReq.asJson();
System.out.println(String.format("getGstr2InvoicesResp Request : Status[%s] Response[%s]", getGstr2InvoicesResp.getStatus(), getGstr2InvoicesResp.getBody()));
if (getGstr2InvoicesResp.getStatus() == 200)
{
JSONObject getGstr2InvoicesRespObj = getGstr2InvoicesResp.getBody().getObject();
if(getGstr2InvoicesRespObj.has("data") && getGstr2InvoicesRespObj.has("rek"))
{
String gstr2InvoicesData = getGstr2InvoicesRespObj.getString("data");
String gstr2InvoicesRek = getGstr2InvoicesRespObj.getString("rek");
byte[] apiEK = aesEncryption.decrypt(gstr2InvoicesRek, authSEK);
String respJsoninBase64 = new String(aesEncryption.decrypt(gstr2InvoicesData, apiEK));
byte[] apiEK = aesEncryption.decrypt(gstr2InvoicesRek, authSEK);
String respJsoninBase64 = new String(aesEncryption.decrypt(gstr2InvoicesData, apiEK));
byte[] respJsonInBytes = aesEncryption.decodeBase64StringTOByte(respJsoninBase64);
byte[] respJsonInBytes = aesEncryption.decodeBase64StringTOByte(respJsoninBase64);
JSONObject gstr2InvoiceJsonObj = new JSONObject(new String(respJsonInBytes));
JSONObject gstr2InvoiceJsonObj = new JSONObject(new String(respJsonInBytes));
System.out.println("respJsonInBytes["+new String(respJsonInBytes)+"]");
if(gstr2InvoiceJsonObj.has("est") && gstr2InvoiceJsonObj.has("token"))
{
retString = getDataFromFileServer("4", gstr2InvoiceJsonObj, action, xtraParams, conn);
}
else
{
if("B2B".equalsIgnoreCase(action))
{
insertB2BInvoiceData(stateCode, periodCode, siteCode, gstr2InvoiceJsonObj, xtraParams, conn);
}
else if("CDN".equalsIgnoreCase(action))
System.out.println("respJsonInBytes["+new String(respJsonInBytes)+"]");
if(gstr2InvoiceJsonObj.has("est") && gstr2InvoiceJsonObj.has("token"))
{
callStatus = "0";
responseId = gstr2InvoiceJsonObj.getString("token");
retString = getDataFromFileServer("4", gstr2InvoiceJsonObj, action, xtraParams, conn);
}
else
{
insertCDNData(stateCode, periodCode, siteCode, gstr2InvoiceJsonObj, xtraParams, conn);
callStatus = "1";
if("B2B".equalsIgnoreCase(action))
{
insertB2BInvoiceData(stateCode, periodCode, siteCode, gstr2InvoiceJsonObj, xtraParams, conn);
}
else if("CDN".equalsIgnoreCase(action))
{
insertCDNData(stateCode, periodCode, siteCode, gstr2InvoiceJsonObj, xtraParams, conn);
}
}
}
else
{
callStatus = "2";
JSONObject errorJSON = getGstr2InvoicesResp.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(getGstr2InvoicesResp.getStatus() == 500)
{
callStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+getGstr2InvoicesResp.getStatus();
responseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
}
else
{
......@@ -3478,40 +3552,24 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
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("GET_"+action);
apiCallData.setRecType("4");
apiCallData.setNoOfRecords(0);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId(responseId);
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(chgTerm);
apiCallDataList.add(apiCallData);
}
else if(getGstr2InvoicesResp.getStatus() == 500)
{
callStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+getGstr2InvoicesResp.getStatus();
responseJsonStr = errMsg;
retString = getError(errMsg, "GSTAPIERR", conn);
}
else
{
callStatus = "2";
JSONObject errorJSON = getGstr2InvoicesResp.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("GET_"+action);
apiCallData.setRecType("4");
apiCallData.setNoOfRecords(0);
apiCallData.setCallStatus(callStatus);
apiCallData.setResponseId(responseId);
apiCallData.setResponseJsonStr(responseJsonStr);
apiCallData.setChgUser(loginCode);
apiCallData.setChgDate(new Date());
apiCallData.setChgTerm(chgTerm);
apiCallDataList.add(apiCallData);
}
}
catch(Exception e)
......@@ -4428,6 +4486,13 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
String transactionId = "", gspAuthString = "", gspAuthSignature = "";
String siteCode = "", loginCode = "", chgTerm = "", responseId = "", responseJsonStr = "", callStatus = "";
String sep = File.separator;
String sql = "", apiTranId = "";
PreparedStatement pstmt = null;
Connection localConn = null;
int updateCnt = 0;
boolean isError = false;
try
{
siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
......@@ -4518,7 +4583,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
if(tempJsonObj.has("ul"))
{
String fileUrl = tempJsonObj.getString("ul");
fileUrl = BASE_API_URL + fileUrl;
fileUrl = FILEDET_URL + fileUrl;
System.out.println("fileUrl["+fileUrl+"]");
URL url = new URL(fileUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
......@@ -4590,6 +4655,26 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
}
}
}
if(dataJSONObject.has("api_tranid"))
{
apiTranId = dataJSONObject.getString("api_tranid");
sql = "UPDATE API_CALL_LOG SET CALL_STATUS = ? WHERE TRAN_ID = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "1");
pstmt.setString(2, apiTranId);
updateCnt = pstmt.executeUpdate();
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
System.out.println("api call log update["+updateCnt+"] apiTranId["+apiTranId+"]");
}
}
else
{
......@@ -4623,6 +4708,27 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
retString = "<data_error><![CDATA["+errMsg+"]]></data_error>";
}
}
if(dataJSONObject.has("api_tranid"))
{
localConn = getConnection();
apiTranId = dataJSONObject.getString("api_tranid");
sql = "UPDATE API_CALL_LOG SET CALL_STATUS = ? WHERE TRAN_ID = ?";
pstmt = localConn.prepareStatement(sql);
pstmt.setString(1, "1");
pstmt.setString(2, apiTranId);
updateCnt = pstmt.executeUpdate();
if(pstmt!=null)
{
pstmt.close();
pstmt = null;
}
System.out.println("api call log update["+updateCnt+"] apiTranId["+apiTranId+"]");
}
}
APICallData apiCallData = new APICallData();
......@@ -4644,10 +4750,45 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
}
catch(Exception e)
{
isError = true;
System.out.println("GSTDataSubmitWizPos.getDataFromFileServer()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(isError)
{
if(pstmt!=null)
{
pstmt.close();
pstmt=null;
}
if(localConn!=null)
{
localConn.rollback();
}
}
else
{
localConn.commit();
}
if(localConn!=null && !localConn.isClosed())
{
localConn.close();
localConn = null;
}
}
catch(SQLException se)
{
System.out.println("GSTDataSubmitWizPos.getDataFromFileServer().finally["+se.getMessage()+"]");
se.printStackTrace();
throw new ITMException(se);
}
}
System.out.println("final retString["+retString+"]");
return retString;
}
......
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