Adding Application management functionalities and API

Adding application, application lifecycle and application release management business logic and also API implementation
feature/appm-store/pbac
lasantha 7 years ago
parent 5ee9983305
commit 460a356bee

@ -51,7 +51,7 @@ public interface ApplicationManager {
* @return Updated Application
* @throws ApplicationManagementException Application Management Exception
*/
Application editApplication(Application application) throws ApplicationManagementException;
Application updateApplication(Application application) throws ApplicationManagementException;
/**
* Delete an application identified by the unique ID.
@ -59,7 +59,7 @@ public interface ApplicationManager {
* @param applicationId ID for tha application
* @throws ApplicationManagementException Application Management Exception
*/
void deleteApplication(int applicationId) throws ApplicationManagementException;
List<String> deleteApplication(int applicationId) throws ApplicationManagementException;
/**
* Delete an application identified by the unique ID.
@ -68,7 +68,7 @@ public interface ApplicationManager {
* @param releaseUuid UUID of tha application release
* @throws ApplicationManagementException Application Management Exception
*/
void deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException;
String deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException;
/**
* To get the applications based on the search filter.
@ -88,27 +88,6 @@ public interface ApplicationManager {
*/
String getUuidOfLatestRelease(int appId) throws ApplicationManagementException;
/**
* To change the lifecycle of the Application.
*
* @param applicationUuid UUID of the Application
* @param lifecycleIdentifier New life-cycle that need to be changed.
* @throws ApplicationManagementException Application Management Exception.
*/
void changeLifecycle(String applicationUuid, String lifecycleIdentifier) throws
ApplicationManagementException;
/**
* To get the next possible life-cycle states for the application.
*
* @param applicationUUID UUID of the application.
* @return the List of possible states
* @throws ApplicationManagementException Application Management Exception
*/
List<LifecycleStateTransition> getLifeCycleStates(String applicationUUID)
throws ApplicationManagementException;
/**
* To get Application with the given UUID.
*
@ -163,9 +142,49 @@ public interface ApplicationManager {
*/
List<ApplicationRelease> getReleases(int applicationId) throws ApplicationManagementException;
LifecycleState getLifecycleState(int appReleaseId, String applicationUuid) throws LifecycleManagementException;
/**
* To get all the releases of a particular Application.
*
* @param applicationId ID of the Application .
* @param applicationUuid UUID of the Application Release.
* @return the LifecycleState of the Application releases related with the particular Application.
* @throws ApplicationManagementException Application Management Exception.
*/
LifecycleState getLifecycleState(int applicationId, String applicationUuid) throws ApplicationManagementException;
void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws LifecycleManagementException;
/**
* To get all the releases of a particular Application.
*
* @param applicationId ID of the Application.
* @param applicationUuid UUID of the Application Release.
* @throws ApplicationManagementException Application Management Exception.
*/
void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws ApplicationManagementException;
/**
* To validate the application existence for given application id
*
* @param applicationId ID of the Application.
* @throws ApplicationManagementException Application Management Exception.
*/
Application validateApplication(int applicationId) throws ApplicationManagementException;
/**
* To validate the application release existence for given application release UUID
*
* @param releaseUuid UUID of the Application Release.
* @throws ApplicationManagementException Application Management Exception.
*/
ApplicationRelease validateApplicationRelease(String releaseUuid) throws ApplicationManagementException;
/**
* To update with a new release for an Application.
*
* @param appId ID of the Application
* @param applicationRelease ApplicationRelease
* @return Updated Application Release.
* @throws ApplicationManagementException Application Management Exception.
*/
ApplicationRelease updateRelease(int appId, ApplicationRelease applicationRelease)
throws ApplicationManagementException;
}

