complete app release getting flow and fixed related bugs

feature/appm-store/pbac
lasantha 7 years ago
parent 569007514e
commit fdac04dd3e

@ -18,10 +18,7 @@
*/
package org.wso2.carbon.device.application.mgt.common.services;
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.Filter;
import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition;
import org.wso2.carbon.device.application.mgt.common.*;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
@ -121,4 +118,12 @@ public interface ApplicationManager {
* @throws ApplicationManagementException Application Management Exception.
*/
Boolean verifyApplicationExistenceById(int appId) throws ApplicationManagementException;
/**
* To get Application with the given UUID.
*
* @return the boolean value, whether user has assigned unrestricted roles to access the application
* * @throws ApplicationManagementException Application Management Exception.
*/
Boolean isUserAllowable(List<UnrestrictedRole> unrestrictedRoles, String userName) throws ApplicationManagementException;
}

@ -51,14 +51,23 @@ public interface ApplicationReleaseManager {
*/
ApplicationRelease getRelease(String applicationUuid, String version, String releaseType) throws ApplicationManagementException;
/**
* To get the application release of the Application/
*
* @param applicationUuid UUID of the Application.
* @return ApplicationRelease related with particular Application UUID and version.
* @throws ApplicationManagementException ApplicationManagementException
*/
ApplicationRelease getReleaseByUuid(String applicationUuid) throws ApplicationManagementException;
/**
* To get all the releases of a particular Application.
*
* @param applicationUuid UUID of the Application to get all the releases.
* @param applicationId ID of the Application to get all the releases.
* @return the List of the Application releases related with the particular Application.
* @throws ApplicationManagementException Application Management Exception.
*/
List<ApplicationRelease> getReleases(String applicationUuid) throws ApplicationManagementException;
List<ApplicationRelease> getReleases(int applicationId) throws ApplicationManagementException;
/**
* To make a particular application release as the default / not default-one

@ -18,15 +18,18 @@
package org.wso2.carbon.device.application.mgt.common.services;
import org.wso2.carbon.device.application.mgt.common.UnrestrictedRole;
import org.wso2.carbon.device.application.mgt.common.Visibility;
import org.wso2.carbon.device.application.mgt.common.exception.VisibilityManagementException;
import java.util.List;
/**
* This interface manages all the operations related with Application Visibility.
* This will be invoking the necessary backend calls for the data bases layer
* and provide the functional implementation.
*/
public interface VisibilityManager {
public interface UnrestrictedRoleManager {
/**
* Add (if there is no visibility configuration for the application) or
@ -42,9 +45,10 @@ public interface VisibilityManager {
* Returns the Visibility configuration of the provided applicationUUID.
*
* @param applicationID The ID of the application
* @param tenantId tenant Id
* @return Visibility configuration
*/
Visibility get(int applicationID) throws VisibilityManagementException;
List<UnrestrictedRole> getUnrestrictedRoles(int applicationID, int tenantId) throws VisibilityManagementException;
/**
* Remove the visibility configuration mapping for the provided application.

@ -454,6 +454,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
public Boolean isUserAllowable(List<UnrestrictedRole> unrestrictedRoles, String userName) throws ApplicationManagementException{
try {
return isRoleExists(unrestrictedRoles, userName);
} catch (UserStoreException e) {
throw new ApplicationManagementException("User-store exception while verifying whether user have assigned"
+ "unrestricted roles or not"); }
}
/**
* To check whether current user is application owner or admin.

@ -83,9 +83,10 @@ public class ApplicationReleaseManagerImpl implements ApplicationReleaseManager
}
@Override
public List<ApplicationRelease> getReleases(String applicationUuid) throws ApplicationManagementException {
public List<ApplicationRelease> getReleases(int applicationId) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Application application = validateApplicationRelease(applicationUuid);
Application application = validateApplication(applicationId);
if (log.isDebugEnabled()) {
log.debug("Request is received to retrieve all the releases related with the application " +
application.toString());

@ -31,6 +31,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage
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.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.device.application.mgt.core.util.Constants;
@ -158,6 +159,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
@Override
public InputStream getReleasedArtifacts(String applicationUUID, String versionName)
throws ApplicationStorageManagementException {
// todo this should be validate application release
Application application = validateApplication(applicationUUID);
String artifactPath = storagePath + application.getId() + File.separator + versionName;
@ -181,6 +183,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
@Override
public void deleteApplicationArtifacts(String applicationUUID) throws ApplicationStorageManagementException {
// todo this should be validate application release
Application application = validateApplication(applicationUUID);
String artifactDirectoryPath = storagePath + application.getId();
File artifactDirectory = new File(artifactDirectoryPath);
@ -193,6 +196,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
@Override
public void deleteApplicationReleaseArtifacts(String applicationUUID, String version)
throws ApplicationStorageManagementException {
// todo this should be validate application release
Application application = validateApplication(applicationUUID);
String artifactPath = storagePath + application.getId() + File.separator + version;
File artifact = new File(artifactPath);
@ -205,6 +209,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
@Override
public void deleteAllApplicationReleaseArtifacts(String applicationUUID) throws
ApplicationStorageManagementException {
// todo this should be validate application release
validateApplication(applicationUUID);
try {
List<ApplicationRelease> applicationReleases = DataHolder.getInstance().getApplicationReleaseManager()
@ -222,6 +227,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
@Override
public ImageArtifact getImageArtifact(String applicationUUID, String name, int count) throws
ApplicationStorageManagementException {
// todo this should be validate application release
Application application = validateApplication(applicationUUID);
validateImageArtifactNames(name);
String imageArtifactPath = storagePath + application.getId() + File.separator + name.toLowerCase();
@ -267,7 +273,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
* To validate the Application before storing and retrieving the artifacts of a particular application.
*
* @param appId ID of the Application
* @return {@link Application} if it is validated
* @return boolean if it is validated
* @throws ApplicationStorageManagementException Application Storage Management Exception will be thrown if a
* valid application related with the specific UUID
* could not be found.
@ -284,6 +290,25 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
return isAppExist;
}
/**
* To validate the pre-request of the ApplicationRelease.
*
* @param applicationUuid UUID of the Application.
* @return Application related with the UUID
*/
private ApplicationRelease validateApplicationRelease(String applicationUuid) throws ApplicationManagementException {
if (applicationUuid == null) {
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
+ "parameter to get the relevant application.");
}
ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager().getRelease();
if (applicationRelease == null) {
throw new NotFoundException(
"Application with UUID " + applicationUuid + " does not exist.");
}
return applicationRelease;
}
private String getMD5(InputStream binaryFile) throws ApplicationStorageManagementException {
String md5;
try {

@ -17,18 +17,21 @@
*/
package org.wso2.carbon.device.application.mgt.core.impl;
import org.wso2.carbon.device.application.mgt.common.UnrestrictedRole;
import org.wso2.carbon.device.application.mgt.common.Visibility;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.VisibilityManagementException;
import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager;
import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager;
import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import java.util.List;
/**
* This is the default implementation for the visibility manager.
*/
public class VisibilityManagerImpl implements VisibilityManager {
public class UnrestrictedRoleManagerImpl implements UnrestrictedRoleManager {
@Override
public Visibility put(int applicationID, Visibility visibility) throws VisibilityManagementException {
@ -68,15 +71,13 @@ public class VisibilityManagerImpl implements VisibilityManager {
}
@Override
public Visibility get(int applicationID) throws VisibilityManagementException {
public List<UnrestrictedRole> getUnrestrictedRoles(int applicationID, int tenantId) throws VisibilityManagementException {
try {
VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
Visibility visibility = visibilityDAO.get(applicationID);
if (visibility.getType() == null && (visibility.getAllowedList() == null ||
visibility.getAllowedList().isEmpty())) {
visibility.setType(Visibility.Type.PUBLIC);
}
return visibility;
List<UnrestrictedRole> unrestrictedRoles = visibilityDAO.getUnrestrictedRoles(applicationID, tenantId);
if (unrestrictedRoles == null)
return null;
return unrestrictedRoles;
} catch (ApplicationManagementException e) {
throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - "
+ applicationID, e);

@ -24,7 +24,7 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage
import org.wso2.carbon.device.application.mgt.common.services.CommentsManager;
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager;
import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.user.core.service.RealmService;
@ -47,7 +47,7 @@ public class DataHolder {
private SubscriptionManager subscriptionManager;
private VisibilityManager visibilityManager;
private UnrestrictedRoleManager unrestrictedRoleManager;
private ApplicationStorageManager applicationStorageManager;
@ -109,12 +109,12 @@ public class DataHolder {
this.subscriptionManager = subscriptionManager;
}
public VisibilityManager getVisibilityManager() {
return visibilityManager;
public UnrestrictedRoleManager getVisibilityManager() {
return unrestrictedRoleManager;
}
public void setVisibilityManager(VisibilityManager visibilityManager) {
this.visibilityManager = visibilityManager;
public void setVisibilityManager(UnrestrictedRoleManager unrestrictedRoleManager) {
this.unrestrictedRoleManager = unrestrictedRoleManager;
}
public RealmService getRealmService() {

@ -29,7 +29,7 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage
import org.wso2.carbon.device.application.mgt.common.services.CommentsManager;
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager;
import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
@ -93,9 +93,9 @@ public class ServiceComponent {
DataHolder.getInstance().setSubscriptionManager(subscriptionManager);
bundleContext.registerService(SubscriptionManager.class.getName(), subscriptionManager, null);
VisibilityManager visibilityManager = ApplicationManagementUtil.getVisibilityManagerInstance();
DataHolder.getInstance().setVisibilityManager(visibilityManager);
bundleContext.registerService(VisibilityManager.class.getName(), visibilityManager, null);
UnrestrictedRoleManager unrestrictedRoleManager = ApplicationManagementUtil.getVisibilityManagerInstance();
DataHolder.getInstance().setVisibilityManager(unrestrictedRoleManager);
bundleContext.registerService(UnrestrictedRoleManager.class.getName(), unrestrictedRoleManager, null);
ApplicationStorageManager applicationStorageManager = ApplicationManagementUtil
.getApplicationStorageManagerInstance();

@ -27,7 +27,7 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage
import org.wso2.carbon.device.application.mgt.common.services.CommentsManager;
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager;
import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.config.Extension;
@ -66,10 +66,10 @@ public class ApplicationManagementUtil {
return getInstance(extension, LifecycleStateManager.class);
}
public static VisibilityManager getVisibilityManagerInstance() throws InvalidConfigurationException {
public static UnrestrictedRoleManager getVisibilityManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.VisibilityManager);
return getInstance(extension, VisibilityManager.class);
return getInstance(extension, UnrestrictedRoleManager.class);
}
public static SubscriptionManager getSubscriptionManagerInstance() throws InvalidConfigurationException {

@ -51,7 +51,7 @@
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.SubscriptionManagerImpl</ClassName>
</Extension>
<Extension name="VisibilityManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.VisibilityManagerImpl</ClassName>
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.UnrestrictedRoleManagerImpl</ClassName>
</Extension>
<Extension name="VisibilityTypeManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.VisibilityTypeManagerImpl</ClassName>

@ -21,12 +21,8 @@ package org.wso2.carbon.device.application.mgt.publisher.api;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.services.*;
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
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.common.services.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import javax.ws.rs.core.Response;
@ -43,7 +39,8 @@ public class APIUtil {
private static ApplicationReleaseManager applicationReleaseManager;
private static ApplicationStorageManager applicationStorageManager;
private static SubscriptionManager subscriptionManager;
private static CategoryManager categoryManager;
private static UnrestrictedRoleManager unrestrictedRoleManager;
public static ApplicationManager getApplicationManager() {
if (applicationManager == null) {
@ -127,28 +124,6 @@ public class APIUtil {
return applicationStorageManager;
}
/**
* To get the Category Manager from the osgi context.
*
* @return CategoryManager instance in the current osgi context.
*/
public static CategoryManager getCategoryManager() {
if (categoryManager == null) {
synchronized (APIUtil.class) {
if (categoryManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
categoryManager = (CategoryManager) ctx.getOSGiService(CategoryManager.class, null);
if (categoryManager == null) {
String msg = "Category Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return categoryManager;
}
public static Response getResponse(Exception ex, Response.Status status) {
return getResponse(ex.getMessage(), status);
}
@ -185,4 +160,27 @@ public class APIUtil {
return subscriptionManager;
}
/**
* To get the Unrestricted Role manager from the osgi context.
* @return Unrestricted Role manager instance in the current osgi context.
*/
public static UnrestrictedRoleManager getUnrestrictedRoleManager() {
if (unrestrictedRoleManager == null) {
synchronized (APIUtil.class) {
if (unrestrictedRoleManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
unrestrictedRoleManager =
(UnrestrictedRoleManager) ctx.getOSGiService(UnrestrictedRoleManager.class, null);
if (unrestrictedRoleManager == null) {
String msg = "Subscription Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return unrestrictedRoleManager;
}
}

@ -289,156 +289,6 @@ public interface ApplicationManagementAPI {
required = true)
@Valid Application application);
@POST
@Path("/upload-artifacts/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
consumes = MediaType.MULTIPART_FORM_DATA,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Upload artifacts",
notes = "This will create a new application",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:application:create")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "OK. \n Successfully uploaded artifacts."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the application list.",
response = ErrorResponse.class)
})
Response uploadApplicationArtifacts(
@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 = "screenshot") List<Attachment> screenshots);
@PUT
@Path("/upload-artifacts/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
consumes = MediaType.MULTIPART_FORM_DATA,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Upload artifacts",
notes = "This will create a new application",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:application:create")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "OK. \n Successfully uploaded artifacts."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the application list.",
response = ErrorResponse.class)
})
Response updateApplicationArtifacts(
@ApiParam(
name = "uuid",
value = "UUID of the application",
required = true)
@PathParam("uuid") String applicationUUID,
@Multipart(value = "icon", required = false) Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart(value = "screenshot", required = false) List<Attachment> screenshots);
@PUT
@Consumes("application/json")
@Path("/{uuid}/lifecycle")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Change the life cycle state of the application",
notes = "This will change the life-cycle state of the application",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:application-mgt:login")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully changed application state."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the application list.",
response = ErrorResponse.class)
})
Response changeLifecycleState(
@ApiParam(
name = "UUID",
value = "Unique identifier of the Application",
required = true)
@PathParam("uuid") String applicationUUID,
@ApiParam(
name = "state",
value = "Lifecycle State that need to be changed to",
required = true)
@QueryParam("state") String state);
@GET
@Consumes("application/json")
@Path("/{uuid}/lifecycle")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Change the life cycle state of the application",
notes = "This will retrieve the next life cycle states of the application based on the user and the "
+ "current state",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:application-mgt:login")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved the lifecycle states.",
response = List.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the life-cycle states.",
response = ErrorResponse.class)
})
Response getNextLifeCycleStates(
@ApiParam(
name = "UUID",
value = "Unique identifier of the Application",
required = true)
@PathParam("uuid") String applicationUUID);
@DELETE
@Consumes("application/json")
@Path("/{appuuid}")
@ -473,246 +323,6 @@ public interface ApplicationManagementAPI {
required = true)
@PathParam("appuuid") String applicationUUID);
@POST
@Path("/release/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
consumes = MediaType.MULTIPART_FORM_DATA,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Create an application release",
notes = "This will create a new application release",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:application:create")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "OK. \n Successfully created an application release.",
response = ApplicationRelease.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while releasing the application.",
response = ErrorResponse.class)
})
Response createApplicationRelease(
@ApiParam(
name = "UUID",
value = "Unique identifier of the Application",
required = true)
@PathParam("uuid") String applicationUUID,
@Multipart(value = "applicationRelease", type = "application/json") ApplicationRelease applicationRelease,
@Multipart(value = "binaryFile") Attachment binaryFile);
@PUT
@Path("/release/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
consumes = MediaType.MULTIPART_FORM_DATA,
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Update an application release",
notes = "This will update a new application release",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:application:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "OK. \n Successfully created an application release.",
response = ApplicationRelease.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while releasing the application.",
response = ErrorResponse.class)
})
Response updateApplicationRelease(
@ApiParam(
name = "UUID",
value = "Unique identifier of the Application",
required = true)
@PathParam("uuid") String applicationUUID,
@Multipart(value = "applicationRelease", required = false, type = "application/json")
ApplicationRelease applicationRelease,
@Multipart(value = "binaryFile", required = false) Attachment binaryFile);
@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 getApplicationReleases(
@ApiParam(
name = "UUID",
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);
@DELETE
@Path("/release/{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:delete")
})
}
)
@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 deleteApplicationRelease(
@ApiParam(
name = "UUID",
value = "Unique identifier of the Application",
required = true)
@PathParam("uuid") String applicationUUID,
@ApiParam(
name = "version",
value = "Version of the application")
@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);
@PUT
@Consumes("application/json")
@Path("/{uuid}/{version}/{channel}")

@ -232,40 +232,6 @@ public interface ApplicationReleaseManagementAPI {
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart(value = "screenshot", required = false) List<Attachment> screenshots);
@POST
@Path("/release/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
consumes = MediaType.MULTIPART_FORM_DATA,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Create an application release",
notes = "This will create a new application release",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:application:create")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "OK. \n Successfully created an application release.",
response = ApplicationRelease.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while releasing the application.",
response = ErrorResponse.class)
})
Response createApplicationRelease(
@ApiParam(name = "UUID", value = "Unique identifier of the Application", required = true) @PathParam("uuid") String applicationUUID,
@Multipart(value = "applicationRelease", type = "application/json") ApplicationRelease applicationRelease,
@Multipart(value = "binaryFile") Attachment binaryFile);
@PUT
@Path("/release/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@ -333,7 +299,7 @@ public interface ApplicationReleaseManagementAPI {
@ApiParam(name = "Version", value = "Version of the Application release need to be retrieved", required = true) @PathParam("version") String version);
@GET
@Path("/release/{uuid}")
@Path("/{appId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
@ -359,9 +325,8 @@ public interface ApplicationReleaseManagementAPI {
message = "Internal Server Error. \n Error occurred while releasing the application.",
response = ErrorResponse.class)
})
Response getApplicationReleases(
@ApiParam(name = "UUID", 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);
Response getApplicationReleases(@ApiParam(name = "appId", value = "Unique identifier of the Application",
required = true) @PathParam("appId") int applicationId);
@DELETE
@Path("/release/{uuid}")
@ -384,7 +349,7 @@ public interface ApplicationReleaseManagementAPI {
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deleted the Application release."),
message = "OK. \nI Successfully deleted the Application release."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while deleting the release of a"

@ -17,15 +17,7 @@
*/
package org.wso2.carbon.device.application.mgt.publisher.api.services;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag;
import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
@ -33,11 +25,7 @@ import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@ -177,4 +165,77 @@ public interface LifecycleManagementAPI {
response = ErrorResponse.class)
})
Response deleteLifecycleState(@PathParam("identifier") String identifier);
@PUT
@Consumes("application/json")
@Path("/{uuid}/lifecycle")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Change the life cycle state of the application",
notes = "This will change the life-cycle state of the application",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:application-mgt:login")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully changed application state."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the application list.",
response = ErrorResponse.class)
})
Response changeLifecycleState(
@ApiParam(
name = "UUID",
value = "Unique identifier of the Application",
required = true)
@PathParam("uuid") String applicationUUID,
@ApiParam(
name = "state",
value = "Lifecycle State that need to be changed to",
required = true)
@QueryParam("state") String state);
@GET
@Consumes("application/json")
@Path("/{uuid}/lifecycle")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Change the life cycle state of the application",
notes = "This will retrieve the next life cycle states of the application based on the user and the "
+ "current state",
tags = "Application Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:application-mgt:login")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved the lifecycle states.",
response = List.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the life-cycle states.",
response = ErrorResponse.class)
})
Response getNextLifeCycleStates(
@ApiParam(
name = "UUID",
value = "Unique identifier of the Application",
required = true)
@PathParam("uuid") String applicationUUID);
}

