diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupData.java index 4aaabe103..17831e1af 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupData.java @@ -42,6 +42,27 @@ public class GroupData { @SuppressWarnings("unused") private final Collection childGroups; + public GroupData(Long id, String name, String externalId, Long officeId, Long staffId, Long parentId, String hierarchy) { + this.id = id; + this.name = name; + this.externalId = externalId; + this.officeId = officeId; + this.staffId = staffId; + this.parentId = parentId; + this.hierarchy = hierarchy; + this.officeName = null; + this.parentName = null; + this.staffName = null; + this.groupSummaryData = null; + this.groupLevelData = null; + this.clientMembers = null; + this.allowedClients = null; + this.allowedOffices = null; + this.allowedParentGroups = null; + this.allowedStaffs = null; + this.childGroups = null; + } + public GroupData(final Long id, final Long officeId, final String officeName, final String name, final String externalId, final Long parentId, final String parentName, final Long staffId, final String staffName, final String hierarchy) { this.id = id; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java index 8ddbbb6b8..20a47c02d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java @@ -61,6 +61,8 @@ import org.mifosplatform.portfolio.loanaccount.service.LoanChargeReadPlatformSer import org.mifosplatform.portfolio.loanaccount.service.LoanReadPlatformService; import org.mifosplatform.portfolio.loanproduct.data.LoanProductData; import org.mifosplatform.portfolio.loanproduct.data.TransactionProcessingStrategyData; +import org.mifosplatform.portfolio.loanproduct.domain.LendingStrategy; +import org.mifosplatform.portfolio.loanproduct.exception.InvalidLendingStrategy; import org.mifosplatform.portfolio.loanproduct.service.LoanDropdownReadPlatformService; import org.mifosplatform.portfolio.loanproduct.service.LoanProductReadPlatformService; import org.springframework.beans.factory.annotation.Autowired; @@ -76,16 +78,16 @@ import com.google.gson.JsonElement; public class LoansApiResource { private final Set LOAN_DATA_PARAMETERS = new HashSet(Arrays.asList("id", "accountNo", "status", "externalId", - "clientId", "groupId", "clientName", "groupName", "loanProductId", "loanProductName", "loanProductDescription", "fundId", - "fundName", "loanPurposeId", "loanPurposeName", "loanOfficerId", "loanOfficerName", "currency", "principal", - "inArrearsTolerance", "termFrequency", "termPeriodFrequencyType", "numberOfRepayments", "repaymentEvery", - "interestRatePerPeriod", "annualInterestRate", "repaymentFrequencyType", "transactionProcessingStrategyId", - "interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType", - "expectedFirstRepaymentOnDate", "interestChargedFromDate", "timeline", "totalFeeChargesAtDisbursement", "summary", - "repaymentSchedule", "transactions", "charges", "collateral", "guarantors", "productOptions", "amortizationTypeOptions", - "interestTypeOptions", "interestCalculationPeriodTypeOptions", "repaymentFrequencyTypeOptions", "termFrequencyTypeOptions", - "interestRateFrequencyTypeOptions", "fundOptions", "repaymentStrategyOptions", "chargeOptions", "loanOfficerOptions", - "loanPurposeOptions", "loanCollateralOptions", "chargeTemplate")); + "clientId", "group", "loanProductId", "loanProductName", "loanProductDescription", "fundId", "fundName", "loanPurposeId", + "loanPurposeName", "loanOfficerId", "loanOfficerName", "currency", "principal", "inArrearsTolerance", "termFrequency", + "termPeriodFrequencyType", "numberOfRepayments", "repaymentEvery", "interestRatePerPeriod", "annualInterestRate", + "repaymentFrequencyType", "transactionProcessingStrategyId", "interestRateFrequencyType", "amortizationType", "interestType", + "interestCalculationPeriodType", "expectedFirstRepaymentOnDate", "interestChargedFromDate", "timeline", + "totalFeeChargesAtDisbursement", "summary", "repaymentSchedule", "transactions", "charges", "collateral", "guarantors", + "productOptions", "amortizationTypeOptions", "interestTypeOptions", "interestCalculationPeriodTypeOptions", + "repaymentFrequencyTypeOptions", "termFrequencyTypeOptions", "interestRateFrequencyTypeOptions", "fundOptions", + "repaymentStrategyOptions", "chargeOptions", "loanOfficerOptions", "loanPurposeOptions", "loanCollateralOptions", + "chargeTemplate")); private final String resourceNameForPermissions = "LOAN"; @@ -147,7 +149,7 @@ public class LoansApiResource { @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String template(@QueryParam("clientId") final Long clientId, @QueryParam("groupId") final Long groupId, - @QueryParam("productId") final Long productId, @Context final UriInfo uriInfo) { + @QueryParam("productId") final Long productId, @QueryParam("lendingStrategy") final Integer lendingStrategy, @Context final UriInfo uriInfo) { context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions); @@ -198,6 +200,7 @@ public class LoansApiResource { final LoanAccountData loanBasicDetails = this.loanReadPlatformService.retrieveTemplateWithClientAndProductDetails(clientId, productId); final Collection charges = loanBasicDetails.charges(); + if (productId != null) { final Long officeId = loanBasicDetails.officeId(); allowedLoanOfficers = this.staffReadPlatformService.retrieveAllLoanOfficersByOffice(officeId); @@ -209,9 +212,22 @@ public class LoansApiResource { interestCalculationPeriodTypeOptions, fundOptions, chargeOptions, chargeTemplate, allowedLoanOfficers, loanPurposeOptions, loanCollateralOptions); - } else if (groupId != null) { - final LoanAccountData loanBasicDetails = this.loanReadPlatformService.retrieveTemplateWithGroupAndProductDetails(groupId, - productId); + } else if (groupId != null ) { + + LoanAccountData loanBasicDetails = null; + + if (LendingStrategy.JOINT_LIABILITY_LOAN.getId().equals(lendingStrategy)){ + loanBasicDetails = this.loanReadPlatformService.retrieveTemplateWithCompleteGroupAndProductDetails(groupId, + productId); + } + else if( LendingStrategy.GROUP_LOAN.getId().equals(lendingStrategy)){ + loanBasicDetails = this.loanReadPlatformService.retrieveTemplateWithGroupAndProductDetails(groupId, + productId); + }else{ + throw new InvalidLendingStrategy(lendingStrategy); + } + + final Collection charges = loanBasicDetails.charges(); if (productId != null) { final Long officeId = loanBasicDetails.officeId(); @@ -223,7 +239,8 @@ public class LoansApiResource { repaymentStrategyOptions, interestRateFrequencyTypeOptions, amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions, fundOptions, chargeOptions, chargeTemplate, allowedLoanOfficers, loanPurposeOptions, loanCollateralOptions); - } else { + } + else { newLoanAccount = LoanAccountData.collateralTemplate(loanCollateralOptions); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/data/LoanAccountData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/data/LoanAccountData.java index 8cc3c0103..9aec45848 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/data/LoanAccountData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/data/LoanAccountData.java @@ -19,6 +19,7 @@ import org.mifosplatform.organisation.staff.data.StaffData; import org.mifosplatform.portfolio.charge.data.ChargeData; import org.mifosplatform.portfolio.collateral.data.CollateralData; import org.mifosplatform.portfolio.fund.data.FundData; +import org.mifosplatform.portfolio.group.data.GroupData; import org.mifosplatform.portfolio.loanaccount.guarantor.data.GuarantorData; import org.mifosplatform.portfolio.loanaccount.loanschedule.data.LoanScheduleData; import org.mifosplatform.portfolio.loanproduct.data.LoanProductData; @@ -45,9 +46,7 @@ public class LoanAccountData { private final Long clientId; private final String clientName; private final Long clientOfficeId; - private final Long groupId; - private final String groupName; - private final Long groupOfficeId; + private final GroupData group; private final Long loanProductId; private final String loanProductName; private final String loanProductDescription; @@ -122,9 +121,7 @@ public class LoanAccountData { final Long clientId = null; final String clientName = null; final Long clientOfficeId = null; - final Long groupId = null; - final String groupName = null; - final Long groupOfficeId = null; + final GroupData group = null; final Long loanProductId = null; final String loanProductName = null; final String loanProductDescription = null; @@ -174,8 +171,8 @@ public class LoanAccountData { final Collection loanOfficerOptions = null; final Collection loanPurposeOptions = null; - return new LoanAccountData(id, accountNo, status, externalId, clientId, clientName, clientOfficeId, groupId, groupName, - groupOfficeId, loanProductId, loanProductName, loanProductDescription, fundId, fundName, loanPurposeId, loanPurposeName, + return new LoanAccountData(id, accountNo, status, externalId, clientId, clientName, clientOfficeId, group, + loanProductId, loanProductName, loanProductDescription, fundId, fundName, loanPurposeId, loanPurposeName, loanOfficerId, loanOfficerName, currencyData, principal, inArrearsTolerance, termFrequency, termPeriodFrequencyType, numberOfRepayments, repaymentEvery, repaymentFrequencyType, transactionProcessingStrategyId, amortizationType, interestRatePerPeriod, interestRateFrequencyType, annualInterestRate, interestType, interestCalculationPeriodType, @@ -196,9 +193,8 @@ public class LoanAccountData { final String accountNo = null; final LoanStatusEnumData status = null; final String externalId = null; - final Long groupId = null; + final GroupData group = null; final String groupName = null; - final Long groupOfficeId = null; final Long loanProductId = null; final String loanProductName = null; final String loanProductDescription = null; @@ -249,8 +245,8 @@ public class LoanAccountData { final Collection loanPurposeOptions = null; final Collection loanCollateralOptions = null; - return new LoanAccountData(id, accountNo, status, externalId, clientId, clientName, clientOfficeId, groupId, groupName, - groupOfficeId, loanProductId, loanProductName, loanProductDescription, fundId, fundName, loanPurposeId, loanPurposeName, + return new LoanAccountData(id, accountNo, status, externalId, clientId, clientName, clientOfficeId, group, + loanProductId, loanProductName, loanProductDescription, fundId, fundName, loanPurposeId, loanPurposeName, loanOfficerId, loanOfficerName, currencyData, principal, inArrearsTolerance, termFrequency, termPeriodFrequencyType, numberOfRepayments, repaymentEvery, repaymentFrequencyType, transactionProcessingStrategyId, amortizationType, interestRatePerPeriod, interestRateFrequencyType, annualInterestRate, interestType, interestCalculationPeriodType, @@ -265,7 +261,7 @@ public class LoanAccountData { * Used to produce a {@link LoanAccountData} with only group information * defaulted. */ - public static LoanAccountData groupDefaults(final Long groupId, final String groupName, final Long groupOfficeId, + public static LoanAccountData groupDefaults(final GroupData group, final LocalDate expectedDisbursementDate) { final Long id = null; @@ -325,8 +321,8 @@ public class LoanAccountData { final Collection loanPurposeOptions = null; final Collection loanCollateralOptions = null; - return new LoanAccountData(id, accountNo, status, externalId, clientId, clientName, clientOfficeId, groupId, groupName, - groupOfficeId, loanProductId, loanProductName, loanProductDescription, fundId, fundName, loanPurposeId, loanPurposeName, + return new LoanAccountData(id, accountNo, status, externalId, clientId, clientName, clientOfficeId, group, + loanProductId, loanProductName, loanProductDescription, fundId, fundName, loanPurposeId, loanPurposeName, loanOfficerId, loanOfficerName, currencyData, principal, inArrearsTolerance, termFrequency, termPeriodFrequencyType, numberOfRepayments, repaymentEvery, repaymentFrequencyType, transactionProcessingStrategyId, amortizationType, interestRatePerPeriod, interestRateFrequencyType, annualInterestRate, interestType, interestCalculationPeriodType, @@ -367,7 +363,7 @@ public class LoanAccountData { } return new LoanAccountData(acc.id, acc.accountNo, acc.status, acc.externalId, acc.clientId, acc.clientName, acc.clientOfficeId, - acc.groupId, acc.groupName, acc.groupOfficeId, product.getId(), product.getName(), product.getDescription(), + acc.group, product.getId(), product.getName(), product.getDescription(), product.getFundId(), product.getFundName(), acc.loanPurposeId, acc.loanPurposeName, acc.loanOfficerId, acc.loanOfficerName, product.getCurrency(), product.getPrincipal(), product.getInArrearsTolerance(), termFrequency, termPeriodFrequencyType, product.getNumberOfRepayments(), product.getRepaymentEvery(), product.getRepaymentFrequencyType(), @@ -385,8 +381,8 @@ public class LoanAccountData { * query. */ public static LoanAccountData basicLoanDetails(final Long id, final String accountNo, final LoanStatusEnumData status, - final String externalId, final Long clientId, final String clientName, final Long clientOfficeId, final Long groupId, - final String groupName, final Long groupOfficeId, final Long loanProductId, final String loanProductName, + final String externalId, final Long clientId, final String clientName, final Long clientOfficeId, final GroupData group, + final Long loanProductId, final String loanProductName, final String loanProductDescription, final Long fundId, final String fundName, final Long loanPurposeId, final String loanPurposeName, final Long loanOfficerId, final String loanOfficerName, final CurrencyData currencyData, final BigDecimal principal, final BigDecimal inArrearsTolerance, final Integer termFrequency, @@ -418,8 +414,8 @@ public class LoanAccountData { final Collection loanPurposeOptions = null; final Collection loanCollateralOptions = null; - return new LoanAccountData(id, accountNo, status, externalId, clientId, clientName, clientOfficeId, groupId, groupName, - groupOfficeId, loanProductId, loanProductName, loanProductDescription, fundId, fundName, loanPurposeId, loanPurposeName, + return new LoanAccountData(id, accountNo, status, externalId, clientId, clientName, clientOfficeId, group, + loanProductId, loanProductName, loanProductDescription, fundId, fundName, loanPurposeId, loanPurposeName, loanOfficerId, loanOfficerName, currencyData, principal, inArrearsTolerance, termFrequency, termPeriodFrequencyType, numberOfRepayments, repaymentEvery, repaymentFrequencyType, transactionStrategyId, amortizationType, interestRatePerPeriod, interestRateFrequencyType, annualInterestRate, interestType, interestCalculationPeriodType, expectedFirstRepaymentOnDate, @@ -446,7 +442,7 @@ public class LoanAccountData { final Collection loanOfficerOptions, final Collection loanPurposeOptions, final Collection loanCollateralOptions) { return new LoanAccountData(acc.id, acc.accountNo, acc.status, acc.externalId, acc.clientId, acc.clientName, acc.clientOfficeId, - acc.groupId, acc.groupName, acc.groupOfficeId, acc.loanProductId, acc.loanProductName, acc.loanProductDescription, + acc.group, acc.loanProductId, acc.loanProductName, acc.loanProductDescription, acc.fundId, acc.fundName, acc.loanPurposeId, acc.loanPurposeName, acc.loanOfficerId, acc.loanOfficerName, acc.currency, acc.principal, acc.inArrearsTolerance, acc.termFrequency, acc.termPeriodFrequencyType, acc.numberOfRepayments, acc.repaymentEvery, acc.repaymentFrequencyType, acc.transactionProcessingStrategyId, acc.amortizationType, @@ -466,9 +462,7 @@ public class LoanAccountData { final Long clientId, final String clientName, final Long clientOfficeId, // - final Long groupId, - final String groupName, - final Long groupOfficeId, // + final GroupData group, final Long loanProductId, final String loanProductName, final String loanProductDescription, // @@ -508,9 +502,7 @@ public class LoanAccountData { this.clientId = clientId; this.clientName = clientName; this.clientOfficeId = clientOfficeId; - this.groupId = groupId; - this.groupName = groupName; - this.groupOfficeId = groupOfficeId; + this.group = group; this.loanProductId = loanProductId; this.loanProductName = loanProductName; this.loanProductDescription = loanProductDescription; @@ -602,13 +594,7 @@ public class LoanAccountData { } public Long officeId() { - Long officeId = this.clientOfficeId; - - if (officeId == null) { - officeId = this.groupOfficeId; - } - - return officeId; + return this.clientOfficeId; } public Long loanOfficerId() { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformService.java index d4c3d54e5..893a6892f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformService.java @@ -31,4 +31,6 @@ public interface LoanReadPlatformService { LoanTransactionData retrieveLoanTransaction(Long loanId, Long transactionId); LoanTransactionData retrieveNewClosureDetails(); + + LoanAccountData retrieveTemplateWithCompleteGroupAndProductDetails(Long groupId, Long productId); } \ No newline at end of file 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 edcdd99f6..4606f64e3 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 @@ -158,10 +158,9 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { context.authenticatedUser(); - final GroupData groupAccount = this.groupReadPlatformService.retrieveGroup(groupId); + final GroupData groupAccount = this.groupReadPlatformService.retrieveGroupDetails(groupId , false); final LocalDate expectedDisbursementDate = DateUtils.getLocalDateOfTenant(); - LoanAccountData loanDetails = LoanAccountData.groupDefaults(groupAccount.getId(), groupAccount.getName(), - groupAccount.getOfficeId(), expectedDisbursementDate); + LoanAccountData loanDetails = LoanAccountData.groupDefaults(groupAccount, expectedDisbursementDate); if (productId != null) { LoanProductData selectedProduct = this.loanProductReadPlatformService.retrieveLoanProduct(productId); @@ -170,7 +169,25 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { return loanDetails; } + + @Override + public LoanAccountData retrieveTemplateWithCompleteGroupAndProductDetails(Long groupId, Long productId){ + + context.authenticatedUser(); + final GroupData groupAccount = this.groupReadPlatformService.retrieveGroup(groupId); + final LocalDate expectedDisbursementDate = DateUtils.getLocalDateOfTenant(); + LoanAccountData loanDetails = LoanAccountData.groupDefaults(groupAccount, expectedDisbursementDate); + + if (productId != null) { + LoanProductData selectedProduct = this.loanProductReadPlatformService.retrieveLoanProduct(productId); + loanDetails = LoanAccountData.populateLoanProductDefaults(loanDetails, selectedProduct); + } + + return loanDetails; + } + + @Override public LoanTransactionData retrieveLoanTransactionTemplate(final Long loanId) { @@ -263,7 +280,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { + " l.loanpurpose_cv_id as loanPurposeId, cv.code_value as loanPurposeName," + " lp.id as loanProductId, lp.name as loanProductName, lp.description as loanProductDescription," + " c.id as clientId, c.display_name as clientName, c.office_id as clientOfficeId," - + " g.id as groupId, g.name as groupName, g.office_id as groupOfficeId," + + " g.id as groupId, g.name as groupName, g.office_id as groupOfficeId, g.staff_id As groupStaffId , g.parent_id as groupParentId , g.hierarchy As groupHierarchy , g.external_id As groupExternalId , " + " l.submittedon_date as submittedOnDate, sbu.username as submittedByUsername, sbu.firstname as submittedByFirstname, sbu.lastname as submittedByLastname," + " l.rejectedon_date as rejectedOnDate, rbu.username as rejectedByUsername, rbu.firstname as rejectedByFirstname, rbu.lastname as rejectedByLastname," + " l.withdrawnon_date as withdrawnOnDate, wbu.username as withdrawnByUsername, wbu.firstname as withdrawnByFirstname, wbu.lastname as withdrawnByLastname," @@ -349,8 +366,12 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { final String clientName = rs.getString("clientName"); final Long groupId = JdbcSupport.getLong(rs, "groupId"); - final Long groupOfficeId = JdbcSupport.getLong(rs, "groupOfficeId"); final String groupName = rs.getString("groupName"); + final String groupExternalId = rs.getString("groupExternalId"); + final Long groupOfficeId = JdbcSupport.getLong(rs, "groupOfficeId"); + final Long groupStaffId = JdbcSupport.getLong(rs, "groupStaffId"); + final Long groupParentId = JdbcSupport.getLong(rs, "groupParentId"); + final String groupHierarchy = rs.getString("groupHierarchy"); final Long fundId = JdbcSupport.getLong(rs, "fundId"); final String fundName = rs.getString("fundName"); @@ -494,8 +515,15 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { totalWaived, totalWrittenOff, totalOutstanding, totalOverdue, overdueSinceDate); } - return LoanAccountData.basicLoanDetails(id, accountNo, status, externalId, clientId, clientName, clientOfficeId, groupId, - groupName, groupOfficeId, loanProductId, loanProductName, loanProductDescription, fundId, fundName, loanPurposeId, + GroupData groupData = null; + + if(groupId != null){ + + groupData = new GroupData(groupId, groupName, groupExternalId, groupOfficeId, groupStaffId, groupParentId, groupHierarchy); + } + + return LoanAccountData.basicLoanDetails(id, accountNo, status, externalId, clientId, clientName, clientOfficeId, groupData, + loanProductId, loanProductName, loanProductDescription, fundId, fundName, loanPurposeId, loanPurposeName, loanOfficerId, loanOfficerName, currencyData, principal, inArrearsTolerance, termFrequency, termPeriodFrequencyType, numberOfRepayments, repaymentEvery, repaymentFrequencyType, transactionStrategyId, amortizationType, interestRatePerPeriod, interestRateFrequencyType, annualInterestRate, interestType, diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/domain/LendingStrategy.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/domain/LendingStrategy.java new file mode 100644 index 000000000..f7c5df6d3 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/domain/LendingStrategy.java @@ -0,0 +1,84 @@ +package org.mifosplatform.portfolio.loanproduct.domain; + +import java.util.HashMap; +import java.util.Map; + +/** + * INDIVIDUAL_LOAN: Individual loans are applicable only to clients. + * GROUP_LOAN: * Group loans are applicable only to groups. And tracked only at + * group level. + * JOINT_LIABILITY_LOAN: Joint liability loans are applicable only + * to clients within a group. + * LINKED_LOAN: Loan is given to group, then later loan amount is split into individual loans. Loan is tracked at both + * individual and group level + * + */ +public enum LendingStrategy { + + INDIVIDUAL_LOAN(100, "lendingStrategy.individaulLoan", "individaulLoan"), // + GROUP_LOAN(200, "lendingStrategy.groupLoan", "groupLoan"), // + JOINT_LIABILITY_LOAN(300, "lendingStrategy.joinLiabilityLoan", "joinLiabilityLoan"), // + LINKED_LOAN(400, "lendingStrategy.linkedLoan", "linkedLoan"), // + INVALID(900, "lendingStrategy.invalid", "invalid"); + + private Integer id; + private String code; + private String value; + + LendingStrategy(final Integer id, final String code, final String value) { + this.id = id; + this.code = code; + this.value = value; + } + + private static final Map intToEnumMap = new HashMap(); + private static int minValue; + private static int maxValue; + static { + int i = 0; + for (final LendingStrategy type : LendingStrategy.values()) { + if (i == 0) { + minValue = type.id; + } + intToEnumMap.put(type.id, type); + if (minValue >= type.id) { + minValue = type.id; + } + if (maxValue < type.id) { + maxValue = type.id; + } + i = i + 1; + } + } + + public static LendingStrategy fromInt(final int i) { + final LendingStrategy type = intToEnumMap.get(Integer.valueOf(i)); + return type; + } + + public static int getMinValue() { + return minValue; + } + + public static int getMaxValue() { + return maxValue; + } + + @Override + public String toString() { + return name().toString(); + } + + public Integer getId() { + return this.id; + } + + public String getCode() { + return this.code; + } + + public String getValue() { + return this.value; + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/exception/InvalidLendingStrategy.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/exception/InvalidLendingStrategy.java new file mode 100644 index 000000000..e03b721b2 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/exception/InvalidLendingStrategy.java @@ -0,0 +1,18 @@ +/** + * 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.loanproduct.exception; + +import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException; + +/** + * {@link AbstractPlatformDomainRuleException} thrown when lending strategy mismatch + * occurs + */ +public class InvalidLendingStrategy extends AbstractPlatformDomainRuleException { + public InvalidLendingStrategy(final Integer strategyId ) { + super("error.msg.unsupported.lending.strategy", "Stratagy code ["+ strategyId + "] passed is not valid."); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LendingStrategyEnumerations.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LendingStrategyEnumerations.java new file mode 100644 index 000000000..e8c4dd5a8 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LendingStrategyEnumerations.java @@ -0,0 +1,41 @@ +/** + * 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.loanproduct.service; + +import org.mifosplatform.infrastructure.core.data.EnumOptionData; +import org.mifosplatform.portfolio.loanproduct.domain.LendingStrategy; + +public class LendingStrategyEnumerations { + + public static EnumOptionData lendingStrategy(final Integer id) { + return lendingStrategy(LendingStrategy.fromInt(id)); + } + + public static EnumOptionData lendingStrategy(final LendingStrategy type) { + EnumOptionData optionData = null; + switch (type) { + case INDIVIDUAL_LOAN: + optionData = new EnumOptionData(type.getId().longValue(), type.getCode(), "Individual loan"); + break; + case GROUP_LOAN: + optionData = new EnumOptionData(type.getId().longValue(), type.getCode(), "Group loan"); + break; + case JOINT_LIABILITY_LOAN: + optionData = new EnumOptionData(type.getId().longValue(), type.getCode(), "Joint liability loan"); + break; + case LINKED_LOAN: + optionData = new EnumOptionData(type.getId().longValue(), type.getCode(), "Linked loan"); + break; + + default: + optionData = new EnumOptionData(LendingStrategy.INVALID.getId().longValue(), LendingStrategy.INVALID.getCode() , "Invalid"); + break; + + } + return optionData; + } + +}