From 92b3ed40301be7fe6da4ccdcbf87fbe8dc7b7bde Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Tue, 29 May 2012 22:29:21 +0100 Subject: [PATCH] update state transition and transaction api for loans. --- .../command/AdjustLoanTransactionCommand.java | 98 --------------- .../data/command/LoanTransactionCommand.java | 88 ------------- .../views/client/viewClientAccount.jsp | 31 ++--- .../webapp/WEB-INF/views/view-templates.jsp | 24 ++-- .../platform/ImportPlatformService.java | 4 +- .../platform/ImportPlatformServiceImpl.java | 22 ++-- .../platform/api/ClientApiResource.java | 2 +- .../platform/api/LoansApiResource.java | 117 ++++++++++-------- .../AdjustLoanTransactionCommand.java | 107 ++++++++++++++++ .../CalculateLoanScheduleCommand.java | 2 +- .../api/commands}/ImportLoanCommand.java | 3 +- .../ImportLoanRepaymentsCommand.java | 2 +- .../commands}/LoanStateTransitionCommand.java | 55 ++++---- .../api/commands/LoanTransactionCommand.java | 97 +++++++++++++++ .../platform/api/commands}/NoteCommand.java | 2 +- .../SubmitApproveDisburseLoanCommand.java | 3 +- .../SubmitLoanApplicationCommand.java | 2 +- .../commands}/UndoStateTransitionCommand.java | 17 ++- .../service/ClientWritePlatformService.java | 2 +- ...WritePlatformServiceJpaRepositoryImpl.java | 2 +- ...AdjustLoanTransactionCommandValidator.java | 18 +-- ...CalculateLoanScheduleCommandValidator.java | 2 +- .../service/CalculationPlatformService.java | 2 +- .../CalculationPlatformServiceImpl.java | 2 +- .../platform/loan/service/LoanAssembler.java | 2 +- .../loan/service/LoanReadPlatformService.java | 2 +- .../service/LoanReadPlatformServiceImpl.java | 6 +- .../LoanStateTransitionCommandValidator.java | 21 +--- .../LoanTransactionCommandValidator.java | 13 +- .../service/LoanWritePlatformService.java | 10 +- ...WritePlatformServiceJpaRepositoryImpl.java | 113 +++++++++-------- ...SubmitLoanApplicationCommandValidator.java | 4 +- .../mifosng/platform/rest/ImportResource.java | 4 +- .../platform/rest/ImportTriggerResource.java | 4 +- 34 files changed, 448 insertions(+), 435 deletions(-) delete mode 100644 mifosng-data/src/main/java/org/mifosng/data/command/AdjustLoanTransactionCommand.java delete mode 100644 mifosng-data/src/main/java/org/mifosng/data/command/LoanTransactionCommand.java create mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/api/commands/AdjustLoanTransactionCommand.java rename {mifosng-data/src/main/java/org/mifosng/data/command => mifosng-provider/src/main/java/org/mifosng/platform/api/commands}/CalculateLoanScheduleCommand.java (99%) rename {mifosng-data/src/main/java/org/mifosng/data/command => mifosng-provider/src/main/java/org/mifosng/platform/api/commands}/ImportLoanCommand.java (91%) rename {mifosng-data/src/main/java/org/mifosng/data/command => mifosng-provider/src/main/java/org/mifosng/platform/api/commands}/ImportLoanRepaymentsCommand.java (91%) rename {mifosng-data/src/main/java/org/mifosng/data/command => mifosng-provider/src/main/java/org/mifosng/platform/api/commands}/LoanStateTransitionCommand.java (55%) create mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/api/commands/LoanTransactionCommand.java rename {mifosng-data/src/main/java/org/mifosng/data/command => mifosng-provider/src/main/java/org/mifosng/platform/api/commands}/NoteCommand.java (95%) rename {mifosng-data/src/main/java/org/mifosng/data/command => mifosng-provider/src/main/java/org/mifosng/platform/api/commands}/SubmitApproveDisburseLoanCommand.java (96%) rename {mifosng-data/src/main/java/org/mifosng/data/command => mifosng-provider/src/main/java/org/mifosng/platform/api/commands}/SubmitLoanApplicationCommand.java (99%) rename {mifosng-data/src/main/java/org/mifosng/data/command => mifosng-provider/src/main/java/org/mifosng/platform/api/commands}/UndoStateTransitionCommand.java (61%) diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/AdjustLoanTransactionCommand.java b/mifosng-data/src/main/java/org/mifosng/data/command/AdjustLoanTransactionCommand.java deleted file mode 100644 index 71594861d..000000000 --- a/mifosng-data/src/main/java/org/mifosng/data/command/AdjustLoanTransactionCommand.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.mifosng.data.command; - -import java.math.BigDecimal; - -import javax.xml.bind.annotation.XmlRootElement; - -import org.joda.time.LocalDate; - -@XmlRootElement -public class AdjustLoanTransactionCommand { - - private Long loanId; - private Long repaymentId; - private String dateFormat; - private String transactionDateFormatted; - private LocalDate transactionDate; - private String comment; - private String transactionAmountFormatted; - private BigDecimal transactionAmount; - - protected AdjustLoanTransactionCommand() { - // - } - - public AdjustLoanTransactionCommand(final Long loanId, final Long repaymentId, - final LocalDate paymentDate, final String comment, - final BigDecimal paymentAmount) { - this.loanId = loanId; - this.repaymentId = repaymentId; - this.transactionDate = paymentDate; - this.comment = comment; - this.transactionAmount = paymentAmount; - } - - public Long getLoanId() { - return this.loanId; - } - - public void setLoanId(final Long loanId) { - this.loanId = loanId; - } - - public Long getRepaymentId() { - return repaymentId; - } - - public void setRepaymentId(Long repaymentId) { - this.repaymentId = repaymentId; - } - - public String getDateFormat() { - return dateFormat; - } - - public void setDateFormat(String dateFormat) { - this.dateFormat = dateFormat; - } - - public String getTransactionDateFormatted() { - return transactionDateFormatted; - } - - public void setTransactionDateFormatted(String transactionDateFormatted) { - this.transactionDateFormatted = transactionDateFormatted; - } - - public LocalDate getTransactionDate() { - return transactionDate; - } - - public void setTransactionDate(LocalDate transactionDate) { - this.transactionDate = transactionDate; - } - - public String getComment() { - return comment; - } - - public void setComment(String comment) { - this.comment = comment; - } - - public String getTransactionAmountFormatted() { - return transactionAmountFormatted; - } - - public void setTransactionAmountFormatted(String transactionAmountFormatted) { - this.transactionAmountFormatted = transactionAmountFormatted; - } - - public BigDecimal getTransactionAmount() { - return transactionAmount; - } - - public void setTransactionAmount(BigDecimal transactionAmount) { - this.transactionAmount = transactionAmount; - } -} \ No newline at end of file diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/LoanTransactionCommand.java b/mifosng-data/src/main/java/org/mifosng/data/command/LoanTransactionCommand.java deleted file mode 100644 index 4c0b8f2c7..000000000 --- a/mifosng-data/src/main/java/org/mifosng/data/command/LoanTransactionCommand.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.mifosng.data.command; - -import java.math.BigDecimal; - -import javax.xml.bind.annotation.XmlRootElement; - -import org.joda.time.LocalDate; - -@XmlRootElement -public class LoanTransactionCommand { - - private Long loanId; - private String dateFormat; - private String transactionDateFormatted; - private LocalDate transactionDate; - private String comment; - private String transactionAmountFormatted; - private BigDecimal transactionAmount; - - protected LoanTransactionCommand() { - // - } - - public LoanTransactionCommand(final Long loanId, - final LocalDate paymentDate, final String comment, - final BigDecimal paymentAmount) { - this.loanId = loanId; - this.transactionDate = paymentDate; - this.comment = comment; - this.transactionAmount = paymentAmount; - } - - public Long getLoanId() { - return this.loanId; - } - - public void setLoanId(final Long loanId) { - this.loanId = loanId; - } - - public String getComment() { - return this.comment; - } - - public void setComment(final String comment) { - this.comment = comment; - } - - public String getDateFormat() { - return dateFormat; - } - - public void setDateFormat(String dateFormat) { - this.dateFormat = dateFormat; - } - - public String getTransactionDateFormatted() { - return transactionDateFormatted; - } - - public void setTransactionDateFormatted(String transactionDateFormatted) { - this.transactionDateFormatted = transactionDateFormatted; - } - - public LocalDate getTransactionDate() { - return transactionDate; - } - - public void setTransactionDate(LocalDate transactionDate) { - this.transactionDate = transactionDate; - } - - public String getTransactionAmountFormatted() { - return transactionAmountFormatted; - } - - public void setTransactionAmountFormatted(String transactionAmountFormatted) { - this.transactionAmountFormatted = transactionAmountFormatted; - } - - public BigDecimal getTransactionAmount() { - return transactionAmount; - } - - public void setTransactionAmount(BigDecimal transactionAmount) { - this.transactionAmount = transactionAmount; - } -} \ No newline at end of file diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/client/viewClientAccount.jsp b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/client/viewClientAccount.jsp index 74e3466d0..c6a530012 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/client/viewClientAccount.jsp +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/client/viewClientAccount.jsp @@ -139,9 +139,9 @@ $(document).ready(function() { removeErrors(placeholderDiv); var jsonErrors = JSON.parse(jqXHR.responseText); - console.log(jsonErrors); + var valErrors = jsonErrors.errors; - console.log(valErrors); + var errorArray = new Array(); var arrayIndex = 0; $.each(valErrors, function() { @@ -158,7 +158,7 @@ $(document).ready(function() { argArray[argArrayIndex] = this.value; argArrayIndex++; }); - console.log(argArray); + // hardcoded support for six arguments errorObj.message = jQuery.i18n.prop(this.userMessageGlobalisationCode, argArray[0], argArray[1], argArray[2], argArray[3], argArray[4], argArray[5]); errorObj.value = this.value; @@ -292,7 +292,6 @@ $(document).ready(function() { }); var newFormData = JSON.stringify($('#entityform').serializeObject()); - console.log(newFormData); var jqxhr = $.ajax({ url: postUrl, @@ -302,7 +301,6 @@ $(document).ready(function() { cache: false, data: newFormData, beforeSend: function(xhr) { - console.log("base64: " + base64); xhr.setRequestHeader("Authorization", "Basic " + base64); }, success: function(data, textStatus, jqXHR) { @@ -377,7 +375,6 @@ $(document).ready(function() { }); var newFormData = JSON.stringify($('#entityform').serializeObject()); - console.log(newFormData); var jqxhr = $.ajax({ url: postUrl, @@ -435,8 +432,6 @@ $(document).ready(function() { var $newtabs = $("#newtabs").tabs({ "add": function( event, ui ) { - console.log(ui); - //alert("adding new tab: " + ui.panel.id + " :" + ui.tab.className); $newtabs.tabs('select', '#' + ui.panel.id); }, "ajaxOptions": { @@ -445,7 +440,6 @@ $(document).ready(function() { contentType: 'application/json', cache: false, beforeSend: function(xhr) { - console.log("base64: " + base64); xhr.setRequestHeader("Authorization", "Basic " + base64); }, error: function(jqXHR, status, errorThrown, index, anchor) { @@ -455,12 +449,8 @@ $(document).ready(function() { }, success: function(data, status, xhr) { - console.log(data); - var currentTabIndex = $newtabs.tabs('option', 'selected'); var currentTabAnchor = $newtabs.data('tabs').anchors[currentTabIndex]; - //$(currentTabAnchor).data('cache.tabs', true) - //alert('tab: ' + currentTabIndex + ' - id: ' + currentTabAnchor); var offsetToSubmittedDate = 0; var offsetToApprovalDate = 0; @@ -468,7 +458,6 @@ $(document).ready(function() { var maxOffset = 0; // today if (currentTabIndex < 1) { - console.log("success: client tab."); var tableHtml = $("#clientDataTabTemplate").render(data); $("#clienttab").html(tableHtml); @@ -653,8 +642,8 @@ $(document).ready(function() { var linkId = this.id; var loanId = linkId.replace("repaymentbtn", ""); - var getUrl = baseApiUrl + 'loans/' + loanId + '/transactions/template?transactionType=repayment'; - var postUrl = baseApiUrl + 'loans/' + loanId + '/transactions?transactionType=repayment'; + var getUrl = baseApiUrl + 'loans/' + loanId + '/transactions/template?command=repayment'; + var postUrl = baseApiUrl + 'loans/' + loanId + '/transactions?command=repayment'; var templateSelector = "#transactionLoanFormTemplate"; var width = 500; @@ -676,8 +665,8 @@ $(document).ready(function() { var linkId = this.id; var loanId = linkId.replace("waivebtn", ""); - var getUrl = baseApiUrl + 'loans/' + loanId + '/transactions/template?transactionType=waiver'; - var postUrl = baseApiUrl + 'loans/' + loanId + '/transactions?transactionType=waiver'; + var getUrl = baseApiUrl + 'loans/' + loanId + '/transactions/template?command=waiver'; + var postUrl = baseApiUrl + 'loans/' + loanId + '/transactions?command=waiver'; var templateSelector = "#transactionLoanFormTemplate"; var width = 500; @@ -690,7 +679,6 @@ $(document).ready(function() { } popupDialogWithFormView(getUrl, postUrl, 'POST', "dialog.title.waive.loan", templateSelector, width, height, saveSuccessFunction); - //popupDialogWithFormView(getUrl, postUrl, 'POST', 'dialog.title.waive.loan', templateSelector, width, height, currentTabIndex, offsetToSubmittedDate, defaultOffset, maxOffset) e.preventDefault(); }); $('button.waiveloan span').text(jQuery.i18n.prop('dialog.button.loan.waive')); @@ -715,7 +703,6 @@ $(document).ready(function() { } popupDialogWithFormView(getAndPutUrl, getAndPutUrl, 'PUT', "dialog.title.adjust.loan.repayment", templateSelector, width, height, saveSuccessFunction); -// popupDialogWithFormView(getAndPutUrl, getAndPutUrl, 'PUT', 'dialog.title.adjust.loan.repayment', templateSelector, width, height, currentTabIndex, offsetToSubmittedDate, defaultOffset, maxOffset) e.preventDefault(); }); $('button.adjustloanrepayment span').text(jQuery.i18n.prop('dialog.button.adjust.loan.repayment')); @@ -748,11 +735,9 @@ $(document).ready(function() { dataType: 'json', cache: false, beforeSend: function(xhr) { - console.log("base64: " + base64); xhr.setRequestHeader("Authorization", "Basic " + base64); }, success: function(data, textStatus, jqXHR) { - console.log(data); var tableHtml = $("#clientAccountSummariesTemplate").render(data); $("#clientaccountssummary").html(tableHtml); @@ -786,8 +771,6 @@ $(document).ready(function() { xhr.setRequestHeader("Authorization", "Basic " + base64); }, success: function(data, textStatus, jqXHR) { - console.log(data); - var noteParent = new Object(); noteParent.title = jQuery.i18n.prop('widget.notes.heading'); noteParent.notes = data; diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/view-templates.jsp b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/view-templates.jsp index 0bbc92bb5..c4d0f90de 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/view-templates.jsp +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/view-templates.jsp @@ -804,11 +804,11 @@
- - + + - - + + @@ -816,8 +816,8 @@
- - + +
@@ -826,14 +826,14 @@
- - + + - - + + - - + + diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformService.java index a09dd6b14..b4234ffba 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformService.java @@ -1,8 +1,8 @@ package org.mifosng.platform; -import org.mifosng.data.command.ImportLoanCommand; -import org.mifosng.data.command.ImportLoanRepaymentsCommand; import org.mifosng.platform.api.commands.ImportClientCommand; +import org.mifosng.platform.api.commands.ImportLoanCommand; +import org.mifosng.platform.api.commands.ImportLoanRepaymentsCommand; public interface ImportPlatformService { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformServiceImpl.java index 82d60038b..c4eeb0b05 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformServiceImpl.java @@ -19,15 +19,15 @@ import org.joda.time.LocalDate; import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.ISODateTimeFormat; import org.mifosng.data.LoanSchedule; -import org.mifosng.data.command.CalculateLoanScheduleCommand; -import org.mifosng.data.command.ImportLoanCommand; -import org.mifosng.data.command.ImportLoanRepaymentsCommand; -import org.mifosng.data.command.LoanStateTransitionCommand; -import org.mifosng.data.command.LoanTransactionCommand; -import org.mifosng.data.command.SubmitApproveDisburseLoanCommand; -import org.mifosng.data.command.SubmitLoanApplicationCommand; +import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand; import org.mifosng.platform.api.commands.ClientCommand; import org.mifosng.platform.api.commands.ImportClientCommand; +import org.mifosng.platform.api.commands.ImportLoanCommand; +import org.mifosng.platform.api.commands.ImportLoanRepaymentsCommand; +import org.mifosng.platform.api.commands.LoanStateTransitionCommand; +import org.mifosng.platform.api.commands.LoanTransactionCommand; +import org.mifosng.platform.api.commands.SubmitApproveDisburseLoanCommand; +import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand; import org.mifosng.platform.client.domain.Client; import org.mifosng.platform.client.domain.ClientRepository; import org.mifosng.platform.currency.domain.Money; @@ -140,12 +140,12 @@ public class ImportPlatformServiceImpl implements ImportPlatformService { LoanStateTransitionCommand approveLoanCommand = combinedCommand.getApproveLoanCommand(); if (approveLoanCommand != null) { - loan.approve(approveLoanCommand.getEventDate(), loanLifecycleStateMachine); + loan.approve(approveLoanCommand.getEventLocalDate(), loanLifecycleStateMachine); } LoanStateTransitionCommand disburseLoanCommand = combinedCommand.getDisburseLoanCommand(); if (disburseLoanCommand != null) { - loan.disburse(disburseLoanCommand.getEventDate(), loanLifecycleStateMachine); + loan.disburse(disburseLoanCommand.getEventLocalDate(), loanLifecycleStateMachine); } newLoanCollection.add(loan); @@ -173,9 +173,9 @@ public class ImportPlatformServiceImpl implements ImportPlatformService { for (LoanTransactionCommand repaymentDetail : command.getRepayments()) { Loan loan = findLoanByIdentifier(allLoans, repaymentDetail.getLoanId().toString()); - Money repaymentAmount = Money.of(loan.getCurrency(), repaymentDetail.getTransactionAmount()); + Money repaymentAmount = Money.of(loan.getCurrency(), repaymentDetail.getTransactionAmountValue()); - LoanTransaction loanRepayment = LoanTransaction.repayment(repaymentAmount, repaymentDetail.getTransactionDate()); + LoanTransaction loanRepayment = LoanTransaction.repayment(repaymentAmount, repaymentDetail.getTransactionLocalDate()); loan.makeRepayment(loanRepayment, loanLifecycleStateMachine); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientApiResource.java index 05c9be598..5436ee734 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientApiResource.java @@ -22,8 +22,8 @@ import org.mifosng.data.ClientLoanAccountSummaryCollectionData; import org.mifosng.data.EntityIdentifier; import org.mifosng.data.NoteData; import org.mifosng.data.OfficeLookup; -import org.mifosng.data.command.NoteCommand; import org.mifosng.platform.api.commands.ClientCommand; +import org.mifosng.platform.api.commands.NoteCommand; import org.mifosng.platform.api.infrastructure.ApiDataConversionService; import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService; import org.mifosng.platform.client.service.ClientReadPlatformService; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/LoansApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/LoansApiResource.java index a3c47976f..f3618aad7 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/LoansApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/LoansApiResource.java @@ -24,12 +24,12 @@ import org.mifosng.data.LoanAccountData; import org.mifosng.data.LoanRepaymentData; import org.mifosng.data.LoanSchedule; import org.mifosng.data.NewLoanWorkflowStepOneData; -import org.mifosng.data.command.AdjustLoanTransactionCommand; -import org.mifosng.data.command.CalculateLoanScheduleCommand; -import org.mifosng.data.command.LoanStateTransitionCommand; -import org.mifosng.data.command.LoanTransactionCommand; -import org.mifosng.data.command.SubmitLoanApplicationCommand; -import org.mifosng.data.command.UndoStateTransitionCommand; +import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand; +import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand; +import org.mifosng.platform.api.commands.LoanStateTransitionCommand; +import org.mifosng.platform.api.commands.LoanTransactionCommand; +import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand; +import org.mifosng.platform.api.commands.UndoStateTransitionCommand; import org.mifosng.platform.api.infrastructure.ApiDataConversionService; import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService; import org.mifosng.platform.exceptions.UnrecognizedQueryParamException; @@ -187,12 +187,12 @@ public class LoansApiResource { public Response stateTransitions(@PathParam("loanId") final Long loanId, @QueryParam("command") final String commandParam, final LoanStateTransitionCommand command) { - LocalDate eventDate = this.apiDataConversionService.convertFrom( - command.getEventDateFormatted(), "eventDateFormatted", + LocalDate eventLocalDate = this.apiDataConversionService.convertFrom( + command.getEventDate(), "eventDate", command.getDateFormat()); command.setLoanId(loanId); - command.setEventDate(eventDate); + command.setEventLocalDate(eventLocalDate); Response response = null; @@ -210,7 +210,7 @@ public class LoansApiResource { response = Response.ok().entity(identifier).build(); } - UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(loanId, command.getComment()); + UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(loanId, command.getNote()); if (is(commandParam, "undoapproval")) { EntityIdentifier identifier = this.loanWritePlatformService.undoLoanApproval(undoCommand); response = Response.ok().entity(identifier).build(); @@ -236,31 +236,37 @@ public class LoansApiResource { @Produces({ MediaType.APPLICATION_JSON}) public Response executeLoanTransaction( @PathParam("loanId") final Long loanId, - @QueryParam("transactionType") final String transactionType, + @QueryParam("command") final String commandParam, final LoanTransactionCommand command) { + Response response = null; command.setLoanId(loanId); + + Locale clientLocale = this.apiDataConversionService.localeFromString(command.getLocale()); - LocalDate transactionDate = apiDataConversionService.convertFrom( - command.getTransactionDateFormatted(), - "transactionDateFormatted", command.getDateFormat()); - command.setTransactionDate(transactionDate); + LocalDate transactionLocalDate = apiDataConversionService.convertFrom( + command.getTransactionDate(), + "transactionDate", command.getDateFormat()); + command.setTransactionLocalDate(transactionLocalDate); - BigDecimal transactionAmount = apiDataConversionService.convertFrom( - command.getTransactionAmountFormatted(), - "transactionAmountFormatted", Locale.UK); - command.setTransactionAmount(transactionAmount); + BigDecimal transactionAmountValue = apiDataConversionService.convertFrom( + command.getTransactionAmount(), + "transactionAmount", clientLocale); + command.setTransactionAmountValue(transactionAmountValue); - if (StringUtils.isNotBlank(transactionType) - && transactionType.trim().equalsIgnoreCase("waiver")) { - EntityIdentifier identifier = this.loanWritePlatformService - .waiveLoanAmount(command); - return Response.ok().entity(identifier).build(); + if (is(commandParam, "repayment")) { + EntityIdentifier identifier = this.loanWritePlatformService.makeLoanRepayment(command); + response = Response.ok().entity(identifier).build(); + } else if (is(commandParam, "waiver")) { + EntityIdentifier identifier = this.loanWritePlatformService.waiveLoanAmount(command); + response = Response.ok().entity(identifier).build(); + } + + if (response == null) { + throw new UnrecognizedQueryParamException("command", commandParam); } - EntityIdentifier identifier = this.loanWritePlatformService - .makeLoanRepayment(command); - return Response.ok().entity(identifier).build(); + return response; } @GET @@ -269,37 +275,43 @@ public class LoansApiResource { @Produces({ MediaType.APPLICATION_JSON}) public String retrieveNewRepaymentDetails( @PathParam("loanId") final Long loanId, - @QueryParam("type") final String transactionType, + @QueryParam("command") final String commandParam, @Context UriInfo uriInfo) { + String json = ""; String selectedFields = loanRepaymentDefaultFieldList; - if (StringUtils.isNotBlank(transactionType) - && transactionType.trim().equalsIgnoreCase("waiver")) { + if (is(commandParam, "repayment")) { + LoanRepaymentData loanRepaymentData = this.loanReadPlatformService + .retrieveNewLoanRepaymentDetails(loanId); + json = this.jsonFormattingService.convertRequest(loanRepaymentData, + loanRepaymentFilterName, loanRepaymentAllowedFieldList, selectedFields, + uriInfo.getQueryParameters()); + } else if (is(commandParam, "waiver")) { LoanRepaymentData loanWaiverData = this.loanReadPlatformService .retrieveNewLoanWaiverDetails(loanId); - return this.jsonFormattingService.convertRequest(loanWaiverData, + json = this.jsonFormattingService.convertRequest(loanWaiverData, loanRepaymentFilterName, loanRepaymentAllowedFieldList, selectedFields, uriInfo.getQueryParameters()); } - LoanRepaymentData loanRepaymentData = this.loanReadPlatformService - .retrieveNewLoanRepaymentDetails(loanId); - return this.jsonFormattingService.convertRequest(loanRepaymentData, - loanRepaymentFilterName, loanRepaymentAllowedFieldList, selectedFields, - uriInfo.getQueryParameters()); + if (StringUtils.isBlank(json)) { + throw new UnrecognizedQueryParamException("command", commandParam); + } + + return json; } @GET - @Path("{loanId}/transactions/{repaymentId}") + @Path("{loanId}/transactions/{transactionId}") @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({ MediaType.APPLICATION_JSON}) public String retrieveRepaymentDetails( @PathParam("loanId") final Long loanId, - @PathParam("repaymentId") final Long repaymentId, + @PathParam("transactionId") final Long transactionId, @Context UriInfo uriInfo) { LoanRepaymentData loanRepaymentData = this.loanReadPlatformService - .retrieveLoanRepaymentDetails(loanId, repaymentId); + .retrieveLoanRepaymentDetails(loanId, transactionId); String selectedFields = ""; return this.jsonFormattingService.convertRequest(loanRepaymentData, @@ -308,29 +320,30 @@ public class LoansApiResource { } @PUT - @Path("{loanId}/transactions/{repaymentId}") + @Path("{loanId}/transactions/{transactionId}") @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({ MediaType.APPLICATION_JSON}) public Response adjustLoanTransaction( @PathParam("loanId") final Long loanId, - @PathParam("repaymentId") final Long repaymentId, + @PathParam("transactionId") final Long transactionId, final AdjustLoanTransactionCommand command) { command.setLoanId(loanId); - command.setRepaymentId(repaymentId); + command.setTransactionId(transactionId); + + Locale clientLocale = this.apiDataConversionService.localeFromString(command.getLocale()); - LocalDate transactionDate = apiDataConversionService.convertFrom( - command.getTransactionDateFormatted(), - "transactionDateFormatted", command.getDateFormat()); - command.setTransactionDate(transactionDate); + LocalDate transactionLocalDate = apiDataConversionService.convertFrom( + command.getTransactionDate(), + "transactionDate", command.getDateFormat()); + command.setTransactionLocalDate(transactionLocalDate); - BigDecimal transactionAmount = apiDataConversionService.convertFrom( - command.getTransactionAmountFormatted(), - "transactionAmountFormatted", Locale.UK); - command.setTransactionAmount(transactionAmount); + BigDecimal transactionAmountValue = apiDataConversionService.convertFrom( + command.getTransactionAmount(), + "transactionAmount", clientLocale); + command.setTransactionAmountValue(transactionAmountValue); - EntityIdentifier identifier = this.loanWritePlatformService - .adjustLoanTransaction(command); + EntityIdentifier identifier = this.loanWritePlatformService.adjustLoanTransaction(command); return Response.ok().entity(identifier).build(); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/AdjustLoanTransactionCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/AdjustLoanTransactionCommand.java new file mode 100644 index 000000000..a7a2916ac --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/AdjustLoanTransactionCommand.java @@ -0,0 +1,107 @@ +package org.mifosng.platform.api.commands; + +import java.math.BigDecimal; + +import javax.xml.bind.annotation.XmlRootElement; + +import org.joda.time.LocalDate; + +@XmlRootElement +public class AdjustLoanTransactionCommand { + + private Long loanId; + private Long transactionId; + private String locale; + private String dateFormat; + private String transactionDate; + private LocalDate transactionLocalDate; + private String note; + private String transactionAmount; + private BigDecimal transactionAmountValue; + + protected AdjustLoanTransactionCommand() { + // + } + + public AdjustLoanTransactionCommand(final Long loanId, final Long transactionId, + final LocalDate transactionLocalDate, final String note, + final BigDecimal transactionAmountValue) { + this.loanId = loanId; + this.transactionId = transactionId; + this.transactionLocalDate = transactionLocalDate; + this.note = note; + this.transactionAmountValue = transactionAmountValue; + } + + public Long getLoanId() { + return this.loanId; + } + + public void setLoanId(final Long loanId) { + this.loanId = loanId; + } + + public String getDateFormat() { + return dateFormat; + } + + public void setDateFormat(String dateFormat) { + this.dateFormat = dateFormat; + } + + public Long getTransactionId() { + return transactionId; + } + + public void setTransactionId(Long transactionId) { + this.transactionId = transactionId; + } + + public String getLocale() { + return locale; + } + + public void setLocale(String locale) { + this.locale = locale; + } + + public String getTransactionDate() { + return transactionDate; + } + + public void setTransactionDate(String transactionDate) { + this.transactionDate = transactionDate; + } + + public LocalDate getTransactionLocalDate() { + return transactionLocalDate; + } + + public void setTransactionLocalDate(LocalDate transactionLocalDate) { + this.transactionLocalDate = transactionLocalDate; + } + + public String getNote() { + return note; + } + + public void setNote(String note) { + this.note = note; + } + + public String getTransactionAmount() { + return transactionAmount; + } + + public void setTransactionAmount(String transactionAmount) { + this.transactionAmount = transactionAmount; + } + + public BigDecimal getTransactionAmountValue() { + return transactionAmountValue; + } + + public void setTransactionAmountValue(BigDecimal transactionAmountValue) { + this.transactionAmountValue = transactionAmountValue; + } +} \ No newline at end of file diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/CalculateLoanScheduleCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/CalculateLoanScheduleCommand.java similarity index 99% rename from mifosng-data/src/main/java/org/mifosng/data/command/CalculateLoanScheduleCommand.java rename to mifosng-provider/src/main/java/org/mifosng/platform/api/commands/CalculateLoanScheduleCommand.java index 9b4c78f7e..187f8e584 100644 --- a/mifosng-data/src/main/java/org/mifosng/data/command/CalculateLoanScheduleCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/CalculateLoanScheduleCommand.java @@ -1,4 +1,4 @@ -package org.mifosng.data.command; +package org.mifosng.platform.api.commands; import java.math.BigDecimal; diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/ImportLoanCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ImportLoanCommand.java similarity index 91% rename from mifosng-data/src/main/java/org/mifosng/data/command/ImportLoanCommand.java rename to mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ImportLoanCommand.java index f6a075272..848aa75a9 100644 --- a/mifosng-data/src/main/java/org/mifosng/data/command/ImportLoanCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ImportLoanCommand.java @@ -1,10 +1,11 @@ -package org.mifosng.data.command; +package org.mifosng.platform.api.commands; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlRootElement; + @XmlRootElement public class ImportLoanCommand { diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/ImportLoanRepaymentsCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ImportLoanRepaymentsCommand.java similarity index 91% rename from mifosng-data/src/main/java/org/mifosng/data/command/ImportLoanRepaymentsCommand.java rename to mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ImportLoanRepaymentsCommand.java index 6f39b6e31..a202d1b2b 100644 --- a/mifosng-data/src/main/java/org/mifosng/data/command/ImportLoanRepaymentsCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ImportLoanRepaymentsCommand.java @@ -1,4 +1,4 @@ -package org.mifosng.data.command; +package org.mifosng.platform.api.commands; import java.util.ArrayList; import java.util.List; diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/LoanStateTransitionCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/LoanStateTransitionCommand.java similarity index 55% rename from mifosng-data/src/main/java/org/mifosng/data/command/LoanStateTransitionCommand.java rename to mifosng-provider/src/main/java/org/mifosng/platform/api/commands/LoanStateTransitionCommand.java index 3aa917617..3f8d22bd4 100644 --- a/mifosng-data/src/main/java/org/mifosng/data/command/LoanStateTransitionCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/LoanStateTransitionCommand.java @@ -1,4 +1,4 @@ -package org.mifosng.data.command; +package org.mifosng.platform.api.commands; import javax.xml.bind.annotation.XmlRootElement; @@ -12,19 +12,18 @@ public class LoanStateTransitionCommand { private Long loanId; private String dateFormat; - private String eventDateFormatted; - private LocalDate eventDate; - private String comment; + private String eventDate; + private LocalDate eventLocalDate; + private String note; protected LoanStateTransitionCommand() { // } - public LoanStateTransitionCommand(final Long loanId, final LocalDate eventDate, - final String comment) { + public LoanStateTransitionCommand(final Long loanId, final LocalDate eventDate, final String comment) { this.loanId = loanId; - this.eventDate = eventDate; - this.comment = comment; + this.eventLocalDate = eventDate; + this.note = comment; } public Long getLoanId() { @@ -35,22 +34,6 @@ public class LoanStateTransitionCommand { this.loanId = loanId; } - public String getComment() { - return this.comment; - } - - public void setComment(final String comment) { - this.comment = comment; - } - - public LocalDate getEventDate() { - return eventDate; - } - - public void setEventDate(LocalDate eventDate) { - this.eventDate = eventDate; - } - public String getDateFormat() { return dateFormat; } @@ -59,11 +42,27 @@ public class LoanStateTransitionCommand { this.dateFormat = dateFormat; } - public String getEventDateFormatted() { - return eventDateFormatted; + public String getEventDate() { + return eventDate; } - public void setEventDateFormatted(String eventDateFormatted) { - this.eventDateFormatted = eventDateFormatted; + public void setEventDate(String eventDate) { + this.eventDate = eventDate; + } + + public LocalDate getEventLocalDate() { + return eventLocalDate; + } + + public void setEventLocalDate(LocalDate eventLocalDate) { + this.eventLocalDate = eventLocalDate; + } + + public String getNote() { + return note; + } + + public void setNote(String note) { + this.note = note; } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/LoanTransactionCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/LoanTransactionCommand.java new file mode 100644 index 000000000..c3d569c07 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/LoanTransactionCommand.java @@ -0,0 +1,97 @@ +package org.mifosng.platform.api.commands; + +import java.math.BigDecimal; + +import javax.xml.bind.annotation.XmlRootElement; + +import org.joda.time.LocalDate; + +@XmlRootElement +public class LoanTransactionCommand { + + private Long loanId; + private String locale; + private String dateFormat; + private String transactionDate; + private LocalDate transactionLocalDate; + private String note; + private String transactionAmount; + private BigDecimal transactionAmountValue; + + protected LoanTransactionCommand() { + // + } + + public LoanTransactionCommand(final Long loanId, + final LocalDate paymentDate, final String note, + final BigDecimal paymentAmount) { + this.loanId = loanId; + this.transactionLocalDate = paymentDate; + this.note = note; + this.transactionAmountValue = paymentAmount; + } + + public Long getLoanId() { + return this.loanId; + } + + public void setLoanId(final Long loanId) { + this.loanId = loanId; + } + + public String getDateFormat() { + return dateFormat; + } + + public void setDateFormat(String dateFormat) { + this.dateFormat = dateFormat; + } + + public String getTransactionDate() { + return transactionDate; + } + + public void setTransactionDate(String transactionDate) { + this.transactionDate = transactionDate; + } + + public LocalDate getTransactionLocalDate() { + return transactionLocalDate; + } + + public void setTransactionLocalDate(LocalDate transactionLocalDate) { + this.transactionLocalDate = transactionLocalDate; + } + + public String getNote() { + return note; + } + + public void setNote(String note) { + this.note = note; + } + + public String getTransactionAmount() { + return transactionAmount; + } + + public void setTransactionAmount(String transactionAmount) { + this.transactionAmount = transactionAmount; + } + + public BigDecimal getTransactionAmountValue() { + return transactionAmountValue; + } + + public void setTransactionAmountValue(BigDecimal transactionAmountValue) { + this.transactionAmountValue = transactionAmountValue; + } + + public String getLocale() { + return locale; + } + + public void setLocale(String locale) { + this.locale = locale; + } +} \ No newline at end of file diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/NoteCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/NoteCommand.java similarity index 95% rename from mifosng-data/src/main/java/org/mifosng/data/command/NoteCommand.java rename to mifosng-provider/src/main/java/org/mifosng/platform/api/commands/NoteCommand.java index d4b81f728..0ad551cf5 100644 --- a/mifosng-data/src/main/java/org/mifosng/data/command/NoteCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/NoteCommand.java @@ -1,4 +1,4 @@ -package org.mifosng.data.command; +package org.mifosng.platform.api.commands; import javax.xml.bind.annotation.XmlRootElement; diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/SubmitApproveDisburseLoanCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/SubmitApproveDisburseLoanCommand.java similarity index 96% rename from mifosng-data/src/main/java/org/mifosng/data/command/SubmitApproveDisburseLoanCommand.java rename to mifosng-provider/src/main/java/org/mifosng/platform/api/commands/SubmitApproveDisburseLoanCommand.java index 7f4cad475..5f7c5fc12 100644 --- a/mifosng-data/src/main/java/org/mifosng/data/command/SubmitApproveDisburseLoanCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/SubmitApproveDisburseLoanCommand.java @@ -1,7 +1,8 @@ -package org.mifosng.data.command; +package org.mifosng.platform.api.commands; import javax.xml.bind.annotation.XmlRootElement; + @XmlRootElement public class SubmitApproveDisburseLoanCommand { diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/SubmitLoanApplicationCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/SubmitLoanApplicationCommand.java similarity index 99% rename from mifosng-data/src/main/java/org/mifosng/data/command/SubmitLoanApplicationCommand.java rename to mifosng-provider/src/main/java/org/mifosng/platform/api/commands/SubmitLoanApplicationCommand.java index 64205f24a..6665459ae 100644 --- a/mifosng-data/src/main/java/org/mifosng/data/command/SubmitLoanApplicationCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/SubmitLoanApplicationCommand.java @@ -1,4 +1,4 @@ -package org.mifosng.data.command; +package org.mifosng.platform.api.commands; import java.math.BigDecimal; diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/UndoStateTransitionCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/UndoStateTransitionCommand.java similarity index 61% rename from mifosng-data/src/main/java/org/mifosng/data/command/UndoStateTransitionCommand.java rename to mifosng-provider/src/main/java/org/mifosng/platform/api/commands/UndoStateTransitionCommand.java index 7e97a2c30..dec3703b1 100644 --- a/mifosng-data/src/main/java/org/mifosng/data/command/UndoStateTransitionCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/UndoStateTransitionCommand.java @@ -1,18 +1,17 @@ -package org.mifosng.data.command; - +package org.mifosng.platform.api.commands; public class UndoStateTransitionCommand { private Long loanId; - private String comment; + private String note; protected UndoStateTransitionCommand() { // } - public UndoStateTransitionCommand(final Long loanId, final String comment) { + public UndoStateTransitionCommand(final Long loanId, final String note) { this.loanId = loanId; - this.comment = comment; + this.note = note; } public Long getLoanId() { @@ -23,11 +22,11 @@ public class UndoStateTransitionCommand { this.loanId = loanId; } - public String getComment() { - return comment; + public String getNote() { + return note; } - public void setComment(String comment) { - this.comment = comment; + public void setNote(String note) { + this.note = note; } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformService.java index 832df6489..76a527a4a 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformService.java @@ -1,8 +1,8 @@ package org.mifosng.platform.client.service; import org.mifosng.data.EntityIdentifier; -import org.mifosng.data.command.NoteCommand; import org.mifosng.platform.api.commands.ClientCommand; +import org.mifosng.platform.api.commands.NoteCommand; import org.springframework.security.access.prepost.PreAuthorize; public interface ClientWritePlatformService { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java index fc82c2d25..25909f335 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java @@ -6,8 +6,8 @@ import static org.mifosng.platform.Specifications.officesThatMatch; import org.apache.commons.lang.StringUtils; import org.mifosng.data.EntityIdentifier; -import org.mifosng.data.command.NoteCommand; import org.mifosng.platform.api.commands.ClientCommand; +import org.mifosng.platform.api.commands.NoteCommand; import org.mifosng.platform.client.domain.Client; import org.mifosng.platform.client.domain.ClientRepository; import org.mifosng.platform.client.domain.Note; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/AdjustLoanTransactionCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/AdjustLoanTransactionCommandValidator.java index 50e06ae5e..576201613 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/AdjustLoanTransactionCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/AdjustLoanTransactionCommandValidator.java @@ -5,7 +5,7 @@ import java.util.List; import org.apache.commons.lang.StringUtils; import org.mifosng.data.ApiParameterError; -import org.mifosng.data.command.AdjustLoanTransactionCommand; +import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand; import org.mifosng.platform.exceptions.PlatformApiDataValidationException; public class AdjustLoanTransactionCommandValidator { @@ -19,8 +19,8 @@ public class AdjustLoanTransactionCommandValidator { public void validate() { List dataValidationErrors = new ArrayList(); - if (command.getRepaymentId() == null || command.getRepaymentId().longValue() <= 0) { - ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.id.is.invalid", "The parameter repaymentId is invalid.", "repaymentId", command.getRepaymentId()); + if (command.getTransactionId() == null || command.getTransactionId().longValue() <= 0) { + ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.id.is.invalid", "The parameter repaymentId is invalid.", "transactionId", command.getTransactionId()); dataValidationErrors.add(error); } @@ -29,18 +29,18 @@ public class AdjustLoanTransactionCommandValidator { dataValidationErrors.add(error); } - if (command.getTransactionDate() == null) { - ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.repayment.date.cannot.be.blank", "The parameter transactionDateFormatted cannot be blank.", "transactionDateFormatted"); + if (command.getTransactionLocalDate() == null) { + ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.repayment.date.cannot.be.blank", "The parameter transactionDate cannot be blank.", "transactionDate"); dataValidationErrors.add(error); } - if (command.getTransactionAmount() == null || command.getTransactionAmount().doubleValue() <= 0) { - ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.repayment.must.be.greater.than.zero", "The parameter transactionAmountFormatted less than zero.", "transactionAmountFormatted", command.getTransactionAmountFormatted()); + if (command.getTransactionAmountValue() == null || command.getTransactionAmountValue().doubleValue() <= 0) { + ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.repayment.must.be.greater.than.zero", "The parameter transactionAmount less than zero.", "transactionAmount", command.getTransactionAmountValue()); dataValidationErrors.add(error); } - if (StringUtils.isNotBlank(command.getComment()) && command.getComment().length() > 1000) { - ApiParameterError error = ApiParameterError.parameterError("validation.msg.note.exceeds.max.length", "The parameter comment exceeds max allowed size of {0}", "comment", 1000); + if (StringUtils.isNotBlank(command.getNote()) && command.getNote().length() > 1000) { + ApiParameterError error = ApiParameterError.parameterError("validation.msg.note.exceeds.max.length", "The parameter note exceeds max allowed size of {0}", "note", 1000); dataValidationErrors.add(error); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculateLoanScheduleCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculateLoanScheduleCommandValidator.java index bce7f6119..e3cf97cca 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculateLoanScheduleCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculateLoanScheduleCommandValidator.java @@ -4,8 +4,8 @@ import java.util.ArrayList; import java.util.List; import org.mifosng.data.ApiParameterError; -import org.mifosng.data.command.CalculateLoanScheduleCommand; import org.mifosng.platform.DataValidatorBuilder; +import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand; import org.mifosng.platform.exceptions.PlatformApiDataValidationException; public class CalculateLoanScheduleCommandValidator { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculationPlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculationPlatformService.java index 586937640..d231030a2 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculationPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculationPlatformService.java @@ -3,7 +3,7 @@ package org.mifosng.platform.loan.service; import org.joda.time.LocalDate; import org.mifosng.data.LoanPayoffReadModel; import org.mifosng.data.LoanSchedule; -import org.mifosng.data.command.CalculateLoanScheduleCommand; +import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand; public interface CalculationPlatformService { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculationPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculationPlatformServiceImpl.java index 1a5c70820..0058a4ffb 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculationPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculationPlatformServiceImpl.java @@ -7,7 +7,7 @@ import org.mifosng.data.CurrencyData; import org.mifosng.data.LoanPayoffReadModel; import org.mifosng.data.LoanSchedule; import org.mifosng.data.MoneyData; -import org.mifosng.data.command.CalculateLoanScheduleCommand; +import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand; import org.mifosng.platform.currency.domain.ApplicationCurrency; import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository; import org.mifosng.platform.currency.domain.MonetaryCurrency; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanAssembler.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanAssembler.java index dd2032c1a..bbb5043b7 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanAssembler.java @@ -9,7 +9,7 @@ import java.util.List; import org.mifosng.data.LoanSchedule; import org.mifosng.data.MoneyData; import org.mifosng.data.ScheduledLoanInstallment; -import org.mifosng.data.command.SubmitLoanApplicationCommand; +import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand; import org.mifosng.platform.client.domain.Client; import org.mifosng.platform.client.domain.ClientRepository; import org.mifosng.platform.currency.domain.MonetaryCurrency; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformService.java index 253db403b..a960940f6 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformService.java @@ -14,5 +14,5 @@ public interface LoanReadPlatformService { LoanRepaymentData retrieveNewLoanWaiverDetails(Long loanId); - LoanRepaymentData retrieveLoanRepaymentDetails(Long loanId, Long repaymentId); + LoanRepaymentData retrieveLoanRepaymentDetails(Long loanId, Long transactionId); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java index 6ccd8d4f5..3b5e81e15 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java @@ -36,7 +36,6 @@ import org.springframework.stereotype.Service; @Service public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { -// private final SimpleJdbcTemplate jdbcTemplate; private final PlatformSecurityContext context; private final LoanRepository loanRepository; private final ApplicationCurrencyRepository applicationCurrencyRepository; @@ -46,7 +45,6 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { @Autowired public LoanReadPlatformServiceImpl(final PlatformSecurityContext context, -// final DataSource dataSource, final LoanRepository loanRepository, final LoanTransactionRepository loanTransactionRepository, final ApplicationCurrencyRepository applicationCurrencyRepository, final LoanProductReadPlatformService loanProductReadPlatformService, final ClientReadPlatformService clientReadPlatformService) { this.context = context; @@ -55,7 +53,6 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { this.applicationCurrencyRepository = applicationCurrencyRepository; this.loanProductReadPlatformService = loanProductReadPlatformService; this.clientReadPlatformService = clientReadPlatformService; -// this.jdbcTemplate = new SimpleJdbcTemplate(dataSource); } @Override @@ -264,8 +261,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { // TODO - OPTIMIZE - write simple sql query to fetch back date of // possible next transaction date. - Loan loan = this.loanRepository.findOne(loansThatMatch( - currentUser.getOrganisation(), loanId)); + Loan loan = this.loanRepository.findOne(loansThatMatch(currentUser.getOrganisation(), loanId)); if (loan == null) { throw new LoanNotFoundException(loanId); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanStateTransitionCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanStateTransitionCommandValidator.java index eae9798c8..4920e2eab 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanStateTransitionCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanStateTransitionCommandValidator.java @@ -3,9 +3,9 @@ package org.mifosng.platform.loan.service; import java.util.ArrayList; import java.util.List; -import org.apache.commons.lang.StringUtils; import org.mifosng.data.ApiParameterError; -import org.mifosng.data.command.LoanStateTransitionCommand; +import org.mifosng.platform.DataValidatorBuilder; +import org.mifosng.platform.api.commands.LoanStateTransitionCommand; import org.mifosng.platform.exceptions.PlatformApiDataValidationException; public class LoanStateTransitionCommandValidator { @@ -19,20 +19,11 @@ public class LoanStateTransitionCommandValidator { public void validate() { List dataValidationErrors = new ArrayList(); - if (command.getLoanId() == null) { - ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.id.is.invalid", "The parameter loanId is invalid.", "loanId", command.getLoanId()); - dataValidationErrors.add(error); - } + DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transition"); - if (command.getEventDate() == null) { - ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.state.transition.date.cannot.be.blank", "The parameter eventDate cannot be blank.", "eventDate"); - dataValidationErrors.add(error); - } - - if (StringUtils.isNotBlank(command.getComment()) && command.getComment().length() > 1000) { - ApiParameterError error = ApiParameterError.parameterError("validation.msg.note.exceeds.max.length", "The parameter comment exceeds mas allowed length of {0}.", "comment"); - dataValidationErrors.add(error); - } + baseDataValidator.reset().parameter("loanId").value(command.getLoanId()).notNull(); + baseDataValidator.reset().parameter("eventDate").value(command.getEventLocalDate()).notNull(); + baseDataValidator.reset().parameter("note").value(command.getNote()).notExceedingLengthOf(1000); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanTransactionCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanTransactionCommandValidator.java index 8ce84bf3b..67547122f 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanTransactionCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanTransactionCommandValidator.java @@ -5,7 +5,7 @@ import java.util.List; import org.apache.commons.lang.StringUtils; import org.mifosng.data.ApiParameterError; -import org.mifosng.data.command.LoanTransactionCommand; +import org.mifosng.platform.api.commands.LoanTransactionCommand; import org.mifosng.platform.exceptions.PlatformApiDataValidationException; public class LoanTransactionCommandValidator { @@ -24,17 +24,17 @@ public class LoanTransactionCommandValidator { dataValidationErrors.add(error); } - if (command.getTransactionDate() == null) { + if (command.getTransactionLocalDate() == null) { ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.repayment.date.cannot.be.blank", "The parameter transactionDateFormatted cannot be blank.", "transactionDateFormatted"); dataValidationErrors.add(error); } - if (command.getTransactionAmount() == null || command.getTransactionAmount().doubleValue() <= 0) { - ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.repayment.must.be.greater.than.zero", "The parameter transactionAmountFormatted less than zero.", "transactionAmountFormatted", command.getTransactionAmountFormatted()); + if (command.getTransactionAmount() == null || command.getTransactionAmountValue().doubleValue() <= 0) { + ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.repayment.must.be.greater.than.zero", "The parameter transactionAmountFormatted less than zero.", "transactionAmountFormatted", command.getTransactionAmountValue()); dataValidationErrors.add(error); } - if (StringUtils.isNotBlank(command.getComment()) && command.getComment().length() > 1000) { + if (StringUtils.isNotBlank(command.getNote()) && command.getNote().length() > 1000) { ApiParameterError error = ApiParameterError.parameterError("validation.msg.note.exceeds.max.length", "The parameter comment exceeds max allowed size of {0}", "comment", 1000); dataValidationErrors.add(error); } @@ -43,5 +43,4 @@ public class LoanTransactionCommandValidator { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } } - -} +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformService.java index a0225dfbb..9bac31baf 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformService.java @@ -1,11 +1,11 @@ package org.mifosng.platform.loan.service; import org.mifosng.data.EntityIdentifier; -import org.mifosng.data.command.AdjustLoanTransactionCommand; -import org.mifosng.data.command.LoanStateTransitionCommand; -import org.mifosng.data.command.LoanTransactionCommand; -import org.mifosng.data.command.SubmitLoanApplicationCommand; -import org.mifosng.data.command.UndoStateTransitionCommand; +import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand; +import org.mifosng.platform.api.commands.LoanStateTransitionCommand; +import org.mifosng.platform.api.commands.LoanTransactionCommand; +import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand; +import org.mifosng.platform.api.commands.UndoStateTransitionCommand; import org.springframework.security.access.prepost.PreAuthorize; public interface LoanWritePlatformService { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformServiceJpaRepositoryImpl.java index 86bc30181..c82085dc9 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -10,17 +10,18 @@ import org.joda.time.LocalDate; import org.mifosng.data.EntityIdentifier; import org.mifosng.data.LoanSchedule; import org.mifosng.data.ScheduledLoanInstallment; -import org.mifosng.data.command.AdjustLoanTransactionCommand; -import org.mifosng.data.command.CalculateLoanScheduleCommand; -import org.mifosng.data.command.LoanStateTransitionCommand; -import org.mifosng.data.command.LoanTransactionCommand; -import org.mifosng.data.command.SubmitLoanApplicationCommand; -import org.mifosng.data.command.UndoStateTransitionCommand; +import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand; +import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand; +import org.mifosng.platform.api.commands.LoanStateTransitionCommand; +import org.mifosng.platform.api.commands.LoanTransactionCommand; +import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand; +import org.mifosng.platform.api.commands.UndoStateTransitionCommand; import org.mifosng.platform.client.domain.Note; import org.mifosng.platform.client.domain.NoteRepository; import org.mifosng.platform.currency.domain.MonetaryCurrency; import org.mifosng.platform.currency.domain.Money; import org.mifosng.platform.exceptions.LoanNotFoundException; +import org.mifosng.platform.exceptions.LoanTransactionNotFoundException; import org.mifosng.platform.exceptions.NoAuthorizationException; import org.mifosng.platform.exceptions.PlatformDomainRuleException; import org.mifosng.platform.loan.domain.DefaultLoanLifecycleStateMachine; @@ -138,16 +139,18 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf if (loan == null) { throw new LoanNotFoundException(command.getLoanId()); } - - if (this.isBeforeToday(command.getEventDate()) && currentUser.canNotApproveLoanInPast()) { + + LocalDate eventDate = command.getEventLocalDate(); + if (this.isBeforeToday(eventDate) && currentUser.canNotApproveLoanInPast()) { throw new NoAuthorizationException("User has no authority to approve loan with a date in the past."); } - loan.approve(command.getEventDate(), defaultLoanLifecycleStateMachine()); + loan.approve(eventDate, defaultLoanLifecycleStateMachine()); this.loanRepository.save(loan); - if (StringUtils.isNotBlank(command.getComment())) { - Note note = Note.loanNote(currentUser.getOrganisation(), loan, command.getComment()); + String noteText = command.getNote(); + if (StringUtils.isNotBlank(noteText)) { + Note note = Note.loanNote(currentUser.getOrganisation(), loan, noteText); this.noteRepository.save(note); } @@ -168,8 +171,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf loan.undoApproval(defaultLoanLifecycleStateMachine()); this.loanRepository.save(loan); - if (StringUtils.isNotBlank(command.getComment())) { - Note note = Note.loanNote(currentUser.getOrganisation(), loan, command.getComment()); + String noteText = command.getNote(); + if (StringUtils.isNotBlank(noteText)) { + Note note = Note.loanNote(currentUser.getOrganisation(), loan, noteText); this.noteRepository.save(note); } @@ -190,15 +194,17 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf throw new LoanNotFoundException(command.getLoanId()); } - if (this.isBeforeToday(command.getEventDate()) && currentUser.canNotRejectLoanInPast()) { + LocalDate eventDate = command.getEventLocalDate(); + if (this.isBeforeToday(eventDate) && currentUser.canNotRejectLoanInPast()) { throw new NoAuthorizationException("User has no authority to reject loan with a date in the past."); } - loan.reject(command.getEventDate(), defaultLoanLifecycleStateMachine()); + loan.reject(eventDate, defaultLoanLifecycleStateMachine()); this.loanRepository.save(loan); - if (StringUtils.isNotBlank(command.getComment())) { - Note note = Note.loanNote(currentUser.getOrganisation(), loan, command.getComment()); + String noteText = command.getNote(); + if (StringUtils.isNotBlank(noteText)) { + Note note = Note.loanNote(currentUser.getOrganisation(), loan, noteText); this.noteRepository.save(note); } @@ -219,15 +225,17 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf throw new LoanNotFoundException(command.getLoanId()); } - if (this.isBeforeToday(command.getEventDate()) && currentUser.canNotWithdrawByClientLoanInPast()) { + LocalDate eventDate = command.getEventLocalDate(); + if (this.isBeforeToday(eventDate) && currentUser.canNotWithdrawByClientLoanInPast()) { throw new NoAuthorizationException("User has no authority to mark loan as withdrawn by client with a date in the past."); } - loan.withdraw(command.getEventDate(), defaultLoanLifecycleStateMachine()); + loan.withdraw(eventDate, defaultLoanLifecycleStateMachine()); this.loanRepository.save(loan); - if (StringUtils.isNotBlank(command.getComment())) { - Note note = Note.loanNote(currentUser.getOrganisation(), loan, command.getComment()); + String noteText = command.getNote(); + if (StringUtils.isNotBlank(noteText)) { + Note note = Note.loanNote(currentUser.getOrganisation(), loan, noteText); this.noteRepository.save(note); } @@ -248,15 +256,12 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf throw new LoanNotFoundException(command.getLoanId()); } - if (this.isBeforeToday(command.getEventDate()) && currentUser.canNotDisburseLoanInPast()) { + String noteText = command.getNote(); + LocalDate actualDisbursementDate = command.getEventLocalDate(); + if (this.isBeforeToday(actualDisbursementDate) && currentUser.canNotDisburseLoanInPast()) { throw new NoAuthorizationException("User has no authority to disburse loan with a date in the past."); } - LocalDate disbursedOn = command.getEventDate(); - String comment = command.getComment(); - - LocalDate actualDisbursementDate = new LocalDate(disbursedOn); - if (loan.isRepaymentScheduleRegenerationRequiredForDisbursement(actualDisbursementDate)) { LocalDate repaymentsStartingFromDate = loan.getExpectedFirstRepaymentOnDate(); @@ -309,15 +314,15 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf interest.getAmount()); modifiedLoanRepaymentSchedule.add(installment); } - loan.disburseWithModifiedRepaymentSchedule(disbursedOn, comment, modifiedLoanRepaymentSchedule, defaultLoanLifecycleStateMachine()); + loan.disburseWithModifiedRepaymentSchedule(actualDisbursementDate, noteText, modifiedLoanRepaymentSchedule, defaultLoanLifecycleStateMachine()); } else { - loan.disburse(disbursedOn, defaultLoanLifecycleStateMachine()); + loan.disburse(actualDisbursementDate, defaultLoanLifecycleStateMachine()); } this.loanRepository.save(loan); - if (StringUtils.isNotBlank(command.getComment())) { - Note note = Note.loanNote(currentUser.getOrganisation(), loan, command.getComment()); + if (StringUtils.isNotBlank(noteText)) { + Note note = Note.loanNote(currentUser.getOrganisation(), loan, noteText); this.noteRepository.save(note); } @@ -343,8 +348,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf this.loanRepository.save(loan); - if (StringUtils.isNotBlank(command.getComment())) { - Note note = Note.loanNote(currentUser.getOrganisation(), loan, command.getComment()); + String noteText = command.getNote(); + if (StringUtils.isNotBlank(noteText)) { + Note note = Note.loanNote(currentUser.getOrganisation(), loan, noteText); this.noteRepository.save(note); } @@ -365,21 +371,23 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf throw new LoanNotFoundException(command.getLoanId()); } - if (this.isBeforeToday(command.getTransactionDate()) && currentUser.canNotMakeRepaymentOnLoanInPast()) { + LocalDate transactionDate = command.getTransactionLocalDate(); + if (this.isBeforeToday(transactionDate) && currentUser.canNotMakeRepaymentOnLoanInPast()) { throw new NoAuthorizationException("error.msg.no.permission.to.make.repayment.on.loan.in.past"); } Money repayment = Money.of(loan.getLoanRepaymentScheduleDetail() .getPrincipal().getCurrency(), - command.getTransactionAmount()); + command.getTransactionAmountValue()); - LoanTransaction loanRepayment = LoanTransaction.repayment(repayment, command.getTransactionDate()); + LoanTransaction loanRepayment = LoanTransaction.repayment(repayment, transactionDate); loan.makeRepayment(loanRepayment, defaultLoanLifecycleStateMachine()); this.loanTransactionRepository.save(loanRepayment); this.loanRepository.save(loan); - if (StringUtils.isNotBlank(command.getComment())) { - Note note = Note.loanTransactionNote(currentUser.getOrganisation(), loan, loanRepayment, command.getComment()); + String noteText = command.getNote(); + if (StringUtils.isNotBlank(noteText)) { + Note note = Note.loanTransactionNote(currentUser.getOrganisation(), loan, loanRepayment, noteText); this.noteRepository.save(note); } @@ -400,17 +408,20 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf throw new LoanNotFoundException(command.getLoanId()); } - LoanTransaction transactionToAdjust = this.loanTransactionRepository - .findOne(command.getRepaymentId()); - + LoanTransaction transactionToAdjust = this.loanTransactionRepository.findOne(command.getTransactionId()); + if (transactionToAdjust == null) { + throw new LoanTransactionNotFoundException(command.getTransactionId()); + } + Money transactionAmount = Money.of(loan .getLoanRepaymentScheduleDetail().getPrincipal() - .getCurrency(), command.getTransactionAmount()); + .getCurrency(), command.getTransactionAmountValue()); // adjustment is only supported for repayments and waivers at present - LoanTransaction newTransactionDetail = LoanTransaction.repayment(transactionAmount, command.getTransactionDate()); + LocalDate transactionDate = command.getTransactionLocalDate(); + LoanTransaction newTransactionDetail = LoanTransaction.repayment(transactionAmount, transactionDate); if (transactionToAdjust.isWaiver()) { - newTransactionDetail = LoanTransaction.waiver(transactionAmount, command.getTransactionDate()); + newTransactionDetail = LoanTransaction.waiver(transactionAmount, transactionDate); } loan.adjustExistingTransaction(transactionToAdjust, newTransactionDetail, defaultLoanLifecycleStateMachine()); @@ -419,9 +430,10 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf this.loanRepository.save(loan); - if (StringUtils.isNotBlank(command.getComment())) { + String noteText = command.getNote(); + if (StringUtils.isNotBlank(noteText)) { Note note = Note.loanTransactionNote(currentUser.getOrganisation(), - loan, newTransactionDetail, command.getComment()); + loan, newTransactionDetail, noteText); this.noteRepository.save(note); } @@ -444,9 +456,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf Money waived = Money.of(loan.getLoanRepaymentScheduleDetail() .getPrincipal().getCurrency(), - command.getTransactionAmount()); + command.getTransactionAmountValue()); - LoanTransaction waiver = LoanTransaction.waiver(waived, command.getTransactionDate()); + LoanTransaction waiver = LoanTransaction.waiver(waived, command.getTransactionLocalDate()); loan.waive(waiver, defaultLoanLifecycleStateMachine()); @@ -454,8 +466,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf this.loanRepository.save(loan); - if (StringUtils.isNotBlank(command.getComment())) { - Note note = Note.loanTransactionNote(currentUser.getOrganisation(), loan, waiver, command.getComment()); + String noteText = command.getNote(); + if (StringUtils.isNotBlank(noteText)) { + Note note = Note.loanTransactionNote(currentUser.getOrganisation(), loan, waiver, noteText); this.noteRepository.save(note); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/SubmitLoanApplicationCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/SubmitLoanApplicationCommandValidator.java index a72aa1046..fdfd4c1c4 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/SubmitLoanApplicationCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/SubmitLoanApplicationCommandValidator.java @@ -4,8 +4,8 @@ import java.util.ArrayList; import java.util.List; import org.mifosng.data.ApiParameterError; -import org.mifosng.data.command.CalculateLoanScheduleCommand; -import org.mifosng.data.command.SubmitLoanApplicationCommand; +import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand; +import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand; import org.mifosng.platform.exceptions.PlatformApiDataValidationException; public class SubmitLoanApplicationCommandValidator { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportResource.java index db30e3aec..8a49674a3 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportResource.java @@ -7,10 +7,10 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.mifosng.data.command.ImportLoanCommand; -import org.mifosng.data.command.ImportLoanRepaymentsCommand; import org.mifosng.platform.ImportPlatformService; import org.mifosng.platform.api.commands.ImportClientCommand; +import org.mifosng.platform.api.commands.ImportLoanCommand; +import org.mifosng.platform.api.commands.ImportLoanRepaymentsCommand; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportTriggerResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportTriggerResource.java index 531026ffa..8a1efa225 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportTriggerResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportTriggerResource.java @@ -7,10 +7,10 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.mifosng.data.command.ImportLoanCommand; -import org.mifosng.data.command.ImportLoanRepaymentsCommand; import org.mifosng.platform.ImportPlatformService; import org.mifosng.platform.api.commands.ImportClientCommand; +import org.mifosng.platform.api.commands.ImportLoanCommand; +import org.mifosng.platform.api.commands.ImportLoanRepaymentsCommand; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component;