update state transition and transaction api for loans.

This commit is contained in:
Keith Woodlock
2012-05-29 22:29:21 +01:00
parent d92a2b1f25
commit 92b3ed4030
34 changed files with 448 additions and 435 deletions
@@ -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;
}
}
@@ -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;
}
}
@@ -139,9 +139,9 @@ $(document).ready(function() {
removeErrors(placeholderDiv); removeErrors(placeholderDiv);
var jsonErrors = JSON.parse(jqXHR.responseText); var jsonErrors = JSON.parse(jqXHR.responseText);
console.log(jsonErrors);
var valErrors = jsonErrors.errors; var valErrors = jsonErrors.errors;
console.log(valErrors);
var errorArray = new Array(); var errorArray = new Array();
var arrayIndex = 0; var arrayIndex = 0;
$.each(valErrors, function() { $.each(valErrors, function() {
@@ -158,7 +158,7 @@ $(document).ready(function() {
argArray[argArrayIndex] = this.value; argArray[argArrayIndex] = this.value;
argArrayIndex++; argArrayIndex++;
}); });
console.log(argArray);
// hardcoded support for six arguments // 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.message = jQuery.i18n.prop(this.userMessageGlobalisationCode, argArray[0], argArray[1], argArray[2], argArray[3], argArray[4], argArray[5]);
errorObj.value = this.value; errorObj.value = this.value;
@@ -292,7 +292,6 @@ $(document).ready(function() {
}); });
var newFormData = JSON.stringify($('#entityform').serializeObject()); var newFormData = JSON.stringify($('#entityform').serializeObject());
console.log(newFormData);
var jqxhr = $.ajax({ var jqxhr = $.ajax({
url: postUrl, url: postUrl,
@@ -302,7 +301,6 @@ $(document).ready(function() {
cache: false, cache: false,
data: newFormData, data: newFormData,
beforeSend: function(xhr) { beforeSend: function(xhr) {
console.log("base64: " + base64);
xhr.setRequestHeader("Authorization", "Basic " + base64); xhr.setRequestHeader("Authorization", "Basic " + base64);
}, },
success: function(data, textStatus, jqXHR) { success: function(data, textStatus, jqXHR) {
@@ -377,7 +375,6 @@ $(document).ready(function() {
}); });
var newFormData = JSON.stringify($('#entityform').serializeObject()); var newFormData = JSON.stringify($('#entityform').serializeObject());
console.log(newFormData);
var jqxhr = $.ajax({ var jqxhr = $.ajax({
url: postUrl, url: postUrl,
@@ -435,8 +432,6 @@ $(document).ready(function() {
var $newtabs = $("#newtabs").tabs({ var $newtabs = $("#newtabs").tabs({
"add": function( event, ui ) { "add": function( event, ui ) {
console.log(ui);
//alert("adding new tab: " + ui.panel.id + " :" + ui.tab.className);
$newtabs.tabs('select', '#' + ui.panel.id); $newtabs.tabs('select', '#' + ui.panel.id);
}, },
"ajaxOptions": { "ajaxOptions": {
@@ -445,7 +440,6 @@ $(document).ready(function() {
contentType: 'application/json', contentType: 'application/json',
cache: false, cache: false,
beforeSend: function(xhr) { beforeSend: function(xhr) {
console.log("base64: " + base64);
xhr.setRequestHeader("Authorization", "Basic " + base64); xhr.setRequestHeader("Authorization", "Basic " + base64);
}, },
error: function(jqXHR, status, errorThrown, index, anchor) { error: function(jqXHR, status, errorThrown, index, anchor) {
@@ -455,12 +449,8 @@ $(document).ready(function() {
}, },
success: function(data, status, xhr) { success: function(data, status, xhr) {
console.log(data);
var currentTabIndex = $newtabs.tabs('option', 'selected'); var currentTabIndex = $newtabs.tabs('option', 'selected');
var currentTabAnchor = $newtabs.data('tabs').anchors[currentTabIndex]; var currentTabAnchor = $newtabs.data('tabs').anchors[currentTabIndex];
//$(currentTabAnchor).data('cache.tabs', true)
//alert('tab: ' + currentTabIndex + ' - id: ' + currentTabAnchor);
var offsetToSubmittedDate = 0; var offsetToSubmittedDate = 0;
var offsetToApprovalDate = 0; var offsetToApprovalDate = 0;
@@ -468,7 +458,6 @@ $(document).ready(function() {
var maxOffset = 0; // today var maxOffset = 0; // today
if (currentTabIndex < 1) { if (currentTabIndex < 1) {
console.log("success: client tab.");
var tableHtml = $("#clientDataTabTemplate").render(data); var tableHtml = $("#clientDataTabTemplate").render(data);
$("#clienttab").html(tableHtml); $("#clienttab").html(tableHtml);
@@ -653,8 +642,8 @@ $(document).ready(function() {
var linkId = this.id; var linkId = this.id;
var loanId = linkId.replace("repaymentbtn", ""); var loanId = linkId.replace("repaymentbtn", "");
var getUrl = baseApiUrl + 'loans/' + loanId + '/transactions/template?transactionType=repayment'; var getUrl = baseApiUrl + 'loans/' + loanId + '/transactions/template?command=repayment';
var postUrl = baseApiUrl + 'loans/' + loanId + '/transactions?transactionType=repayment'; var postUrl = baseApiUrl + 'loans/' + loanId + '/transactions?command=repayment';
var templateSelector = "#transactionLoanFormTemplate"; var templateSelector = "#transactionLoanFormTemplate";
var width = 500; var width = 500;
@@ -676,8 +665,8 @@ $(document).ready(function() {
var linkId = this.id; var linkId = this.id;
var loanId = linkId.replace("waivebtn", ""); var loanId = linkId.replace("waivebtn", "");
var getUrl = baseApiUrl + 'loans/' + loanId + '/transactions/template?transactionType=waiver'; var getUrl = baseApiUrl + 'loans/' + loanId + '/transactions/template?command=waiver';
var postUrl = baseApiUrl + 'loans/' + loanId + '/transactions?transactionType=waiver'; var postUrl = baseApiUrl + 'loans/' + loanId + '/transactions?command=waiver';
var templateSelector = "#transactionLoanFormTemplate"; var templateSelector = "#transactionLoanFormTemplate";
var width = 500; 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, saveSuccessFunction);
//popupDialogWithFormView(getUrl, postUrl, 'POST', 'dialog.title.waive.loan', templateSelector, width, height, currentTabIndex, offsetToSubmittedDate, defaultOffset, maxOffset)
e.preventDefault(); e.preventDefault();
}); });
$('button.waiveloan span').text(jQuery.i18n.prop('dialog.button.loan.waive')); $('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, saveSuccessFunction);
// popupDialogWithFormView(getAndPutUrl, getAndPutUrl, 'PUT', 'dialog.title.adjust.loan.repayment', templateSelector, width, height, currentTabIndex, offsetToSubmittedDate, defaultOffset, maxOffset)
e.preventDefault(); e.preventDefault();
}); });
$('button.adjustloanrepayment span').text(jQuery.i18n.prop('dialog.button.adjust.loan.repayment')); $('button.adjustloanrepayment span').text(jQuery.i18n.prop('dialog.button.adjust.loan.repayment'));
@@ -748,11 +735,9 @@ $(document).ready(function() {
dataType: 'json', dataType: 'json',
cache: false, cache: false,
beforeSend: function(xhr) { beforeSend: function(xhr) {
console.log("base64: " + base64);
xhr.setRequestHeader("Authorization", "Basic " + base64); xhr.setRequestHeader("Authorization", "Basic " + base64);
}, },
success: function(data, textStatus, jqXHR) { success: function(data, textStatus, jqXHR) {
console.log(data);
var tableHtml = $("#clientAccountSummariesTemplate").render(data); var tableHtml = $("#clientAccountSummariesTemplate").render(data);
$("#clientaccountssummary").html(tableHtml); $("#clientaccountssummary").html(tableHtml);
@@ -786,8 +771,6 @@ $(document).ready(function() {
xhr.setRequestHeader("Authorization", "Basic " + base64); xhr.setRequestHeader("Authorization", "Basic " + base64);
}, },
success: function(data, textStatus, jqXHR) { success: function(data, textStatus, jqXHR) {
console.log(data);
var noteParent = new Object(); var noteParent = new Object();
noteParent.title = jQuery.i18n.prop('widget.notes.heading'); noteParent.title = jQuery.i18n.prop('widget.notes.heading');
noteParent.notes = data; noteParent.notes = data;
@@ -804,11 +804,11 @@
<div id="formerrors"></div> <div id="formerrors"></div>
<input type="hidden" id="dateFormat" name="dateFormat" value="dd MMMM yyyy" /> <input type="hidden" id="dateFormat" name="dateFormat" value="dd MMMM yyyy" />
<label for="eventDateFormatted"><spring:message code="label.loan.on"/></label> <label for="eventDate"><spring:message code="label.loan.on"/></label>
<input id="eventDateFormatted" name="eventDateFormatted" title="" class="datepickerfield" /> <input id="eventDate" name="eventDate" title="" class="datepickerfield" />
<label for="comment"><spring:message code="label.loan.action.note"/></label> <label for="note"><spring:message code="label.loan.action.note"/></label>
<textarea rows="3" cols="53" id="comment" name="comment"></textarea> <textarea rows="3" cols="53" id="note" name="note"></textarea>
</form> </form>
</script> </script>
@@ -816,8 +816,8 @@
<form id="entityform"> <form id="entityform">
<div id="formerrors"></div> <div id="formerrors"></div>
<label for="comment"><spring:message code="label.loan.action.note"/></label> <label for="note"><spring:message code="label.loan.action.note"/></label>
<textarea rows="6" cols="53" id="comment" name="comment"></textarea> <textarea rows="6" cols="53" id="note" name="note"></textarea>
</form> </form>
</script> </script>
@@ -826,14 +826,14 @@
<div id="formerrors"></div> <div id="formerrors"></div>
<input type="hidden" id="dateFormat" name="dateFormat" value="dd MMMM yyyy" /> <input type="hidden" id="dateFormat" name="dateFormat" value="dd MMMM yyyy" />
<label for="transactionDateFormatted"><spring:message code="label.loan.transaction.on"/></label> <label for="transactionDate"><spring:message code="label.loan.transaction.on"/></label>
<input id="transactionDateFormatted" name="transactionDateFormatted" cssClass="text ui-widget-content ui-corner-all" title="" class="datepickerfield" value="{{=$ctx.globalDate(date)}}"/> <input id="transactionDate" name="transactionDate" class="text ui-widget-content ui-corner-all" title="" class="datepickerfield" value="{{=$ctx.globalDate(date)}}"/>
<label for="transactionAmountFormatted"><spring:message code="label.loan.transaction.amount"/></label> <label for="transactionAmount"><spring:message code="label.loan.transaction.amount"/></label>
<input id="transactionAmountFormatted" name="transactionAmountFormatted" cssClass="text ui-widget-content ui-corner-all" title="" value="{{=$ctx.money(total)}}" /> <input id="transactionAmount" name="transactionAmount" class="text ui-widget-content ui-corner-all" title="" value="{{=$ctx.money(total)}}" />
<label for="comment"><spring:message code="label.loan.action.note"/></label> <label for="note"><spring:message code="label.loan.action.note"/></label>
<textarea rows="3" cols="53" id="comment" name="comment" cssClass="text ui-widget-content ui-corner-all"></textarea> <textarea rows="3" cols="53" id="note" name="note" class="text ui-widget-content ui-corner-all"></textarea>
</form> </form>
</script> </script>
@@ -1,8 +1,8 @@
package org.mifosng.platform; 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.ImportClientCommand;
import org.mifosng.platform.api.commands.ImportLoanCommand;
import org.mifosng.platform.api.commands.ImportLoanRepaymentsCommand;
public interface ImportPlatformService { public interface ImportPlatformService {
@@ -19,15 +19,15 @@ import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat; import org.joda.time.format.ISODateTimeFormat;
import org.mifosng.data.LoanSchedule; import org.mifosng.data.LoanSchedule;
import org.mifosng.data.command.CalculateLoanScheduleCommand; import org.mifosng.platform.api.commands.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.ClientCommand; import org.mifosng.platform.api.commands.ClientCommand;
import org.mifosng.platform.api.commands.ImportClientCommand; 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.Client;
import org.mifosng.platform.client.domain.ClientRepository; import org.mifosng.platform.client.domain.ClientRepository;
import org.mifosng.platform.currency.domain.Money; import org.mifosng.platform.currency.domain.Money;
@@ -140,12 +140,12 @@ public class ImportPlatformServiceImpl implements ImportPlatformService {
LoanStateTransitionCommand approveLoanCommand = combinedCommand.getApproveLoanCommand(); LoanStateTransitionCommand approveLoanCommand = combinedCommand.getApproveLoanCommand();
if (approveLoanCommand != null) { if (approveLoanCommand != null) {
loan.approve(approveLoanCommand.getEventDate(), loanLifecycleStateMachine); loan.approve(approveLoanCommand.getEventLocalDate(), loanLifecycleStateMachine);
} }
LoanStateTransitionCommand disburseLoanCommand = combinedCommand.getDisburseLoanCommand(); LoanStateTransitionCommand disburseLoanCommand = combinedCommand.getDisburseLoanCommand();
if (disburseLoanCommand != null) { if (disburseLoanCommand != null) {
loan.disburse(disburseLoanCommand.getEventDate(), loanLifecycleStateMachine); loan.disburse(disburseLoanCommand.getEventLocalDate(), loanLifecycleStateMachine);
} }
newLoanCollection.add(loan); newLoanCollection.add(loan);
@@ -173,9 +173,9 @@ public class ImportPlatformServiceImpl implements ImportPlatformService {
for (LoanTransactionCommand repaymentDetail : command.getRepayments()) { for (LoanTransactionCommand repaymentDetail : command.getRepayments()) {
Loan loan = findLoanByIdentifier(allLoans, repaymentDetail.getLoanId().toString()); 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); loan.makeRepayment(loanRepayment, loanLifecycleStateMachine);
} }
@@ -22,8 +22,8 @@ import org.mifosng.data.ClientLoanAccountSummaryCollectionData;
import org.mifosng.data.EntityIdentifier; import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.NoteData; import org.mifosng.data.NoteData;
import org.mifosng.data.OfficeLookup; import org.mifosng.data.OfficeLookup;
import org.mifosng.data.command.NoteCommand;
import org.mifosng.platform.api.commands.ClientCommand; 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.ApiDataConversionService;
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService; import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
import org.mifosng.platform.client.service.ClientReadPlatformService; import org.mifosng.platform.client.service.ClientReadPlatformService;
@@ -24,12 +24,12 @@ import org.mifosng.data.LoanAccountData;
import org.mifosng.data.LoanRepaymentData; import org.mifosng.data.LoanRepaymentData;
import org.mifosng.data.LoanSchedule; import org.mifosng.data.LoanSchedule;
import org.mifosng.data.NewLoanWorkflowStepOneData; import org.mifosng.data.NewLoanWorkflowStepOneData;
import org.mifosng.data.command.AdjustLoanTransactionCommand; import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand;
import org.mifosng.data.command.CalculateLoanScheduleCommand; import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand;
import org.mifosng.data.command.LoanStateTransitionCommand; import org.mifosng.platform.api.commands.LoanStateTransitionCommand;
import org.mifosng.data.command.LoanTransactionCommand; import org.mifosng.platform.api.commands.LoanTransactionCommand;
import org.mifosng.data.command.SubmitLoanApplicationCommand; import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
import org.mifosng.data.command.UndoStateTransitionCommand; import org.mifosng.platform.api.commands.UndoStateTransitionCommand;
import org.mifosng.platform.api.infrastructure.ApiDataConversionService; import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService; import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
import org.mifosng.platform.exceptions.UnrecognizedQueryParamException; 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, public Response stateTransitions(@PathParam("loanId") final Long loanId, @QueryParam("command") final String commandParam,
final LoanStateTransitionCommand command) { final LoanStateTransitionCommand command) {
LocalDate eventDate = this.apiDataConversionService.convertFrom( LocalDate eventLocalDate = this.apiDataConversionService.convertFrom(
command.getEventDateFormatted(), "eventDateFormatted", command.getEventDate(), "eventDate",
command.getDateFormat()); command.getDateFormat());
command.setLoanId(loanId); command.setLoanId(loanId);
command.setEventDate(eventDate); command.setEventLocalDate(eventLocalDate);
Response response = null; Response response = null;
@@ -210,7 +210,7 @@ public class LoansApiResource {
response = Response.ok().entity(identifier).build(); response = Response.ok().entity(identifier).build();
} }
UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(loanId, command.getComment()); UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(loanId, command.getNote());
if (is(commandParam, "undoapproval")) { if (is(commandParam, "undoapproval")) {
EntityIdentifier identifier = this.loanWritePlatformService.undoLoanApproval(undoCommand); EntityIdentifier identifier = this.loanWritePlatformService.undoLoanApproval(undoCommand);
response = Response.ok().entity(identifier).build(); response = Response.ok().entity(identifier).build();
@@ -236,31 +236,37 @@ public class LoansApiResource {
@Produces({ MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON})
public Response executeLoanTransaction( public Response executeLoanTransaction(
@PathParam("loanId") final Long loanId, @PathParam("loanId") final Long loanId,
@QueryParam("transactionType") final String transactionType, @QueryParam("command") final String commandParam,
final LoanTransactionCommand command) { final LoanTransactionCommand command) {
Response response = null;
command.setLoanId(loanId); command.setLoanId(loanId);
LocalDate transactionDate = apiDataConversionService.convertFrom( Locale clientLocale = this.apiDataConversionService.localeFromString(command.getLocale());
command.getTransactionDateFormatted(),
"transactionDateFormatted", command.getDateFormat());
command.setTransactionDate(transactionDate);
BigDecimal transactionAmount = apiDataConversionService.convertFrom( LocalDate transactionLocalDate = apiDataConversionService.convertFrom(
command.getTransactionAmountFormatted(), command.getTransactionDate(),
"transactionAmountFormatted", Locale.UK); "transactionDate", command.getDateFormat());
command.setTransactionAmount(transactionAmount); command.setTransactionLocalDate(transactionLocalDate);
if (StringUtils.isNotBlank(transactionType) BigDecimal transactionAmountValue = apiDataConversionService.convertFrom(
&& transactionType.trim().equalsIgnoreCase("waiver")) { command.getTransactionAmount(),
EntityIdentifier identifier = this.loanWritePlatformService "transactionAmount", clientLocale);
.waiveLoanAmount(command); command.setTransactionAmountValue(transactionAmountValue);
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();
} }
EntityIdentifier identifier = this.loanWritePlatformService if (response == null) {
.makeLoanRepayment(command); throw new UnrecognizedQueryParamException("command", commandParam);
return Response.ok().entity(identifier).build(); }
return response;
} }
@GET @GET
@@ -269,37 +275,43 @@ public class LoansApiResource {
@Produces({ MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON})
public String retrieveNewRepaymentDetails( public String retrieveNewRepaymentDetails(
@PathParam("loanId") final Long loanId, @PathParam("loanId") final Long loanId,
@QueryParam("type") final String transactionType, @QueryParam("command") final String commandParam,
@Context UriInfo uriInfo) { @Context UriInfo uriInfo) {
String json = "";
String selectedFields = loanRepaymentDefaultFieldList; String selectedFields = loanRepaymentDefaultFieldList;
if (StringUtils.isNotBlank(transactionType) if (is(commandParam, "repayment")) {
&& transactionType.trim().equalsIgnoreCase("waiver")) { 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 LoanRepaymentData loanWaiverData = this.loanReadPlatformService
.retrieveNewLoanWaiverDetails(loanId); .retrieveNewLoanWaiverDetails(loanId);
return this.jsonFormattingService.convertRequest(loanWaiverData, json = this.jsonFormattingService.convertRequest(loanWaiverData,
loanRepaymentFilterName, loanRepaymentAllowedFieldList, selectedFields, loanRepaymentFilterName, loanRepaymentAllowedFieldList, selectedFields,
uriInfo.getQueryParameters()); uriInfo.getQueryParameters());
} }
LoanRepaymentData loanRepaymentData = this.loanReadPlatformService if (StringUtils.isBlank(json)) {
.retrieveNewLoanRepaymentDetails(loanId); throw new UnrecognizedQueryParamException("command", commandParam);
return this.jsonFormattingService.convertRequest(loanRepaymentData, }
loanRepaymentFilterName, loanRepaymentAllowedFieldList, selectedFields,
uriInfo.getQueryParameters()); return json;
} }
@GET @GET
@Path("{loanId}/transactions/{repaymentId}") @Path("{loanId}/transactions/{transactionId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({ MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON})
public String retrieveRepaymentDetails( public String retrieveRepaymentDetails(
@PathParam("loanId") final Long loanId, @PathParam("loanId") final Long loanId,
@PathParam("repaymentId") final Long repaymentId, @PathParam("transactionId") final Long transactionId,
@Context UriInfo uriInfo) { @Context UriInfo uriInfo) {
LoanRepaymentData loanRepaymentData = this.loanReadPlatformService LoanRepaymentData loanRepaymentData = this.loanReadPlatformService
.retrieveLoanRepaymentDetails(loanId, repaymentId); .retrieveLoanRepaymentDetails(loanId, transactionId);
String selectedFields = ""; String selectedFields = "";
return this.jsonFormattingService.convertRequest(loanRepaymentData, return this.jsonFormattingService.convertRequest(loanRepaymentData,
@@ -308,29 +320,30 @@ public class LoansApiResource {
} }
@PUT @PUT
@Path("{loanId}/transactions/{repaymentId}") @Path("{loanId}/transactions/{transactionId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({ MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON})
public Response adjustLoanTransaction( public Response adjustLoanTransaction(
@PathParam("loanId") final Long loanId, @PathParam("loanId") final Long loanId,
@PathParam("repaymentId") final Long repaymentId, @PathParam("transactionId") final Long transactionId,
final AdjustLoanTransactionCommand command) { final AdjustLoanTransactionCommand command) {
command.setLoanId(loanId); command.setLoanId(loanId);
command.setRepaymentId(repaymentId); command.setTransactionId(transactionId);
LocalDate transactionDate = apiDataConversionService.convertFrom( Locale clientLocale = this.apiDataConversionService.localeFromString(command.getLocale());
command.getTransactionDateFormatted(),
"transactionDateFormatted", command.getDateFormat());
command.setTransactionDate(transactionDate);
BigDecimal transactionAmount = apiDataConversionService.convertFrom( LocalDate transactionLocalDate = apiDataConversionService.convertFrom(
command.getTransactionAmountFormatted(), command.getTransactionDate(),
"transactionAmountFormatted", Locale.UK); "transactionDate", command.getDateFormat());
command.setTransactionAmount(transactionAmount); command.setTransactionLocalDate(transactionLocalDate);
EntityIdentifier identifier = this.loanWritePlatformService BigDecimal transactionAmountValue = apiDataConversionService.convertFrom(
.adjustLoanTransaction(command); command.getTransactionAmount(),
"transactionAmount", clientLocale);
command.setTransactionAmountValue(transactionAmountValue);
EntityIdentifier identifier = this.loanWritePlatformService.adjustLoanTransaction(command);
return Response.ok().entity(identifier).build(); return Response.ok().entity(identifier).build();
} }
@@ -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;
}
}
@@ -1,4 +1,4 @@
package org.mifosng.data.command; package org.mifosng.platform.api.commands;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -1,10 +1,11 @@
package org.mifosng.data.command; package org.mifosng.platform.api.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement @XmlRootElement
public class ImportLoanCommand { public class ImportLoanCommand {
@@ -1,4 +1,4 @@
package org.mifosng.data.command; package org.mifosng.platform.api.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -1,4 +1,4 @@
package org.mifosng.data.command; package org.mifosng.platform.api.commands;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
@@ -12,19 +12,18 @@ public class LoanStateTransitionCommand {
private Long loanId; private Long loanId;
private String dateFormat; private String dateFormat;
private String eventDateFormatted; private String eventDate;
private LocalDate eventDate; private LocalDate eventLocalDate;
private String comment; private String note;
protected LoanStateTransitionCommand() { protected LoanStateTransitionCommand() {
// //
} }
public LoanStateTransitionCommand(final Long loanId, final LocalDate eventDate, public LoanStateTransitionCommand(final Long loanId, final LocalDate eventDate, final String comment) {
final String comment) {
this.loanId = loanId; this.loanId = loanId;
this.eventDate = eventDate; this.eventLocalDate = eventDate;
this.comment = comment; this.note = comment;
} }
public Long getLoanId() { public Long getLoanId() {
@@ -35,22 +34,6 @@ public class LoanStateTransitionCommand {
this.loanId = loanId; 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() { public String getDateFormat() {
return dateFormat; return dateFormat;
} }
@@ -59,11 +42,27 @@ public class LoanStateTransitionCommand {
this.dateFormat = dateFormat; this.dateFormat = dateFormat;
} }
public String getEventDateFormatted() { public String getEventDate() {
return eventDateFormatted; return eventDate;
} }
public void setEventDateFormatted(String eventDateFormatted) { public void setEventDate(String eventDate) {
this.eventDateFormatted = eventDateFormatted; 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;
} }
} }
@@ -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;
}
}
@@ -1,4 +1,4 @@
package org.mifosng.data.command; package org.mifosng.platform.api.commands;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
@@ -1,7 +1,8 @@
package org.mifosng.data.command; package org.mifosng.platform.api.commands;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement @XmlRootElement
public class SubmitApproveDisburseLoanCommand { public class SubmitApproveDisburseLoanCommand {
@@ -1,4 +1,4 @@
package org.mifosng.data.command; package org.mifosng.platform.api.commands;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -1,18 +1,17 @@
package org.mifosng.data.command; package org.mifosng.platform.api.commands;
public class UndoStateTransitionCommand { public class UndoStateTransitionCommand {
private Long loanId; private Long loanId;
private String comment; private String note;
protected UndoStateTransitionCommand() { protected UndoStateTransitionCommand() {
// //
} }
public UndoStateTransitionCommand(final Long loanId, final String comment) { public UndoStateTransitionCommand(final Long loanId, final String note) {
this.loanId = loanId; this.loanId = loanId;
this.comment = comment; this.note = note;
} }
public Long getLoanId() { public Long getLoanId() {
@@ -23,11 +22,11 @@ public class UndoStateTransitionCommand {
this.loanId = loanId; this.loanId = loanId;
} }
public String getComment() { public String getNote() {
return comment; return note;
} }
public void setComment(String comment) { public void setNote(String note) {
this.comment = comment; this.note = note;
} }
} }
@@ -1,8 +1,8 @@
package org.mifosng.platform.client.service; package org.mifosng.platform.client.service;
import org.mifosng.data.EntityIdentifier; import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.command.NoteCommand;
import org.mifosng.platform.api.commands.ClientCommand; import org.mifosng.platform.api.commands.ClientCommand;
import org.mifosng.platform.api.commands.NoteCommand;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
public interface ClientWritePlatformService { public interface ClientWritePlatformService {
@@ -6,8 +6,8 @@ import static org.mifosng.platform.Specifications.officesThatMatch;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.mifosng.data.EntityIdentifier; import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.command.NoteCommand;
import org.mifosng.platform.api.commands.ClientCommand; 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.Client;
import org.mifosng.platform.client.domain.ClientRepository; import org.mifosng.platform.client.domain.ClientRepository;
import org.mifosng.platform.client.domain.Note; import org.mifosng.platform.client.domain.Note;
@@ -5,7 +5,7 @@ import java.util.List;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.mifosng.data.ApiParameterError; import org.mifosng.data.ApiParameterError;
import org.mifosng.data.command.AdjustLoanTransactionCommand; import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException; import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
public class AdjustLoanTransactionCommandValidator { public class AdjustLoanTransactionCommandValidator {
@@ -19,8 +19,8 @@ public class AdjustLoanTransactionCommandValidator {
public void validate() { public void validate() {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>(); List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
if (command.getRepaymentId() == null || command.getRepaymentId().longValue() <= 0) { if (command.getTransactionId() == null || command.getTransactionId().longValue() <= 0) {
ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.id.is.invalid", "The parameter repaymentId is invalid.", "repaymentId", command.getRepaymentId()); ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.id.is.invalid", "The parameter repaymentId is invalid.", "transactionId", command.getTransactionId());
dataValidationErrors.add(error); dataValidationErrors.add(error);
} }
@@ -29,18 +29,18 @@ public class AdjustLoanTransactionCommandValidator {
dataValidationErrors.add(error); 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"); ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.repayment.date.cannot.be.blank", "The parameter transactionDate cannot be blank.", "transactionDate");
dataValidationErrors.add(error); dataValidationErrors.add(error);
} }
if (command.getTransactionAmount() == null || command.getTransactionAmount().doubleValue() <= 0) { if (command.getTransactionAmountValue() == 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.getTransactionAmountFormatted()); 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); 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); ApiParameterError error = ApiParameterError.parameterError("validation.msg.note.exceeds.max.length", "The parameter note exceeds max allowed size of {0}", "note", 1000);
dataValidationErrors.add(error); dataValidationErrors.add(error);
} }
@@ -4,8 +4,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.mifosng.data.ApiParameterError; import org.mifosng.data.ApiParameterError;
import org.mifosng.data.command.CalculateLoanScheduleCommand;
import org.mifosng.platform.DataValidatorBuilder; import org.mifosng.platform.DataValidatorBuilder;
import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException; import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
public class CalculateLoanScheduleCommandValidator { public class CalculateLoanScheduleCommandValidator {
@@ -3,7 +3,7 @@ package org.mifosng.platform.loan.service;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.mifosng.data.LoanPayoffReadModel; import org.mifosng.data.LoanPayoffReadModel;
import org.mifosng.data.LoanSchedule; import org.mifosng.data.LoanSchedule;
import org.mifosng.data.command.CalculateLoanScheduleCommand; import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand;
public interface CalculationPlatformService { public interface CalculationPlatformService {
@@ -7,7 +7,7 @@ import org.mifosng.data.CurrencyData;
import org.mifosng.data.LoanPayoffReadModel; import org.mifosng.data.LoanPayoffReadModel;
import org.mifosng.data.LoanSchedule; import org.mifosng.data.LoanSchedule;
import org.mifosng.data.MoneyData; 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.ApplicationCurrency;
import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository; import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository;
import org.mifosng.platform.currency.domain.MonetaryCurrency; import org.mifosng.platform.currency.domain.MonetaryCurrency;
@@ -9,7 +9,7 @@ import java.util.List;
import org.mifosng.data.LoanSchedule; import org.mifosng.data.LoanSchedule;
import org.mifosng.data.MoneyData; import org.mifosng.data.MoneyData;
import org.mifosng.data.ScheduledLoanInstallment; 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.Client;
import org.mifosng.platform.client.domain.ClientRepository; import org.mifosng.platform.client.domain.ClientRepository;
import org.mifosng.platform.currency.domain.MonetaryCurrency; import org.mifosng.platform.currency.domain.MonetaryCurrency;
@@ -14,5 +14,5 @@ public interface LoanReadPlatformService {
LoanRepaymentData retrieveNewLoanWaiverDetails(Long loanId); LoanRepaymentData retrieveNewLoanWaiverDetails(Long loanId);
LoanRepaymentData retrieveLoanRepaymentDetails(Long loanId, Long repaymentId); LoanRepaymentData retrieveLoanRepaymentDetails(Long loanId, Long transactionId);
} }
@@ -36,7 +36,6 @@ import org.springframework.stereotype.Service;
@Service @Service
public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
// private final SimpleJdbcTemplate jdbcTemplate;
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final LoanRepository loanRepository; private final LoanRepository loanRepository;
private final ApplicationCurrencyRepository applicationCurrencyRepository; private final ApplicationCurrencyRepository applicationCurrencyRepository;
@@ -46,7 +45,6 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
@Autowired @Autowired
public LoanReadPlatformServiceImpl(final PlatformSecurityContext context, public LoanReadPlatformServiceImpl(final PlatformSecurityContext context,
// final DataSource dataSource,
final LoanRepository loanRepository, final LoanTransactionRepository loanTransactionRepository, final ApplicationCurrencyRepository applicationCurrencyRepository, final LoanRepository loanRepository, final LoanTransactionRepository loanTransactionRepository, final ApplicationCurrencyRepository applicationCurrencyRepository,
final LoanProductReadPlatformService loanProductReadPlatformService, final ClientReadPlatformService clientReadPlatformService) { final LoanProductReadPlatformService loanProductReadPlatformService, final ClientReadPlatformService clientReadPlatformService) {
this.context = context; this.context = context;
@@ -55,7 +53,6 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
this.applicationCurrencyRepository = applicationCurrencyRepository; this.applicationCurrencyRepository = applicationCurrencyRepository;
this.loanProductReadPlatformService = loanProductReadPlatformService; this.loanProductReadPlatformService = loanProductReadPlatformService;
this.clientReadPlatformService = clientReadPlatformService; this.clientReadPlatformService = clientReadPlatformService;
// this.jdbcTemplate = new SimpleJdbcTemplate(dataSource);
} }
@Override @Override
@@ -264,8 +261,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
// TODO - OPTIMIZE - write simple sql query to fetch back date of // TODO - OPTIMIZE - write simple sql query to fetch back date of
// possible next transaction date. // possible next transaction date.
Loan loan = this.loanRepository.findOne(loansThatMatch( Loan loan = this.loanRepository.findOne(loansThatMatch(currentUser.getOrganisation(), loanId));
currentUser.getOrganisation(), loanId));
if (loan == null) { if (loan == null) {
throw new LoanNotFoundException(loanId); throw new LoanNotFoundException(loanId);
} }
@@ -3,9 +3,9 @@ package org.mifosng.platform.loan.service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.mifosng.data.ApiParameterError; 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; import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
public class LoanStateTransitionCommandValidator { public class LoanStateTransitionCommandValidator {
@@ -19,20 +19,11 @@ public class LoanStateTransitionCommandValidator {
public void validate() { public void validate() {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>(); List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
if (command.getLoanId() == null) { DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transition");
ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.id.is.invalid", "The parameter loanId is invalid.", "loanId", command.getLoanId());
dataValidationErrors.add(error);
}
if (command.getEventDate() == null) { baseDataValidator.reset().parameter("loanId").value(command.getLoanId()).notNull();
ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.state.transition.date.cannot.be.blank", "The parameter eventDate cannot be blank.", "eventDate"); baseDataValidator.reset().parameter("eventDate").value(command.getEventLocalDate()).notNull();
dataValidationErrors.add(error); baseDataValidator.reset().parameter("note").value(command.getNote()).notExceedingLengthOf(1000);
}
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);
}
if (!dataValidationErrors.isEmpty()) { if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
@@ -5,7 +5,7 @@ import java.util.List;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.mifosng.data.ApiParameterError; import org.mifosng.data.ApiParameterError;
import org.mifosng.data.command.LoanTransactionCommand; import org.mifosng.platform.api.commands.LoanTransactionCommand;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException; import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
public class LoanTransactionCommandValidator { public class LoanTransactionCommandValidator {
@@ -24,17 +24,17 @@ public class LoanTransactionCommandValidator {
dataValidationErrors.add(error); 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"); ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.repayment.date.cannot.be.blank", "The parameter transactionDateFormatted cannot be blank.", "transactionDateFormatted");
dataValidationErrors.add(error); dataValidationErrors.add(error);
} }
if (command.getTransactionAmount() == null || command.getTransactionAmount().doubleValue() <= 0) { 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.getTransactionAmountFormatted()); 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); 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); ApiParameterError error = ApiParameterError.parameterError("validation.msg.note.exceeds.max.length", "The parameter comment exceeds max allowed size of {0}", "comment", 1000);
dataValidationErrors.add(error); dataValidationErrors.add(error);
} }
@@ -43,5 +43,4 @@ public class LoanTransactionCommandValidator {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
} }
} }
} }
@@ -1,11 +1,11 @@
package org.mifosng.platform.loan.service; package org.mifosng.platform.loan.service;
import org.mifosng.data.EntityIdentifier; import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.command.AdjustLoanTransactionCommand; import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand;
import org.mifosng.data.command.LoanStateTransitionCommand; import org.mifosng.platform.api.commands.LoanStateTransitionCommand;
import org.mifosng.data.command.LoanTransactionCommand; import org.mifosng.platform.api.commands.LoanTransactionCommand;
import org.mifosng.data.command.SubmitLoanApplicationCommand; import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
import org.mifosng.data.command.UndoStateTransitionCommand; import org.mifosng.platform.api.commands.UndoStateTransitionCommand;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
public interface LoanWritePlatformService { public interface LoanWritePlatformService {
@@ -10,17 +10,18 @@ import org.joda.time.LocalDate;
import org.mifosng.data.EntityIdentifier; import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.LoanSchedule; import org.mifosng.data.LoanSchedule;
import org.mifosng.data.ScheduledLoanInstallment; import org.mifosng.data.ScheduledLoanInstallment;
import org.mifosng.data.command.AdjustLoanTransactionCommand; import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand;
import org.mifosng.data.command.CalculateLoanScheduleCommand; import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand;
import org.mifosng.data.command.LoanStateTransitionCommand; import org.mifosng.platform.api.commands.LoanStateTransitionCommand;
import org.mifosng.data.command.LoanTransactionCommand; import org.mifosng.platform.api.commands.LoanTransactionCommand;
import org.mifosng.data.command.SubmitLoanApplicationCommand; import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
import org.mifosng.data.command.UndoStateTransitionCommand; import org.mifosng.platform.api.commands.UndoStateTransitionCommand;
import org.mifosng.platform.client.domain.Note; import org.mifosng.platform.client.domain.Note;
import org.mifosng.platform.client.domain.NoteRepository; import org.mifosng.platform.client.domain.NoteRepository;
import org.mifosng.platform.currency.domain.MonetaryCurrency; import org.mifosng.platform.currency.domain.MonetaryCurrency;
import org.mifosng.platform.currency.domain.Money; import org.mifosng.platform.currency.domain.Money;
import org.mifosng.platform.exceptions.LoanNotFoundException; import org.mifosng.platform.exceptions.LoanNotFoundException;
import org.mifosng.platform.exceptions.LoanTransactionNotFoundException;
import org.mifosng.platform.exceptions.NoAuthorizationException; import org.mifosng.platform.exceptions.NoAuthorizationException;
import org.mifosng.platform.exceptions.PlatformDomainRuleException; import org.mifosng.platform.exceptions.PlatformDomainRuleException;
import org.mifosng.platform.loan.domain.DefaultLoanLifecycleStateMachine; import org.mifosng.platform.loan.domain.DefaultLoanLifecycleStateMachine;
@@ -139,15 +140,17 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
throw new LoanNotFoundException(command.getLoanId()); 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."); 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); this.loanRepository.save(loan);
if (StringUtils.isNotBlank(command.getComment())) { String noteText = command.getNote();
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); this.noteRepository.save(note);
} }
@@ -168,8 +171,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
loan.undoApproval(defaultLoanLifecycleStateMachine()); loan.undoApproval(defaultLoanLifecycleStateMachine());
this.loanRepository.save(loan); this.loanRepository.save(loan);
if (StringUtils.isNotBlank(command.getComment())) { String noteText = command.getNote();
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); this.noteRepository.save(note);
} }
@@ -190,15 +194,17 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
throw new LoanNotFoundException(command.getLoanId()); 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."); 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); this.loanRepository.save(loan);
if (StringUtils.isNotBlank(command.getComment())) { String noteText = command.getNote();
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); this.noteRepository.save(note);
} }
@@ -219,15 +225,17 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
throw new LoanNotFoundException(command.getLoanId()); 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."); 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); this.loanRepository.save(loan);
if (StringUtils.isNotBlank(command.getComment())) { String noteText = command.getNote();
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); this.noteRepository.save(note);
} }
@@ -248,15 +256,12 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
throw new LoanNotFoundException(command.getLoanId()); 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."); 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)) { if (loan.isRepaymentScheduleRegenerationRequiredForDisbursement(actualDisbursementDate)) {
LocalDate repaymentsStartingFromDate = loan.getExpectedFirstRepaymentOnDate(); LocalDate repaymentsStartingFromDate = loan.getExpectedFirstRepaymentOnDate();
@@ -309,15 +314,15 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
interest.getAmount()); interest.getAmount());
modifiedLoanRepaymentSchedule.add(installment); modifiedLoanRepaymentSchedule.add(installment);
} }
loan.disburseWithModifiedRepaymentSchedule(disbursedOn, comment, modifiedLoanRepaymentSchedule, defaultLoanLifecycleStateMachine()); loan.disburseWithModifiedRepaymentSchedule(actualDisbursementDate, noteText, modifiedLoanRepaymentSchedule, defaultLoanLifecycleStateMachine());
} else { } else {
loan.disburse(disbursedOn, defaultLoanLifecycleStateMachine()); loan.disburse(actualDisbursementDate, defaultLoanLifecycleStateMachine());
} }
this.loanRepository.save(loan); this.loanRepository.save(loan);
if (StringUtils.isNotBlank(command.getComment())) { if (StringUtils.isNotBlank(noteText)) {
Note note = Note.loanNote(currentUser.getOrganisation(), loan, command.getComment()); Note note = Note.loanNote(currentUser.getOrganisation(), loan, noteText);
this.noteRepository.save(note); this.noteRepository.save(note);
} }
@@ -343,8 +348,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
this.loanRepository.save(loan); this.loanRepository.save(loan);
if (StringUtils.isNotBlank(command.getComment())) { String noteText = command.getNote();
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); this.noteRepository.save(note);
} }
@@ -365,21 +371,23 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
throw new LoanNotFoundException(command.getLoanId()); 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"); throw new NoAuthorizationException("error.msg.no.permission.to.make.repayment.on.loan.in.past");
} }
Money repayment = Money.of(loan.getLoanRepaymentScheduleDetail() Money repayment = Money.of(loan.getLoanRepaymentScheduleDetail()
.getPrincipal().getCurrency(), .getPrincipal().getCurrency(),
command.getTransactionAmount()); command.getTransactionAmountValue());
LoanTransaction loanRepayment = LoanTransaction.repayment(repayment, command.getTransactionDate()); LoanTransaction loanRepayment = LoanTransaction.repayment(repayment, transactionDate);
loan.makeRepayment(loanRepayment, defaultLoanLifecycleStateMachine()); loan.makeRepayment(loanRepayment, defaultLoanLifecycleStateMachine());
this.loanTransactionRepository.save(loanRepayment); this.loanTransactionRepository.save(loanRepayment);
this.loanRepository.save(loan); this.loanRepository.save(loan);
if (StringUtils.isNotBlank(command.getComment())) { String noteText = command.getNote();
Note note = Note.loanTransactionNote(currentUser.getOrganisation(), loan, loanRepayment, command.getComment()); if (StringUtils.isNotBlank(noteText)) {
Note note = Note.loanTransactionNote(currentUser.getOrganisation(), loan, loanRepayment, noteText);
this.noteRepository.save(note); this.noteRepository.save(note);
} }
@@ -400,17 +408,20 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
throw new LoanNotFoundException(command.getLoanId()); throw new LoanNotFoundException(command.getLoanId());
} }
LoanTransaction transactionToAdjust = this.loanTransactionRepository LoanTransaction transactionToAdjust = this.loanTransactionRepository.findOne(command.getTransactionId());
.findOne(command.getRepaymentId()); if (transactionToAdjust == null) {
throw new LoanTransactionNotFoundException(command.getTransactionId());
}
Money transactionAmount = Money.of(loan Money transactionAmount = Money.of(loan
.getLoanRepaymentScheduleDetail().getPrincipal() .getLoanRepaymentScheduleDetail().getPrincipal()
.getCurrency(), command.getTransactionAmount()); .getCurrency(), command.getTransactionAmountValue());
// adjustment is only supported for repayments and waivers at present // 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()) { if (transactionToAdjust.isWaiver()) {
newTransactionDetail = LoanTransaction.waiver(transactionAmount, command.getTransactionDate()); newTransactionDetail = LoanTransaction.waiver(transactionAmount, transactionDate);
} }
loan.adjustExistingTransaction(transactionToAdjust, newTransactionDetail, defaultLoanLifecycleStateMachine()); loan.adjustExistingTransaction(transactionToAdjust, newTransactionDetail, defaultLoanLifecycleStateMachine());
@@ -419,9 +430,10 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
this.loanRepository.save(loan); this.loanRepository.save(loan);
if (StringUtils.isNotBlank(command.getComment())) { String noteText = command.getNote();
if (StringUtils.isNotBlank(noteText)) {
Note note = Note.loanTransactionNote(currentUser.getOrganisation(), Note note = Note.loanTransactionNote(currentUser.getOrganisation(),
loan, newTransactionDetail, command.getComment()); loan, newTransactionDetail, noteText);
this.noteRepository.save(note); this.noteRepository.save(note);
} }
@@ -444,9 +456,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
Money waived = Money.of(loan.getLoanRepaymentScheduleDetail() Money waived = Money.of(loan.getLoanRepaymentScheduleDetail()
.getPrincipal().getCurrency(), .getPrincipal().getCurrency(),
command.getTransactionAmount()); command.getTransactionAmountValue());
LoanTransaction waiver = LoanTransaction.waiver(waived, command.getTransactionDate()); LoanTransaction waiver = LoanTransaction.waiver(waived, command.getTransactionLocalDate());
loan.waive(waiver, defaultLoanLifecycleStateMachine()); loan.waive(waiver, defaultLoanLifecycleStateMachine());
@@ -454,8 +466,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
this.loanRepository.save(loan); this.loanRepository.save(loan);
if (StringUtils.isNotBlank(command.getComment())) { String noteText = command.getNote();
Note note = Note.loanTransactionNote(currentUser.getOrganisation(), loan, waiver, command.getComment()); if (StringUtils.isNotBlank(noteText)) {
Note note = Note.loanTransactionNote(currentUser.getOrganisation(), loan, waiver, noteText);
this.noteRepository.save(note); this.noteRepository.save(note);
} }
@@ -4,8 +4,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.mifosng.data.ApiParameterError; import org.mifosng.data.ApiParameterError;
import org.mifosng.data.command.CalculateLoanScheduleCommand; import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand;
import org.mifosng.data.command.SubmitLoanApplicationCommand; import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException; import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
public class SubmitLoanApplicationCommandValidator { public class SubmitLoanApplicationCommandValidator {
@@ -7,10 +7,10 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; 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.ImportPlatformService;
import org.mifosng.platform.api.commands.ImportClientCommand; 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.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -7,10 +7,10 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; 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.ImportPlatformService;
import org.mifosng.platform.api.commands.ImportClientCommand; 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.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;