Improve publisher APIs

4.x.x
lasanthaDLPDS 6 years ago
parent abf9c05f0c
commit f4e1ca6815

@ -18,54 +18,51 @@
*/ */
package org.wso2.carbon.device.application.mgt.common; 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. * 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 { public class Filter {
@ApiModelProperty( /**
name = "appName", * Name of the application
value = "Name of the application", */
required = false)
private String appName; private String appName;
@ApiModelProperty( /**
name = "appType", * Type of the application
value = "Type of the application", */
required = false)
private String appType; private String appType;
/**
* Category of the application
*/
private String appCategory; private String appCategory;
@ApiModelProperty( /**
name = "isFullMatch", * Checking the application name matches fully with given name
value = "Checking the application name matches fully with given name", */
required = false)
private boolean isFullMatch; private boolean isFullMatch;
@ApiModelProperty( /**
name = "limit", * Limit of the applications
value = "Limit of the applications", */
required = false)
private int limit; private int limit;
@ApiModelProperty( /**
name = "offset", * Started from
value = "Started from", */
required = false)
private int offset; private int offset;
@ApiModelProperty( /**
name = "sortBy", * Ascending or descending order
value = "Ascending or descending order", */
required = false)
private String sortBy; private String sortBy;
/**
* Set as True if required to have only published application release, otherwise set to False
*/
private boolean requirePublishedRelease;
public int getLimit() { public int getLimit() {
return limit; return limit;
} }
@ -121,4 +118,12 @@ public class Filter {
public void setAppCategory(String appCategory) { public void setAppCategory(String appCategory) {
this.appCategory = appCategory; this.appCategory = appCategory;
} }
public boolean isRequirePublishedRelease() {
return requirePublishedRelease;
}
public void setRequirePublishedRelease(boolean requirePublishedRelease) {
this.requirePublishedRelease = requirePublishedRelease;
}
} }

@ -90,10 +90,11 @@ public interface ApplicationManager {
* To get Application with the given Id. * To get Application with the given Id.
* *
* @param id id of the Application * @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 * @return the Application identified by the UUID
* @throws ApplicationManagementException Application Management Exception. * @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. * To get an application associated with the release.

@ -218,7 +218,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationList = getRoleRestrictedApplicationList(applicationList, userName); applicationList = getRoleRestrictedApplicationList(applicationList, userName);
} }
for (Application application : applicationList.getApplications()) { for (Application application : applicationList.getApplications()) {
applicationReleases = getReleases(application, false); applicationReleases = getReleases(application, filter.isRequirePublishedRelease());
application.setApplicationReleases(applicationReleases); application.setApplicationReleases(applicationReleases);
} }
} }
@ -275,7 +275,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public Application getApplicationById(int id) throws ApplicationManagementException { public Application getApplicationById(int id, boolean requirePublishedReleases) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
Application application; Application application;
@ -286,7 +286,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
application = ApplicationManagementDAOFactory.getApplicationDAO() application = ApplicationManagementDAOFactory.getApplicationDAO()
.getApplicationById(id, tenantId); .getApplicationById(id, tenantId);
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
applicationReleases = getReleases(application, false); applicationReleases = getReleases(application, requirePublishedReleases);
application.setApplicationReleases(applicationReleases); application.setApplicationReleases(applicationReleases);
return application; return application;
} }
@ -303,7 +303,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
return null; return null;
} }
applicationReleases = getReleases(application, false); applicationReleases = getReleases(application, requirePublishedReleases);
application.setApplicationReleases(applicationReleases); application.setApplicationReleases(applicationReleases);
return application; return application;
} catch (UserStoreException e) { } catch (UserStoreException e) {

@ -141,6 +141,10 @@ public interface ApplicationManagementAPI {
name = "exact-match", name = "exact-match",
value = "Is it requesting exactly matching application or partially matching application.") value = "Is it requesting exactly matching application or partially matching application.")
@QueryParam("exact-match") boolean isFullMatch, @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( @ApiParam(
name = "offset", name = "offset",
value = "offset", value = "offset",
@ -190,6 +194,10 @@ public interface ApplicationManagementAPI {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getApplication( Response getApplication(
@ApiParam(
name = "published-release",
value = "If set to True, only get published release for the application")
@QueryParam("published-release") boolean requirePublishedReleases,
@ApiParam( @ApiParam(
name = "appId", name = "appId",
value = "application Id", value = "application Id",

@ -49,7 +49,6 @@ 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.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
/** /**
@ -69,6 +68,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@QueryParam("type") String appType, @QueryParam("type") String appType,
@QueryParam("category") String appCategory, @QueryParam("category") String appCategory,
@QueryParam("exact-match") boolean isFullMatch, @QueryParam("exact-match") boolean isFullMatch,
@QueryParam("published-release") boolean requirePublishedReleases,
@DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("0") @QueryParam("offset") int offset,
@DefaultValue("20") @QueryParam("limit") int limit, @DefaultValue("20") @QueryParam("limit") int limit,
@DefaultValue("ASC") @QueryParam("sort") String sortBy) { @DefaultValue("ASC") @QueryParam("sort") String sortBy) {
@ -80,6 +80,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
filter.setLimit(limit); filter.setLimit(limit);
filter.setSortBy(sortBy); filter.setSortBy(sortBy);
filter.setFullMatch(isFullMatch); filter.setFullMatch(isFullMatch);
filter.setRequirePublishedRelease(requirePublishedReleases);
if (appName != null && !appName.isEmpty()) { if (appName != null && !appName.isEmpty()) {
filter.setAppName(appName); filter.setAppName(appName);
} }
@ -107,10 +108,11 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@Consumes("application/json") @Consumes("application/json")
@Path("/{appId}") @Path("/{appId}")
public Response getApplication( public Response getApplication(
@QueryParam("published-release") boolean requirePublishedReleases,
@PathParam("appId") int appId) { @PathParam("appId") int appId) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
Application application = applicationManager.getApplicationById(appId); Application application = applicationManager.getApplicationById(appId, requirePublishedReleases);
if (application == null) { if (application == null) {
return Response.status(Response.Status.NOT_FOUND).entity return Response.status(Response.Status.NOT_FOUND).entity
("Application with application id: " + appId + " not found").build(); ("Application with application id: " + appId + " not found").build();

Loading…
Cancel
Save