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;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
......@@ -17,7 +20,6 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
......@@ -75,6 +77,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
private String clientId = "";
private String clientSecret = "";
private String fileDownloadDir = "";
private String saveFilePath = "";
AESEncryption aesEncryption = null;
PubKeyEncryption pubKeyEncryption = null;
GSPSignature gspSignature;
......@@ -371,6 +374,8 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
byte[] authSEK = null;
String loginCode = "", chgTerm = "", callStatus = "", responseId = "", responseJsonStr= "", recType = "";
String signDataXML = "", summaryDataJsonStr = "";
int submitRowCnt = 0;
boolean isLocalDataFiles = false;
System.out.println(" -------- Inside itemchange case 2222222 ------------ ");
if( currentColumn.trim().equalsIgnoreCase( "itm_default" ))
......@@ -419,199 +424,266 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
}
}
transactionId = UUID.randomUUID().toString().replaceAll("-", "");
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
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");
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();
authTokenReqObj.put("action", "AUTHTOKEN");
authTokenReqObj.put("username", userName);
authTokenReqObj.put("app_key", appKeyEncryptedAndCoded);
authTokenReqObj.put("otp", encryptedOTP);
if("GETINV".equalsIgnoreCase(action) || "SUBMIT".equalsIgnoreCase(action))
{
File baseDir = new File(fileDownloadDir);
String baseDirPath = baseDir.getAbsolutePath();
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))
.header("Content-Type",APPLICATION_JSON)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("state-cd", stateCode)
.header("ip-usr", ipAddress)
.header("txn", transactionId)
.header("app_key", appKeyEncryptedAndCoded)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(authTokenReqObj.toString()))
.getHttpRequest();
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();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
otp = checkNull(e12GenericUtility.getColumnValue("otp", dom1));
String encryptedOTP = aesEncryption.encryptEK(otp.getBytes(), appKeyInBytes);
JSONObject authTokenReqObj = new JSONObject();
authTokenReqObj.put("action", "AUTHTOKEN");
authTokenReqObj.put("username", userName);
authTokenReqObj.put("app_key", appKeyEncryptedAndCoded);
authTokenReqObj.put("otp", encryptedOTP);
System.out.println(String.format("authTokenResp Request : Status[%s] Response[%s]", authTokenResp.getStatus(), authTokenResp.getBody()));
if(authTokenResp.getStatus() == 200)
{
JSONObject object = authTokenResp.getBody().getObject();
if (object.has("auth_token") && object.has("sek") && object.has("status_cd") && Objects.equals(object.getString("status_cd"), "1"))
{
callStatus = "1";
authToken = object.getString("auth_token");
sek = object.getString("sek");
authSEK = aesEncryption.decrypt(sek, appKeyInBytes);
System.out.println("AuthSEK = "+ aesEncryption.encodeBase64String(authSEK));
}
else
{
callStatus = "2";
JSONObject errorJSON = authTokenResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
if("AUTH4033".equalsIgnoreCase(errorJSON.getString("error_cd")))
{
errorXML = new ITMDBAccessEJB().getErrorString("","VTINVOTP","","",conn);
}
else
{
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
errorXML = getError(errMsg, "GSTAPIERR", conn);
}
}
}
else if(authTokenResp.getStatus() == 500)
{
callStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+authTokenResp.getStatus();
responseJsonStr = errMsg;
errorXML = getError(errMsg, "GSTAPIERR", conn);
}
else
{
callStatus = "2";
JSONObject errorJSON = authTokenResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
errorXML = getError(errMsg, "GSTAPIERR", conn);
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("AUTHTOKEN");
apiCallData.setRecType(recType);
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);
if( authToken != null && authToken.trim().length()>0 && authSEK != null)
{
if("GSTR1".equalsIgnoreCase(returnType))
{
if("SUBMIT".equalsIgnoreCase(action))
{
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>";
}
else if(summaryDataJsonStr.indexOf("Message :") >= 0)
{
retXML += summaryDataJsonStr;
}
retXML += downloadGstr1Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
}
else if("FILE".equalsIgnoreCase(action))
{
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>";
}
else if(summaryDataJsonStr.indexOf("Message :") >= 0)
{
retXML += summaryDataJsonStr;
}
}
else if("GETINV".equalsIgnoreCase(action))
{
retXML += downloadGstr1Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
}
}
if("GSTR2".equalsIgnoreCase(returnType))
{
if("SUBMIT".equalsIgnoreCase(action))
{
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>";
}
else if(summaryDataJsonStr.indexOf("Message :") >= 0)
{
retXML += summaryDataJsonStr;
}
retXML += downloadGstr2Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
}
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)
{
retXML += "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>";
}
else if(summaryDataJsonStr.indexOf("Message :") >= 0)
{
retXML += summaryDataJsonStr;
}
}
else if("GETINV".equalsIgnoreCase(action))
{
retXML += downloadGstr2Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
}
}
if("GSTR3B".equalsIgnoreCase(returnType))
{
if("SUBMIT".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 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;
}
}
}
}
HttpRequest authTokenReq = Unirest.post(String.format("%s%s", GSP_API_URL, AUTH_TOKEN_URL_V2))
.header("Content-Type",APPLICATION_JSON)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("state-cd", stateCode)
.header("ip-usr", ipAddress)
.header("txn", transactionId)
.header("app_key", appKeyEncryptedAndCoded)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(authTokenReqObj.toString()))
.getHttpRequest();
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()));
if(authTokenResp.getStatus() == 200)
{
JSONObject object = authTokenResp.getBody().getObject();
if (object.has("auth_token") && object.has("sek") && object.has("status_cd") && Objects.equals(object.getString("status_cd"), "1"))
{
callStatus = "1";
authToken = object.getString("auth_token");
sek = object.getString("sek");
authSEK = aesEncryption.decrypt(sek, appKeyInBytes);
System.out.println("AuthSEK = "+ aesEncryption.encodeBase64String(authSEK));
}
else
{
callStatus = "2";
JSONObject errorJSON = authTokenResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
if("AUTH4033".equalsIgnoreCase(errorJSON.getString("error_cd")))
{
errorXML = new ITMDBAccessEJB().getErrorString("","VTINVOTP","","",conn);
}
else
{
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
errorXML = getError(errMsg, "GSTAPIERR", conn);
}
}
}
else if(authTokenResp.getStatus() == 500)
{
callStatus = "2";
errMsg = "Message : Error occurred at GSTN server \nResponse code : "+authTokenResp.getStatus();
responseJsonStr = errMsg;
errorXML = getError(errMsg, "GSTAPIERR", conn);
}
else
{
callStatus = "2";
JSONObject errorJSON = authTokenResp.getBody().getObject().getJSONObject("error");
responseJsonStr = errorJSON.toString();
errMsg = "Message : "+errorJSON.getString("message")+" \nError code : "+errorJSON.getString("error_cd");
errorXML = getError(errMsg, "GSTAPIERR", conn);
}
APICallData apiCallData = new APICallData();
apiCallData.setPeriodCode(periodCode);
apiCallData.setCallDate(new Date());
apiCallData.setSiteCode(siteCode);
apiCallData.setUserId(loginCode);
apiCallData.setCallType("AUTHTOKEN");
apiCallData.setRecType(recType);
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);
if( authToken != null && authToken.trim().length()>0 && authSEK != null)
{
if("GSTR1".equalsIgnoreCase(returnType))
{
if("SUBMIT".equalsIgnoreCase(action))
{
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>";
}
else if(summaryDataJsonStr.indexOf("Message :") >= 0)
{
retXML += summaryDataJsonStr;
}
retXML += downloadGstr1Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
}
else if("FILE".equalsIgnoreCase(action))
{
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>";
}
else if(summaryDataJsonStr.indexOf("Message :") >= 0)
{
retXML += summaryDataJsonStr;
}
}
else if("GETINV".equalsIgnoreCase(action))
{
retXML += downloadGstr1Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
}
}
if("GSTR2".equalsIgnoreCase(returnType))
{
if("SUBMIT".equalsIgnoreCase(action))
{
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>";
}
else if(summaryDataJsonStr.indexOf("Message :") >= 0)
{
retXML += summaryDataJsonStr;
}
retXML += downloadGstr2Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
}
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)
{
retXML += "<summary_data>" + XML.toString(new JSONObject(summaryDataJsonStr)) + "</summary_data>";
}
else if(summaryDataJsonStr.indexOf("Message :") >= 0)
{
retXML += summaryDataJsonStr;
}
}
else if("GETINV".equalsIgnoreCase(action))
{
retXML += downloadGstr2Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, xtraParams, authSEK);
}
}
if("GSTR3B".equalsIgnoreCase(returnType))
{
if("SUBMIT".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 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("<auth_token><![CDATA["+ authToken +"]]></auth_token>");
......@@ -1528,6 +1600,49 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
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)
{
......@@ -1567,7 +1682,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
siteCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
for(String action : gstr1Section)
{
long timeStamp = new Timestamp().getDateTime();
......@@ -1577,7 +1692,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
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("gstin", gstinNo)
.queryString("ret_period", periodCode)
......@@ -1626,11 +1741,12 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
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
{
dataXML = XML.toString(getJsonDataJsonObj);
writeDatatoJsonFile(getJsonDataJsonObj.toString(), action);
}
......@@ -2757,10 +2873,10 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("final retString ["+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 transactionId = "", gspAuthString = "", gspAuthSignature = "", returnType = "", saveFilePath = "";
String transactionId = "", gspAuthString = "", gspAuthSignature = "";
String siteCode = "", loginCode = "", chgTerm = "", responseId = "", responseJsonStr = "", callStatus = "";
try
{
......@@ -2768,30 +2884,15 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
loginCode = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
chgTerm = e12GenericUtility.getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
if("1".equalsIgnoreCase(recType))
{
returnType = "GSTR1";
}
else if("2".equalsIgnoreCase(recType))
{
returnType = "GSTR2";
}
System.out.println("saveFilePath on 2795["+saveFilePath+"]");
File baseDir = new File(fileDownloadDir);
String baseDirPath = baseDir.getAbsolutePath();
String finalDirPath = baseDirPath+File.separator+gstin+File.separator+periodCode+File.separator+returnType;
File finalDir = new File(finalDirPath);
if(!finalDir.exists())
File sectionFolder = new File(saveFilePath + File.separator + sectionName);
if(!sectionFolder.exists())
{
boolean isFoderCreated = finalDir.mkdirs();
if(isFoderCreated)
{
System.out.println("final folder structure created for ["+gstin+"] for return period["+periodCode+"] for ["+returnType+"]");
}
sectionFolder.mkdir();
System.out.println("section folder created for ["+sectionName+"]");
}
saveFilePath = finalDir.getAbsolutePath();
transactionId = UUID.randomUUID().toString().replaceAll("-", "");
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
......@@ -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))
.queryString("gstin", gstin)
.queryString("ret_period",periodCode)
.queryString("token",dataJSONObject.getString("token"))
//.queryString("token",dataJSONObject.getString("token"))//TODO need to change
.queryString("token", "7163714af8a84b62ae6688d8f7a238c1")
.queryString("action","FILEDET")
.header("Content-Type", APPLICATION_JSON)
.header("state-cd", stateCode)
......@@ -2847,9 +2949,15 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
JSONArray fileDetailsArry = filedetailsJsonObj.getJSONArray("urls");
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++)
{
String fileName = "", filePath = "";
JSONObject tempJsonObj = fileDetailsArry.getJSONObject(i);
if(tempJsonObj.has("ul"))
......@@ -2862,7 +2970,6 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK)
{
String fileName = "";
String disposition = connection.getHeaderField("Content-Disposition");
if (disposition != null)
......@@ -2880,9 +2987,9 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
InputStream inputStream = connection.getInputStream();
saveFilePath += File.separator+fileName;
FileOutputStream outputStream = new FileOutputStream(saveFilePath);
filePath = saveFilePath + File.separator + sectionName + File.separator + fileName;
FileOutputStream outputStream = new FileOutputStream(filePath);
int bytesRead = -1;
byte[] buffer = new byte[1024];
......@@ -2895,17 +3002,17 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
inputStream.close();
}
TarArchiveInputStream tarInput = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(saveFilePath)));
/*TarArchiveInputStream tarInput = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(filePath)));
TarArchiveEntry currentEntry = tarInput.getNextTarEntry();
BufferedReader br = null;
while (currentEntry != null)
{
br = new BufferedReader(new InputStreamReader(tarInput));
System.out.println("For File = " + currentEntry.getName());
//System.out.println("For File = " + currentEntry.getName());
String line;
while ((line = br.readLine()) != null)
{
System.out.println("line="+line);
//System.out.println("line="+line);
byte[] decryptEK = aesEncryption.decodeBase64StringTOByte(sessionKey);
String decryptedData = new String(aesEncryption.decrypt(line, decryptEK));
......@@ -2915,9 +3022,11 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
}
currentEntry = tarInput.getNextTarEntry();
}
tarInput.close();
tarInput.close();*/
}
}
retString = getDataXMLFromJsonFile(sectionName);
}
}
else
......@@ -2980,6 +3089,185 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("final retString["+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)
{
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