support client update properly and tidy up parameter names for client.
This commit is contained in:
@@ -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 {
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package org.mifosng.platform.api.commands;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
@XmlRootElement
|
||||
public class ClientCommand {
|
||||
|
||||
private Long id;
|
||||
private String firstname;
|
||||
private String lastname;
|
||||
private String clientOrBusinessName;
|
||||
private Long officeId;
|
||||
private String externalId;
|
||||
|
||||
private String dateFormat;
|
||||
private String joiningDate;
|
||||
private LocalDate joiningLocalDate;
|
||||
|
||||
protected ClientCommand() {
|
||||
//
|
||||
}
|
||||
|
||||
public ClientCommand(final String firstname, final String lastname, final String clientOrBusinessName, final Long officeId, final LocalDate joiningDate) {
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.clientOrBusinessName = clientOrBusinessName;
|
||||
this.officeId = officeId;
|
||||
this.joiningLocalDate = joiningDate;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return this.firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(final String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return this.lastname;
|
||||
}
|
||||
|
||||
public void setLastname(final String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public Long getOfficeId() {
|
||||
return this.officeId;
|
||||
}
|
||||
|
||||
public void setOfficeId(final Long officeId) {
|
||||
this.officeId = officeId;
|
||||
}
|
||||
|
||||
public String getExternalId() {
|
||||
return externalId;
|
||||
}
|
||||
|
||||
public void setExternalId(String externalId) {
|
||||
this.externalId = externalId;
|
||||
}
|
||||
|
||||
public String getDateFormat() {
|
||||
return dateFormat;
|
||||
}
|
||||
|
||||
public void setDateFormat(String dateFormat) {
|
||||
this.dateFormat = dateFormat;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package org.mifosng.platform.api.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
|
||||
@XmlRootElement
|
||||
public class ImportClientCommand {
|
||||
|
||||
private List<ClientCommand> clients = new ArrayList<ClientCommand>();
|
||||
|
||||
public ImportClientCommand() {
|
||||
//
|
||||
}
|
||||
|
||||
public List<ClientCommand> getClients() {
|
||||
return clients;
|
||||
}
|
||||
|
||||
public void setClients(List<ClientCommand> clients) {
|
||||
this.clients = clients;
|
||||
}
|
||||
}
|
||||
@@ -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<AppUser, Long> {
|
||||
}
|
||||
|
||||
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<AppUser, Long> {
|
||||
if (StringUtils.isNotBlank(firstname)) {
|
||||
this.firstName = firstname;
|
||||
}
|
||||
if (StringUtils.isNotBlank(firstname)) {
|
||||
if (StringUtils.isNotBlank(lastname)) {
|
||||
this.lastName = lastname;
|
||||
}
|
||||
if (externalId != null) {
|
||||
|
||||
+13
-10
@@ -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();
|
||||
|
||||
|
||||
+5
-5
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
+16
-12
@@ -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);
|
||||
|
||||
|
||||
+3
@@ -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);
|
||||
}
|
||||
+3
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user