Added app release updating fucntionality and fixed APPM related bugs

merge-requests/7/head
lasantha 7 years ago
parent c392f0e57d
commit f17c36d13f

@ -23,11 +23,6 @@ import org.apache.commons.logging.LogFactory;
import org.json.JSONException; import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.common.*; import org.wso2.carbon.device.application.mgt.common.*;
import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.Platform;
import org.wso2.carbon.device.application.mgt.common.User;
import org.wso2.carbon.device.application.mgt.common.Category;
import org.wso2.carbon.device.application.mgt.common.Lifecycle;
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest; import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.exception.CommentManagementException; import org.wso2.carbon.device.application.mgt.common.exception.CommentManagementException;
@ -38,9 +33,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* This class is responsible for handling the utils of the Application Management DAO. * This class is responsible for handling the utils of the Application Management DAO.

@ -82,6 +82,10 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
} }
} }
@Override public ApplicationRelease getReleaseByUuid(String applicationUuid) throws ApplicationManagementException {
return null;
}
@Override @Override
public List<ApplicationRelease> getReleases(int applicationId) throws ApplicationManagementException { public List<ApplicationRelease> getReleases(int applicationId) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);

@ -86,15 +86,21 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
iconStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[0]; iconStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[0];
bannerStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[1]; bannerStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[1];
if (iconFileStream != null){
saveFile(iconFileStream, iconStoredLocation); saveFile(iconFileStream, iconStoredLocation);
saveFile(bannerFileStream, bannerStoredLocation);
applicationRelease.setIconLoc(iconStoredLocation); applicationRelease.setIconLoc(iconStoredLocation);
}
if (bannerFileStream != null){
saveFile(bannerFileStream, bannerStoredLocation);
applicationRelease.setBannerLoc(bannerStoredLocation); applicationRelease.setBannerLoc(bannerStoredLocation);
}
if (screenShotStreams.size() > screenShotMaxCount) { if (screenShotStreams.size() > screenShotMaxCount) {
throw new ApplicationStorageManagementException("Maximum limit for the screen-shot exceeds"); throw new ApplicationStorageManagementException("Maximum limit for the screen-shot exceeds");
} }else if(!screenShotStreams.isEmpty() && screenShotStreams.size() <= screenShotMaxCount){
int count = 1; int count = 1;
for (InputStream screenshotStream : screenShotStreams) { for (InputStream screenshotStream : screenShotStreams) {
scStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[2] + count; scStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[2] + count;
@ -111,6 +117,9 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
count++; count++;
} }
} }
}
return applicationRelease; return applicationRelease;
} catch (IOException e) { } catch (IOException e) {
throw new ApplicationStorageManagementException( throw new ApplicationStorageManagementException(
@ -131,6 +140,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
String artifactDirectoryPath; String artifactDirectoryPath;
String md5OfApp; String md5OfApp;
md5OfApp = getMD5(binaryFile); md5OfApp = getMD5(binaryFile);
//todo validate binary file.
if(validateApplication(applicationId) && md5OfApp != null){ if(validateApplication(applicationId) && md5OfApp != null){
artifactDirectoryPath = storagePath + md5OfApp; artifactDirectoryPath = storagePath + md5OfApp;

@ -75,8 +75,9 @@ public class UnrestrictedRoleManagerImpl implements UnrestrictedRoleManager {
try { try {
VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO(); VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
List<UnrestrictedRole> unrestrictedRoles = visibilityDAO.getUnrestrictedRoles(applicationID, tenantId); List<UnrestrictedRole> unrestrictedRoles = visibilityDAO.getUnrestrictedRoles(applicationID, tenantId);
if (unrestrictedRoles == null) if (unrestrictedRoles == null) {
return null; return null;
}
return unrestrictedRoles; return unrestrictedRoles;
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - " throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - "

@ -194,7 +194,7 @@ public interface ApplicationReleaseManagementAPI {
message = "Internal Server Error. \n Error occurred while getting the application list.", message = "Internal Server Error. \n Error occurred while getting the application list.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response uploadApplicationArtifacts( Response updateApplicationImageArtifacts(
@ApiParam(name = "uuid", value = "UUID of the application", required = true) @PathParam("uuid") String applicationUUID, @ApiParam(name = "uuid", value = "UUID of the application", required = true) @PathParam("uuid") String applicationUUID,
@Multipart(value = "icon") Attachment iconFile, @Multipart(value = "banner") Attachment bannerFile, @Multipart(value = "icon") Attachment iconFile, @Multipart(value = "banner") Attachment bannerFile,
@Multipart(value = "screenshot") List<Attachment> screenshots); @Multipart(value = "screenshot") List<Attachment> screenshots);
@ -233,7 +233,7 @@ public interface ApplicationReleaseManagementAPI {
@Multipart(value = "screenshot", required = false) List<Attachment> screenshots); @Multipart(value = "screenshot", required = false) List<Attachment> screenshots);
@PUT @PUT
@Path("/release/{uuid}") @Path("/{appId}/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation( @ApiOperation(
@ -262,9 +262,13 @@ public interface ApplicationReleaseManagementAPI {
}) })
Response updateApplicationRelease( Response updateApplicationRelease(
@ApiParam(name = "UUID", value = "Unique identifier of the Application", required = true) @PathParam("uuid") String applicationUUID, @ApiParam(name = "appId", value = "Identifier of the Application", required = true) @PathParam("appId") int applicationId,
@ApiParam(name = "UUID", value = "Unique identifier of the Application Release", required = true) @PathParam("uuid") String applicationUUID,
@Multipart(value = "applicationRelease", required = false, type = "application/json") ApplicationRelease applicationRelease, @Multipart(value = "applicationRelease", required = false, type = "application/json") ApplicationRelease applicationRelease,
@Multipart(value = "binaryFile", required = false) Attachment binaryFile); @Multipart(value = "binaryFile", required = false) Attachment binaryFile,
@Multipart(value = "icon", required = false) Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart(value = "screenshot", required = false) List<Attachment> attachmentList);
@GET @GET
@Path("/release-artifacts/{uuid}/{version}") @Path("/release-artifacts/{uuid}/{version}")

@ -69,6 +69,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
private static final int DEFAULT_LIMIT = 20; private static final int DEFAULT_LIMIT = 20;
private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class); private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class);
//todo need to pass uuid
@GET @GET
@Override @Override
@Consumes("application/json") @Consumes("application/json")

@ -144,7 +144,7 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
List<ApplicationRelease> applicationReleases; List<ApplicationRelease> applicationReleases;
try { try {
List<UnrestrictedRole> unrestrictedRoles = unrestrictedRoleManager.getUnrestrictedRoles(applicationId, tenantId); List<UnrestrictedRole> unrestrictedRoles = unrestrictedRoleManager.getUnrestrictedRoles(applicationId, tenantId);
if(applicationManager.isUserAllowable(unrestrictedRoles,userName)){ if(unrestrictedRoles == null || applicationManager.isUserAllowable(unrestrictedRoles,userName)){
applicationReleases= applicationReleaseManager.getReleases(applicationId); applicationReleases= applicationReleaseManager.getReleases(applicationId);
return Response.status(Response.Status.OK).entity(applicationReleases).build(); return Response.status(Response.Status.OK).entity(applicationReleases).build();
@ -160,11 +160,77 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
} }
} }
//todo I think we can remove this DLPDS or this has to be update Image artifacts not upload application artifact @Override
@PUT
@Path("/{appId}/{uuid}")
public Response updateApplicationRelease(
@PathParam("appId") int applicationId,
@PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") ApplicationRelease applicationRelease,
@Multipart("binaryFile") Attachment binaryFile,
@Multipart("icon") Attachment iconFile,
@Multipart("banner") Attachment bannerFile,
@Multipart("screenshot") List<Attachment> attachmentList) {
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
InputStream iconFileStream = null;
InputStream bannerFileStream = null;
List<InputStream> attachments = new ArrayList<>();
try {
if (binaryFile != null) {
//todo add binary file validation
applicationRelease = applicationStorageManager.uploadReleaseArtifacts
(applicationId, applicationRelease, binaryFile.getDataHandler().getInputStream());
}
if(iconFile != null ){
iconFileStream = iconFile.getDataHandler().getInputStream();
}
if (bannerFile != null){
bannerFileStream = bannerFile.getDataHandler().getInputStream();
}
if (!attachmentList.isEmpty()){
for (Attachment screenshot : attachmentList) {
attachments.add(screenshot.getDataHandler().getInputStream());
}
}
applicationRelease = applicationStorageManager.uploadImageArtifacts(applicationId, applicationRelease,
iconFileStream, bannerFileStream, attachments);
if (applicationRelease != null) {
applicationRelease = applicationReleaseManager.updateRelease(applicationUUID, applicationRelease);
}
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 updating the application release of the application with UUID " + applicationUUID);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
catch (IOException e) {
log.error("Error while updating the release artifacts of the application with UUID " + applicationUUID);
return APIUtil.getResponse(new ApplicationManagementException(
"Error while updating the release artifacts of the application with UUID "
+ applicationUUID), Response.Status.INTERNAL_SERVER_ERROR);
}
catch (ResourceManagementException e) {
log.error("Error occurred while updating the releases artifacts of the application with the uuid "
+ applicationUUID + " for the release " + applicationRelease.getVersion(), e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
//todo
@Override @Override
@POST @POST
@Path("/upload-image-artifacts/{uuid}") @Path("/upload-image-artifacts/{uuid}")
public Response uploadApplicationArtifacts(@PathParam("uuid") String applicationUUID, public Response updateApplicationImageArtifacts(@PathParam("uuid") String applicationUUID,
@Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile, @Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile,
@Multipart("screenshot") List<Attachment> attachmentList) { @Multipart("screenshot") List<Attachment> attachmentList) {
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
@ -216,6 +282,7 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
// } // }
} }
//todo
@Override @Override
@PUT @PUT
@Path("/upload-image-artifacts/{uuid}") @Path("/upload-image-artifacts/{uuid}")
@ -257,48 +324,40 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
} }
@Override @Override
@PUT @DELETE
@Path("/release/{uuid}") @Path("/release/{uuid}")
public Response updateApplicationRelease(@PathParam("uuid") String applicationUUID, @Multipart public Response deleteApplicationRelease(@PathParam("uuid") String applicationUUID,
("applicationRelease") ApplicationRelease applicationRelease, @Multipart("binaryFile") Attachment @QueryParam("version") String version) {
binaryFile) {
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager(); ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try { try {
if (applicationRelease != null) { if (version != null && !version.isEmpty()) {
applicationRelease = applicationReleaseManager.updateRelease(applicationUUID, applicationRelease); applicationStorageManager.deleteApplicationReleaseArtifacts(applicationUUID, version);
} // applicationReleaseManager.deleteApplicationRelease(applicationUUID, version);
if (binaryFile != null) { return Response.status(Response.Status.OK)
String version = applicationRelease == null ? null : applicationRelease.getVersion(); .entity("Successfully deleted Application release with " + "version " + version
+ " for the application with UUID " + applicationUUID).build();
if (version == null) { } else {
return Response.status(Response.Status.BAD_REQUEST).entity("Version cannot be null. Version is a " applicationStorageManager.deleteAllApplicationReleaseArtifacts(applicationUUID);
+ "mandatory parameter to update the release artifacts").build(); applicationReleaseManager.deleteApplicationReleases(applicationUUID);
} return Response.status(Response.Status.OK)
// applicationStorageManager .entity("Successfully deleted Application releases for the " + "application with UUID "
// .uploadReleaseArtifacts(applicationUUID, version, binaryFile.getDataHandler().getInputStream()); + applicationUUID).build();
} }
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build(); return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
log.error("Error while updating the application release of the application with UUID " + applicationUUID); log.error("Error while deleting application release with the application UUID " + applicationUUID, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
} catch (ApplicationStorageManagementException e) {
log.error("Error occurred while deleting the releases artifacts of the application with the uuid "
+ applicationUUID + " for the release " + version, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
} }
// catch (IOException e) {
// log.error("Error while updating the release artifacts of the application with UUID " + applicationUUID);
// return APIUtil.getResponse(new ApplicationManagementException(
// "Error while updating the release artifacts of the application with UUID "
// + applicationUUID), Response.Status.INTERNAL_SERVER_ERROR);
// }
// catch (ResourceManagementException e) {
// log.error("Error occurred while updating the releases artifacts of the application with the uuid "
// + applicationUUID + " for the release " + applicationRelease.getVersion(), e);
// return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
// }
} }
//todo I think we must remove this DLPDS
//todo I think we must remove following methods - By DLPDS
@Override @Override
@GET @GET
@Produces(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM)
@ -323,42 +382,6 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
} }
} }
@Override
@DELETE
@Path("/release/{uuid}")
public Response deleteApplicationRelease(@PathParam("uuid") String applicationUUID,
@QueryParam("version") String version) {
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
if (version != null && !version.isEmpty()) {
applicationStorageManager.deleteApplicationReleaseArtifacts(applicationUUID, version);
// applicationReleaseManager.deleteApplicationRelease(applicationUUID, version);
return Response.status(Response.Status.OK)
.entity("Successfully deleted Application release with " + "version " + version
+ " for the application with UUID " + applicationUUID).build();
} else {
applicationStorageManager.deleteAllApplicationReleaseArtifacts(applicationUUID);
applicationReleaseManager.deleteApplicationReleases(applicationUUID);
return Response.status(Response.Status.OK)
.entity("Successfully deleted Application releases for the " + "application with UUID "
+ applicationUUID).build();
}
} catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) {
log.error("Error while deleting application release with the application UUID " + applicationUUID, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
} catch (ApplicationStorageManagementException e) {
log.error("Error occurred while deleting the releases artifacts of the application with the uuid "
+ applicationUUID + " for the release " + version, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
//todo I think we must remove this DLPDS
@Override @Override
@GET @GET
@Path("/image-artifacts/{uuid}") @Path("/image-artifacts/{uuid}")

@ -16,7 +16,7 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.device.application.mgt.publisher.api.services; package org.wso2.carbon.device.application.mgt.store.api.services;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -218,6 +218,9 @@ public interface ApplicationManagementAPI {
); );
@GET @GET
@Path("/release-artifacts/{uuid}/{version}") @Path("/release-artifacts/{uuid}/{version}")
@Produces(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM)
@ -247,16 +250,8 @@ public interface ApplicationManagementAPI {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getApplicationReleaseArtifacts( Response getApplicationReleaseArtifacts(
@ApiParam( @ApiParam(name = "UUID", value = "Unique identifier of the Application", required = true) @PathParam("uuid") String applicationUUID,
name = "UUID", @ApiParam(name = "Version", value = "Version of the Application release need to be retrieved", required = true) @PathParam("version") String version);
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 @GET
@Path("/release/{uuid}") @Path("/release/{uuid}")
@ -285,17 +280,9 @@ public interface ApplicationManagementAPI {
message = "Internal Server Error. \n Error occurred while releasing the application.", message = "Internal Server Error. \n Error occurred while releasing the application.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getPublishedRelease( Response getApplicationRelease(
@ApiParam( @ApiParam(name = "ID", value = "Identifier of the Application", required = true) @PathParam("uuid") String applicationUUID,
name = "UUID", @ApiParam(name = "version", value = "Version of the application", required = false) @QueryParam("version") String version);
value = "Unique 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 @GET
@Path("/image-artifacts/{uuid}") @Path("/image-artifacts/{uuid}")
@ -326,20 +313,9 @@ public interface ApplicationManagementAPI {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getApplicationImageArtifacts( Response getApplicationImageArtifacts(
@ApiParam( @ApiParam(name = "UUID", value = "Unique identifier of the Application", required = true) @PathParam("uuid") String applicationUUID,
name = "UUID", @ApiParam(name = "name", value = "Name of the artifact to be retrieved", required = true) @QueryParam("name") String name,
value = "Unique identifier of the Application", @ApiParam(name = "count", value = "Count of the screen-shot artifact to be retrieved", required = false) @QueryParam("count") int count);
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,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);
}

@ -22,7 +22,6 @@ 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.store.api.APIUtil; 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.FileStreamingOutput;
import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementAPI;
import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.Application;
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.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
@ -35,6 +34,7 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationRelease
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; 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.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.util.Constants; import org.wso2.carbon.device.application.mgt.core.util.Constants;
import org.wso2.carbon.device.application.mgt.store.api.services.ApplicationManagementAPI;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
@ -103,8 +103,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} }
} }
@GET @GET
@Consumes("application/json") @Consumes("application/json")
@Path("/{appType}") @Path("/{appType}")
@ -140,7 +138,32 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} }
} }
//todo WIP
@Override
@Path("/{uuid}")
@GET
public Response getApplicationRelease(@PathParam("uuid") String applicationUUID,
@QueryParam("version") String version) {
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
return null;
// 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);
// }
}
//todo We must remove following methods - By DLPDS
@Override @Override
@GET @GET
@Produces(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM)
@ -165,29 +188,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} }
} }
@Override
@Path("/release/{uuid}")
@GET
public Response getPublishedRelease(@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 @Override
@GET @GET
@Path("/image-artifacts/{uuid}") @Path("/image-artifacts/{uuid}")

@ -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);
}
}
}

@ -15,7 +15,7 @@
* 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.publisher.api.services.impl; package org.wso2.carbon.device.application.mgt.store.api.services.impl;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;

Loading…
Cancel
Save