@ -91,10 +91,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
ApplicationList applications = applicationManager.getApplications(filter);
for (Application application : applications.getApplications()) {
// ToDo : use better approach to solve this
String uuId = applicationManager.getUuidOfLatestRelease(application.getId());
if (uuId != null){
application.setUuidOfLatestRelease(uuId);
ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(uuId, Constants.IMAGE_ARTIFACTS[0], 0);
application.setIconOfLatestRelease(imageArtifact);
}else{
@ -127,10 +125,8 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
.entity("Application with UUID " + appType + " not found").build();
}
// ToDo : use better approach to solve this
String uuId = applicationManager.getUuidOfLatestRelease(application.getId());
if (uuId != null){
application.setUuidOfLatestRelease(uuId);
ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(uuId, Constants.IMAGE_ARTIFACTS[0], 0);
application.setIconOfLatestRelease(imageArtifact);
}else{
@ -175,6 +171,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
}
//Todo Not complete
@PUT
@Consumes("application/json")
public Response editApplication(@Valid Application application) {
@ -184,13 +181,14 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} catch (NotFoundException e) {
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating the application";
String msg = "Error occurred while modifying the application";
log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.BAD_REQUEST);
}
return Response.status(Response.Status.OK).entity(application).build();
}
//todo this need to be rethink and fix --- > This is somthing change lifecycle
@DELETE
@Path("/{appuuid}")
public Response deleteApplication(@PathParam("appuuid") String uuid) {
@ -215,333 +213,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
}
}
// ToDo
@PUT
@Consumes("application/json")
@Path("/{uuid}/lifecycle")
public Response changeLifecycleState(@PathParam("uuid") String applicationUUID, @QueryParam("state") String state) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
if (!Arrays.asList(Constants.LIFE_CYCLES).contains(state)) {
log.warn("Provided lifecycle state " + state + " is not valid. Please select one from"
+ Arrays.toString(Constants.LIFE_CYCLES));
return Response.status(Response.Status.BAD_REQUEST)
.entity("Provided lifecycle state " + state + " is not valid. Please select one from "
+ Arrays.toString(Constants.LIFE_CYCLES)).build();
}
try {
applicationManager.changeLifecycle(applicationUUID, state);
return Response.status(Response.Status.OK)
.entity("Successfully changed the lifecycle state of the application: " + applicationUUID).build();
} catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while changing the lifecycle of application: " + applicationUUID;
log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.BAD_REQUEST);
}
}
@GET
@Path("/{uuid}/lifecycle")
@Override
public Response getNextLifeCycleStates(@PathParam("uuid") String applicationUUID) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
if (applicationManager.getApplication(applicationUUID) == null) {
if (log.isDebugEnabled()) {
log.debug("Application with the UUID '" + applicationUUID + "' is not found.");
}
return Response.status(Response.Status.NOT_FOUND).entity("Application with the UUID '" +
applicationUUID + "' is not found.").build();
}
if (log.isDebugEnabled()) {
log.debug("Application with UUID '" + applicationUUID + "' is found. Request received for getting "
+ "next life-cycle states for the particular application.");
}
return Response.status(Response.Status.OK).entity(applicationManager.getLifeCycleStates(applicationUUID))
.build();
} catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) {
log.error("Application Management Exception while trying to get next states for the applications with "
+ "the application ID", e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
@Override
@POST
@Path("/upload-image-artifacts/{uuid}")
public Response uploadApplicationArtifacts(@PathParam("uuid") String applicationUUID,
@Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile,
@Multipart("screenshot") List<Attachment> attachmentList) {
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
InputStream iconFileStream;
InputStream bannerFileStream;
List<InputStream> attachments = new ArrayList<>();
if (iconFile != null) {
iconFileStream = iconFile.getDataHandler().getInputStream();
} else {
throw new ApplicationManagementException(
"Icon file is not uploaded for the application " + applicationUUID);
}
if (bannerFile != null) {
bannerFileStream = bannerFile.getDataHandler().getInputStream();
} else {
throw new ApplicationManagementException(
"Banner file is not uploaded for the application " + applicationUUID);
}
if (attachmentList != null && !attachmentList.isEmpty()) {
for (Attachment screenshot : attachmentList) {
attachments.add(screenshot.getDataHandler().getInputStream());
}
} else {
throw new ApplicationManagementException(
"Screen-shot are not uploaded for the application " + applicationUUID);
}
applicationStorageManager
.uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments);
return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationUUID).build();
} catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating the application";
log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.BAD_REQUEST);
} catch (IOException e) {
log.error("Exception while trying to read icon, banner files for the application " + applicationUUID);
return APIUtil.getResponse(new ApplicationManagementException(
"Exception while trying to read icon, " + "banner files for the application " +
applicationUUID, e), Response.Status.BAD_REQUEST);
} catch (ResourceManagementException e) {
log.error("Error occurred while uploading the image artifacts of the application with the uuid "
+ applicationUUID, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
@Override
@PUT
@Path("/upload-image-artifacts/{uuid}")
public Response updateApplicationArtifacts(@PathParam("uuid") String applicationUUID,
@Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile,
@Multipart("screenshot") List<Attachment> attachmentList) {
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
InputStream iconFileStream = null;
InputStream bannerFileStream = null;
List<InputStream> attachments = new ArrayList<>();
if (iconFile != null) {
iconFileStream = iconFile.getDataHandler().getInputStream();
}
if (bannerFile != null) {
bannerFileStream = bannerFile.getDataHandler().getInputStream();
}
if (attachmentList != null) {
for (Attachment screenshot : attachmentList) {
attachments.add(screenshot.getDataHandler().getInputStream());
}
}
applicationStorageManager
.uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments);
return Response.status(Response.Status.OK)
.entity("Successfully updated artifacts for the application " + applicationUUID).build();
} catch (IOException e) {
log.error("Exception while trying to read icon, banner files for the application " + applicationUUID);
return APIUtil.getResponse(new ApplicationManagementException(
"Exception while trying to read icon, banner files for the application " +
applicationUUID, e), Response.Status.BAD_REQUEST);
} catch (ResourceManagementException e) {
log.error("Error occurred while uploading the image artifacts of the application with the uuid "
+ applicationUUID, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
@Override
@POST
@Path("/release/{uuid}")
public Response createApplicationRelease(@PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") ApplicationRelease applicationRelease,
@Multipart("binaryFile") Attachment binaryFile) {
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
applicationRelease = applicationReleaseManager.createRelease(applicationUUID, applicationRelease);
if (binaryFile != null) {
applicationStorageManager.uploadReleaseArtifacts(applicationUUID, applicationRelease.getVersion(),
binaryFile.getDataHandler().getInputStream());
}
return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
} catch (ApplicationManagementException e) {
log.error("Error while creating an application release for the application with UUID " + applicationUUID,
e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
} catch (IOException e) {
String errorMessage =
"Error while uploading binary file for the application release of the application with UUID "
+ applicationUUID;
log.error(errorMessage, e);
return APIUtil.getResponse(new ApplicationManagementException(errorMessage, e),
Response.Status.INTERNAL_SERVER_ERROR);
} catch (ResourceManagementException e) {
log.error("Error occurred while uploading 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);
}
}
@Override
@PUT
@Path("/release/{uuid}")
public Response updateApplicationRelease(@PathParam("uuid") String applicationUUID, @Multipart
("applicationRelease") ApplicationRelease applicationRelease, @Multipart("binaryFile") Attachment
binaryFile) {
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
if (applicationRelease != null) {
applicationRelease = applicationReleaseManager.updateRelease(applicationUUID, applicationRelease);
}
if (binaryFile != null) {
String version = applicationRelease == null ? null : applicationRelease.getVersion();
if (version == null) {
return Response.status(Response.Status.BAD_REQUEST).entity("Version cannot be null. Version is a "
+ "mandatory parameter to update the release artifacts").build();
}
applicationStorageManager
.uploadReleaseArtifacts(applicationUUID, version, binaryFile.getDataHandler().getInputStream());
}
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);
}
}
@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 getApplicationReleases(@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
@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);
}
}
@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);
}
}
// todo I think we must remove this
@Override
@PUT
@Consumes("application/json")

