merge master to develop

This commit is contained in:
Keith Woodlock
2013-06-06 16:19:31 +01:00
9 changed files with 78 additions and 32 deletions
+1 -1
View File
@@ -1 +1 @@
releaseVersion=1.2.0.RELEASE releaseVersion=1.2.1.RELEASE
@@ -7,6 +7,7 @@ package org.mifosplatform.portfolio.client.data;
import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.portfolio.loanaccount.data.LoanStatusEnumData; import org.mifosplatform.portfolio.loanaccount.data.LoanStatusEnumData;
import org.mifosplatform.portfolio.savings.data.SavingsAccountStatusEnumData;
/** /**
* Immutable data object for client loan accounts. * Immutable data object for client loan accounts.
@@ -27,7 +28,8 @@ public class ClientAccountSummaryData {
private final Integer accountStatusId; private final Integer accountStatusId;
private final LoanStatusEnumData status; private final LoanStatusEnumData status;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final EnumOptionData loanType; private final EnumOptionData loanType;
private final SavingsAccountStatusEnumData savingAccountStatus;
public ClientAccountSummaryData(final Long id, final String externalId, final Long productId, final String loanProductName, public ClientAccountSummaryData(final Long id, final String externalId, final Long productId, final String loanProductName,
final Integer loanStatusId) { final Integer loanStatusId) {
@@ -39,18 +41,7 @@ public class ClientAccountSummaryData {
this.accountStatusId = loanStatusId; this.accountStatusId = loanStatusId;
this.status = null; this.status = null;
this.loanType = null; this.loanType = null;
} this.savingAccountStatus = null;
public ClientAccountSummaryData(final Long id, final String accountNo, final String externalId, final Long productId,
final String loanProductName, final LoanStatusEnumData loanStatus) {
this.id = id;
this.accountNo = accountNo;
this.externalId = externalId;
this.productId = productId;
this.productName = loanProductName;
this.accountStatusId = null;
this.status = loanStatus;
this.loanType = null;
} }
public ClientAccountSummaryData(final Long id, final String accountNo, final String externalId, final Long productId, public ClientAccountSummaryData(final Long id, final String accountNo, final String externalId, final Long productId,
@@ -63,12 +54,28 @@ public class ClientAccountSummaryData {
this.accountStatusId = null; this.accountStatusId = null;
this.status = loanStatus; this.status = loanStatus;
this.loanType = loanType; this.loanType = loanType;
this.savingAccountStatus = null;
}
public ClientAccountSummaryData(final Long id, final String accountNo, final String externalId, final Long productId,
final String loanProductName, final SavingsAccountStatusEnumData savingAccountStatus) {
this.id = id;
this.accountNo = accountNo;
this.externalId = externalId;
this.productId = productId;
this.productName = loanProductName;
this.accountStatusId = null;
this.status = null;
this.loanType = null;
this.savingAccountStatus = savingAccountStatus;
} }
public Integer accountStatusId() { public Integer accountStatusId() {
Integer accountStatus = this.accountStatusId; Integer accountStatus = this.accountStatusId;
if (accountStatus == null && this.status != null) { if (accountStatus == null && this.status != null) {
accountStatus = this.status.id().intValue(); accountStatus = this.status.id().intValue();
} else if (accountStatus == null && this.savingAccountStatus != null) {
accountStatus = this.savingAccountStatus.id().intValue();
} }
return accountStatus; return accountStatus;
} }
@@ -31,6 +31,9 @@ import org.mifosplatform.portfolio.group.data.GroupGeneralData;
import org.mifosplatform.portfolio.group.service.SearchParameters; import org.mifosplatform.portfolio.group.service.SearchParameters;
import org.mifosplatform.portfolio.loanaccount.data.LoanStatusEnumData; import org.mifosplatform.portfolio.loanaccount.data.LoanStatusEnumData;
import org.mifosplatform.portfolio.loanproduct.service.LoanEnumerations; import org.mifosplatform.portfolio.loanproduct.service.LoanEnumerations;
import org.mifosplatform.portfolio.savings.data.SavingsAccountStatusEnumData;
import org.mifosplatform.portfolio.savings.service.SavingStatusMapper;
import org.mifosplatform.portfolio.savings.service.SavingsEnumerations;
import org.mifosplatform.useradministration.domain.AppUser; import org.mifosplatform.useradministration.domain.AppUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.dao.EmptyResultDataAccessException;
@@ -410,8 +413,18 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
final List<ClientAccountSummaryData> savingsAccounts = this.jdbcTemplate.query(savingsSql, savingsAccountSummaryDataMapper, final List<ClientAccountSummaryData> savingsAccounts = this.jdbcTemplate.query(savingsSql, savingsAccountSummaryDataMapper,
new Object[] { clientId }); new Object[] { clientId });
approvedSavingAccounts.addAll(savingsAccounts); if (results != null) {
for (ClientAccountSummaryData row : savingsAccounts) {
SavingStatusMapper statusMapper = new SavingStatusMapper(row.accountStatusId());
if (statusMapper.isOpen()) {
approvedSavingAccounts.add(row);
} else {
pendingApprovalSavingAccounts.add(row);
}
}
}
return new ClientAccountSummaryCollectionData(pendingApprovalLoans, awaitingDisbursalLoans, openLoans, closedLoans, return new ClientAccountSummaryCollectionData(pendingApprovalLoans, awaitingDisbursalLoans, openLoans, closedLoans,
pendingApprovalDepositAccounts, approvedDepositAccounts, withdrawnByClientDespositAccounts, rejectedDepositAccounts, pendingApprovalDepositAccounts, approvedDepositAccounts, withdrawnByClientDespositAccounts, rejectedDepositAccounts,
closedDepositAccounts, preclosedDepositAccounts, maturedDepositAccounts, pendingApprovalSavingAccounts, closedDepositAccounts, preclosedDepositAccounts, maturedDepositAccounts, pendingApprovalSavingAccounts,
@@ -445,7 +458,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
public ClientSavingsAccountSummaryDataMapper() { public ClientSavingsAccountSummaryDataMapper() {
StringBuilder accountsSummary = new StringBuilder(); StringBuilder accountsSummary = new StringBuilder();
accountsSummary.append("sa.id as id, sa.account_no as accountNo, sa.external_id as externalId,"); accountsSummary.append("sa.id as id, sa.account_no as accountNo, sa.external_id as externalId, sa.status_enum as statusEnum, ");
accountsSummary.append("sa.product_id as productId, p.name as productName "); accountsSummary.append("sa.product_id as productId, p.name as productName ");
accountsSummary.append("from m_savings_account sa "); accountsSummary.append("from m_savings_account sa ");
accountsSummary.append("join m_savings_product as p on p.id = sa.product_id "); accountsSummary.append("join m_savings_product as p on p.id = sa.product_id ");
@@ -464,10 +477,11 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
final String accountNo = rs.getString("accountNo"); final String accountNo = rs.getString("accountNo");
final String externalId = rs.getString("externalId"); final String externalId = rs.getString("externalId");
final Long productId = JdbcSupport.getLong(rs, "productId"); final Long productId = JdbcSupport.getLong(rs, "productId");
final String loanProductName = rs.getString("productName"); final String savingsProductName = rs.getString("productName");
final LoanStatusEnumData loanStatus = null; final Integer statusId = JdbcSupport.getInteger(rs, "statusEnum");
final SavingsAccountStatusEnumData savingAccountStatus = SavingsEnumerations.status(statusId);
return new ClientAccountSummaryData(id, accountNo, externalId, productId, loanProductName, loanStatus); return new ClientAccountSummaryData(id, accountNo, externalId, productId, savingsProductName, savingAccountStatus);
} }
} }
@@ -476,8 +490,9 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
public String loanAccountSummarySchema() { public String loanAccountSummarySchema() {
StringBuilder accountsSummary = new StringBuilder("l.id as id, l.account_no as accountNo, l.external_id as externalId,"); StringBuilder accountsSummary = new StringBuilder("l.id as id, l.account_no as accountNo, l.external_id as externalId,");
accountsSummary.append("l.product_id as productId, lp.name as productName,").append("l.loan_status_id as statusId, l.loan_type_enum as loanType ") accountsSummary.append("l.product_id as productId, lp.name as productName,")
.append("from m_loan l ").append("LEFT JOIN m_product_loan AS lp ON lp.id = l.product_id "); .append("l.loan_status_id as statusId, l.loan_type_enum as loanType ").append("from m_loan l ")
.append("LEFT JOIN m_product_loan AS lp ON lp.id = l.product_id ");
return accountsSummary.toString(); return accountsSummary.toString();
} }
@@ -10,7 +10,6 @@ package org.mifosplatform.portfolio.savings.data;
*/ */
public class SavingsAccountStatusEnumData { public class SavingsAccountStatusEnumData {
@SuppressWarnings("unused")
private final Long id; private final Long id;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final String code; private final String code;
@@ -32,4 +31,8 @@ public class SavingsAccountStatusEnumData {
this.active = active; this.active = active;
this.closed = closed; this.closed = closed;
} }
public Long id() {
return this.id;
}
} }
@@ -151,7 +151,7 @@ public class SavingsProductDataValidator {
if (this.fromApiJsonHelper.parameterExists(annualFeeAmountParamName, element)) { if (this.fromApiJsonHelper.parameterExists(annualFeeAmountParamName, element)) {
final BigDecimal annualFeeAmount = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(annualFeeAmountParamName, element); final BigDecimal annualFeeAmount = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(annualFeeAmountParamName, element);
baseDataValidator.reset().parameter(annualFeeAmountParamName).value(annualFeeAmount).notNull().positiveAmount(); baseDataValidator.reset().parameter(annualFeeAmountParamName).value(annualFeeAmount).ignoreIfNull().positiveAmount();
if (annualFeeAmount != null) { if (annualFeeAmount != null) {
MonthDay monthDayOfAnnualFee = fromApiJsonHelper.extractMonthDayNamed(annualFeeOnMonthDayParamName, element); MonthDay monthDayOfAnnualFee = fromApiJsonHelper.extractMonthDayNamed(annualFeeOnMonthDayParamName, element);
@@ -800,6 +800,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
existingReversedTransactionIds.addAll(findExistingReversedTransactionIds()); existingReversedTransactionIds.addAll(findExistingReversedTransactionIds());
final Money amount = Money.of(this.currency, transactionAmount); final Money amount = Money.of(this.currency, transactionAmount);
final SavingsAccountTransaction transaction = SavingsAccountTransaction.deposit(this, paymentDetail, transactionDate, amount); final SavingsAccountTransaction transaction = SavingsAccountTransaction.deposit(this, paymentDetail, transactionDate, amount);
this.transactions.add(transaction); this.transactions.add(transaction);
@@ -877,9 +878,9 @@ public class SavingsAccount extends AbstractPersistable<Long> {
final Money transactionAmountMoney = Money.of(this.currency, transactionAmount); final Money transactionAmountMoney = Money.of(this.currency, transactionAmount);
if (isNotEnoughFundsToWithdraw(transactionAmountMoney)) { if (this.summary.getAccountBalance(this.currency).isLessThan(transactionAmountMoney.plus(this.withdrawalFeeAmount))) {
// //
throw new InsufficientAccountBalanceException("transactionAmount", getAccountBalance(), transactionAmount); throw new InsufficientAccountBalanceException("transactionAmount", getAccountBalance(), this.withdrawalFeeAmount, transactionAmount);
} }
final SavingsAccountTransaction transaction = SavingsAccountTransaction.withdrawal(this, paymentDetail, transactionDate, final SavingsAccountTransaction transaction = SavingsAccountTransaction.withdrawal(this, paymentDetail, transactionDate,
@@ -15,8 +15,8 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRul
*/ */
public class InsufficientAccountBalanceException extends AbstractPlatformDomainRuleException { public class InsufficientAccountBalanceException extends AbstractPlatformDomainRuleException {
public InsufficientAccountBalanceException(final String paramName, final BigDecimal accountBalance, final BigDecimal withdrawalRequested) { public InsufficientAccountBalanceException(final String paramName, final BigDecimal accountBalance, final BigDecimal withdrawalFee, final BigDecimal transactionAmount) {
super("error.msg.savingsaccount.transaction.insufficient.account.balance", "Insufficient account balance.", paramName, super(withdrawalFee != null? "error.msg.savingsaccount.transaction.insufficient.account.balance.withdraw" : "error.msg.savingsaccount.transaction.insufficient.account.balance",
accountBalance, withdrawalRequested); "Insufficient account balance.", paramName, accountBalance, withdrawalFee, transactionAmount);
} }
} }
@@ -9,8 +9,9 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRul
public class InvalidSavingsAccountStateTransitionException extends AbstractPlatformDomainRuleException { public class InvalidSavingsAccountStateTransitionException extends AbstractPlatformDomainRuleException {
public InvalidSavingsAccountStateTransitionException(final String action, String postFix, String defaultUserMessage, Object... defaultUserMessageArgs) { public InvalidSavingsAccountStateTransitionException(final String action, final String postFix, final String defaultUserMessage,
super("error.msg.saving." + action + "." + postFix, defaultUserMessage, defaultUserMessageArgs); final Object... defaultUserMessageArgs) {
} super("error.msg.saving." + action + "." + postFix, defaultUserMessage, defaultUserMessageArgs);
}
} }
@@ -0,0 +1,19 @@
package org.mifosplatform.portfolio.savings.service;
public class SavingStatusMapper {
private final Integer statusId;
public SavingStatusMapper(Integer statusId) {
this.statusId = statusId;
}
public boolean isPendingApproval() {
return Integer.valueOf(100).equals(statusId);
}
public boolean isOpen() {
return Integer.valueOf(300).equals(statusId);
}
}