@ -66,7 +66,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
private static final Log log = LogFactory.getLog(ApplicationManagerImpl.class);
private DeviceTypeDAO deviceTypeDAO;
private VisibilityDAO visibilityDAO;
private LifecycleStateDAO lifecycleStateDAO;
private ApplicationDAO applicationDAO;
public ApplicationManagerImpl() {
@ -76,7 +75,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
private void initDataAccessObjects() {
this.deviceTypeDAO = ApplicationManagementDAOFactory.getDeviceTypeDAO();
this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
}
@ -276,7 +274,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
return application;
} catch (UserStoreException e) {
throw new ApplicationManagementException(
"User-store exception while getting application with the " + "application id " + applicationId);
"User-store exception while getting application with the " + "application id " + applicationId, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -322,7 +320,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
return isRoleExists(unrestrictedRoles, userName);
} catch (UserStoreException e) {
throw new ApplicationManagementException(
"User-store exception while verifying whether user have assigned" + "unrestricted roles or not");
"User-store exception while verifying whether user have assigned" + "unrestricted roles or not", e);
}
}
@ -354,7 +352,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public void deleteApplication(int applicationId) throws ApplicationManagementException {
public List<String> deleteApplication(int applicationId) throws ApplicationManagementException {
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -362,6 +360,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException("Invalid Application");
}
List<ApplicationRelease> applicationReleases = getReleases(applicationId);
List<String> storedLocations = new ArrayList<>();
if (log.isDebugEnabled()) {
log.debug("Request is received to delete applications which are related with the application id " +
applicationId);
@ -374,12 +373,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
newAppLifecycleState.setTenantId(tenantId);
newAppLifecycleState.setUpdatedBy(userName);
addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState);
storedLocations.add(applicationRelease.getAppHashValue());
}
//todo add column into application and move application into removed state
return storedLocations;
}
@Override
public void deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException {
public String deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException {
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Application application = validateApplication(applicationId);
@ -399,6 +400,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
newAppLifecycleState.setTenantId(tenantId);
newAppLifecycleState.setUpdatedBy(userName);
addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState);
return applicationRelease.getAppHashValue();
}
/**
@ -459,7 +461,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationList applicationList = getApplications(filter);
if (applicationList != null && applicationList.getApplications() != null && !applicationList.getApplications()
.isEmpty()) {
throw new ValidationException(
throw new ApplicationManagementException(
"Already an application registered with same name - " + applicationList.getApplications().get(0)
.getName());
}
@ -471,7 +473,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
* @param applicationID ID of the Application.
* @return Application related with the UUID
*/
private Application validateApplication(int applicationID) throws ApplicationManagementException {
public Application validateApplication(int applicationID) throws ApplicationManagementException {
if (applicationID <= 0) {
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
+ "parameter to get the relevant application.");
@ -489,7 +491,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
* @param applicationUuid UUID of the Application.
* @return Application related with the UUID
*/
private ApplicationRelease validateApplicationRelease(String applicationUuid) throws ApplicationManagementException {
public 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.");
@ -503,6 +505,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
return applicationRelease;
}
@Override
public ApplicationRelease updateRelease(int appId, ApplicationRelease applicationRelease) throws ApplicationManagementException {
return null;
}
/**
* To get role restricted application list.
*
@ -559,7 +566,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public LifecycleState getLifecycleState(int applicationId, String applicationUuid) throws LifecycleManagementException {
public LifecycleState getLifecycleState(int applicationId, String applicationUuid) throws
ApplicationManagementException {
LifecycleState lifecycleState;
try {
ConnectionManagerUtil.openDBConnection();
@ -570,11 +578,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
lifecycleState = lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
lifecycleState.setNextStates(getNextLifecycleStates(lifecycleState.getCurrentState()));
} catch (ApplicationManagementDAOException e) {
throw new LifecycleManagementException("Failed to get lifecycle state", e);
} catch (DBConnectionException e) {
throw new LifecycleManagementException("Failed to connect with Database", e);
throw new ApplicationManagementException("Failed to get lifecycle state", e);
} catch (ApplicationManagementException e) {
throw new LifecycleManagementException("Failed to get application and application management", e);
throw new ApplicationManagementException("Failed to get application and application management", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -582,7 +588,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws LifecycleManagementException {
public void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws
ApplicationManagementException {
try {
ConnectionManagerUtil.openDBConnection();
Application application = validateApplication(applicationId);
@ -602,9 +609,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
lifecycleStateDAO.addLifecycleState(state);
}
} catch (LifeCycleManagementDAOException | DBConnectionException e) {
throw new LifecycleManagementException("Failed to add lifecycle state", e);
throw new ApplicationManagementException("Failed to add lifecycle state", e);
} catch (ApplicationManagementException e) {
throw new LifecycleManagementException("Lifecycle State Validation failed", e);
throw new ApplicationManagementException("Lifecycle State Validation failed", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -697,186 +704,47 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public Application editApplication(Application application) throws ApplicationManagementException {
// String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
// if (application.getUuid() == null) {
// throw new ValidationException("Application UUID cannot be empty");
// }
//
// if (!isApplicationOwnerOrAdmin(application.getUuid(), userName, tenantId)) {
// throw new ApplicationManagementException(
// "User " + userName + " does not have permissions to edit the " + "application with the UUID "
// + application.getUuid());
// }
// if (this.getApplication(application.getUuid()) != null) {
// if (application.getPlatform() == null || application.getPlatform().getIdentifier() == null) {
// throw new NotFoundException("Platform information not available with the application!");
// }
// Platform platform = DataHolder.getInstance().getPlatformManager()
// .getPlatform(tenantId, application.getPlatform().getIdentifier());
// if (platform == null) {
// throw new NotFoundException(
// "Platform specified by identifier " + application.getPlatform().getIdentifier()
// + " is not found. Please give a valid platform identifier.");
// }
// application.setPlatform(platform);
// if (application.getCategory() != null) {
// String applicationCategoryName = application.getCategory().getName();
// if (applicationCategoryName == null || applicationCategoryName.isEmpty()) {
// throw new ApplicationManagementException(
// "Application category name cannot be null or " + "empty. Cannot edit the application.");
// }
// Category category = DataHolder.getInstance().getCategoryManager()
// .getCategory(application.getCategory().getName());
// if (category == null) {
// throw new NotFoundException(
// "Invalid Category is provided for the application " + application.getUuid() + ". "
// + "Cannot edit application");
// }
// application.setCategory(category);
// }
// try {
// ConnectionManagerUtil.beginDBTransaction();
// ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
// application.setModifiedAt(new Date());
// Application modifiedApplication = applicationDAO.editApplication(application, tenantId);
// Visibility visibility = DataHolder.getInstance().getVisibilityManager()
// .put(application.getId(), application.getVisibility());
// modifiedApplication.setVisibility(visibility);
// ConnectionManagerUtil.commitDBTransaction();
// return modifiedApplication;
// } catch (ApplicationManagementDAOException e) {
// ConnectionManagerUtil.rollbackDBTransaction();
// throw e;
// } finally {
// ConnectionManagerUtil.closeDBConnection();
// }
// } else {
// throw new NotFoundException("No applications found with application UUID - " + application.getUuid());
// }
return application;
public Application updateApplication(Application application) throws ApplicationManagementException {
Application existingApplication = validateApplication(application.getId());
if (existingApplication == null) {
throw new NotFoundException("Tried to update Application which is not in the publisher, " +
"Please verify application details");
}
@Override
public void changeLifecycle(String applicationUuid, String lifecycleIdentifier)
throws ApplicationManagementException {
// boolean isAvailableNextState = false;
// String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
// List<LifecycleStateTransition> nextLifeCycles = getLifeCycleStates(applicationUuid);
//
// for (LifecycleStateTransition lifecycleStateTransition : nextLifeCycles) {
// if (log.isDebugEnabled()) {
// log.debug("Lifecycle state of the application " + applicationUuid + " can be changed to"
// + lifecycleStateTransition.getNextState());
// }
// if (lifecycleStateTransition.getNextState().equalsIgnoreCase(lifecycleIdentifier)) {
// isAvailableNextState = true;
// break;
// }
// }
// if (!isAvailableNextState) {
// throw new ApplicationManagementException("User " + userName + " does not have the permission to change "
// + "the lifecycle state of the application " + applicationUuid + " to lifecycle state "
// + lifecycleIdentifier);
// }
// try {
// ConnectionManagerUtil.beginDBTransaction();
// ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
// applicationDAO.changeLifecycle(applicationUuid, lifecycleIdentifier, userName, tenantId);
// ConnectionManagerUtil.commitDBTransaction();
// } catch (ApplicationManagementDAOException e) {
// ConnectionManagerUtil.rollbackDBTransaction();
// throw e;
// } finally {
// ConnectionManagerUtil.closeDBConnection();
// }
if (!existingApplication.getType().equals(application.getType())) {
throw new ApplicationManagementException("You are trying to change the application type and it is not " +
"possible after you create an application. Therefore please remove this application and publish " +
"new application with type: " + application.getType());
}
@Override
public List<LifecycleStateTransition> getLifeCycleStates(String applicationUUID)
throws ApplicationManagementException {
// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
// String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
// boolean isAdminOrApplicationOwner = isApplicationOwnerOrAdmin(applicationUUID, userName, tenantId);
//
// if (log.isDebugEnabled()) {
// log.debug("User " + userName + " in tenant " + tenantId + " is an Admin or Application owner of the "
// + "application " + applicationUUID);
// }
// try {
// ConnectionManagerUtil.openDBConnection();
// List<LifecycleStateTransition> transitions = ApplicationManagementDAOFactory.getApplicationDAO()
// .getNextLifeCycleStates(applicationUUID, tenantId);
// List<LifecycleStateTransition> filteredTransitions = new ArrayList<>();
//
// if (log.isDebugEnabled()) {
// log.debug("Lifecycle of the application with UUID : " + applicationUUID + " can be changed to "
// + transitions.size() + ". The number may vary according to the permission level of user : "
// + userName + " of tenant " + tenantId);
// }
// for (LifecycleStateTransition transition : transitions) {
// String permission = transition.getPermission();
// if (permission != null) {
// if (log.isDebugEnabled()) {
// log.debug("In order to make the state change to " + transition.getNextState() + " permission "
// + permission + " is required");
// }
// if (isAdminUser(userName, tenantId, permission)) {
// filteredTransitions.add(transition);
// } else {
// if (log.isDebugEnabled()) {
// log.debug("User " + userName + " does not have the permission " + permission + " to "
// + "change the life-cycle state to " + transition.getNextState() + " of the "
// + "application " + applicationUUID);
// }
// }
// } else if (isAdminOrApplicationOwner) {
// filteredTransitions.add(transition);
// }
// }
// if (log.isDebugEnabled()) {
// log.debug("User " + userName + " can do " + filteredTransitions.size() + " life-cyle state changes "
// + "currently on application with the UUID " + applicationUUID);
// }
// return filteredTransitions;
// } catch (UserStoreException e) {
// throw new ApplicationManagementException(
// "Userstore exception while checking whether user " + userName + " from tenant " + tenantId
// + " is authorized to do a life-cycle status change in an application ", e);
// } finally {
// ConnectionManagerUtil.closeDBConnection();
// }
return null;
if (existingApplication.getIsFree() != application.getIsFree()) {
if (existingApplication.getIsFree() == 1) {
if (application.getPaymentCurrency() != null || !application.getPaymentCurrency().equals("")) {
throw new ApplicationManagementException("If you are going to change Non-Free app as Free app, " +
"currency attribute in the application updating payload should be null or \"\"");
}
/**
* To check whether current user is application owner or admin.
*
* @param applicationUUID UUID of the Application.
* @return true if the current user is application owner or admin, unless false.
* @throws ApplicationManagementException Application Management Exception.
*/
private boolean isApplicationOwnerOrAdmin(String applicationUUID, String userName, int tenantId)
throws ApplicationManagementException {
// try {
// if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
// return true;
// }
// } catch (UserStoreException e) {
// throw new ApplicationManagementException("Userstore exception while checking whether user is an admin", e);
// }
// try {
// ConnectionManagerUtil.openDBConnection();
// Application application = ApplicationManagementDAOFactory.getApplicationDAO()
// .getApplication(applicationUUID, tenantId, userName);
// return application.getUser().getUserName().equals(userName)
// && application.getUser().getTenantId() == tenantId;
// } finally {
// ConnectionManagerUtil.closeDBConnection();
// }
return false;
} else if (existingApplication.getIsFree() == 0) {
if (application.getPaymentCurrency() == null || application.getPaymentCurrency().equals("")) {
throw new ApplicationManagementException("If you are going to change Free app as Non-Free app, " +
"currency attribute in the application payload should not be null or \"\"");
}
}
}
//todo get restricted roles and assign for application
if (existingApplication.getIsRestricted() != application.getIsRestricted()) {
if (existingApplication.getIsRestricted() == 1) {
if (application.getUnrestrictedRoles() == null || application.getUnrestrictedRoles().isEmpty()) {
throw new ApplicationManagementException("If you are going to add role restriction for non role " +
"restricted Application, Unrestricted role list won't be empty or null");
}
} else if (existingApplication.getIsRestricted() == 0) {
if (application.getUnrestrictedRoles() != null || !application.getUnrestrictedRoles().isEmpty()) {
throw new ApplicationManagementException("If you are going to remove role restriction from role " +
"restricted Application, Unrestricted role list should be empty or null");
}
}
//todo update role restriction
}
//todo get tags and assign for application verify
//todo update application
return application;
}
}

