From f4e1ca6815ab8a14c9c325fcb75a9abc3c3f5b2c Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 27 Sep 2018 09:24:31 +0530 Subject: [PATCH] Improve publisher APIs --- .../device/application/mgt/common/Filter.java | 63 ++++++++++--------- .../common/services/ApplicationManager.java | 3 +- .../mgt/core/impl/ApplicationManagerImpl.java | 8 +-- .../services/ApplicationManagementAPI.java | 8 +++ .../impl/ApplicationManagementAPIImpl.java | 6 +- 5 files changed, 52 insertions(+), 36 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java index 96ee8e49bd7..0d1c5b693c6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java @@ -18,54 +18,51 @@ */ package org.wso2.carbon.device.application.mgt.common; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; - /** * Filter represents a criteria that can be used for searching applications. */ - -@ApiModel(value = "Filter", description = "This is related to the application filtering.") public class Filter { - @ApiModelProperty( - name = "appName", - value = "Name of the application", - required = false) + /** + * Name of the application + */ private String appName; - @ApiModelProperty( - name = "appType", - value = "Type of the application", - required = false) + /** + * Type of the application + */ private String appType; + /** + * Category of the application + */ private String appCategory; - @ApiModelProperty( - name = "isFullMatch", - value = "Checking the application name matches fully with given name", - required = false) + /** + * Checking the application name matches fully with given name + */ private boolean isFullMatch; - @ApiModelProperty( - name = "limit", - value = "Limit of the applications", - required = false) + /** + * Limit of the applications + */ private int limit; - @ApiModelProperty( - name = "offset", - value = "Started from", - required = false) + /** + * Started from + */ private int offset; - @ApiModelProperty( - name = "sortBy", - value = "Ascending or descending order", - required = false) + /** + * Ascending or descending order + */ private String sortBy; + /** + * Set as True if required to have only published application release, otherwise set to False + */ + private boolean requirePublishedRelease; + public int getLimit() { return limit; } @@ -121,4 +118,12 @@ public class Filter { public void setAppCategory(String appCategory) { this.appCategory = appCategory; } + + public boolean isRequirePublishedRelease() { + return requirePublishedRelease; + } + + public void setRequirePublishedRelease(boolean requirePublishedRelease) { + this.requirePublishedRelease = requirePublishedRelease; + } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index 44733a2f377..a4260704d47 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -90,10 +90,11 @@ public interface ApplicationManager { * To get Application with the given Id. * * @param id id of the Application + * @param requirePublishedReleases If it is required to have only published application release set to True, otherwise set to false * @return the Application identified by the UUID * @throws ApplicationManagementException Application Management Exception. */ - Application getApplicationById(int id) throws ApplicationManagementException; + Application getApplicationById(int id, boolean requirePublishedReleases) throws ApplicationManagementException; /** * To get an application associated with the release. 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 adf98a7c188..2ca8c4b2501 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 @@ -218,7 +218,7 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationList = getRoleRestrictedApplicationList(applicationList, userName); } for (Application application : applicationList.getApplications()) { - applicationReleases = getReleases(application, false); + applicationReleases = getReleases(application, filter.isRequirePublishedRelease()); application.setApplicationReleases(applicationReleases); } } @@ -275,7 +275,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public Application getApplicationById(int id) throws ApplicationManagementException { + public Application getApplicationById(int id, boolean requirePublishedReleases) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); Application application; @@ -286,7 +286,7 @@ public class ApplicationManagerImpl implements ApplicationManager { application = ApplicationManagementDAOFactory.getApplicationDAO() .getApplicationById(id, tenantId); if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { - applicationReleases = getReleases(application, false); + applicationReleases = getReleases(application, requirePublishedReleases); application.setApplicationReleases(applicationReleases); return application; } @@ -303,7 +303,7 @@ public class ApplicationManagerImpl implements ApplicationManager { return null; } - applicationReleases = getReleases(application, false); + applicationReleases = getReleases(application, requirePublishedReleases); application.setApplicationReleases(applicationReleases); return application; } catch (UserStoreException e) { 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 3459bd7d816..1151dc3d6ec 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 @@ -141,6 +141,10 @@ public interface ApplicationManagementAPI { name = "exact-match", value = "Is it requesting exactly matching application or partially matching application.") @QueryParam("exact-match") boolean isFullMatch, + @ApiParam( + name = "published-release", + value = "If set to True, only get published release for the application") + @QueryParam("published-release") boolean requirePublishedReleases, @ApiParam( name = "offset", value = "offset", @@ -190,6 +194,10 @@ public interface ApplicationManagementAPI { response = ErrorResponse.class) }) Response getApplication( + @ApiParam( + name = "published-release", + value = "If set to True, only get published release for the application") + @QueryParam("published-release") boolean requirePublishedReleases, @ApiParam( name = "appId", value = "application Id", 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 eec6282e856..2b1ee720cb3 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 @@ -49,7 +49,6 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; /** @@ -69,6 +68,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @QueryParam("type") String appType, @QueryParam("category") String appCategory, @QueryParam("exact-match") boolean isFullMatch, + @QueryParam("published-release") boolean requirePublishedReleases, @DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("20") @QueryParam("limit") int limit, @DefaultValue("ASC") @QueryParam("sort") String sortBy) { @@ -80,6 +80,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { filter.setLimit(limit); filter.setSortBy(sortBy); filter.setFullMatch(isFullMatch); + filter.setRequirePublishedRelease(requirePublishedReleases); if (appName != null && !appName.isEmpty()) { filter.setAppName(appName); } @@ -107,10 +108,11 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @Consumes("application/json") @Path("/{appId}") public Response getApplication( + @QueryParam("published-release") boolean requirePublishedReleases, @PathParam("appId") int appId) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { - Application application = applicationManager.getApplicationById(appId); + Application application = applicationManager.getApplicationById(appId, requirePublishedReleases); if (application == null) { return Response.status(Response.Status.NOT_FOUND).entity ("Application with application id: " + appId + " not found").build();