From 61b49d0b4ca36db67ead027c3a3d991cbb793deb Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Fri, 7 Sep 2012 15:32:17 +0100 Subject: [PATCH] fix update loan product transaction strategy field and align new loan application with implementation of modify loan application work from mifosx-32. --- .../platform/api/LoansApiResource.java | 55 +++++- .../platform/api/data/LoanAccountData.java | 41 +++-- .../api/data/LoanBasicDetailsData.java | 173 +++++++++++++++--- .../platform/api/data/NewLoanData.java | 80 -------- .../ApiJsonSerializerService.java | 5 +- .../GoogleGsonApiJsonSerializerService.java | 21 +-- .../loan/service/LoanReadPlatformService.java | 7 +- .../service/LoanReadPlatformServiceImpl.java | 56 +----- .../LoanProductReadPlatformServiceImpl.java | 2 +- ...WritePlatformServiceJpaRepositoryImpl.java | 2 +- 10 files changed, 233 insertions(+), 209 deletions(-) delete mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/api/data/NewLoanData.java diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/LoansApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/LoansApiResource.java index be4102913..803709dee 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/LoansApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/LoansApiResource.java @@ -23,9 +23,9 @@ import javax.ws.rs.core.UriInfo; import org.apache.commons.lang.StringUtils; import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand; import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand; +import org.mifosng.platform.api.commands.LoanApplicationCommand; import org.mifosng.platform.api.commands.LoanStateTransitionCommand; import org.mifosng.platform.api.commands.LoanTransactionCommand; -import org.mifosng.platform.api.commands.LoanApplicationCommand; import org.mifosng.platform.api.commands.UndoStateTransitionCommand; import org.mifosng.platform.api.data.ChargeData; import org.mifosng.platform.api.data.EntityIdentifier; @@ -40,7 +40,6 @@ import org.mifosng.platform.api.data.LoanRepaymentPeriodData; import org.mifosng.platform.api.data.LoanRepaymentTransactionData; import org.mifosng.platform.api.data.LoanSchedule; import org.mifosng.platform.api.data.LoanTransactionData; -import org.mifosng.platform.api.data.NewLoanData; import org.mifosng.platform.api.data.TransactionProcessingStrategyData; import org.mifosng.platform.api.infrastructure.ApiDataConversionService; import org.mifosng.platform.api.infrastructure.ApiJsonSerializerService; @@ -98,8 +97,23 @@ public class LoansApiResource { @QueryParam("productId") final Long productId, @Context final UriInfo uriInfo) { - Set typicalResponseParameters = new HashSet(Arrays.asList("clientId", "clientName", "productId", "productName", - "selectedProduct", "expectedDisbursementDate", "allowedProducts")); + Set typicalResponseParameters = new HashSet( + Arrays.asList("id", "externalId", "clientId", "clientName", "fundId", "fundName", + "loanProductId", "loanProductName", "loanProductDescription", + "currency", "principal", + "inArrearsTolerance", "numberOfRepayments", + "repaymentEvery", "interestRatePerPeriod", + "annualInterestRate", "repaymentFrequencyType", + "interestRateFrequencyType", "amortizationType", + "interestType", "interestCalculationPeriodType", + "submittedOnDate", "approvedOnDate", + "expectedDisbursementDate", "actualDisbursementDate", + "expectedFirstRepaymentOnDate", "interestChargedFromDate", + "closedOnDate", "expectedMaturityDate", + "status", + "lifeCycleStatusDate", "summary", "repaymentSchedule", + "loanRepayments", "permissions", "convenienceData", "charges") + ); Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); if (responseParameters.isEmpty()) { @@ -107,9 +121,32 @@ public class LoansApiResource { } boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); - NewLoanData workflowData = this.loanReadPlatformService.retrieveClientAndProductDetails(clientId, productId); + responseParameters.addAll(Arrays.asList("productOptions", "amortizationTypeOptions", "interestTypeOptions", "interestCalculationPeriodTypeOptions", + "repaymentFrequencyTypeOptions", "interestRateFrequencyTypeOptions", "fundOptions", "transactionProcessingStrategyOptions", "chargeOptions")); + + // tempate related + Collection productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup(); + CollectionloanTermFrequencyTypeOptions = dropdownReadPlatformService.retrieveLoanTermFrequencyTypeOptions(); + CollectionrepaymentFrequencyTypeOptions = dropdownReadPlatformService.retrieveRepaymentFrequencyTypeOptions(); + CollectioninterestRateFrequencyTypeOptions = dropdownReadPlatformService.retrieveInterestRateFrequencyTypeOptions(); + + CollectionamortizationTypeOptions = dropdownReadPlatformService.retrieveLoanAmortizationTypeOptions(); + CollectioninterestTypeOptions = dropdownReadPlatformService.retrieveLoanInterestTypeOptions(); + CollectioninterestCalculationPeriodTypeOptions = dropdownReadPlatformService.retrieveLoanInterestRateCalculatedInPeriodOptions(); + + Collection fundOptions = this.fundReadPlatformService.retrieveAllFunds(); + Collection transactionProcessingStrategyOptions = this.dropdownReadPlatformService.retreiveTransactionProcessingStrategies(); + + LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService.retrieveClientAndProductDetails(clientId, productId); + + final boolean convenienceDataRequired = false; + Collection charges = null; + final LoanAccountData newLoanAccount = new LoanAccountData(loanBasicDetails, convenienceDataRequired, null, null, null, null, charges, + productOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions, + transactionProcessingStrategyOptions, interestRateFrequencyTypeOptions, + amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions, fundOptions); - return this.apiJsonSerializerService.serializeNewLoanDataToJson(prettyPrint, responseParameters, workflowData); + return this.apiJsonSerializerService.serialzieLoanAccountDataToJson(prettyPrint, responseParameters, newLoanAccount); } @GET @@ -145,6 +182,7 @@ public class LoansApiResource { LoanPermissionData permissions = null; Collection charges = null; + boolean convenienceDataRequired = false; Set associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters()); if (!associationParameters.isEmpty()) { if (associationParameters.contains("all")) { @@ -160,7 +198,8 @@ public class LoansApiResource { boolean isWaiveAllowed = summary.isWaiveAllowed(loanBasicDetails.getCurrency(), loanBasicDetails.getInArrearsTolerance()); permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails, isWaiveAllowed, loanRepayments.size()); - + convenienceDataRequired = true; + charges = this.chargeReadPlatformService.retrieveLoanCharges(loanId); } @@ -193,7 +232,7 @@ public class LoansApiResource { transactionProcessingStrategyOptions = this.dropdownReadPlatformService.retreiveTransactionProcessingStrategies(); } - final LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, summary, repaymentSchedule, loanRepayments, permissions, charges, + final LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, convenienceDataRequired, summary, repaymentSchedule, loanRepayments, permissions, charges, productOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions, transactionProcessingStrategyOptions, interestRateFrequencyTypeOptions, amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions, fundOptions); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/LoanAccountData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/LoanAccountData.java index eb702a9a2..07e916cc9 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/LoanAccountData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/LoanAccountData.java @@ -67,9 +67,10 @@ public class LoanAccountData { private final LoanPermissionData permissions; private final LoanConvenienceData convenienceData; - + public LoanAccountData( final LoanBasicDetailsData basicDetails, + final boolean convenienceDataRequired, final LoanAccountSummaryData summary, final Collection repaymentSchedule, final Collection loanRepayments, @@ -99,22 +100,26 @@ public class LoanAccountData { this.interestCalculationPeriodTypeOptions = interestCalculationPeriodTypeOptions; this.fundOptions = fundOptions; - int maxSubmittedOnOffsetFromToday = basicDetails - .getMaxSubmittedOnOffsetFromToday(); - int maxApprovedOnOffsetFromToday = basicDetails - .getMaxApprovedOnOffsetFromToday(); - int maxDisbursedOnOffsetFromToday = basicDetails - .getMaxDisbursedOnOffsetFromToday(); - int expectedLoanTermInDays = basicDetails.getLoanTermInDays(); - int expectedLoanTermInMonths = basicDetails.getLoanTermInMonths(); - int actualLoanTermInDays = basicDetails.getActualLoanTermInDays(); - int actualLoanTermInMonths = basicDetails.getActualLoanTermInMonths(); - - this.convenienceData = new LoanConvenienceData( - maxSubmittedOnOffsetFromToday, maxApprovedOnOffsetFromToday, - maxDisbursedOnOffsetFromToday, expectedLoanTermInDays, - actualLoanTermInDays, expectedLoanTermInMonths, - actualLoanTermInMonths); + if (convenienceDataRequired) { + int maxSubmittedOnOffsetFromToday = basicDetails + .getMaxSubmittedOnOffsetFromToday(); + int maxApprovedOnOffsetFromToday = basicDetails + .getMaxApprovedOnOffsetFromToday(); + int maxDisbursedOnOffsetFromToday = basicDetails + .getMaxDisbursedOnOffsetFromToday(); + int expectedLoanTermInDays = basicDetails.getLoanTermInDays(); + int expectedLoanTermInMonths = basicDetails.getLoanTermInMonths(); + int actualLoanTermInDays = basicDetails.getActualLoanTermInDays(); + int actualLoanTermInMonths = basicDetails.getActualLoanTermInMonths(); + + this.convenienceData = new LoanConvenienceData( + maxSubmittedOnOffsetFromToday, maxApprovedOnOffsetFromToday, + maxDisbursedOnOffsetFromToday, expectedLoanTermInDays, + actualLoanTermInDays, expectedLoanTermInMonths, + actualLoanTermInMonths); + } else { + this.convenienceData = null; + } this.id = basicDetails.getId(); this.externalId = basicDetails.getExternalId(); @@ -133,7 +138,7 @@ public class LoanAccountData { this.actualDisbursementDate = basicDetails.getActualDisbursementDate(); this.closedOnDate = basicDetails.getClosedOnDate(); this.expectedMaturityDate = basicDetails.getExpectedMaturityDate(); - this.repaymentsStartingFromDate = basicDetails.getExpectedFirstRepaymentOnDate(); + this.repaymentsStartingFromDate = basicDetails.getRepaymentsStartingFromDate(); this.interestChargedFromDate = basicDetails.getInterestChargedFromDate(); this.currency = basicDetails.getCurrency(); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/LoanBasicDetailsData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/LoanBasicDetailsData.java index 5b9557252..74595df89 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/LoanBasicDetailsData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/LoanBasicDetailsData.java @@ -7,6 +7,9 @@ import org.joda.time.Days; import org.joda.time.LocalDate; import org.joda.time.Months; +/** + * Immutable data object for core details of loan to be combined with {@link LoanAccountData} usage. + */ public class LoanBasicDetailsData { private final Long id; @@ -16,38 +19,156 @@ public class LoanBasicDetailsData { private final Long loanProductId; private final String loanProductName; private final String loanProductDescription; + private final EnumOptionData status; private final Long fundId; private final String fundName; - private final EnumOptionData status; + private final CurrencyData currency; + private final BigDecimal principal; + private final BigDecimal inArrearsTolerance; + + private final Integer termFrequency; + private final EnumOptionData termPeriodFrequencyType; + private final Integer numberOfRepayments; + private final Integer repaymentEvery; + private final EnumOptionData repaymentFrequencyType; + private final Integer transactionStrategyId; + private final EnumOptionData amortizationType; + private final BigDecimal interestRatePerPeriod; + private final EnumOptionData interestRateFrequencyType; + private final BigDecimal annualInterestRate; + private final EnumOptionData interestType; + private final EnumOptionData interestCalculationPeriodType; private final LocalDate submittedOnDate; private final LocalDate approvedOnDate; private final LocalDate expectedDisbursementDate; private final LocalDate actualDisbursementDate; - private final LocalDate expectedFirstRepaymentOnDate; + private final LocalDate repaymentsStartingFromDate; private final LocalDate interestChargedFromDate; private final LocalDate closedOnDate; private final LocalDate expectedMaturityDate; - - private final CurrencyData currency; - private final BigDecimal principal; - private final BigDecimal inArrearsTolerance; - - private final Integer termFrequency; - private final EnumOptionData termPeriodFrequencyType; - private final Integer numberOfRepayments; - private final Integer repaymentEvery; - private final Integer transactionStrategyId; - private final BigDecimal interestRatePerPeriod; - private final BigDecimal annualInterestRate; - - private final EnumOptionData repaymentFrequencyType; - private final EnumOptionData interestRateFrequencyType; - private final EnumOptionData amortizationType; - private final EnumOptionData interestType; - private final EnumOptionData interestCalculationPeriodType; - private final LocalDate lifeCycleStatusDate; + + public static LoanBasicDetailsData populateForNewLoanCreation(final Long clientId, final String clientName, final LocalDate expectedDisbursementDate) { + return new LoanBasicDetailsData(clientId, clientName, expectedDisbursementDate); + } + + public static LoanBasicDetailsData populateForNewLoanCreation(final LoanBasicDetailsData loanAccount, final LoanProductData product) { + + final Integer termFrequency = product.getNumberOfRepayments() * product.getRepaymentEvery(); + final EnumOptionData termPeriodFrequencyType = product.getRepaymentFrequencyType(); + return new LoanBasicDetailsData( + loanAccount.clientId, loanAccount.clientName, + product.getId(), product.getName(), product.getDescription(), product.getFundId(), product.getFundName(), + product.getCurrency(), product.getPrincipal(), product.getInArrearsTolerance(), + termFrequency, termPeriodFrequencyType, product.getNumberOfRepayments(), product.getRepaymentEvery(), product.getRepaymentFrequencyType(), + product.getTransactionProcessingStrategyId(), product.getAmortizationType(), + product.getInterestRatePerPeriod(), product.getInterestRateFrequencyType(), product.getInterestType(), product.getInterestCalculationPeriodType(), + loanAccount.expectedDisbursementDate); + } + + private LoanBasicDetailsData( + final Long clientId, final String clientName, + final Long productId, final String productName, final String productDescription, final Long fundId, final String fundName, + final CurrencyData currency, final BigDecimal principal, final BigDecimal inArrearsTolerance, + final Integer termFrequency, + final EnumOptionData termPeriodFrequencyType, + final Integer numberOfRepayments, + final Integer repaymentEvery, + final EnumOptionData repaymentFrequencyType, + final Long transactionStrategyId, + final EnumOptionData amortizationType, + final BigDecimal interestRatePerPeriod, + final EnumOptionData interestRateFrequencyType, + final EnumOptionData interestType, + final EnumOptionData interestCalculationPeriodType, + final LocalDate expectedDisbursementDate) { + this.id = null; + this.externalId = null; + this.clientId = clientId; + this.clientName = clientName; + this.loanProductId = productId; + this.loanProductName = productName; + this.loanProductDescription= productDescription; + this.status = null; + this.fundId = fundId; + this.fundName = fundName; + this.currency = currency; + this.principal = principal; + this.inArrearsTolerance = inArrearsTolerance; + + this.termFrequency = termFrequency; + this.termPeriodFrequencyType = termPeriodFrequencyType; + this.numberOfRepayments = numberOfRepayments; + this.repaymentEvery = repaymentEvery; + this.repaymentFrequencyType = repaymentFrequencyType; + + // FIXME - kw - settle on using either long or integer for this throughout product and account fields for loan. + if (transactionStrategyId != null) { + this.transactionStrategyId = transactionStrategyId.intValue(); + } else { + this.transactionStrategyId = null; + } + this.amortizationType = amortizationType; + + this.interestRatePerPeriod = interestRatePerPeriod; + this.annualInterestRate = null; + this.interestRateFrequencyType = interestRateFrequencyType; + this.interestType = interestType; + this.interestCalculationPeriodType = interestCalculationPeriodType; + + this.submittedOnDate = null; + this.approvedOnDate = null; + this.expectedDisbursementDate = expectedDisbursementDate; + + this.actualDisbursementDate = null; + this.closedOnDate = null; + this.expectedMaturityDate = null; + this.repaymentsStartingFromDate = null; + this.interestChargedFromDate = null; + this.lifeCycleStatusDate = null; + } + + private LoanBasicDetailsData(final Long clientId, final String clientName, final LocalDate expectedDisbursementDate) { + this.id = null; + this.externalId = null; + this.clientId = clientId; + this.clientName = clientName; + this.loanProductId = null; + this.loanProductName = null; + this.loanProductDescription= null; + this.status = null; + this.fundId = null; + this.fundName = null; + + this.currency = null; + this.principal = null; + this.inArrearsTolerance = null; + this.termFrequency = null; + this.termPeriodFrequencyType = null; + this.numberOfRepayments = null; + this.repaymentEvery = null; + this.transactionStrategyId = null; + this.interestRatePerPeriod = null; + this.annualInterestRate = null; + this.repaymentFrequencyType = null; + this.interestRateFrequencyType = null; + this.amortizationType = null; + this.interestType = null; + this.interestCalculationPeriodType = null; + + this.lifeCycleStatusDate = null; + + this.submittedOnDate = null; + this.approvedOnDate = null; + this.expectedDisbursementDate = expectedDisbursementDate; + + this.actualDisbursementDate = null; + this.closedOnDate = null; + this.expectedMaturityDate = null; + this.repaymentsStartingFromDate = null; + this.interestChargedFromDate = null; + } public LoanBasicDetailsData( final Long id, @@ -63,7 +184,7 @@ public class LoanBasicDetailsData { final LocalDate expectedDisbursementDate, final LocalDate actualDisbursementDate, final LocalDate expectedMaturityDate, - final LocalDate expectedFirstRepaymentOnDate, + final LocalDate repaymentsStartingFromDate, final LocalDate interestChargedFromDate, final CurrencyData currency, final BigDecimal principal, @@ -97,7 +218,7 @@ public class LoanBasicDetailsData { this.expectedDisbursementDate = expectedDisbursementDate; this.actualDisbursementDate = actualDisbursementDate; this.expectedMaturityDate = expectedMaturityDate; - this.expectedFirstRepaymentOnDate = expectedFirstRepaymentOnDate; + this.repaymentsStartingFromDate = repaymentsStartingFromDate; this.interestChargedFromDate = interestChargedFromDate; this.currency = currency; this.principal = principal; @@ -270,9 +391,9 @@ public class LoanBasicDetailsData { public LocalDate getActualDisbursementDate() { return actualDisbursementDate; } - - public LocalDate getExpectedFirstRepaymentOnDate() { - return expectedFirstRepaymentOnDate; + + public LocalDate getRepaymentsStartingFromDate() { + return repaymentsStartingFromDate; } public LocalDate getInterestChargedFromDate() { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/NewLoanData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/NewLoanData.java deleted file mode 100644 index 0401f7179..000000000 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/NewLoanData.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.mifosng.platform.api.data; - -import java.util.ArrayList; -import java.util.List; - -import org.joda.time.LocalDate; - -public class NewLoanData { - - private Long clientId; - private String clientName; - private Long productId; - private String productName; - - private LoanProductData selectedProduct; - - private LocalDate expectedDisbursementDate; - - private List allowedProducts = new ArrayList(); - - public NewLoanData() { - // - } - - public Long getClientId() { - return clientId; - } - - public void setClientId(Long clientId) { - this.clientId = clientId; - } - - public String getClientName() { - return clientName; - } - - public void setClientName(String clientName) { - this.clientName = clientName; - } - - public Long getProductId() { - return productId; - } - - public void setProductId(Long productId) { - this.productId = productId; - } - - public String getProductName() { - return productName; - } - - public void setProductName(String productName) { - this.productName = productName; - } - - public List getAllowedProducts() { - return allowedProducts; - } - - public void setAllowedProducts(List allowedProducts) { - this.allowedProducts = allowedProducts; - } - - public LoanProductData getSelectedProduct() { - return selectedProduct; - } - - public void setSelectedProduct(LoanProductData selectedProduct) { - this.selectedProduct = selectedProduct; - } - - public LocalDate getExpectedDisbursementDate() { - return expectedDisbursementDate; - } - - public void setExpectedDisbursementDate(LocalDate expectedDisbursementDate) { - this.expectedDisbursementDate = expectedDisbursementDate; - } -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiJsonSerializerService.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiJsonSerializerService.java index 0a4f479d8..a308ff0d4 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiJsonSerializerService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiJsonSerializerService.java @@ -7,8 +7,8 @@ import org.mifosng.platform.api.data.AdditionalFieldsSetData; import org.mifosng.platform.api.data.AppUserData; import org.mifosng.platform.api.data.AuthenticatedUserData; import org.mifosng.platform.api.data.ChargeData; -import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.ClientAccountSummaryCollectionData; +import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.ConfigurationData; import org.mifosng.platform.api.data.DepositAccountData; import org.mifosng.platform.api.data.DepositProductData; @@ -18,7 +18,6 @@ import org.mifosng.platform.api.data.GroupData; import org.mifosng.platform.api.data.LoanAccountData; import org.mifosng.platform.api.data.LoanProductData; import org.mifosng.platform.api.data.LoanTransactionData; -import org.mifosng.platform.api.data.NewLoanData; import org.mifosng.platform.api.data.NoteData; import org.mifosng.platform.api.data.OfficeData; import org.mifosng.platform.api.data.OfficeTransactionData; @@ -89,8 +88,6 @@ public interface ApiJsonSerializerService { String serializeNoteDataToJson(boolean prettyPrint, Set responseParameters, NoteData note); - String serializeNewLoanDataToJson(boolean prettyPrint, Set responseParameters, NewLoanData newLoan); - String serialzieLoanAccountDataToJson(boolean prettyPrint, Set responseParameters, LoanAccountData loanAccount); String serializeLoanTransactionDataToJson(boolean prettyPrint, Set responseParameters, LoanTransactionData transaction); 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 8694e41f0..c4172b203 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 @@ -9,8 +9,8 @@ import org.mifosng.platform.api.data.AdditionalFieldsSetData; import org.mifosng.platform.api.data.AppUserData; import org.mifosng.platform.api.data.AuthenticatedUserData; import org.mifosng.platform.api.data.ChargeData; -import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.ClientAccountSummaryCollectionData; +import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.ConfigurationData; import org.mifosng.platform.api.data.DepositAccountData; import org.mifosng.platform.api.data.DepositProductData; @@ -20,7 +20,6 @@ import org.mifosng.platform.api.data.GroupData; import org.mifosng.platform.api.data.LoanAccountData; import org.mifosng.platform.api.data.LoanProductData; import org.mifosng.platform.api.data.LoanTransactionData; -import org.mifosng.platform.api.data.NewLoanData; import org.mifosng.platform.api.data.NoteData; import org.mifosng.platform.api.data.OfficeData; import org.mifosng.platform.api.data.OfficeTransactionData; @@ -38,8 +37,7 @@ import com.google.gson.Gson; * serialize Java object representation into JSON. */ @Service -public class GoogleGsonApiJsonSerializerService implements - ApiJsonSerializerService { +public class GoogleGsonApiJsonSerializerService implements ApiJsonSerializerService { private static final Set PERMISSION_DATA_PARAMETERS = new HashSet( Arrays.asList("id", "name", "description", "code")); @@ -133,11 +131,6 @@ public class GoogleGsonApiJsonSerializerService implements "createdOn", "updatedById", "updatedByUsername", "updatedOn")); - private static final Set NEW_LOAN_DATA_PARAMETERS = new HashSet( - Arrays.asList("clientId", "clientName", "productId", "productName", - "selectedProduct", "expectedDisbursementDate", - "allowedProducts")); - private static final Set LOAN_DATA_PARAMETERS = new HashSet( Arrays.asList("id", "externalId", "clientId", "clientName", "fundId", "fundName", "loanProductId", "loanProductName", "loanProductDescription", @@ -488,16 +481,6 @@ public class GoogleGsonApiJsonSerializerService implements return helper.serializedJsonFrom(gsonDeserializer, note); } - @Override - public String serializeNewLoanDataToJson(final boolean prettyPrint, - final Set responseParameters, final NewLoanData newLoan) { - final Gson gsonDeserializer = helper - .createGsonBuilderWithParameterExclusionSerializationStrategy( - NEW_LOAN_DATA_PARAMETERS, prettyPrint, - responseParameters); - return helper.serializedJsonFrom(gsonDeserializer, newLoan); - } - @Override public String serialzieLoanAccountDataToJson(final boolean prettyPrint, final Set responseParameters, diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformService.java index c27cd3e0f..db2f0dd13 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformService.java @@ -9,7 +9,6 @@ import org.mifosng.platform.api.data.LoanPermissionData; import org.mifosng.platform.api.data.LoanRepaymentPeriodData; import org.mifosng.platform.api.data.LoanRepaymentTransactionData; import org.mifosng.platform.api.data.LoanTransactionData; -import org.mifosng.platform.api.data.NewLoanData; public interface LoanReadPlatformService { @@ -27,13 +26,11 @@ public interface LoanReadPlatformService { LoanBasicDetailsData loanBasicDetails, boolean isWaiverAllowed, int repaymentAndWaiveCount); - NewLoanData retrieveClientAndProductDetails(Long clientId, Long productId); + LoanBasicDetailsData retrieveClientAndProductDetails(Long clientId, Long productId); LoanTransactionData retrieveNewLoanRepaymentDetails(Long loanId); LoanTransactionData retrieveNewLoanWaiverDetails(Long loanId); - LoanTransactionData retrieveLoanTransactionDetails(Long loanId, - Long transactionId); - + LoanTransactionData retrieveLoanTransactionDetails(Long loanId, Long transactionId); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java index 0bff24f5d..8d410773e 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java @@ -3,11 +3,9 @@ package org.mifosng.platform.loan.service; import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Collection; import org.joda.time.LocalDate; -import org.mifosng.platform.api.data.ChargeData; import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.CurrencyData; import org.mifosng.platform.api.data.EnumOptionData; @@ -15,13 +13,10 @@ import org.mifosng.platform.api.data.LoanAccountSummaryData; import org.mifosng.platform.api.data.LoanBasicDetailsData; import org.mifosng.platform.api.data.LoanPermissionData; import org.mifosng.platform.api.data.LoanProductData; -import org.mifosng.platform.api.data.LoanProductLookup; import org.mifosng.platform.api.data.LoanRepaymentPeriodData; import org.mifosng.platform.api.data.LoanRepaymentTransactionData; import org.mifosng.platform.api.data.LoanTransactionData; import org.mifosng.platform.api.data.MoneyData; -import org.mifosng.platform.api.data.NewLoanData; -import org.mifosng.platform.charge.service.ChargeReadPlatformService; import org.mifosng.platform.client.service.ClientReadPlatformService; import org.mifosng.platform.currency.domain.ApplicationCurrency; import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository; @@ -55,7 +50,6 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { private final LoanProductReadPlatformService loanProductReadPlatformService; private final ClientReadPlatformService clientReadPlatformService; private final LoanTransactionRepository loanTransactionRepository; - private final ChargeReadPlatformService chargeReadPlatformService; @Autowired public LoanReadPlatformServiceImpl( @@ -65,7 +59,6 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { final ApplicationCurrencyRepository applicationCurrencyRepository, final LoanProductReadPlatformService loanProductReadPlatformService, final ClientReadPlatformService clientReadPlatformService, - final ChargeReadPlatformService chargeReadPlatformService, final TenantAwareRoutingDataSource dataSource) { this.context = context; this.loanRepository = loanRepository; @@ -73,7 +66,6 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { this.applicationCurrencyRepository = applicationCurrencyRepository; this.loanProductReadPlatformService = loanProductReadPlatformService; this.clientReadPlatformService = clientReadPlatformService; - this.chargeReadPlatformService = chargeReadPlatformService; this.jdbcTemplate = new JdbcTemplate(dataSource); } @@ -234,51 +226,21 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { } @Override - public NewLoanData retrieveClientAndProductDetails(final Long clientId, - final Long productId) { + public LoanBasicDetailsData retrieveClientAndProductDetails(final Long clientId, final Long productId) { context.authenticatedUser(); - NewLoanData workflowData = new NewLoanData(); - - Collection loanProducts = this.loanProductReadPlatformService - .retrieveAllLoanProductsForLookup(); - workflowData.setAllowedProducts(new ArrayList( - loanProducts)); - + final LocalDate expectedDisbursementDate = new LocalDate(); + final ClientData clientAccount = this.clientReadPlatformService.retrieveIndividualClient(clientId); + + LoanBasicDetailsData loanDetails = LoanBasicDetailsData.populateForNewLoanCreation(clientAccount.getId(), clientAccount.getDisplayName(), expectedDisbursementDate); + if (productId != null) { - LoanProductData selectedProduct = findLoanProductById(loanProducts, productId); - - workflowData.setProductId(selectedProduct.getId()); - workflowData.setProductName(selectedProduct.getName()); - workflowData.setSelectedProduct(selectedProduct); + LoanProductData selectedProduct = this.loanProductReadPlatformService.retrieveLoanProduct(productId); + loanDetails = LoanBasicDetailsData.populateForNewLoanCreation(loanDetails, selectedProduct); } - ClientData clientAccount = this.clientReadPlatformService - .retrieveIndividualClient(clientId); - workflowData.setClientId(clientAccount.getId()); - workflowData.setClientName(clientAccount.getDisplayName()); - - workflowData.setExpectedDisbursementDate(new LocalDate()); - - return workflowData; - } - - private LoanProductData findLoanProductById( - Collection loanProducts, Long productId) { - LoanProductData match = this.loanProductReadPlatformService - .retrieveNewLoanProductDetails(); - for (LoanProductLookup loanProductLookup : loanProducts) { - if (loanProductLookup.getId().equals(productId)) { - match = this.loanProductReadPlatformService - .retrieveLoanProduct(loanProductLookup.getId()); - Collection chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(); - chargeOptions.removeAll(match.getCharges()); - match.setChargeOptions(chargeOptions); - break; - } - } - return match; + return loanDetails; } @Override diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductReadPlatformServiceImpl.java index f46945bc2..8a4c3d50f 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductReadPlatformServiceImpl.java @@ -151,7 +151,7 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo } public String loanProductSchema() { - return "lp.id as id, lp.fund_id as fundId, f.name as fundName, lp.loan_transaction_strategy_id as transactionStrategyId, ltps.name as transactionStrategyName, " + return "lp.id as id, lp.fund_id as fundId, f.name as fundName, lp.loan_transaction_strategy_id as transactionStrategyId, ltps.name as transactionStrategyName, " + "lp.name as name, lp.description as description, lp.flexible_repayment_schedule as isFlexible, lp.interest_rebate as isInterestRebateAllowed, " + "lp.principal_amount as principal, lp.currency_code as currencyCode, lp.currency_digits as currencyDigits, " + "lp.nominal_interest_rate_per_period as interestRatePerPeriod, lp.interest_period_frequency_enum as interestRatePerPeriodFreq, " diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java index 2eabe1bd5..2ab02c652 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java @@ -141,7 +141,7 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro LoanTransactionProcessingStrategy loanTransactionProcessingStrategy = null; if (command.isTransactionProcessingStrategyChanged()) { - findStrategyByIdIfProvided(command.getTransactionProcessingStrategyId()); + loanTransactionProcessingStrategy = findStrategyByIdIfProvided(command.getTransactionProcessingStrategyId()); } final Set charges = this.assembleSetOfCharges(command, product.getCurrency().getCode());