allow undo disbursal if only disbursement transactions. refactor loanTransactionData object.

This commit is contained in:
Keith Woodlock
2012-10-18 17:48:26 +01:00
parent 3e40a0dac4
commit 09165cbb04
8 changed files with 53 additions and 37 deletions
@@ -38,7 +38,7 @@ import org.mifosng.platform.api.data.LoanBasicDetailsData;
import org.mifosng.platform.api.data.LoanChargeData; import org.mifosng.platform.api.data.LoanChargeData;
import org.mifosng.platform.api.data.LoanPermissionData; import org.mifosng.platform.api.data.LoanPermissionData;
import org.mifosng.platform.api.data.LoanProductData; import org.mifosng.platform.api.data.LoanProductData;
import org.mifosng.platform.api.data.LoanTransactionNewData; import org.mifosng.platform.api.data.LoanTransactionData;
import org.mifosng.platform.api.data.StaffData; import org.mifosng.platform.api.data.StaffData;
import org.mifosng.platform.api.data.TransactionProcessingStrategyData; import org.mifosng.platform.api.data.TransactionProcessingStrategyData;
import org.mifosng.platform.api.infrastructure.ApiDataConversionService; import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
@@ -192,7 +192,7 @@ public class LoansApiResource {
final LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService.retrieveLoanAccountDetails(loanId); final LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService.retrieveLoanAccountDetails(loanId);
int loanRepaymentsCount = 0; int loanRepaymentsCount = 0;
Collection<LoanTransactionNewData> loanRepayments = null; Collection<LoanTransactionData> loanRepayments = null;
LoanScheduleData repaymentSchedule = null; LoanScheduleData repaymentSchedule = null;
LoanPermissionData permissions = null; LoanPermissionData permissions = null;
Collection<LoanChargeData> charges = null; Collection<LoanChargeData> charges = null;
@@ -208,10 +208,9 @@ public class LoansApiResource {
} }
if (responseParameters.contains("transactions")) { if (responseParameters.contains("transactions")) {
Collection<LoanTransactionNewData> currentLoanRepayments = this.loanReadPlatformService.retrieveLoanTransactions(loanId); final Collection<LoanTransactionData> currentLoanRepayments = this.loanReadPlatformService.retrieveLoanTransactions(loanId);
if (!CollectionUtils.isEmpty(currentLoanRepayments)) { if (!CollectionUtils.isEmpty(currentLoanRepayments)) {
loanRepayments = currentLoanRepayments; loanRepayments = currentLoanRepayments;
loanRepaymentsCount = loanRepayments.size();
} }
} }
@@ -229,6 +228,7 @@ public class LoansApiResource {
boolean isWaiveAllowed = totalOutstandingMoney.isGreaterThanZero() && (tolerance.isGreaterThan(totalOutstandingMoney) || tolerance.isEqualTo(totalOutstandingMoney)); boolean isWaiveAllowed = totalOutstandingMoney.isGreaterThanZero() && (tolerance.isGreaterThan(totalOutstandingMoney) || tolerance.isEqualTo(totalOutstandingMoney));
if (responseParameters.contains("permissions")) { if (responseParameters.contains("permissions")) {
loanRepaymentsCount = retrieveNonDisbursementTransactions(loanRepayments);
permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails, isWaiveAllowed, loanRepaymentsCount); permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails, isWaiveAllowed, loanRepaymentsCount);
} }
convenienceDataRequired = true; convenienceDataRequired = true;
@@ -290,6 +290,19 @@ public class LoansApiResource {
return this.apiJsonSerializerService.serializeLoanAccountDataToJson(prettyPrint, responseParameters, loanAccount); return this.apiJsonSerializerService.serializeLoanAccountDataToJson(prettyPrint, responseParameters, loanAccount);
} }
private int retrieveNonDisbursementTransactions(final Collection<LoanTransactionData> loanRepayments) {
int loanRepaymentsCount = 0;
if (!CollectionUtils.isEmpty(loanRepayments)) {
for (LoanTransactionData transaction : loanRepayments) {
if (transaction.isNotDisbursement()) {
// use this to decide if undo disbural should permission should be set to true.
loanRepaymentsCount++;
}
}
}
return loanRepaymentsCount;
}
@POST @POST
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
@@ -453,7 +466,7 @@ public class LoansApiResource {
} }
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
LoanTransactionNewData transactionData = null; LoanTransactionData transactionData = null;
if (is(commandParam, "repayment")) { if (is(commandParam, "repayment")) {
transactionData = this.loanReadPlatformService.retrieveNewLoanRepaymentDetails(loanId); transactionData = this.loanReadPlatformService.retrieveNewLoanRepaymentDetails(loanId);
} else if (is(commandParam, "waiveinterest")) { } else if (is(commandParam, "waiveinterest")) {
@@ -485,7 +498,7 @@ public class LoansApiResource {
} }
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final LoanTransactionNewData transactionData = this.loanReadPlatformService.retrieveLoanTransactionDetails(loanId, transactionId); final LoanTransactionData transactionData = this.loanReadPlatformService.retrieveLoanTransactionDetails(loanId, transactionId);
return this.apiJsonSerializerService.serializeLoanTransactionDataToJson(prettyPrint, responseParameters, transactionData); return this.apiJsonSerializerService.serializeLoanTransactionDataToJson(prettyPrint, responseParameters, transactionData);
} }
@@ -56,7 +56,7 @@ public class LoanAccountData {
// associations // associations
private final LoanScheduleData repaymentSchedule; private final LoanScheduleData repaymentSchedule;
private final Collection<LoanTransactionNewData> transactions; private final Collection<LoanTransactionData> transactions;
private final Collection<LoanChargeData> charges; private final Collection<LoanChargeData> charges;
private final LoanPermissionData permissions; private final LoanPermissionData permissions;
private final LoanConvenienceData convenienceData; private final LoanConvenienceData convenienceData;
@@ -79,7 +79,7 @@ public class LoanAccountData {
final LoanBasicDetailsData basicDetails, final LoanBasicDetailsData basicDetails,
final boolean convenienceDataRequired, final boolean convenienceDataRequired,
final LoanScheduleData repaymentSchedule, final LoanScheduleData repaymentSchedule,
final Collection<LoanTransactionNewData> transactions, final Collection<LoanTransactionData> transactions,
final LoanPermissionData permissions, final LoanPermissionData permissions,
final Collection<LoanChargeData> charges, final Collection<LoanChargeData> charges,
final Collection<LoanProductData> productOptions, final Collection<LoanProductData> productOptions,
@@ -7,12 +7,11 @@ import org.joda.time.LocalDate;
/** /**
* Immutable data object representing a loan transaction. * Immutable data object representing a loan transaction.
*/ */
public class LoanTransactionNewData { public class LoanTransactionData {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private Long id; private Long id;
@SuppressWarnings("unused")
private EnumOptionData type; private EnumOptionData type;
private LocalDate date; private LocalDate date;
@@ -23,7 +22,7 @@ public class LoanTransactionNewData {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private BigDecimal amount; private BigDecimal amount;
public LoanTransactionNewData( public LoanTransactionData(
final Long id, final Long id,
final EnumOptionData transactionType, final EnumOptionData transactionType,
final CurrencyData currency, final CurrencyData currency,
@@ -39,4 +38,8 @@ public class LoanTransactionNewData {
public LocalDate dateOf() { public LocalDate dateOf() {
return this.date; return this.date;
} }
public boolean isNotDisbursement() {
return type.getId().equals(Integer.valueOf(1));
}
} }
@@ -24,7 +24,7 @@ import org.mifosng.platform.api.data.GroupData;
import org.mifosng.platform.api.data.LoanAccountData; import org.mifosng.platform.api.data.LoanAccountData;
import org.mifosng.platform.api.data.LoanChargeData; import org.mifosng.platform.api.data.LoanChargeData;
import org.mifosng.platform.api.data.LoanProductData; import org.mifosng.platform.api.data.LoanProductData;
import org.mifosng.platform.api.data.LoanTransactionNewData; import org.mifosng.platform.api.data.LoanTransactionData;
import org.mifosng.platform.api.data.NoteData; import org.mifosng.platform.api.data.NoteData;
import org.mifosng.platform.api.data.OfficeData; import org.mifosng.platform.api.data.OfficeData;
import org.mifosng.platform.api.data.OfficeTransactionData; import org.mifosng.platform.api.data.OfficeTransactionData;
@@ -103,7 +103,7 @@ public interface ApiJsonSerializerService {
String serializeLoanAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanAccountData loanAccount); String serializeLoanAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanAccountData loanAccount);
String serializeLoanTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanTransactionNewData newTransactionData); String serializeLoanTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanTransactionData newTransactionData);
String serializeChargeDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<ChargeData> charges); String serializeChargeDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<ChargeData> charges);
@@ -26,7 +26,7 @@ import org.mifosng.platform.api.data.GroupData;
import org.mifosng.platform.api.data.LoanAccountData; import org.mifosng.platform.api.data.LoanAccountData;
import org.mifosng.platform.api.data.LoanChargeData; import org.mifosng.platform.api.data.LoanChargeData;
import org.mifosng.platform.api.data.LoanProductData; import org.mifosng.platform.api.data.LoanProductData;
import org.mifosng.platform.api.data.LoanTransactionNewData; import org.mifosng.platform.api.data.LoanTransactionData;
import org.mifosng.platform.api.data.NoteData; import org.mifosng.platform.api.data.NoteData;
import org.mifosng.platform.api.data.OfficeData; import org.mifosng.platform.api.data.OfficeData;
import org.mifosng.platform.api.data.OfficeTransactionData; import org.mifosng.platform.api.data.OfficeTransactionData;
@@ -556,7 +556,7 @@ public class GoogleGsonApiJsonSerializerService implements ApiJsonSerializerServ
@Override @Override
public String serializeLoanTransactionDataToJson(final boolean prettyPrint, public String serializeLoanTransactionDataToJson(final boolean prettyPrint,
final Set<String> responseParameters, final Set<String> responseParameters,
final LoanTransactionNewData transaction) { final LoanTransactionData transaction) {
final Gson gsonDeserializer = helper final Gson gsonDeserializer = helper
.createGsonBuilderWithParameterExclusionSerializationStrategy( .createGsonBuilderWithParameterExclusionSerializationStrategy(
LOAN_TRANSACTION_NEW_DATA_PARAMETERS, prettyPrint, LOAN_TRANSACTION_NEW_DATA_PARAMETERS, prettyPrint,
@@ -2,12 +2,12 @@ package org.mifosng.platform.loan.domain;
import java.util.Comparator; import java.util.Comparator;
import org.mifosng.platform.api.data.LoanTransactionNewData; import org.mifosng.platform.api.data.LoanTransactionData;
public class LoanRepaymentDataComparator implements Comparator<LoanTransactionNewData> { public class LoanRepaymentDataComparator implements Comparator<LoanTransactionData> {
@Override @Override
public int compare(final LoanTransactionNewData o1, final LoanTransactionNewData o2) { public int compare(final LoanTransactionData o1, final LoanTransactionData o2) {
return o2.dateOf().compareTo(o1.dateOf()); return o2.dateOf().compareTo(o1.dateOf());
} }
} }
@@ -8,7 +8,7 @@ import org.mifosng.platform.api.data.CurrencyData;
import org.mifosng.platform.api.data.DisbursementData; import org.mifosng.platform.api.data.DisbursementData;
import org.mifosng.platform.api.data.LoanBasicDetailsData; import org.mifosng.platform.api.data.LoanBasicDetailsData;
import org.mifosng.platform.api.data.LoanPermissionData; import org.mifosng.platform.api.data.LoanPermissionData;
import org.mifosng.platform.api.data.LoanTransactionNewData; import org.mifosng.platform.api.data.LoanTransactionData;
public interface LoanReadPlatformService { public interface LoanReadPlatformService {
@@ -16,7 +16,7 @@ public interface LoanReadPlatformService {
LoanScheduleData retrieveRepaymentSchedule(Long loanId, CurrencyData currency, DisbursementData disbursement, BigDecimal totalChargesAtDisbursement, BigDecimal inArrearsTolerance); LoanScheduleData retrieveRepaymentSchedule(Long loanId, CurrencyData currency, DisbursementData disbursement, BigDecimal totalChargesAtDisbursement, BigDecimal inArrearsTolerance);
Collection<LoanTransactionNewData> retrieveLoanTransactions(Long loanId); Collection<LoanTransactionData> retrieveLoanTransactions(Long loanId);
LoanPermissionData retrieveLoanPermissions( LoanPermissionData retrieveLoanPermissions(
LoanBasicDetailsData loanBasicDetails, boolean isWaiverAllowed, LoanBasicDetailsData loanBasicDetails, boolean isWaiverAllowed,
@@ -26,11 +26,11 @@ public interface LoanReadPlatformService {
LoanBasicDetailsData retrieveGroupAndProductDetails(Long groupId, Long productId); LoanBasicDetailsData retrieveGroupAndProductDetails(Long groupId, Long productId);
LoanTransactionNewData retrieveNewLoanRepaymentDetails(Long loanId); LoanTransactionData retrieveNewLoanRepaymentDetails(Long loanId);
LoanTransactionNewData retrieveNewLoanWaiveInterestDetails(Long loanId); LoanTransactionData retrieveNewLoanWaiveInterestDetails(Long loanId);
LoanTransactionNewData retrieveLoanTransactionDetails(Long loanId, Long transactionId); LoanTransactionData retrieveLoanTransactionDetails(Long loanId, Long transactionId);
LoanTransactionNewData retrieveNewClosureDetails(); LoanTransactionData retrieveNewClosureDetails();
} }
@@ -18,7 +18,7 @@ import org.mifosng.platform.api.data.LoanChargeData;
import org.mifosng.platform.api.data.LoanPermissionData; import org.mifosng.platform.api.data.LoanPermissionData;
import org.mifosng.platform.api.data.LoanProductData; import org.mifosng.platform.api.data.LoanProductData;
import org.mifosng.platform.api.data.LoanSchedulePeriodData; import org.mifosng.platform.api.data.LoanSchedulePeriodData;
import org.mifosng.platform.api.data.LoanTransactionNewData; import org.mifosng.platform.api.data.LoanTransactionData;
import org.mifosng.platform.client.service.ClientReadPlatformService; import org.mifosng.platform.client.service.ClientReadPlatformService;
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;
@@ -162,7 +162,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
} }
@Override @Override
public Collection<LoanTransactionNewData> retrieveLoanTransactions(final Long loanId) { public Collection<LoanTransactionData> retrieveLoanTransactions(final Long loanId) {
try { try {
context.authenticatedUser(); context.authenticatedUser();
@@ -262,7 +262,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
} }
@Override @Override
public LoanTransactionNewData retrieveNewLoanRepaymentDetails(final Long loanId) { public LoanTransactionData retrieveNewLoanRepaymentDetails(final Long loanId) {
context.authenticatedUser(); context.authenticatedUser();
@@ -287,11 +287,11 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
final Money possibleNextRepaymentAmount = loan.possibleNextRepaymentAmount(); final Money possibleNextRepaymentAmount = loan.possibleNextRepaymentAmount();
final EnumOptionData transactionType = LoanEnumerations.transactionType(LoanTransactionType.REPAYMENT); final EnumOptionData transactionType = LoanEnumerations.transactionType(LoanTransactionType.REPAYMENT);
return new LoanTransactionNewData(null, transactionType, currencyData, earliestUnpaidInstallmentDate, possibleNextRepaymentAmount.getAmount()); return new LoanTransactionData(null, transactionType, currencyData, earliestUnpaidInstallmentDate, possibleNextRepaymentAmount.getAmount());
} }
@Override @Override
public LoanTransactionNewData retrieveNewLoanWaiveInterestDetails(final Long loanId) { public LoanTransactionData retrieveNewLoanWaiveInterestDetails(final Long loanId) {
context.authenticatedUser(); context.authenticatedUser();
@@ -315,21 +315,21 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
final EnumOptionData transactionType = LoanEnumerations.transactionType(LoanTransactionType.WAIVE_INTEREST); final EnumOptionData transactionType = LoanEnumerations.transactionType(LoanTransactionType.WAIVE_INTEREST);
return new LoanTransactionNewData(null, transactionType, currencyData, waiveOfInterest.getTransactionDate(), waiveOfInterest.getAmount()); return new LoanTransactionData(null, transactionType, currencyData, waiveOfInterest.getTransactionDate(), waiveOfInterest.getAmount());
} }
@Override @Override
public LoanTransactionNewData retrieveNewClosureDetails() { public LoanTransactionData retrieveNewClosureDetails() {
context.authenticatedUser(); context.authenticatedUser();
EnumOptionData transactionType = LoanEnumerations.transactionType(LoanTransactionType.WRITEOFF); EnumOptionData transactionType = LoanEnumerations.transactionType(LoanTransactionType.WRITEOFF);
return new LoanTransactionNewData(null, transactionType, null, new LocalDate(), null); return new LoanTransactionData(null, transactionType, null, new LocalDate(), null);
} }
@Override @Override
public LoanTransactionNewData retrieveLoanTransactionDetails( public LoanTransactionData retrieveLoanTransactionDetails(
final Long loanId, final Long transactionId) { final Long loanId, final Long transactionId) {
context.authenticatedUser(); context.authenticatedUser();
@@ -359,7 +359,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
currency.getDisplaySymbol(), currency.getNameCode()); currency.getDisplaySymbol(), currency.getNameCode());
final EnumOptionData transactionType = LoanEnumerations.transactionType(transaction.getTypeOf()); final EnumOptionData transactionType = LoanEnumerations.transactionType(transaction.getTypeOf());
return new LoanTransactionNewData(transactionId, transactionType, currencyData, transaction.getTransactionDate(), transaction.getAmount()); return new LoanTransactionData(transactionId, transactionType, currencyData, transaction.getTransactionDate(), transaction.getAmount());
} }
private static final class LoanMapper implements private static final class LoanMapper implements
@@ -573,7 +573,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
} }
} }
private static final class LoanTransactionsMapper implements RowMapper<LoanTransactionNewData> { private static final class LoanTransactionsMapper implements RowMapper<LoanTransactionData> {
public String LoanPaymentsSchema() { public String LoanPaymentsSchema() {
@@ -586,7 +586,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
} }
@Override @Override
public LoanTransactionNewData mapRow(final ResultSet rs, public LoanTransactionData mapRow(final ResultSet rs,
@SuppressWarnings("unused") final int rowNum) throws SQLException { @SuppressWarnings("unused") final int rowNum) throws SQLException {
String currencyCode = rs.getString("currencyCode"); String currencyCode = rs.getString("currencyCode");
@@ -604,7 +604,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
LocalDate date = JdbcSupport.getLocalDate(rs, "date"); LocalDate date = JdbcSupport.getLocalDate(rs, "date");
BigDecimal totalAmount = rs.getBigDecimal("total"); BigDecimal totalAmount = rs.getBigDecimal("total");
return new LoanTransactionNewData(id, transactionType, currencyData, date, totalAmount); return new LoanTransactionData(id, transactionType, currencyData, date, totalAmount);
} }
} }
} }