filtering clients (part of)
This commit is contained in:
@@ -6,11 +6,15 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
||||||
|
import org.codehaus.jackson.map.annotate.JsonFilter;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Days;
|
import org.joda.time.Days;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
|
|
||||||
@XmlRootElement(name = "client")
|
@XmlRootElement(name = "client")
|
||||||
|
@JsonIgnoreProperties({ "organisationId","organisationName" })
|
||||||
|
@JsonFilter("myFilter")
|
||||||
public class ClientData implements Serializable {
|
public class ClientData implements Serializable {
|
||||||
|
|
||||||
private Long organisationId;
|
private Long organisationId;
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
package org.mifosng.data;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
@XmlRootElement
|
|
||||||
public class ClientList {
|
|
||||||
|
|
||||||
private Collection<ClientData> clients = new ArrayList<ClientData>();
|
|
||||||
|
|
||||||
protected ClientList() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClientList(final Collection<ClientData> clients) {
|
|
||||||
this.clients = clients;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<ClientData> getClients() {
|
|
||||||
return this.clients;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClients(final Collection<ClientData> clients) {
|
|
||||||
this.clients = clients;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.mifosng.platform.api;
|
package org.mifosng.platform.api;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
@@ -9,22 +10,26 @@ import javax.ws.rs.PUT;
|
|||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
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 javax.ws.rs.core.UriInfo;
|
||||||
|
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.mifosng.data.ClientData;
|
import org.mifosng.data.ClientData;
|
||||||
import org.mifosng.data.ClientList;
|
|
||||||
import org.mifosng.data.ClientLoanAccountSummaryCollectionData;
|
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.NoteDataList;
|
import org.mifosng.data.NoteDataList;
|
||||||
|
import org.mifosng.data.OfficeLookup;
|
||||||
import org.mifosng.data.command.ClientCommand;
|
import org.mifosng.data.command.ClientCommand;
|
||||||
import org.mifosng.data.command.NoteCommand;
|
import org.mifosng.data.command.NoteCommand;
|
||||||
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;
|
||||||
import org.mifosng.platform.client.service.ClientWritePlatformService;
|
import org.mifosng.platform.client.service.ClientWritePlatformService;
|
||||||
|
import org.mifosng.platform.organisation.service.OfficeReadPlatformService;
|
||||||
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;
|
||||||
@@ -34,60 +39,83 @@ import org.springframework.stereotype.Component;
|
|||||||
@Scope("singleton")
|
@Scope("singleton")
|
||||||
public class ClientApiResource {
|
public class ClientApiResource {
|
||||||
|
|
||||||
private String defaultFieldList = "openingDate";
|
private String defaultFieldList = "joinedDate";
|
||||||
private String allowedFieldList = "allowedParents";
|
private String allowedFieldList = "allowedOffices";
|
||||||
private String filterName = "myFilter";
|
private String filterName = "myFilter";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ClientReadPlatformService clientReadPlatformService;
|
private ClientReadPlatformService clientReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ClientWritePlatformService clientWritePlatformService;
|
private ClientWritePlatformService clientWritePlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApiDataConversionService apiDataConversionService;
|
private ApiDataConversionService apiDataConversionService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OfficeReadPlatformService officeReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApiJSONFormattingService jsonFormattingService;
|
private ApiJSONFormattingService jsonFormattingService;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response retrieveAllIndividualClients() {
|
public String retrieveAllIndividualClients(@Context UriInfo uriInfo) {
|
||||||
|
|
||||||
Collection<ClientData> clients = this.clientReadPlatformService.retrieveAllIndividualClients();
|
Collection<ClientData> clients = this.clientReadPlatformService
|
||||||
|
.retrieveAllIndividualClients();
|
||||||
|
|
||||||
return Response.ok().entity(new ClientList(clients)).build();
|
String selectedFields = "";
|
||||||
|
return this.jsonFormattingService.convertRequest(clients, filterName,
|
||||||
|
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{clientId}")
|
@Path("{clientId}")
|
||||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response retrieveClientData(@PathParam("clientId") final Long clientId) {
|
public String retrieveClientData(
|
||||||
|
@PathParam("clientId") final Long clientId,
|
||||||
|
@QueryParam("template") String template, @Context UriInfo uriInfo) {
|
||||||
|
|
||||||
ClientData clientData = this.clientReadPlatformService.retrieveIndividualClient(clientId);
|
ClientData clientData = this.clientReadPlatformService
|
||||||
|
.retrieveIndividualClient(clientId);
|
||||||
|
|
||||||
return Response.ok().entity(clientData).build();
|
if (template != null && template.equalsIgnoreCase("true")) {
|
||||||
|
clientData.setAllowedOffices(new ArrayList<OfficeLookup>(
|
||||||
|
officeReadPlatformService.retrieveAllOfficesForLookup()));
|
||||||
|
}
|
||||||
|
|
||||||
|
String selectedFields = "";
|
||||||
|
return this.jsonFormattingService.convertRequest(clientData,
|
||||||
|
filterName, allowedFieldList, selectedFields,
|
||||||
|
uriInfo.getQueryParameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("template")
|
@Path("template")
|
||||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response newClientDetails() {
|
public String newClientDetails(@Context UriInfo uriInfo) {
|
||||||
|
|
||||||
ClientData clientData = this.clientReadPlatformService.retrieveNewClientDetails();
|
ClientData clientData = this.clientReadPlatformService
|
||||||
|
.retrieveNewClientDetails();
|
||||||
|
|
||||||
return Response.ok().entity(clientData).build();
|
String selectedFields = defaultFieldList + "," + allowedFieldList;
|
||||||
|
return this.jsonFormattingService.convertRequest(clientData,
|
||||||
|
filterName, allowedFieldList, selectedFields,
|
||||||
|
uriInfo.getQueryParameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@Produces({MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response enrollClient(final ClientCommand command) {
|
public Response enrollClient(final ClientCommand command) {
|
||||||
|
|
||||||
LocalDate joiningDate = apiDataConversionService.convertFrom(command.getJoiningDateFormatted(), "joiningDateFormatted", command.getDateFormat());
|
LocalDate joiningDate = apiDataConversionService.convertFrom(
|
||||||
|
command.getJoiningDateFormatted(), "joiningDateFormatted",
|
||||||
|
command.getDateFormat());
|
||||||
command.setJoiningDate(joiningDate);
|
command.setJoiningDate(joiningDate);
|
||||||
|
|
||||||
Long clientId = this.clientWritePlatformService.enrollClient(command);
|
Long clientId = this.clientWritePlatformService.enrollClient(command);
|
||||||
@@ -97,75 +125,92 @@ public class ClientApiResource {
|
|||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{clientId}")
|
@Path("{clientId}")
|
||||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@Produces({MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response updateClient(@PathParam("clientId") final Long clientId, final ClientCommand command) {
|
public Response updateClient(@PathParam("clientId") final Long clientId,
|
||||||
|
final ClientCommand command) {
|
||||||
|
|
||||||
LocalDate joiningDate = apiDataConversionService.convertFrom(command.getJoiningDateFormatted(), "joiningDateFormatted", command.getDateFormat());
|
LocalDate joiningDate = apiDataConversionService.convertFrom(
|
||||||
|
command.getJoiningDateFormatted(), "joiningDateFormatted",
|
||||||
|
command.getDateFormat());
|
||||||
command.setJoiningDate(joiningDate);
|
command.setJoiningDate(joiningDate);
|
||||||
command.setId(clientId);
|
command.setId(clientId);
|
||||||
|
|
||||||
EntityIdentifier identifier = this.clientWritePlatformService.updateClientDetails(command);
|
EntityIdentifier identifier = this.clientWritePlatformService
|
||||||
|
.updateClientDetails(command);
|
||||||
|
|
||||||
return Response.ok().entity(identifier).build();
|
return Response.ok().entity(identifier).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{clientId}/loans")
|
@Path("{clientId}/loans")
|
||||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@Produces({MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response retrieveClientAccount(@PathParam("clientId") final Long clientId) {
|
public Response retrieveClientAccount(
|
||||||
|
@PathParam("clientId") final Long clientId) {
|
||||||
|
|
||||||
ClientLoanAccountSummaryCollectionData clientAccount = this.clientReadPlatformService.retrieveClientAccountDetails(clientId);
|
ClientLoanAccountSummaryCollectionData clientAccount = this.clientReadPlatformService
|
||||||
|
.retrieveClientAccountDetails(clientId);
|
||||||
|
|
||||||
return Response.ok().entity(clientAccount).build();
|
return Response.ok().entity(clientAccount).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{clientId}/notes")
|
@Path("{clientId}/notes")
|
||||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response retrieveAllClientNotes(@PathParam("clientId") final Long clientId) {
|
public Response retrieveAllClientNotes(
|
||||||
|
@PathParam("clientId") final Long clientId) {
|
||||||
|
|
||||||
Collection<NoteData> notes = this.clientReadPlatformService.retrieveAllClientNotes(clientId);
|
Collection<NoteData> notes = this.clientReadPlatformService
|
||||||
|
.retrieveAllClientNotes(clientId);
|
||||||
|
|
||||||
return Response.ok().entity(new NoteDataList(notes)).build();
|
return Response.ok().entity(new NoteDataList(notes)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("{clientId}/notes")
|
@Path("{clientId}/notes")
|
||||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response addNewClientNote(@PathParam("clientId") final Long clientId, final NoteCommand command) {
|
public Response addNewClientNote(
|
||||||
|
@PathParam("clientId") final Long clientId,
|
||||||
|
final NoteCommand command) {
|
||||||
|
|
||||||
command.setClientId(clientId);
|
command.setClientId(clientId);
|
||||||
|
|
||||||
EntityIdentifier identifier = this.clientWritePlatformService.addClientNote(command);
|
EntityIdentifier identifier = this.clientWritePlatformService
|
||||||
|
.addClientNote(command);
|
||||||
|
|
||||||
return Response.ok().entity(identifier).build();
|
return Response.ok().entity(identifier).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{clientId}/notes/{noteId}")
|
@Path("{clientId}/notes/{noteId}")
|
||||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@Produces({MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response retrieveClientNote(@PathParam("clientId") final Long clientId, @PathParam("noteId") final Long noteId) {
|
public Response retrieveClientNote(
|
||||||
|
@PathParam("clientId") final Long clientId,
|
||||||
|
@PathParam("noteId") final Long noteId) {
|
||||||
|
|
||||||
NoteData note = this.clientReadPlatformService.retrieveClientNote(clientId, noteId);
|
NoteData note = this.clientReadPlatformService.retrieveClientNote(
|
||||||
|
clientId, noteId);
|
||||||
|
|
||||||
return Response.ok().entity(note).build();
|
return Response.ok().entity(note).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{clientId}/notes/{noteId}")
|
@Path("{clientId}/notes/{noteId}")
|
||||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@Produces({MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response updateClientNote(@PathParam("clientId") final Long clientId, @PathParam("noteId") final Long noteId, final NoteCommand command) {
|
public Response updateClientNote(
|
||||||
|
@PathParam("clientId") final Long clientId,
|
||||||
|
@PathParam("noteId") final Long noteId, final NoteCommand command) {
|
||||||
|
|
||||||
command.setClientId(clientId);
|
command.setClientId(clientId);
|
||||||
command.setId(noteId);
|
command.setId(noteId);
|
||||||
|
|
||||||
EntityIdentifier identifier = this.clientWritePlatformService.updateNote(command);
|
EntityIdentifier identifier = this.clientWritePlatformService
|
||||||
|
.updateNote(command);
|
||||||
|
|
||||||
return Response.ok().entity(identifier).build();
|
return Response.ok().entity(identifier).build();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -83,7 +83,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
AppUser currentUser = this.context.authenticatedUser();
|
AppUser currentUser = this.context.authenticatedUser();
|
||||||
|
//TODO - JW include office name in query rather than get the lot for office name
|
||||||
List<OfficeData> offices = new ArrayList<OfficeData>(officeReadPlatformService.retrieveAllOffices());
|
List<OfficeData> offices = new ArrayList<OfficeData>(officeReadPlatformService.retrieveAllOffices());
|
||||||
ClientMapper rm = new ClientMapper(offices, currentUser.getOrganisation());
|
ClientMapper rm = new ClientMapper(offices, currentUser.getOrganisation());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user