From b100fd16a17a2baba75041540c61809229455637 Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Fri, 24 Aug 2012 23:00:46 +0100 Subject: [PATCH] return status with deposit account data. --- .../api/DepositAccountsApiResource.java | 34 ++++----------- .../platform/api/data/DepositAccountData.java | 33 +++++---------- .../GoogleGsonApiJsonSerializerService.java | 17 ++++---- .../platform/saving/domain/DepositStatus.java | 6 +-- .../service/DepositAccountEnumerations.java | 42 +++++++++++++++++++ ...DepositAccountReadPlatformServiceImpl.java | 14 +++---- 6 files changed, 78 insertions(+), 68 deletions(-) create mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountEnumerations.java diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java index bbc3da5c6..dc7b26e53 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java @@ -60,6 +60,15 @@ public class DepositAccountsApiResource { @Autowired private ApiJsonSerializerService apiJsonSerializerService; + + private static final Set typicalResponseParameters = new HashSet( + Arrays.asList("id", "externalId", "clientId", "clientName", + "productId", "productName", "status", "currency", + "deposit", "maturityInterestRate", "tenureInMonths", + "interestCompoundedEvery", + "interestCompoundedEveryPeriodType", "renewalAllowed", + "preClosureAllowed", "preClosureInterestRate")); + @POST @Consumes({MediaType.APPLICATION_JSON}) @@ -91,14 +100,6 @@ public class DepositAccountsApiResource { @Produces({MediaType.APPLICATION_JSON}) public String retrieveAllDepositAccounts(@Context final UriInfo uriInfo) { - Set typicalResponseParameters = new HashSet( - Arrays.asList("createdOn", "lastModifedOn", - "id", "externalId", "clientId", "clientName", "productId", "productName", - "currency", "deposit", "maturityInterestRate", "tenureInMonths", "interestCompoundedEvery", "interestCompoundedEveryPeriodType", - "renewalAllowed","preClosureAllowed","preClosureInterestRate" - ) - ); - Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); if (responseParameters.isEmpty()) { responseParameters.addAll(typicalResponseParameters); @@ -116,14 +117,6 @@ public class DepositAccountsApiResource { @Produces({MediaType.APPLICATION_JSON}) public String retrieveDepositAccount(@PathParam("accountId") final Long accountId, @Context final UriInfo uriInfo) { - Set typicalResponseParameters = new HashSet( - Arrays.asList("createdOn", "lastModifedOn", - "id", "externalId", "clientId", "clientName", "productId", "productName", - "currency", "deposit", "maturityInterestRate", "tenureInMonths", "interestCompoundedEvery", "interestCompoundedEveryPeriodType", - "renewalAllowed","preClosureAllowed","preClosureInterestRate" - ) - ); - Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); if (responseParameters.isEmpty()) { responseParameters.addAll(typicalResponseParameters); @@ -149,15 +142,6 @@ public class DepositAccountsApiResource { @QueryParam("productId") final Long productId, @Context final UriInfo uriInfo) { - Set typicalResponseParameters = new HashSet( - Arrays.asList( - "createdOn", "lastModifedOn", - "id", "externalId", "clientId", "clientName", "productId", "productName", - "currency", "deposit", "maturityInterestRate", "tenureInMonths", "interestCompoundedEvery", "interestCompoundedEveryPeriodType", - "renewalAllowed","preClosureAllowed","preClosureInterestRate" - ) - ); - Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); if (responseParameters.isEmpty()) { responseParameters.addAll(typicalResponseParameters); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java index 04e094220..8d946f1c8 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java @@ -5,7 +5,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import org.joda.time.DateTime; import org.joda.time.LocalDate; /** @@ -15,7 +14,7 @@ public class DepositAccountData { private final Long id; private final String externalId; - + private final EnumOptionData status; private final Long clientId; private final String clientName; private final Long productId; @@ -41,9 +40,6 @@ public class DepositAccountData { private final boolean preClosureAllowed; private final BigDecimal preClosureInterestRate; - private final DateTime createdOn; - private final DateTime lastModifedOn; - private final List interestCompoundedEveryPeriodTypeOptions; private final List productOptions; @@ -58,10 +54,9 @@ public class DepositAccountData { private DepositAccountData( final Long clientId, final String clientName) { - this.createdOn=null; - this.lastModifedOn=null; this.id=null; this.externalId = null; + this.status = null; this.clientId = clientId; this.clientName = clientName; this.productId = null; @@ -92,10 +87,9 @@ public class DepositAccountData { final DepositAccountData account, final List interestCompoundedEveryPeriodTypeOptions, final Collection productOptions) { - this.createdOn = account.getCreatedOn(); - this.lastModifedOn = account.getLastModifedOn(); this.id = account.getId(); this.externalId = account.getExternalId(); + this.status = account.getStatus(); this.clientId = account.getClientId(); this.clientName = account.getClientName(); this.productId = account.getProductId(); @@ -123,10 +117,9 @@ public class DepositAccountData { } public DepositAccountData( - final DateTime createdOn, - final DateTime lastModifedOn, final Long id, final String externalId, + final EnumOptionData status, final Long clientId, final String clientName, final Long productId, @@ -147,10 +140,9 @@ public class DepositAccountData { final boolean renewalAllowed, final boolean preClosureAllowed, final BigDecimal preClosureInterestRate) { - this.createdOn=createdOn; - this.lastModifedOn=lastModifedOn; this.id=id; this.externalId = externalId; + this.status = status; this.clientId = clientId; this.clientName = clientName; this.productId = productId; @@ -190,10 +182,9 @@ public class DepositAccountData { final boolean renewalAllowed, final boolean preClosureAllowed, final BigDecimal preClosureInterestRate) { - this.createdOn=null; - this.lastModifedOn=null; this.id=null; this.externalId = null; + this.status = null; this.clientId = clientId; this.clientName = clientName; this.productId = productId; @@ -227,6 +218,10 @@ public class DepositAccountData { public String getExternalId() { return externalId; } + + public EnumOptionData getStatus() { + return status; + } public Long getClientId() { return clientId; @@ -312,14 +307,6 @@ public class DepositAccountData { return preClosureInterestRate; } - public DateTime getCreatedOn() { - return createdOn; - } - - public DateTime getLastModifedOn() { - return lastModifedOn; - } - public List getInterestCompoundedEveryPeriodTypeOptions() { return interestCompoundedEveryPeriodTypeOptions; } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/GoogleGsonApiJsonSerializerService.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/GoogleGsonApiJsonSerializerService.java index e6d2a562a..3dd4019ff 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/GoogleGsonApiJsonSerializerService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/GoogleGsonApiJsonSerializerService.java @@ -97,15 +97,14 @@ public class GoogleGsonApiJsonSerializerService implements "preClosureAllowed", "preClosureInterestRate")); private static final Set SAVINGS_DEPOSIT_ACCOUNT_DATA_PARAMETERS = new HashSet( - Arrays.asList("productOptions", - "interestCompoundedEveryPeriodTypeOptions", "createdOn", - "lastModifedOn", "id", "externalId", "clientId", - "clientName", "productId", "productName", "currency", - "deposit", "maturityInterestRate", "tenureInMonths", - "interestCompoundedEvery", - "interestCompoundedEveryPeriodType", "renewalAllowed", - "preClosureAllowed", "preClosureInterestRate")); - + Arrays.asList("productOptions", "interestCompoundedEveryPeriodTypeOptions", + "id", "externalId", "clientId", "clientName", "productId", "productName", "status", + "currency", "deposit", "maturityInterestRate", "tenureInMonths", + "interestCompoundedEvery", "interestCompoundedEveryPeriodType", + "renewalAllowed","preClosureAllowed","preClosureInterestRate" + ) + ); + private static final Set CLIENT_DATA_PARAMETERS = new HashSet( Arrays.asList("id", "officeId", "officeName", "externalId", "firstname", "lastname", "joinedDate", "displayName", diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositStatus.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositStatus.java index f96d94e8b..829f51f83 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositStatus.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositStatus.java @@ -8,9 +8,9 @@ public enum DepositStatus { ACTIVE(300, "depositStatusType.active"), // WITHDRAWN_BY_CLIENT(400, "depositStatusType.withdrawn.by.client"), // REJECTED(500, "depositStatusType.rejected"), // - MATURED(700,"depositStatusType.matured"), - CLOSED(600, "depositStatusType.closed"); - + CLOSED(600, "depositStatusType.closed"), // + MATURED(700,"depositStatusType.matured"); + private final Integer value; private final String code; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountEnumerations.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountEnumerations.java new file mode 100644 index 000000000..cc9983f43 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountEnumerations.java @@ -0,0 +1,42 @@ +package org.mifosng.platform.saving.service; + +import org.mifosng.platform.api.data.EnumOptionData; +import org.mifosng.platform.saving.domain.DepositStatus; + +public class DepositAccountEnumerations { + + public static EnumOptionData status(final Integer statusId) { + return status(DepositStatus.fromInt(statusId)); + } + + public static EnumOptionData status(final DepositStatus status) { + EnumOptionData optionData = null; + switch (status) { + case SUBMITED_AND_PENDING_APPROVAL: + optionData = new EnumOptionData(DepositStatus.SUBMITED_AND_PENDING_APPROVAL.getValue().longValue(), DepositStatus.SUBMITED_AND_PENDING_APPROVAL.getCode(), "Submitted and pending approval"); + break; + case APPROVED: + optionData = new EnumOptionData(DepositStatus.APPROVED.getValue().longValue(), DepositStatus.APPROVED.getCode(), "Approved"); + break; + case ACTIVE: + optionData = new EnumOptionData(DepositStatus.ACTIVE.getValue().longValue(), DepositStatus.ACTIVE.getCode(), "Active"); + break; + case REJECTED: + optionData = new EnumOptionData(DepositStatus.REJECTED.getValue().longValue(), DepositStatus.REJECTED.getCode(), "Rejected"); + break; + case WITHDRAWN_BY_CLIENT: + optionData = new EnumOptionData(DepositStatus.WITHDRAWN_BY_CLIENT.getValue().longValue(), DepositStatus.WITHDRAWN_BY_CLIENT.getCode(), "Withdrawn by applicant"); + break; + case MATURED: + optionData = new EnumOptionData(DepositStatus.MATURED.getValue().longValue(), DepositStatus.MATURED.getCode(), "Matured"); + break; + case CLOSED: + optionData = new EnumOptionData(DepositStatus.CLOSED.getValue().longValue(), DepositStatus.CLOSED.getCode(), "Closed"); + break; + default: + optionData = new EnumOptionData(DepositStatus.INVALID.getValue().longValue(), DepositStatus.INVALID.getCode(), "Invalid"); + break; + } + return optionData; + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java index 493c1e466..abff6abde 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java @@ -5,7 +5,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Collection; -import org.joda.time.DateTime; import org.joda.time.LocalDate; import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.CurrencyData; @@ -88,7 +87,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead CurrencyData currency = new CurrencyData(selectedProduct.getCurrencyCode(), "", selectedProduct.getDigitsAfterDecimal(), "", ""); accountData = new DepositAccountData( - clientAccount.getId(), clientAccount.getDisplayName(), selectedProduct.getId(), selectedProduct.getName(), + clientAccount.getId(), clientAccount.getDisplayName(), selectedProduct.getId(), selectedProduct.getName(), currency, selectedProduct.getMinimumBalance(), selectedProduct.getMaturityDefaultInterestRate(), selectedProduct.getTenureInMonths(), selectedProduct.getInterestCompoundedEvery(), selectedProduct.getInterestCompoundedEveryPeriodType(), selectedProduct.isRenewalAllowed(), selectedProduct.isPreClosureAllowed(), @@ -118,14 +117,13 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead public String schema() { return "da.id as id, da.external_id as externalId, da.client_id as clientId, da.product_id as productId," + " da.currency_code as currencyCode, da.currency_digits as currencyDigits, " - + " da.deposit_amount as depositAmount, " + + " da.deposit_amount as depositAmount, da.status_enum as statusId, " + " da.maturity_nominal_interest_rate as interestRate, da.tenure_months as termInMonths, da.projected_commencement_date as projectedCommencementDate," + " da.actual_commencement_date as actualCommencementDate, da.projected_maturity_date as projectedMaturityDate, da.actual_maturity_date as actualMaturityDate," + " da.projected_interest_accrued_on_maturity as projectedInterestAccrued, da.actual_interest_accrued as actualInterestAccrued, " + " da.projected_total_maturity_amount as projectedMaturityAmount, da.actual_total_amount as actualMaturityAmount, " + " da.interest_compounded_every as interestCompoundedEvery, da.interest_compounded_every_period_enum as interestCompoundedEveryPeriodType, " + " da.is_renewal_allowed as renewalAllowed, da.is_preclosure_allowed as preClosureAllowed, da.pre_closure_interest_rate as preClosureInterestRate, " - + " da.created_date as createdon, da.lastmodified_date as modifiedon, " + " c.firstname as firstname, c.lastname as lastname, pd.name as productName," + " curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, curr.display_symbol as currencyDisplaySymbol" + " from m_deposit_account da " @@ -145,6 +143,9 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead Long productId = rs.getLong("productId"); String productName = rs.getString("productName"); + Integer statusId = JdbcSupport.getInteger(rs, "statusId"); + EnumOptionData status = DepositAccountEnumerations.status(statusId); + String currencyCode = rs.getString("currencyCode"); String currencyName = rs.getString("currencyName"); String currencyNameCode = rs.getString("currencyNameCode"); @@ -176,10 +177,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead BigDecimal preClosureInterestRate = rs.getBigDecimal("preClosureInterestRate"); - DateTime createdOn = JdbcSupport.getDateTime(rs, "createdon"); - DateTime lastModifedOn = JdbcSupport.getDateTime(rs, "modifiedon"); - - return new DepositAccountData(createdOn, lastModifedOn, id, externalId, clientId, clientName, productId, productName, currencyData, depositAmount, + return new DepositAccountData(id, externalId, status, clientId, clientName, productId, productName, currencyData, depositAmount, interestRate, termInMonths, projectedCommencementDate, actualCommencementDate, projectedMaturityDate, actualMaturityDate, projectedInterestAccrued, actualInterestAccrued, projectedMaturityAmount, actualMaturityAmount, interestCompoundedEvery, interestCompoundedEveryPeriodType,