Modify application retrieval API

As per the API designing best practices, added offset and limit query parameters for application getting API.
feature/appm-store/pbac
lasanthaDLPDS 7 years ago
parent 71aa6762ac
commit 976d0ad60d

@ -66,8 +66,6 @@ import java.util.Date;
public class ApplicationManagerImpl implements ApplicationManager { public class ApplicationManagerImpl implements ApplicationManager {
private static final Log log = LogFactory.getLog(ApplicationManagerImpl.class); private static final Log log = LogFactory.getLog(ApplicationManagerImpl.class);
private static final int DEFAULT_LIMIT = 20;
private static final int DEFAULT_OFFSET = 10;
private DeviceTypeDAO deviceTypeDAO; private DeviceTypeDAO deviceTypeDAO;
private VisibilityDAO visibilityDAO; private VisibilityDAO visibilityDAO;
private ApplicationDAO applicationDAO; private ApplicationDAO applicationDAO;
@ -843,12 +841,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
private Filter validateFilter(Filter filter) { private Filter validateFilter(Filter filter) {
if (filter != null) { if (filter != null) {
if (filter.getLimit() == 0) {
filter.setLimit(DEFAULT_LIMIT);
}
if (filter.getOffset() == 0) {
filter.setOffset(DEFAULT_OFFSET);
}
if (!SortingOrder.ASC.toString().equals(filter.getSortBy()) && if (!SortingOrder.ASC.toString().equals(filter.getSortBy()) &&
!SortingOrder.DESC.toString().equals(filter.getSortBy())) { !SortingOrder.DESC.toString().equals(filter.getSortBy())) {
return null; return null;

@ -133,9 +133,9 @@ public interface ApplicationManagementAPI {
message = "OK. \n Successfully got application list.", message = "OK. \n Successfully got application list.",
response = ApplicationList.class), response = ApplicationList.class),
@ApiResponse( @ApiResponse(
code = 304, code = 404,
message = "Not Modified. Empty body because the client already has the latest version " message = "Not Found. There doesn't have an application which is matched with requested " +
+ "of the requested resource."), "query."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred while getting the application list.", message = "Internal Server Error. \n Error occurred while getting the application list.",
@ -146,7 +146,17 @@ public interface ApplicationManagementAPI {
name = "filter", name = "filter",
value = "Filter to get application list", value = "Filter to get application list",
required = true) required = true)
@Valid Filter filter @Valid Filter filter,
@ApiParam(
name = "offset",
value = "offset",
defaultValue = "0")
@QueryParam("offset") int offset,
@ApiParam(
name = "limit",
value = "limit",
defaultValue = "20")
@QueryParam("limit") int limit
); );
@GET @GET

@ -61,10 +61,15 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@GET @GET
@Override @Override
@Consumes("application/json") @Consumes("application/json")
public Response getApplications(@Valid Filter filter) { public Response getApplications(
@Valid Filter filter,
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
filter.setOffset(offset);
filter.setLimit(limit);
ApplicationList applications = applicationManager.getApplications(filter); ApplicationList applications = applicationManager.getApplications(filter);
if (applications.getApplications().isEmpty()) { if (applications.getApplications().isEmpty()) {
return Response.status(Response.Status.NOT_FOUND).entity return Response.status(Response.Status.NOT_FOUND).entity

Loading…
Cancel
Save