Commit 4265c334 authored by steurwadkar's avatar steurwadkar

F17ABAS001 source code commit


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@106621 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 5e1989fb
package ibase.webitm.ejb.gst; package ibase.webitm.ejb.gst;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
...@@ -17,7 +20,6 @@ import java.sql.SQLException; ...@@ -17,7 +20,6 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
...@@ -75,6 +77,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -75,6 +77,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
private String clientId = ""; private String clientId = "";
private String clientSecret = ""; private String clientSecret = "";
private String fileDownloadDir = ""; private String fileDownloadDir = "";
private String saveFilePath = "";
AESEncryption aesEncryption = null; AESEncryption aesEncryption = null;
PubKeyEncryption pubKeyEncryption = null; PubKeyEncryption pubKeyEncryption = null;
GSPSignature gspSignature; GSPSignature gspSignature;
...@@ -371,6 +374,8 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -371,6 +374,8 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
byte[] authSEK = null; byte[] authSEK = null;
String loginCode = "", chgTerm = "", callStatus = "", responseId = "", responseJsonStr= "", recType = ""; String loginCode = "", chgTerm = "", callStatus = "", responseId = "", responseJsonStr= "", recType = "";
String signDataXML = "", summaryDataJsonStr = ""; String signDataXML = "", summaryDataJsonStr = "";
int submitRowCnt = 0;
boolean isLocalDataFiles = false;
System.out.println(" -------- Inside itemchange case 2222222 ------------ "); System.out.println(" -------- Inside itemchange case 2222222 ------------ ");
if( currentColumn.trim().equalsIgnoreCase( "itm_default" )) if( currentColumn.trim().equalsIgnoreCase( "itm_default" ))
...@@ -419,199 +424,266 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -419,199 +424,266 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
} }
} }
transactionId = UUID.randomUUID().toString().replaceAll("-", ""); sql = " SELECT COUNT(1) AS CNT FROM GST_DATA_HDR WHERE SITE_CODE = ? AND PRD_CODE = ? AND REC_TYPE = ? AND SUBMIT_STATUS = ? ";
pstmt = conn.prepareStatement(sql);
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo; pstmt.setString(1, siteCode);
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey); pstmt.setString(2, periodCode);
pstmt.setString(3, recType);
pstmt.setString(4, "S");
otp = checkNull(e12GenericUtility.getColumnValue("otp", dom1)); rs = pstmt.executeQuery();
if(rs.next())
{
submitRowCnt = rs.getInt("CNT");
}
closeResources(rs, pstmt);
String encryptedOTP = aesEncryption.encryptEK(otp.getBytes(), appKeyInBytes); System.out.println("submitRowCnt=["+submitRowCnt+"]");
JSONObject authTokenReqObj = new JSONObject(); if("GETINV".equalsIgnoreCase(action) || "SUBMIT".equalsIgnoreCase(action))
authTokenReqObj.put("action", "AUTHTOKEN"); {
authTokenReqObj.put("username", userName); File baseDir = new File(fileDownloadDir);
authTokenReqObj.put("app_key", appKeyEncryptedAndCoded); String baseDirPath = baseDir.getAbsolutePath();
authTokenReqObj.put("otp", encryptedOTP); String finalDirPath = baseDirPath + File.separator + gstinNo + File.separator + periodCode + File.separator + returnType;
File finalDir = new File(finalDirPath);
if(!finalDir.exists())
{
boolean isFoderCreated = finalDir.mkdirs();
if(isFoderCreated)
{
System.out.println("433.final folder structure created for ["+gstinNo+"] for return period["+periodCode+"] for ["+returnType+"]");
}
}
else
{
if(submitRowCnt == 0)
{
String[] fileList = finalDir.list();
for(String eachFileName : fileList)
{
File eachFile = new File(finalDir.getPath(), eachFileName);
eachFile.delete();
}
boolean isDeleted = finalDir.delete();
System.out.println("Old folder deleted["+isDeleted+"]");
if(isDeleted && !finalDir.exists())
{
boolean isFoderCreated = finalDir.mkdirs();
if(isFoderCreated)
{
System.out.println("452.final folder structure created for ["+gstinNo+"] for return period["+periodCode+"] for ["+returnType+"]");
}
}
}
else
{
isLocalDataFiles = true;
}
}
saveFilePath = finalDir.getAbsolutePath();
}
if(!isLocalDataFiles )
{
transactionId = UUID.randomUUID().toString().replaceAll("-", "");
HttpRequest authTokenReq = Unirest.post(String.format("%s%s", GSP_API_URL, AUTH_TOKEN_URL_V2)) gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
.header("Content-Type",APPLICATION_JSON) gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
.header("clientid", clientId)
.header("client-secret", clientSecret) otp = checkNull(e12GenericUtility.getColumnValue("otp", dom1));
.header("state-cd", stateCode)
.header("ip-usr", ipAddress) String encryptedOTP = aesEncryption.encryptEK(otp.getBytes(), appKeyInBytes);
.header("txn", transactionId)
.header("app_key", appKeyEncryptedAndCoded) JSONObject authTokenReqObj = new JSONObject();
.header("X-Asp-Auth-Token", gspAuthString) authTokenReqObj.put("action", "AUTHTOKEN");
.header("X-Asp-Auth-Signature", gspAuthSignature) authTokenReqObj.put("username", userName);
.body(new JsonNode(authTokenReqObj.toString())) authTokenReqObj.put("app_key", appKeyEncryptedAndCoded);
.getHttpRequest(); authTokenReqObj.put("otp", encryptedOTP);
System.out.println("authtoken url["+authTokenReq.getUrl()+"]");
System.out.println("authtoken method["+authTokenReq.getHttpMethod()+"]");
System.out.println("authtoken request header["+authTokenReq.getHeaders()+"]");
System.out.println("authtoken request payload["+IOUtils.toString(authTokenReq.getBody().getEntity().getContent())+"]");
HttpResponse<JsonNode> authTokenResp = authTokenReq.asJson();
System.out.println(String.format("authTokenResp Request : Status[%s] Response[%s]", authTokenResp.getStatus(), authTokenResp.getBody())); HttpRequest authTokenReq = Unirest.post(String.format("%s%s", GSP_API_URL, AUTH_TOKEN_URL_V2))
.header("Content-Type",APPLICATION_JSON)
if(authTokenResp.getStatus() == 200) .header("clientid", clientId)
{ .header("client-secret", clientSecret)
JSONObject object = authTokenResp.getBody().getObject(); .header("state-cd", stateCode)
if (object.has("auth_token") && object.has("sek") && object.has("status_cd") && Objects.equals(object.getString("status_cd"), "1")) .header("ip-usr", ipAddress)
{ .header("txn", transactionId)
callStatus = "1"; .header("app_key", appKeyEncryptedAndCoded)
authToken = object.getString("auth_token"); .header("X-Asp-Auth-Token", gspAuthString)
sek = object.getString("sek"); .header("X-Asp-Auth-Signature", gspAuthSignature)
authSEK = aesEncryption.decrypt(sek, appKeyInBytes); .body(new JsonNode(authTokenReqObj.toString()))
System.out.println("AuthSEK = "+ aesEncryption.encodeBase64String(authSEK)); .getHttpRequest();
} System.out.println("authtoken url["+authTokenReq.getUrl()+"]");
else System.out.println("authtoken method["+authTokenReq.getHttpMethod()+"]");
{ System.out.println("authtoken request header["+authTokenReq.getHeaders()+"]");
callStatus = "2"; System.out.println("authtoken request payload["+IOUtils.toString(authTokenReq.getBody().getEntity().getContent())+"]");
JSONObject errorJSON = authTokenResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString(); HttpResponse<JsonNode> authTokenResp = authTokenReq.asJson();
if("AUTH4033".equalsIgnoreCase(errorJSON.getString("error_cd"))) System.out.println(String.format("authTokenResp Request : Status[%s] Response[%s]", authTokenResp.getStatus(), authTokenResp.getBody()));
{
errorXML = new ITMDBAccessEJB().getErrorString("","VTINVOTP","","",conn); if(authTokenResp.getStatus() == 200)
} {
else JSONObject object = authTokenResp.getBody().getObject();
{ if (object.has("auth_token") && object.has("sek") && object.has("status_cd") && Objects.equals(object.getString("status_cd"), "1"))
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd"); {
errorXML = getError(errMsg, "GSTAPIERR", conn); callStatus = "1";
} authToken = object.getString("auth_token");
} sek = object.getString("sek");
} authSEK = aesEncryption.decrypt(sek, appKeyInBytes);
else if(authTokenResp.getStatus() == 500) System.out.println("AuthSEK = "+ aesEncryption.encodeBase64String(authSEK));
{
callStatus = "2"; }
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+authTokenResp.getStatus(); else
responseJsonStr = errMsg; {
errorXML = getError(errMsg, "GSTAPIERR", conn); callStatus = "2";
} JSONObject errorJSON = authTokenResp.getBody().getObject().getJSONObject("error");
else responseJsonStr = errorJSON.toString();
{
callStatus = "2"; if("AUTH4033".equalsIgnoreCase(errorJSON.getString("error_cd")))
JSONObject errorJSON = authTokenResp.getBody().getObject().getJSONObject("error"); {
responseJsonStr = errorJSON.toString(); errorXML = new ITMDBAccessEJB().getErrorString("","VTINVOTP","","",conn);
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd"); }
errorXML = getError(errMsg, "GSTAPIERR", conn); else
} {
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
APICallData apiCallData = new APICallData(); errorXML = getError(errMsg, "GSTAPIERR", conn);
apiCallData.setPeriodCode(periodCode); }
apiCallData.setCallDate(new Date()); }
apiCallData.setSiteCode(siteCode); }
apiCallData.setUserId(loginCode); else if(authTokenResp.getStatus() == 500)
apiCallData.setCallType("AUTHTOKEN"); {
apiCallData.setRecType(recType); callStatus = "2";
apiCallData.setNoOfRecords(0); errMsg = "Message : Error occurred at GSTN server \nResponse code : "+authTokenResp.getStatus();
apiCallData.setCallStatus(callStatus); responseJsonStr = errMsg;
apiCallData.setResponseId(responseId); errorXML = getError(errMsg, "GSTAPIERR", conn);
apiCallData.setResponseJsonStr(responseJsonStr); }
apiCallData.setChgUser(loginCode); else
apiCallData.setChgDate(new Date()); {
apiCallData.setChgTerm(chgTerm); callStatus = "2";
JSONObject errorJSON = authTokenResp.getBody().getObject().getJSONObject("error");
gstCommonUtil.updateAPICallLogHistory(apiCallData, null); responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
if( authToken != null && authToken.trim().length()>0 && authSEK != null) errorXML = getError(errMsg, "GSTAPIERR", conn);
{ }
if("GSTR1".equalsIgnoreCase(returnType))
{ APICallData apiCallData = new APICallData();
if("SUBMIT".equalsIgnoreCase(action)) apiCallData.setPeriodCode(periodCode);
{ apiCallData.setCallDate(new Date());
summaryDataJsonStr += getGstr1Summary(authToken, stateCode, userName, gstinNo, periodCode, authSEK, appKeyEncryptedAndCoded, xtraParams, conn); apiCallData.setSiteCode(siteCode);
if(summaryDataJsonStr!= null && summaryDataJsonStr.trim().length() > 0 && summaryDataJsonStr.indexOf("Message :") == -1) apiCallData.setUserId(loginCode);
{ apiCallData.setCallType("AUTHTOKEN");
retXML += "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>"; apiCallData.setRecType(recType);
} apiCallData.setNoOfRecords(0);
else if(summaryDataJsonStr.indexOf("Message :") >= 0) apiCallData.setCallStatus(callStatus);
{ apiCallData.setResponseId(responseId);
retXML += summaryDataJsonStr; apiCallData.setResponseJsonStr(responseJsonStr);
} apiCallData.setChgUser(loginCode);
retXML += downloadGstr1Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK); apiCallData.setChgDate(new Date());
} apiCallData.setChgTerm(chgTerm);
else if("FILE".equalsIgnoreCase(action))
{ gstCommonUtil.updateAPICallLogHistory(apiCallData, null);
summaryDataJsonStr += getGstr1Summary(authToken, stateCode, userName, gstinNo, periodCode, authSEK, appKeyEncryptedAndCoded, xtraParams, conn);
if(summaryDataJsonStr!= null && summaryDataJsonStr.trim().length() > 0 && summaryDataJsonStr.indexOf("Message :") == -1) if( authToken != null && authToken.trim().length()>0 && authSEK != null)
{ {
retXML += "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>"; if("GSTR1".equalsIgnoreCase(returnType))
} {
else if(summaryDataJsonStr.indexOf("Message :") >= 0) if("SUBMIT".equalsIgnoreCase(action))
{ {
retXML += summaryDataJsonStr; summaryDataJsonStr += getGstr1Summary(authToken, stateCode, userName, gstinNo, periodCode, authSEK, appKeyEncryptedAndCoded, xtraParams, conn);
} if(summaryDataJsonStr!= null && summaryDataJsonStr.trim().length() > 0 && summaryDataJsonStr.indexOf("Message :") == -1)
} {
else if("GETINV".equalsIgnoreCase(action)) retXML += "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>";
{ }
retXML += downloadGstr1Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK); else if(summaryDataJsonStr.indexOf("Message :") >= 0)
} {
} retXML += summaryDataJsonStr;
if("GSTR2".equalsIgnoreCase(returnType)) }
{ retXML += downloadGstr1Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
if("SUBMIT".equalsIgnoreCase(action)) }
{ else if("FILE".equalsIgnoreCase(action))
summaryDataJsonStr += getGstr2Summary(authToken, stateCode, userName, gstinNo, periodCode, authSEK, appKeyEncryptedAndCoded, xtraParams, conn); {
if(summaryDataJsonStr!= null && summaryDataJsonStr.trim().length() > 0 && summaryDataJsonStr.indexOf("Message :") == -1) summaryDataJsonStr += getGstr1Summary(authToken, stateCode, userName, gstinNo, periodCode, authSEK, appKeyEncryptedAndCoded, xtraParams, conn);
{ if(summaryDataJsonStr!= null && summaryDataJsonStr.trim().length() > 0 && summaryDataJsonStr.indexOf("Message :") == -1)
retXML += "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>"; {
} retXML += "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>";
else if(summaryDataJsonStr.indexOf("Message :") >= 0) }
{ else if(summaryDataJsonStr.indexOf("Message :") >= 0)
retXML += summaryDataJsonStr; {
} retXML += summaryDataJsonStr;
retXML += downloadGstr2Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK); }
} }
else if("FILE".equalsIgnoreCase(action)) else if("GETINV".equalsIgnoreCase(action))
{ {
summaryDataJsonStr += getGstr2Summary(authToken, stateCode, userName, gstinNo, periodCode, authSEK, appKeyEncryptedAndCoded, xtraParams, conn); retXML += downloadGstr1Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
if(summaryDataJsonStr!= null && summaryDataJsonStr.trim().length() > 0 && summaryDataJsonStr.indexOf("Message :") == -1) }
{ }
retXML += "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>"; if("GSTR2".equalsIgnoreCase(returnType))
} {
else if(summaryDataJsonStr.indexOf("Message :") >= 0) if("SUBMIT".equalsIgnoreCase(action))
{ {
retXML += summaryDataJsonStr; summaryDataJsonStr += getGstr2Summary(authToken, stateCode, userName, gstinNo, periodCode, authSEK, appKeyEncryptedAndCoded, xtraParams, conn);
} if(summaryDataJsonStr!= null && summaryDataJsonStr.trim().length() > 0 && summaryDataJsonStr.indexOf("Message :") == -1)
} {
else if("GETINV".equalsIgnoreCase(action)) retXML += "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>";
{ }
retXML += downloadGstr2Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK); else if(summaryDataJsonStr.indexOf("Message :") >= 0)
} {
} retXML += summaryDataJsonStr;
if("GSTR3B".equalsIgnoreCase(returnType)) }
{ retXML += downloadGstr2Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
if("SUBMIT".equalsIgnoreCase(action)) }
{ else if("FILE".equalsIgnoreCase(action))
summaryDataJsonStr += getGstr3bSummary(authToken, stateCode, userName, gstinNo, periodCode, authSEK, appKeyEncryptedAndCoded, xtraParams, conn); {
if(summaryDataJsonStr!= null && summaryDataJsonStr.trim().length() > 0 && summaryDataJsonStr.indexOf("Message :") == -1) summaryDataJsonStr += getGstr2Summary(authToken, stateCode, userName, gstinNo, periodCode, authSEK, appKeyEncryptedAndCoded, xtraParams, conn);
{ if(summaryDataJsonStr!= null && summaryDataJsonStr.trim().length() > 0 && summaryDataJsonStr.indexOf("Message :") == -1)
retXML += "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>"; {
} retXML += "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>";
else if(summaryDataJsonStr.indexOf("Message :") >= 0) }
{ else if(summaryDataJsonStr.indexOf("Message :") >= 0)
retXML += summaryDataJsonStr; {
} retXML += summaryDataJsonStr;
} }
else if("FILE".equalsIgnoreCase(action)) }
{ else if("GETINV".equalsIgnoreCase(action))
summaryDataJsonStr += getGstr3bSummary(authToken, stateCode, userName, gstinNo, periodCode, authSEK, appKeyEncryptedAndCoded, xtraParams, conn); {
if(summaryDataJsonStr!= null && summaryDataJsonStr.trim().length() > 0 && summaryDataJsonStr.indexOf("Message :") == -1) retXML += downloadGstr2Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
{ }
retXML += "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>"; }
} if("GSTR3B".equalsIgnoreCase(returnType))
else if(summaryDataJsonStr.indexOf("Message :") >= 0) {
{ if("SUBMIT".equalsIgnoreCase(action))
retXML += summaryDataJsonStr; {
} summaryDataJsonStr += getGstr3bSummary(authToken, stateCode, userName, gstinNo, periodCode, authSEK, appKeyEncryptedAndCoded, xtraParams, conn);
} if(summaryDataJsonStr!= null && summaryDataJsonStr.trim().length() > 0 && summaryDataJsonStr.indexOf("Message :") == -1)
} {
} retXML += "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>";
}
else if(summaryDataJsonStr.indexOf("Message :") >= 0)
{
retXML += summaryDataJsonStr;
}
}
else if("FILE".equalsIgnoreCase(action))
{
summaryDataJsonStr += getGstr3bSummary(authToken, stateCode, userName, gstinNo, periodCode, authSEK, appKeyEncryptedAndCoded, xtraParams, conn);
if(summaryDataJsonStr!= null && summaryDataJsonStr.trim().length() > 0 && summaryDataJsonStr.indexOf("Message :") == -1)
{
retXML += "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>";
}
else if(summaryDataJsonStr.indexOf("Message :") >= 0)
{
retXML += summaryDataJsonStr;
}
}
}
}
}
else
{
retXML = getDataXMLFromJsonFile("");
}
valueXmlString.append("<Detail2 domID='1'>"); valueXmlString.append("<Detail2 domID='1'>");
valueXmlString.append("<auth_token><![CDATA["+ authToken +"]]></auth_token>"); valueXmlString.append("<auth_token><![CDATA["+ authToken +"]]></auth_token>");
...@@ -1528,6 +1600,49 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1528,6 +1600,49 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
retResponseXML = "<root><error_message><![CDATA[Message : "+dataErrMsg+"]]></error_message></root>"; retResponseXML = "<root><error_message><![CDATA[Message : "+dataErrMsg+"]]></error_message></root>";
} }
} }
else if("SUBMIT_CNT".equalsIgnoreCase(action))
{
String periodCode = "", siteCode = "", recordType = "", recType = "", submitRowCnt = "";
periodCode = reqParamMap.get("period_code");
siteCode = reqParamMap.get("site_code");
recordType = reqParamMap.get("rec_type");
if("GSTR1".equalsIgnoreCase(recordType))
{
recType = "1";
}
else if("GSTR2".equalsIgnoreCase(recordType))
{
recType = "2";
}
else if("GSTR3".equalsIgnoreCase(recordType))
{
recType = "3";
}
else if("GSTR3B".equalsIgnoreCase(recordType))
{
recType = "6";
}
sql = " SELECT COUNT(1) AS CNT FROM GST_DATA_HDR WHERE SITE_CODE = ? AND PRD_CODE = ? AND REC_TYPE = ? AND SUBMIT_STATUS = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
pstmt.setString(2, periodCode);
pstmt.setString(3, recType);
pstmt.setString(4, "S");
rs = pstmt.executeQuery();
if(rs.next())
{
submitRowCnt = String.valueOf(rs.getInt("CNT"));
}
closeResources(rs, pstmt);
System.out.println("submitRowCnt=["+submitRowCnt+"]");
retResponseXML = "<root><submit_cnt><![CDATA["+submitRowCnt+"]]></submit_cnt></root>";
}
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -1567,7 +1682,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1567,7 +1682,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode"); siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"); loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm"); chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
for(String action : gstr1Section) for(String action : gstr1Section)
{ {
long timeStamp = new Timestamp().getDateTime(); long timeStamp = new Timestamp().getDateTime();
...@@ -1577,7 +1692,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1577,7 +1692,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo; gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey); gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpRequest getDataReq = Unirest.get(String.format("%s%s", GSP_API_URL,GSTR1_URL_V3)) HttpRequest getDataReq = Unirest.get(String.format("%s%s", GSP_API_URL, GSTR1_URL_V3))
.queryString("action", action) .queryString("action", action)
.queryString("gstin", gstinNo) .queryString("gstin", gstinNo)
.queryString("ret_period", periodCode) .queryString("ret_period", periodCode)
...@@ -1626,11 +1741,12 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1626,11 +1741,12 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
if(getJsonDataJsonObj.has("est") && getJsonDataJsonObj.has("token")) if(getJsonDataJsonObj.has("est") && getJsonDataJsonObj.has("token"))
{ {
dataXML = getDataFromFileServer(gstinNo, "1", periodCode, authToken, userName, stateCode, authSek, getJsonDataJsonObj, xtraParams); dataXML = getDataFromFileServer(gstinNo, "1", periodCode, authToken, userName, stateCode, authSek, getJsonDataJsonObj, action, xtraParams);
} }
else else
{ {
dataXML = XML.toString(getJsonDataJsonObj); dataXML = XML.toString(getJsonDataJsonObj);
writeDatatoJsonFile(getJsonDataJsonObj.toString(), action);
} }
...@@ -2757,10 +2873,10 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2757,10 +2873,10 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("final retString ["+retString+"]"); System.out.println("final retString ["+retString+"]");
return retString; return retString;
} }
private String getDataFromFileServer(String gstin, String recType, String periodCode, String authToken, String userName, String stateCode, byte[] authSek, JSONObject dataJSONObject, String xtraParams) throws ITMException private String getDataFromFileServer(String gstin, String recType, String periodCode, String authToken, String userName, String stateCode, byte[] authSek, JSONObject dataJSONObject, String sectionName, String xtraParams) throws ITMException
{ {
String retString = null; String retString = null;
String transactionId = "", gspAuthString = "", gspAuthSignature = "", returnType = "", saveFilePath = ""; String transactionId = "", gspAuthString = "", gspAuthSignature = "";
String siteCode = "", loginCode = "", chgTerm = "", responseId = "", responseJsonStr = "", callStatus = ""; String siteCode = "", loginCode = "", chgTerm = "", responseId = "", responseJsonStr = "", callStatus = "";
try try
{ {
...@@ -2768,30 +2884,15 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2768,30 +2884,15 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"); loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm"); chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
if("1".equalsIgnoreCase(recType)) System.out.println("saveFilePath on 2795["+saveFilePath+"]");
{
returnType = "GSTR1";
}
else if("2".equalsIgnoreCase(recType))
{
returnType = "GSTR2";
}
File baseDir = new File(fileDownloadDir); File sectionFolder = new File(saveFilePath + File.separator + sectionName);
String baseDirPath = baseDir.getAbsolutePath(); if(!sectionFolder.exists())
String finalDirPath = baseDirPath+File.separator+gstin+File.separator+periodCode+File.separator+returnType;
File finalDir = new File(finalDirPath);
if(!finalDir.exists())
{ {
boolean isFoderCreated = finalDir.mkdirs(); sectionFolder.mkdir();
if(isFoderCreated) System.out.println("section folder created for ["+sectionName+"]");
{
System.out.println("final folder structure created for ["+gstin+"] for return period["+periodCode+"] for ["+returnType+"]");
}
} }
saveFilePath = finalDir.getAbsolutePath();
transactionId = UUID.randomUUID().toString().replaceAll("-", ""); transactionId = UUID.randomUUID().toString().replaceAll("-", "");
long timeStamp = new Timestamp().getDateTime(); long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin; gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
...@@ -2800,7 +2901,8 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2800,7 +2901,8 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
HttpRequest fileDetailsReq = Unirest.get(String.format("%s%s", GSP_API_URL, GSTR_URL_V3)) HttpRequest fileDetailsReq = Unirest.get(String.format("%s%s", GSP_API_URL, GSTR_URL_V3))
.queryString("gstin", gstin) .queryString("gstin", gstin)
.queryString("ret_period",periodCode) .queryString("ret_period",periodCode)
.queryString("token",dataJSONObject.getString("token")) //.queryString("token",dataJSONObject.getString("token"))//TODO need to change
.queryString("token", "7163714af8a84b62ae6688d8f7a238c1")
.queryString("action","FILEDET") .queryString("action","FILEDET")
.header("Content-Type", APPLICATION_JSON) .header("Content-Type", APPLICATION_JSON)
.header("state-cd", stateCode) .header("state-cd", stateCode)
...@@ -2847,9 +2949,15 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2847,9 +2949,15 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
JSONArray fileDetailsArry = filedetailsJsonObj.getJSONArray("urls"); JSONArray fileDetailsArry = filedetailsJsonObj.getJSONArray("urls");
System.out.println("sessionKey["+sessionKey+"]"); System.out.println("sessionKey["+sessionKey+"]");
String sessionKeyFilePath = saveFilePath + File.separator + sectionName + File.separator + "key.txt";
FileOutputStream keyFileOutStream = new FileOutputStream(sessionKeyFilePath);
keyFileOutStream.write(sessionKey.getBytes());
keyFileOutStream.close();
for(int i=0; i<fileDetailsArry.length(); i++) for(int i=0; i<fileDetailsArry.length(); i++)
{ {
String fileName = "", filePath = "";
JSONObject tempJsonObj = fileDetailsArry.getJSONObject(i); JSONObject tempJsonObj = fileDetailsArry.getJSONObject(i);
if(tempJsonObj.has("ul")) if(tempJsonObj.has("ul"))
...@@ -2862,7 +2970,6 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2862,7 +2970,6 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
int responseCode = connection.getResponseCode(); int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) if (responseCode == HttpURLConnection.HTTP_OK)
{ {
String fileName = "";
String disposition = connection.getHeaderField("Content-Disposition"); String disposition = connection.getHeaderField("Content-Disposition");
if (disposition != null) if (disposition != null)
...@@ -2880,9 +2987,9 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2880,9 +2987,9 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
InputStream inputStream = connection.getInputStream(); InputStream inputStream = connection.getInputStream();
saveFilePath += File.separator+fileName; filePath = saveFilePath + File.separator + sectionName + File.separator + fileName;
FileOutputStream outputStream = new FileOutputStream(saveFilePath); FileOutputStream outputStream = new FileOutputStream(filePath);
int bytesRead = -1; int bytesRead = -1;
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
...@@ -2895,17 +3002,17 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2895,17 +3002,17 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
inputStream.close(); inputStream.close();
} }
TarArchiveInputStream tarInput = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(saveFilePath))); /*TarArchiveInputStream tarInput = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(filePath)));
TarArchiveEntry currentEntry = tarInput.getNextTarEntry(); TarArchiveEntry currentEntry = tarInput.getNextTarEntry();
BufferedReader br = null; BufferedReader br = null;
while (currentEntry != null) while (currentEntry != null)
{ {
br = new BufferedReader(new InputStreamReader(tarInput)); br = new BufferedReader(new InputStreamReader(tarInput));
System.out.println("For File = " + currentEntry.getName()); //System.out.println("For File = " + currentEntry.getName());
String line; String line;
while ((line = br.readLine()) != null) while ((line = br.readLine()) != null)
{ {
System.out.println("line="+line); //System.out.println("line="+line);
byte[] decryptEK = aesEncryption.decodeBase64StringTOByte(sessionKey); byte[] decryptEK = aesEncryption.decodeBase64StringTOByte(sessionKey);
String decryptedData = new String(aesEncryption.decrypt(line, decryptEK)); String decryptedData = new String(aesEncryption.decrypt(line, decryptEK));
...@@ -2915,9 +3022,11 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2915,9 +3022,11 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
} }
currentEntry = tarInput.getNextTarEntry(); currentEntry = tarInput.getNextTarEntry();
} }
tarInput.close(); tarInput.close();*/
} }
} }
retString = getDataXMLFromJsonFile(sectionName);
} }
} }
else else
...@@ -2980,6 +3089,185 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -2980,6 +3089,185 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("final retString["+retString+"]"); System.out.println("final retString["+retString+"]");
return retString; return retString;
} }
private String getDataXMLFromJsonFile(String sectionName) throws ITMException
{
String retString = "", sessionKey = "";
StringBuffer retStringBuff = new StringBuffer();
boolean isFilesEncrypted = false;
try
{
String sessionKeyFilePath = saveFilePath + File.separator + sectionName + File.separator + "key.txt";
File sessKeyFile = new File(sessionKeyFilePath);
if(sessKeyFile.exists())
{
FileReader keyInputStream = new FileReader(sessKeyFile);
BufferedReader keyBr = new BufferedReader(keyInputStream);
sessionKey = keyBr.readLine();
keyBr.close();
isFilesEncrypted = true;
}
if(isFilesEncrypted)
{
File jsonFilePath = new File(saveFilePath + File.separator + sectionName);
String[] listOfFiles = jsonFilePath.list();
for(String eachFileName : listOfFiles)
{
System.out.println("eachFileName["+eachFileName+"]");
if(!"key.txt".equalsIgnoreCase(eachFileName))
{
String eachFilePath = saveFilePath + File.separator + sectionName + File.separator + eachFileName;
TarArchiveInputStream tarInput = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(eachFilePath)));
TarArchiveEntry currentEntry = tarInput.getNextTarEntry();
BufferedReader br = null;
while (currentEntry != null)
{
br = new BufferedReader(new InputStreamReader(tarInput));
String line;
while ((line = br.readLine()) != null)
{
byte[] decryptEK = aesEncryption.decodeBase64StringTOByte(sessionKey);
String decryptedData = new String(aesEncryption.decrypt(line, decryptEK));
String decodedJson = new String(Base64.decodeBase64(decryptedData));
retString += XML.toString(new JSONObject(decodedJson));
}
currentEntry = tarInput.getNextTarEntry();
}
tarInput.close();
}
}
}
else
{
String jsonStr = "";
File dataFiles = new File(saveFilePath);
File[] allFileNDir = dataFiles.listFiles();
for(File eachFolder : allFileNDir)
{
if(eachFolder.isDirectory())
{
String eachSecName = eachFolder.getName();
File sectionDataFile = new File(eachFolder.getAbsolutePath());
String[] sectionDataFiles = sectionDataFile.list();
for(String eachSecFileName : sectionDataFiles)
{
System.out.println(sectionDataFile.getAbsolutePath() + File.separator + eachSecFileName);
FileReader secFileReader = new FileReader(sectionDataFile.getAbsolutePath() + File.separator + eachSecFileName);
BufferedReader br = new BufferedReader(secFileReader);
jsonStr = br.readLine();
System.out.println("jsonStr["+jsonStr+"]");
br.close();
}
String dataXML = XML.toString(new JSONObject(jsonStr));
if("B2B".equalsIgnoreCase(eachSecName))
{
retStringBuff.append("<b2b_invoices>");
retStringBuff.append(dataXML);
retStringBuff.append("</b2b_invoices>");
}
else if("B2CL".equalsIgnoreCase(eachSecName))
{
retStringBuff.append("<b2cl_invoices>");
retStringBuff.append(dataXML);
retStringBuff.append("</b2cl_invoices>");
}
else if("B2CS".equalsIgnoreCase(eachSecName))
{
retStringBuff.append("<b2cs_invoices>");
retStringBuff.append(dataXML);
retStringBuff.append("</b2cs_invoices>");
}
else if("CDNR".equalsIgnoreCase(eachSecName))
{
retStringBuff.append("<cdnr_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</cdnr_data>");
}
else if("CDNUR".equalsIgnoreCase(eachSecName))
{
retStringBuff.append("<cdnur_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</cdnur_data>");
}
else if("AT".equalsIgnoreCase(eachSecName))
{
retStringBuff.append("<at_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</at_data>");
}
else if("TXP".equalsIgnoreCase(eachSecName))
{
retStringBuff.append("<txp_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</txp_data>");
}
else if("NIL".equalsIgnoreCase(eachSecName))
{
retStringBuff.append("<nil_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</nil_data>");
}
else if("EXP".equalsIgnoreCase(eachSecName))
{
retStringBuff.append("<exp_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</exp_data>");
}
else if("HSNSUM".equalsIgnoreCase(eachSecName))
{
retStringBuff.append("<hsnsum_data>");
retStringBuff.append(dataXML);
retStringBuff.append("</hsnsum_data>");
}
}
}
retString = retStringBuff.toString();
}
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizEJB.getDataXMLFromJsonFile()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
private void writeDatatoJsonFile(String jsonDataStr, String sectionName) throws ITMException
{
String jsonDataFilePath = "", jsonDataDir = "";
File jsonDataFile = null;
BufferedWriter jsonDataFileWriter = null;
try
{
jsonDataDir = saveFilePath + File.separator + sectionName;
jsonDataFile = new File(jsonDataDir);
if(!jsonDataFile.exists())
{
boolean isFolderCreated = jsonDataFile.mkdir();
System.out.println("section folder created to store json data["+isFolderCreated+"]");
}
jsonDataFilePath = saveFilePath + File.separator + sectionName + File.separator + sectionName+".json";
jsonDataFileWriter = new BufferedWriter(new FileWriter(new File(jsonDataFilePath)));
jsonDataFileWriter.write(jsonDataStr);
jsonDataFileWriter.close();
}
catch(Exception e)
{
System.out.println("GSTDataSubmitWizEJB.writeDatatoJsonFile()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
}
private String checkNull(String input) private String checkNull(String input)
{ {
if (input==null) if (input==null)
......
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