Loan Document API added and PreviousDayCancellationTransaction check added

Exception-Handling
Wasiullah Khan Jadoon 3 weeks ago
parent 2c1745cf62
commit a222751188

@ -33,4 +33,11 @@ public class UploadDocumentController {
return uploadDocumentService.crmCacheFiles(files, porOrgacode, susUserCode, token);
}
@PostMapping(value = AconnectURI.LOAN_DOCUMENT_UPLOAD, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<Map<String, String>> uploadLOANDocuments(@RequestParam("file") List<MultipartFile> files,
@RequestHeader("POR_ORGACODE") String porOrgacode, @RequestHeader("Authorization") String token,
@RequestHeader("SUS_USERCODE") String susUserCode) {
return uploadDocumentService.loanCacheFiles(files, porOrgacode, susUserCode, token);
}
}

@ -0,0 +1,11 @@
package com.mfsys.aconnect.client.exception;
import com.mfsys.common.configuration.constant.ERRCode;
import com.mfsys.common.configuration.exception.ApplicationException;
public class PreviousDayCancellationException extends ApplicationException {
public PreviousDayCancellationException(String porOrgacode) {
super(porOrgacode, ERRCode.PREVIOUS_DAY_CANCELLATION);
}
}

@ -0,0 +1,10 @@
package com.mfsys.aconnect.client.exception;
import com.mfsys.common.configuration.constant.ERRCode;
import com.mfsys.common.configuration.exception.ApplicationException;
public class TransactionNotFoundException extends ApplicationException {
public TransactionNotFoundException(String porOrgacode) {
super(porOrgacode, ERRCode.TRANSACTION_NOT_FOUND_EXCEPTION);
}
}

@ -3,5 +3,10 @@ package com.mfsys.aconnect.client.repository;
import com.mfsys.aconnect.client.model.TransactionLog;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Optional;
public interface TransactionLogRepository extends JpaRepository<TransactionLog, Long> {
Optional<TransactionLog> findByTransactionIDAndPorOrgacode(
String transactionID,
String porOrgacode);
}

