Skip to content

Commit

Permalink
Merge pull request #1313 from sriranjan-s/Dev-2.0
Browse files Browse the repository at this point in the history
reverted code changes
  • Loading branch information
sriranjan-s authored Sep 1, 2024
2 parents 937c8db + 6971d6e commit 19a1e54
Show file tree
Hide file tree
Showing 20 changed files with 423 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public BillResponseV2 fetchBill(GenerateBillCriteria billCriteria, RequestInfoWr
log.info( "If bills are empty" +bills.size());
//if(!billCriteria.getBusinessService().equalsIgnoreCase("WS") && !billCriteria.getBusinessService().equalsIgnoreCase("SW"))
//if(!billCriteria.getBusinessService().equalsIgnoreCase("SW"))
if(!billCriteria.getBusinessService().equalsIgnoreCase("BPA.NC_SAN_FEE"))
updateDemandsForexpiredBillDetails(billCriteria.getBusinessService(), billCriteria.getConsumerCode(), billCriteria.getTenantId(), requestInfoWrapper);
return generateBill(billCriteria, requestInfo);
}
Expand Down Expand Up @@ -379,7 +380,7 @@ public BillResponseV2 generateBill(GenerateBillCriteria billCriteria, RequestInf
consumerCodes.addAll(billCriteria.getConsumerCode());

DemandCriteria demandCriteria=new DemandCriteria();
if(billCriteria.getBusinessService().equalsIgnoreCase("WS") || billCriteria.getBusinessService().equalsIgnoreCase("SW"))
if(billCriteria.getBusinessService().equalsIgnoreCase("WS") || billCriteria.getBusinessService().equalsIgnoreCase("SW") || billCriteria.getBusinessService().equalsIgnoreCase("BPA.NC_SAN_FEE"))
demandCriteria = DemandCriteria.builder()
.status(org.egov.demand.model.Demand.StatusEnum.ACTIVE.toString())
.businessService(billCriteria.getBusinessService())
Expand Down Expand Up @@ -761,4 +762,4 @@ public static List<String> getOwnerFieldsPlainAccessList() {
return ownerPlainRequestFieldsList;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
import org.springframework.jdbc.core.SingleColumnRowMapper;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

@Component
@Slf4j
public class EscalationRepository {


Expand Down Expand Up @@ -43,6 +46,8 @@ public List<String> getBusinessIds(EscalationSearchCriteria criteria){
else {
query = queryBuilder.getEscalationQuery(criteria, preparedStmtList);
}
log.info("query is"+query);
log.info("params are " +preparedStmtList.toString());
List<String> businessIds = jdbcTemplate.query(query, preparedStmtList.toArray(), new SingleColumnRowMapper<>(String.class));
return businessIds;

Expand All @@ -67,4 +72,4 @@ public List<String> getBusinessSMSIds(EscalationSearchCriteria criteria,List<Str
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public String getEscalationQuery(EscalationSearchCriteria criteria, List<Object>
preparedStmtList.add(criteria.getStatus());

if(criteria.getStateSlaExceededBy() != null){
builder.append(" AND (select extract(epoch from current_timestamp)) * 1000 - wf.createdtime - wf.statesla > ? ");
builder.append(" AND (select extract(epoch from current_timestamp)) * 1000 - wf.createdtime > ? ");
preparedStmtList.add(criteria.getStateSlaExceededBy());
}

if(criteria.getBusinessSlaExceededBy() != null){
builder.append(" AND (select extract(epoch from current_timestamp)) * 1000 - wf.createdtime - wf.businessservicesla > ? ");
builder.append(" AND (select extract(epoch from current_timestamp)) * 1000 - wf.createdtime > ? ");
preparedStmtList.add(criteria.getBusinessSlaExceededBy());
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public String getEscalationQueryFiltered(EscalationSearchCriteria criteria,List<
}

if(criteria.getBusinessSlaExceededBy() != null){
builder.append(" AND (select extract(epoch from current_timestamp)) * 1000 - wf.createdtime - wf.businessservicesla > ? ");
builder.append(" AND (select extract(epoch from current_timestamp)) * 1000 - wf.createdtime > ? ");
preparedStmtList.add(criteria.getBusinessSlaExceededBy());
}

Expand Down Expand Up @@ -134,4 +134,4 @@ public String getSMSQueryFiltered(EscalationSearchCriteria criteria,List<String>
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ private void processEscalation(RequestInfo requestInfo, Escalation escalation, L
Integer numberOfBusinessIds = businessIds.size();
Integer batchSize = config.getEscalationBatchSize();

log.info("Records to process"+numberOfBusinessIds);

for(int i = 0; i < numberOfBusinessIds; i = i + batchSize){

// Processing the businessIds in batches
Expand Down Expand Up @@ -249,4 +251,4 @@ private void triggerSMS(RequestInfo requestInfo, Escalation escalation, List<Str
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void testGetEscalationQuery() {
"select businessId from ( SELECT *,RANK () OVER (PARTITION BY businessId ORDER BY createdtime DESC)"
+ " rank_number FROM eg_wf_processinstance_v2 WHERE businessservice = ? AND tenantid= ? ) wf WHERE"
+ " rank_number = 1 AND wf.status = ? AND (select extract(epoch from current_timestamp)) * 1000 -"
+ " wf.createdtime - wf.statesla > ? AND (select extract(epoch from current_timestamp)) * 1000 -"
+ " wf.createdtime - wf.businessservicesla > ? ",
+ " wf.createdtime > ? AND (select extract(epoch from current_timestamp)) * 1000 -"
+ " wf.createdtime > ? ",
this.escalationQueryBuilder.getEscalationQuery(escalationSearchCriteria, objectList));
verify(escalationSearchCriteria, atLeast(1)).getBusinessSlaExceededBy();
verify(escalationSearchCriteria, atLeast(1)).getStateSlaExceededBy();
Expand All @@ -60,7 +60,7 @@ void testGetEscalationQuerywithstatesla() {
"select businessId from ( SELECT *,RANK () OVER (PARTITION BY businessId ORDER BY createdtime DESC)"
+ " rank_number FROM eg_wf_processinstance_v2 WHERE businessservice = ? AND tenantid= ? ) wf WHERE"
+ " rank_number = 1 AND wf.status = ? AND (select extract(epoch from current_timestamp)) * 1000 -"
+ " wf.createdtime - wf.statesla > ? ",
+ " wf.createdtime > ? ",
this.escalationQueryBuilder.getEscalationQuery(escalationSearchCriteria, objectList));
verify(escalationSearchCriteria).getBusinessSlaExceededBy();
verify(escalationSearchCriteria, atLeast(1)).getStateSlaExceededBy();
Expand All @@ -83,7 +83,7 @@ void testGetEscalationQuerywithbusinessservicesla() {
"select businessId from ( SELECT *,RANK () OVER (PARTITION BY businessId ORDER BY createdtime DESC)"
+ " rank_number FROM eg_wf_processinstance_v2 WHERE businessservice = ? AND tenantid= ? ) wf WHERE"
+ " rank_number = 1 AND wf.status = ? AND (select extract(epoch from current_timestamp)) * 1000 -"
+ " wf.createdtime - wf.businessservicesla > ? ",
+ " wf.createdtime > ? ",
this.escalationQueryBuilder.getEscalationQuery(escalationSearchCriteria, objectList));
verify(escalationSearchCriteria, atLeast(1)).getBusinessSlaExceededBy();
verify(escalationSearchCriteria).getStateSlaExceededBy();
Expand All @@ -93,4 +93,3 @@ void testGetEscalationQuerywithbusinessservicesla() {
assertEquals(4, objectList.size());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,43 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Base64;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;

import org.egov.dx.util.Configurations;
import org.egov.dx.util.Utilities;

import org.egov.dx.web.models.FileResponse;
import org.egov.dx.web.models.RequestInfoWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import org.w3c.dom.Document;

import com.emudhra.esign.ReturnDocument;
import com.emudhra.esign.eSign;
import com.emudhra.esign.eSignInput;
import com.emudhra.esign.eSignInputBuilder;
import com.emudhra.esign.eSignServiceReturn;
import com.google.gson.Gson;

import lombok.extern.slf4j.Slf4j;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

@Service
@Slf4j
public class eSignService {

@Autowired
Expand Down Expand Up @@ -85,7 +91,7 @@ public String processPDF(RequestInfoWrapper requestInfoWrapper) throws IOExcepti
.setSignedBy("Manvi") //(mandatory)
.setCoSign(true)
.setAppearanceType(eSign.AppearanceType.StandardSignature)
.setPageTobeSigned(eSign.PageTobeSigned.Even)
.setPageTobeSigned(eSign.PageTobeSigned.First)
.setCoordinates(eSign.Coordinates.TopLeft)
.build();

Expand Down Expand Up @@ -118,6 +124,9 @@ public String getEsignedPDF(HttpServletRequest request, HttpServletResponse resp
InputStream xmlStream;
String xml = "";
String txnref = null;
byte[] signedBytes = null;
String pdfPath=null;

try {
// Get response from gateway
xmlStream = request.getInputStream();
Expand All @@ -127,21 +136,20 @@ public String getEsignedPDF(HttpServletRequest request, HttpServletResponse resp

String txn = new String(java.util.Base64.getDecoder().decode(txns.getBytes()));
String[] strArr = txn.split("\\|");
String txnid = strArr[0];

eSign eSign = new eSign(configurations.getLicenceFile(), configurations.getPfxPath(), configurations.getPfxPassword(), configurations.getPfxAllias());
eSignServiceReturn returnService = eSign.getStatus(txnid);
xml = returnService.getResponseXML();
String txnId = strArr[0];

String xmlString = URLDecoder.decode(txnref);
xml = xmlString.split("&XML=")[1];

Document doc = Utilities.convertStringToDocument(xml);

XPath xPath = XPathFactory.newInstance().newXPath();
String status = Utilities.GetXpathValue(xPath, "/EsignResp/@status", doc);
String txnId = Utilities.GetXpathValue(xPath, "/EsignResp/@txn", doc);

txnId = Utilities.GetXpathValue(xPath, "/EsignResp/@txn", doc);
if ("1".equals(status)) {

// complete signing
eSign eSign = new eSign(configurations.getLicenceFile(), configurations.getPfxPath(), configurations.getPfxPassword(), configurations.getPfxAllias());
eSignServiceReturn serviceReturn = eSign.getSigedDocument(xml, configurations.getTempFolder() + File.separator + txnId + ".sig");

// To convert signed pdf from base 64 encoded string to pdf file
Expand All @@ -150,8 +158,10 @@ public String getEsignedPDF(HttpServletRequest request, HttpServletResponse resp
int i = 0;
for (ReturnDocument returnDocument : returnDocuments) {
String pdfBase64 = returnDocument.getSignedDocument();
byte[] signedBytes = esign.text.pdf.codec.Base64.decode(pdfBase64);
String pdfPath = configurations.getOutputFolder() + File.separator + txnId + "_" + i + ".pdf";
System.out.println("Print" +pdfBase64);
signedBytes = esign.text.pdf.codec.Base64.decode(pdfBase64);
pdfPath = configurations.getOutputFolder() + File.separator + txnId + "_" + i + ".pdf";
//String pdfPath = configurations.getS3Bucket() + File.separator + txnId + "_" + i + ".pdf";
try (FileOutputStream fos = new FileOutputStream(pdfPath)) {
fos.write(signedBytes);
}
Expand All @@ -162,10 +172,31 @@ public String getEsignedPDF(HttpServletRequest request, HttpServletResponse resp
} catch (Exception e) {
e.printStackTrace();
}
return ("Document Signed and saved successfully");


OkHttpClient client = new OkHttpClient().newBuilder()
.build();
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("tenantId","pg")
.addFormDataPart("module","TL")
.addFormDataPart("file",pdfPath,
RequestBody.create(MediaType.parse("application/pdf"),
new File(pdfPath)))
.build();
Request request1 = new Request.Builder()
.url("https://upyog-test.niua.org/filestore/v1/files")
.method("POST", body)
.addHeader("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundaryf04Aqi5zqaexyYxK")
.build();

String responsee = client.newCall(request1).execute().body().string();
log.info(responsee);
Gson gson = new Gson();
FileResponse files = gson.fromJson(responsee , FileResponse.class);

return files.getFiles().get(0).getFileStoreId();

}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,16 @@ public class Configurations {
@Value("${esign.outputfolder}")
private String outputFolder;

}
@Value("${esign.UIURL}")
private String uIURL;

// @Value("${esign.tlredirecturl}")
// private String tlRedirectUrl;

// @Value("${eSign.s3bucket}")
// private String s3Bucket;
//
// @Value("${api.documenthost}")
// private String documentHost;

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,31 @@

package org.egov.dx.web.controller;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URISyntaxException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.http.MediaType;
import org.egov.common.contract.request.RequestInfo;
import org.egov.dx.service.eSignService;
import org.egov.dx.util.Configurations;
import org.egov.dx.web.models.ResponseInfoFactory;
import org.egov.dx.web.models.RequestInfoWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.util.UriComponentsBuilder;


import lombok.extern.slf4j.Slf4j;

Expand All @@ -76,6 +82,9 @@ public class EsignController {
@Autowired
eSignService esignService;

@Autowired
Configurations configurations;

@RequestMapping("/process")
public ResponseEntity<String> processPDF(@Valid @RequestBody RequestInfoWrapper requestInfoWrapper) throws URISyntaxException {
try {
Expand All @@ -86,13 +95,25 @@ public ResponseEntity<String> processPDF(@Valid @RequestBody RequestInfoWrapper
}
}
@RequestMapping("/redirect")
public ResponseEntity<String> getEsignedPDF(HttpServletRequest request, HttpServletResponse response) throws ServletException {
public ResponseEntity<Object> getEsignedPDF(HttpServletRequest request, HttpServletResponse response) throws ServletException {
try {
String responseUrl = esignService.getEsignedPDF( request, response);
return new ResponseEntity<>(responseUrl, HttpStatus.OK);
//byte[] byteArray = esignService.getEsignedPDF( request, response);

String ff = esignService.getEsignedPDF( request, response);

HttpHeaders httpHeaders = new HttpHeaders();
// httpHeaders.add(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=report.pdf");
// httpHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_PDF_VALUE);
StringBuilder redirectURL = new StringBuilder();
redirectURL.append(configurations.getUIURL()+"?filestore="+ff);
httpHeaders.setLocation(UriComponentsBuilder.fromHttpUrl(redirectURL.toString())
.queryParams(null).build().encode().toUri());
return new ResponseEntity<>(httpHeaders, HttpStatus.FOUND);


} catch (IOException e) {
return new ResponseEntity<>("Error processing PDF: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}


Loading

0 comments on commit 19a1e54

Please sign in to comment.