From d193fcf35f9c36d4ec82c0380102a07bfcb3f4f4 Mon Sep 17 00:00:00 2001 From: Pramod Nuthakki Date: Mon, 5 Aug 2013 11:24:59 +0530 Subject: [PATCH] group retrive accountdetails API changes --- .../StaffAccountSummaryCollectionData.java | 47 +---- .../data/AccountSummaryCollectionData.java | 57 ++++++ .../data/LoanAccountSummaryData.java} | 8 +- .../data/SavingsAccountSummaryData.java} | 8 +- .../accountdetails/domain/AccountType.java | 81 ++++++++ .../AccountDetailsReadPlatformService.java | 18 ++ ...sReadPlatformServiceJpaRepositoryImpl.java | 178 ++++++++++++++++++ .../service/AccountEnumerations.java | 38 ++++ .../client/api/ClientsApiResource.java | 14 +- .../ClientAccountSummaryCollectionData.java | 33 ---- .../service/ClientReadPlatformService.java | 8 +- .../ClientReadPlatformServiceImpl.java | 131 +------------ .../group/api/CentersApiResource.java | 43 ++--- .../group/api/GroupsApiResource.java | 22 ++- .../GroupAccountSummaryCollectionData.java | 101 ---------- .../group/data/GroupAccountSummaryData.java | 50 ----- .../service/GroupReadPlatformService.java | 9 - .../service/GroupReadPlatformServiceImpl.java | 119 ------------ .../portfolio/loanaccount/domain/Loan.java | 3 +- .../loanaccount/domain/LoanType.java | 81 -------- ...anApplicationCommandFromApiJsonHelper.java | 10 +- .../BulkLoansReadPlatformServiceImpl.java | 38 ++-- .../loanaccount/service/LoanAssembler.java | 4 +- .../service/LoanReadPlatformServiceImpl.java | 3 +- ...WritePlatformServiceJpaRepositoryImpl.java | 14 +- .../loanproduct/service/LoanEnumerations.java | 34 +--- .../domain/SavingsAccountAssembler.java | 5 + 27 files changed, 478 insertions(+), 679 deletions(-) create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/data/AccountSummaryCollectionData.java rename mifosng-provider/src/main/java/org/mifosplatform/portfolio/{client/data/ClientLoanAccountSummaryData.java => accountdetails/data/LoanAccountSummaryData.java} (80%) rename mifosng-provider/src/main/java/org/mifosplatform/portfolio/{client/data/ClientSavingsAccountSummaryData.java => accountdetails/data/SavingsAccountSummaryData.java} (80%) create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/domain/AccountType.java create mode 100755 mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/service/AccountDetailsReadPlatformService.java create mode 100755 mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/service/AccountDetailsReadPlatformServiceJpaRepositoryImpl.java create mode 100755 mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/service/AccountEnumerations.java delete mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientAccountSummaryCollectionData.java delete mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupAccountSummaryCollectionData.java delete mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupAccountSummaryData.java delete mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/LoanType.java diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/data/StaffAccountSummaryCollectionData.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/data/StaffAccountSummaryCollectionData.java index bb4fbb40d..0fd820705 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/data/StaffAccountSummaryCollectionData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/data/StaffAccountSummaryCollectionData.java @@ -8,8 +8,7 @@ package org.mifosplatform.organisation.staff.data; import java.util.Collection; import java.util.List; -import org.mifosplatform.portfolio.client.data.ClientLoanAccountSummaryData; -import org.mifosplatform.portfolio.group.data.GroupAccountSummaryData; +import org.mifosplatform.portfolio.accountdetails.data.LoanAccountSummaryData; /** * @@ -17,23 +16,23 @@ import org.mifosplatform.portfolio.group.data.GroupAccountSummaryData; public class StaffAccountSummaryCollectionData { @SuppressWarnings("unused") - private final List clients; + private final List clients; @SuppressWarnings("unused") - private final List groups; + private final List groups; - public StaffAccountSummaryCollectionData(final List clients, final List groups) { + public StaffAccountSummaryCollectionData(final List clients, final List groups) { this.clients = clients; this.groups = groups; } - public static final class ClientSummary { + public static final class LoanAccountSummary { private final Long id; private final String displayName; - private Collection loans; + private Collection loans; - public ClientSummary(Long id, String displayName) { + public LoanAccountSummary(Long id, String displayName) { this.id = id; this.displayName = displayName; } @@ -46,41 +45,13 @@ public class StaffAccountSummaryCollectionData { return displayName; } - public Collection getLoans() { + public Collection getLoans() { return loans; } - public void setLoans(Collection loans) { + public void setLoans(Collection loans) { this.loans = loans; } } - public static final class GroupSummary { - - private final Long id; - private final String name; - - private Collection loans; - - public GroupSummary(Long id, String name) { - this.id = id; - this.name = name; - } - - public Long getId() { - return id; - } - - public String getName() { - return name; - } - - public Collection getLoans() { - return loans; - } - - public void setLoans(Collection loans) { - this.loans = loans; - } - } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/data/AccountSummaryCollectionData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/data/AccountSummaryCollectionData.java new file mode 100644 index 000000000..dd4b59650 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/data/AccountSummaryCollectionData.java @@ -0,0 +1,57 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.mifosplatform.portfolio.accountdetails.data; + +import java.util.Collection; + +/** + * Immutable data object representing a summary of various accounts. + */ +public class AccountSummaryCollectionData { + + @SuppressWarnings("unused") + private final Collection loanAccounts; + @SuppressWarnings("unused") + private final Collection savingsAccounts; + @SuppressWarnings("unused") + private final Collection memberLoanAccounts; + @SuppressWarnings("unused") + private final Collection memberSavingsAccounts; + + public AccountSummaryCollectionData(final Collection loanAccounts, + final Collection savingsAccounts) { + this.loanAccounts = defaultLoanAccountsIfEmpty(loanAccounts); + this.savingsAccounts = defaultSavingsAccountsIfEmpty(savingsAccounts); + this.memberLoanAccounts = null; + this.memberSavingsAccounts = null; + } + + public AccountSummaryCollectionData(final Collection loanAccounts, + final Collection savingsAccounts, final Collection memberLoanAccounts, + Collection memberSavingsAccounts) { + this.loanAccounts = defaultLoanAccountsIfEmpty(loanAccounts); + this.savingsAccounts = defaultSavingsAccountsIfEmpty(savingsAccounts); + this.memberLoanAccounts = defaultLoanAccountsIfEmpty(memberLoanAccounts); + this.memberSavingsAccounts = defaultSavingsAccountsIfEmpty(memberSavingsAccounts); + } + + private Collection defaultLoanAccountsIfEmpty(final Collection collection) { + Collection returnCollection = null; + if (collection != null && !collection.isEmpty()) { + returnCollection = collection; + } + return returnCollection; + } + + private Collection defaultSavingsAccountsIfEmpty(final Collection collection) { + Collection returnCollection = null; + if (collection != null && !collection.isEmpty()) { + returnCollection = collection; + } + return returnCollection; + } + +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientLoanAccountSummaryData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/data/LoanAccountSummaryData.java similarity index 80% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientLoanAccountSummaryData.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/data/LoanAccountSummaryData.java index 990de0c62..15a64d472 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientLoanAccountSummaryData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/data/LoanAccountSummaryData.java @@ -3,16 +3,16 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.mifosplatform.portfolio.client.data; +package org.mifosplatform.portfolio.accountdetails.data; import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.portfolio.loanaccount.data.LoanStatusEnumData; /** - * Immutable data object for client loan accounts. + * Immutable data object for loan accounts. */ @SuppressWarnings("unused") -public class ClientLoanAccountSummaryData { +public class LoanAccountSummaryData { private final Long id; private final String accountNo; @@ -23,7 +23,7 @@ public class ClientLoanAccountSummaryData { private final EnumOptionData loanType; private final Integer loanCycle; - public ClientLoanAccountSummaryData(final Long id, final String accountNo, final String externalId, final Long productId, + public LoanAccountSummaryData(final Long id, final String accountNo, final String externalId, final Long productId, final String loanProductName, final LoanStatusEnumData loanStatus, final EnumOptionData loanType, final Integer loanCycle) { this.id = id; this.accountNo = accountNo; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientSavingsAccountSummaryData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/data/SavingsAccountSummaryData.java similarity index 80% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientSavingsAccountSummaryData.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/data/SavingsAccountSummaryData.java index 711969e04..dc5cde49b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientSavingsAccountSummaryData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/data/SavingsAccountSummaryData.java @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.mifosplatform.portfolio.client.data; +package org.mifosplatform.portfolio.accountdetails.data; import java.math.BigDecimal; @@ -11,10 +11,10 @@ import org.mifosplatform.organisation.monetary.data.CurrencyData; import org.mifosplatform.portfolio.savings.data.SavingsAccountStatusEnumData; /** - * Immutable data object for client savings accounts. + * Immutable data object for savings accounts. */ @SuppressWarnings("unused") -public class ClientSavingsAccountSummaryData { +public class SavingsAccountSummaryData { private final Long id; private final String accountNo; @@ -25,7 +25,7 @@ public class ClientSavingsAccountSummaryData { private final CurrencyData currency; private final BigDecimal accountBalance; - public ClientSavingsAccountSummaryData(final Long id, final String accountNo, final String externalId, final Long productId, + public SavingsAccountSummaryData(final Long id, final String accountNo, final String externalId, final Long productId, final String productName, final SavingsAccountStatusEnumData status, final CurrencyData currency, final BigDecimal accountBalance) { this.id = id; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/domain/AccountType.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/domain/AccountType.java new file mode 100644 index 000000000..02ba6955e --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/domain/AccountType.java @@ -0,0 +1,81 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.mifosplatform.portfolio.accountdetails.domain; + +/** + * Enum representation of account types . + */ +public enum AccountType { + + INVALID(0, "accountType.invalid"), // + INDIVIDUAL(1, "accountType.individual"), // + GROUP(2, "accountType.group"), // + JLG(3, "accountType.jlg");//JLG account given in group context + + private final Integer value; + private final String code; + + private AccountType(final Integer value, final String code) { + this.value = value; + this.code = code; + } + + public static AccountType fromInt(final Integer accountTypeValue) { + + AccountType enumeration = AccountType.INVALID; + switch (accountTypeValue) { + case 1: + enumeration = AccountType.INDIVIDUAL; + break; + case 2: + enumeration = AccountType.GROUP; + break; + case 3: + enumeration = AccountType.JLG; + break; + } + return enumeration; + } + + public static AccountType fromName(final String name){ + AccountType accountType = AccountType.INVALID; + for (AccountType type : AccountType.values()) { + if(type.getName().equals(name)) { + accountType = type; + break; + } + } + return accountType; + } + + public Integer getValue() { + return this.value; + } + + public String getCode() { + return code; + } + + public String getName(){ + return name().toLowerCase(); + } + + public boolean isInvalid(){ + return this.value.equals(AccountType.INVALID.getValue()); + } + + public boolean isIndividualAccount(){ + return this.value.equals(AccountType.INDIVIDUAL.getValue()); + } + + public boolean isGroupAccount(){ + return this.value.equals(AccountType.GROUP.getValue()); + } + + public boolean isJLGAccount(){ + return this.value.equals(AccountType.JLG.getValue()); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/service/AccountDetailsReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/service/AccountDetailsReadPlatformService.java new file mode 100755 index 000000000..ad918f046 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/service/AccountDetailsReadPlatformService.java @@ -0,0 +1,18 @@ +package org.mifosplatform.portfolio.accountdetails.service; + +import java.util.Collection; + +import org.mifosplatform.portfolio.accountdetails.data.AccountSummaryCollectionData; +import org.mifosplatform.portfolio.accountdetails.data.LoanAccountSummaryData; + + +public interface AccountDetailsReadPlatformService { + + public AccountSummaryCollectionData retrieveClientAccountDetails(final Long clientId); + + public AccountSummaryCollectionData retrieveGroupAccountDetails(final Long groupId); + + public Collection retrieveClientLoanAccountsByLoanOfficerId(final Long clientId, final Long loanOfficerId); + + public Collection retrieveGroupLoanAccountsByLoanOfficerId(final Long groupId,final Long loanOfficerId); +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/service/AccountDetailsReadPlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/service/AccountDetailsReadPlatformServiceJpaRepositoryImpl.java new file mode 100755 index 000000000..3e99e27a5 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/service/AccountDetailsReadPlatformServiceJpaRepositoryImpl.java @@ -0,0 +1,178 @@ +package org.mifosplatform.portfolio.accountdetails.service; + +import java.math.BigDecimal; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; +import java.util.List; + +import org.mifosplatform.infrastructure.core.data.EnumOptionData; +import org.mifosplatform.infrastructure.core.domain.JdbcSupport; +import org.mifosplatform.infrastructure.core.service.RoutingDataSource; +import org.mifosplatform.organisation.monetary.data.CurrencyData; +import org.mifosplatform.portfolio.accountdetails.data.AccountSummaryCollectionData; +import org.mifosplatform.portfolio.accountdetails.data.LoanAccountSummaryData; +import org.mifosplatform.portfolio.accountdetails.data.SavingsAccountSummaryData; +import org.mifosplatform.portfolio.client.service.ClientReadPlatformService; +import org.mifosplatform.portfolio.group.service.GroupReadPlatformService; +import org.mifosplatform.portfolio.loanaccount.data.LoanStatusEnumData; +import org.mifosplatform.portfolio.loanproduct.service.LoanEnumerations; +import org.mifosplatform.portfolio.savings.data.SavingsAccountStatusEnumData; +import org.mifosplatform.portfolio.savings.service.SavingsEnumerations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.stereotype.Service; + +@Service +public class AccountDetailsReadPlatformServiceJpaRepositoryImpl implements AccountDetailsReadPlatformService { + + private final JdbcTemplate jdbcTemplate; + private final ClientReadPlatformService clientReadPlatformService; + private final GroupReadPlatformService groupReadPlatformService; + + @Autowired + public AccountDetailsReadPlatformServiceJpaRepositoryImpl(final ClientReadPlatformService clientReadPlatformService, + final RoutingDataSource dataSource, final GroupReadPlatformService groupReadPlatformService) { + this.clientReadPlatformService = clientReadPlatformService; + this.jdbcTemplate = new JdbcTemplate(dataSource); + this.groupReadPlatformService = groupReadPlatformService; + } + + @Override + public AccountSummaryCollectionData retrieveClientAccountDetails(Long clientId) { + // Check if client exists + clientReadPlatformService.retrieveOne(clientId); + String loanwhereClause = " where l.client_id = ?"; + String savingswhereClause = " where sa.client_id = ? order by sa.status_enum ASC, sa.account_no ASC"; + List loanAccounts = retrieveLoanAccountDetails(loanwhereClause, new Object[] { clientId }); + List savingsAccounts = retrieveAccountDetails(savingswhereClause, new Object[] { clientId }); + return new AccountSummaryCollectionData(loanAccounts, savingsAccounts); + } + + @Override + public AccountSummaryCollectionData retrieveGroupAccountDetails(Long groupId) { + // Check if group exists + groupReadPlatformService.retrieveOne(groupId); + String loanWhereClauseForGroup = " where l.group_id = ? and l.client_id is null"; + String loanWhereClauseForMembers = " where l.group_id = ? and l.client_id is not null"; + String savingswhereClauseForGroup = " where sa.group_id = ? and sa.client_id is null order by sa.status_enum ASC, sa.account_no ASC"; + String savingswhereClauseForMembers = " where sa.group_id = ? and sa.client_id is not null order by sa.status_enum ASC, sa.account_no ASC"; + List groupLoanAccounts = retrieveLoanAccountDetails(loanWhereClauseForGroup, new Object[] { groupId }); + List groupSavingsAccounts = retrieveAccountDetails(savingswhereClauseForGroup, new Object[] { groupId }); + List memberLoanAccounts = retrieveLoanAccountDetails(loanWhereClauseForMembers, new Object[] { groupId }); + List memberSavingsAccounts = retrieveAccountDetails(savingswhereClauseForMembers, + new Object[] { groupId }); + return new AccountSummaryCollectionData(groupLoanAccounts, groupSavingsAccounts,memberLoanAccounts, memberSavingsAccounts); + } + + @Override + public Collection retrieveClientLoanAccountsByLoanOfficerId(final Long clientId, final Long loanOfficerId) { + // Check if client exists + clientReadPlatformService.retrieveOne(clientId); + String loanWhereClause = " where l.client_id = ? and l.loan_officer_id = ?"; + return retrieveLoanAccountDetails(loanWhereClause, new Object[] { clientId, loanOfficerId }); + } + + @Override + public Collection retrieveGroupLoanAccountsByLoanOfficerId(final Long groupId, final Long loanOfficerId) { + // Check if group exists + groupReadPlatformService.retrieveOne(groupId); + String loanWhereClause = " where l.group_id = ? and l.client_id is null and l.loan_officer_id = ?"; + return retrieveLoanAccountDetails(loanWhereClause, new Object[] { groupId, loanOfficerId }); + } + + private List retrieveLoanAccountDetails(String loanwhereClause, Object[] inputs) { + LoanAccountSummaryDataMapper rm = new LoanAccountSummaryDataMapper(); + String sql = "select " + rm.loanAccountSummarySchema() + loanwhereClause; + return this.jdbcTemplate.query(sql, rm, inputs); + } + + /** + * @param entityId + * @return + */ + private List retrieveAccountDetails(String savingswhereClause, Object[] inputs) { + SavingsAccountSummaryDataMapper savingsAccountSummaryDataMapper = new SavingsAccountSummaryDataMapper(); + final String savingsSql = "select " + savingsAccountSummaryDataMapper.schema() + savingswhereClause; + return this.jdbcTemplate.query(savingsSql, savingsAccountSummaryDataMapper, inputs); + } + + private static final class SavingsAccountSummaryDataMapper implements RowMapper { + + final String schemaSql; + + public SavingsAccountSummaryDataMapper() { + StringBuilder accountsSummary = new StringBuilder(); + accountsSummary.append("sa.id as id, sa.account_no as accountNo, sa.external_id as externalId, sa.status_enum as statusEnum, "); + accountsSummary.append("sa.account_balance_derived as accountBalance, "); + accountsSummary.append("sa.currency_code as currencyCode, sa.currency_digits as currencyDigits, "); + accountsSummary.append("curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, "); + accountsSummary.append("curr.display_symbol as currencyDisplaySymbol, "); + accountsSummary.append("sa.product_id as productId, p.name as productName "); + 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_currency curr on curr.code = sa.currency_code "); + + this.schemaSql = accountsSummary.toString(); + } + + public String schema() { + return this.schemaSql; + } + + @Override + public SavingsAccountSummaryData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { + + final Long id = JdbcSupport.getLong(rs, "id"); + final String accountNo = rs.getString("accountNo"); + final String externalId = rs.getString("externalId"); + final Long productId = JdbcSupport.getLong(rs, "productId"); + final String productName = rs.getString("productName"); + final Integer statusId = JdbcSupport.getInteger(rs, "statusEnum"); + final BigDecimal accountBalance = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "accountBalance"); + final SavingsAccountStatusEnumData status = SavingsEnumerations.status(statusId); + + final String currencyCode = rs.getString("currencyCode"); + final String currencyName = rs.getString("currencyName"); + final String currencyNameCode = rs.getString("currencyNameCode"); + final String currencyDisplaySymbol = rs.getString("currencyDisplaySymbol"); + final Integer currencyDigits = JdbcSupport.getInteger(rs, "currencyDigits"); + final CurrencyData currency = new CurrencyData(currencyCode, currencyName, currencyDigits, currencyDisplaySymbol, + currencyNameCode); + + return new SavingsAccountSummaryData(id, accountNo, externalId, productId, productName, status, currency, accountBalance); + } + } + + private static final class LoanAccountSummaryDataMapper implements RowMapper { + + public String loanAccountSummarySchema() { + + 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, ").append("l.loan_product_counter as loanCycle ") + .append(" from m_loan l ").append("LEFT JOIN m_product_loan AS lp ON lp.id = l.product_id"); + + return accountsSummary.toString(); + } + + @Override + public LoanAccountSummaryData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { + + final Long id = JdbcSupport.getLong(rs, "id"); + final String accountNo = rs.getString("accountNo"); + final String externalId = rs.getString("externalId"); + final Long productId = JdbcSupport.getLong(rs, "productId"); + final String loanProductName = rs.getString("productName"); + final Integer loanStatusId = JdbcSupport.getInteger(rs, "statusId"); + final LoanStatusEnumData loanStatus = LoanEnumerations.status(loanStatusId); + final Integer loanTypeId = JdbcSupport.getInteger(rs, "loanType"); + final EnumOptionData loanType = AccountEnumerations.loanType(loanTypeId); + final Integer loanCycle = JdbcSupport.getInteger(rs, "loanCycle"); + + return new LoanAccountSummaryData(id, accountNo, externalId, productId, loanProductName, loanStatus, loanType, loanCycle); + } + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/service/AccountEnumerations.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/service/AccountEnumerations.java new file mode 100755 index 000000000..119d3c8a4 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/accountdetails/service/AccountEnumerations.java @@ -0,0 +1,38 @@ +package org.mifosplatform.portfolio.accountdetails.service; + +import org.mifosplatform.infrastructure.core.data.EnumOptionData; +import org.mifosplatform.portfolio.accountdetails.domain.AccountType; + + +public class AccountEnumerations { + + public static EnumOptionData loanType(final Integer loanTypeId) { + return loanType(AccountType.fromInt(loanTypeId)); + } + + public static EnumOptionData loanType(final String name) { + return loanType(AccountType.fromName(name)); + } + + public static EnumOptionData loanType(final AccountType type) { + EnumOptionData optionData = new EnumOptionData(AccountType.INVALID.getValue().longValue(), AccountType.INVALID.getCode(), "Invalid"); + switch (type) { + case INVALID: + optionData = new EnumOptionData(AccountType.INVALID.getValue().longValue(), AccountType.INVALID.getCode(), "Invalid"); + break; + case INDIVIDUAL: + optionData = new EnumOptionData(AccountType.INDIVIDUAL.getValue().longValue(), AccountType.INDIVIDUAL.getCode(), "Individual"); + break; + case GROUP: + optionData = new EnumOptionData(AccountType.GROUP.getValue().longValue(), AccountType.GROUP.getCode(), "Group"); + break; + case JLG: + optionData = new EnumOptionData(AccountType.JLG.getValue().longValue(), AccountType.JLG.getCode(), "JLG"); + break; + } + + return optionData; + } + + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientsApiResource.java index 9309e030d..a760e9e6d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientsApiResource.java @@ -34,7 +34,8 @@ import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSeriali import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer; import org.mifosplatform.infrastructure.core.service.Page; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; -import org.mifosplatform.portfolio.client.data.ClientAccountSummaryCollectionData; +import org.mifosplatform.portfolio.accountdetails.data.AccountSummaryCollectionData; +import org.mifosplatform.portfolio.accountdetails.service.AccountDetailsReadPlatformService; import org.mifosplatform.portfolio.client.data.ClientData; import org.mifosplatform.portfolio.client.service.ClientReadPlatformService; import org.mifosplatform.portfolio.group.service.SearchParameters; @@ -50,22 +51,25 @@ public class ClientsApiResource { private final PlatformSecurityContext context; private final ClientReadPlatformService clientReadPlatformService; private final ToApiJsonSerializer toApiJsonSerializer; - private final ToApiJsonSerializer clientAccountSummaryToApiJsonSerializer; + private final ToApiJsonSerializer clientAccountSummaryToApiJsonSerializer; private final ApiRequestParameterHelper apiRequestParameterHelper; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + private final AccountDetailsReadPlatformService accountDetailsReadPlatformService; @Autowired public ClientsApiResource(final PlatformSecurityContext context, final ClientReadPlatformService readPlatformService, final ToApiJsonSerializer toApiJsonSerializer, - final ToApiJsonSerializer clientAccountSummaryToApiJsonSerializer, + final ToApiJsonSerializer clientAccountSummaryToApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper, - final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) { + final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, + final AccountDetailsReadPlatformService accountDetailsReadPlatformService) { this.context = context; this.clientReadPlatformService = readPlatformService; this.toApiJsonSerializer = toApiJsonSerializer; this.clientAccountSummaryToApiJsonSerializer = clientAccountSummaryToApiJsonSerializer; this.apiRequestParameterHelper = apiRequestParameterHelper; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + this.accountDetailsReadPlatformService = accountDetailsReadPlatformService; } @GET @@ -223,7 +227,7 @@ public class ClientsApiResource { context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_RESOURCE_NAME); - final ClientAccountSummaryCollectionData clientAccount = this.clientReadPlatformService.retrieveClientAccountDetails(clientId); + final AccountSummaryCollectionData clientAccount = this.accountDetailsReadPlatformService.retrieveClientAccountDetails(clientId); final Set CLIENT_ACCOUNTS_DATA_PARAMETERS = new HashSet(Arrays.asList("loanAccounts", "savingsAccounts")); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientAccountSummaryCollectionData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientAccountSummaryCollectionData.java deleted file mode 100644 index 239b96947..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientAccountSummaryCollectionData.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.client.data; - -import java.util.Collection; - -/** - * Immutable data object representing a summary of a clients various accounts. - */ -public class ClientAccountSummaryCollectionData { - - @SuppressWarnings("unused") - private final Collection loanAccounts; - @SuppressWarnings("unused") - private final Collection savingsAccounts; - - public ClientAccountSummaryCollectionData(final Collection loanAccounts, - final Collection savingsAccounts) { - this.loanAccounts = defaultIfEmpty(loanAccounts); - this.savingsAccounts = savingsAccounts; - } - - private Collection defaultIfEmpty(final Collection collection) { - Collection returnCollection = null; - if (collection != null && !collection.isEmpty()) { - returnCollection = collection; - } - return returnCollection; - } -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformService.java index 29b15bb45..4a60e8e86 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformService.java @@ -8,8 +8,6 @@ package org.mifosplatform.portfolio.client.service; import java.util.Collection; import org.mifosplatform.infrastructure.core.service.Page; -import org.mifosplatform.portfolio.client.data.ClientAccountSummaryCollectionData; -import org.mifosplatform.portfolio.client.data.ClientLoanAccountSummaryData; import org.mifosplatform.portfolio.client.data.ClientData; import org.mifosplatform.portfolio.group.service.SearchParameters; @@ -25,14 +23,10 @@ public interface ClientReadPlatformService { Collection retrieveAllForLookupByOfficeId(Long officeId); - ClientAccountSummaryCollectionData retrieveClientAccountDetails(Long clientId); - - Collection retrieveClientLoanAccountsByLoanOfficerId(Long clientId, Long loanOfficerId); - ClientData retrieveClientByIdentifier(Long identifierTypeId, String identifierKey); Collection retrieveClientMembersOfGroup(Long groupId); - + Collection retrieveActiveClientMembersOfGroup(Long groupId); ClientData retrieveAllClosureReasons(String clientClosureReason); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformServiceImpl.java index 6d9ea0746..d334b2ba8 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientReadPlatformServiceImpl.java @@ -5,7 +5,6 @@ */ package org.mifosplatform.portfolio.client.service; -import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; @@ -23,24 +22,16 @@ import org.mifosplatform.infrastructure.core.service.Page; import org.mifosplatform.infrastructure.core.service.PaginationHelper; import org.mifosplatform.infrastructure.core.service.RoutingDataSource; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; -import org.mifosplatform.organisation.monetary.data.CurrencyData; import org.mifosplatform.organisation.office.data.OfficeData; import org.mifosplatform.organisation.office.service.OfficeReadPlatformService; import org.mifosplatform.organisation.staff.data.StaffData; import org.mifosplatform.organisation.staff.service.StaffReadPlatformService; -import org.mifosplatform.portfolio.client.data.ClientAccountSummaryCollectionData; -import org.mifosplatform.portfolio.client.data.ClientLoanAccountSummaryData; import org.mifosplatform.portfolio.client.data.ClientData; -import org.mifosplatform.portfolio.client.data.ClientSavingsAccountSummaryData; import org.mifosplatform.portfolio.client.domain.ClientEnumerations; import org.mifosplatform.portfolio.client.domain.ClientStatus; import org.mifosplatform.portfolio.client.exception.ClientNotFoundException; import org.mifosplatform.portfolio.group.data.GroupGeneralData; import org.mifosplatform.portfolio.group.service.SearchParameters; -import org.mifosplatform.portfolio.loanaccount.data.LoanStatusEnumData; -import org.mifosplatform.portfolio.loanproduct.service.LoanEnumerations; -import org.mifosplatform.portfolio.savings.data.SavingsAccountStatusEnumData; -import org.mifosplatform.portfolio.savings.service.SavingsEnumerations; import org.mifosplatform.useradministration.domain.AppUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.EmptyResultDataAccessException; @@ -63,7 +54,6 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService private final ClientLookupMapper lookupMapper = new ClientLookupMapper(); private final ClientMembersOfGroupMapper membersOfGroupMapper = new ClientMembersOfGroupMapper(); private final ParentGroupsMapper clientGroupsMapper = new ParentGroupsMapper(); - private final ClientSavingsAccountSummaryDataMapper savingsAccountSummaryDataMapper = new ClientSavingsAccountSummaryDataMapper(); @Autowired public ClientReadPlatformServiceImpl(final PlatformSecurityContext context, final RoutingDataSource dataSource, @@ -255,7 +245,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService return this.jdbcTemplate.query(sql, this.membersOfGroupMapper, new Object[] { hierarchySearchString, groupId, ClientStatus.ACTIVE.getValue() }); } - + private static final class ClientMembersOfGroupMapper implements RowMapper { private final String schema; @@ -407,125 +397,6 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService } } - @Override - public ClientAccountSummaryCollectionData retrieveClientAccountDetails(final Long clientId) { - - try { - // Check if client exists - retrieveOne(clientId); - - ClientLoanAccountSummaryDataMapper rm = new ClientLoanAccountSummaryDataMapper(); - - String sql = "select " + rm.loanAccountSummarySchema() + " where l.client_id = ?"; - - List allLoanAccounts = this.jdbcTemplate.query(sql, rm, new Object[] { clientId }); - - final String savingsSql = "select " + this.savingsAccountSummaryDataMapper.schema() - + " where sa.client_id = ? order by sa.status_enum ASC, sa.account_no ASC"; - - final List allSavingsAccounts = this.jdbcTemplate.query(savingsSql, - savingsAccountSummaryDataMapper, new Object[] { clientId }); - - return new ClientAccountSummaryCollectionData(allLoanAccounts, allSavingsAccounts); - } catch (EmptyResultDataAccessException e) { - throw new ClientNotFoundException(clientId); - } - } - - @Override - public Collection retrieveClientLoanAccountsByLoanOfficerId(final Long clientId, final Long loanOfficerId) { - - this.context.authenticatedUser(); - - // Check if client exists - retrieveOne(clientId); - - ClientLoanAccountSummaryDataMapper rm = new ClientLoanAccountSummaryDataMapper(); - - String sql = "select " + rm.loanAccountSummarySchema() + " where l.client_id = ? and l.loan_officer_id = ?"; - - List loanAccounts = this.jdbcTemplate.query(sql, rm, new Object[] { clientId, loanOfficerId }); - - return loanAccounts; - } - - private static final class ClientSavingsAccountSummaryDataMapper implements RowMapper { - - final String schemaSql; - - public ClientSavingsAccountSummaryDataMapper() { - StringBuilder accountsSummary = new StringBuilder(); - accountsSummary.append("sa.id as id, sa.account_no as accountNo, sa.external_id as externalId, sa.status_enum as statusEnum, "); - accountsSummary.append("sa.account_balance_derived as accountBalance, "); - accountsSummary.append("sa.currency_code as currencyCode, sa.currency_digits as currencyDigits, "); - accountsSummary.append("curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, "); - accountsSummary.append("curr.display_symbol as currencyDisplaySymbol, "); - accountsSummary.append("sa.product_id as productId, p.name as productName "); - 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_currency curr on curr.code = sa.currency_code "); - - this.schemaSql = accountsSummary.toString(); - } - - public String schema() { - return this.schemaSql; - } - - @Override - public ClientSavingsAccountSummaryData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { - - final Long id = JdbcSupport.getLong(rs, "id"); - final String accountNo = rs.getString("accountNo"); - final String externalId = rs.getString("externalId"); - final Long productId = JdbcSupport.getLong(rs, "productId"); - final String productName = rs.getString("productName"); - final Integer statusId = JdbcSupport.getInteger(rs, "statusEnum"); - final BigDecimal accountBalance = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "accountBalance"); - final SavingsAccountStatusEnumData status = SavingsEnumerations.status(statusId); - - final String currencyCode = rs.getString("currencyCode"); - final String currencyName = rs.getString("currencyName"); - final String currencyNameCode = rs.getString("currencyNameCode"); - final String currencyDisplaySymbol = rs.getString("currencyDisplaySymbol"); - final Integer currencyDigits = JdbcSupport.getInteger(rs, "currencyDigits"); - final CurrencyData currency = new CurrencyData(currencyCode, currencyName, currencyDigits, currencyDisplaySymbol, - currencyNameCode); - - return new ClientSavingsAccountSummaryData(id, accountNo, externalId, productId, productName, status, currency, accountBalance); - } - } - - private static final class ClientLoanAccountSummaryDataMapper implements RowMapper { - - public String loanAccountSummarySchema() { - - 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, ").append("l.loan_product_counter as loanCycle ") - .append(" from m_loan l ").append("LEFT JOIN m_product_loan AS lp ON lp.id = l.product_id"); - - return accountsSummary.toString(); - } - - @Override - public ClientLoanAccountSummaryData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { - - final Long id = JdbcSupport.getLong(rs, "id"); - final String accountNo = rs.getString("accountNo"); - final String externalId = rs.getString("externalId"); - final Long productId = JdbcSupport.getLong(rs, "productId"); - final String loanProductName = rs.getString("productName"); - final Integer loanStatusId = JdbcSupport.getInteger(rs, "statusId"); - final LoanStatusEnumData loanStatus = LoanEnumerations.status(loanStatusId); - final Integer loanTypeId = JdbcSupport.getInteger(rs, "loanType"); - final EnumOptionData loanType = LoanEnumerations.loanType(loanTypeId); - final Integer loanCycle = JdbcSupport.getInteger(rs, "loanCycle"); - - return new ClientLoanAccountSummaryData(id, accountNo, externalId, productId, loanProductName, loanStatus, loanType, loanCycle); - } - } - @Override public ClientData retrieveClientByIdentifier(final Long identifierTypeId, final String identifierKey) { try { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.java index 03bbec3ee..f363af10a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.java @@ -36,12 +36,12 @@ import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer; import org.mifosplatform.infrastructure.core.service.Page; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; +import org.mifosplatform.portfolio.accountdetails.data.AccountSummaryCollectionData; +import org.mifosplatform.portfolio.accountdetails.service.AccountDetailsReadPlatformService; import org.mifosplatform.portfolio.collectionsheet.data.JLGCollectionSheetData; import org.mifosplatform.portfolio.collectionsheet.service.CollectionSheetReadPlatformService; import org.mifosplatform.portfolio.group.data.CenterData; -import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData; import org.mifosplatform.portfolio.group.service.CenterReadPlatformService; -import org.mifosplatform.portfolio.group.service.GroupReadPlatformService; import org.mifosplatform.portfolio.group.service.SearchParameters; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; @@ -56,26 +56,25 @@ public class CentersApiResource { private final PlatformSecurityContext context; private final CenterReadPlatformService centerReadPlatformService; - private final GroupReadPlatformService groupReadPlatformService; private final ToApiJsonSerializer centerApiJsonSerializer; private final ToApiJsonSerializer toApiJsonSerializer; - private final ToApiJsonSerializer groupSummaryToApiJsonSerializer; + private final ToApiJsonSerializer groupSummaryToApiJsonSerializer; private final ApiRequestParameterHelper apiRequestParameterHelper; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final CollectionSheetReadPlatformService collectionSheetReadPlatformService; private final FromJsonHelper fromJsonHelper; + private final AccountDetailsReadPlatformService accountDetailsReadPlatformService; @Autowired public CentersApiResource(final PlatformSecurityContext context, final CenterReadPlatformService centerReadPlatformService, - final GroupReadPlatformService groupReadPlatformService, final ToApiJsonSerializer centerApiJsonSerializer, - final ToApiJsonSerializer toApiJsonSerializer, - final ToApiJsonSerializer groupSummaryToApiJsonSerializer, + final ToApiJsonSerializer centerApiJsonSerializer, final ToApiJsonSerializer toApiJsonSerializer, + final ToApiJsonSerializer groupSummaryToApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, - final CollectionSheetReadPlatformService collectionSheetReadPlatformService, final FromJsonHelper fromJsonHelper) { + final CollectionSheetReadPlatformService collectionSheetReadPlatformService, final FromJsonHelper fromJsonHelper, + final AccountDetailsReadPlatformService accountDetailsReadPlatformService) { this.context = context; this.centerReadPlatformService = centerReadPlatformService; - this.groupReadPlatformService = groupReadPlatformService; this.centerApiJsonSerializer = centerApiJsonSerializer; this.toApiJsonSerializer = toApiJsonSerializer; this.groupSummaryToApiJsonSerializer = groupSummaryToApiJsonSerializer; @@ -83,6 +82,7 @@ public class CentersApiResource { this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.collectionSheetReadPlatformService = collectionSheetReadPlatformService; this.fromJsonHelper = fromJsonHelper; + this.accountDetailsReadPlatformService = accountDetailsReadPlatformService; } @GET @@ -126,7 +126,7 @@ public class CentersApiResource { this.context.authenticatedUser().validateHasReadPermission(GroupingTypesApiConstants.CENTER_RESOURCE_NAME); final Set associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters()); - + CenterData center = this.centerReadPlatformService.retrieveOne(centerId); final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters()); @@ -134,7 +134,7 @@ public class CentersApiResource { final CenterData templateCenter = this.centerReadPlatformService.retrieveTemplate(center.officeId()); center = CenterData.withTemplate(templateCenter, center); } - + if (!associationParameters.isEmpty()) { if (associationParameters.contains("groupMembers")) { center = CenterData.setGroups(center, this.centerReadPlatformService.retrieveAssociatedGroups(centerId)); @@ -200,18 +200,20 @@ public class CentersApiResource { final CommandWrapper commandRequest = builder.activateCenter(centerId).build(); result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); - }else if (is(commandParam, "generateCollectionSheet")) { + } else if (is(commandParam, "generateCollectionSheet")) { final JsonElement parsedQuery = this.fromJsonHelper.parse(apiRequestBodyAsJson); final JsonQuery query = JsonQuery.from(apiRequestBodyAsJson, parsedQuery, this.fromJsonHelper); - final JLGCollectionSheetData collectionSheet = this.collectionSheetReadPlatformService.generateCenterCollectionSheet(centerId, query); + final JLGCollectionSheetData collectionSheet = this.collectionSheetReadPlatformService.generateCenterCollectionSheet(centerId, + query); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.toApiJsonSerializer.serialize(settings, collectionSheet, GroupingTypesApiConstants.COLLECTIONSHEET_DATA_PARAMETERS); - }else if (is(commandParam, "saveCollectionSheet")) { + } else if (is(commandParam, "saveCollectionSheet")) { final CommandWrapper commandRequest = builder.saveCenterCollectionSheet(centerId).build(); result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); - } else { - throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate", "generateCollectionSheet", "createRole" }); + } else { + throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate", "generateCollectionSheet", + "createRole" }); } } @@ -221,18 +223,17 @@ public class CentersApiResource { } @GET - @Path("{centerId}/loans") + @Path("{centerId}/accounts") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String retrieveGroupAccount(@PathParam("centerId") final Long centerId, @Context final UriInfo uriInfo) { this.context.authenticatedUser().validateHasReadPermission(GroupingTypesApiConstants.CENTER_RESOURCE_NAME); - final GroupAccountSummaryCollectionData groupAccount = this.groupReadPlatformService.retrieveGroupAccountDetails(centerId); + final AccountSummaryCollectionData groupAccount = this.accountDetailsReadPlatformService.retrieveGroupAccountDetails(centerId); - final Set GROUP_ACCOUNTS_DATA_PARAMETERS = new HashSet(Arrays.asList("pendingApprovalLoans", - "awaitingDisbursalLoans", "openLoans", "closedLoans", "anyLoanCount", "pendingApprovalLoanCount", - "awaitingDisbursalLoanCount", "activeLoanCount", "closedLoanCount")); + final Set GROUP_ACCOUNTS_DATA_PARAMETERS = new HashSet(Arrays.asList("loanAccounts", "savingsAccounts", + "memberLoanAccounts", "memberSavingsAccounts")); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.groupSummaryToApiJsonSerializer.serialize(settings, groupAccount, GROUP_ACCOUNTS_DATA_PARAMETERS); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java index 6d47d5812..3e008d920 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java @@ -38,11 +38,12 @@ import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer; import org.mifosplatform.infrastructure.core.service.Page; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; +import org.mifosplatform.portfolio.accountdetails.data.AccountSummaryCollectionData; +import org.mifosplatform.portfolio.accountdetails.service.AccountDetailsReadPlatformService; import org.mifosplatform.portfolio.client.data.ClientData; import org.mifosplatform.portfolio.client.service.ClientReadPlatformService; import org.mifosplatform.portfolio.collectionsheet.data.JLGCollectionSheetData; import org.mifosplatform.portfolio.collectionsheet.service.CollectionSheetReadPlatformService; -import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData; import org.mifosplatform.portfolio.group.data.GroupGeneralData; import org.mifosplatform.portfolio.group.data.GroupRoleData; import org.mifosplatform.portfolio.group.service.CenterReadPlatformService; @@ -67,23 +68,25 @@ public class GroupsApiResource { private final ClientReadPlatformService clientReadPlatformService; private final ToApiJsonSerializer toApiJsonSerializer; private final ToApiJsonSerializer groupGeneralApiJsonSerializer; - private final ToApiJsonSerializer groupSummaryToApiJsonSerializer; + private final ToApiJsonSerializer groupSummaryToApiJsonSerializer; private final ApiRequestParameterHelper apiRequestParameterHelper; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final CollectionSheetReadPlatformService collectionSheetReadPlatformService; private final FromJsonHelper fromJsonHelper; private final GroupRolesReadPlatformService groupRolesReadPlatformService; + private final AccountDetailsReadPlatformService accountDetailsReadPlatformService; @Autowired public GroupsApiResource(final PlatformSecurityContext context, final GroupReadPlatformService groupReadPlatformService, final CenterReadPlatformService centerReadPlatformService, final ClientReadPlatformService clientReadPlatformService, final ToApiJsonSerializer toApiJsonSerializer, final ToApiJsonSerializer groupTopOfHierarchyApiJsonSerializer, - final ToApiJsonSerializer groupSummaryToApiJsonSerializer, + final ToApiJsonSerializer groupSummaryToApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, final CollectionSheetReadPlatformService collectionSheetReadPlatformService, final FromJsonHelper fromJsonHelper, - final GroupRolesReadPlatformService groupRolesReadPlatformService) { + final GroupRolesReadPlatformService groupRolesReadPlatformService, + final AccountDetailsReadPlatformService accountDetailsReadPlatformService) { this.context = context; this.groupReadPlatformService = groupReadPlatformService; this.centerReadPlatformService = centerReadPlatformService; @@ -96,6 +99,7 @@ public class GroupsApiResource { this.collectionSheetReadPlatformService = collectionSheetReadPlatformService; this.fromJsonHelper = fromJsonHelper; this.groupRolesReadPlatformService = groupRolesReadPlatformService; + this.accountDetailsReadPlatformService = accountDetailsReadPlatformService; } @GET @@ -315,20 +319,20 @@ public class GroupsApiResource { } @GET - @Path("{groupId}/loans") + @Path("{groupId}/accounts") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String retrieveLoans(@PathParam("groupId") final Long groupId, @Context final UriInfo uriInfo) { this.context.authenticatedUser().validateHasReadPermission("GROUP"); - final GroupAccountSummaryCollectionData groupAccount = this.groupReadPlatformService.retrieveGroupAccountDetails(groupId); + final AccountSummaryCollectionData groupAccount = this.accountDetailsReadPlatformService.retrieveGroupAccountDetails(groupId); - final Set GROUP_ACCOUNTS_DATA_PARAMETERS = new HashSet(Arrays.asList("pendingApprovalLoans", - "awaitingDisbursalLoans", "openLoans", "closedLoans", "anyLoanCount", "pendingApprovalLoanCount", - "awaitingDisbursalLoanCount", "activeLoanCount", "closedLoanCount")); + final Set GROUP_ACCOUNTS_DATA_PARAMETERS = new HashSet(Arrays.asList("loanAccounts", "savingsAccounts", + "memberLoanAccounts", "memberSavingsAccounts")); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.groupSummaryToApiJsonSerializer.serialize(settings, groupAccount, GROUP_ACCOUNTS_DATA_PARAMETERS); } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupAccountSummaryCollectionData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupAccountSummaryCollectionData.java deleted file mode 100644 index c5f29e3e9..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupAccountSummaryCollectionData.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.group.data; - -import java.util.List; - -public class GroupAccountSummaryCollectionData { - - private final int anyLoanCount; - private final int pendingApprovalLoanCount; - private final List pendingApprovalLoans; - private final int awaitingDisbursalLoanCount; - private final List awaitingDisbursalLoans; - private final int activeLoanCount; - private final List openLoans; - private final int closedLoanCount; - private final List closedLoans; - - @SuppressWarnings("unused") - private final int anyIndividualLoanCount; - private final int pendingApprovalIndividualLoanCount; - @SuppressWarnings("unused") - private final List pendingApprovalIndividualLoans; - private final int awaitingDisbursalIndividualLoanCount; - @SuppressWarnings("unused") - private final List awaitingDisbursalIndividualLoans; - private final int activeIndividualLoanCount; - @SuppressWarnings("unused") - private final List openIndividualLoans; - private final int closedIndividualLoanCount; - @SuppressWarnings("unused") - private final List closedIndividualLoans; - - public GroupAccountSummaryCollectionData(final List pendingApprovalLoans, - final List awaitingDisbursalLoans, final List openLoans, - final List closedLoans, final List pendingApprovalIndividualLoans, - final List awaitingDisbursalIndividualLoans, final List openIndividualLoans, - final List closedIndividualLoans) { - this.pendingApprovalLoans = pendingApprovalLoans; - this.pendingApprovalLoanCount = pendingApprovalLoans.size(); - this.awaitingDisbursalLoans = awaitingDisbursalLoans; - this.awaitingDisbursalLoanCount = awaitingDisbursalLoans.size(); - this.openLoans = openLoans; - this.activeLoanCount = openLoans.size(); - this.closedLoans = closedLoans; - this.closedLoanCount = closedLoans.size(); - - this.anyLoanCount = this.pendingApprovalLoanCount + this.awaitingDisbursalLoanCount + this.activeLoanCount + this.closedLoanCount; - - this.pendingApprovalIndividualLoans = pendingApprovalIndividualLoans; - this.pendingApprovalIndividualLoanCount = pendingApprovalIndividualLoans.size(); - this.awaitingDisbursalIndividualLoans = awaitingDisbursalIndividualLoans; - this.awaitingDisbursalIndividualLoanCount = awaitingDisbursalIndividualLoans.size(); - this.openIndividualLoans = openIndividualLoans; - this.activeIndividualLoanCount = openIndividualLoans.size(); - this.closedIndividualLoans = closedIndividualLoans; - this.closedIndividualLoanCount = closedIndividualLoans.size(); - - this.anyIndividualLoanCount = this.pendingApprovalIndividualLoanCount + this.awaitingDisbursalIndividualLoanCount - + this.activeIndividualLoanCount + this.closedIndividualLoanCount; - } - - public int getAnyLoanCount() { - return this.anyLoanCount; - } - - public int getPendingApprovalLoanCount() { - return this.pendingApprovalLoanCount; - } - - public List getPendingApprovalLoans() { - return this.pendingApprovalLoans; - } - - public int getAwaitingDisbursalLoanCount() { - return this.awaitingDisbursalLoanCount; - } - - public List getAwaitingDisbursalLoans() { - return this.awaitingDisbursalLoans; - } - - public int getActiveLoanCount() { - return this.activeLoanCount; - } - - public List getOpenLoans() { - return this.openLoans; - } - - public int getClosedLoanCount() { - return this.closedLoanCount; - } - - public List getClosedLoans() { - return this.closedLoans; - } -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupAccountSummaryData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupAccountSummaryData.java deleted file mode 100644 index d02c746fd..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupAccountSummaryData.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.group.data; - -/** - * Immutable data object for group loan accounts. - */ -public class GroupAccountSummaryData { - - private final Long id; - private final String externalId; - private final Long productId; - private final String productName; - private final Integer accountStatusId; - @SuppressWarnings("unused") - private final String accountNo; - - public GroupAccountSummaryData(final Long id, final String externalId, final Long productId, final String productName, - final Integer accountStatusId, final String accountNo) { - this.id = id; - this.externalId = externalId; - this.productId = productId; - this.productName = productName; - this.accountStatusId = accountStatusId; - this.accountNo = accountNo; - } - - public Long getId() { - return this.id; - } - - public String getExternalId() { - return this.externalId; - } - - public Long getProductId() { - return this.productId; - } - - public String getProductName() { - return this.productName; - } - - public Integer getAccountStatusId() { - return this.accountStatusId; - } -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformService.java index 9a38c6aed..f850d8845 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformService.java @@ -5,11 +5,7 @@ */ package org.mifosplatform.portfolio.group.service; -import java.util.Collection; - import org.mifosplatform.infrastructure.core.service.Page; -import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData; -import org.mifosplatform.portfolio.group.data.GroupAccountSummaryData; import org.mifosplatform.portfolio.group.data.GroupGeneralData; public interface GroupReadPlatformService { @@ -19,9 +15,4 @@ public interface GroupReadPlatformService { Page retrieveAll(SearchParameters searchParameters); GroupGeneralData retrieveOne(Long groupId); - - // - GroupAccountSummaryCollectionData retrieveGroupAccountDetails(Long groupId); - - Collection retrieveGroupLoanAccountsByLoanOfficerId(Long groupId, Long loanOfficerId); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java index d75be5e33..d10d84f35 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java @@ -5,17 +5,12 @@ */ package org.mifosplatform.portfolio.group.service; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; import org.apache.commons.lang.StringUtils; import org.mifosplatform.infrastructure.codes.data.CodeValueData; import org.mifosplatform.infrastructure.codes.service.CodeValueReadPlatformService; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; -import org.mifosplatform.infrastructure.core.domain.JdbcSupport; import org.mifosplatform.infrastructure.core.service.Page; import org.mifosplatform.infrastructure.core.service.PaginationHelper; import org.mifosplatform.infrastructure.core.service.RoutingDataSource; @@ -26,11 +21,8 @@ import org.mifosplatform.organisation.staff.data.StaffData; import org.mifosplatform.organisation.staff.service.StaffReadPlatformService; import org.mifosplatform.portfolio.client.data.ClientData; import org.mifosplatform.portfolio.client.service.ClientReadPlatformService; -import org.mifosplatform.portfolio.client.service.LoanStatusMapper; import org.mifosplatform.portfolio.group.api.GroupingTypesApiConstants; import org.mifosplatform.portfolio.group.data.CenterData; -import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData; -import org.mifosplatform.portfolio.group.data.GroupAccountSummaryData; import org.mifosplatform.portfolio.group.data.GroupGeneralData; import org.mifosplatform.portfolio.group.domain.GroupTypes; import org.mifosplatform.portfolio.group.exception.GroupNotFoundException; @@ -38,7 +30,6 @@ import org.mifosplatform.useradministration.domain.AppUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -209,114 +200,4 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { throw new GroupNotFoundException(groupId); } } - - @Override - public GroupAccountSummaryCollectionData retrieveGroupAccountDetails(final Long groupId) { - try { - this.context.authenticatedUser(); - - // Check if group exists - // retrieveGroup(groupId); - - final List pendingApprovalLoans = new ArrayList(); - final List awaitingDisbursalLoans = new ArrayList(); - final List openLoans = new ArrayList(); - final List closedLoans = new ArrayList(); - - final GroupLoanAccountSummaryDataMapper rm = new GroupLoanAccountSummaryDataMapper(); - - String sql = "select " + rm.loanAccountSummarySchema() + " where l.group_id = ? and l.client_id is null"; - - List results = this.jdbcTemplate.query(sql, rm, new Object[] { groupId }); - if (results != null) { - for (final GroupAccountSummaryData row : results) { - - final LoanStatusMapper statusMapper = new LoanStatusMapper(row.getAccountStatusId()); - - if (statusMapper.isOpen()) { - openLoans.add(row); - } else if (statusMapper.isAwaitingDisbursal()) { - awaitingDisbursalLoans.add(row); - } else if (statusMapper.isPendingApproval()) { - pendingApprovalLoans.add(row); - } else { - closedLoans.add(row); - } - } - } - - final List pendingApprovalIndividualLoans = new ArrayList(); - final List awaitingDisbursalIndividualLoans = new ArrayList(); - final List openIndividualLoans = new ArrayList(); - final List closedIndividualLoans = new ArrayList(); - - sql = "select " + rm.loanAccountSummarySchema() + " where l.group_id = ? and l.client_id is not null"; - - results = this.jdbcTemplate.query(sql, rm, new Object[] { groupId }); - if (results != null) { - for (final GroupAccountSummaryData row : results) { - - final LoanStatusMapper statusMapper = new LoanStatusMapper(row.getAccountStatusId()); - - if (statusMapper.isOpen()) { - openIndividualLoans.add(row); - } else if (statusMapper.isAwaitingDisbursal()) { - awaitingDisbursalIndividualLoans.add(row); - } else if (statusMapper.isPendingApproval()) { - pendingApprovalIndividualLoans.add(row); - } else { - closedIndividualLoans.add(row); - } - } - } - - return new GroupAccountSummaryCollectionData(pendingApprovalLoans, awaitingDisbursalLoans, openLoans, closedLoans, - pendingApprovalIndividualLoans, awaitingDisbursalIndividualLoans, openIndividualLoans, closedIndividualLoans); - } catch (final EmptyResultDataAccessException e) { - throw new GroupNotFoundException(groupId); - } - } - - @Override - public Collection retrieveGroupLoanAccountsByLoanOfficerId(final Long groupId, final Long loanOfficerId) { - - this.context.authenticatedUser(); - - // Check if group exists - // retrieveGroup(groupId); - - final GroupLoanAccountSummaryDataMapper rm = new GroupLoanAccountSummaryDataMapper(); - - final String sql = "select " + rm.loanAccountSummarySchema() - + " where l.group_id = ? and l.client_id is null and l.loan_officer_id = ?"; - - final List loanAccounts = this.jdbcTemplate.query(sql, rm, new Object[] { groupId, loanOfficerId }); - - return loanAccounts; - } - - private static final class GroupLoanAccountSummaryDataMapper implements RowMapper { - - public String loanAccountSummarySchema() { - - final StringBuilder accountsSummary = new StringBuilder("l.id as id, l.external_id as externalId,"); - accountsSummary.append("l.product_id as productId, lp.name as productName,").append("l.loan_status_id as statusId, ") - .append("l.account_no as accountNo ").append("from m_loan l ") - .append("LEFT JOIN m_product_loan AS lp ON lp.id = l.product_id "); - - return accountsSummary.toString(); - } - - @Override - public GroupAccountSummaryData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { - - final Long id = JdbcSupport.getLong(rs, "id"); - final String externalId = rs.getString("externalId"); - final Long productId = JdbcSupport.getLong(rs, "productId"); - final String loanProductName = rs.getString("productName"); - final Integer loanStatusId = JdbcSupport.getInteger(rs, "statusId"); - final String accountNo = rs.getString("accountNo"); - return new GroupAccountSummaryData(id, externalId, productId, loanProductName, loanStatusId, accountNo); - } - } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java index e94d31b05..9b33ffb57 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java @@ -55,6 +55,7 @@ import org.mifosplatform.organisation.monetary.domain.Money; import org.mifosplatform.organisation.staff.domain.Staff; import org.mifosplatform.organisation.workingdays.domain.WorkingDays; import org.mifosplatform.organisation.workingdays.service.WorkingDaysUtil; +import org.mifosplatform.portfolio.accountdetails.domain.AccountType; import org.mifosplatform.portfolio.calendar.service.CalendarHelper; import org.mifosplatform.portfolio.charge.exception.LoanChargeCannotBeAddedException; import org.mifosplatform.portfolio.client.domain.Client; @@ -2499,7 +2500,7 @@ public class Loan extends AbstractPersistable { } public boolean isGroupLoan() { - return LoanType.fromInt(this.loanType).isGroupLoan(); + return AccountType.fromInt(this.loanType).isGroupAccount(); } public void updateInterestRateFrequencyType() { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/LoanType.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/LoanType.java deleted file mode 100644 index 9a51a5cc6..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/LoanType.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.loanaccount.domain; - -/** - * Enum representation of loan types . - */ -public enum LoanType { - - INVALID(0, "loanType.invalid"), // - INDIVIDUAL(1, "loanType.individual"), // - GROUP(2, "loanType.group"), // - JLG(3, "loanType.jlg");//JLG loans given in group context - - private final Integer value; - private final String code; - - private LoanType(final Integer value, final String code) { - this.value = value; - this.code = code; - } - - public static LoanType fromInt(final Integer loanTypeValue) { - - LoanType enumeration = LoanType.INVALID; - switch (loanTypeValue) { - case 1: - enumeration = LoanType.INDIVIDUAL; - break; - case 2: - enumeration = LoanType.GROUP; - break; - case 3: - enumeration = LoanType.JLG; - break; - } - return enumeration; - } - - public static LoanType fromName(final String name){ - LoanType loanType = LoanType.INVALID; - for (LoanType type : LoanType.values()) { - if(type.getName().equals(name)) { - loanType = type; - break; - } - } - return loanType; - } - - public Integer getValue() { - return this.value; - } - - public String getCode() { - return code; - } - - public String getName(){ - return name().toLowerCase(); - } - - public boolean isInvalid(){ - return this.value.equals(LoanType.INVALID.getValue()); - } - - public boolean isIndividualLoan(){ - return this.value.equals(LoanType.INDIVIDUAL.getValue()); - } - - public boolean isGroupLoan(){ - return this.value.equals(LoanType.GROUP.getValue()); - } - - public boolean isJLGLoan(){ - return this.value.equals(LoanType.JLG.getValue()); - } -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java index f826af108..48f44a7cc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java @@ -22,7 +22,7 @@ import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; import org.mifosplatform.infrastructure.core.exception.InvalidJsonException; import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; -import org.mifosplatform.portfolio.loanaccount.domain.LoanType; +import org.mifosplatform.portfolio.accountdetails.domain.AccountType; import org.mifosplatform.portfolio.loanproduct.domain.LoanProduct; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -77,22 +77,22 @@ public final class LoanApplicationCommandFromApiJsonHelper { baseDataValidator.reset().parameter(loanTypeParameterName).value(loanTypeStr).notNull(); if (!StringUtils.isBlank(loanTypeStr)) { - final LoanType loanType = LoanType.fromName(loanTypeStr); + final AccountType loanType = AccountType.fromName(loanTypeStr); baseDataValidator.reset().parameter(loanTypeParameterName).value(loanType.getValue()).inMinMaxRange(1, 3); final Long clientId = fromApiJsonHelper.extractLongNamed("clientId", element); final Long groupId = fromApiJsonHelper.extractLongNamed("groupId", element); - if (loanType.isIndividualLoan()) { + if (loanType.isIndividualAccount()) { baseDataValidator.reset().parameter("clientId").value(clientId).notNull().longGreaterThanZero(); baseDataValidator.reset().parameter("groupId").value(groupId).mustBeBlankWhenParameterProvided("clientId", clientId); } - if (loanType.isGroupLoan()) { + if (loanType.isGroupAccount()) { baseDataValidator.reset().parameter("groupId").value(groupId).notNull().longGreaterThanZero(); baseDataValidator.reset().parameter("clientId").value(clientId).mustBeBlankWhenParameterProvided("groupId", groupId); } - if (loanType.isJLGLoan()) { + if (loanType.isJLGAccount()) { baseDataValidator.reset().parameter("clientId").value(clientId).notNull().integerGreaterThanZero(); baseDataValidator.reset().parameter("groupId").value(groupId).notNull().longGreaterThanZero(); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/BulkLoansReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/BulkLoansReadPlatformServiceImpl.java index b0409c981..8a6506259 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/BulkLoansReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/BulkLoansReadPlatformServiceImpl.java @@ -14,10 +14,8 @@ import org.mifosplatform.infrastructure.core.domain.JdbcSupport; import org.mifosplatform.infrastructure.core.service.RoutingDataSource; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.staff.data.StaffAccountSummaryCollectionData; -import org.mifosplatform.portfolio.client.data.ClientLoanAccountSummaryData; -import org.mifosplatform.portfolio.client.service.ClientReadPlatformService; -import org.mifosplatform.portfolio.group.data.GroupAccountSummaryData; -import org.mifosplatform.portfolio.group.service.GroupReadPlatformService; +import org.mifosplatform.portfolio.accountdetails.data.LoanAccountSummaryData; +import org.mifosplatform.portfolio.accountdetails.service.AccountDetailsReadPlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; @@ -28,16 +26,14 @@ public class BulkLoansReadPlatformServiceImpl implements BulkLoansReadPlatformSe private final JdbcTemplate jdbcTemplate; private final PlatformSecurityContext context; - private final ClientReadPlatformService clientReadPlatformService; - private final GroupReadPlatformService groupReadPlatformService; + private final AccountDetailsReadPlatformService accountDetailsReadPlatformService; @Autowired public BulkLoansReadPlatformServiceImpl(final PlatformSecurityContext context, final RoutingDataSource dataSource, - final ClientReadPlatformService clientReadPlatformService, final GroupReadPlatformService groupReadPlatformService) { + final AccountDetailsReadPlatformService accountDetailsReadPlatformService) { this.context = context; this.jdbcTemplate = new JdbcTemplate(dataSource); - this.clientReadPlatformService = clientReadPlatformService; - this.groupReadPlatformService = groupReadPlatformService; + this.accountDetailsReadPlatformService = accountDetailsReadPlatformService; } @Override @@ -51,23 +47,23 @@ public class BulkLoansReadPlatformServiceImpl implements BulkLoansReadPlatformSe final StaffGroupMapper staffGroupMapper = new StaffGroupMapper(); final String groupSql = "select distinct " + staffGroupMapper.schema(); - final List clientSummaryList = this.jdbcTemplate.query(clientSql, + final List clientSummaryList = this.jdbcTemplate.query(clientSql, staffClientMapper, new Object[] { loanOfficerId }); - for (StaffAccountSummaryCollectionData.ClientSummary clientSummary : clientSummaryList) { + for (StaffAccountSummaryCollectionData.LoanAccountSummary clientSummary : clientSummaryList) { - final Collection clientLoanAccounts = this.clientReadPlatformService + final Collection clientLoanAccounts = this.accountDetailsReadPlatformService .retrieveClientLoanAccountsByLoanOfficerId(clientSummary.getId(), loanOfficerId); clientSummary.setLoans(clientLoanAccounts); } - final List groupSummaryList = this.jdbcTemplate.query(groupSql, staffGroupMapper, + final List groupSummaryList = this.jdbcTemplate.query(groupSql, staffGroupMapper, new Object[] { loanOfficerId }); - for (StaffAccountSummaryCollectionData.GroupSummary groupSummary : groupSummaryList) { + for (StaffAccountSummaryCollectionData.LoanAccountSummary groupSummary : groupSummaryList) { - final Collection groupLoanAccounts = this.groupReadPlatformService + final Collection groupLoanAccounts = this.accountDetailsReadPlatformService .retrieveGroupLoanAccountsByLoanOfficerId(groupSummary.getId(), loanOfficerId); groupSummary.setLoans(groupLoanAccounts); @@ -76,7 +72,7 @@ public class BulkLoansReadPlatformServiceImpl implements BulkLoansReadPlatformSe return new StaffAccountSummaryCollectionData(clientSummaryList, groupSummaryList); } - private static final class StaffClientMapper implements RowMapper { + private static final class StaffClientMapper implements RowMapper { public String schema() { return " c.id as id, c.display_name as displayName from m_client c " @@ -84,16 +80,16 @@ public class BulkLoansReadPlatformServiceImpl implements BulkLoansReadPlatformSe } @Override - public StaffAccountSummaryCollectionData.ClientSummary mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) + public StaffAccountSummaryCollectionData.LoanAccountSummary mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { final Long id = JdbcSupport.getLong(rs, "id"); final String displayName = rs.getString("displayName"); - return new StaffAccountSummaryCollectionData.ClientSummary(id, displayName); + return new StaffAccountSummaryCollectionData.LoanAccountSummary(id, displayName); } } - private static final class StaffGroupMapper implements RowMapper { + private static final class StaffGroupMapper implements RowMapper { public String schema() { return " g.id as id, g.display_name as name from m_group g" @@ -101,12 +97,12 @@ public class BulkLoansReadPlatformServiceImpl implements BulkLoansReadPlatformSe } @Override - public StaffAccountSummaryCollectionData.GroupSummary mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) + public StaffAccountSummaryCollectionData.LoanAccountSummary mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { final Long id = JdbcSupport.getLong(rs, "id"); final String name = rs.getString("name"); - return new StaffAccountSummaryCollectionData.GroupSummary(id, name); + return new StaffAccountSummaryCollectionData.LoanAccountSummary(id, name); } } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanAssembler.java index 40c1c1e4d..1e55611b1 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanAssembler.java @@ -24,6 +24,7 @@ import org.mifosplatform.organisation.staff.exception.StaffNotFoundException; import org.mifosplatform.organisation.staff.exception.StaffRoleException; import org.mifosplatform.organisation.workingdays.domain.WorkingDays; import org.mifosplatform.organisation.workingdays.domain.WorkingDaysRepositoryWrapper; +import org.mifosplatform.portfolio.accountdetails.service.AccountEnumerations; import org.mifosplatform.portfolio.client.domain.Client; import org.mifosplatform.portfolio.client.domain.ClientRepositoryWrapper; import org.mifosplatform.portfolio.collateral.domain.LoanCollateral; @@ -53,7 +54,6 @@ import org.mifosplatform.portfolio.loanproduct.domain.LoanProductRepository; import org.mifosplatform.portfolio.loanproduct.domain.LoanTransactionProcessingStrategy; import org.mifosplatform.portfolio.loanproduct.exception.InvalidCurrencyException; import org.mifosplatform.portfolio.loanproduct.exception.LoanProductNotFoundException; -import org.mifosplatform.portfolio.loanproduct.service.LoanEnumerations; import org.mifosplatform.useradministration.domain.AppUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -154,7 +154,7 @@ public class LoanAssembler { final String loanTypeParameterName = "loanType"; final String loanTypeStr = fromApiJsonHelper.extractStringNamed(loanTypeParameterName, element); - final EnumOptionData loanType = LoanEnumerations.loanType(loanTypeStr); + final EnumOptionData loanType = AccountEnumerations.loanType(loanTypeStr); if (clientId != null) { client = this.clientRepository.findOneWithNotFoundDetection(clientId); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java index 11e15721a..d348e94bc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java @@ -29,6 +29,7 @@ import org.mifosplatform.organisation.monetary.domain.ApplicationCurrency; import org.mifosplatform.organisation.monetary.domain.ApplicationCurrencyRepositoryWrapper; import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency; import org.mifosplatform.organisation.monetary.domain.Money; +import org.mifosplatform.portfolio.accountdetails.service.AccountEnumerations; import org.mifosplatform.portfolio.calendar.data.CalendarData; import org.mifosplatform.portfolio.calendar.domain.CalendarEntityType; import org.mifosplatform.portfolio.calendar.service.CalendarReadPlatformService; @@ -492,7 +493,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { final String groupHierarchy = rs.getString("groupHierarchy"); final Integer loanTypeId = JdbcSupport.getInteger(rs, "loanType"); - final EnumOptionData loanType = LoanEnumerations.loanType(loanTypeId); + final EnumOptionData loanType = AccountEnumerations.loanType(loanTypeId); final Long fundId = JdbcSupport.getLong(rs, "fundId"); final String fundName = rs.getString("fundName"); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java index c8ea47a3d..fb18ad442 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -34,6 +34,7 @@ import org.mifosplatform.organisation.office.domain.Office; import org.mifosplatform.organisation.staff.domain.Staff; import org.mifosplatform.organisation.workingdays.domain.WorkingDays; import org.mifosplatform.organisation.workingdays.domain.WorkingDaysRepositoryWrapper; +import org.mifosplatform.portfolio.accountdetails.domain.AccountType; import org.mifosplatform.portfolio.calendar.domain.Calendar; import org.mifosplatform.portfolio.calendar.domain.CalendarEntityType; import org.mifosplatform.portfolio.calendar.domain.CalendarInstance; @@ -65,7 +66,6 @@ import org.mifosplatform.portfolio.loanaccount.domain.LoanStatus; import org.mifosplatform.portfolio.loanaccount.domain.LoanSummaryWrapper; import org.mifosplatform.portfolio.loanaccount.domain.LoanTransaction; import org.mifosplatform.portfolio.loanaccount.domain.LoanTransactionRepository; -import org.mifosplatform.portfolio.loanaccount.domain.LoanType; import org.mifosplatform.portfolio.loanaccount.exception.LoanDisbursalException; import org.mifosplatform.portfolio.loanaccount.exception.LoanNotFoundException; import org.mifosplatform.portfolio.loanaccount.exception.LoanOfficerAssignmentException; @@ -1040,7 +1040,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf final WorkingDays workingDays = this.workingDaysRepository.findOne(); final Collection loanStatuses = new ArrayList(Arrays.asList(LoanStatus.SUBMITTED_AND_PENDING_APPROVAL.getValue(), LoanStatus.APPROVED.getValue(), LoanStatus.ACTIVE.getValue())); - final Collection loanTypes = new ArrayList(Arrays.asList(LoanType.GROUP.getValue(), LoanType.JLG.getValue())); + final Collection loanTypes = new ArrayList(Arrays.asList(AccountType.GROUP.getValue(), AccountType.JLG.getValue())); final Collection loanIds = new ArrayList(loanCalendarInstances.size()); // loop through loanCalendarInstances to get loan ids for (CalendarInstance calendarInstance : loanCalendarInstances) { @@ -1064,10 +1064,10 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf if (loan.isGroupLoan()) { if (loan.loanProduct().isIncludeInBorrowerCycle()) { loansToUpdate = this.loanRepository.getGroupLoansToUpdateLoanCounter(loan.getCurrentLoanCounter(), loan.getGroupId(), - LoanType.GROUP.getValue()); + AccountType.GROUP.getValue()); } else { loansToUpdate = this.loanRepository.getGroupLoansToUpdateLoanProductCounter(loan.getLoanProductLoanCounter(), - loan.getGroupId(), LoanType.GROUP.getValue()); + loan.getGroupId(), AccountType.GROUP.getValue()); } } else { @@ -1092,7 +1092,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf if (loan.isGroupLoan()) { final List loansToUpdateForLoanCounter = this.loanRepository.getGroupLoansDisbursedAfter(actualDisbursementDate.toDate(), - loan.getGroupId(), LoanType.GROUP.getValue()); + loan.getGroupId(), AccountType.GROUP.getValue()); final Integer newLoanCounter = getNewGroupLoanCounter(loan); final Integer newLoanProductCounter = getNewGroupLoanProductCounter(loan); updateLoanCounter(loan, loansToUpdateForLoanCounter, newLoanCounter, newLoanProductCounter); @@ -1107,7 +1107,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf private Integer getNewGroupLoanCounter(final Loan loan) { - Integer maxClientLoanCounter = this.loanRepository.getMaxGroupLoanCounter(loan.getGroupId(), LoanType.GROUP.getValue()); + Integer maxClientLoanCounter = this.loanRepository.getMaxGroupLoanCounter(loan.getGroupId(), AccountType.GROUP.getValue()); if (maxClientLoanCounter == null) { maxClientLoanCounter = 1; } else { @@ -1119,7 +1119,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf private Integer getNewGroupLoanProductCounter(final Loan loan) { Integer maxLoanProductLoanCounter = this.loanRepository.getMaxGroupLoanProductCounter(loan.loanProduct().getId(), - loan.getGroupId(), LoanType.GROUP.getValue()); + loan.getGroupId(), AccountType.GROUP.getValue()); if (maxLoanProductLoanCounter == null) { maxLoanProductLoanCounter = 1; } else { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanEnumerations.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanEnumerations.java index ee5ba9673..6ebdea8e9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanEnumerations.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanEnumerations.java @@ -6,17 +6,17 @@ package org.mifosplatform.portfolio.loanproduct.service; import org.mifosplatform.infrastructure.core.data.EnumOptionData; +import org.mifosplatform.portfolio.accountdetails.service.AccountEnumerations; import org.mifosplatform.portfolio.loanaccount.data.LoanStatusEnumData; import org.mifosplatform.portfolio.loanaccount.data.LoanTransactionEnumData; import org.mifosplatform.portfolio.loanaccount.domain.LoanStatus; import org.mifosplatform.portfolio.loanaccount.domain.LoanTransactionType; -import org.mifosplatform.portfolio.loanaccount.domain.LoanType; import org.mifosplatform.portfolio.loanproduct.domain.AmortizationMethod; import org.mifosplatform.portfolio.loanproduct.domain.InterestCalculationPeriodMethod; import org.mifosplatform.portfolio.loanproduct.domain.InterestMethod; import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType; -public class LoanEnumerations { +public class LoanEnumerations{ public static final String LOAN_TERM_FREQUENCY_TYPE = "loanTermFrequencyType"; public static final String TERM_FREQUENCY_TYPE = "termFrequencyType"; @@ -44,7 +44,7 @@ public class LoanEnumerations { return interestType(id); } else if (typeName.equals(INTEREST_CALCULATION_PERIOD_TYPE)) { return interestCalculationPeriodType(id); - } else if (typeName.equals(LOAN_TYPE)) { return loanType(id); } + } else if (typeName.equals(LOAN_TYPE)) { return AccountEnumerations.loanType(id); } return null; } @@ -333,32 +333,4 @@ public class LoanEnumerations { return optionData; } - - public static EnumOptionData loanType(final Integer loanTypeId) { - return loanType(LoanType.fromInt(loanTypeId)); - } - - public static EnumOptionData loanType(final String name) { - return loanType(LoanType.fromName(name)); - } - - public static EnumOptionData loanType(final LoanType type) { - EnumOptionData optionData = new EnumOptionData(LoanType.INVALID.getValue().longValue(), LoanType.INVALID.getCode(), "Invalid"); - switch (type) { - case INVALID: - optionData = new EnumOptionData(LoanType.INVALID.getValue().longValue(), LoanType.INVALID.getCode(), "Invalid"); - break; - case INDIVIDUAL: - optionData = new EnumOptionData(LoanType.INDIVIDUAL.getValue().longValue(), LoanType.INDIVIDUAL.getCode(), "Individual"); - break; - case GROUP: - optionData = new EnumOptionData(LoanType.GROUP.getValue().longValue(), LoanType.GROUP.getCode(), "Group"); - break; - case JLG: - optionData = new EnumOptionData(LoanType.JLG.getValue().longValue(), LoanType.JLG.getCode(), "JLG"); - break; - } - - return optionData; - } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java index 0b0826f29..bc8ede232 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java @@ -38,6 +38,7 @@ import org.mifosplatform.portfolio.client.domain.Client; import org.mifosplatform.portfolio.client.domain.ClientRepositoryWrapper; import org.mifosplatform.portfolio.group.domain.Group; import org.mifosplatform.portfolio.group.domain.GroupRepositoryWrapper; +import org.mifosplatform.portfolio.group.exception.ClientNotInGroupException; import org.mifosplatform.portfolio.savings.SavingsCompoundingInterestPeriodType; import org.mifosplatform.portfolio.savings.SavingsInterestCalculationDaysInYearType; import org.mifosplatform.portfolio.savings.SavingsInterestCalculationType; @@ -106,6 +107,10 @@ public class SavingsAccountAssembler { if (groupId != null) { group = this.groupRepository.findOneWithNotFoundDetection(groupId); } + + if(group != null && client != null){ + if (!group.hasClientAsMember(client)) { throw new ClientNotInGroupException(clientId, groupId); } + } final Long fieldOfficerId = fromApiJsonHelper.extractLongNamed(fieldOfficerIdParamName, element); if (fieldOfficerId != null) {