Add APPM store APIs for getting application data

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent f356b0df6b
commit 8a6411bac6

@ -124,7 +124,7 @@ public interface ApplicationManager {
* @return the ApplicationDTO identified by the ID * @return the ApplicationDTO identified by the ID
* @throws ApplicationManagementException ApplicationDTO Management Exception. * @throws ApplicationManagementException ApplicationDTO Management Exception.
*/ */
ApplicationDTO getApplicationByUuid(String uuid, String state) throws ApplicationManagementException; Application getApplicationByUuid(String uuid, String state) throws ApplicationManagementException;
/** /**
* To get an application associated with the release. * To get an application associated with the release.
@ -252,4 +252,6 @@ public interface ApplicationManager {
void updateCategory(String oldCategoryName, String newCategoryName) throws ApplicationManagementException; void updateCategory(String oldCategoryName, String newCategoryName) throws ApplicationManagementException;
String getInstallableLifecycleState() throws ApplicationManagementException;
} }

@ -444,20 +444,45 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
ResultSet rs = null; ResultSet rs = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = String sql = "SELECT "
"SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " + "AP_APP.ID AS APP_ID, "
+ "AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP.CURRENCY AS CURRENCY, " + "AP_APP.NAME AS APP_NAME, "
+ "AP_APP.RESTRICTED AS RESTRICTED, AP_APP.DEVICE_TYPE_ID AS DEVICE_TYPE_ID, " + "AP_APP.DESCRIPTION AS APP_DESCRIPTION, "
+ "AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLE.ROLE AS " + "AP_APP.TYPE AS APP_TYPE, "
+ "ROLE FROM ((AP_APP LEFT JOIN AP_APP_TAG ON AP_APP.ID = AP_APP_TAG.AP_APP_ID) " + "AP_APP.STATUS AS APP_STATUS, "
+ "LEFT JOIN AP_UNRESTRICTED_ROLE ON AP_APP.ID = AP_UNRESTRICTED_ROLE.AP_APP_ID) " + "AP_APP.SUB_TYPE AS APP_SUB_TYPE, "
+ "WHERE AP_APP.ID = (SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID =? ) AND " + "AP_APP.CURRENCY AS APP_CURRENCY, "
+ "AP_APP.TENANT_ID = ? AND AP_APP.STATUS != ?;"; + "AP_APP.RATING AS APP_RATING, "
+ "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, "
+ "AP_APP_RELEASE.ID AS RELEASE_ID, "
+ "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, "
+ "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, "
+ "AP_APP_RELEASE.UUID AS RELEASE_UUID, "
+ "AP_APP_RELEASE.RELEASE_TYPE AS RELEASE_TYPE, "
+ "AP_APP_RELEASE.INSTALLER_LOCATION AS AP_RELEASE_STORED_LOC, "
+ "AP_APP_RELEASE.ICON_LOCATION AS AP_RELEASE_ICON_LOC, "
+ "AP_APP_RELEASE.BANNER_LOCATION AS AP_RELEASE_BANNER_LOC, "
+ "AP_APP_RELEASE.SC_1_LOCATION AS AP_RELEASE_SC1, "
+ "AP_APP_RELEASE.SC_2_LOCATION AS AP_RELEASE_SC2, "
+ "AP_APP_RELEASE.SC_3_LOCATION AS AP_RELEASE_SC3, "
+ "AP_APP_RELEASE.APP_HASH_VALUE AS RELEASE_HASH_VALUE, "
+ "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, "
+ "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, "
+ "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, "
+ "AP_APP_RELEASE.RATING AS RELEASE_RATING, "
+ "AP_APP_RELEASE.CURRENT_STATE AS RELEASE_CURRENT_STATE, "
+ "AP_APP_RELEASE.RATED_USERS AS RATED_USER_COUNT "
+ "FROM AP_APP "
+ "INNER JOIN AP_APP_RELEASE ON "
+ "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID AND "
+ "AP_APP.TENANT_ID = AP_APP_RELEASE.TENANT_ID "
+ "WHERE "
+ "AP_APP.ID = (SELECT AP_APP_RELEASE.AP_APP_ID FROM AP_APP_RELEASE WHERE AP_APP_RELEASE.UUID = ?) "
+ "AND AP_APP.TENANT_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, releaseUuid); stmt.setString(1, releaseUuid);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
stmt.setString(3, AppLifecycleState.RETIRED.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

@ -625,11 +625,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override @Override
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
if (filter == null) {
String msg = "Request Payload is null";
log.error(msg);
throw new BadRequestException(msg);
}
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
ApplicationList applicationList = new ApplicationList(); ApplicationList applicationList = new ApplicationList();
@ -845,10 +840,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
filteredApplicationReleaseDTOs.add(applicationReleaseDTO); filteredApplicationReleaseDTOs.add(applicationReleaseDTO);
} }
} }
applicationDTO.setApplicationReleaseDTOs(filteredApplicationReleaseDTOs); if (state != null && filteredApplicationReleaseDTOs.isEmpty()) {
if (applicationDTO.getApplicationReleaseDTOs().isEmpty()){
return null; return null;
} }
applicationDTO.setApplicationReleaseDTOs(filteredApplicationReleaseDTOs);
List<String> tags = this.applicationDAO.getAppTags(appId, tenantId); List<String> tags = this.applicationDAO.getAppTags(appId, tenantId);
List<String> categories = this.applicationDAO.getAppCategories(appId, tenantId); List<String> categories = this.applicationDAO.getAppCategories(appId, tenantId);
@ -856,9 +851,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (!categories.isEmpty()){ if (!categories.isEmpty()){
applicationDTO.setAppCategories(categories); applicationDTO.setAppCategories(categories);
} }
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
return appDtoToAppResponse(applicationDTO);
}
List<String> unrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(appId, tenantId); List<String> unrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(appId, tenantId);
if (!unrestrictedRoles.isEmpty()) { if (!unrestrictedRoles.isEmpty()) {
@ -944,44 +936,66 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override @Override
public ApplicationDTO getApplicationByUuid(String uuid, String state) throws ApplicationManagementException { public Application getApplicationByUuid(String uuid, String state) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
ApplicationDTO application; boolean isVisibleApp = false;
boolean isAppAllowed = false;
List<ApplicationReleaseDTO> applicationReleases;
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
application = this.applicationDAO.getApplicationByUUID(uuid, tenantId); ApplicationDTO applicationDTO = applicationDAO.getApplicationByUUID(uuid, tenantId);
if (application == null) {
throw new NotFoundException("Couldn't find an application for application release UUID:: " + uuid); if (applicationDTO == null) {
String msg = "Couldn't found an application for application release UUID: " + uuid;
log.error(msg);
throw new NotFoundException(msg);
} }
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
applicationReleases = getReleases(application, state); List<ApplicationReleaseDTO> filteredApplicationReleaseDTOs = new ArrayList<>();
application.setApplicationReleaseDTOs(applicationReleases); for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) {
return application; if (!applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getEndState()) && (
state == null || applicationReleaseDTO.getCurrentState().equals(state))) {
filteredApplicationReleaseDTOs.add(applicationReleaseDTO);
} }
}
if (state != null && filteredApplicationReleaseDTOs.isEmpty()) {
return null;
}
applicationDTO.setApplicationReleaseDTOs(filteredApplicationReleaseDTOs);
if (!application.getUnrestrictedRoles().isEmpty()) { List<String> tags = this.applicationDAO.getAppTags(applicationDTO.getId(), tenantId);
if (hasUserRole(application.getUnrestrictedRoles(), userName)) { List<String> categories = this.applicationDAO.getAppCategories(applicationDTO.getId(), tenantId);
isAppAllowed = true; applicationDTO.setTags(tags);
applicationDTO.setAppCategories(categories);
List<String> unrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(applicationDTO.getId(), tenantId);
if (!unrestrictedRoles.isEmpty()) {
if (hasUserRole(unrestrictedRoles, userName)) {
isVisibleApp = true;
} }
} else { } else {
isAppAllowed = true; isVisibleApp = true;
} }
if (!isAppAllowed) { if (!isVisibleApp) {
return null; String msg = "You are trying to access visibility restricted application. You don't have required "
+ "roles to view this application,";
log.error(msg);
throw new ForbiddenException(msg);
} }
applicationReleases = getReleases(application, state); return appDtoToAppResponse(applicationDTO);
application.setApplicationReleaseDTOs(applicationReleases); } catch (LifecycleManagementException e) {
return application; String msg = "Error occurred when getting the last state of the application lifecycle flow";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (UserStoreException e) { } catch (UserStoreException e) {
throw new ApplicationManagementException( String msg = "User-store exception while getting application with the application release UUID " + uuid;
"User-store exception while getting application with the application release UUID " + uuid); log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
//todo String msg = "Error occurred while getting, application data.";
throw new ApplicationManagementException(""); log.error(msg);
throw new ApplicationManagementException(msg);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -2198,6 +2212,17 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
@Override
public String getInstallableLifecycleState() throws ApplicationManagementException {
if (lifecycleStateManager == null) {
String msg = "Application lifecycle manager is not initialed. Please contact the administrator.";
log.error(msg);
throw new ApplicationManagementException(msg);
}
return lifecycleStateManager.getInstallableState();
}
private void validateFilter(Filter filter) throws BadRequestException { private void validateFilter(Filter filter) throws BadRequestException {
if (filter == null) { if (filter == null) {
String msg = "Filter validation is failed, Filter shouldn't be null, hence please verify the request payload"; String msg = "Filter validation is failed, Filter shouldn't be null, hence please verify the request payload";

@ -121,9 +121,9 @@ public interface ApplicationManagementPublisherAPI {
message = "OK. \n Successfully got application list.", message = "OK. \n Successfully got application list.",
response = ApplicationList.class), response = ApplicationList.class),
@ApiResponse( @ApiResponse(
code = 404, code = 400,
message = "Not Found. There doesn't have an application which is matched with requested " + message = "Bad Request. \n " +
"query."), "Application retrieving request payload contains unacceptable or vulnerable data"),
@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.",

@ -74,10 +74,14 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Override @Override
@Consumes("application/json") @Consumes("application/json")
public Response getApplications( public Response getApplications(
@Valid Filter filter ){ @Valid Filter filter) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
if (filter == null) {
String msg = "Request Payload is null";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
ApplicationList applications = applicationManager.getApplications(filter); ApplicationList applications = applicationManager.getApplications(filter);
if (applications.getApplications().isEmpty()) { if (applications.getApplications().isEmpty()) {
return Response.status(Response.Status.OK) return Response.status(Response.Status.OK)

@ -1,7 +1,6 @@
/* /* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +13,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.application.mgt.store.api.services; package org.wso2.carbon.device.application.mgt.store.api.services;
@ -31,15 +29,17 @@ import io.swagger.annotations.Tag;
import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.common.ErrorResponse; import org.wso2.carbon.device.application.mgt.common.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import javax.validation.Valid;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path; 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.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@ -72,7 +72,7 @@ import javax.ws.rs.core.Response;
) )
} }
) )
@Path("/store/applications") @Path("/applications")
@Api(value = "ApplicationDTO Management", description = "This API carries all app store management related operations " + @Api(value = "ApplicationDTO Management", description = "This API carries all app store management related operations " +
"such as get all the applications etc.") "such as get all the applications etc.")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -80,7 +80,7 @@ public interface ApplicationManagementAPI {
String SCOPE = "scope"; String SCOPE = "scope";
@GET @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
@ -103,8 +103,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 = 404, code = 400,
message = "Not Found. Not Found Applications."), message = "Bad Request. \n " +
"Application retrieving request payload contains unacceptable or vulnerable data"),
@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.",
@ -112,34 +113,10 @@ public interface ApplicationManagementAPI {
}) })
Response getApplications( Response getApplications(
@ApiParam( @ApiParam(
name = "name", name = "filter",
value = "Name of the application") value = "Application filtering data",
@QueryParam("name") String appName, required = true)
@ApiParam( @Valid Filter filter
name = "type",
value = "Type of the application")
@QueryParam("type") String appType,
@ApiParam(
name = "category",
value = "CategoryDTO of the application")
@QueryParam("category") String appCategory,
@ApiParam(
name = "exact-match",
value = "Is it requesting exactly matching application or partially matching application.")
@QueryParam("exact-match") boolean isFullMatch,
@ApiParam(
name = "offset",
value = "Provide from which position apps should return", defaultValue = "0")
@QueryParam("offset") int offset,
@ApiParam(
name = "limit",
value = "Provide how many apps it should return", defaultValue = "20")
@QueryParam("limit") int limit,
@ApiParam(
name = "limit",
value = "Provide how many apps it should return", defaultValue = "ASC")
@QueryParam("sort") String sortBy
); );
@GET @GET

@ -1,7 +1,6 @@
/* /* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,77 +13,68 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.application.mgt.store.api.services.impl; package org.wso2.carbon.device.application.mgt.store.api.services.impl;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.AppLifecycleState;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.response.Application;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
import org.wso2.carbon.device.application.mgt.core.util.APIUtil; import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
import org.wso2.carbon.device.application.mgt.store.api.services.ApplicationManagementAPI; import org.wso2.carbon.device.application.mgt.store.api.services.ApplicationManagementAPI;
import javax.validation.Valid;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path; 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.core.Response; import javax.ws.rs.core.Response;
/** /**
* Implementation of Application Management related APIs. * Implementation of Application Management STORE APIs.
*/ */
@Produces({ "application/json" }) @Produces({ "application/json" })
@Path("/store/applications") @Path("/applications")
public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class); private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class);
@GET @POST
@Override @Override
@Consumes("application/json") @Consumes("application/json")
public Response getApplications( public Response getApplications(@Valid Filter filter) {
@QueryParam("name") String appName,
@QueryParam("type") String appType,
@QueryParam("category") String appCategory,
@QueryParam("exact-match") boolean isFullMatch,
@DefaultValue("0") @QueryParam("offset") int offset,
@DefaultValue("20") @QueryParam("limit") int limit,
@DefaultValue("ASC") @QueryParam("sort") String sortBy) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
Filter filter = new Filter(); if (filter == null) {
filter.setOffset(offset); String msg = "Request Payload is null";
filter.setLimit(limit); log.error(msg);
filter.setSortBy(sortBy); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
filter.setFullMatch(isFullMatch);
filter.setAppReleaseState(AppLifecycleState.PUBLISHED.toString());
if (appName != null && !appName.isEmpty()) {
filter.setAppName(appName);
}
if (appType != null && !appType.isEmpty()) {
filter.setAppType(appType);
} }
// if (appCategory != null && !appCategory.isEmpty()) { filter.setAppReleaseState(applicationManager.getInstallableLifecycleState());
// filter.setAppCategories(appCategory);
// }
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) return Response.status(Response.Status.OK)
.entity("Couldn't find any application for requested query.").build(); .entity("Couldn't find any application for the requested query.").build();
} }
return Response.status(Response.Status.OK).entity(applications).build(); return Response.status(Response.Status.OK).entity(applications).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (UnexpectedServerErrorException e) {
String msg = e.getMessage();
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while getting the application list for publisher "; String msg = e.getMessage();
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -93,12 +83,17 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@GET @GET
@Consumes("application/json") @Consumes("application/json")
@Path("/{uuid}") @Path("/{uuid}")
public Response getApplication( public Response getApplication(@PathParam("uuid") String uuid) {
@PathParam("uuid") String uuid) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
ApplicationDTO application = applicationManager Application application = applicationManager
.getApplicationByUuid(uuid, AppLifecycleState.PUBLISHED.toString()); .getApplicationByUuid(uuid, applicationManager.getInstallableLifecycleState());
if (application == null) {
String msg = "Could not found an application release which is in " + applicationManager
.getInstallableLifecycleState() + " state.";
log.error(msg);
return Response.status(Response.Status.OK).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(application).build(); return Response.status(Response.Status.OK).entity(application).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Application with application release UUID: " + uuid + " is not found"; String msg = "Application with application release UUID: " + uuid + " is not found";

Loading…
Cancel
Save