Improve publisher APIs

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent abf9c05f0c
commit f4e1ca6815

@ -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;
}
}

@ -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.

@ -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) {

@ -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",

@ -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();

Loading…
Cancel
Save