@ -32,6 +32,7 @@ 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.LifecycleState;
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
@ -229,7 +230,7 @@ public interface ApplicationManagementAPI {
message = "Internal Server Error. \n Error occurred while editing the application.",
response = ErrorResponse.class)
})
Response editApplication(
Response updateApplication(
@ApiParam(
name = "application",
value = "The application that need to be edited.",
@ -333,55 +334,6 @@ public interface ApplicationManagementAPI {
required = true)
@PathParam("appid") int applicationId);
@PUT
@Consumes("application/json")
@Path("/{uuid}/{version}/{channel}")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Make the particular application release as default or not",
notes = "Make the particular application release as default or not",
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 updateDefaultVersion(
@ApiParam(
name = "UUID",
value = "Unique identifier of the Application",
required = true)
@PathParam("uuid") String applicationUUID,
@ApiParam(
name = "Version",
value = "Version of the Application Release",
required = true)
@PathParam("version") String version,
@ApiParam(
name = "Release Channel",
value = "Release Channel",
required = true)
@PathParam("channel") String channel,
@ApiParam(
name = "isDefault",
value = "Whether to make it default or not",
required = false)
@QueryParam("isDefault") boolean isDefault);
@POST
@Path("/image-artifacts/{appId}/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@ -483,4 +435,71 @@ public interface ApplicationManagementAPI {
@Multipart(value = "icon", required = false) Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart(value = "screenshot", required = false) List<Attachment> attachmentList);
@GET
@Path("/lifecycle/{appId}/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get lifecycle states",
notes = "Get all lifecycle states",
tags = "Lifecycle Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:lifecycle:get")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved lifecycle states.",
response = List.class,
responseContainer = "List"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the lifecycle list.",
response = ErrorResponse.class)
})
Response getLifecycleState(@PathParam("appId") int applicationId,
@PathParam("uuid") String applicationUuid);
@POST
@Path("/lifecycle/{appId}/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Add a lifecycle state",
notes = "This will add a new lifecycle state",
tags = "Lifecycle Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:lifecycle:add")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "OK. \n Successfully add a lifecycle state.",
response = Application.class),
@ApiResponse(
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested "
+ "resource."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred adding a lifecycle state.",
response = ErrorResponse.class)
})
Response addLifecycleState(@PathParam("appId") int applicationId,
@PathParam("uuid") String applicationUuid,
LifecycleState state);
}

