diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/FundsApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/FundsApiResource.java index 62603571d..18376440d 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/FundsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/FundsApiResource.java @@ -69,7 +69,7 @@ public class FundsApiResource { @Path("{fundId}") @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) - public String retreiveOffice(@PathParam("fundId") final Long fundId, @Context UriInfo uriInfo) { + public String retreiveOffice(@PathParam("fundId") final Long fundId, @Context final UriInfo uriInfo) { Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ClientCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ClientCommand.java index 537dfbc09..31b37401c 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ClientCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ClientCommand.java @@ -56,7 +56,27 @@ public class ClientCommand { return joiningDate; } - public boolean isOfficeIdChanged() { + public boolean isFirstnameChanged() { + return this.modifiedParameters.contains("firstname"); + } + + public boolean isLastnameChanged() { + return this.modifiedParameters.contains("lastname"); + } + + public boolean isClientOrBusinessNameChanged() { + return this.modifiedParameters.contains("clientOrBusinessName"); + } + + public boolean isExternalIdChanged() { + return this.modifiedParameters.contains("externalId"); + } + + public boolean isJoiningDateChanged() { + return this.modifiedParameters.contains("joiningDate"); + } + + public boolean isOfficeChanged() { return this.modifiedParameters.contains("officeId"); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/ClientData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/ClientData.java index 9b3553f8b..ec42b13cd 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/ClientData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/ClientData.java @@ -9,12 +9,12 @@ import org.joda.time.LocalDate; public class ClientData { private final Long id; - private final Long officeId; - private final String officeName; private final String firstname; private final String lastname; private final String clientOrBusinessName; private final String displayName; + private final Long officeId; + private final String officeName; private final String externalId; private final LocalDate joinedDate; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/OfficeData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/OfficeData.java index b2f2ee3c2..b9cbf6354 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/OfficeData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/OfficeData.java @@ -13,8 +13,9 @@ public class OfficeData { private String externalId; private LocalDate openingDate; private String hierarchy; - private String parentName; private Long parentId; + private String parentName; + private List allowedParents = new ArrayList(); public OfficeData() { @@ -106,5 +107,4 @@ public class OfficeData { public void setAllowedParents(List allowedParents) { this.allowedParents = allowedParents; } - } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/client/domain/Client.java b/mifosng-provider/src/main/java/org/mifosng/platform/client/domain/Client.java index ced06f577..5e7683abf 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/client/domain/Client.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/client/domain/Client.java @@ -98,21 +98,27 @@ public class Client extends AbstractAuditableCustom { } } - public void update(Office clientOffice, String firstname, String lastname, String externalId, LocalDate joiningDate) { - if (clientOffice != null) { + public void update(final Office clientOffice, final ClientCommand command) { + if (command.isOfficeChanged()) { this.office = clientOffice; } - if (joiningDate != null) { - this.joiningDate = joiningDate.toDate(); + if (command.isJoiningDateChanged()) { + this.joiningDate = command.getJoiningDate().toDate(); } - if (StringUtils.isNotBlank(firstname)) { - this.firstName = firstname; + if (command.isFirstnameChanged()) { + this.firstName = command.getFirstname(); } - if (StringUtils.isNotBlank(lastname)) { - this.lastName = lastname; + if (command.isLastnameChanged()) { + this.lastName = command.getLastname(); } - if (externalId != null) { - this.externalId = externalId.trim(); + + if (command.isClientOrBusinessNameChanged()) { + this.lastName = command.getClientOrBusinessName(); + this.firstName = null; + } + + if (command.isExternalIdChanged()) { + this.externalId = StringUtils.defaultIfEmpty(externalId.trim(), null); } } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientCommandValidator.java index 6e7f7d18d..69c2b61a3 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientCommandValidator.java @@ -33,7 +33,7 @@ public class ClientCommandValidator { baseDataValidator.reset().parameter("joiningDate").value(command.getJoiningDate()).ignoreIfNull().notBlank(); baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).ignoreIfNull().notExceedingLengthOf(100); - if (command.isOfficeIdChanged()) { + if (command.isOfficeChanged()) { baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).notNull().greaterThanZero(); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java index 6cd59f88b..e6f35cd64 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java @@ -89,25 +89,18 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP Office clientOffice = null; Long officeId = command.getOfficeId(); - if (officeId != null) { + if (command.isOfficeChanged() && officeId != null) { clientOffice = this.officeRepository.findOne(officeId); if (clientOffice == null) { throw new OfficeNotFoundException(command.getOfficeId()); } } - String firstname = command.getFirstname(); - String lastname = command.getLastname(); - if (StringUtils.isNotBlank(command.getClientOrBusinessName())) { - lastname = command.getClientOrBusinessName(); - firstname = null; - } - Client clientForUpdate = this.clientRepository.findOne(command.getId()); if (clientForUpdate == null || clientForUpdate.isDeleted()) { throw new ClientNotFoundException(command.getId()); } - clientForUpdate.update(clientOffice, firstname, lastname, command.getExternalId(), command.getJoiningDate()); + clientForUpdate.update(clientOffice, command); this.clientRepository.save(clientForUpdate); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductCommandValidator.java index 18b26078f..889dbc47c 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductCommandValidator.java @@ -43,7 +43,7 @@ public class LoanProductCommandValidator { baseDataValidator.reset().parameter("interestType").value(command.getInterestType()).ignoreIfNull().notNull().inMinMaxRange(0, 1); baseDataValidator.reset().parameter("interestCalculationPeriodType").value(command.getInterestCalculationPeriodType()).ignoreIfNull().notNull().inMinMaxRange(0, 1); - baseDataValidator.reset().anyOfNotNull(command.getFundId(), command.getName(), command.getDescription(), command.getCurrencyCode(), command.getDigitsAfterDecimal(), + baseDataValidator.reset().anyOfNotNull(command.getFundId(), command.getTransactionProcessingStrategyId(), command.getName(), command.getDescription(), command.getCurrencyCode(), command.getDigitsAfterDecimal(), command.getPrincipal(), command.getInArrearsTolerance(), command.getRepaymentFrequencyType(), command.getRepaymentEvery(), command.getNumberOfRepayments(), command.getInterestRatePerPeriod(), command.getInterestRateFrequencyType(), command.getAmortizationType(), command.getInterestType(), command.getInterestCalculationPeriodType()); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java index c7679359c..6a7707661 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java @@ -121,8 +121,15 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro } // associating fund with loan product at creation is optional for now. - Fund fund = findFundByIdIfProvided(command.getFundId()); - LoanTransactionProcessingStrategy loanTransactionProcessingStrategy = findStrategyByIdIfProvided(command.getTransactionProcessingStrategyId()); + Fund fund = null; + if (command.isFundChanged()) { + fund = findFundByIdIfProvided(command.getFundId()); + } + + LoanTransactionProcessingStrategy loanTransactionProcessingStrategy = null; + if (command.isTransactionProcessingStrategyChanged()) { + findStrategyByIdIfProvided(command.getTransactionProcessingStrategyId()); + } product.update(command, fund, loanTransactionProcessingStrategy);