Changed the client endpoint methods to retrieve clients
This commit is contained in:
+8
-49
@@ -5,17 +5,14 @@
|
||||
*/
|
||||
package org.mifosplatform.portfolio.client.api;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.DefaultValue;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
@@ -93,19 +90,19 @@ public class ClientsApiResource {
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveAll(@Context final UriInfo uriInfo, @QueryParam("sqlSearch") final String sqlSearch,
|
||||
public String retrieveAllPaginatedAndSorted(@QueryParam("sqlSearch") final String sqlSearch,
|
||||
@QueryParam("officeId") final Long officeId, @QueryParam("externalId") final String externalId,
|
||||
@QueryParam("displayName") final String displayName, @QueryParam("firstName") final String firstname,
|
||||
@QueryParam("lastName") final String lastname, @QueryParam("underHierarchy") final String hierarchy) {
|
||||
|
||||
@QueryParam("lastName") final String lastname, @QueryParam("underHierarchy") final String hierarchy,
|
||||
@QueryParam("offset") final int offset, @QueryParam("limit") final int limit, @QueryParam("orderBy") final String orderBy,
|
||||
@QueryParam("sortOrder") final String sortOrder) {
|
||||
context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_RESOURCE_NAME);
|
||||
|
||||
final SearchParameters searchParameters = SearchParameters.forClients(sqlSearch, officeId, externalId, displayName, firstname,
|
||||
lastname, hierarchy);
|
||||
final Collection<ClientData> clients = this.clientReadPlatformService.retrieveAll(searchParameters);
|
||||
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, clients, ClientApiConstants.CLIENT_RESPONSE_DATA_PARAMETERS);
|
||||
Page<ClientData> clientData = this.clientReadPlatformService.retrieveAllPaginatedAndSorted(searchParameters, offset, limit,
|
||||
orderBy, sortOrder);
|
||||
return this.toApiJsonSerializer.serialize(clientData);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -126,45 +123,7 @@ public class ClientsApiResource {
|
||||
|
||||
return this.toApiJsonSerializer.serialize(settings, clientData, ClientApiConstants.CLIENT_RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/paginatedandsorted")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveAllPaginatedAndSorted(@Context final UriInfo uriInfo, @QueryParam("sqlSearch") final String sqlSearch,
|
||||
@QueryParam("officeId") final Long officeId, @QueryParam("externalId") final String externalId,
|
||||
@QueryParam("displayName") final String displayName, @QueryParam("firstName") final String firstname,
|
||||
@QueryParam("lastName") final String lastname, @QueryParam("underHierarchy") final String hierarchy,
|
||||
@DefaultValue("0") @QueryParam("offset") final int offset, @DefaultValue("200") @QueryParam("limit") final int limit,
|
||||
@QueryParam("orderBy") final String orderBy, @QueryParam("sortOrder") final String sortOrder) throws SQLException {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_RESOURCE_NAME);
|
||||
|
||||
final SearchParameters searchParameters = SearchParameters.forClients(sqlSearch, officeId, externalId, displayName, firstname,
|
||||
lastname, hierarchy);
|
||||
Page<ClientData> clientData = this.clientReadPlatformService.retrieveAllPaginatedAndSorted(searchParameters, offset, limit, orderBy, sortOrder);
|
||||
return this.toApiJsonSerializer.serialize(clientData);
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/paginated")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveAllPaginated(@Context final UriInfo uriInfo, @QueryParam("sqlSearch") final String sqlSearch,
|
||||
@QueryParam("officeId") final Long officeId, @QueryParam("externalId") final String externalId,
|
||||
@QueryParam("displayName") final String displayName, @QueryParam("firstName") final String firstname,
|
||||
@QueryParam("lastName") final String lastname, @QueryParam("underHierarchy") final String hierarchy,
|
||||
@DefaultValue("0") @QueryParam("offset") final int offset, @DefaultValue("200") @QueryParam("limit") final int limit)
|
||||
throws SQLException {
|
||||
context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_RESOURCE_NAME);
|
||||
|
||||
final SearchParameters searchParameters = SearchParameters.forClients(sqlSearch, officeId, externalId, displayName, firstname,
|
||||
lastname, hierarchy);
|
||||
Page<ClientData> clientData = this.clientReadPlatformService.retrieveAllPaginatedAndSorted(searchParameters, offset, limit, null, null);
|
||||
return this.toApiJsonSerializer.serialize(clientData);
|
||||
}
|
||||
|
||||
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ public interface ClientReadPlatformService {
|
||||
|
||||
Collection<ClientData> retrieveAll(SearchParameters searchParameters);
|
||||
|
||||
Page<ClientData> retrieveAllPaginatedAndSorted(SearchParameters searchParameters, int pageNo, int pageSize, String sortBy, String sortOrder);
|
||||
Page<ClientData> retrieveAllPaginatedAndSorted(SearchParameters searchParameters, int offset, int limit, String sortBy, String sortOrder);
|
||||
|
||||
ClientData retrieveOne(Long clientId);
|
||||
|
||||
|
||||
+3
-2
@@ -112,8 +112,9 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
||||
|
||||
PaginationHelper<ClientData> ph = new PaginationHelper<ClientData>();
|
||||
String sqlCountRows = "SELECT FOUND_ROWS()";
|
||||
String sqlFetchRows = sql + " LIMIT " + limit + " OFFSET " + offset;
|
||||
return ph.fetchPage(jdbcTemplate, sqlCountRows, sqlFetchRows, new Object[] { hierarchySearchString }, offset, limit, clientMapper);
|
||||
String sqlFetchRows = sql;
|
||||
if (limit != 0) sqlFetchRows = sql + " LIMIT " + limit + " OFFSET " + offset;
|
||||
return ph.fetchPage(jdbcTemplate, sqlCountRows, sqlFetchRows, new Object[] { hierarchySearchString }, clientMapper);
|
||||
}
|
||||
|
||||
private String buildSqlStringFromClientCriteria(final SearchParameters searchParameters) {
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.portfolio.pagination;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -7,27 +12,17 @@ import com.google.gson.Gson;
|
||||
|
||||
public class Page<E> {
|
||||
|
||||
private int pageNumber;
|
||||
private int totalFilteredRecords;
|
||||
private List<E> pageItems = new ArrayList<E>();
|
||||
|
||||
public void setPageNumber(int pageNumber) {
|
||||
this.pageNumber = pageNumber;
|
||||
}
|
||||
|
||||
public void setPageItems(List<E> pageItems) {
|
||||
this.pageItems = pageItems;
|
||||
}
|
||||
|
||||
public int getPageNumber() {
|
||||
return pageNumber;
|
||||
}
|
||||
|
||||
public int getTotalFilteredRecords() {
|
||||
return this.totalFilteredRecords;
|
||||
}
|
||||
|
||||
|
||||
public void setTotalFilteredRecords(int totalFilteredRecords) {
|
||||
this.totalFilteredRecords = totalFilteredRecords;
|
||||
}
|
||||
|
||||
+6
-2
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.portfolio.pagination;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -6,7 +11,7 @@ import org.springframework.jdbc.core.RowMapper;
|
||||
public class PaginationHelper<E> {
|
||||
|
||||
public Page<E> fetchPage(final JdbcTemplate jt, final String sqlCountRows, final String sqlFetchRows, final Object args[],
|
||||
final int offset, final int limit, final RowMapper<E> rowMapper) {
|
||||
final RowMapper<E> rowMapper) {
|
||||
|
||||
final Page<E> page = new Page<E>();
|
||||
|
||||
@@ -15,7 +20,6 @@ public class PaginationHelper<E> {
|
||||
// determine how many rows are available
|
||||
final int totalFilteredRecords = jt.queryForInt(sqlCountRows);
|
||||
|
||||
page.setPageNumber(offset);//TODO will change to suit limit & offset
|
||||
page.setTotalFilteredRecords(totalFilteredRecords);
|
||||
|
||||
return page;
|
||||
|
||||
Reference in New Issue
Block a user