@ -22,16 +22,13 @@ 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.*;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.publisher.api.APIUtil;
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.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.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.core.exception.NotFoundException;
@ -125,7 +122,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@Multipart("banner") Attachment bannerFile,
@Multipart("screenshot") List<Attachment> attachmentList) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
InputStream iconFileStream;
InputStream bannerFileStream;
@ -204,14 +200,14 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@Path("/image-artifacts/{appId}/{uuid}")
public Response updateApplicationImageArtifacts(
@PathParam("appId") int appId,
@PathParam("uuid") String applicationUUID,
@PathParam("uuid") String applicationUuid,
@Multipart("icon") Attachment iconFile,
@Multipart("banner") Attachment bannerFile,
@Multipart("screenshot") List<Attachment> attachmentList) {
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
ApplicationRelease applicationRelease = null;
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationRelease applicationRelease;
try {
InputStream iconFileStream = null;
@ -229,11 +225,12 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
attachments.add(screenshot.getDataHandler().getInputStream());
}
}
applicationRelease = applicationManager.validateApplicationRelease(applicationUuid);
applicationRelease = applicationStorageManager
.updateImageArtifacts(appId, applicationUUID, iconFileStream, bannerFileStream, attachments);
applicationReleaseManager.updateRelease(appId, applicationRelease);
.updateImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments);
applicationManager.updateRelease(appId, applicationRelease);
return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationUUID).build();
.entity("Successfully uploaded artifacts for the application " + applicationUuid).build();
} catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) {
@ -241,13 +238,13 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
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);
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),
"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);
+ applicationUuid, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
@ -260,14 +257,17 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@PathParam("uuid") String applicationUuuid,
@Multipart("binaryFile") Attachment binaryFile) {
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
ApplicationRelease applicationRelease = null;
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationRelease applicationRelease;
try {
if (binaryFile != null) {
applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationId, applicationUuuid,
applicationRelease = applicationManager.validateApplicationRelease(applicationUuuid);
applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationRelease,
binaryFile.getDataHandler().getInputStream());
applicationReleaseManager.updateRelease(applicationId, applicationRelease);
applicationManager.updateRelease(applicationId, applicationRelease);
return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationUuuid).build();
@ -291,13 +291,12 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
}
//Todo Not complete
@PUT
@Consumes("application/json")
public Response editApplication(@Valid Application application) {
public Response updateApplication(@Valid Application application) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
application = applicationManager.editApplication(application);
application = applicationManager.updateApplication(application);
} catch (NotFoundException e) {
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
} catch (ApplicationManagementException e) {
@ -308,42 +307,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
return Response.status(Response.Status.OK).entity(application).build();
}
@DELETE
@Path("/{appid}")
public Response deleteApplication(@PathParam("appid") int applicationId) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
applicationManager.deleteApplication(applicationId);
// todo delete storage details
// applicationStorageManager.deleteApplicationArtifacts(uuid);
String responseMsg = "Successfully deleted the application: " + applicationId;
return Response.status(Response.Status.OK).entity(responseMsg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while deleting the application: " + applicationId;
log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
@DELETE
@Path("/{appid}/{uuid}")
public Response deleteApplicationRelease(@PathParam("appid") int applicationId, @PathParam("uuid") String releaseUuid) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
applicationManager.deleteApplication(applicationId);
// todo delete release storage details
// applicationStorageManager.deleteApplicationArtifacts(uuid);
String responseMsg = "Successfully deleted the application release of: " + applicationId + "";
return Response.status(Response.Status.OK).entity(responseMsg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while deleting the application: " + applicationId;
log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
@Override
@PUT
@Path("/{appId}/{uuid}")
@ -355,7 +318,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@Multipart("icon") Attachment iconFile,
@Multipart("banner") Attachment bannerFile,
@Multipart("screenshot") List<Attachment> attachmentList) {
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
InputStream iconFileStream = null;
InputStream bannerFileStream = null;
@ -363,11 +326,10 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
try {
if (binaryFile != null) {
applicationRelease = applicationManager.validateApplicationRelease(applicationUUID);
//todo add binary file validation
applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationId, applicationUUID,
binaryFile.getDataHandler().getInputStream());
if (binaryFile != null) {
applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationRelease, binaryFile.getDataHandler().getInputStream());
}
if (iconFile != null) {
@ -385,10 +347,9 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
}
applicationRelease = applicationStorageManager
.updateImageArtifacts(applicationId, applicationUUID, iconFileStream, bannerFileStream,
attachments);
.updateImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments);
applicationRelease = applicationReleaseManager.updateRelease(applicationId, applicationRelease);
applicationRelease = applicationManager.updateRelease(applicationId, applicationRelease);
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (NotFoundException e) {
@ -408,27 +369,80 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
}
}
@DELETE
@Path("/{appid}")
public Response deleteApplication(@PathParam("appid") int applicationId) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
List<String> storedLocations = applicationManager.deleteApplication(applicationId);
applicationStorageManager.deleteAllApplicationReleaseArtifacts(storedLocations);
String responseMsg = "Successfully deleted the application and application releases: " + applicationId;
return Response.status(Response.Status.OK).entity(responseMsg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while deleting the application: " + applicationId;
log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
} catch (ApplicationStorageManagementException e) {
String msg = "Error occurred while deleting the application storage: " + applicationId;
log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
// todo I think we must remove this
@Override
@PUT
@Consumes("application/json")
@Path("/{uuid}/{version}/{channel}")
public Response updateDefaultVersion(@PathParam("uuid") String applicationUUID, @PathParam("version") String
version, @PathParam("channel") String channel, @QueryParam("isDefault") boolean isDefault) {
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
@DELETE
@Path("/{appid}/{uuid}")
public Response deleteApplicationRelease(@PathParam("appid") int applicationId, @PathParam("uuid") String releaseUuid) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
applicationReleaseManager.changeDefaultRelease(applicationUUID, version, isDefault, channel);
return Response.status(Response.Status.OK)
.entity("Successfully changed the default version for the " + "release channel " + channel
+ " for the application UUID " + applicationUUID).build();
} catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
String storedLocation = applicationManager.deleteApplicationRelease(applicationId, releaseUuid);
applicationStorageManager.deleteApplicationReleaseArtifacts(storedLocation);
String responseMsg = "Successfully deleted the application release of: " + applicationId + "";
return Response.status(Response.Status.OK).entity(responseMsg).build();
} catch (ApplicationManagementException e) {
log.error("Application Release Management Exception while changing the default release for the release "
+ "channel " + channel + " for the application with UUID " + applicationUUID + " for the version "
+ version);
String msg = "Error occurred while deleting the application: " + applicationId;
log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
} catch (ApplicationStorageManagementException e) {
String msg = "Error occurred while deleting the application storage: " + applicationId;
log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
@GET
@Path("/lifecycle/{appId}/{uuid}")
public Response getLifecycleState(
@PathParam("appId") int applicationId,
@PathParam("uuid") String applicationUuid) {
LifecycleState lifecycleState;
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
lifecycleState = applicationManager.getLifecycleState(applicationId, applicationUuid);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting lifecycle state.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
}
return Response.status(Response.Status.OK).entity(lifecycleState).build();
}
@POST
@Path("/lifecycle/{appId}/{uuid}")
public Response addLifecycleState(
@PathParam("appId") int applicationId,
@PathParam("uuid") String applicationUuid,
LifecycleState state) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
applicationManager.addLifecycleState(applicationId, applicationUuid, state);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while adding lifecycle state.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
}
return Response.status(Response.Status.CREATED).entity("Lifecycle state added successfully.").build();
}
}

Loading…
Cancel
Save