Exceptions added

Exceptions added
Wasi/BS-2343
Naeem Ullah 1 week ago
parent b5e4115227
commit 25fd316087

@ -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 InvalidTransactionAmountException extends ApplicationException {
public InvalidTransactionAmountException(String porOrgacode) {
super(porOrgacode, ERRCode.INVALID_TRANSACTIONAMOUNT);
}
}

@ -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 MismatchGLException extends ApplicationException {
public MismatchGLException(String porOrgacode) {
super(porOrgacode, ERRCode.SAMEGLCODE);
}
}

@ -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 MismatchTransactionAmtException extends ApplicationException {
public MismatchTransactionAmtException(String porOrgacode) {
super(porOrgacode, ERRCode.MISSING_TRX_AMOUNT);
}
}

@ -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 MissingAccountException extends ApplicationException {
public MissingAccountException(String porOrgacode) {
super(porOrgacode, ERRCode.MISSING_ACCOUNT_NUMBER);
}
}

@ -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 MissingGLCodeException extends ApplicationException {
public MissingGLCodeException(String porOrgacode) {
super(porOrgacode, ERRCode.MISSING_GL_CODE);
}
}

@ -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 MissingTransactionAmountException extends ApplicationException {
public MissingTransactionAmountException(String porOrgacode) {
super(porOrgacode, ERRCode.MISSING_TRX_AMOUNT);
}
}

@ -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 SameTransactionAccountException extends ApplicationException {
public SameTransactionAccountException(String porOrgacode) {
super(porOrgacode, ERRCode.SAMEACCOUNTNUMBER);
}
}

@ -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 TransactionAmountException extends ApplicationException {
public TransactionAmountException(String porOrgacode) {
super(porOrgacode, ERRCode.TRANSACTIONAMOUNT);
}
}

@ -1,6 +1,7 @@
package com.mfsys.aconnect.client.service;
import com.mfsys.aconnect.client.dto.*;
import com.mfsys.aconnect.client.exception.*;
import com.mfsys.aconnect.client.model.TransactionLog;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
@ -60,21 +61,15 @@ public class TransactionService {
Double debitAmount = accountGLTransactionRequest.getDebitAcc().getSgtGntramtfc();
if (creditAmount == null || debitAmount == null) {
return ResponseEntity
.badRequest()
.body("Credit and Debit amounts are required");
throw new MissingTransactionAmountException(accountGLTransactionRequest.getPorOrgacode());
}
if (creditAmount <= 0 || debitAmount <= 0) {
return ResponseEntity
.badRequest()
.body("Credit and Debit amounts must be greater than 0");
throw new InvalidTransactionAmountException(accountGLTransactionRequest.getPorOrgacode());
}
if (!creditAmount.equals(debitAmount)) {
return ResponseEntity
.badRequest()
.body("Credit and Debit amounts must be equal");
throw new MismatchTransactionAmtException(accountGLTransactionRequest.getPorOrgacode());
}
String porOrgacode = accountGLTransactionRequest.getPorOrgacode();
@ -114,33 +109,23 @@ public class TransactionService {
String crLocation = gLtoGLRequest.getCreditGl().getPlcLocacode();
if(crGL == null || drGL == null) {
return ResponseEntity
.badRequest()
.body("Credit and Debit GL codes are required");
throw new MissingGLCodeException(gLtoGLRequest.getPorOrgacode());
}
if(crGL.equals(drGL) && drLocation.equals(crLocation)) {
return ResponseEntity
.badRequest()
.body("Credit and Debit GL codes cannot be same");
throw new MismatchGLException(gLtoGLRequest.getPorOrgacode());
}
if (creditAmount == null || debitAmount == null) {
return ResponseEntity
.badRequest()
.body("Credit and Debit amounts are required");
throw new MissingTransactionAmountException(gLtoGLRequest.getPorOrgacode());
}
if (creditAmount <= 0 || debitAmount <= 0) {
return ResponseEntity
.badRequest()
.body("Credit and Debit amounts must be greater than 0");
throw new InvalidTransactionAmountException(gLtoGLRequest.getPorOrgacode());
}
if (!creditAmount.equals(debitAmount)) {
return ResponseEntity
.badRequest()
.body("Credit and Debit amounts must be equal");
throw new TransactionAmountException(gLtoGLRequest.getPorOrgacode());
}
String porOrgacode = gLtoGLRequest.getPorOrgacode();
@ -176,34 +161,24 @@ public class TransactionService {
String drAcc = accountToAccountDTO.getDebitAcc().getMbmBkmsnumber();
if(crAcc == null || drAcc == null) {
return ResponseEntity
.badRequest()
.body("Credit and Debit account numbers are required");
throw new MissingAccountException(accountToAccountDTO.getPorOrgacode());
}
if(crAcc.equals(drAcc)) {
return ResponseEntity
.badRequest()
.body("Debit Account Number and Credit Account Number shouldn't be same");
throw new SameTransactionAccountException(accountToAccountDTO.getPorOrgacode());
}
if (creditAmount == null || debitAmount == null) {
return ResponseEntity
.badRequest()
.body("Credit and Debit amounts are required");
throw new MissingTransactionAmountException(accountToAccountDTO.getPorOrgacode());
}
if (creditAmount.compareTo(BigDecimal.ZERO) <= 0 ||
debitAmount.compareTo(BigDecimal.ZERO) <= 0) {
return ResponseEntity
.badRequest()
.body("Credit and Debit amounts must be greater than 0");
throw new InvalidTransactionAmountException(accountToAccountDTO.getPorOrgacode());
}
if (!creditAmount.equals(debitAmount)) {
return ResponseEntity
.badRequest()
.body("Credit and Debit amounts must be equal");
throw new TransactionAmountException(accountToAccountDTO.getPorOrgacode());
}
String porOrgacode = accountToAccountDTO.getPorOrgacode();
@ -237,16 +212,12 @@ public class TransactionService {
BigDecimal debitAmount = glToAccountDTO.getDebitGl().getSgtGntramtfc();
if (!creditAmount.equals(debitAmount)) {
return ResponseEntity
.badRequest()
.body("Credit and Debit amounts must be equal");
throw new TransactionAmountException(glToAccountDTO.getPorOrgacode());
}
if (creditAmount.compareTo(BigDecimal.ZERO) <= 0 ||
debitAmount.compareTo(BigDecimal.ZERO) <= 0) {
return ResponseEntity
.badRequest()
.body("Credit and Debit amounts must be greater than 0");
throw new InvalidTransactionAmountException(glToAccountDTO.getPorOrgacode());
}
String porOrgacode = glToAccountDTO.getPorOrgacode();

@ -8,7 +8,15 @@ public enum ERRCode implements ErrorMessage {
PASSWORD_ALREADY_EXIST("ERR_SEC_0003", "Old Password is not correct"),
INVALID_CREDENTIALS("ERR_SEC_0004", "Invalid credentials"),
USER_NOT_FOUND("ERR_SEC_0005", "User not found"),
WRONG_PASSWORD("ERR_SEC_0006", "Incorrect password");
WRONG_PASSWORD("ERR_SEC_0006", "Incorrect password"),
TRANSACTIONAMOUNT("ERR_TRX_0001","Credit and Debit amounts must be equal"),
INVALID_TRANSACTIONAMOUNT("ERR_TRX_0002","Credit and Debit amounts must be greater than 0"),
MISSING_TRX_AMOUNT("ERR_TRX_0003","Credit and Debit amounts are required"),
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");
private String code;

Loading…
Cancel
Save