@ -22,12 +22,15 @@ 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.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.*;
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.ApplicationManager;
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.common.services.UnrestrictedRoleManager;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.publisher.api.APIUtil;
import org.wso2.carbon.device.application.mgt.publisher.api.FileStreamingOutput;
@ -107,6 +110,7 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
applicationRelease.setUuid(UUID.randomUUID().toString());
applicationRelease = applicationReleaseManager.createRelease(applicationId, applicationRelease);
//Todo insert lifecycle into lifecycle table
return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
@ -128,6 +132,35 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
}
}
@Override
@Path("/{appId}")
@GET
public Response getApplicationReleases(@PathParam("appId") int applicationId){
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
UnrestrictedRoleManager unrestrictedRoleManager = APIUtil.getUnrestrictedRoleManager();
ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<ApplicationRelease> applicationReleases;
try {
List<UnrestrictedRole> unrestrictedRoles = unrestrictedRoleManager.getUnrestrictedRoles(applicationId, tenantId);
if(applicationManager.isUserAllowable(unrestrictedRoles,userName)){
applicationReleases= applicationReleaseManager.getReleases(applicationId);
return Response.status(Response.Status.OK).entity(applicationReleases).build();
}
return Response.status(Response.Status.UNAUTHORIZED).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 id "
+ applicationId, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
//todo I think we can remove this DLPDS or this has to be update Image artifacts not upload application artifact
@Override
@POST
@Path("/upload-image-artifacts/{uuid}")
@ -160,8 +193,8 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
throw new ApplicationManagementException(
"Screen-shot are not uploaded for the application " + applicationUUID);
}
applicationStorageManager
.uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments);
// applicationStorageManager
// .uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments);
return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationUUID).build();
} catch (NotFoundException e) {
@ -175,11 +208,12 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
return APIUtil.getResponse(new ApplicationManagementException(
"Exception while trying to read icon, " + "banner files for the application " +
applicationUUID, e), Response.Status.BAD_REQUEST);
} catch (ResourceManagementException e) {
log.error("Error occurred while uploading the image artifacts of the application with the uuid "
+ applicationUUID, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
// catch (ResourceManagementException e) {
// log.error("Error occurred while uploading the image artifacts of the application with the uuid "
// + applicationUUID, e);
// return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
// }
}
@Override
@ -205,8 +239,8 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
attachments.add(screenshot.getDataHandler().getInputStream());
}
}
applicationStorageManager
.uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments);
// applicationStorageManager
// .uploadImageArtifacts(applicationUUID, iconFileStream, bannerFileStream, attachments);
return Response.status(Response.Status.OK)
.entity("Successfully updated artifacts for the application " + applicationUUID).build();
} catch (IOException e) {
@ -214,16 +248,14 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
return APIUtil.getResponse(new ApplicationManagementException(
"Exception while trying to read icon, banner files for the application " +
applicationUUID, e), Response.Status.BAD_REQUEST);
} catch (ResourceManagementException e) {
log.error("Error occurred while uploading the image artifacts of the application with the uuid "
+ applicationUUID, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
// catch (ResourceManagementException e) {
// log.error("Error occurred while uploading the image artifacts of the application with the uuid "
// + applicationUUID, e);
// return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
// }
}
@Override
@PUT
@Path("/release/{uuid}")
@ -243,8 +275,8 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
return Response.status(Response.Status.BAD_REQUEST).entity("Version cannot be null. Version is a "
+ "mandatory parameter to update the release artifacts").build();
}
applicationStorageManager
.uploadReleaseArtifacts(applicationUUID, version, binaryFile.getDataHandler().getInputStream());
// applicationStorageManager
// .uploadReleaseArtifacts(applicationUUID, version, binaryFile.getDataHandler().getInputStream());
}
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (NotFoundException e) {
@ -252,18 +284,21 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
} 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);
}
// 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
@Override
@GET
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@ -288,28 +323,6 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
}
}
@Override
@Path("/release/{uuid}")
@GET
public Response getApplicationReleases(@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
@DELETE
@ -321,7 +334,7 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
try {
if (version != null && !version.isEmpty()) {
applicationStorageManager.deleteApplicationReleaseArtifacts(applicationUUID, version);
applicationReleaseManager.deleteApplicationRelease(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();
@ -344,6 +357,8 @@ public class ApplicationReleaseManagementAPIImpl implements ApplicationReleaseMa
}
}
//todo I think we must remove this DLPDS
@Override
@GET
@Path("/image-artifacts/{uuid}")

@ -138,4 +138,62 @@ public class LifecycleManagementAPIImpl implements LifecycleManagementAPI {
// return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
// }
// }
// ToDo
@PUT
@Consumes("application/json")
@Path("/{uuid}/lifecycle")
public Response changeLifecycleState(@PathParam("uuid") String applicationUUID, @QueryParam("state") String state) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
if (!Arrays.asList(Constants.LIFE_CYCLES).contains(state)) {
log.warn("Provided lifecycle state " + state + " is not valid. Please select one from"
+ Arrays.toString(Constants.LIFE_CYCLES));
return Response.status(Response.Status.BAD_REQUEST)
.entity("Provided lifecycle state " + state + " is not valid. Please select one from "
+ Arrays.toString(Constants.LIFE_CYCLES)).build();
}
try {
applicationManager.changeLifecycle(applicationUUID, state);
return Response.status(Response.Status.OK)
.entity("Successfully changed the lifecycle state of the application: " + applicationUUID).build();
} catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while changing the lifecycle of application: " + applicationUUID;
log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.BAD_REQUEST);
}
}
@GET
@Path("/{uuid}/lifecycle")
@Override
public Response getNextLifeCycleStates(@PathParam("uuid") String applicationUUID) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
// if (applicationManager.getApplication(applicationUUID) == null) {
// if (log.isDebugEnabled()) {
// log.debug("Application with the UUID '" + applicationUUID + "' is not found.");
// }
// return Response.status(Response.Status.NOT_FOUND).entity("Application with the UUID '" +
// applicationUUID + "' is not found.").build();
// }
if (log.isDebugEnabled()) {
log.debug("Application with UUID '" + applicationUUID + "' is found. Request received for getting "
+ "next life-cycle states for the particular application.");
}
return Response.status(Response.Status.OK).entity(applicationManager.getLifeCycleStates(applicationUUID))
.build();
} catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) {
log.error("Application Management Exception while trying to get next states for the applications with "
+ "the application ID", e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
}

@ -0,0 +1,206 @@
/*
* 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);
}

@ -0,0 +1,127 @@
/*
* 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);
}
}
}

@ -44,7 +44,7 @@
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.SubscriptionManagerImpl</ClassName>
</Extension>
<Extension name="VisibilityManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.VisibilityManagerImpl</ClassName>
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.UnrestrictedRoleManagerImpl</ClassName>
</Extension>
<Extension name="ApplicationStorageManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationStorageManagerImpl</ClassName>

Loading…
Cancel
Save