mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Add APPM store APIs for getting application data
This commit is contained in:
parent
f356b0df6b
commit
8a6411bac6
@ -124,7 +124,7 @@ public interface ApplicationManager {
|
||||
* @return the ApplicationDTO identified by the ID
|
||||
* @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.
|
||||
@ -252,4 +252,6 @@ public interface ApplicationManager {
|
||||
|
||||
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;
|
||||
try {
|
||||
conn = this.getDBConnection();
|
||||
String sql =
|
||||
"SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY "
|
||||
+ "AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP.CURRENCY AS CURRENCY, "
|
||||
+ "AP_APP.RESTRICTED AS RESTRICTED, AP_APP.DEVICE_TYPE_ID AS DEVICE_TYPE_ID, "
|
||||
+ "AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLE.ROLE AS "
|
||||
+ "ROLE FROM ((AP_APP LEFT JOIN AP_APP_TAG ON AP_APP.ID = AP_APP_TAG.AP_APP_ID) "
|
||||
+ "LEFT JOIN AP_UNRESTRICTED_ROLE ON AP_APP.ID = AP_UNRESTRICTED_ROLE.AP_APP_ID) "
|
||||
+ "WHERE AP_APP.ID = (SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID =? ) AND "
|
||||
+ "AP_APP.TENANT_ID = ? AND AP_APP.STATUS != ?;";
|
||||
String sql = "SELECT "
|
||||
+ "AP_APP.ID AS APP_ID, "
|
||||
+ "AP_APP.NAME AS APP_NAME, "
|
||||
+ "AP_APP.DESCRIPTION AS APP_DESCRIPTION, "
|
||||
+ "AP_APP.TYPE AS APP_TYPE, "
|
||||
+ "AP_APP.STATUS AS APP_STATUS, "
|
||||
+ "AP_APP.SUB_TYPE AS APP_SUB_TYPE, "
|
||||
+ "AP_APP.CURRENCY AS APP_CURRENCY, "
|
||||
+ "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.setString(1, releaseUuid);
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.setString(3, AppLifecycleState.RETIRED.toString());
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
|
||||
@ -625,11 +625,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
|
||||
@Override
|
||||
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);
|
||||
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
ApplicationList applicationList = new ApplicationList();
|
||||
@ -845,10 +840,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
filteredApplicationReleaseDTOs.add(applicationReleaseDTO);
|
||||
}
|
||||
}
|
||||
applicationDTO.setApplicationReleaseDTOs(filteredApplicationReleaseDTOs);
|
||||
if (applicationDTO.getApplicationReleaseDTOs().isEmpty()){
|
||||
if (state != null && filteredApplicationReleaseDTOs.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
applicationDTO.setApplicationReleaseDTOs(filteredApplicationReleaseDTOs);
|
||||
|
||||
List<String> tags = this.applicationDAO.getAppTags(appId, tenantId);
|
||||
List<String> categories = this.applicationDAO.getAppCategories(appId, tenantId);
|
||||
@ -856,9 +851,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
if (!categories.isEmpty()){
|
||||
applicationDTO.setAppCategories(categories);
|
||||
}
|
||||
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
|
||||
return appDtoToAppResponse(applicationDTO);
|
||||
}
|
||||
|
||||
List<String> unrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(appId, tenantId);
|
||||
if (!unrestrictedRoles.isEmpty()) {
|
||||
@ -944,44 +936,66 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
|
||||
|
||||
@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);
|
||||
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
ApplicationDTO application;
|
||||
boolean isAppAllowed = false;
|
||||
List<ApplicationReleaseDTO> applicationReleases;
|
||||
boolean isVisibleApp = false;
|
||||
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
application = this.applicationDAO.getApplicationByUUID(uuid, tenantId);
|
||||
if (application == null) {
|
||||
throw new NotFoundException("Couldn't find an application for application release UUID:: " + uuid);
|
||||
}
|
||||
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
|
||||
applicationReleases = getReleases(application, state);
|
||||
application.setApplicationReleaseDTOs(applicationReleases);
|
||||
return application;
|
||||
ApplicationDTO applicationDTO = applicationDAO.getApplicationByUUID(uuid, tenantId);
|
||||
|
||||
if (applicationDTO == null) {
|
||||
String msg = "Couldn't found an application for application release UUID: " + uuid;
|
||||
log.error(msg);
|
||||
throw new NotFoundException(msg);
|
||||
}
|
||||
|
||||
if (!application.getUnrestrictedRoles().isEmpty()) {
|
||||
if (hasUserRole(application.getUnrestrictedRoles(), userName)) {
|
||||
isAppAllowed = true;
|
||||
List<ApplicationReleaseDTO> filteredApplicationReleaseDTOs = new ArrayList<>();
|
||||
for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) {
|
||||
if (!applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getEndState()) && (
|
||||
state == null || applicationReleaseDTO.getCurrentState().equals(state))) {
|
||||
filteredApplicationReleaseDTOs.add(applicationReleaseDTO);
|
||||
}
|
||||
} else {
|
||||
isAppAllowed = true;
|
||||
}
|
||||
|
||||
if (!isAppAllowed) {
|
||||
if (state != null && filteredApplicationReleaseDTOs.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
applicationReleases = getReleases(application, state);
|
||||
application.setApplicationReleaseDTOs(applicationReleases);
|
||||
return application;
|
||||
applicationDTO.setApplicationReleaseDTOs(filteredApplicationReleaseDTOs);
|
||||
|
||||
List<String> tags = this.applicationDAO.getAppTags(applicationDTO.getId(), tenantId);
|
||||
List<String> categories = this.applicationDAO.getAppCategories(applicationDTO.getId(), tenantId);
|
||||
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 {
|
||||
isVisibleApp = true;
|
||||
}
|
||||
|
||||
if (!isVisibleApp) {
|
||||
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);
|
||||
}
|
||||
return appDtoToAppResponse(applicationDTO);
|
||||
} catch (LifecycleManagementException e) {
|
||||
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) {
|
||||
throw new ApplicationManagementException(
|
||||
"User-store exception while getting application with the application release UUID " + uuid);
|
||||
String msg = "User-store exception while getting application with the application release UUID " + uuid;
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
//todo
|
||||
throw new ApplicationManagementException("");
|
||||
String msg = "Error occurred while getting, application data.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg);
|
||||
} finally {
|
||||
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 {
|
||||
if (filter == null) {
|
||||
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.",
|
||||
response = ApplicationList.class),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not Found. There doesn't have an application which is matched with requested " +
|
||||
"query."),
|
||||
code = 400,
|
||||
message = "Bad Request. \n " +
|
||||
"Application retrieving request payload contains unacceptable or vulnerable data"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while getting the application list.",
|
||||
|
||||
@ -74,10 +74,14 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
||||
@Override
|
||||
@Consumes("application/json")
|
||||
public Response getApplications(
|
||||
@Valid Filter filter ){
|
||||
@Valid Filter filter) {
|
||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||
|
||||
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);
|
||||
if (applications.getApplications().isEmpty()) {
|
||||
return Response.status(Response.Status.OK)
|
||||
|
||||
@ -1,20 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
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.Scopes;
|
||||
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.ApplicationList;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
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;
|
||||
|
||||
@ -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 " +
|
||||
"such as get all the applications etc.")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@ -80,7 +80,7 @@ public interface ApplicationManagementAPI {
|
||||
|
||||
String SCOPE = "scope";
|
||||
|
||||
@GET
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
@ -103,8 +103,9 @@ public interface ApplicationManagementAPI {
|
||||
message = "OK. \n Successfully got application list.",
|
||||
response = ApplicationList.class),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not Found. Not Found Applications."),
|
||||
code = 400,
|
||||
message = "Bad Request. \n " +
|
||||
"Application retrieving request payload contains unacceptable or vulnerable data"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while getting the application list.",
|
||||
@ -112,34 +113,10 @@ public interface ApplicationManagementAPI {
|
||||
})
|
||||
Response getApplications(
|
||||
@ApiParam(
|
||||
name = "name",
|
||||
value = "Name of the application")
|
||||
@QueryParam("name") String appName,
|
||||
@ApiParam(
|
||||
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
|
||||
|
||||
name = "filter",
|
||||
value = "Application filtering data",
|
||||
required = true)
|
||||
@Valid Filter filter
|
||||
);
|
||||
|
||||
@GET
|
||||
|
||||
@ -1,90 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.store.api.services.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
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.Filter;
|
||||
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.core.exception.BadRequestException;
|
||||
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.store.api.services.ApplicationManagementAPI;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DefaultValue;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
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.Response;
|
||||
|
||||
/**
|
||||
* Implementation of Application Management related APIs.
|
||||
* Implementation of Application Management STORE APIs.
|
||||
*/
|
||||
@Produces({ "application/json" })
|
||||
@Path("/store/applications")
|
||||
@Path("/applications")
|
||||
public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
|
||||
private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class);
|
||||
|
||||
@GET
|
||||
@POST
|
||||
@Override
|
||||
@Consumes("application/json")
|
||||
public Response getApplications(
|
||||
@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) {
|
||||
|
||||
public Response getApplications(@Valid Filter filter) {
|
||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||
try {
|
||||
Filter filter = new Filter();
|
||||
filter.setOffset(offset);
|
||||
filter.setLimit(limit);
|
||||
filter.setSortBy(sortBy);
|
||||
filter.setFullMatch(isFullMatch);
|
||||
filter.setAppReleaseState(AppLifecycleState.PUBLISHED.toString());
|
||||
if (appName != null && !appName.isEmpty()) {
|
||||
filter.setAppName(appName);
|
||||
if (filter == null) {
|
||||
String msg = "Request Payload is null";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
}
|
||||
if (appType != null && !appType.isEmpty()) {
|
||||
filter.setAppType(appType);
|
||||
}
|
||||
// if (appCategory != null && !appCategory.isEmpty()) {
|
||||
// filter.setAppCategories(appCategory);
|
||||
// }
|
||||
filter.setAppReleaseState(applicationManager.getInstallableLifecycleState());
|
||||
ApplicationList applications = applicationManager.getApplications(filter);
|
||||
if (applications.getApplications().isEmpty()) {
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.entity("Couldn't find any application for requested query.").build();
|
||||
return Response.status(Response.Status.OK)
|
||||
.entity("Couldn't find any application for the requested query.").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) {
|
||||
String msg = "Error occurred while getting the application list for publisher ";
|
||||
String msg = e.getMessage();
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
@ -93,12 +83,17 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
|
||||
@GET
|
||||
@Consumes("application/json")
|
||||
@Path("/{uuid}")
|
||||
public Response getApplication(
|
||||
@PathParam("uuid") String uuid) {
|
||||
public Response getApplication(@PathParam("uuid") String uuid) {
|
||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||
try {
|
||||
ApplicationDTO application = applicationManager
|
||||
.getApplicationByUuid(uuid, AppLifecycleState.PUBLISHED.toString());
|
||||
Application application = applicationManager
|
||||
.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();
|
||||
} catch (NotFoundException e) {
|
||||
String msg = "Application with application release UUID: " + uuid + " is not found";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user