wip:modifications to guarantor related services
This commit is contained in:
Executable
+48
@@ -0,0 +1,48 @@
|
||||
-- Guarantor table is no longer an external Table
|
||||
DELETE FROM `x_registered_table` WHERE `registered_table_name`='m_guarantor_external' LIMIT 1;
|
||||
|
||||
-- drop guarantor table
|
||||
drop table m_guarantor_external;
|
||||
|
||||
-- New m_guarantor table
|
||||
CREATE TABLE `m_guarantor` (
|
||||
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
|
||||
`loan_id` BIGINT(20) NOT NULL,
|
||||
`type_enum` SMALLINT(5) NOT NULL,
|
||||
`entity_id` BIGINT(20) NULL DEFAULT NULL,
|
||||
`firstname` VARCHAR(50) NULL DEFAULT NULL,
|
||||
`lastname` VARCHAR(50) NULL DEFAULT NULL,
|
||||
`dob` DATE NULL DEFAULT NULL,
|
||||
`address_line_1` VARCHAR(500) NULL DEFAULT NULL,
|
||||
`address_line_2` VARCHAR(500) NULL DEFAULT NULL,
|
||||
`city` VARCHAR(50) NULL DEFAULT NULL,
|
||||
`state` VARCHAR(50) NULL DEFAULT NULL,
|
||||
`country` VARCHAR(50) NULL DEFAULT NULL,
|
||||
`zip` VARCHAR(20) NULL DEFAULT NULL,
|
||||
`house_phone_number` VARCHAR(20) NULL DEFAULT NULL,
|
||||
`mobile_number` VARCHAR(20) NULL DEFAULT NULL,
|
||||
`comment` VARCHAR(500) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `FK_m_guarantor_m_loan` (`loan_id`),
|
||||
CONSTRAINT `FK_m_guarantor_m_loan` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`id`)
|
||||
)
|
||||
COLLATE='utf8_general_ci'
|
||||
ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
-- Update loan table
|
||||
|
||||
ALTER TABLE `m_loan`
|
||||
DROP FOREIGN KEY `FK_m_loan_guarantor`;
|
||||
|
||||
update m_loan
|
||||
set guarantor_id=null;
|
||||
|
||||
ALTER TABLE `m_loan`
|
||||
ADD CONSTRAINT `FK_m_loan_guarantor` FOREIGN KEY (`guarantor_id`) REFERENCES `m_guarantor` (`id`);
|
||||
|
||||
-- Insert new permissions
|
||||
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'CREATE_GUARANTOR', 'GUARANTOR', 'CREATE', 1);
|
||||
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'DELETE_GUARANTOR', 'GUARANTOR', 'DELETE', 1);
|
||||
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'READ_GUARANTOR', 'GUARANTOR', 'READ', 0);
|
||||
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'UPDATE_GUARANTOR', 'GUARANTOR', 'UPDATE', 1);
|
||||
|
||||
+2
-2
@@ -75,8 +75,8 @@ public class AccountingApiDataConversionServiceImpl implements AccountingApiData
|
||||
final String glCode = helper.extractStringNamed("glCode", element, requestParamatersDetected);
|
||||
final Boolean disabled = helper.extractBooleanNamed("disabled", element, requestParamatersDetected);
|
||||
final Boolean manualEntriesAllowed = helper.extractBooleanNamed("manualEntriesAllowed", element, requestParamatersDetected);
|
||||
final Integer category = helper.extractIntegerFromUnFormattedStringNamed("classification", element, requestParamatersDetected);
|
||||
final Integer usage = helper.extractIntegerFromUnFormattedStringNamed("usage", element, requestParamatersDetected);
|
||||
final Integer category = helper.extractIntegerSansLocaleNamed("classification", element, requestParamatersDetected);
|
||||
final Integer usage = helper.extractIntegerSansLocaleNamed("usage", element, requestParamatersDetected);
|
||||
final String description = helper.extractStringNamed("description", element, requestParamatersDetected);
|
||||
|
||||
return new GLAccountCommand(requestParamatersDetected, resourceIdentifier, name, parentId, glCode, disabled, manualEntriesAllowed,
|
||||
|
||||
@@ -173,6 +173,10 @@ public class CommandWrapper {
|
||||
public boolean isStaffResource() {
|
||||
return this.entityName.equalsIgnoreCase("STAFF");
|
||||
}
|
||||
|
||||
public boolean isGuarantorResource() {
|
||||
return this.entityName.equalsIgnoreCase("GUARANTOR");
|
||||
}
|
||||
|
||||
public boolean isFundResource() {
|
||||
return this.entityName.equalsIgnoreCase("FUND");
|
||||
|
||||
+24
@@ -150,6 +150,30 @@ public class CommandWrapperBuilder {
|
||||
this.href = "/staff/" + staffId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder createGuarantor() {
|
||||
this.actionName = "CREATE";
|
||||
this.entityName = "GUARANTOR";
|
||||
this.entityId = null;
|
||||
this.href = "/guarantors/template";
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder updateGuarantor(final Long guarantorId) {
|
||||
this.actionName = "UPDATE";
|
||||
this.entityName = "GUARANTOR";
|
||||
this.entityId = guarantorId;
|
||||
this.href = "/guarantors/" + guarantorId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder deleteGuarantor(final Long guarantorId) {
|
||||
this.actionName = "DELETE";
|
||||
this.entityName = "GUARANTOR";
|
||||
this.entityId = guarantorId;
|
||||
this.href = "/guarantors/" + guarantorId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder createFund() {
|
||||
this.actionName = "CREATE";
|
||||
|
||||
+8
@@ -180,6 +180,14 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
||||
} else {
|
||||
throw new UnsupportedCommandException(wrapper.commandName());
|
||||
}
|
||||
} else if (wrapper.isGuarantorResource()) {
|
||||
if (wrapper.isCreate()) {
|
||||
handler = applicationContext.getBean("createGuarantorCommandHandler", NewCommandSourceHandler.class);
|
||||
} else if (wrapper.isUpdate()) {
|
||||
handler = applicationContext.getBean("updateGuarantorCommandHandler", NewCommandSourceHandler.class);
|
||||
} else {
|
||||
throw new UnsupportedCommandException(wrapper.commandName());
|
||||
}
|
||||
} else if (wrapper.isCodeResource()) {
|
||||
if (wrapper.isCreate()) {
|
||||
handler = applicationContext.getBean("createCodeCommandHandler", NewCommandSourceHandler.class);
|
||||
|
||||
+21
@@ -2,6 +2,7 @@ package org.mifosplatform.infrastructure.core.api;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@@ -195,6 +196,14 @@ public final class JsonCommand {
|
||||
public Long longValueOfParameterNamed(final String parameterName) {
|
||||
return this.fromApiJsonHelper.extractLongNamed(parameterName, parsedCommand);
|
||||
}
|
||||
|
||||
public boolean isChangeInDateParameterNamed(final String parameterName, final Date existingValue) {
|
||||
LocalDate localDate = null;
|
||||
if (existingValue != null) {
|
||||
localDate = LocalDate.fromDateFields(existingValue);
|
||||
}
|
||||
return isChangeInLocalDateParameterNamed( parameterName, localDate);
|
||||
}
|
||||
|
||||
public boolean isChangeInLocalDateParameterNamed(final String parameterName, final LocalDate existingValue) {
|
||||
boolean isChanged = false;
|
||||
@@ -208,6 +217,12 @@ public final class JsonCommand {
|
||||
public LocalDate localDateValueOfParameterNamed(final String parameterName) {
|
||||
return this.fromApiJsonHelper.extractLocalDateNamed(parameterName, parsedCommand);
|
||||
}
|
||||
|
||||
public Date DateValueOfParameterNamed(final String parameterName) {
|
||||
LocalDate localDate = this.fromApiJsonHelper.extractLocalDateNamed(parameterName, parsedCommand);
|
||||
if (localDate == null) { return null; }
|
||||
return localDate.toDateMidnight().toDate();
|
||||
}
|
||||
|
||||
public boolean isChangeInStringParameterNamed(final String parameterName, final String existingValue) {
|
||||
boolean isChanged = false;
|
||||
@@ -248,6 +263,12 @@ public final class JsonCommand {
|
||||
public Integer integerValueOfParameterNamed(final String parameterName) {
|
||||
return this.fromApiJsonHelper.extractIntegerWithLocaleNamed(parameterName, parsedCommand);
|
||||
}
|
||||
|
||||
public Integer integerValueSansLocaleOfParameterNamed(final String parameterName) {
|
||||
return this.fromApiJsonHelper.extractIntegerSansLocaleNamed(parameterName, parsedCommand);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean isChangeInBooleanParameterNamed(final String parameterName, final Boolean existingValue) {
|
||||
boolean isChanged = false;
|
||||
|
||||
+4
@@ -141,6 +141,10 @@ public class FromJsonHelper {
|
||||
return helperDelegator.extractIntegerWithLocaleNamed(parameterName, element.getAsJsonObject(), new HashSet<String>());
|
||||
}
|
||||
|
||||
public Integer extractIntegerSansLocaleNamed(final String parameterName, final JsonElement element){
|
||||
return helperDelegator.extractIntegerSansLocaleNamed(parameterName, element.getAsJsonObject(), new HashSet<String>());
|
||||
}
|
||||
|
||||
public Integer extractIntegerWithLocaleNamed(final String parameterName, final JsonElement element,
|
||||
final Set<String> parametersPassedInRequest) {
|
||||
return helperDelegator.extractIntegerWithLocaleNamed(parameterName, element.getAsJsonObject(), parametersPassedInRequest);
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ public class JsonParserHelper {
|
||||
* @param parametersPassedInRequest
|
||||
* @return
|
||||
*/
|
||||
public Integer extractIntegerFromUnFormattedStringNamed(final String parameterName, final JsonElement element, final Set<String> parametersPassedInRequest) {
|
||||
public Integer extractIntegerSansLocaleNamed(final String parameterName, final JsonElement element, final Set<String> parametersPassedInRequest) {
|
||||
Integer intValue = null;
|
||||
if (element.isJsonObject()) {
|
||||
JsonObject object = element.getAsJsonObject();
|
||||
|
||||
+37
@@ -41,4 +41,41 @@ public class StaffData {
|
||||
this.officeId = officeId;
|
||||
this.allowedOffices = allowedOffices;
|
||||
}
|
||||
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
||||
public String getFirstname() {
|
||||
return this.firstname;
|
||||
}
|
||||
|
||||
|
||||
public String getLastname() {
|
||||
return this.lastname;
|
||||
}
|
||||
|
||||
|
||||
public String getDisplayName() {
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
|
||||
public Long getOfficeId() {
|
||||
return this.officeId;
|
||||
}
|
||||
|
||||
|
||||
public String getOfficeName() {
|
||||
return this.officeName;
|
||||
}
|
||||
|
||||
|
||||
public boolean isLoanOfficer() {
|
||||
return this.isLoanOfficer;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+25
@@ -122,4 +122,29 @@ final public class ClientData {
|
||||
public ClientData currentChange() {
|
||||
return this.currentChange;
|
||||
}
|
||||
|
||||
public String getExternalId() {
|
||||
return this.externalId;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return this.firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return this.lastname;
|
||||
}
|
||||
|
||||
public Long getOfficeId() {
|
||||
return this.officeId;
|
||||
}
|
||||
|
||||
public String getOfficeName() {
|
||||
return this.officeName;
|
||||
}
|
||||
|
||||
public LocalDate getJoinedDate() {
|
||||
return this.joinedDate;
|
||||
}
|
||||
|
||||
}
|
||||
+6
-8
@@ -199,7 +199,7 @@ public class LoansApiResource {
|
||||
LoanScheduleData repaymentSchedule = null;
|
||||
LoanPermissionData permissions = null;
|
||||
Collection<LoanChargeData> charges = null;
|
||||
GuarantorData guarantorData = null;
|
||||
Collection<GuarantorData> guarantors = null;
|
||||
|
||||
boolean convenienceDataRequired = false;
|
||||
final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
@@ -210,11 +210,10 @@ public class LoansApiResource {
|
||||
"charges", "guarantor"));
|
||||
}
|
||||
|
||||
boolean existsGuarantor = false;
|
||||
if (associationParameters.contains("guarantor")) {
|
||||
if (guarantorReadPlatformService.existsGuarantor(loanId)) {
|
||||
guarantorData = this.guarantorReadPlatformService.retrieveGuarantor(loanId);
|
||||
existsGuarantor = true;
|
||||
guarantors = this.guarantorReadPlatformService.retrieveGuarantorsForLoan(loanId);
|
||||
if (CollectionUtils.isEmpty(guarantors)) {
|
||||
guarantors = null; // set back to null so doesn't appear in JSON
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,8 +250,7 @@ public class LoansApiResource {
|
||||
&& (tolerance.isGreaterThan(totalOutstandingMoney) || tolerance.isEqualTo(totalOutstandingMoney));
|
||||
|
||||
loanRepaymentsCount = retrieveNonDisbursementTransactions(loanRepayments);
|
||||
permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails, isWaiveAllowed, loanRepaymentsCount,
|
||||
existsGuarantor);
|
||||
permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails, isWaiveAllowed, loanRepaymentsCount);
|
||||
|
||||
// clear parent data which wasn't requested
|
||||
if (!associationParameters.contains("repaymentSchedule")) {
|
||||
@@ -302,7 +300,7 @@ public class LoansApiResource {
|
||||
final LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, convenienceDataRequired, repaymentSchedule,
|
||||
loanRepayments, permissions, charges, productOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions,
|
||||
repaymentStrategyOptions, interestRateFrequencyTypeOptions, amortizationTypeOptions, interestTypeOptions,
|
||||
interestCalculationPeriodTypeOptions, fundOptions, chargeOptions, chargeTemplate, null, guarantorData);
|
||||
interestCalculationPeriodTypeOptions, fundOptions, chargeOptions, chargeTemplate, null, guarantors);
|
||||
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, loanAccount, LOAN_DATA_PARAMETERS);
|
||||
|
||||
+3
-3
@@ -69,7 +69,7 @@ public class LoanAccountData {
|
||||
private final Collection<LoanChargeData> charges;
|
||||
private final LoanPermissionData permissions;
|
||||
private final LoanConvenienceData convenienceData;
|
||||
private final GuarantorData guarantorData;
|
||||
private final Collection<GuarantorData> guarantors;
|
||||
|
||||
// template
|
||||
private final Collection<StaffData> loanOfficerOptions;
|
||||
@@ -94,7 +94,7 @@ public class LoanAccountData {
|
||||
final Collection<EnumOptionData> interestRateFrequencyTypeOptions, final Collection<EnumOptionData> amortizationTypeOptions,
|
||||
final Collection<EnumOptionData> interestTypeOptions, final Collection<EnumOptionData> interestCalculationPeriodTypeOptions,
|
||||
final Collection<FundData> fundOptions, final Collection<ChargeData> chargeOptions, final ChargeData chargeTemplate,
|
||||
final Collection<StaffData> loanOfficerOptions, final GuarantorData guarantorData) {
|
||||
final Collection<StaffData> loanOfficerOptions, final Collection<GuarantorData> guarantors) {
|
||||
this.repaymentSchedule = repaymentSchedule;
|
||||
this.transactions = transactions;
|
||||
this.permissions = permissions;
|
||||
@@ -111,7 +111,7 @@ public class LoanAccountData {
|
||||
this.chargeOptions = chargeOptions;
|
||||
this.chargeTemplate = chargeTemplate;
|
||||
this.loanOfficerOptions = loanOfficerOptions;
|
||||
this.guarantorData = guarantorData;
|
||||
this.guarantors = guarantors;
|
||||
|
||||
if (convenienceDataRequired) {
|
||||
int maxSubmittedOnOffsetFromToday = basicDetails.getMaxSubmittedOnOffsetFromToday();
|
||||
|
||||
-12
@@ -80,10 +80,6 @@ public class Loan extends AbstractAuditableCustom<AppUser, Long> {
|
||||
@JoinColumn(name = "client_id")
|
||||
private Client client;
|
||||
|
||||
@ManyToOne(optional = true)
|
||||
@JoinColumn(name = "guarantor_id")
|
||||
private Client guarantor;
|
||||
|
||||
@ManyToOne(optional = true)
|
||||
@JoinColumn(name = "group_id")
|
||||
private Group group;
|
||||
@@ -1953,14 +1949,6 @@ public class Loan extends AbstractAuditableCustom<AppUser, Long> {
|
||||
return latestRecordWithNoEndDate;
|
||||
}
|
||||
|
||||
public Client getGuarantor() {
|
||||
return guarantor;
|
||||
}
|
||||
|
||||
public void setGuarantor(Client guarantor) {
|
||||
this.guarantor = guarantor;
|
||||
}
|
||||
|
||||
public Client getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class GuarantorConstants {
|
||||
|
||||
/***
|
||||
* Enum of all parameters passed in while creating/updating a loan product
|
||||
***/
|
||||
public static enum GUARANTOR_JSON_INPUT_PARAMS {
|
||||
LOAN_ID("loanId"), GUARANTOR_TYPE_ID("guarantorTypeId"), ENTITY_ID("entityId"), FIRSTNAME("firstname"), LASTNAME("lastname"), ADDRESS_LINE_1(
|
||||
"addressLine1"), ADDRESS_LINE_2("addressLine2"), CITY("city"), STATE("state"), ZIP("zip"), COUNTRY("country"), MOBILE_NUMBER(
|
||||
"mobileNumber"), PHONE_NUMBER("housePhoneNumber"), COMMENT("comment"), DATE_OF_BIRTH("dob"), ;
|
||||
|
||||
private final String value;
|
||||
|
||||
private GUARANTOR_JSON_INPUT_PARAMS(final String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private static final Set<String> values = new HashSet<String>();
|
||||
static {
|
||||
for (GUARANTOR_JSON_INPUT_PARAMS type : GUARANTOR_JSON_INPUT_PARAMS.values()) {
|
||||
values.add(type.value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<String> getAllValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().toString().replaceAll("_", " ");
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
+68
-43
@@ -2,6 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.gaurantor.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
@@ -14,93 +15,117 @@ import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
||||
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.command.GuarantorCommand;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.domain.GuarantorType;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.service.GuarantorEnumerations;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.service.GuarantorReadPlatformService;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.service.GuarantorWritePlatformService;
|
||||
import org.mifosplatform.portfolio.savingsaccount.PortfolioApiDataConversionService;
|
||||
import org.mifosplatform.portfolio.savingsaccount.PortfolioApiJsonSerializerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Path("/loans/{loanId}/guarantor")
|
||||
@Path("/guarantors")
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class GuarantorsApiResource {
|
||||
|
||||
@Autowired
|
||||
private GuarantorWritePlatformService guarantorWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
private GuarantorReadPlatformService guarantorReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
private PortfolioApiDataConversionService apiDataConversionService;
|
||||
|
||||
@Autowired
|
||||
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
|
||||
private static final Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("externalGuarantor", "existingClientId",
|
||||
private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("externalGuarantor", "existingClientId",
|
||||
"firstname", "lastname", "addressLine1", "addressLine2", "city", "state", "zip", "country", "mobileNumber", "housePhoneNumber",
|
||||
"comment", "dob"));
|
||||
|
||||
private final String SystemEntityType = "m_guarantor_external";
|
||||
private final String resourceNameForPermission = "GUARANTOR";
|
||||
|
||||
private final GuarantorReadPlatformService guarantorReadPlatformService;
|
||||
private final DefaultToApiJsonSerializer<GuarantorData> apiJsonSerializerService;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
private final PlatformSecurityContext context;
|
||||
|
||||
@Autowired
|
||||
private PlatformSecurityContext context;
|
||||
public GuarantorsApiResource(final PlatformSecurityContext context, final GuarantorReadPlatformService guarantorReadPlatformService,
|
||||
final DefaultToApiJsonSerializer<GuarantorData> toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
||||
this.context = context;
|
||||
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||
this.apiJsonSerializerService = toApiJsonSerializer;
|
||||
this.guarantorReadPlatformService = guarantorReadPlatformService;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("template")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveGuarantorDetails(@Context final UriInfo uriInfo, @PathParam("loanId") final Long loanId) {
|
||||
context.authenticatedUser().validateHasReadPermission(SystemEntityType);
|
||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (responseParameters.isEmpty()) {
|
||||
responseParameters.addAll(typicalResponseParameters);
|
||||
public String newGuarantorTemplate(@Context final UriInfo uriInfo) {
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermission);
|
||||
|
||||
GuarantorData guarantorData = guarantorReadPlatformService.retrieveNewGuarantorDetails();
|
||||
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.apiJsonSerializerService.serialize(settings, guarantorData, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{guarantorId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveGuarantorDetails(@Context final UriInfo uriInfo, @PathParam("guarantorId") final Long guarantorId) {
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermission);
|
||||
|
||||
GuarantorData guarantorData = guarantorReadPlatformService.retrieveGuarantor(guarantorId);
|
||||
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
if (settings.isTemplate()) {
|
||||
final List<EnumOptionData> guarantorTypeOptions = GuarantorEnumerations.guarantorType(GuarantorType.values());
|
||||
guarantorData = GuarantorData.templateOnTop(guarantorData, guarantorTypeOptions);
|
||||
}
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
GuarantorData guarantorData = guarantorReadPlatformService.retrieveGuarantor(loanId);
|
||||
|
||||
return this.apiJsonSerializerService.serializeGuarantorDataToJson(prettyPrint, responseParameters, guarantorData);
|
||||
return this.apiJsonSerializerService.serialize(settings, guarantorData, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public Response createGuarantor(@PathParam("loanId") final Long loanId, final String jsonRequestBody) {
|
||||
public String createGuarantor(final String apiRequestBodyAsJson) {
|
||||
|
||||
final GuarantorCommand command = this.apiDataConversionService.convertJsonToGuarantorCommand(null, loanId, jsonRequestBody);
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().createGuarantor().withJson(apiRequestBodyAsJson).build();
|
||||
|
||||
this.guarantorWritePlatformService.createGuarantor(loanId, command);
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
|
||||
// returns the loan Identifier for which the guarantor was associated
|
||||
return Response.ok().entity(new CommandProcessingResult(loanId)).build();
|
||||
return this.apiJsonSerializerService.serialize(result);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{guarantorId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public Response updateGuarantor(@PathParam("loanId") final Long loanId, final String jsonRequestBody) {
|
||||
final GuarantorCommand command = this.apiDataConversionService.convertJsonToGuarantorCommand(null, loanId, jsonRequestBody);
|
||||
public String updateGuarantor(@PathParam("guarantorId") final Long guarantorId, final String jsonRequestBody) {
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateGuarantor(guarantorId).withJson(jsonRequestBody).build();
|
||||
|
||||
this.guarantorWritePlatformService.updateGuarantor(loanId, command);
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
|
||||
return Response.ok().entity(new CommandProcessingResult(loanId)).build();
|
||||
return this.apiJsonSerializerService.serialize(result);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{guarantorId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public Response deleteGuarantor(@PathParam("loanId") final Long loanId) {
|
||||
this.guarantorWritePlatformService.removeGuarantor(loanId);
|
||||
return Response.ok(new CommandProcessingResult(loanId)).build();
|
||||
public String deleteGuarantor(@PathParam("guarantorId") final Long guarantorId) {
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteGuarantor(guarantorId).build();
|
||||
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
|
||||
return this.apiJsonSerializerService.serialize(result);
|
||||
}
|
||||
}
|
||||
+112
-87
@@ -1,19 +1,27 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.command;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.GuarantorConstants.GUARANTOR_JSON_INPUT_PARAMS;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.domain.GuarantorType;
|
||||
|
||||
/**
|
||||
* Immutable command for creating or updating details of a Guarantor.
|
||||
*/
|
||||
public class GuarantorCommand {
|
||||
|
||||
private final boolean externalGuarantor;
|
||||
|
||||
/*** Fields for current customers serving as guarantors **/
|
||||
private final Long existingClientId;
|
||||
private final Long loanId;
|
||||
private final Integer guarantorTypeId;
|
||||
private final Long entityId;
|
||||
|
||||
/*** Fields for external persons serving as guarantors ***/
|
||||
// FIXME - kw - what if the details for collecting guarantors change? we are using datatable approach but embedding a structure here?
|
||||
private final String firstname;
|
||||
private final String lastname;
|
||||
private final String addressLine1;
|
||||
@@ -25,24 +33,16 @@ public class GuarantorCommand {
|
||||
private final String mobileNumber;
|
||||
private final String housePhoneNumber;
|
||||
private final String comment;
|
||||
private final String dob;
|
||||
private final LocalDate dob;
|
||||
|
||||
/** Feilds for passing Locale info to generic data service api **/
|
||||
private String dateFormat;
|
||||
private String locale;
|
||||
|
||||
private final Set<String> modifiedParameters;
|
||||
|
||||
public GuarantorCommand(final Set<String> modifiedParameters, final Long existingClientId, final String firstname,
|
||||
final String lastname, final Boolean externalGuarantor, final String addressLine1, final String addressLine2,
|
||||
final String city, final String state, final String zip, final String country, final String mobileNumber,
|
||||
final String housePhoneNumber, final String comment, final String dob) {
|
||||
this.modifiedParameters = modifiedParameters;
|
||||
|
||||
this.externalGuarantor = externalGuarantor;
|
||||
|
||||
/*** Fields for current customers serving as guarantors **/
|
||||
this.existingClientId = existingClientId;
|
||||
public GuarantorCommand(final Long loanId, final Integer guarantorTypeId, final Long entityId, final String firstname,
|
||||
final String lastname, final String addressLine1, final String addressLine2, final String city, final String state,
|
||||
final String zip, final String country, final String mobileNumber, final String housePhoneNumber, final String comment,
|
||||
final LocalDate dob) {
|
||||
this.loanId = loanId;
|
||||
/*** Fields for current entities serving as guarantors **/
|
||||
this.guarantorTypeId = guarantorTypeId;
|
||||
this.entityId = entityId;
|
||||
|
||||
/*** Fields for external persons serving as guarantors ***/
|
||||
this.firstname = firstname;
|
||||
@@ -59,80 +59,105 @@ public class GuarantorCommand {
|
||||
this.dob = dob;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
public boolean isExternalGuarantor() {
|
||||
return GuarantorType.EXTERNAL.getValue().equals(guarantorTypeId);
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
public Date getDobAsDate() {
|
||||
return this.dob.toDateMidnight().toDate();
|
||||
}
|
||||
|
||||
public Boolean isExternalGuarantor() {
|
||||
return externalGuarantor;
|
||||
public void validateForCreate() {
|
||||
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
DataValidatorBuilder baseDataValidator = getDataValidator(dataValidationErrors);
|
||||
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.LOAN_ID.getValue()).value(this.loanId).notNull()
|
||||
.integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.GUARANTOR_TYPE_ID.getValue()).value(this.guarantorTypeId).notNull()
|
||||
.inMinMaxRange(GuarantorType.getMinValue(), GuarantorType.getMaxValue());
|
||||
|
||||
// validate for existing Client or Staff serving as gurantor
|
||||
if (!this.isExternalGuarantor()) {
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.ENTITY_ID.getValue()).value(this.entityId).notNull()
|
||||
.integerGreaterThanZero();
|
||||
} else {
|
||||
// validate for an external guarantor
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.FIRSTNAME.getValue()).value(this.firstname).notBlank()
|
||||
.notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.LASTNAME.getValue()).value(this.lastname).notBlank()
|
||||
.notExceedingLengthOf(50);
|
||||
validateNonMandatoryFieldsForMaxLength(baseDataValidator);
|
||||
}
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
|
||||
public Long getExistingClientId() {
|
||||
return existingClientId;
|
||||
public void validateForUpdate() {
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
DataValidatorBuilder baseDataValidator = getDataValidator(dataValidationErrors);
|
||||
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.GUARANTOR_TYPE_ID.getValue()).value(this.guarantorTypeId)
|
||||
.ignoreIfNull().inMinMaxRange(GuarantorType.getMinValue(), GuarantorType.getMaxValue());
|
||||
|
||||
// validate for existing Client or Staff serving as gurantor
|
||||
if (!this.isExternalGuarantor()) {
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.ENTITY_ID.getValue()).value(this.entityId).ignoreIfNull()
|
||||
.integerGreaterThanZero();
|
||||
} else {
|
||||
// TODO: Vishwas this validation is buggy (it is compulsory to
|
||||
// update
|
||||
// firstname and last name when a guarantor type is changed), to be
|
||||
// corrected while
|
||||
// refactoring for maker checker
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.FIRSTNAME.getValue()).value(this.firstname).ignoreIfNull()
|
||||
.notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.LASTNAME.getValue()).value(this.lastname).ignoreIfNull()
|
||||
.notExceedingLengthOf(50);
|
||||
|
||||
validateNonMandatoryFieldsForMaxLength(baseDataValidator);
|
||||
}
|
||||
baseDataValidator.reset().anyOfNotNull(this.entityId, this.addressLine1, this.addressLine2, this.city, this.comment, this.country,
|
||||
this.firstname, this.housePhoneNumber, this.lastname, this.mobileNumber, this.state, this.zip);
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
|
||||
public String getAddressLine1() {
|
||||
return addressLine1;
|
||||
/**
|
||||
* @param baseDataValidator
|
||||
*/
|
||||
private void validateNonMandatoryFieldsForMaxLength(DataValidatorBuilder baseDataValidator) {
|
||||
// validate non mandatory fields for length
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.ADDRESS_LINE_1.getValue()).value(this.addressLine1).ignoreIfNull()
|
||||
.notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.ADDRESS_LINE_2.getValue()).value(this.addressLine2).ignoreIfNull()
|
||||
.notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.CITY.getValue()).value(this.city).ignoreIfNull()
|
||||
.notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.STATE.getValue()).value(this.state).ignoreIfNull()
|
||||
.notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.ZIP.getValue()).value(this.zip).ignoreIfNull()
|
||||
.notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.COUNTRY.getValue()).value(this.country).ignoreIfNull()
|
||||
.notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.MOBILE_NUMBER.getValue()).value(this.mobileNumber).ignoreIfNull()
|
||||
.notExceedingLengthOf(20);
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.PHONE_NUMBER.getValue()).value(this.housePhoneNumber)
|
||||
.ignoreIfNull().notExceedingLengthOf(20);
|
||||
baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.COMMENT.getValue()).value(this.comment).ignoreIfNull()
|
||||
.notExceedingLengthOf(500);
|
||||
}
|
||||
|
||||
public String getAddressLine2() {
|
||||
return addressLine2;
|
||||
/**
|
||||
* @param dataValidationErrors
|
||||
* @return
|
||||
*/
|
||||
private DataValidatorBuilder getDataValidator(List<ApiParameterError> dataValidationErrors) {
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("Guarantor");
|
||||
return baseDataValidator;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public String getZip() {
|
||||
return zip;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public String getMobileNumber() {
|
||||
return mobileNumber;
|
||||
}
|
||||
|
||||
public String getHousePhoneNumber() {
|
||||
return housePhoneNumber;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public Set<String> getModifiedParameters() {
|
||||
return modifiedParameters;
|
||||
}
|
||||
|
||||
public String getDob() {
|
||||
return dob;
|
||||
}
|
||||
|
||||
public String getDateFormat() {
|
||||
return dateFormat;
|
||||
}
|
||||
|
||||
public void setDateFormat(String dateFormat) {
|
||||
this.dateFormat = dateFormat;
|
||||
}
|
||||
|
||||
public String getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public void setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
}
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
|
||||
public class GuarantorCommandValidator {
|
||||
|
||||
private final GuarantorCommand command;
|
||||
|
||||
public GuarantorCommandValidator(GuarantorCommand command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public void validateForCreate() {
|
||||
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("Guarantor");
|
||||
|
||||
// validate for existing Client
|
||||
if (command.isExternalGuarantor() == null || command.isExternalGuarantor() == false) {
|
||||
baseDataValidator.reset().parameter("existingClientId").value(command.getExistingClientId()).notNull().integerGreaterThanZero();
|
||||
} else {
|
||||
// validate for an external guarantor
|
||||
baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).notBlank().notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter("lastname").value(command.getLastname()).notBlank().notExceedingLengthOf(50);
|
||||
|
||||
validateNonMandatoryFieldsForMaxLength(baseDataValidator);
|
||||
}
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
|
||||
public void validateForUpdate() {
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("Guarantor");
|
||||
|
||||
// validate for existing Client
|
||||
if (command.isExternalGuarantor() == null || command.isExternalGuarantor() == false) {
|
||||
baseDataValidator.reset().parameter("existingClientId").value(command.getExistingClientId()).notNull().integerGreaterThanZero();
|
||||
} else {
|
||||
// validate for an external guarantor
|
||||
baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).notBlank().notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter("lastname").value(command.getLastname()).notBlank().notExceedingLengthOf(50);
|
||||
|
||||
validateNonMandatoryFieldsForMaxLength(baseDataValidator);
|
||||
}
|
||||
baseDataValidator.reset().anyOfNotNull(command.getExistingClientId(), command.getAddressLine1(), command.getAddressLine2(),
|
||||
command.getCity(), command.getComment(), command.getCountry(), command.getFirstname(), command.getHousePhoneNumber(),
|
||||
command.getLastname(), command.getMobileNumber(), command.getState(), command.getZip());
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
|
||||
/**
|
||||
* @param baseDataValidator
|
||||
*/
|
||||
private void validateNonMandatoryFieldsForMaxLength(DataValidatorBuilder baseDataValidator) {
|
||||
// validate non mandatory fields for length
|
||||
baseDataValidator.reset().parameter("addressLine1").value(command.getAddressLine1()).ignoreIfNull().notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter("addressLine2").value(command.getAddressLine2()).ignoreIfNull().notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter("city").value(command.getCity()).ignoreIfNull().notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter("state").value(command.getState()).ignoreIfNull().notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter("zip").value(command.getZip()).ignoreIfNull().notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter("country").value(command.getCountry()).ignoreIfNull().notExceedingLengthOf(50);
|
||||
baseDataValidator.reset().parameter("mobileNumber").value(command.getMobileNumber()).ignoreIfNull().notExceedingLengthOf(20);
|
||||
baseDataValidator.reset().parameter("housePhoneNumber").value(command.getHousePhoneNumber()).ignoreIfNull()
|
||||
.notExceedingLengthOf(20);
|
||||
baseDataValidator.reset().parameter("comment").value(command.getComment()).ignoreIfNull().notExceedingLengthOf(500);
|
||||
}
|
||||
}
|
||||
+89
-174
@@ -1,196 +1,111 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||
import org.mifosplatform.organisation.staff.data.StaffData;
|
||||
import org.mifosplatform.portfolio.client.data.ClientData;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.domain.GuarantorType;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.service.GuarantorEnumerations;
|
||||
|
||||
public class GuarantorData {
|
||||
private String firstname;
|
||||
private String lastname;
|
||||
private boolean externalGuarantor;
|
||||
|
||||
/*** Fields for current customers serving as guarantors **/
|
||||
private Long existingClientId;
|
||||
private String externalId;
|
||||
private String officeName;
|
||||
private LocalDate joinedDate;
|
||||
private final Long id;
|
||||
private final Long loanId;
|
||||
private final EnumOptionData guarantorType;
|
||||
|
||||
/*** Fields for external persons serving as guarantors ***/
|
||||
private String addressLine1;
|
||||
private String addressLine2;
|
||||
private String city;
|
||||
private String state;
|
||||
private String zip;
|
||||
private String country;
|
||||
private String mobileNumber;
|
||||
private String housePhoneNumber;
|
||||
private String comment;
|
||||
private LocalDate dob;
|
||||
private final String firstname;
|
||||
private final String lastname;
|
||||
|
||||
public GuarantorData(final Long existingClientId, final String firstname,
|
||||
final String lastname, final String externalId,
|
||||
final String officeName, final LocalDate joinedDate) {
|
||||
this.existingClientId = existingClientId;
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.externalId = externalId;
|
||||
this.officeName = officeName;
|
||||
this.joinedDate = joinedDate;
|
||||
this.externalGuarantor = false;
|
||||
}
|
||||
/*** Fields for current customers/staff serving as guarantors **/
|
||||
private final Long entityId;
|
||||
private final String externalId;
|
||||
private final String officeName;
|
||||
private final LocalDate joinedDate;
|
||||
|
||||
public GuarantorData(final String firstname, final String lastname,
|
||||
final LocalDate dob, final String addressLine1,
|
||||
final String addressLine2, final String city, final String state,
|
||||
final String zip, final String country, final String mobileNumber,
|
||||
final String housePhoneNumber, final String comment) {
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.dob = dob;
|
||||
this.addressLine1 = addressLine1;
|
||||
this.addressLine2 = addressLine2;
|
||||
this.city = city;
|
||||
this.state = state;
|
||||
this.zip = zip;
|
||||
this.country = country;
|
||||
this.mobileNumber = mobileNumber;
|
||||
this.housePhoneNumber = housePhoneNumber;
|
||||
this.comment = comment;
|
||||
this.externalGuarantor = true;
|
||||
}
|
||||
/*** Fields for external persons serving as guarantors ***/
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
private final String addressLine1;
|
||||
private final String addressLine2;
|
||||
private final String city;
|
||||
private final String state;
|
||||
private final String zip;
|
||||
private final String country;
|
||||
private final String mobileNumber;
|
||||
private final String housePhoneNumber;
|
||||
private final String comment;
|
||||
private final LocalDate dob;
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
// template
|
||||
@SuppressWarnings("unused")
|
||||
private final List<EnumOptionData> guarantorTypeOptions;
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
public static GuarantorData template(final List<EnumOptionData> guarantorTypeOptions) {
|
||||
return new GuarantorData(null, null, null, GuarantorEnumerations.guarantorType(GuarantorType.CUSTOMER), null, null, null, null,
|
||||
null, null, null, null, null, null, null, null, null, null, null, guarantorTypeOptions);
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
public static GuarantorData templateOnTop(final GuarantorData guarantorData, final List<EnumOptionData> guarantorTypeOptions) {
|
||||
return new GuarantorData(guarantorData.id, guarantorData.loanId, guarantorData.entityId, guarantorData.guarantorType,
|
||||
guarantorData.firstname, guarantorData.lastname, guarantorData.dob, guarantorData.addressLine1, guarantorData.addressLine2,
|
||||
guarantorData.city, guarantorData.state, guarantorData.zip, guarantorData.country, guarantorData.mobileNumber,
|
||||
guarantorData.housePhoneNumber, guarantorData.comment, guarantorData.officeName, guarantorData.joinedDate,
|
||||
guarantorData.externalId, guarantorTypeOptions);
|
||||
}
|
||||
|
||||
public Long getExistingClientId() {
|
||||
return existingClientId;
|
||||
}
|
||||
public static GuarantorData mergeClientData(ClientData clientData, GuarantorData guarantorData) {
|
||||
return new GuarantorData(guarantorData.id, guarantorData.loanId, guarantorData.entityId, guarantorData.guarantorType,
|
||||
clientData.getFirstname(), clientData.getLastname(), null, null, null, null, null, null, null, null, null, null,
|
||||
clientData.getOfficeName(), clientData.getJoinedDate(), clientData.getExternalId(), null);
|
||||
}
|
||||
|
||||
public void setExistingClientId(Long existingClientId) {
|
||||
this.existingClientId = existingClientId;
|
||||
}
|
||||
public static GuarantorData mergeStaffData(StaffData staffData, GuarantorData guarantorData) {
|
||||
return new GuarantorData(guarantorData.id, guarantorData.loanId, guarantorData.entityId, guarantorData.guarantorType,
|
||||
staffData.getFirstname(), staffData.getLastname(), null, null, null, null, null, null, null, null, null, null,
|
||||
staffData.getOfficeName(), null, null, null);
|
||||
}
|
||||
|
||||
public String getExternalId() {
|
||||
return externalId;
|
||||
}
|
||||
public GuarantorData(Long id, Long loanId, Long entityId, EnumOptionData guarantorType, String firstname, String lastname,
|
||||
LocalDate dob, String addressLine1, String addressLine2, String city, String state, String zip, String country,
|
||||
String mobileNumber, String housePhoneNumber, String comment, String officeName, LocalDate joinedDate, String externalId,
|
||||
List<EnumOptionData> guarantorTypeOptions) {
|
||||
this.id = id;
|
||||
this.loanId = loanId;
|
||||
this.guarantorType = guarantorType;
|
||||
this.entityId = entityId;
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.dob = dob;
|
||||
this.addressLine1 = addressLine1;
|
||||
this.addressLine2 = addressLine2;
|
||||
this.city = city;
|
||||
this.state = state;
|
||||
this.zip = zip;
|
||||
this.country = country;
|
||||
this.mobileNumber = mobileNumber;
|
||||
this.housePhoneNumber = housePhoneNumber;
|
||||
this.comment = comment;
|
||||
this.officeName = officeName;
|
||||
this.joinedDate = joinedDate;
|
||||
this.externalId = externalId;
|
||||
this.guarantorTypeOptions = guarantorTypeOptions;
|
||||
}
|
||||
|
||||
public void setExternalId(String externalId) {
|
||||
this.externalId = externalId;
|
||||
}
|
||||
public boolean isExternalGuarantor() {
|
||||
return GuarantorType.EXTERNAL.getValue().equals(guarantorType.getId());
|
||||
}
|
||||
|
||||
public String getOfficeName() {
|
||||
return officeName;
|
||||
}
|
||||
public boolean isExistingClient() {
|
||||
return GuarantorType.CUSTOMER.getValue().equals(guarantorType.getId());
|
||||
}
|
||||
|
||||
public void setOfficeName(String officeName) {
|
||||
this.officeName = officeName;
|
||||
}
|
||||
public boolean isStaffMember() {
|
||||
return GuarantorType.STAFF.getValue().equals(guarantorType.getId());
|
||||
}
|
||||
|
||||
public LocalDate getJoinedDate() {
|
||||
return joinedDate;
|
||||
}
|
||||
|
||||
public void setJoinedDate(LocalDate joinedDate) {
|
||||
this.joinedDate = joinedDate;
|
||||
}
|
||||
|
||||
public String getAddressLine1() {
|
||||
return addressLine1;
|
||||
}
|
||||
|
||||
public void setAddressLine1(String addressLine1) {
|
||||
this.addressLine1 = addressLine1;
|
||||
}
|
||||
|
||||
public String getAddressLine2() {
|
||||
return addressLine2;
|
||||
}
|
||||
|
||||
public void setAddressLine2(String addressLine2) {
|
||||
this.addressLine2 = addressLine2;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getZip() {
|
||||
return zip;
|
||||
}
|
||||
|
||||
public void setZip(String zip) {
|
||||
this.zip = zip;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getMobileNumber() {
|
||||
return mobileNumber;
|
||||
}
|
||||
|
||||
public void setMobileNumber(String mobileNumber) {
|
||||
this.mobileNumber = mobileNumber;
|
||||
}
|
||||
|
||||
public String getHousePhoneNumber() {
|
||||
return housePhoneNumber;
|
||||
}
|
||||
|
||||
public void setHousePhoneNumber(String housePhoneNumber) {
|
||||
this.housePhoneNumber = housePhoneNumber;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public boolean getExternalGuarantor() {
|
||||
return externalGuarantor;
|
||||
}
|
||||
|
||||
public void setExternalGuarantor(boolean externalGuarantor) {
|
||||
this.externalGuarantor = externalGuarantor;
|
||||
}
|
||||
|
||||
public LocalDate getDob() {
|
||||
return dob;
|
||||
}
|
||||
|
||||
public void setDob(LocalDate dob) {
|
||||
this.dob = dob;
|
||||
}
|
||||
public Long getEntityId() {
|
||||
return this.entityId;
|
||||
}
|
||||
|
||||
}
|
||||
+263
@@ -0,0 +1,263 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.portfolio.loanaccount.domain.Loan;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.GuarantorConstants.GUARANTOR_JSON_INPUT_PARAMS;
|
||||
import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||
|
||||
@Entity
|
||||
@Table(name = "m_guarantor")
|
||||
public class Guarantor extends AbstractPersistable<Long> {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "loan_id", nullable = false)
|
||||
private Loan loan;
|
||||
|
||||
@Column(name = "type_enum", nullable = false)
|
||||
private Integer gurantorType;
|
||||
|
||||
@Column(name = "entity_id")
|
||||
private Long entityId;
|
||||
|
||||
@Column(name = "firstname", length = 50)
|
||||
private String firstname;
|
||||
|
||||
@Column(name = "lastname", length = 50)
|
||||
private String lastname;
|
||||
|
||||
@Column(name = "dob")
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date dateOfBirth;
|
||||
|
||||
@Column(name = "address_line_1", length = 500)
|
||||
private String addressLine1;
|
||||
|
||||
@Column(name = "address_line_2", length = 500)
|
||||
private String addressLine2;
|
||||
|
||||
@Column(name = "city", length = 50)
|
||||
private String city;
|
||||
|
||||
@Column(name = "state", length = 50)
|
||||
private String state;
|
||||
|
||||
@Column(name = "country", length = 50)
|
||||
private String country;
|
||||
|
||||
@Column(name = "zip", length = 20)
|
||||
private String zip;
|
||||
|
||||
@Column(name = "house_phone_number", length = 20)
|
||||
private String housePhoneNumber;
|
||||
|
||||
@Column(name = "mobile_number", length = 20)
|
||||
private String mobilePhoneNumber;
|
||||
|
||||
@Column(name = "comment", length = 500)
|
||||
private String comment;
|
||||
|
||||
protected Guarantor() {
|
||||
|
||||
}
|
||||
|
||||
public static Guarantor createNew(Loan loan, Integer gurantorType, Long entityId, String firstname, String lastname, Date dateOfBirth,
|
||||
String addressLine1, String addressLine2, String city, String state, String country, String zip, String housePhoneNumber,
|
||||
String mobilePhoneNumber, String comment) {
|
||||
return new Guarantor(loan, gurantorType, entityId, firstname, lastname, dateOfBirth, addressLine1, addressLine2, city, state,
|
||||
country, zip, housePhoneNumber, mobilePhoneNumber, comment);
|
||||
}
|
||||
|
||||
public Guarantor(Loan loan, Integer gurantorType, Long entityId, String firstname, String lastname, Date dateOfBirth,
|
||||
String addressLine1, String addressLine2, String city, String state, String country, String zip, String housePhoneNumber,
|
||||
String mobilePhoneNumber, String comment) {
|
||||
this.loan = loan;
|
||||
this.gurantorType = gurantorType;
|
||||
this.entityId = entityId;
|
||||
this.firstname = StringUtils.defaultIfEmpty(firstname, null);
|
||||
this.lastname = StringUtils.defaultIfEmpty(lastname, null);
|
||||
this.dateOfBirth = dateOfBirth;
|
||||
this.addressLine1 = StringUtils.defaultIfEmpty(addressLine1, null);
|
||||
this.addressLine2 = StringUtils.defaultIfEmpty(addressLine2, null);
|
||||
this.city = StringUtils.defaultIfEmpty(city, null);
|
||||
this.state = StringUtils.defaultIfEmpty(state, null);
|
||||
this.country = StringUtils.defaultIfEmpty(country, null);
|
||||
this.zip = StringUtils.defaultIfEmpty(zip, null);
|
||||
this.housePhoneNumber = StringUtils.defaultIfEmpty(housePhoneNumber, null);
|
||||
this.mobilePhoneNumber = StringUtils.defaultIfEmpty(mobilePhoneNumber, null);
|
||||
this.comment = StringUtils.defaultIfEmpty(comment, null);
|
||||
}
|
||||
|
||||
public static Guarantor fromJson(final Loan loan, final JsonCommand command) {
|
||||
Integer gurantorType = command.integerValueSansLocaleOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.GUARANTOR_TYPE_ID.getValue());
|
||||
Long entityId = command.longValueOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.ENTITY_ID.getValue());
|
||||
|
||||
if (GuarantorType.EXTERNAL.getValue().equals(gurantorType)) {
|
||||
String firstname = command.stringValueOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.FIRSTNAME.getValue());
|
||||
String lastname = command.stringValueOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.LASTNAME.getValue());
|
||||
Date dateOfBirth = command.DateValueOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.DATE_OF_BIRTH.getValue());
|
||||
String addressLine1 = command.stringValueOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.ADDRESS_LINE_1.getValue());
|
||||
String addressLine2 = command.stringValueOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.ADDRESS_LINE_2.getValue());
|
||||
String city = command.stringValueOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.CITY.getValue());
|
||||
String state = command.stringValueOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.STATE.getValue());
|
||||
String country = command.stringValueOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.COUNTRY.getValue());
|
||||
String zip = command.stringValueOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.ZIP.getValue());
|
||||
String housePhoneNumber = command.stringValueOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.PHONE_NUMBER.getValue());
|
||||
String mobilePhoneNumber = command.stringValueOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.MOBILE_NUMBER.getValue());
|
||||
String comment = command.stringValueOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.COMMENT.getValue());
|
||||
|
||||
return new Guarantor(loan, gurantorType, entityId, firstname, lastname, dateOfBirth, addressLine1, addressLine2, city, state,
|
||||
country, zip, housePhoneNumber, mobilePhoneNumber, comment);
|
||||
}
|
||||
|
||||
return new Guarantor(loan, gurantorType, entityId, null, null, null, null, null, null, null, null, null, null, null, null);
|
||||
|
||||
}
|
||||
|
||||
public Map<String, Object> update(final JsonCommand command) {
|
||||
|
||||
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(7);
|
||||
|
||||
handlePropertyUpdate(command, actualChanges, GUARANTOR_JSON_INPUT_PARAMS.GUARANTOR_TYPE_ID.getValue(), this.gurantorType, true);
|
||||
handlePropertyUpdate(command, actualChanges, GUARANTOR_JSON_INPUT_PARAMS.ENTITY_ID.getValue(), this.entityId);
|
||||
|
||||
if (this.isExternalGuarantor()) {
|
||||
handlePropertyUpdate(command, actualChanges, GUARANTOR_JSON_INPUT_PARAMS.FIRSTNAME.getValue(), this.firstname);
|
||||
handlePropertyUpdate(command, actualChanges, GUARANTOR_JSON_INPUT_PARAMS.LASTNAME.getValue(), this.lastname);
|
||||
handlePropertyUpdate(command, actualChanges, GUARANTOR_JSON_INPUT_PARAMS.DATE_OF_BIRTH.getValue(), this.dateOfBirth);
|
||||
handlePropertyUpdate(command, actualChanges, GUARANTOR_JSON_INPUT_PARAMS.ADDRESS_LINE_1.getValue(), this.addressLine1);
|
||||
handlePropertyUpdate(command, actualChanges, GUARANTOR_JSON_INPUT_PARAMS.ADDRESS_LINE_2.getValue(), this.addressLine2);
|
||||
handlePropertyUpdate(command, actualChanges, GUARANTOR_JSON_INPUT_PARAMS.CITY.getValue(), this.city);
|
||||
handlePropertyUpdate(command, actualChanges, GUARANTOR_JSON_INPUT_PARAMS.STATE.getValue(), this.state);
|
||||
handlePropertyUpdate(command, actualChanges, GUARANTOR_JSON_INPUT_PARAMS.COUNTRY.getValue(), this.country);
|
||||
handlePropertyUpdate(command, actualChanges, GUARANTOR_JSON_INPUT_PARAMS.ZIP.getValue(), this.zip);
|
||||
handlePropertyUpdate(command, actualChanges, GUARANTOR_JSON_INPUT_PARAMS.PHONE_NUMBER.getValue(), this.housePhoneNumber);
|
||||
handlePropertyUpdate(command, actualChanges, GUARANTOR_JSON_INPUT_PARAMS.MOBILE_NUMBER.getValue(), this.mobilePhoneNumber);
|
||||
handlePropertyUpdate(command, actualChanges, GUARANTOR_JSON_INPUT_PARAMS.COMMENT.getValue(), this.comment);
|
||||
}
|
||||
|
||||
return actualChanges;
|
||||
}
|
||||
|
||||
public boolean isExistingCustomer() {
|
||||
return GuarantorType.CUSTOMER.getValue().equals(this.gurantorType);
|
||||
}
|
||||
|
||||
public boolean isExistingEmployee() {
|
||||
return GuarantorType.STAFF.getValue().equals(this.gurantorType);
|
||||
}
|
||||
|
||||
public boolean isExternalGuarantor() {
|
||||
return GuarantorType.EXTERNAL.getValue().equals(this.gurantorType);
|
||||
}
|
||||
|
||||
private void handlePropertyUpdate(final JsonCommand command, final Map<String, Object> actualChanges, final String paramName,
|
||||
Integer propertyToBeUpdated, boolean sansLocale) {
|
||||
if (command.isChangeInIntegerParameterNamed(paramName, propertyToBeUpdated)) {
|
||||
Integer newValue = null;
|
||||
if (sansLocale) {
|
||||
newValue = command.integerValueSansLocaleOfParameterNamed(paramName);
|
||||
} else {
|
||||
newValue = command.integerValueOfParameterNamed(paramName);
|
||||
}
|
||||
actualChanges.put(paramName, newValue);
|
||||
propertyToBeUpdated = newValue;
|
||||
|
||||
// now update actual property
|
||||
if (paramName.equals(GUARANTOR_JSON_INPUT_PARAMS.GUARANTOR_TYPE_ID.getValue())) {
|
||||
this.gurantorType = newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePropertyUpdate(final JsonCommand command, final Map<String, Object> actualChanges, final String paramName,
|
||||
String propertyToBeUpdated) {
|
||||
if (command.isChangeInStringParameterNamed(paramName, propertyToBeUpdated)) {
|
||||
final String newValue = command.stringValueOfParameterNamed(paramName);
|
||||
actualChanges.put(paramName, newValue);
|
||||
propertyToBeUpdated = newValue;
|
||||
|
||||
// now update actual property
|
||||
if (paramName.equals(GUARANTOR_JSON_INPUT_PARAMS.FIRSTNAME.getValue())) {
|
||||
this.firstname = newValue;
|
||||
} else if (paramName.equals(GUARANTOR_JSON_INPUT_PARAMS.LASTNAME.getValue())) {
|
||||
this.lastname = newValue;
|
||||
} else if (paramName.equals(GUARANTOR_JSON_INPUT_PARAMS.ADDRESS_LINE_1.getValue())) {
|
||||
this.addressLine1 = newValue;
|
||||
} else if (paramName.equals(GUARANTOR_JSON_INPUT_PARAMS.ADDRESS_LINE_2.getValue())) {
|
||||
this.addressLine2 = newValue;
|
||||
} else if (paramName.equals(GUARANTOR_JSON_INPUT_PARAMS.CITY.getValue())) {
|
||||
this.city = newValue;
|
||||
} else if (paramName.equals(GUARANTOR_JSON_INPUT_PARAMS.STATE.getValue())) {
|
||||
this.state = newValue;
|
||||
} else if (paramName.equals(GUARANTOR_JSON_INPUT_PARAMS.COUNTRY.getValue())) {
|
||||
this.country = newValue;
|
||||
} else if (paramName.equals(GUARANTOR_JSON_INPUT_PARAMS.ZIP.getValue())) {
|
||||
this.zip = newValue;
|
||||
} else if (paramName.equals(GUARANTOR_JSON_INPUT_PARAMS.PHONE_NUMBER.getValue())) {
|
||||
this.housePhoneNumber = newValue;
|
||||
} else if (paramName.equals(GUARANTOR_JSON_INPUT_PARAMS.MOBILE_NUMBER.getValue())) {
|
||||
this.mobilePhoneNumber = newValue;
|
||||
} else if (paramName.equals(GUARANTOR_JSON_INPUT_PARAMS.COMMENT.getValue())) {
|
||||
this.comment = newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePropertyUpdate(final JsonCommand command, final Map<String, Object> actualChanges, final String paramName,
|
||||
Long propertyToBeUpdated) {
|
||||
if (command.isChangeInLongParameterNamed(paramName, propertyToBeUpdated)) {
|
||||
final Long newValue = command.longValueOfParameterNamed(paramName);
|
||||
actualChanges.put(paramName, newValue);
|
||||
propertyToBeUpdated = newValue;
|
||||
|
||||
// now update actual property
|
||||
if (paramName.equals(GUARANTOR_JSON_INPUT_PARAMS.ENTITY_ID.getValue())) {
|
||||
this.entityId = newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePropertyUpdate(final JsonCommand command, final Map<String, Object> actualChanges, final String paramName,
|
||||
Date propertyToBeUpdated) {
|
||||
if (command.isChangeInDateParameterNamed(paramName, propertyToBeUpdated)) {
|
||||
final Date newValue = command.DateValueOfParameterNamed(paramName);
|
||||
actualChanges.put(paramName, newValue);
|
||||
propertyToBeUpdated = newValue;
|
||||
|
||||
// now update actual property
|
||||
if (paramName.equals(GUARANTOR_JSON_INPUT_PARAMS.DATE_OF_BIRTH.getValue())) {
|
||||
this.dateOfBirth = newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Long getEntityId() {
|
||||
return this.entityId;
|
||||
}
|
||||
|
||||
public Long getLoanId() {
|
||||
return this.loan.getId();
|
||||
}
|
||||
|
||||
public Long getClientId() {
|
||||
return this.loan.getClientId();
|
||||
}
|
||||
|
||||
public Long getOfficeId() {
|
||||
return this.loan.getOfficeId();
|
||||
}
|
||||
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.domain;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
public interface GuarantorRepository extends JpaRepository<Guarantor, Long>, JpaSpecificationExecutor<Guarantor> {
|
||||
// no behaviour
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.domain;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum GuarantorType {
|
||||
CUSTOMER(1, "guarantor.existing.customer"), STAFF(2, "guarantor.staff"), EXTERNAL(3, "guarantor.external");
|
||||
|
||||
private final Integer value;
|
||||
private final String code;
|
||||
|
||||
private GuarantorType(final Integer value, final String code) {
|
||||
this.value = value;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
private static final Map<Integer, GuarantorType> intToEnumMap = new HashMap<Integer, GuarantorType>();
|
||||
private static int minValue;
|
||||
private static int maxValue;
|
||||
static {
|
||||
int i = 0;
|
||||
for (GuarantorType type : GuarantorType.values()) {
|
||||
if (i == 0) {
|
||||
minValue = type.value;
|
||||
}
|
||||
intToEnumMap.put(type.value, type);
|
||||
if (minValue >= type.value) {
|
||||
minValue = type.value;
|
||||
}
|
||||
if (maxValue < type.value) {
|
||||
maxValue = type.value;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public static GuarantorType fromInt(int i) {
|
||||
GuarantorType 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();
|
||||
}
|
||||
|
||||
}
|
||||
+4
-6
@@ -5,11 +5,9 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceN
|
||||
/**
|
||||
* A {@link RuntimeException} thrown when guarantor resources are not found.
|
||||
*/
|
||||
public class GuarantorNotFoundException extends
|
||||
AbstractPlatformResourceNotFoundException {
|
||||
public class GuarantorNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
|
||||
public GuarantorNotFoundException(Long id) {
|
||||
super("error.msg.loan.guarantor.", "Loan with identifier " + id
|
||||
+ " does not have a guarantor associated with it", id);
|
||||
}
|
||||
public GuarantorNotFoundException(Long id) {
|
||||
super("error.msg.loan.guarantor.", "Guarantor with identifier " + id + " does not exist", id);
|
||||
}
|
||||
}
|
||||
+5
-8
@@ -6,14 +6,11 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRul
|
||||
* {@link AbstractPlatformDomainRuleException} thrown when a Client is set as a
|
||||
* guarantor for his/her own loans
|
||||
*/
|
||||
public class InvalidGuarantorException extends
|
||||
AbstractPlatformDomainRuleException {
|
||||
public class InvalidGuarantorException extends AbstractPlatformDomainRuleException {
|
||||
|
||||
public InvalidGuarantorException(Long clientId, Long loanId) {
|
||||
super("error.msg.invalid.guarantor", "Tried to set Client with id "
|
||||
+ clientId
|
||||
+ " as a guarantor to his/her own loan with loan identifier ="
|
||||
+ loanId, clientId, loanId);
|
||||
}
|
||||
public InvalidGuarantorException(Long clientId, Long loanId) {
|
||||
super("error.msg.invalid.guarantor", "Tried to set Client with id " + clientId
|
||||
+ " as a guarantor to his/her own loan with loan identifier =" + loanId, clientId, loanId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.handler;
|
||||
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.service.GuarantorWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class CreateGuarantorCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final GuarantorWritePlatformService writePlatformService;
|
||||
|
||||
@Autowired
|
||||
public CreateGuarantorCommandHandler(final GuarantorWritePlatformService writePlatformService) {
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||
|
||||
return this.writePlatformService.createGuarantor(command);
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.handler;
|
||||
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.service.GuarantorWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class DeleteGuarantorCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final GuarantorWritePlatformService guarantorWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public DeleteGuarantorCommandHandler(final GuarantorWritePlatformService guarantorWritePlatformService) {
|
||||
this.guarantorWritePlatformService = guarantorWritePlatformService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||
return this.guarantorWritePlatformService.removeGuarantor(command.entityId());
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.handler;
|
||||
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.service.GuarantorWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class UpdateGuarantorCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final GuarantorWritePlatformService writePlatformService;
|
||||
|
||||
@Autowired
|
||||
public UpdateGuarantorCommandHandler(final GuarantorWritePlatformService writePlatformService) {
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||
return this.writePlatformService.updateGuarantor(command.entityId(), command);
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.AbstractFromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.GuarantorConstants.GUARANTOR_JSON_INPUT_PARAMS;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.command.GuarantorCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for
|
||||
* {@link GuarantorCommand}'s.
|
||||
*/
|
||||
@Component
|
||||
public final class GuarantorCommandFromApiJsonDeserializer extends AbstractFromApiJsonDeserializer<GuarantorCommand> {
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public GuarantorCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuarantorCommand commandFromApiJson(String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, GUARANTOR_JSON_INPUT_PARAMS.getAllValues());
|
||||
|
||||
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||
|
||||
Long loanId = fromApiJsonHelper.extractLongNamed(GUARANTOR_JSON_INPUT_PARAMS.LOAN_ID.getValue(), element);
|
||||
Integer guarantorTypeId = fromApiJsonHelper.extractIntegerSansLocaleNamed(
|
||||
GUARANTOR_JSON_INPUT_PARAMS.GUARANTOR_TYPE_ID.getValue(), element);
|
||||
Long entityId = fromApiJsonHelper.extractLongNamed(GUARANTOR_JSON_INPUT_PARAMS.ENTITY_ID.getValue(), element);
|
||||
String firstname = fromApiJsonHelper.extractStringNamed(GUARANTOR_JSON_INPUT_PARAMS.FIRSTNAME.getValue(), element);
|
||||
String lastname = fromApiJsonHelper.extractStringNamed(GUARANTOR_JSON_INPUT_PARAMS.LASTNAME.getValue(), element);
|
||||
String addressLine1 = fromApiJsonHelper.extractStringNamed(GUARANTOR_JSON_INPUT_PARAMS.ADDRESS_LINE_1.getValue(), element);
|
||||
String addressLine2 = fromApiJsonHelper.extractStringNamed(GUARANTOR_JSON_INPUT_PARAMS.ADDRESS_LINE_2.getValue(), element);
|
||||
String city = fromApiJsonHelper.extractStringNamed(GUARANTOR_JSON_INPUT_PARAMS.CITY.getValue(), element);
|
||||
String state = fromApiJsonHelper.extractStringNamed(GUARANTOR_JSON_INPUT_PARAMS.STATE.getValue(), element);
|
||||
String zip = fromApiJsonHelper.extractStringNamed(GUARANTOR_JSON_INPUT_PARAMS.ZIP.getValue(), element);
|
||||
String country = fromApiJsonHelper.extractStringNamed(GUARANTOR_JSON_INPUT_PARAMS.COUNTRY.getValue(), element);
|
||||
String mobileNumber = fromApiJsonHelper.extractStringNamed(GUARANTOR_JSON_INPUT_PARAMS.MOBILE_NUMBER.getValue(), element);
|
||||
String housePhoneNumber = fromApiJsonHelper.extractStringNamed(GUARANTOR_JSON_INPUT_PARAMS.PHONE_NUMBER.getValue(), element);
|
||||
String comment = fromApiJsonHelper.extractStringNamed(GUARANTOR_JSON_INPUT_PARAMS.COMMENT.getValue(), element);
|
||||
LocalDate dob = fromApiJsonHelper.extractLocalDateNamed(GUARANTOR_JSON_INPUT_PARAMS.DATE_OF_BIRTH.getValue(), element);
|
||||
|
||||
return new GuarantorCommand(loanId, guarantorTypeId, entityId, firstname, lastname, addressLine1, addressLine2, city, state, zip,
|
||||
country, mobileNumber, housePhoneNumber, comment, dob);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.domain.GuarantorType;
|
||||
|
||||
public class GuarantorEnumerations {
|
||||
|
||||
public static EnumOptionData guarantorType(final int id) {
|
||||
return guarantorType(GuarantorType.fromInt(id));
|
||||
}
|
||||
|
||||
public static EnumOptionData guarantorType(final GuarantorType guarantorType) {
|
||||
EnumOptionData optionData = new EnumOptionData(guarantorType.getValue().longValue(), guarantorType.getCode(),
|
||||
guarantorType.toString());
|
||||
return optionData;
|
||||
}
|
||||
|
||||
public static List<EnumOptionData> guarantorType(GuarantorType[] guarantorTypes) {
|
||||
List<EnumOptionData> optionDatas = new ArrayList<EnumOptionData>();
|
||||
for (GuarantorType guarantorType : guarantorTypes) {
|
||||
optionDatas.add(guarantorType(guarantorType));
|
||||
}
|
||||
return optionDatas;
|
||||
}
|
||||
|
||||
}
|
||||
+5
-3
@@ -1,13 +1,15 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData;
|
||||
|
||||
public interface GuarantorReadPlatformService {
|
||||
|
||||
GuarantorData retrieveGuarantor(Long loanId);
|
||||
List<GuarantorData> retrieveGuarantorsForLoan(Long loanId);
|
||||
|
||||
boolean existsGuarantor(Long loanId);
|
||||
GuarantorData retrieveGuarantor(Long guarantorId);
|
||||
|
||||
GuarantorData getExternalGuarantor(Long loanId);
|
||||
GuarantorData retrieveNewGuarantorDetails();
|
||||
|
||||
}
|
||||
+93
-78
@@ -1,101 +1,116 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.service;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
|
||||
import org.mifosplatform.infrastructure.dataqueries.service.ReadWriteNonCoreDataService;
|
||||
import org.mifosplatform.portfolio.client.domain.Client;
|
||||
import org.mifosplatform.portfolio.loanaccount.domain.Loan;
|
||||
import org.mifosplatform.portfolio.loanaccount.domain.LoanRepository;
|
||||
import org.mifosplatform.portfolio.loanaccount.exception.LoanNotFoundException;
|
||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
||||
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
|
||||
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.loanaccount.gaurantor.data.GuarantorData;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.exception.GuarantorNotFoundException;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.domain.GuarantorType;
|
||||
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 GuarantorReadPlatformServiceImpl implements GuarantorReadPlatformService {
|
||||
|
||||
// Table for storing external Guarantor Details
|
||||
public static final String EXTERNAL_GUARANTOR_TABLE_NAME = "m_guarantor_external";
|
||||
|
||||
private final LoanRepository loanRepository;
|
||||
private final ReadWriteNonCoreDataService readWriteNonCoreDataService;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final ClientReadPlatformService clientReadPlatformService;
|
||||
private final StaffReadPlatformService staffReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
public GuarantorReadPlatformServiceImpl(final LoanRepository loanRepository,
|
||||
final ReadWriteNonCoreDataService readWriteNonCoreDataService) {
|
||||
this.loanRepository = loanRepository;
|
||||
this.readWriteNonCoreDataService = readWriteNonCoreDataService;
|
||||
public GuarantorReadPlatformServiceImpl(final TenantAwareRoutingDataSource dataSource,
|
||||
final ClientReadPlatformService clientReadPlatformService, final StaffReadPlatformService staffReadPlatformService) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.clientReadPlatformService = clientReadPlatformService;
|
||||
this.staffReadPlatformService = staffReadPlatformService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsGuarantor(Long loanId) {
|
||||
Loan loan = retrieveLoanById(loanId);
|
||||
// return if internal guarantor exists
|
||||
if (loan.getGuarantor() != null) { return true; }
|
||||
// return if an external guarantor exists
|
||||
if (null != getExternalGuarantor(loanId)) { return true; }
|
||||
// else no guarantor exists
|
||||
return false;
|
||||
}
|
||||
private static final class GuarantorMapper implements RowMapper<GuarantorData> {
|
||||
|
||||
public String schema() {
|
||||
return " g.id as id, g.loan_id as loanId, g.entity_id as entityId, g.type_enum guarantorType ,g.firstname as firstname,"
|
||||
+ " g.lastname as lastname, g.dob as dateOfBirth, g.address_line_1 as addressLine1, g.address_line_2 as addressLine2,"
|
||||
+ " g.city as city, g.state as state, g.country as country, g.zip as zip, g.house_phone_number as housePhoneNumber, "
|
||||
+ " g.mobile_number as mobilePhoneNumber, g.comment as comment from m_guarantor g";
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuarantorData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
Long id = rs.getLong("id");
|
||||
Long loanId = rs.getLong("loanId");
|
||||
Integer guarantorTypeId = rs.getInt("guarantorType");
|
||||
final EnumOptionData guarantorType = GuarantorEnumerations.guarantorType(guarantorTypeId);
|
||||
Long entityId = rs.getLong("entityId");
|
||||
String firstname = rs.getString("firstname");
|
||||
String lastname = rs.getString("lastname");
|
||||
LocalDate dob = JdbcSupport.getLocalDate(rs, "dateOfBirth");
|
||||
String addressLine1 = rs.getString("addressLine1");
|
||||
String addressLine2 = rs.getString("addressLine2");
|
||||
String city = rs.getString("city");
|
||||
String state = rs.getString("state");
|
||||
String zip = rs.getString("zip");
|
||||
String country = rs.getString("country");
|
||||
String mobileNumber = rs.getString("mobilePhoneNumber");
|
||||
String housePhoneNumber = rs.getString("housePhoneNumber");
|
||||
String comment = rs.getString("comment");
|
||||
return new GuarantorData(id, loanId, entityId, guarantorType, firstname, lastname, dob, addressLine1, addressLine2, city,
|
||||
state, zip, country, mobileNumber, housePhoneNumber, comment, null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuarantorData retrieveGuarantor(Long loanId) {
|
||||
GuarantorData guarantorData = null;
|
||||
Loan loan = retrieveLoanById(loanId);
|
||||
// does an internal guarantor exist
|
||||
if (loan.getGuarantor() != null) {
|
||||
Client guarantor = loan.getGuarantor();
|
||||
LocalDate localDate = new LocalDate(guarantor.getJoiningDate());
|
||||
guarantorData = new GuarantorData(guarantor.getId(), guarantor.getFirstName(), guarantor.getLastName(),
|
||||
guarantor.getExternalId(), guarantor.getOffice().getName(), localDate);
|
||||
} else {
|
||||
guarantorData = getExternalGuarantor(loanId);
|
||||
public List<GuarantorData> retrieveGuarantorsForLoan(Long loanId) {
|
||||
final GuarantorMapper rm = new GuarantorMapper();
|
||||
String sql = "select " + rm.schema();
|
||||
sql += " where loan_id = ?";
|
||||
List<GuarantorData> guarantorDatas = this.jdbcTemplate.query(sql, rm, new Object[] { loanId });
|
||||
|
||||
List<GuarantorData> mergedGuarantorDatas = new ArrayList<GuarantorData>();
|
||||
|
||||
for (GuarantorData guarantorData : guarantorDatas) {
|
||||
mergedGuarantorDatas.add(mergeDetailsForClientOrStaffGuarantor(guarantorData));
|
||||
}
|
||||
return mergedGuarantorDatas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuarantorData retrieveGuarantor(Long guarantorId) {
|
||||
final GuarantorMapper rm = new GuarantorMapper();
|
||||
String sql = "select " + rm.schema();
|
||||
sql += " where loan_id = ?";
|
||||
GuarantorData guarantorData = this.jdbcTemplate.queryForObject(sql, rm, new Object[] { guarantorId });
|
||||
|
||||
return mergeDetailsForClientOrStaffGuarantor(guarantorData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuarantorData retrieveNewGuarantorDetails() {
|
||||
final List<EnumOptionData> guarantorTypeOptions = GuarantorEnumerations.guarantorType(GuarantorType.values());
|
||||
return GuarantorData.template(guarantorTypeOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param guarantorData
|
||||
*/
|
||||
private GuarantorData mergeDetailsForClientOrStaffGuarantor(GuarantorData guarantorData) {
|
||||
if (guarantorData.isExistingClient()) {
|
||||
ClientData clientData = clientReadPlatformService.retrieveIndividualClient(guarantorData.getEntityId());
|
||||
return GuarantorData.mergeClientData(clientData, guarantorData);
|
||||
} else if (guarantorData.isStaffMember()) {
|
||||
StaffData staffData = staffReadPlatformService.retrieveStaff(guarantorData.getEntityId());
|
||||
return GuarantorData.mergeStaffData(staffData, guarantorData);
|
||||
}
|
||||
// throw error if guarantor does not exist
|
||||
if (guarantorData == null) { throw new GuarantorNotFoundException(loanId); }
|
||||
return guarantorData;
|
||||
}
|
||||
|
||||
private Loan retrieveLoanById(final Long loanId) {
|
||||
|
||||
// FIXME - KW - On the read side of services - we would prefer not to
|
||||
// use the repository/ORM pattern
|
||||
Loan loan = loanRepository.findOne(loanId);
|
||||
if (loan == null) { throw new LoanNotFoundException(loanId); }
|
||||
return loan;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuarantorData getExternalGuarantor(final Long loanId) {
|
||||
|
||||
GenericResultsetData genericResultDataSet = readWriteNonCoreDataService.retrieveDataTableGenericResultSet(
|
||||
EXTERNAL_GUARANTOR_TABLE_NAME, loanId, null, null);
|
||||
if (genericResultDataSet.getData().size() == 1) {
|
||||
List<String> guarantorRow = genericResultDataSet.getData().get(0).getRow();
|
||||
String firstname = guarantorRow.get(1);
|
||||
String lastname = guarantorRow.get(2);
|
||||
|
||||
LocalDate dateOfBirth = null;
|
||||
if (!StringUtils.isBlank(guarantorRow.get(3))) {
|
||||
dateOfBirth = new LocalDate(guarantorRow.get(3));
|
||||
}
|
||||
String addressLine1 = guarantorRow.get(4);
|
||||
String addressLine2 = guarantorRow.get(5);
|
||||
String city = guarantorRow.get(6);
|
||||
String state = guarantorRow.get(7);
|
||||
String country = guarantorRow.get(8);
|
||||
String zip = guarantorRow.get(9);
|
||||
String housePhoneNumber = guarantorRow.get(10);
|
||||
String mobileNumber = guarantorRow.get(11);
|
||||
String comment = guarantorRow.get(12);
|
||||
GuarantorData guarantorData = new GuarantorData(firstname, lastname, dateOfBirth, addressLine1, addressLine2, city, state, zip,
|
||||
country, mobileNumber, housePhoneNumber, comment);
|
||||
return guarantorData;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+5
-8
@@ -1,17 +1,14 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.service;
|
||||
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.command.GuarantorCommand;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
|
||||
public interface GuarantorWritePlatformService {
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS')")
|
||||
void createGuarantor(final Long loanId, final GuarantorCommand command);
|
||||
CommandProcessingResult createGuarantor(final JsonCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS')")
|
||||
void updateGuarantor(final Long loanId, final GuarantorCommand command);
|
||||
CommandProcessingResult updateGuarantor(final Long guarantorId, final JsonCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS')")
|
||||
void removeGuarantor(final Long loanId);
|
||||
CommandProcessingResult removeGuarantor(final Long guarantorId);
|
||||
|
||||
}
|
||||
-146
@@ -1,146 +0,0 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.service;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
import org.mifosplatform.infrastructure.dataqueries.service.ReadWriteNonCoreDataService;
|
||||
import org.mifosplatform.portfolio.client.domain.Client;
|
||||
import org.mifosplatform.portfolio.client.domain.ClientRepository;
|
||||
import org.mifosplatform.portfolio.client.exception.ClientNotFoundException;
|
||||
import org.mifosplatform.portfolio.loanaccount.domain.Loan;
|
||||
import org.mifosplatform.portfolio.loanaccount.domain.LoanRepository;
|
||||
import org.mifosplatform.portfolio.loanaccount.exception.LoanNotFoundException;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.command.GuarantorCommand;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.command.GuarantorCommandValidator;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.exception.InvalidGuarantorException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class GuarantorWritePlatformServiceImpl implements GuarantorWritePlatformService {
|
||||
|
||||
// Table for storing external Guarantor Details
|
||||
public static final String EXTERNAL_GUARANTOR_TABLE_NAME = "m_guarantor_external";
|
||||
|
||||
private final LoanRepository loanRepository;
|
||||
private final ClientRepository clientRepository;
|
||||
private final ReadWriteNonCoreDataService readWriteNonCoreDataService;
|
||||
private final GuarantorReadPlatformService guarantorReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
public GuarantorWritePlatformServiceImpl(final LoanRepository loanRepository,
|
||||
final ReadWriteNonCoreDataService readWriteNonCoreDataService, final ClientRepository clientRepository,
|
||||
final GuarantorReadPlatformService guarantorReadPlatformService) {
|
||||
this.loanRepository = loanRepository;
|
||||
this.readWriteNonCoreDataService = readWriteNonCoreDataService;
|
||||
this.clientRepository = clientRepository;
|
||||
this.guarantorReadPlatformService = guarantorReadPlatformService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void createGuarantor(final Long loanId, final GuarantorCommand command) {
|
||||
GuarantorCommandValidator validator = new GuarantorCommandValidator(command);
|
||||
validator.validateForCreate();
|
||||
saveOrUpdateGuarantor(loanId, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateGuarantor(final Long loanId, final GuarantorCommand command) {
|
||||
GuarantorCommandValidator validator = new GuarantorCommandValidator(command);
|
||||
validator.validateForUpdate();
|
||||
saveOrUpdateGuarantor(loanId, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeGuarantor(final Long loanId) {
|
||||
Loan loan = retrieveLoanById(loanId);
|
||||
// remove internal guarantor, if any
|
||||
if (loan.getGuarantor() != null) {
|
||||
loan.setGuarantor(null);
|
||||
loanRepository.saveAndFlush(loan);
|
||||
}
|
||||
// remove external guarantor, if any
|
||||
readWriteNonCoreDataService.deleteDatatableEntries(EXTERNAL_GUARANTOR_TABLE_NAME, loanId);
|
||||
}
|
||||
|
||||
private void saveOrUpdateGuarantor(final Long loanId, final GuarantorCommand command) {
|
||||
Loan loan = retrieveLoanById(loanId);
|
||||
// mark an existing client as a guarantor
|
||||
if (command.isExternalGuarantor() == null || !command.isExternalGuarantor()) {
|
||||
// can't set client as a guarantor to himself
|
||||
if (loan.getClient().getId().equals(command.getExistingClientId())) { throw new InvalidGuarantorException(
|
||||
command.getExistingClientId(), loanId); }
|
||||
Client guarantor = clientRepository.findOne(command.getExistingClientId());
|
||||
if (guarantor == null) { throw new ClientNotFoundException(command.getExistingClientId()); }
|
||||
loan.setGuarantor(guarantor);
|
||||
this.loanRepository.saveAndFlush(loan);
|
||||
// also delete any existing External Guarantors
|
||||
readWriteNonCoreDataService.deleteDatatableEntries(EXTERNAL_GUARANTOR_TABLE_NAME, loanId);
|
||||
}// or create an external guarantor
|
||||
else {
|
||||
Set<String> modifiedParameters = command.getModifiedParameters();
|
||||
Map<String, String> modifiedParametersMap = new HashMap<String, String>();
|
||||
|
||||
/***
|
||||
* TODO Vishwas: Check with JW/KW if using reflection here is a good
|
||||
* idea
|
||||
**/
|
||||
Class<? extends GuarantorCommand> guarantorCommandClass = command.getClass();
|
||||
for (String modifiedParameter : modifiedParameters) {
|
||||
Method method;
|
||||
try {
|
||||
if (modifiedParameter.equalsIgnoreCase("externalGuarantor") || modifiedParameter.equalsIgnoreCase("existingClientId")) {
|
||||
continue;
|
||||
} else {
|
||||
method = guarantorCommandClass.getMethod("get" + StringUtils.capitalize(modifiedParameter));
|
||||
}
|
||||
String columnName = StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(modifiedParameter), '_');
|
||||
modifiedParametersMap.put(columnName.toLowerCase(), method.invoke(command).toString());
|
||||
} catch (Exception e) {
|
||||
// TODO: This block would ideally never be reached, could
|
||||
// use an
|
||||
// empty catch block instead?
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
ApiParameterError apiParameterError = ApiParameterError.parameterError("validation.msg.validation.errors.exist", "",
|
||||
modifiedParameter);
|
||||
dataValidationErrors.add(apiParameterError);
|
||||
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Invalid parameter passed for Creating updating Guarantor", dataValidationErrors);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*** update or create a new external Guarantor entry ***/
|
||||
modifiedParametersMap.put("locale", command.getLocale());
|
||||
modifiedParametersMap.put("dateFormat", command.getDateFormat());
|
||||
if (guarantorReadPlatformService.getExternalGuarantor(loanId) != null) {
|
||||
// readWriteNonCoreDataService.updateDatatableEntryOnetoOne(EXTERNAL_GUARANTOR_TABLE_NAME, loanId, modifiedParametersMap);
|
||||
} else {
|
||||
// FIXME - put back in call to datatable passing JsonCommand
|
||||
// readWriteNonCoreDataService.newDatatableEntry(EXTERNAL_GUARANTOR_TABLE_NAME, loanId, modifiedParametersMap);
|
||||
}
|
||||
// finally unset any existing internal guarantors
|
||||
if (loan.getGuarantor() != null) {
|
||||
loan.setGuarantor(null);
|
||||
this.loanRepository.saveAndFlush(loan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Loan retrieveLoanById(final Long loanId) {
|
||||
Loan loan = loanRepository.findOne(loanId);
|
||||
if (loan == null) { throw new LoanNotFoundException(loanId); }
|
||||
return loan;
|
||||
}
|
||||
}
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
package org.mifosplatform.portfolio.loanaccount.gaurantor.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||
import org.mifosplatform.organisation.staff.domain.Staff;
|
||||
import org.mifosplatform.organisation.staff.domain.StaffRepository;
|
||||
import org.mifosplatform.organisation.staff.exception.StaffNotFoundException;
|
||||
import org.mifosplatform.portfolio.client.domain.Client;
|
||||
import org.mifosplatform.portfolio.client.domain.ClientRepository;
|
||||
import org.mifosplatform.portfolio.client.exception.ClientNotFoundException;
|
||||
import org.mifosplatform.portfolio.loanaccount.domain.Loan;
|
||||
import org.mifosplatform.portfolio.loanaccount.domain.LoanRepository;
|
||||
import org.mifosplatform.portfolio.loanaccount.exception.LoanNotFoundException;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.GuarantorConstants.GUARANTOR_JSON_INPUT_PARAMS;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.command.GuarantorCommand;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.domain.Guarantor;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.domain.GuarantorRepository;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.exception.GuarantorNotFoundException;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.exception.InvalidGuarantorException;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.serialization.GuarantorCommandFromApiJsonDeserializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements GuarantorWritePlatformService {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(GuarantorWritePlatformServiceJpaRepositoryIImpl.class);
|
||||
|
||||
private final ClientRepository clientRepository;
|
||||
private final StaffRepository staffRepository;
|
||||
private final LoanRepository loanRepository;
|
||||
private final GuarantorRepository guarantorRepository;
|
||||
private final GuarantorCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||
|
||||
@Autowired
|
||||
public GuarantorWritePlatformServiceJpaRepositoryIImpl(final LoanRepository loanRepository,
|
||||
final GuarantorRepository guarantorRepository, final ClientRepository clientRepository, final StaffRepository staffRepository,
|
||||
final GuarantorCommandFromApiJsonDeserializer fromApiJsonDeserializer) {
|
||||
this.loanRepository = loanRepository;
|
||||
this.clientRepository = clientRepository;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.guarantorRepository = guarantorRepository;
|
||||
this.staffRepository = staffRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CommandProcessingResult createGuarantor(final JsonCommand command) {
|
||||
try {
|
||||
final GuarantorCommand guarantorCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json());
|
||||
guarantorCommand.validateForCreate();
|
||||
|
||||
final Long loanId = command.longValueOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.LOAN_ID.getValue());
|
||||
Loan loan = retrieveLoanById(loanId);
|
||||
Guarantor guarantor = null;
|
||||
guarantor = Guarantor.fromJson(loan, command);
|
||||
|
||||
validateGuarantorBusinessRules(guarantor);
|
||||
|
||||
this.guarantorRepository.saveAndFlush(guarantor);
|
||||
|
||||
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(guarantor.getOfficeId())
|
||||
.withEntityId(guarantor.getId()).withLoanId(loanId).build();
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleGuarantorDataIntegrityIssues(command, dve);
|
||||
return CommandProcessingResult.empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CommandProcessingResult updateGuarantor(final Long guarantorId, final JsonCommand command) {
|
||||
try {
|
||||
final GuarantorCommand guarantorCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json());
|
||||
guarantorCommand.validateForUpdate();
|
||||
|
||||
final Guarantor guarantorForUpdate = this.guarantorRepository.findOne(guarantorId);
|
||||
if (guarantorForUpdate == null) { throw new GuarantorNotFoundException(guarantorId); }
|
||||
|
||||
final Map<String, Object> changesOnly = guarantorForUpdate.update(command);
|
||||
|
||||
if (changesOnly.containsKey(GUARANTOR_JSON_INPUT_PARAMS.ENTITY_ID)
|
||||
|| changesOnly.containsKey(GUARANTOR_JSON_INPUT_PARAMS.GUARANTOR_TYPE_ID)) {
|
||||
validateGuarantorBusinessRules(guarantorForUpdate);
|
||||
}
|
||||
|
||||
if (!changesOnly.isEmpty()) {
|
||||
this.guarantorRepository.save(guarantorForUpdate);
|
||||
}
|
||||
|
||||
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(guarantorForUpdate.getOfficeId())
|
||||
.withEntityId(guarantorForUpdate.getId()).withOfficeId(guarantorForUpdate.getLoanId()).with(changesOnly).build();
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleGuarantorDataIntegrityIssues(command, dve);
|
||||
return CommandProcessingResult.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CommandProcessingResult removeGuarantor(final Long guarantorId) {
|
||||
final Guarantor guarantorForDelete = this.guarantorRepository.findOne(guarantorId);
|
||||
if (guarantorForDelete == null) { throw new GuarantorNotFoundException(guarantorId); }
|
||||
|
||||
this.guarantorRepository.delete(guarantorForDelete);
|
||||
|
||||
return new CommandProcessingResultBuilder().withEntityId(guarantorId).withLoanId(guarantorForDelete.getLoanId())
|
||||
.withOfficeId(guarantorForDelete.getOfficeId()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param loanId
|
||||
* @param loan
|
||||
* @param guarantor
|
||||
*/
|
||||
private void validateGuarantorBusinessRules(Guarantor guarantor) {
|
||||
// validate guarantor conditions
|
||||
if (guarantor.isExistingCustomer()) {
|
||||
// check client exists
|
||||
Client client = clientRepository.findOne(guarantor.getEntityId());
|
||||
if (client == null) { throw new ClientNotFoundException(guarantor.getEntityId()); }
|
||||
|
||||
// validate that the client is not set as a self guarantor
|
||||
if (guarantor.getClientId().equals(guarantor.getEntityId())) { throw new InvalidGuarantorException(guarantor.getEntityId(),
|
||||
guarantor.getLoanId()); }
|
||||
} else if (guarantor.isExistingEmployee()) {
|
||||
Staff staff = staffRepository.findOne(guarantor.getEntityId());
|
||||
if (staff == null) { throw new StaffNotFoundException(guarantor.getEntityId()); }
|
||||
}
|
||||
}
|
||||
|
||||
private Loan retrieveLoanById(final Long loanId) {
|
||||
Loan loan = loanRepository.findOne(loanId);
|
||||
if (loan == null) { throw new LoanNotFoundException(loanId); }
|
||||
return loan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an exception for any data Integrity issue
|
||||
*
|
||||
* @param command
|
||||
* @param dve
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private void handleGuarantorDataIntegrityIssues(final JsonCommand command, DataIntegrityViolationException dve) {
|
||||
Throwable realCause = dve.getMostSpecificCause();
|
||||
logger.error(dve.getMessage(), dve);
|
||||
throw new PlatformDataIntegrityException("error.msg.guarantor.unknown.data.integrity.issue",
|
||||
"Unknown data integrity issue with resource Guarantor: " + realCause.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
+1
-2
@@ -19,8 +19,7 @@ public interface LoanReadPlatformService {
|
||||
|
||||
Collection<LoanTransactionData> retrieveLoanTransactions(Long loanId);
|
||||
|
||||
LoanPermissionData retrieveLoanPermissions(LoanBasicDetailsData loanBasicDetails, boolean isWaiverAllowed, int repaymentAndWaiveCount,
|
||||
boolean existsGuarantor);
|
||||
LoanPermissionData retrieveLoanPermissions(LoanBasicDetailsData loanBasicDetails, boolean isWaiverAllowed, int repaymentAndWaiveCount);
|
||||
|
||||
LoanBasicDetailsData retrieveClientAndProductDetails(Long clientId, Long productId);
|
||||
|
||||
|
||||
+1
-7
@@ -197,7 +197,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
|
||||
@Override
|
||||
public LoanPermissionData retrieveLoanPermissions(final LoanBasicDetailsData loanBasicDetails, final boolean isWaiverAllowed,
|
||||
final int repaymentAndWaiveCount, final boolean existsGuarantor) {
|
||||
final int repaymentAndWaiveCount) {
|
||||
|
||||
final boolean pendingApproval = (loanBasicDetails.getStatus().getId().equals(100L));
|
||||
final boolean waitingForDisbursal = (loanBasicDetails.getStatus().getId().equals(200L));
|
||||
@@ -218,12 +218,6 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
editGuarantorAllowed = false;
|
||||
}
|
||||
|
||||
if (existsGuarantor) {
|
||||
setGuarantorAllowed = false;
|
||||
} else {
|
||||
editGuarantorAllowed = false;
|
||||
}
|
||||
|
||||
final boolean waiveAllowed = isWaiverAllowed && isActive;
|
||||
final boolean makeRepaymentAllowed = isActive;
|
||||
final boolean closeLoanAllowed = !closed && isActive;
|
||||
|
||||
-13
@@ -6,7 +6,6 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.serialization.GoogleGsonSerializerHelper;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData;
|
||||
import org.mifosplatform.portfolio.savingsaccount.data.SavingAccountData;
|
||||
import org.mifosplatform.portfolio.savingsaccount.data.SavingScheduleData;
|
||||
import org.mifosplatform.portfolio.savingsaccountproduct.data.SavingProductData;
|
||||
@@ -57,11 +56,6 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
|
||||
"savingFrequencyOptions", "savingsInterestTypeOptions", "lockinPeriodTypeOptions", "interestCalculationOptions","permissions","savingScheduleDatas",
|
||||
"dueAmount", "savingScheduleData", "transactions","interestPostEvery","interestPostFrequency"));
|
||||
|
||||
// guarantors
|
||||
private static final Set<String> GUARANTOR_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("externalGuarantor", "existingClientId",
|
||||
"firstname", "lastname", "addressLine1", "addressLine2", "city", "state", "zip", "country", "mobileNumber", "housePhoneNumber",
|
||||
"comment", "dob"));
|
||||
|
||||
private static final Set<String> SAVING_SCHEDULE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("periods", "cumulativeDepositDue"));
|
||||
|
||||
private final GoogleGsonSerializerHelper helper;
|
||||
@@ -134,13 +128,6 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
|
||||
return helper.serializedJsonFrom(gsonDeserializer, accounts.toArray(new SavingAccountData[accounts.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeGuarantorDataToJson(boolean prettyPrint, Set<String> responseParameters, GuarantorData guarantorData) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(GUARANTOR_DATA_PARAMETERS,
|
||||
prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, guarantorData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeSavingScheduleDataToJson(boolean prettyPrint, Set<String> responseParameters,
|
||||
SavingScheduleData savingScheduleData) {
|
||||
|
||||
+1
-3
@@ -2,7 +2,6 @@ package org.mifosplatform.portfolio.savingsaccount;
|
||||
|
||||
import org.mifosplatform.portfolio.client.data.ClientData;
|
||||
import org.mifosplatform.portfolio.group.command.GroupCommand;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.command.GuarantorCommand;
|
||||
import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountApprovalCommand;
|
||||
import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountCommand;
|
||||
import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountDepositCommand;
|
||||
@@ -38,8 +37,6 @@ public interface PortfolioApiDataConversionService {
|
||||
|
||||
SavingAccountCommand convertJsonToSavingAccountCommand(Long resourceIdentifier, String json);
|
||||
|
||||
GuarantorCommand convertJsonToGuarantorCommand(Long resourceIdentifier, Long loanId, String json);
|
||||
|
||||
SavingStateTransitionsCommand convertJsonToSavingStateTransitionCommand(Long accountId, String json);
|
||||
|
||||
SavingAccountApprovalCommand convertJsonToSavingApprovalCommand(Long accountId, String json);
|
||||
@@ -47,4 +44,5 @@ public interface PortfolioApiDataConversionService {
|
||||
SavingAccountDepositCommand convertJsonToSavingAccountDepositCommand(Long accountId, String json);
|
||||
|
||||
SavingAccountWithdrawalCommand convertJsonToSavingAccountWithdrawalCommand(Long accountId, String jsonRequestBody);
|
||||
|
||||
}
|
||||
+30
-72
@@ -25,7 +25,6 @@ import org.mifosplatform.portfolio.client.command.ClientCommand;
|
||||
import org.mifosplatform.portfolio.client.data.ClientData;
|
||||
import org.mifosplatform.portfolio.client.serialization.ClientCommandFromApiJsonDeserializer;
|
||||
import org.mifosplatform.portfolio.group.command.GroupCommand;
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.command.GuarantorCommand;
|
||||
import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountApprovalCommand;
|
||||
import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountCommand;
|
||||
import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountDepositCommand;
|
||||
@@ -854,51 +853,10 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
isLockinPeriodAllowed, isPartialDepositAllowed, lockinPeriod, lockinPeriodType, depositEvery, interestPostEvery, interestPostFrequency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuarantorCommand convertJsonToGuarantorCommand(Long resourceIdentifier, Long loanId, String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
Type typeOfMap = new TypeToken<Map<String, String>>() {}.getType();
|
||||
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
Set<String> supportedParams = new HashSet<String>(Arrays.asList("externalGuarantor", "existingClientId", "firstname", "lastname",
|
||||
"addressLine1", "addressLine2", "city", "state", "zip", "country", "mobileNumber", "housePhoneNumber", "comment", "dob",
|
||||
"locale", "dateFormat"));
|
||||
|
||||
checkForUnsupportedParameters(requestMap, supportedParams);
|
||||
|
||||
Set<String> modifiedParameters = new HashSet<String>();
|
||||
|
||||
boolean externalGuarantor = extractBooleanParameter("externalGuarantor", requestMap, modifiedParameters);
|
||||
|
||||
Long existingClientId = extractLongParameter("existingClientId", requestMap, modifiedParameters);
|
||||
String firstname = extractStringParameter("firstname", requestMap, modifiedParameters);
|
||||
String lastname = extractStringParameter("lastname", requestMap, modifiedParameters);
|
||||
String addressLine1 = extractStringParameter("addressLine1", requestMap, modifiedParameters);
|
||||
String addressLine2 = extractStringParameter("addressLine2", requestMap, modifiedParameters);
|
||||
String city = extractStringParameter("city", requestMap, modifiedParameters);
|
||||
String state = extractStringParameter("state", requestMap, modifiedParameters);
|
||||
String zip = extractStringParameter("zip", requestMap, modifiedParameters);
|
||||
String country = extractStringParameter("country", requestMap, modifiedParameters);
|
||||
String mobileNumber = extractStringParameter("mobileNumber", requestMap, modifiedParameters);
|
||||
String housePhoneNumber = extractStringParameter("housePhoneNumber", requestMap, modifiedParameters);
|
||||
String comment = extractStringParameter("comment", requestMap, modifiedParameters);
|
||||
String dob = extractStringParameter("dob", requestMap, modifiedParameters);
|
||||
|
||||
// workaround for passing locale info to data table api
|
||||
final String dateFormat = requestMap.get("dateFormat");
|
||||
final String locale = requestMap.get("locale");
|
||||
|
||||
GuarantorCommand command = new GuarantorCommand(modifiedParameters, existingClientId, firstname, lastname, externalGuarantor,
|
||||
addressLine1, addressLine2, city, state, zip, country, mobileNumber, housePhoneNumber, comment, dob);
|
||||
command.setDateFormat(dateFormat);
|
||||
command.setLocale(locale);
|
||||
return command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavingStateTransitionsCommand convertJsonToSavingStateTransitionCommand( Long accountId, String json) {
|
||||
|
||||
@Override
|
||||
public SavingStateTransitionsCommand convertJsonToSavingStateTransitionCommand( Long accountId, String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
@@ -914,20 +872,20 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
String note = extractStringParameter("note", requestMap, modifiedParameters);
|
||||
|
||||
return new SavingStateTransitionsCommand(accountId, eventDate, note);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavingAccountApprovalCommand convertJsonToSavingApprovalCommand( Long accountId, String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
@Override
|
||||
public SavingAccountApprovalCommand convertJsonToSavingApprovalCommand( Long accountId, String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
Set<String> supportedParams = new HashSet<String>(Arrays.asList("locale", "dateFormat", "commencementDate", "savingsDepositAmountPerPeriod",
|
||||
"minimumBalanceForWithdrawal", "recurringInterestRate", "savingInterestRate", "interestType", "tenure", "tenureType", "frequency", "payEvery", "note",
|
||||
"interestPostEvery", "interestPostFrequency"));
|
||||
"minimumBalanceForWithdrawal", "recurringInterestRate", "savingInterestRate", "interestType", "tenure", "tenureType", "frequency", "payEvery", "note",
|
||||
"interestPostEvery", "interestPostFrequency"));
|
||||
|
||||
checkForUnsupportedParameters(requestMap, supportedParams);
|
||||
Set<String> modifiedParameters = new HashSet<String>();
|
||||
@@ -945,15 +903,15 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
String note = extractStringParameter("note", requestMap, modifiedParameters);
|
||||
Integer interestPostEvery = extractIntegerParameter("interestPostEvery", requestMap, modifiedParameters);
|
||||
Integer interestPostFrequency = extractIntegerParameter("interestPostFrequency", requestMap, modifiedParameters);
|
||||
return new SavingAccountApprovalCommand(accountId, commencementDate, savingsDepositAmountPerPeriod, minimumBalanceForWithdrawal, recurringInterestRate,
|
||||
savingInterestRate, interestType, tenure, tenureType, frequency, payEvery, note, interestPostEvery, interestPostFrequency);
|
||||
}
|
||||
return new SavingAccountApprovalCommand(accountId, commencementDate, savingsDepositAmountPerPeriod, minimumBalanceForWithdrawal, recurringInterestRate,
|
||||
savingInterestRate, interestType, tenure, tenureType, frequency, payEvery, note, interestPostEvery, interestPostFrequency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavingAccountDepositCommand convertJsonToSavingAccountDepositCommand(Long accountId, String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
@Override
|
||||
public SavingAccountDepositCommand convertJsonToSavingAccountDepositCommand(Long accountId, String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
Set<String> supportedParams = new HashSet<String>(Arrays.asList("locale", "dateFormat", "depositDate", "savingsDepositAmountPerPeriod", "note"));
|
||||
@@ -964,14 +922,14 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
LocalDate depositDate = extractLocalDateParameter("depositDate", requestMap, modifiedParameters);
|
||||
BigDecimal savingsDepositAmountPerPeriod = extractBigDecimalParameter("savingsDepositAmountPerPeriod", requestMap, modifiedParameters);
|
||||
String note = extractStringParameter("note", requestMap, modifiedParameters);
|
||||
return new SavingAccountDepositCommand(accountId, savingsDepositAmountPerPeriod, depositDate, note);
|
||||
}
|
||||
return new SavingAccountDepositCommand(accountId, savingsDepositAmountPerPeriod, depositDate, note);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavingAccountWithdrawalCommand convertJsonToSavingAccountWithdrawalCommand(Long accountId, String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
@Override
|
||||
public SavingAccountWithdrawalCommand convertJsonToSavingAccountWithdrawalCommand(Long accountId, String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
Set<String> supportedParams = new HashSet<String>(Arrays.asList("locale", "dateFormat", "transactionDate", "amount", "note"));
|
||||
@@ -982,6 +940,6 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
LocalDate transactionDate = extractLocalDateParameter("transactionDate", requestMap, modifiedParameters);
|
||||
BigDecimal amount = extractBigDecimalParameter("amount", requestMap, modifiedParameters);
|
||||
String note = extractStringParameter("note", requestMap, modifiedParameters);
|
||||
return new SavingAccountWithdrawalCommand(accountId, transactionDate, amount, note);
|
||||
}
|
||||
return new SavingAccountWithdrawalCommand(accountId, transactionDate, amount, note);
|
||||
}
|
||||
}
|
||||
-3
@@ -3,7 +3,6 @@ package org.mifosplatform.portfolio.savingsaccount;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData;
|
||||
import org.mifosplatform.portfolio.savingsaccount.data.SavingAccountData;
|
||||
import org.mifosplatform.portfolio.savingsaccount.data.SavingScheduleData;
|
||||
import org.mifosplatform.portfolio.savingsaccountproduct.data.SavingProductData;
|
||||
@@ -28,8 +27,6 @@ public interface PortfolioApiJsonSerializerService {
|
||||
|
||||
String serializeSavingAccountsDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<SavingAccountData> accounts);
|
||||
|
||||
String serializeGuarantorDataToJson(boolean prettyPrint, Set<String> responseParameters, GuarantorData guarantorData);
|
||||
|
||||
String serializeSavingScheduleDataToJson(boolean prettyPrint, Set<String> responseParameters, SavingScheduleData savingScheduleData);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user