From 1450e38f7b2189edf930f809c6e6b14859dbd745 Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Tue, 29 May 2012 14:45:20 +0100 Subject: [PATCH] support client update properly and tidy up parameter names for client. --- .../global-translations/messages.properties | 9 ++- .../messages_fr.properties | 7 +-- .../webapp/WEB-INF/views/view-templates.jsp | 8 +-- .../platform/ImportPlatformService.java | 2 +- .../platform/ImportPlatformServiceImpl.java | 6 +- .../platform/api/ClientApiResource.java | 14 ++--- .../platform/api/commands}/ClientCommand.java | 62 +++++++++---------- .../api/commands}/ImportClientCommand.java | 3 +- .../platform/client/domain/Client.java | 10 +-- .../service/ClientCommandValidator.java | 23 ++++--- .../service/ClientWritePlatformService.java | 10 +-- ...WritePlatformServiceJpaRepositoryImpl.java | 28 +++++---- .../LoanProductWritePlatformService.java | 3 + .../service/OfficeWritePlatformService.java | 3 + .../mifosng/platform/rest/ImportResource.java | 2 +- .../platform/rest/ImportTriggerResource.java | 2 +- 16 files changed, 102 insertions(+), 90 deletions(-) rename {mifosng-data/src/main/java/org/mifosng/data/command => mifosng-provider/src/main/java/org/mifosng/platform/api/commands}/ClientCommand.java (62%) rename {mifosng-data/src/main/java/org/mifosng/data/command => mifosng-provider/src/main/java/org/mifosng/platform/api/commands}/ImportClientCommand.java (90%) diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages.properties b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages.properties index 4ddd7ec19..686ed5e96 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages.properties +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages.properties @@ -25,17 +25,16 @@ label.office=Office: option.office.first.choice=--Select Office-- label.lastname=Last name: label.firstname=First name: -label.longname=Full name: +label.longname=Client or Business name: label.joiningdate=Joining date: error.msg.header=You have the following errors: validation.msg.client.officeId.cannot.be.blank=A client must be associated with an office. validation.msg.client.firstname.cannot.be.blank=First name cannot be blank. validation.msg.client.lastname.cannot.be.blank=Last name cannot be blank. -validation.msg.client.joiningDateFormatted.cannot.be.blank=Joining date cannot be blank. -validation.msg.client.fullname.must.be.provide.or.firstname.lastname=A fullname must be provided or else both firstname and lastname details. -validation.msg.client.firstname.cannot.also.be.provided.when.fullname.is.populated=You cannot provide both fullname and firstname or lastname details. A fullname must be provided or else both firstname and lastname details. -validation.msg.client.lastname.cannot.also.be.provided.when.fullname.is.populated=You cannot provide both fullname and firstname or lastname details. A fullname must be provided or else both firstname and lastname details. +validation.msg.client.joiningDate.cannot.be.blank=Joining date cannot be blank. +validation.msg.client.firstname.cannot.also.be.provided.when.clientOrBusinessName.is.populated=You cannot provide both fullname and firstname or lastname details. A fullname must be provided or else both firstname and lastname details. +validation.msg.client.lastname.cannot.also.be.provided.when.clientOrBusinessName.is.populated=You cannot provide both fullname and firstname or lastname details. A fullname must be provided or else both firstname and lastname details. error.msg.client.id.invalid=Client does not exist. error.msg.office.id.invalid=Office does not exist. diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages_fr.properties b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages_fr.properties index 00b3958c6..512c56c70 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages_fr.properties +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages_fr.properties @@ -31,10 +31,9 @@ error.msg.header=You have the following errors:(fr) validation.msg.client.officeId.cannot.be.blank=A client must be associated with an office.(fr) validation.msg.client.firstname.cannot.be.blank=First name cannot be blank.(fr) validation.msg.client.lastname.cannot.be.blank=Last name cannot be blank.(fr) -validation.msg.client.joiningDateFormatted.cannot.be.blank=Joining date cannot be blank.(fr) -validation.msg.client.fullname.must.be.provide.or.firstname.lastname=A fullname must be provided or else both firstname and lastname details.(fr) -validation.msg.client.firstname.cannot.also.be.provided.when.fullname.is.populated=You cannot provide both fullname and firstname or lastname details. A fullname must be provided or else both firstname and lastname details.(fr) -validation.msg.client.lastname.cannot.also.be.provided.when.fullname.is.populated=You cannot provide both fullname and firstname or lastname details. A fullname must be provided or else both firstname and lastname details.(fr) +validation.msg.client.joiningDate.cannot.be.blank=Joining date cannot be blank.(fr) +validation.msg.client.firstname.cannot.also.be.provided.when.clientOrBusinessName.is.populated=You cannot provide both fullname and firstname or lastname details. A fullname must be provided or else both firstname and lastname details.(fr) +validation.msg.client.lastname.cannot.also.be.provided.when.clientOrBusinessName.is.populated=You cannot provide both fullname and firstname or lastname details. A fullname must be provided or else both firstname and lastname details.(fr) error.msg.client.id.invalid=Client does not exist.(fr) error.msg.office.id.invalid=Office does not exist.(fr) diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/view-templates.jsp b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/view-templates.jsp index d83ec000a..de37ba7ea 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/view-templates.jsp +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/view-templates.jsp @@ -350,15 +350,15 @@ - - + + - - + + diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformService.java index 1b31bd83f..a09dd6b14 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformService.java @@ -1,8 +1,8 @@ package org.mifosng.platform; -import org.mifosng.data.command.ImportClientCommand; import org.mifosng.data.command.ImportLoanCommand; import org.mifosng.data.command.ImportLoanRepaymentsCommand; +import org.mifosng.platform.api.commands.ImportClientCommand; public interface ImportPlatformService { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformServiceImpl.java index d26160d4f..9295d8bd0 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/ImportPlatformServiceImpl.java @@ -22,14 +22,14 @@ import org.mifosng.data.LoanSchedule; import org.mifosng.data.MoneyData; import org.mifosng.data.ScheduledLoanInstallment; import org.mifosng.data.command.CalculateLoanScheduleCommand; -import org.mifosng.data.command.ClientCommand; -import org.mifosng.data.command.ImportClientCommand; import org.mifosng.data.command.ImportLoanCommand; import org.mifosng.data.command.ImportLoanRepaymentsCommand; import org.mifosng.data.command.LoanStateTransitionCommand; import org.mifosng.data.command.LoanTransactionCommand; import org.mifosng.data.command.SubmitApproveDisburseLoanCommand; import org.mifosng.data.command.SubmitLoanApplicationCommand; +import org.mifosng.platform.api.commands.ClientCommand; +import org.mifosng.platform.api.commands.ImportClientCommand; import org.mifosng.platform.client.domain.Client; import org.mifosng.platform.client.domain.ClientRepository; import org.mifosng.platform.currency.domain.MonetaryCurrency; @@ -118,7 +118,7 @@ public class ImportPlatformServiceImpl implements ImportPlatformService { for (ClientCommand client : command.getClients()) { Office clientOffice = findById(allOffices, client.getOfficeId()); - Client newClient = Client.newClient(currentUser.getOrganisation(), clientOffice, client.getFirstname(), client.getLastname(), client.getJoiningDate(), client.getExternalId()); + Client newClient = Client.newClient(currentUser.getOrganisation(), clientOffice, client.getFirstname(), client.getLastname(), client.getJoiningLocalDate(), client.getExternalId()); newClientCollection.add(newClient); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientApiResource.java index a2a90e8dc..05c9be598 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientApiResource.java @@ -22,8 +22,8 @@ import org.mifosng.data.ClientLoanAccountSummaryCollectionData; import org.mifosng.data.EntityIdentifier; import org.mifosng.data.NoteData; import org.mifosng.data.OfficeLookup; -import org.mifosng.data.command.ClientCommand; import org.mifosng.data.command.NoteCommand; +import org.mifosng.platform.api.commands.ClientCommand; import org.mifosng.platform.api.infrastructure.ApiDataConversionService; import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService; import org.mifosng.platform.client.service.ClientReadPlatformService; @@ -112,10 +112,10 @@ public class ClientApiResource { @Produces({ MediaType.APPLICATION_JSON }) public Response enrollClient(final ClientCommand command) { - LocalDate joiningDate = apiDataConversionService.convertFrom( - command.getJoiningDateFormatted(), "joiningDateFormatted", + LocalDate joiningLocalDate = apiDataConversionService.convertFrom( + command.getJoiningDate(), "joiningDate", command.getDateFormat()); - command.setJoiningDate(joiningDate); + command.setJoiningLocalDate(joiningLocalDate); Long clientId = this.clientWritePlatformService.enrollClient(command); @@ -129,10 +129,10 @@ public class ClientApiResource { public Response updateClient(@PathParam("clientId") final Long clientId, final ClientCommand command) { - LocalDate joiningDate = apiDataConversionService.convertFrom( - command.getJoiningDateFormatted(), "joiningDateFormatted", + LocalDate joiningLocalDate = apiDataConversionService.convertFrom( + command.getJoiningDate(), "joiningDate", command.getDateFormat()); - command.setJoiningDate(joiningDate); + command.setJoiningLocalDate(joiningLocalDate); command.setId(clientId); EntityIdentifier identifier = this.clientWritePlatformService diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/ClientCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ClientCommand.java similarity index 62% rename from mifosng-data/src/main/java/org/mifosng/data/command/ClientCommand.java rename to mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ClientCommand.java index 2e563a4ca..a9ee8beb2 100644 --- a/mifosng-data/src/main/java/org/mifosng/data/command/ClientCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ClientCommand.java @@ -1,4 +1,4 @@ -package org.mifosng.data.command; +package org.mifosng.platform.api.commands; import javax.xml.bind.annotation.XmlRootElement; @@ -10,24 +10,24 @@ public class ClientCommand { private Long id; private String firstname; private String lastname; - private String fullname; + private String clientOrBusinessName; private Long officeId; private String externalId; private String dateFormat; - private String joiningDateFormatted; - private LocalDate joiningDate; + private String joiningDate; + private LocalDate joiningLocalDate; protected ClientCommand() { // } - public ClientCommand(final String firstname, final String lastname, String fullname, final Long officeId, final LocalDate joiningDate) { + public ClientCommand(final String firstname, final String lastname, final String clientOrBusinessName, final Long officeId, final LocalDate joiningDate) { this.firstname = firstname; this.lastname = lastname; - this.fullname = fullname; + this.clientOrBusinessName = clientOrBusinessName; this.officeId = officeId; - this.joiningDate = joiningDate; + this.joiningLocalDate = joiningDate; } public String getFirstname() { @@ -54,14 +54,6 @@ public class ClientCommand { this.officeId = officeId; } - public LocalDate getJoiningDate() { - return this.joiningDate; - } - - public void setJoiningDate(final LocalDate joiningDate) { - this.joiningDate = joiningDate; - } - public String getExternalId() { return externalId; } @@ -70,14 +62,6 @@ public class ClientCommand { this.externalId = externalId; } - public String getFullname() { - return fullname; - } - - public void setFullname(String fullname) { - this.fullname = fullname; - } - public String getDateFormat() { return dateFormat; } @@ -86,14 +70,6 @@ public class ClientCommand { this.dateFormat = dateFormat; } - public String getJoiningDateFormatted() { - return joiningDateFormatted; - } - - public void setJoiningDateFormatted(String joiningDateFormatted) { - this.joiningDateFormatted = joiningDateFormatted; - } - public Long getId() { return id; } @@ -101,4 +77,28 @@ public class ClientCommand { public void setId(Long id) { this.id = id; } + + public String getJoiningDate() { + return joiningDate; + } + + public void setJoiningDate(String joiningDate) { + this.joiningDate = joiningDate; + } + + public LocalDate getJoiningLocalDate() { + return joiningLocalDate; + } + + public void setJoiningLocalDate(LocalDate joiningLocalDate) { + this.joiningLocalDate = joiningLocalDate; + } + + public String getClientOrBusinessName() { + return clientOrBusinessName; + } + + public void setClientOrBusinessName(String clientOrBusinessName) { + this.clientOrBusinessName = clientOrBusinessName; + } } \ No newline at end of file diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/ImportClientCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ImportClientCommand.java similarity index 90% rename from mifosng-data/src/main/java/org/mifosng/data/command/ImportClientCommand.java rename to mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ImportClientCommand.java index 5f57f7145..f520bb979 100644 --- a/mifosng-data/src/main/java/org/mifosng/data/command/ImportClientCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/ImportClientCommand.java @@ -1,10 +1,11 @@ -package org.mifosng.data.command; +package org.mifosng.platform.api.commands; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlRootElement; + @XmlRootElement public class ImportClientCommand { 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 4d89af70d..b7116faa8 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 @@ -13,7 +13,7 @@ import javax.persistence.UniqueConstraint; import org.apache.commons.lang.StringUtils; import org.joda.time.LocalDate; -import org.mifosng.data.command.ClientCommand; +import org.mifosng.platform.api.commands.ClientCommand; import org.mifosng.platform.infrastructure.AbstractAuditableCustom; import org.mifosng.platform.organisation.domain.Office; import org.mifosng.platform.organisation.domain.Organisation; @@ -88,13 +88,13 @@ public class Client extends AbstractAuditableCustom { } public void update(ClientCommand command) { - this.joiningDate = command.getJoiningDate().toDate(); + this.joiningDate = command.getJoiningLocalDate().toDate(); this.firstName = command.getFirstname(); this.lastName = command.getLastname(); - if (StringUtils.isNotBlank(command.getFullname())) { + if (StringUtils.isNotBlank(command.getClientOrBusinessName())) { this.firstName = null; - this.lastName = command.getFullname().trim(); + this.lastName = command.getClientOrBusinessName().trim(); } if (StringUtils.isNotBlank(command.getExternalId())) { @@ -114,7 +114,7 @@ public class Client extends AbstractAuditableCustom { if (StringUtils.isNotBlank(firstname)) { this.firstName = firstname; } - if (StringUtils.isNotBlank(firstname)) { + if (StringUtils.isNotBlank(lastname)) { this.lastName = lastname; } if (externalId != 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 0c3ef432a..09b6ef64d 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 @@ -5,8 +5,8 @@ import java.util.List; import org.apache.commons.lang.StringUtils; import org.mifosng.data.ApiParameterError; -import org.mifosng.data.command.ClientCommand; import org.mifosng.platform.DataValidatorBuilder; +import org.mifosng.platform.api.commands.ClientCommand; import org.mifosng.platform.exceptions.PlatformApiDataValidationException; public class ClientCommandValidator { @@ -22,18 +22,21 @@ public class ClientCommandValidator { DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("client"); - if (command.getFullname() != null && StringUtils.isNotBlank(command.getFullname())) { - baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).mustBeBlankWhenParameterProvided("fullname", command.getFullname()); - baseDataValidator.reset().parameter("lastname").value(command.getLastname()).mustBeBlankWhenParameterProvided("fullname", command.getFullname()); - } else if (StringUtils.isBlank(command.getFullname())) { + if (command.getClientOrBusinessName() != null && StringUtils.isNotBlank(command.getClientOrBusinessName())) { + baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).mustBeBlankWhenParameterProvided("clientOrBusinessName", command.getClientOrBusinessName()); + baseDataValidator.reset().parameter("lastname").value(command.getLastname()).mustBeBlankWhenParameterProvided("clientOrBusinessName", command.getClientOrBusinessName()); + } else if (StringUtils.isBlank(command.getClientOrBusinessName())) { baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).ignoreIfNull().notBlank(); baseDataValidator.reset().parameter("lastname").value(command.getLastname()).ignoreIfNull().notBlank(); } - baseDataValidator.reset().parameter("joiningDateFormatted").value(command.getJoiningDateFormatted()).ignoreIfNull().notBlank(); + baseDataValidator.reset().parameter("joiningDate").value(command.getJoiningDate()).ignoreIfNull().notBlank(); baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).ignoreIfNull().notExceedingLengthOf(100); baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).ignoreIfNull().notNull().greaterThanZero(); + baseDataValidator.reset().anyOfNotNull(command.getFirstname(), command.getLastname(), command.getClientOrBusinessName(), + command.getJoiningLocalDate(), command.getExternalId(), command.getOfficeId()); + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } @@ -44,15 +47,15 @@ public class ClientCommandValidator { DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("client"); - if (StringUtils.isNotBlank(command.getFullname())) { - baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).mustBeBlankWhenParameterProvided("fullname", command.getFullname()); - baseDataValidator.reset().parameter("lastname").value(command.getLastname()).mustBeBlankWhenParameterProvided("fullname", command.getFullname()); + if (StringUtils.isNotBlank(command.getClientOrBusinessName())) { + baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).mustBeBlankWhenParameterProvided("clientOrBusinessName", command.getClientOrBusinessName()); + baseDataValidator.reset().parameter("lastname").value(command.getLastname()).mustBeBlankWhenParameterProvided("clientOrBusinessName", command.getClientOrBusinessName()); } else { baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).notBlank(); baseDataValidator.reset().parameter("lastname").value(command.getLastname()).notBlank(); } - baseDataValidator.reset().parameter("joiningDateFormatted").value(command.getJoiningDateFormatted()).notBlank(); + baseDataValidator.reset().parameter("joiningDate").value(command.getJoiningDate()).notBlank(); baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).notExceedingLengthOf(100); baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).notNull().greaterThanZero(); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformService.java index 8715b9458..832df6489 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformService.java @@ -1,8 +1,8 @@ package org.mifosng.platform.client.service; import org.mifosng.data.EntityIdentifier; -import org.mifosng.data.command.ClientCommand; import org.mifosng.data.command.NoteCommand; +import org.mifosng.platform.api.commands.ClientCommand; import org.springframework.security.access.prepost.PreAuthorize; public interface ClientWritePlatformService { @@ -10,12 +10,12 @@ public interface ClientWritePlatformService { @PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE', 'CAN_ENROLL_NEW_CLIENT_ROLE')") Long enrollClient(ClientCommand command); + @PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE')") EntityIdentifier updateClientDetails(ClientCommand command); - - // FIXME - add permission for adding and updating client notes. + + @PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE')") EntityIdentifier addClientNote(NoteCommand command); + @PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE')") EntityIdentifier updateNote(NoteCommand command); - - } \ No newline at end of file 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 e4ea833dd..fc82c2d25 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 @@ -6,8 +6,8 @@ import static org.mifosng.platform.Specifications.officesThatMatch; import org.apache.commons.lang.StringUtils; import org.mifosng.data.EntityIdentifier; -import org.mifosng.data.command.ClientCommand; import org.mifosng.data.command.NoteCommand; +import org.mifosng.platform.api.commands.ClientCommand; import org.mifosng.platform.client.domain.Client; import org.mifosng.platform.client.domain.ClientRepository; import org.mifosng.platform.client.domain.Note; @@ -56,12 +56,12 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP String firstname = command.getFirstname(); String lastname = command.getLastname(); - if (StringUtils.isNotBlank(command.getFullname())) { - lastname = command.getFullname(); + if (StringUtils.isNotBlank(command.getClientOrBusinessName())) { + lastname = command.getClientOrBusinessName(); firstname = null; } - Client newClient = Client.newClient(currentUser.getOrganisation(), clientOffice, firstname, lastname, command.getJoiningDate(), command.getExternalId()); + Client newClient = Client.newClient(currentUser.getOrganisation(), clientOffice, firstname, lastname, command.getJoiningLocalDate(), command.getExternalId()); this.clientRepository.save(newClient); @@ -76,16 +76,20 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP ClientCommandValidator validator = new ClientCommandValidator(command); validator.validateForUpdate(); - - Office clientOffice = this.officeRepository.findOne(officesThatMatch(currentUser.getOrganisation(), command.getOfficeId())); - if (clientOffice == null) { - throw new OfficeNotFoundException(command.getOfficeId()); - } + Office clientOffice = null; + Long officeId = command.getOfficeId(); + if (officeId != null) { + clientOffice = this.officeRepository.findOne(officesThatMatch(currentUser.getOrganisation(), officeId)); + if (clientOffice == null) { + throw new OfficeNotFoundException(command.getOfficeId()); + } + } + String firstname = command.getFirstname(); String lastname = command.getLastname(); - if (StringUtils.isNotBlank(command.getFullname())) { - lastname = command.getFullname(); + if (StringUtils.isNotBlank(command.getClientOrBusinessName())) { + lastname = command.getClientOrBusinessName(); firstname = null; } @@ -93,7 +97,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP if (clientForUpdate == null) { throw new ClientNotFoundException(command.getId()); } - clientForUpdate.update(clientOffice, firstname, lastname, command.getExternalId(), command.getJoiningDate()); + clientForUpdate.update(clientOffice, firstname, lastname, command.getExternalId(), command.getJoiningLocalDate()); this.clientRepository.save(clientForUpdate); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformService.java index 5aba7d534..2bc61a8ef 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformService.java @@ -2,10 +2,13 @@ package org.mifosng.platform.loanproduct.service; import org.mifosng.data.EntityIdentifier; import org.mifosng.platform.api.commands.LoanProductCommand; +import org.springframework.security.access.prepost.PreAuthorize; public interface LoanProductWritePlatformService { + @PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')") EntityIdentifier createLoanProduct(LoanProductCommand command); + @PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')") EntityIdentifier updateLoanProduct(LoanProductCommand command); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeWritePlatformService.java index c1ed08257..e6a347dc6 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeWritePlatformService.java @@ -1,10 +1,13 @@ package org.mifosng.platform.organisation.service; import org.mifosng.platform.api.commands.OfficeCommand; +import org.springframework.security.access.prepost.PreAuthorize; public interface OfficeWritePlatformService { + @PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')") Long createOffice(final OfficeCommand command); + @PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')") Long updateOffice(final OfficeCommand command); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportResource.java index d1a16ff7f..db30e3aec 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportResource.java @@ -7,10 +7,10 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.mifosng.data.command.ImportClientCommand; import org.mifosng.data.command.ImportLoanCommand; import org.mifosng.data.command.ImportLoanRepaymentsCommand; import org.mifosng.platform.ImportPlatformService; +import org.mifosng.platform.api.commands.ImportClientCommand; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportTriggerResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportTriggerResource.java index 881ebfb90..531026ffa 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportTriggerResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ImportTriggerResource.java @@ -7,10 +7,10 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.mifosng.data.command.ImportClientCommand; import org.mifosng.data.command.ImportLoanCommand; import org.mifosng.data.command.ImportLoanRepaymentsCommand; import org.mifosng.platform.ImportPlatformService; +import org.mifosng.platform.api.commands.ImportClientCommand; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component;