doc changes and related code changes around client update.

This commit is contained in:
Keith Woodlock
2012-05-22 23:05:58 +01:00
parent 87275e1d47
commit 7e6f11d398
10 changed files with 697 additions and 240 deletions
@@ -22,7 +22,7 @@ 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.EnrollClientCommand;
import org.mifosng.data.command.ClientCommand;
import org.mifosng.data.command.ImportClientCommand;
import org.mifosng.data.command.ImportLoanCommand;
import org.mifosng.data.command.ImportLoanRepaymentsCommand;
@@ -115,7 +115,7 @@ public class ImportPlatformServiceImpl implements ImportPlatformService {
List<Client> newClientCollection = new ArrayList<Client>();
for (EnrollClientCommand client : command.getClients()) {
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());
@@ -544,7 +544,7 @@ public class ImportPlatformServiceImpl implements ImportPlatformService {
// success = false;
// }
List<EnrollClientCommand> parsedClients = new ArrayList<EnrollClientCommand>();
List<ClientCommand> parsedClients = new ArrayList<ClientCommand>();
while (clients.readRecord()) {
String externalId = clients.get("ExternalId");
String firstname = clients.get("FirstName");
@@ -555,7 +555,7 @@ public class ImportPlatformServiceImpl implements ImportPlatformService {
LocalDate joiningDate = new LocalDate(isoParser.parseDateTime(joined));
EnrollClientCommand parsedClient = new EnrollClientCommand(firstname, lastname, "", matchingOffice.getId(), joiningDate);
ClientCommand parsedClient = new ClientCommand(firstname, lastname, "", matchingOffice.getId(), joiningDate);
parsedClient.setExternalId(externalId);
parsedClients.add(parsedClient);
@@ -19,7 +19,7 @@ import org.mifosng.data.ClientLoanAccountSummaryCollectionData;
import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.NoteData;
import org.mifosng.data.NoteDataList;
import org.mifosng.data.command.EnrollClientCommand;
import org.mifosng.data.command.ClientCommand;
import org.mifosng.data.command.NoteCommand;
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
import org.mifosng.platform.client.service.ClientReadPlatformService;
@@ -43,8 +43,8 @@ public class ClientApiResource {
private ApiDataConversionService apiDataConversionService;
@GET
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({ MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON})
public Response retrieveAllIndividualClients() {
Collection<ClientData> clients = this.clientReadPlatformService.retrieveAllIndividualClients();
@@ -54,8 +54,8 @@ public class ClientApiResource {
@GET
@Path("{clientId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({ MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON})
public Response retrieveClientData(@PathParam("clientId") final Long clientId) {
ClientData clientData = this.clientReadPlatformService.retrieveIndividualClient(clientId);
@@ -65,8 +65,8 @@ public class ClientApiResource {
@GET
@Path("template")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({ MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON})
public Response newClientDetails() {
ClientData clientData = this.clientReadPlatformService.retrieveNewClientDetails();
@@ -75,9 +75,9 @@ public class ClientApiResource {
}
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON })
public Response enrollClient(final EnrollClientCommand command) {
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON })
public Response enrollClient(final ClientCommand command) {
LocalDate joiningDate = apiDataConversionService.convertFrom(command.getJoiningDateFormatted(), "joiningDateFormatted", command.getDateFormat());
command.setJoiningDate(joiningDate);
@@ -87,11 +87,25 @@ public class ClientApiResource {
return Response.ok().entity(new EntityIdentifier(clientId)).build();
}
@PUT
@Path("{clientId}")
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON })
public Response updateClient(@PathParam("clientId") final Long clientId, final ClientCommand command) {
LocalDate joiningDate = apiDataConversionService.convertFrom(command.getJoiningDateFormatted(), "joiningDateFormatted", command.getDateFormat());
command.setJoiningDate(joiningDate);
command.setId(clientId);
EntityIdentifier identifier = this.clientWritePlatformService.updateClientDetails(command);
return Response.ok().entity(identifier).build();
}
@GET
@Path("{clientId}/loans")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON })
public Response retrieveClientAccount(@PathParam("clientId") final Long clientId) {
ClientLoanAccountSummaryCollectionData clientAccount = this.clientReadPlatformService.retrieveClientAccountDetails(clientId);
@@ -101,8 +115,8 @@ public class ClientApiResource {
@GET
@Path("{clientId}/notes")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({ MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON})
public Response retrieveAllClientNotes(@PathParam("clientId") final Long clientId) {
Collection<NoteData> notes = this.clientReadPlatformService.retrieveAllClientNotes(clientId);
@@ -112,8 +126,8 @@ public class ClientApiResource {
@POST
@Path("{clientId}/notes")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({ MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON})
public Response addNewClientNote(@PathParam("clientId") final Long clientId, final NoteCommand command) {
command.setClientId(clientId);
@@ -125,8 +139,8 @@ public class ClientApiResource {
@GET
@Path("{clientId}/notes/{noteId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON })
public Response retrieveClientNote(@PathParam("clientId") final Long clientId, @PathParam("noteId") final Long noteId) {
NoteData note = this.clientReadPlatformService.retrieveClientNote(clientId, noteId);
@@ -136,8 +150,8 @@ public class ClientApiResource {
@PUT
@Path("{clientId}/notes/{noteId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON })
public Response updateClientNote(@PathParam("clientId") final Long clientId, @PathParam("noteId") final Long noteId, final NoteCommand command) {
command.setClientId(clientId);
@@ -13,6 +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.infrastructure.AbstractAuditableCustom;
import org.mifosng.platform.organisation.domain.Office;
import org.mifosng.platform.organisation.domain.Organisation;
@@ -34,19 +35,19 @@ public class Client extends AbstractAuditableCustom<AppUser, Long> {
@SuppressWarnings("unused")
@Column(name = "firstname", length=50)
private final String firstName;
private String firstName;
@SuppressWarnings("unused")
@Column(name = "lastname", length=50)
private final String lastName;
private String lastName;
@SuppressWarnings("unused")
@Column(name = "joining_date")
@Temporal(TemporalType.DATE)
private final Date joiningDate;
private Date joiningDate;
@Column(name = "external_id", length=100)
private final String externalId;
private String externalId;
public static Client newClient(Organisation organisation,
Office clientOffice, String firstname, String lastname,
@@ -85,4 +86,31 @@ public class Client extends AbstractAuditableCustom<AppUser, Long> {
public boolean identifiedBy(final String identifier) {
return identifier.equalsIgnoreCase(this.externalId);
}
public void update(ClientCommand command) {
this.joiningDate = command.getJoiningDate().toDate();
this.firstName = command.getFirstname();
this.lastName = command.getLastname();
if (StringUtils.isNotBlank(command.getFullname())) {
this.firstName = null;
this.lastName = command.getFullname().trim();
}
if (StringUtils.isNotBlank(command.getExternalId())) {
this.externalId = command.getExternalId().trim();
} else {
this.externalId = null;
}
}
public void update(Office clientOffice, String firstname, String lastname, String externalId, LocalDate joiningDate) {
this.joiningDate = joiningDate.toDate();
this.firstName = firstname;
this.lastName = lastname;
this.externalId = externalId;
if (StringUtils.isNotBlank(externalId)) {
this.externalId = externalId.trim();
}
}
}
@@ -5,14 +5,14 @@ import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.mifosng.data.ApiParameterError;
import org.mifosng.data.command.EnrollClientCommand;
import org.mifosng.data.command.ClientCommand;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
public class EnrollClientCommandValidator {
public class ClientCommandValidator {
private final EnrollClientCommand command;
private final ClientCommand command;
public EnrollClientCommandValidator(EnrollClientCommand command) {
public ClientCommandValidator(ClientCommand command) {
this.command = command;
}
@@ -1,17 +1,21 @@
package org.mifosng.platform.client.service;
import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.command.EnrollClientCommand;
import org.mifosng.data.command.ClientCommand;
import org.mifosng.data.command.NoteCommand;
import org.springframework.security.access.prepost.PreAuthorize;
public interface ClientWritePlatformService {
@PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE', 'CAN_ENROLL_NEW_CLIENT_ROLE')")
Long enrollClient(EnrollClientCommand command);
Long enrollClient(ClientCommand command);
EntityIdentifier updateClientDetails(ClientCommand command);
// FIXME - add permission for adding and updating client notes.
EntityIdentifier addClientNote(NoteCommand command);
EntityIdentifier updateNote(NoteCommand command);
}
@@ -1,10 +1,10 @@
package org.mifosng.platform.client.service;
import static org.mifosng.platform.Specifications.officesThatMatch;
import static org.mifosng.platform.Specifications.*;
import org.apache.commons.lang.StringUtils;
import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.command.EnrollClientCommand;
import org.mifosng.data.command.ClientCommand;
import org.mifosng.data.command.NoteCommand;
import org.mifosng.platform.client.domain.Client;
import org.mifosng.platform.client.domain.ClientRepository;
@@ -37,11 +37,11 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
@Transactional
@Override
public Long enrollClient(final EnrollClientCommand command) {
public Long enrollClient(final ClientCommand command) {
AppUser currentUser = context.authenticatedUser();
EnrollClientCommandValidator validator = new EnrollClientCommandValidator(command);
ClientCommandValidator validator = new ClientCommandValidator(command);
validator.validate();
Office clientOffice = this.officeRepository.findOne(officesThatMatch(currentUser.getOrganisation(), command.getOfficeId()));
@@ -60,6 +60,33 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
return newClient.getId();
}
@Transactional
@Override
public EntityIdentifier updateClientDetails(ClientCommand command) {
AppUser currentUser = context.authenticatedUser();
//EnrollClientCommandValidator validator = new EnrollClientCommandValidator(command);
//validator.validate();
Office clientOffice = this.officeRepository.findOne(officesThatMatch(currentUser.getOrganisation(), command.getOfficeId()));
String firstname = command.getFirstname();
String lastname = command.getLastname();
if (StringUtils.isNotBlank(command.getFullname())) {
lastname = command.getFullname();
firstname = null;
}
Client clientForUpdate = this.clientRepository.findOne(clientsThatMatch(currentUser.getOrganisation(), command.getId()));
clientForUpdate.update(clientOffice, firstname, lastname, command.getExternalId(), command.getJoiningDate());
this.clientRepository.save(clientForUpdate);
return new EntityIdentifier(clientForUpdate.getId());
}
@Transactional
@Override
public EntityIdentifier addClientNote(NoteCommand command) {
@@ -45,7 +45,7 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
public LoanProductData retrieveLoanProduct(final Long loanProductId) {
try {
List<CurrencyData> allowedCurrencies = currencyReadPlatformService.retrieveAllowedCurrencies();
List<CurrencyData> allowedCurrencies = currencyReadPlatformService.retrieveAllPlatformCurrencies();
LoanProductMapper rm = new LoanProductMapper(allowedCurrencies);
String sql = "select " + rm.loanProductSchema() + " where lp.id = ?";
@@ -65,7 +65,7 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
AppUser currentUser = this.context.authenticatedUser();
List<CurrencyData> allowedCurrencies = currencyReadPlatformService.retrieveAllowedCurrencies();
List<CurrencyData> allowedCurrencies = currencyReadPlatformService.retrieveAllPlatformCurrencies();
LoanProductMapper rm = new LoanProductMapper(allowedCurrencies);
@@ -134,7 +134,9 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
int currencyDigits = rs.getInt("currencyDigits");
CurrencyData currencyData = findCurrencyByCode(currencyCode, allowedCurrencies);
currencyData.setDecimalPlaces(currencyDigits);
if (currencyData != null) {
currencyData.setDecimalPlaces(currencyDigits);
}
BigDecimal principal = rs.getBigDecimal("principal");
BigDecimal tolerance = rs.getBigDecimal("tolerance");