|
|
@ -1,90 +1,80 @@
|
|
|
|
/*
|
|
|
|
/* 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
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
|
|
|
|
* 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;
|
|
|
|
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";
|
|
|
|