From 976d0ad60dd8f2bfa870a042f9caf46a37ef361c Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Mon, 19 Mar 2018 20:37:30 +0530 Subject: [PATCH] Modify application retrieval API As per the API designing best practices, added offset and limit query parameters for application getting API. --- .../mgt/core/impl/ApplicationManagerImpl.java | 8 -------- .../api/services/ApplicationManagementAPI.java | 18 ++++++++++++++---- .../impl/ApplicationManagementAPIImpl.java | 7 ++++++- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 990520e6b3..fc836f69c7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -66,8 +66,6 @@ import java.util.Date; public class ApplicationManagerImpl implements ApplicationManager { 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 VisibilityDAO visibilityDAO; private ApplicationDAO applicationDAO; @@ -843,12 +841,6 @@ public class ApplicationManagerImpl implements ApplicationManager { private Filter validateFilter(Filter filter) { 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()) && !SortingOrder.DESC.toString().equals(filter.getSortBy())) { return null; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java index b693e8cec8..80629b310b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java @@ -133,9 +133,9 @@ public interface ApplicationManagementAPI { message = "OK. \n Successfully got application list.", response = ApplicationList.class), @ApiResponse( - code = 304, - message = "Not Modified. Empty body because the client already has the latest version " - + "of the requested resource."), + code = 404, + message = "Not Found. There doesn't have an application which is matched with requested " + + "query."), @ApiResponse( code = 500, message = "Internal Server Error. \n Error occurred while getting the application list.", @@ -146,7 +146,17 @@ public interface ApplicationManagementAPI { name = "filter", value = "Filter to get application list", 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 diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java index 91010f8c07..a96b408719 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java @@ -61,10 +61,15 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @GET @Override @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(); try { + filter.setOffset(offset); + filter.setLimit(limit); ApplicationList applications = applicationManager.getApplications(filter); if (applications.getApplications().isEmpty()) { return Response.status(Response.Status.NOT_FOUND).entity