support client update properly and tidy up parameter names for client.

This commit is contained in:
Keith Woodlock
2012-05-29 14:45:20 +01:00
parent d413aadb4a
commit 1450e38f7b
16 changed files with 102 additions and 90 deletions
@@ -25,17 +25,16 @@ label.office=Office:
option.office.first.choice=--Select Office-- option.office.first.choice=--Select Office--
label.lastname=Last name: label.lastname=Last name:
label.firstname=First name: label.firstname=First name:
label.longname=Full name: label.longname=Client or Business name:
label.joiningdate=Joining date: label.joiningdate=Joining date:
error.msg.header=You have the following errors: 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.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.firstname.cannot.be.blank=First name cannot be blank.
validation.msg.client.lastname.cannot.be.blank=Last 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.joiningDate.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.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.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.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.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.
error.msg.client.id.invalid=Client does not exist. error.msg.client.id.invalid=Client does not exist.
error.msg.office.id.invalid=Office does not exist. error.msg.office.id.invalid=Office does not exist.
@@ -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.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.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.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.joiningDate.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.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.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.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.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)
error.msg.client.id.invalid=Client does not exist.(fr) error.msg.client.id.invalid=Client does not exist.(fr)
error.msg.office.id.invalid=Office does not exist.(fr) error.msg.office.id.invalid=Office does not exist.(fr)
@@ -350,15 +350,15 @@
<tr> <tr>
<tr> <tr>
<td colspan="2"> <td colspan="2">
<label for="fullname"><spring:message code="label.longname"/></label> <label for="clientOrBusinessName"><spring:message code="label.longname"/></label>
<input id="fullname" name="fullname" title="" type="text" value="{{=fullname}}" style="width:100%"/> <input id="clientOrBusinessName" name="clientOrBusinessName" title="" type="text" value="{{=fullname}}" style="width:100%"/>
</td> </td>
</tr> </tr>
</table> </table>
<input type="hidden" id="dateFormat" name="dateFormat" value="dd MMMM yyyy" /> <input type="hidden" id="dateFormat" name="dateFormat" value="dd MMMM yyyy" />
<label for="joiningDateFormatted"><spring:message code="label.joiningdate"/></label> <label for="joiningDate"><spring:message code="label.joiningdate"/></label>
<input id="joiningDateFormatted" name="joiningDateFormatted" title="" type="text" class="datepickerfield" value="{{=$ctx.globalDate(joinedDate)}}"/> <input id="joiningDate" name="joiningDate" title="" type="text" class="datepickerfield" value="{{=$ctx.globalDate(joinedDate)}}"/>
</form> </form>
</script> </script>
@@ -1,8 +1,8 @@
package org.mifosng.platform; package org.mifosng.platform;
import org.mifosng.data.command.ImportClientCommand;
import org.mifosng.data.command.ImportLoanCommand; import org.mifosng.data.command.ImportLoanCommand;
import org.mifosng.data.command.ImportLoanRepaymentsCommand; import org.mifosng.data.command.ImportLoanRepaymentsCommand;
import org.mifosng.platform.api.commands.ImportClientCommand;
public interface ImportPlatformService { public interface ImportPlatformService {
@@ -22,14 +22,14 @@ import org.mifosng.data.LoanSchedule;
import org.mifosng.data.MoneyData; import org.mifosng.data.MoneyData;
import org.mifosng.data.ScheduledLoanInstallment; import org.mifosng.data.ScheduledLoanInstallment;
import org.mifosng.data.command.CalculateLoanScheduleCommand; 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.ImportLoanCommand;
import org.mifosng.data.command.ImportLoanRepaymentsCommand; import org.mifosng.data.command.ImportLoanRepaymentsCommand;
import org.mifosng.data.command.LoanStateTransitionCommand; import org.mifosng.data.command.LoanStateTransitionCommand;
import org.mifosng.data.command.LoanTransactionCommand; import org.mifosng.data.command.LoanTransactionCommand;
import org.mifosng.data.command.SubmitApproveDisburseLoanCommand; import org.mifosng.data.command.SubmitApproveDisburseLoanCommand;
import org.mifosng.data.command.SubmitLoanApplicationCommand; 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.Client;
import org.mifosng.platform.client.domain.ClientRepository; import org.mifosng.platform.client.domain.ClientRepository;
import org.mifosng.platform.currency.domain.MonetaryCurrency; import org.mifosng.platform.currency.domain.MonetaryCurrency;
@@ -118,7 +118,7 @@ public class ImportPlatformServiceImpl implements ImportPlatformService {
for (ClientCommand client : command.getClients()) { for (ClientCommand client : command.getClients()) {
Office clientOffice = findById(allOffices, client.getOfficeId()); 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); newClientCollection.add(newClient);
} }
@@ -22,8 +22,8 @@ import org.mifosng.data.ClientLoanAccountSummaryCollectionData;
import org.mifosng.data.EntityIdentifier; import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.NoteData; import org.mifosng.data.NoteData;
import org.mifosng.data.OfficeLookup; import org.mifosng.data.OfficeLookup;
import org.mifosng.data.command.ClientCommand;
import org.mifosng.data.command.NoteCommand; 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.ApiDataConversionService;
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService; import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
import org.mifosng.platform.client.service.ClientReadPlatformService; import org.mifosng.platform.client.service.ClientReadPlatformService;
@@ -112,10 +112,10 @@ public class ClientApiResource {
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public Response enrollClient(final ClientCommand command) { public Response enrollClient(final ClientCommand command) {
LocalDate joiningDate = apiDataConversionService.convertFrom( LocalDate joiningLocalDate = apiDataConversionService.convertFrom(
command.getJoiningDateFormatted(), "joiningDateFormatted", command.getJoiningDate(), "joiningDate",
command.getDateFormat()); command.getDateFormat());
command.setJoiningDate(joiningDate); command.setJoiningLocalDate(joiningLocalDate);
Long clientId = this.clientWritePlatformService.enrollClient(command); Long clientId = this.clientWritePlatformService.enrollClient(command);
@@ -129,10 +129,10 @@ public class ClientApiResource {
public Response updateClient(@PathParam("clientId") final Long clientId, public Response updateClient(@PathParam("clientId") final Long clientId,
final ClientCommand command) { final ClientCommand command) {
LocalDate joiningDate = apiDataConversionService.convertFrom( LocalDate joiningLocalDate = apiDataConversionService.convertFrom(
command.getJoiningDateFormatted(), "joiningDateFormatted", command.getJoiningDate(), "joiningDate",
command.getDateFormat()); command.getDateFormat());
command.setJoiningDate(joiningDate); command.setJoiningLocalDate(joiningLocalDate);
command.setId(clientId); command.setId(clientId);
EntityIdentifier identifier = this.clientWritePlatformService EntityIdentifier identifier = this.clientWritePlatformService
@@ -1,4 +1,4 @@
package org.mifosng.data.command; package org.mifosng.platform.api.commands;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
@@ -10,24 +10,24 @@ public class ClientCommand {
private Long id; private Long id;
private String firstname; private String firstname;
private String lastname; private String lastname;
private String fullname; private String clientOrBusinessName;
private Long officeId; private Long officeId;
private String externalId; private String externalId;
private String dateFormat; private String dateFormat;
private String joiningDateFormatted; private String joiningDate;
private LocalDate joiningDate; private LocalDate joiningLocalDate;
protected ClientCommand() { 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.firstname = firstname;
this.lastname = lastname; this.lastname = lastname;
this.fullname = fullname; this.clientOrBusinessName = clientOrBusinessName;
this.officeId = officeId; this.officeId = officeId;
this.joiningDate = joiningDate; this.joiningLocalDate = joiningDate;
} }
public String getFirstname() { public String getFirstname() {
@@ -54,14 +54,6 @@ public class ClientCommand {
this.officeId = officeId; this.officeId = officeId;
} }
public LocalDate getJoiningDate() {
return this.joiningDate;
}
public void setJoiningDate(final LocalDate joiningDate) {
this.joiningDate = joiningDate;
}
public String getExternalId() { public String getExternalId() {
return externalId; return externalId;
} }
@@ -70,14 +62,6 @@ public class ClientCommand {
this.externalId = externalId; this.externalId = externalId;
} }
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getDateFormat() { public String getDateFormat() {
return dateFormat; return dateFormat;
} }
@@ -86,14 +70,6 @@ public class ClientCommand {
this.dateFormat = dateFormat; this.dateFormat = dateFormat;
} }
public String getJoiningDateFormatted() {
return joiningDateFormatted;
}
public void setJoiningDateFormatted(String joiningDateFormatted) {
this.joiningDateFormatted = joiningDateFormatted;
}
public Long getId() { public Long getId() {
return id; return id;
} }
@@ -101,4 +77,28 @@ public class ClientCommand {
public void setId(Long id) { public void setId(Long id) {
this.id = 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;
}
} }
@@ -1,10 +1,11 @@
package org.mifosng.data.command; package org.mifosng.platform.api.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement @XmlRootElement
public class ImportClientCommand { public class ImportClientCommand {
@@ -13,7 +13,7 @@ import javax.persistence.UniqueConstraint;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate; 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.infrastructure.AbstractAuditableCustom;
import org.mifosng.platform.organisation.domain.Office; import org.mifosng.platform.organisation.domain.Office;
import org.mifosng.platform.organisation.domain.Organisation; import org.mifosng.platform.organisation.domain.Organisation;
@@ -88,13 +88,13 @@ public class Client extends AbstractAuditableCustom<AppUser, Long> {
} }
public void update(ClientCommand command) { public void update(ClientCommand command) {
this.joiningDate = command.getJoiningDate().toDate(); this.joiningDate = command.getJoiningLocalDate().toDate();
this.firstName = command.getFirstname(); this.firstName = command.getFirstname();
this.lastName = command.getLastname(); this.lastName = command.getLastname();
if (StringUtils.isNotBlank(command.getFullname())) { if (StringUtils.isNotBlank(command.getClientOrBusinessName())) {
this.firstName = null; this.firstName = null;
this.lastName = command.getFullname().trim(); this.lastName = command.getClientOrBusinessName().trim();
} }
if (StringUtils.isNotBlank(command.getExternalId())) { if (StringUtils.isNotBlank(command.getExternalId())) {
@@ -114,7 +114,7 @@ public class Client extends AbstractAuditableCustom<AppUser, Long> {
if (StringUtils.isNotBlank(firstname)) { if (StringUtils.isNotBlank(firstname)) {
this.firstName = firstname; this.firstName = firstname;
} }
if (StringUtils.isNotBlank(firstname)) { if (StringUtils.isNotBlank(lastname)) {
this.lastName = lastname; this.lastName = lastname;
} }
if (externalId != null) { if (externalId != null) {
@@ -5,8 +5,8 @@ import java.util.List;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.mifosng.data.ApiParameterError; import org.mifosng.data.ApiParameterError;
import org.mifosng.data.command.ClientCommand;
import org.mifosng.platform.DataValidatorBuilder; import org.mifosng.platform.DataValidatorBuilder;
import org.mifosng.platform.api.commands.ClientCommand;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException; import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
public class ClientCommandValidator { public class ClientCommandValidator {
@@ -22,18 +22,21 @@ public class ClientCommandValidator {
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("client"); DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("client");
if (command.getFullname() != null && StringUtils.isNotBlank(command.getFullname())) { if (command.getClientOrBusinessName() != null && StringUtils.isNotBlank(command.getClientOrBusinessName())) {
baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).mustBeBlankWhenParameterProvided("fullname", command.getFullname()); baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).mustBeBlankWhenParameterProvided("clientOrBusinessName", command.getClientOrBusinessName());
baseDataValidator.reset().parameter("lastname").value(command.getLastname()).mustBeBlankWhenParameterProvided("fullname", command.getFullname()); baseDataValidator.reset().parameter("lastname").value(command.getLastname()).mustBeBlankWhenParameterProvided("clientOrBusinessName", command.getClientOrBusinessName());
} else if (StringUtils.isBlank(command.getFullname())) { } else if (StringUtils.isBlank(command.getClientOrBusinessName())) {
baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).ignoreIfNull().notBlank(); baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("lastname").value(command.getLastname()).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("externalId").value(command.getExternalId()).ignoreIfNull().notExceedingLengthOf(100);
baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).ignoreIfNull().notNull().greaterThanZero(); 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()) { if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); 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"); DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("client");
if (StringUtils.isNotBlank(command.getFullname())) { if (StringUtils.isNotBlank(command.getClientOrBusinessName())) {
baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).mustBeBlankWhenParameterProvided("fullname", command.getFullname()); baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).mustBeBlankWhenParameterProvided("clientOrBusinessName", command.getClientOrBusinessName());
baseDataValidator.reset().parameter("lastname").value(command.getLastname()).mustBeBlankWhenParameterProvided("fullname", command.getFullname()); baseDataValidator.reset().parameter("lastname").value(command.getLastname()).mustBeBlankWhenParameterProvided("clientOrBusinessName", command.getClientOrBusinessName());
} else { } else {
baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).notBlank(); baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).notBlank();
baseDataValidator.reset().parameter("lastname").value(command.getLastname()).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("externalId").value(command.getExternalId()).notExceedingLengthOf(100);
baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).notNull().greaterThanZero(); baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).notNull().greaterThanZero();
@@ -1,8 +1,8 @@
package org.mifosng.platform.client.service; package org.mifosng.platform.client.service;
import org.mifosng.data.EntityIdentifier; import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.command.ClientCommand;
import org.mifosng.data.command.NoteCommand; import org.mifosng.data.command.NoteCommand;
import org.mifosng.platform.api.commands.ClientCommand;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
public interface ClientWritePlatformService { public interface ClientWritePlatformService {
@@ -10,12 +10,12 @@ public interface ClientWritePlatformService {
@PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE', 'CAN_ENROLL_NEW_CLIENT_ROLE')") @PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE', 'CAN_ENROLL_NEW_CLIENT_ROLE')")
Long enrollClient(ClientCommand command); Long enrollClient(ClientCommand command);
@PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE')")
EntityIdentifier updateClientDetails(ClientCommand command); 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); EntityIdentifier addClientNote(NoteCommand command);
@PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE')")
EntityIdentifier updateNote(NoteCommand command); EntityIdentifier updateNote(NoteCommand command);
} }
@@ -6,8 +6,8 @@ import static org.mifosng.platform.Specifications.officesThatMatch;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.mifosng.data.EntityIdentifier; import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.command.ClientCommand;
import org.mifosng.data.command.NoteCommand; 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.Client;
import org.mifosng.platform.client.domain.ClientRepository; import org.mifosng.platform.client.domain.ClientRepository;
import org.mifosng.platform.client.domain.Note; import org.mifosng.platform.client.domain.Note;
@@ -56,12 +56,12 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
String firstname = command.getFirstname(); String firstname = command.getFirstname();
String lastname = command.getLastname(); String lastname = command.getLastname();
if (StringUtils.isNotBlank(command.getFullname())) { if (StringUtils.isNotBlank(command.getClientOrBusinessName())) {
lastname = command.getFullname(); lastname = command.getClientOrBusinessName();
firstname = null; 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); this.clientRepository.save(newClient);
@@ -76,16 +76,20 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
ClientCommandValidator validator = new ClientCommandValidator(command); ClientCommandValidator validator = new ClientCommandValidator(command);
validator.validateForUpdate(); 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 firstname = command.getFirstname();
String lastname = command.getLastname(); String lastname = command.getLastname();
if (StringUtils.isNotBlank(command.getFullname())) { if (StringUtils.isNotBlank(command.getClientOrBusinessName())) {
lastname = command.getFullname(); lastname = command.getClientOrBusinessName();
firstname = null; firstname = null;
} }
@@ -93,7 +97,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
if (clientForUpdate == null) { if (clientForUpdate == null) {
throw new ClientNotFoundException(command.getId()); 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); this.clientRepository.save(clientForUpdate);
@@ -2,10 +2,13 @@ package org.mifosng.platform.loanproduct.service;
import org.mifosng.data.EntityIdentifier; import org.mifosng.data.EntityIdentifier;
import org.mifosng.platform.api.commands.LoanProductCommand; import org.mifosng.platform.api.commands.LoanProductCommand;
import org.springframework.security.access.prepost.PreAuthorize;
public interface LoanProductWritePlatformService { public interface LoanProductWritePlatformService {
@PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')")
EntityIdentifier createLoanProduct(LoanProductCommand command); EntityIdentifier createLoanProduct(LoanProductCommand command);
@PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')")
EntityIdentifier updateLoanProduct(LoanProductCommand command); EntityIdentifier updateLoanProduct(LoanProductCommand command);
} }
@@ -1,10 +1,13 @@
package org.mifosng.platform.organisation.service; package org.mifosng.platform.organisation.service;
import org.mifosng.platform.api.commands.OfficeCommand; import org.mifosng.platform.api.commands.OfficeCommand;
import org.springframework.security.access.prepost.PreAuthorize;
public interface OfficeWritePlatformService { public interface OfficeWritePlatformService {
@PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')")
Long createOffice(final OfficeCommand command); Long createOffice(final OfficeCommand command);
@PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')")
Long updateOffice(final OfficeCommand command); 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.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.mifosng.data.command.ImportClientCommand;
import org.mifosng.data.command.ImportLoanCommand; import org.mifosng.data.command.ImportLoanCommand;
import org.mifosng.data.command.ImportLoanRepaymentsCommand; import org.mifosng.data.command.ImportLoanRepaymentsCommand;
import org.mifosng.platform.ImportPlatformService; import org.mifosng.platform.ImportPlatformService;
import org.mifosng.platform.api.commands.ImportClientCommand;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; 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.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.mifosng.data.command.ImportClientCommand;
import org.mifosng.data.command.ImportLoanCommand; import org.mifosng.data.command.ImportLoanCommand;
import org.mifosng.data.command.ImportLoanRepaymentsCommand; import org.mifosng.data.command.ImportLoanRepaymentsCommand;
import org.mifosng.platform.ImportPlatformService; import org.mifosng.platform.ImportPlatformService;
import org.mifosng.platform.api.commands.ImportClientCommand;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;