forked from community/device-mgt-core
parent
c392f0e57d
commit
f17c36d13f
@ -1,206 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) 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
|
|
||||||
*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
import io.swagger.annotations.*;
|
|
||||||
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
|
|
||||||
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
|
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
|
||||||
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
|
|
||||||
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* APIs to handle application management related tasks.
|
|
||||||
*/
|
|
||||||
@SwaggerDefinition(
|
|
||||||
info = @Info(
|
|
||||||
version = "1.0.0",
|
|
||||||
title = "Application Management Service",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = "name", value = "ApplicationManagementService"),
|
|
||||||
@ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/applications"),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
),
|
|
||||||
tags = {
|
|
||||||
@Tag(name = "application_management, device_management", description = "Application Management related "
|
|
||||||
+ "APIs")
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@Scopes(
|
|
||||||
scopes = {
|
|
||||||
@Scope(
|
|
||||||
name = "Get Application Details",
|
|
||||||
description = "Get application details",
|
|
||||||
key = "perm:application:get",
|
|
||||||
permissions = {"/device-mgt/application/get"}
|
|
||||||
),
|
|
||||||
@Scope(
|
|
||||||
name = "Create an Application",
|
|
||||||
description = "Create an application",
|
|
||||||
key = "perm:application:create",
|
|
||||||
permissions = {"/device-mgt/application/create"}
|
|
||||||
),
|
|
||||||
@Scope(
|
|
||||||
name = "Update an Application",
|
|
||||||
description = "Update an application",
|
|
||||||
key = "perm:application:update",
|
|
||||||
permissions = {"/device-mgt/application/update"}
|
|
||||||
),
|
|
||||||
@Scope(
|
|
||||||
name = "Create an Application",
|
|
||||||
description = "Create an application",
|
|
||||||
key = "perm:application-mgt:login",
|
|
||||||
permissions = {"/device-mgt/application-mgt/login"}
|
|
||||||
),
|
|
||||||
@Scope(
|
|
||||||
name = "Delete an Application",
|
|
||||||
description = "Delete an application",
|
|
||||||
key = "perm:application:delete",
|
|
||||||
permissions = {"/device-mgt/application/delete"}
|
|
||||||
),
|
|
||||||
@Scope(
|
|
||||||
name = "Create an application category",
|
|
||||||
description = "Create an application category",
|
|
||||||
key = "perm:application-category:create",
|
|
||||||
permissions = {"/device-mgt/application/category/create"}
|
|
||||||
),
|
|
||||||
@Scope(
|
|
||||||
name = "Delete an Application category",
|
|
||||||
description = "Delete an application category",
|
|
||||||
key = "perm:application-category:delete",
|
|
||||||
permissions = {"/device-mgt/application/category/delete"}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@Path("/publisher/release")
|
|
||||||
@Api(value = "Application Management", description = "This API carries all application management related operations " +
|
|
||||||
"such as get all the applications, add application, etc.")
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
public interface ApplicationReleaseManagementAPI {
|
|
||||||
|
|
||||||
|
|
||||||
String SCOPE = "scope";
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/release-artifacts/{uuid}/{version}")
|
|
||||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
|
||||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
|
||||||
@ApiOperation(
|
|
||||||
consumes = MediaType.APPLICATION_JSON,
|
|
||||||
produces = MediaType.APPLICATION_OCTET_STREAM,
|
|
||||||
httpMethod = "GET",
|
|
||||||
value = "Get an application release",
|
|
||||||
notes = "This will return the application release indicated by Application UUID and version",
|
|
||||||
tags = "Application Management",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = SCOPE, value = "perm:application:get")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ApiResponses(
|
|
||||||
value = {
|
|
||||||
@ApiResponse(
|
|
||||||
code = 200,
|
|
||||||
message = "OK. \n Successfully retrieved the Application release.",
|
|
||||||
response = Attachment.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 500,
|
|
||||||
message = "Internal Server Error. \n Error occurred while releasing the application.",
|
|
||||||
response = ErrorResponse.class)
|
|
||||||
})
|
|
||||||
Response getApplicationReleaseArtifacts(
|
|
||||||
@ApiParam(name = "UUID", value = "Unique identifier of the Application", required = true) @PathParam("uuid") String applicationUUID,
|
|
||||||
@ApiParam(name = "Version", value = "Version of the Application release need to be retrieved", required = true) @PathParam("version") String version);
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/release/{uuid}")
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
@ApiOperation(
|
|
||||||
consumes = MediaType.APPLICATION_JSON,
|
|
||||||
produces = MediaType.APPLICATION_JSON,
|
|
||||||
httpMethod = "GET",
|
|
||||||
value = "Get all the releases or specific release of an application",
|
|
||||||
notes = "This will retrieve the all the releases or specific release of an application",
|
|
||||||
tags = "Application Management",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = SCOPE, value = "perm:application:get")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ApiResponses(
|
|
||||||
value = {
|
|
||||||
@ApiResponse(
|
|
||||||
code = 200,
|
|
||||||
message = "OK. \n Successfully retrieved the Application release."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 500,
|
|
||||||
message = "Internal Server Error. \n Error occurred while releasing the application.",
|
|
||||||
response = ErrorResponse.class)
|
|
||||||
})
|
|
||||||
Response getApplicationReleasesById(
|
|
||||||
@ApiParam(name = "ID", value = "Identifier of the Application", required = true) @PathParam("uuid") String applicationUUID,
|
|
||||||
@ApiParam(name = "version", value = "Version of the application", required = false) @QueryParam("version") String version);
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/image-artifacts/{uuid}")
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
@ApiOperation(
|
|
||||||
consumes = MediaType.APPLICATION_JSON,
|
|
||||||
produces = MediaType.APPLICATION_JSON,
|
|
||||||
httpMethod = "DELETE",
|
|
||||||
value = "Delete the releases of a particular applicaion",
|
|
||||||
notes = "This will delete the releases or specific release of an application",
|
|
||||||
tags = "Application Management",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = SCOPE, value = "perm:application:get")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ApiResponses(
|
|
||||||
value = {
|
|
||||||
@ApiResponse(
|
|
||||||
code = 200,
|
|
||||||
message = "OK. \n Successfully deleted the Application release."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 500,
|
|
||||||
message = "Internal Server Error. \n Error occurred while deleting the release of a"
|
|
||||||
+ "particular application.",
|
|
||||||
response = ErrorResponse.class)
|
|
||||||
})
|
|
||||||
Response getApplicationImageArtifacts(
|
|
||||||
@ApiParam(name = "UUID", value = "Unique identifier of the Application", required = true) @PathParam("uuid") String applicationUUID,
|
|
||||||
@ApiParam(name = "name", value = "Name of the artifact to be retrieved", required = true) @QueryParam("name") String name,
|
|
||||||
@ApiParam(name = "count", value = "Count of the screen-shot artifact to be retrieved", required = false) @QueryParam("count") int count);
|
|
||||||
|
|
||||||
}
|
|
@ -1,127 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) 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
|
|
||||||
*
|
|
||||||
* 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.apache.cxf.jaxrs.ext.multipart.Attachment;
|
|
||||||
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
|
|
||||||
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
|
|
||||||
import org.wso2.carbon.device.application.mgt.common.ImageArtifact;
|
|
||||||
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
|
||||||
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
|
|
||||||
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
|
|
||||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager;
|
|
||||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
|
|
||||||
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
|
|
||||||
import org.wso2.carbon.device.application.mgt.store.api.APIUtil;
|
|
||||||
import org.wso2.carbon.device.application.mgt.store.api.FileStreamingOutput;
|
|
||||||
import org.wso2.carbon.device.application.mgt.store.api.services.ApplicationReleaseManagementAPI;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of Application Management related APIs.
|
|
||||||
*/
|
|
||||||
@Produces({"application/json"})
|
|
||||||
@Path("/publisher/release")
|
|
||||||
public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseManagementAPI {
|
|
||||||
|
|
||||||
private static final int DEFAULT_LIMIT = 20;
|
|
||||||
private static Log log = LogFactory.getLog(ApplicationReleaseManagementAPIImpl.class);
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@GET
|
|
||||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
|
||||||
@Path("/release-artifacts/{uuid}/{version}")
|
|
||||||
public Response getApplicationReleaseArtifacts(@PathParam("uuid") String applicationUUID,
|
|
||||||
@PathParam("version") String version) {
|
|
||||||
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
|
||||||
try {
|
|
||||||
InputStream binaryFile = applicationStorageManager.getReleasedArtifacts(applicationUUID, version);
|
|
||||||
FileStreamingOutput fileStreamingOutput = new FileStreamingOutput(binaryFile);
|
|
||||||
Response.ResponseBuilder response = Response.status(Response.Status.OK).entity(fileStreamingOutput);
|
|
||||||
response.header("Content-Disposition", "attachment; filename=\"" + version + "\"");
|
|
||||||
return response.build();
|
|
||||||
} catch (ApplicationStorageManagementException e) {
|
|
||||||
log.error("Error while retrieving the binary file of the application release for the application UUID " +
|
|
||||||
applicationUUID + " and version " + version, e);
|
|
||||||
if (e.getMessage().contains("Binary file does not exist")) {
|
|
||||||
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
|
|
||||||
} else {
|
|
||||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Path("/release/{uuid}")
|
|
||||||
@GET
|
|
||||||
public Response getApplicationReleasesById(@PathParam("uuid") String applicationUUID,
|
|
||||||
@QueryParam("version") String version) {
|
|
||||||
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
|
|
||||||
try {
|
|
||||||
if (version == null || version.isEmpty()) {
|
|
||||||
List<ApplicationRelease> applicationReleases = applicationReleaseManager.getReleases(applicationUUID);
|
|
||||||
return Response.status(Response.Status.OK).entity(applicationReleases).build();
|
|
||||||
} else {
|
|
||||||
ApplicationRelease applicationRelease = applicationReleaseManager.getRelease(applicationUUID, version);
|
|
||||||
return Response.status(Response.Status.OK).entity(applicationRelease).build();
|
|
||||||
}
|
|
||||||
} catch (NotFoundException e) {
|
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
|
||||||
} catch (ApplicationManagementException e) {
|
|
||||||
log.error("Error while getting all the application releases for the application with the UUID "
|
|
||||||
+ applicationUUID, e);
|
|
||||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@GET
|
|
||||||
@Path("/image-artifacts/{uuid}")
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
public Response getApplicationImageArtifacts(@PathParam("uuid") String applicationUUID,
|
|
||||||
@QueryParam("name") String name, @QueryParam("count") int count) {
|
|
||||||
if (name == null || name.isEmpty()) {
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity("Name should not be null. Name is mandatory to"
|
|
||||||
+ " retrieve the particular image artifact of the release").build();
|
|
||||||
}
|
|
||||||
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
|
||||||
try {
|
|
||||||
ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(applicationUUID, name, count);
|
|
||||||
Response.ResponseBuilder response = Response.status(Response.Status.OK).entity(imageArtifact);
|
|
||||||
return response.build();
|
|
||||||
} catch (ApplicationStorageManagementException e) {
|
|
||||||
log.error("Application Storage Management Exception while getting the image artifact " + name + " of "
|
|
||||||
+ "the application with UUID " + applicationUUID, e);
|
|
||||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in new issue