FINERACT-1806-undo-charge-off-reverse-external-id-support
This commit is contained in:
committed by
Arnold Gálovics
parent
e6e08814ec
commit
227f5746e5
+2
@@ -261,6 +261,8 @@ final class LoanTransactionsApiResourceSwagger {
|
||||
public String note;
|
||||
@Schema(example = "3e7791ce-aa10-11ec-b909-0242ac120002")
|
||||
public String externalId;
|
||||
@Schema(example = "3f7791cf-bb10-11ec-b909-0242ac120012")
|
||||
public String reversalExternalId;
|
||||
@Schema(example = "3")
|
||||
public Long paymentTypeId;
|
||||
@Schema(example = "acc123")
|
||||
|
||||
+21
@@ -181,6 +181,27 @@ public final class LoanEventApiJsonValidator {
|
||||
}
|
||||
}
|
||||
|
||||
public void validateUndoChargeOff(final String json) {
|
||||
if (!StringUtils.isBlank(json)) {
|
||||
final Set<String> transactionParameters = new HashSet<>(Arrays.asList(LoanApiConstants.REVERSAL_EXTERNAL_ID_PARAMNAME));
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, transactionParameters);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transaction");
|
||||
|
||||
final JsonElement element = this.fromApiJsonHelper.parse(json);
|
||||
|
||||
final String reversalExternalId = this.fromApiJsonHelper.extractStringNamed(LoanApiConstants.REVERSAL_EXTERNAL_ID_PARAMNAME,
|
||||
element);
|
||||
baseDataValidator.reset().parameter(LoanApiConstants.REVERSAL_EXTERNAL_ID_PARAMNAME).ignoreIfNull().value(reversalExternalId)
|
||||
.notExceedingLengthOf(100);
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void validateTransaction(final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) {
|
||||
|
||||
+7
-1
@@ -2796,6 +2796,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
@Override
|
||||
@Transactional
|
||||
public CommandProcessingResult undoChargeOff(JsonCommand command) {
|
||||
this.loanEventApiJsonValidator.validateUndoChargeOff(command.json());
|
||||
final Long loanId = command.getLoanId();
|
||||
final Loan loan = this.loanAssembler.assembleFrom(loanId);
|
||||
final List<Long> existingTransactionIds = loan.findExistingTransactionIds();
|
||||
@@ -2820,8 +2821,13 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
||||
}
|
||||
businessEventNotifierService.notifyPreBusinessEvent(new LoanUndoChargeOffBusinessEvent(chargedOffTransaction));
|
||||
|
||||
chargedOffTransaction.reverse();
|
||||
// check if reversalExternalId is provided
|
||||
final String reversalExternalId = command.stringValueOfParameterNamedAllowingNull(LoanApiConstants.REVERSAL_EXTERNAL_ID_PARAMNAME);
|
||||
final ExternalId reversalTxnExternalId = ExternalIdFactory.produce(reversalExternalId);
|
||||
|
||||
chargedOffTransaction.reverse(reversalTxnExternalId);
|
||||
chargedOffTransaction.manuallyAdjustedOrReversed();
|
||||
|
||||
loan.liftChargeOff();
|
||||
loanTransactionRepository.saveAndFlush(chargedOffTransaction);
|
||||
saveLoanWithDataIntegrityViolationChecks(loan);
|
||||
|
||||
Reference in New Issue
Block a user