@ -2,11 +2,17 @@ package com.mfsys.aconnect.client.service;
import com.mfsys.aconnect.client.dto.DepositCancellationDTO;
import com.mfsys.aconnect.client.dto.GLCancellationDTO;
import com.mfsys.aconnect.client.exception.PreviousDayCancellationException;
import com.mfsys.aconnect.client.exception.TransactionNotFoundException;
import com.mfsys.aconnect.client.model.TransactionLog;
import com.mfsys.aconnect.client.repository.TransactionLogRepository;
import com.mfsys.aconnect.configuration.config.WebClientConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import static com.mfsys.common.configuration.constant.AconnectURI.ACONNECT;
import static com.mfsys.common.configuration.constant.AconnectURI.GENERALLEDGER;
@ -20,12 +26,23 @@ public class CancellationTransactionService {
private String generalledgerURI;
private final WebClientConfig webClientConfig;
public CancellationTransactionService(WebClientConfig webClientConfig) {
private final TransactionLogRepository transactionLogRepository;
public CancellationTransactionService(WebClientConfig webClientConfig, TransactionLogRepository transactionLogRepository) {
this.webClientConfig = webClientConfig;
this.transactionLogRepository = transactionLogRepository;
}
public ResponseEntity<Object> processDepositCancellationTransaction(DepositCancellationDTO depositCancellationDTO, String tokenHeader) {
String porOrgacode = depositCancellationDTO.getPorOrgacode();
TransactionLog log = transactionLogRepository
.findByTransactionIDAndPorOrgacode(depositCancellationDTO.getNodeId()+depositCancellationDTO.getSgtGntrtranlink(), porOrgacode)
.orElseThrow(() -> new TransactionNotFoundException(porOrgacode));
if (!log.getSgtGntrdate().isEqual(LocalDate.now())) {
throw new PreviousDayCancellationException(porOrgacode);
}
String url = depositURI + "/deposit" + "/organizations/" + depositCancellationDTO.getPorOrgacode() +
"/transactions" + ACONNECT + "/cancel/nodes/" + depositCancellationDTO.getNodeId() +
"/trannums/" + depositCancellationDTO.getSgtGntrtranlink();
@ -46,6 +63,15 @@ public class CancellationTransactionService {
public ResponseEntity<Object> processGLCancellationTransaction(GLCancellationDTO glCancellationDTO, String tokenHeader) {
String porOrgacode = glCancellationDTO.getPorOrgacode();
TransactionLog log = transactionLogRepository
.findByTransactionIDAndPorOrgacode(glCancellationDTO.getNodeId()+glCancellationDTO.getSgtGntrtranlink(), porOrgacode)
.orElseThrow(() -> new TransactionNotFoundException(porOrgacode));
if (!log.getSgtGntrdate().isEqual(LocalDate.now())) {
throw new PreviousDayCancellationException(porOrgacode);
}
String url = generalledgerURI + GENERALLEDGER + "/organizations/" + glCancellationDTO.getPorOrgacode() +
"/transactions" + ACONNECT + "/cancel/nodes/" + glCancellationDTO.getNodeId() +
"/trannums/" + glCancellationDTO.getSgtGntrtranlink();

@ -19,6 +19,9 @@ public class UploadDocumentService {
@Value("${app.crm.uri}")
private String crmURI;
@Value("${app.loan.uri}")
private String loanURI;
private final WebClientConfig webClientConfig;
public UploadDocumentService(WebClientConfig webClientConfig){
this.webClientConfig = webClientConfig;
@ -77,4 +80,32 @@ public class UploadDocumentService {
new ParameterizedTypeReference<Map<String, String>>() {}
);
}
public ResponseEntity<Map<String, String>> loanCacheFiles(
List<MultipartFile> files, String porOrgacode, String susUserCode, String token) {
String url = loanURI + "/loan" + "/mongodb/cacheFiles";
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", token);
headers.set("POR_ORGACODE", porOrgacode);
headers.set("SUS_USERCODE", susUserCode);
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("POR_ORGACODE", porOrgacode);
for (MultipartFile file : files) {
body.add("file", file.getResource());
}
return webClientConfig.postMultipart(
url,
body,
headers,
new ParameterizedTypeReference<Map<String, String>>() {}
);
}
}

@ -47,6 +47,7 @@ public interface AconnectURI {
String APPROVE_BUSINESS_DEPOSIT_CREATION_URI = DEPOSIT + BUSINESS + "/approval";
String CRM_DOCUMENT_UPLOAD = CRM + "/uploadDocument";
String DEPOSIT_DOCUMENT_UPLOAD = DEPOSIT + "/uploadDocument";
String LOAN_DOCUMENT_UPLOAD = LOAN + "/uploadDocument";
String BUSINESS_DEPOSIT_CREATION_URI = DEPOSIT + BUSINESS + "/create";

@ -15,7 +15,9 @@ public enum ERRCode implements ErrorMessage {
MISSING_GL_CODE("ERR_GL_0001","Credit and Debit GL codes are required"),
SAMEGLCODE("ERR_GL_0002","Credit and Debit GL codes must be different"),
MISSING_ACCOUNT_NUMBER("ERR_ACCT_0001","Account number is required"),
SAMEACCOUNTNUMBER("ERR_ACCT_0002","Account number must be different");
SAMEACCOUNTNUMBER("ERR_ACCT_0002","Account number must be different"),
PREVIOUS_DAY_CANCELLATION("ERR_TRX_0004","Previous day transactions cannot be cancelled"),
TRANSACTION_NOT_FOUND_EXCEPTION("ERR_TRX_0005","Previous day transaction not found");

@ -12,6 +12,7 @@ public interface TokenBypassURI {
"/aconnect/deposit/uploadDocument",
"/aconnect/crm/uploadDocument",
"/aconnect/loan/uploadDocument",
"/aconnect/transactions/accounttogl",
"/aconnect/crm/individual/approve",
"/aconnect/crm/inprocess",

@ -38,7 +38,7 @@ public class LoggingFilter extends OncePerRequestFilter {
String method = request.getMethod();
return "POST".equalsIgnoreCase(method) && ("/aconnect/deposit/uploadDocument".equals(uri) ||
"/aconnect/crm/uploadDocument".equals(uri));
"/aconnect/crm/uploadDocument".equals(uri) || "/aconnect/loan/uploadDocument".equals(uri));
}
@Override

Loading…
Cancel
Save