From 98472b3e59598bfd34dd77b394c982cf477e5ca1 Mon Sep 17 00:00:00 2001 From: Vishwas Babu AJ Date: Sun, 31 Mar 2013 16:53:43 +0530 Subject: [PATCH] fix for loan officer assignment mifosx-260 --- .../LoanEventApiJsonValidator.java | 23 ++++++++ ...WritePlatformServiceJpaRepositoryImpl.java | 55 +++++++++---------- 2 files changed, 50 insertions(+), 28 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanEventApiJsonValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanEventApiJsonValidator.java index 5330d3825..652290cc6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanEventApiJsonValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanEventApiJsonValidator.java @@ -160,4 +160,27 @@ public final class LoanEventApiJsonValidator { throwExceptionIfValidationWarningsExist(dataValidationErrors); } + + public void validateUpdateOfLoanOfficer(final String json) { + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + + final Set disbursementParameters = new HashSet(Arrays.asList("assignmentDate", "fromLoanOfficerId", + "toLoanOfficerId", "locale", "dateFormat")); + + final Type typeOfMap = new TypeToken>() {}.getType(); + fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, disbursementParameters); + + final List dataValidationErrors = new ArrayList(); + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loanOfficer"); + + final JsonElement element = fromApiJsonHelper.parse(json); + + // final Long fromLoanOfficerId = + // fromApiJsonHelper.extractLongNamed("fromLoanOfficerId", element); + final Long toLoanOfficerId = fromApiJsonHelper.extractLongNamed("toLoanOfficerId", element); + + baseDataValidator.reset().parameter("toLoanOfficerId").value(toLoanOfficerId).ignoreIfNull().integerGreaterThanZero(); + + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java index e86708605..a6f1f9601 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -147,7 +147,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf .with(changes) // .build(); } - + @Transactional @Override public Map bulkLoanDisbursal(JsonCommand command, CollectionSheetBulkDisbursalCommand bulkDisbursalCommand) { @@ -155,31 +155,28 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf SingleDisbursalCommand[] disbursalCommand = bulkDisbursalCommand.getDisburseTransactions(); Map changes = new LinkedHashMap(); - if(disbursalCommand == null){ - return changes; - } - + if (disbursalCommand == null) { return changes; } + for (int i = 0; i < disbursalCommand.length; i++) { SingleDisbursalCommand singleLoanDisbursalCommand = disbursalCommand[i]; final Loan loan = retrieveLoanBy(singleLoanDisbursalCommand.getLoanId()); - + final ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(loan.getCurrencyCode()); - + final List existingTransactionIds = new ArrayList(); final List existingReversedTransactionIds = new ArrayList(); - - changes.putAll(loan.disburse(currentUser, command, currency, existingTransactionIds, - existingReversedTransactionIds)); + + changes.putAll(loan.disburse(currentUser, command, currency, existingTransactionIds, existingReversedTransactionIds)); if (!changes.isEmpty()) { this.loanRepository.save(loan); - + final String noteText = command.stringValueOfParameterNamed("note"); if (StringUtils.isNotBlank(noteText)) { Note note = Note.loanNote(loan, noteText); this.noteRepository.save(note); } - + postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds); } } @@ -250,16 +247,16 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf if (StringUtils.isNotBlank(noteText)) { changes.put("note", noteText); } - - CommandProcessingResultBuilder commandProcessingResultBuilder = saveLoanRepayment(loanId, transactionAmount, transactionDate, noteText); - - return commandProcessingResultBuilder - .withCommandId(command.commandId()) // + + CommandProcessingResultBuilder commandProcessingResultBuilder = saveLoanRepayment(loanId, transactionAmount, transactionDate, + noteText); + + return commandProcessingResultBuilder.withCommandId(command.commandId()) // .withLoanId(loanId) // .with(changes) // .build(); } - + private CommandProcessingResultBuilder saveLoanRepayment(final Long loanId, final BigDecimal transactionAmount, final LocalDate transactionDate, final String noteText) { final Loan loan = retrieveLoanBy(loanId); @@ -288,7 +285,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf } this.loanRepository.save(loan); - if (StringUtils.isNotBlank(noteText)) { Note note = Note.loanTransactionNote(loan, newRepaymentTransaction, noteText); this.noteRepository.save(note); @@ -297,10 +293,10 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds); return new CommandProcessingResultBuilder() // - .withEntityId(newRepaymentTransaction.getId()) // - .withOfficeId(loan.getOfficeId()) // - .withClientId(loan.getClientId()) // - .withGroupId(loan.getGroupId()); // + .withEntityId(newRepaymentTransaction.getId()) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()); // } @Transactional @@ -310,16 +306,17 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf context.authenticatedUser(); final SingleRepaymentCommand[] repaymentCommand = bulkRepaymentCommand.getLoanTransactions(); final Map changes = new LinkedHashMap(); - - if(repaymentCommand == null) return changes; - + + if (repaymentCommand == null) return changes; + for (SingleRepaymentCommand singleLoanRepaymentCommand : repaymentCommand) { - saveLoanRepayment(singleLoanRepaymentCommand.getLoanId(), singleLoanRepaymentCommand.getTransactionAmount(), bulkRepaymentCommand.getTransactionDate(), bulkRepaymentCommand.getNote()); + saveLoanRepayment(singleLoanRepaymentCommand.getLoanId(), singleLoanRepaymentCommand.getTransactionAmount(), + bulkRepaymentCommand.getTransactionDate(), bulkRepaymentCommand.getNote()); changes.put("bulkTransations", singleLoanRepaymentCommand); } return changes; } - + @Transactional @Override public CommandProcessingResult adjustLoanTransaction(final Long loanId, final Long transactionId, final JsonCommand command) { @@ -784,6 +781,8 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf this.context.authenticatedUser(); + this.loanEventApiJsonValidator.validateUpdateOfLoanOfficer(command.json()); + final Long fromLoanOfficerId = command.longValueOfParameterNamed("fromLoanOfficerId"); final Long toLoanOfficerId = command.longValueOfParameterNamed("toLoanOfficerId");