|
|
|
@ -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 (appType != null && !appType.isEmpty()) {
|
|
|
|
|
filter.setAppType(appType);
|
|
|
|
|
if (filter == null) {
|
|
|
|
|
String msg = "Request Payload is null";
|
|
|
|
|
log.error(msg);
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
|
}
|
|
|
|
|
// 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";
|
|
|
|
|