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 * @return Updated Application
* @throws ApplicationManagementException Application Management Exception * @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. * Delete an application identified by the unique ID.
@ -59,7 +59,7 @@ public interface ApplicationManager {
* @param applicationId ID for tha application * @param applicationId ID for tha application
* @throws ApplicationManagementException Application Management Exception * @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. * Delete an application identified by the unique ID.
@ -68,7 +68,7 @@ public interface ApplicationManager {
* @param releaseUuid UUID of tha application release * @param releaseUuid UUID of tha application release
* @throws ApplicationManagementException Application Management Exception * @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. * To get the applications based on the search filter.
@ -88,27 +88,6 @@ public interface ApplicationManager {
*/ */
String getUuidOfLatestRelease(int appId) throws ApplicationManagementException; 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. * To get Application with the given UUID.
* *
@ -163,9 +142,49 @@ public interface ApplicationManager {
*/ */
List<ApplicationRelease> getReleases(int applicationId) throws ApplicationManagementException; 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;
/**
* 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;
void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws LifecycleManagementException; /**
* 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 static final Log log = LogFactory.getLog(ApplicationManagerImpl.class);
private DeviceTypeDAO deviceTypeDAO; private DeviceTypeDAO deviceTypeDAO;
private VisibilityDAO visibilityDAO; private VisibilityDAO visibilityDAO;
private LifecycleStateDAO lifecycleStateDAO;
private ApplicationDAO applicationDAO; private ApplicationDAO applicationDAO;
public ApplicationManagerImpl() { public ApplicationManagerImpl() {
@ -76,7 +75,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
private void initDataAccessObjects() { private void initDataAccessObjects() {
this.deviceTypeDAO = ApplicationManagementDAOFactory.getDeviceTypeDAO(); this.deviceTypeDAO = ApplicationManagementDAOFactory.getDeviceTypeDAO();
this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO(); this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
} }
@ -276,7 +274,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
return application; return application;
} catch (UserStoreException e) { } catch (UserStoreException e) {
throw new ApplicationManagementException( 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 { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -322,7 +320,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
return isRoleExists(unrestrictedRoles, userName); return isRoleExists(unrestrictedRoles, userName);
} catch (UserStoreException e) { } catch (UserStoreException e) {
throw new ApplicationManagementException( 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 @Override
public void deleteApplication(int applicationId) throws ApplicationManagementException { public List<String> deleteApplication(int applicationId) throws ApplicationManagementException {
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -362,6 +360,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException("Invalid Application"); throw new ApplicationManagementException("Invalid Application");
} }
List<ApplicationRelease> applicationReleases = getReleases(applicationId); List<ApplicationRelease> applicationReleases = getReleases(applicationId);
List<String> storedLocations = new ArrayList<>();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request is received to delete applications which are related with the application id " + log.debug("Request is received to delete applications which are related with the application id " +
applicationId); applicationId);
@ -374,12 +373,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
newAppLifecycleState.setTenantId(tenantId); newAppLifecycleState.setTenantId(tenantId);
newAppLifecycleState.setUpdatedBy(userName); newAppLifecycleState.setUpdatedBy(userName);
addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState); addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState);
storedLocations.add(applicationRelease.getAppHashValue());
} }
//todo add column into application and move application into removed state //todo add column into application and move application into removed state
return storedLocations;
} }
@Override @Override
public void deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException { public String deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException {
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Application application = validateApplication(applicationId); Application application = validateApplication(applicationId);
@ -399,6 +400,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
newAppLifecycleState.setTenantId(tenantId); newAppLifecycleState.setTenantId(tenantId);
newAppLifecycleState.setUpdatedBy(userName); newAppLifecycleState.setUpdatedBy(userName);
addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState); addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState);
return applicationRelease.getAppHashValue();
} }
/** /**
@ -459,7 +461,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationList applicationList = getApplications(filter); ApplicationList applicationList = getApplications(filter);
if (applicationList != null && applicationList.getApplications() != null && !applicationList.getApplications() if (applicationList != null && applicationList.getApplications() != null && !applicationList.getApplications()
.isEmpty()) { .isEmpty()) {
throw new ValidationException( throw new ApplicationManagementException(
"Already an application registered with same name - " + applicationList.getApplications().get(0) "Already an application registered with same name - " + applicationList.getApplications().get(0)
.getName()); .getName());
} }
@ -471,7 +473,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
* @param applicationID ID of the Application. * @param applicationID ID of the Application.
* @return Application related with the UUID * @return Application related with the UUID
*/ */
private Application validateApplication(int applicationID) throws ApplicationManagementException { public Application validateApplication(int applicationID) throws ApplicationManagementException {
if (applicationID <= 0) { if (applicationID <= 0) {
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required " throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
+ "parameter to get the relevant application."); + "parameter to get the relevant application.");
@ -489,7 +491,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
* @param applicationUuid UUID of the Application. * @param applicationUuid UUID of the Application.
* @return Application related with the UUID * @return Application related with the UUID
*/ */
private ApplicationRelease validateApplicationRelease(String applicationUuid) throws ApplicationManagementException { public ApplicationRelease validateApplicationRelease(String applicationUuid) throws ApplicationManagementException {
if (applicationUuid == null) { if (applicationUuid == null) {
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required " throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
+ "parameter to get the relevant application."); + "parameter to get the relevant application.");
@ -503,6 +505,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
return applicationRelease; return applicationRelease;
} }
@Override
public ApplicationRelease updateRelease(int appId, ApplicationRelease applicationRelease) throws ApplicationManagementException {
return null;
}
/** /**
* To get role restricted application list. * To get role restricted application list.
* *
@ -559,7 +566,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public LifecycleState getLifecycleState(int applicationId, String applicationUuid) throws LifecycleManagementException { public LifecycleState getLifecycleState(int applicationId, String applicationUuid) throws
ApplicationManagementException {
LifecycleState lifecycleState; LifecycleState lifecycleState;
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
@ -570,11 +578,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
lifecycleState = lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); lifecycleState = lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
lifecycleState.setNextStates(getNextLifecycleStates(lifecycleState.getCurrentState())); lifecycleState.setNextStates(getNextLifecycleStates(lifecycleState.getCurrentState()));
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
throw new LifecycleManagementException("Failed to get lifecycle state", e); throw new ApplicationManagementException("Failed to get lifecycle state", e);
} catch (DBConnectionException e) {
throw new LifecycleManagementException("Failed to connect with Database", e);
} catch (ApplicationManagementException 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 { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -582,7 +588,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws LifecycleManagementException { public void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws
ApplicationManagementException {
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
Application application = validateApplication(applicationId); Application application = validateApplication(applicationId);
@ -602,9 +609,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
lifecycleStateDAO.addLifecycleState(state); lifecycleStateDAO.addLifecycleState(state);
} }
} catch (LifeCycleManagementDAOException | DBConnectionException e) { } 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) { } catch (ApplicationManagementException e) {
throw new LifecycleManagementException("Lifecycle State Validation failed", e); throw new ApplicationManagementException("Lifecycle State Validation failed", e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -697,186 +704,47 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public Application editApplication(Application application) throws ApplicationManagementException { public Application updateApplication(Application application) throws ApplicationManagementException {
// String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); Application existingApplication = validateApplication(application.getId());
// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); if (existingApplication == null) {
// if (application.getUuid() == null) { throw new NotFoundException("Tried to update Application which is not in the publisher, " +
// throw new ValidationException("Application UUID cannot be empty"); "Please verify application details");
// } }
// if (!existingApplication.getType().equals(application.getType())) {
// if (!isApplicationOwnerOrAdmin(application.getUuid(), userName, tenantId)) { throw new ApplicationManagementException("You are trying to change the application type and it is not " +
// throw new ApplicationManagementException( "possible after you create an application. Therefore please remove this application and publish " +
// "User " + userName + " does not have permissions to edit the " + "application with the UUID " "new application with type: " + application.getType());
// + application.getUuid()); }
// } if (existingApplication.getIsFree() != application.getIsFree()) {
// if (this.getApplication(application.getUuid()) != null) { if (existingApplication.getIsFree() == 1) {
// if (application.getPlatform() == null || application.getPlatform().getIdentifier() == null) { if (application.getPaymentCurrency() != null || !application.getPaymentCurrency().equals("")) {
// throw new NotFoundException("Platform information not available with the application!"); 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 \"\"");
// Platform platform = DataHolder.getInstance().getPlatformManager() }
// .getPlatform(tenantId, application.getPlatform().getIdentifier()); } else if (existingApplication.getIsFree() == 0) {
// if (platform == null) { if (application.getPaymentCurrency() == null || application.getPaymentCurrency().equals("")) {
// throw new NotFoundException( throw new ApplicationManagementException("If you are going to change Free app as Non-Free app, " +
// "Platform specified by identifier " + application.getPlatform().getIdentifier() "currency attribute in the application payload should not be null or \"\"");
// + " is not found. Please give a valid platform identifier."); }
// } }
// application.setPlatform(platform); }
// if (application.getCategory() != null) { //todo get restricted roles and assign for application
// String applicationCategoryName = application.getCategory().getName(); if (existingApplication.getIsRestricted() != application.getIsRestricted()) {
// if (applicationCategoryName == null || applicationCategoryName.isEmpty()) { if (existingApplication.getIsRestricted() == 1) {
// throw new ApplicationManagementException( if (application.getUnrestrictedRoles() == null || application.getUnrestrictedRoles().isEmpty()) {
// "Application category name cannot be null or " + "empty. Cannot edit the application."); 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");
// Category category = DataHolder.getInstance().getCategoryManager() }
// .getCategory(application.getCategory().getName()); } else if (existingApplication.getIsRestricted() == 0) {
// if (category == null) { if (application.getUnrestrictedRoles() != null || !application.getUnrestrictedRoles().isEmpty()) {
// throw new NotFoundException( throw new ApplicationManagementException("If you are going to remove role restriction from role " +
// "Invalid Category is provided for the application " + application.getUuid() + ". " "restricted Application, Unrestricted role list should be empty or null");
// + "Cannot edit application"); }
// } }
// application.setCategory(category); //todo update role restriction
// } }
// try { //todo get tags and assign for application verify
// ConnectionManagerUtil.beginDBTransaction(); //todo update application
// 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; return application;
} }
@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();
// }
}
@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;
}
/**
* 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;
}
} }

@ -32,6 +32,7 @@ import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes; 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.publisher.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ApplicationList;
@ -229,7 +230,7 @@ public interface ApplicationManagementAPI {
message = "Internal Server Error. \n Error occurred while editing the application.", message = "Internal Server Error. \n Error occurred while editing the application.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response editApplication( Response updateApplication(
@ApiParam( @ApiParam(
name = "application", name = "application",
value = "The application that need to be edited.", value = "The application that need to be edited.",
@ -333,55 +334,6 @@ public interface ApplicationManagementAPI {
required = true) required = true)
@PathParam("appid") int applicationId); @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 @POST
@Path("/image-artifacts/{appId}/{uuid}") @Path("/image-artifacts/{appId}/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -483,4 +435,71 @@ public interface ApplicationManagementAPI {
@Multipart(value = "icon", required = false) Attachment iconFile, @Multipart(value = "icon", required = false) Attachment iconFile,
@Multipart(value = "banner", required = false) Attachment bannerFile, @Multipart(value = "banner", required = false) Attachment bannerFile,
@Multipart(value = "screenshot", required = false) List<Attachment> attachmentList); @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.commons.logging.LogFactory;
import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart; 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.APIUtil;
import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementAPI; 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.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; 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.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.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
@ -125,7 +122,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@Multipart("banner") Attachment bannerFile, @Multipart("banner") Attachment bannerFile,
@Multipart("screenshot") List<Attachment> attachmentList) { @Multipart("screenshot") List<Attachment> attachmentList) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
InputStream iconFileStream; InputStream iconFileStream;
InputStream bannerFileStream; InputStream bannerFileStream;
@ -204,14 +200,14 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@Path("/image-artifacts/{appId}/{uuid}") @Path("/image-artifacts/{appId}/{uuid}")
public Response updateApplicationImageArtifacts( public Response updateApplicationImageArtifacts(
@PathParam("appId") int appId, @PathParam("appId") int appId,
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUuid,
@Multipart("icon") Attachment iconFile, @Multipart("icon") Attachment iconFile,
@Multipart("banner") Attachment bannerFile, @Multipart("banner") Attachment bannerFile,
@Multipart("screenshot") List<Attachment> attachmentList) { @Multipart("screenshot") List<Attachment> attachmentList) {
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationRelease applicationRelease = null; ApplicationRelease applicationRelease;
try { try {
InputStream iconFileStream = null; InputStream iconFileStream = null;
@ -229,11 +225,12 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
attachments.add(screenshot.getDataHandler().getInputStream()); attachments.add(screenshot.getDataHandler().getInputStream());
} }
} }
applicationRelease = applicationManager.validateApplicationRelease(applicationUuid);
applicationRelease = applicationStorageManager applicationRelease = applicationStorageManager
.updateImageArtifacts(appId, applicationUUID, iconFileStream, bannerFileStream, attachments); .updateImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments);
applicationReleaseManager.updateRelease(appId, applicationRelease); applicationManager.updateRelease(appId, applicationRelease);
return Response.status(Response.Status.OK) 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) { } catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build(); return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
@ -241,13 +238,13 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
log.error(msg, e); log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.BAD_REQUEST); return APIUtil.getResponse(e, Response.Status.BAD_REQUEST);
} catch (IOException e) { } 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( 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); Response.Status.BAD_REQUEST);
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
log.error("Error occurred while uploading the image artifacts of the application with the uuid " 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); return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
} }
} }
@ -260,14 +257,17 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@PathParam("uuid") String applicationUuuid, @PathParam("uuid") String applicationUuuid,
@Multipart("binaryFile") Attachment binaryFile) { @Multipart("binaryFile") Attachment binaryFile) {
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationRelease applicationRelease = null;
ApplicationRelease applicationRelease;
try { try {
if (binaryFile != null) { if (binaryFile != null) {
applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationId, applicationUuuid, applicationRelease = applicationManager.validateApplicationRelease(applicationUuuid);
applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationRelease,
binaryFile.getDataHandler().getInputStream()); binaryFile.getDataHandler().getInputStream());
applicationReleaseManager.updateRelease(applicationId, applicationRelease); applicationManager.updateRelease(applicationId, applicationRelease);
return Response.status(Response.Status.OK) return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationUuuid).build(); .entity("Successfully uploaded artifacts for the application " + applicationUuuid).build();
@ -291,13 +291,12 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} }
//Todo Not complete
@PUT @PUT
@Consumes("application/json") @Consumes("application/json")
public Response editApplication(@Valid Application application) { public Response updateApplication(@Valid Application application) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
application = applicationManager.editApplication(application); application = applicationManager.updateApplication(application);
} catch (NotFoundException e) { } catch (NotFoundException e) {
return APIUtil.getResponse(e, Response.Status.NOT_FOUND); return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
@ -308,42 +307,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
return Response.status(Response.Status.OK).entity(application).build(); 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 @Override
@PUT @PUT
@Path("/{appId}/{uuid}") @Path("/{appId}/{uuid}")
@ -355,7 +318,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@Multipart("icon") Attachment iconFile, @Multipart("icon") Attachment iconFile,
@Multipart("banner") Attachment bannerFile, @Multipart("banner") Attachment bannerFile,
@Multipart("screenshot") List<Attachment> attachmentList) { @Multipart("screenshot") List<Attachment> attachmentList) {
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
InputStream iconFileStream = null; InputStream iconFileStream = null;
InputStream bannerFileStream = null; InputStream bannerFileStream = null;
@ -363,11 +326,10 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
try { try {
if (binaryFile != null) { applicationRelease = applicationManager.validateApplicationRelease(applicationUUID);
//todo add binary file validation if (binaryFile != null) {
applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationId, applicationUUID, applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationRelease, binaryFile.getDataHandler().getInputStream());
binaryFile.getDataHandler().getInputStream());
} }
if (iconFile != null) { if (iconFile != null) {
@ -385,10 +347,9 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} }
applicationRelease = applicationStorageManager applicationRelease = applicationStorageManager
.updateImageArtifacts(applicationId, applicationUUID, iconFileStream, bannerFileStream, .updateImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments);
attachments);
applicationRelease = applicationReleaseManager.updateRelease(applicationId, applicationRelease); applicationRelease = applicationManager.updateRelease(applicationId, applicationRelease);
return Response.status(Response.Status.OK).entity(applicationRelease).build(); return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (NotFoundException e) { } 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 @DELETE
@Override @Path("/{appid}/{uuid}")
@PUT public Response deleteApplicationRelease(@PathParam("appid") int applicationId, @PathParam("uuid") String releaseUuid) {
@Consumes("application/json") ApplicationManager applicationManager = APIUtil.getApplicationManager();
@Path("/{uuid}/{version}/{channel}") ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
public Response updateDefaultVersion(@PathParam("uuid") String applicationUUID, @PathParam("version") String
version, @PathParam("channel") String channel, @QueryParam("isDefault") boolean isDefault) {
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
try { try {
applicationReleaseManager.changeDefaultRelease(applicationUUID, version, isDefault, channel); String storedLocation = applicationManager.deleteApplicationRelease(applicationId, releaseUuid);
return Response.status(Response.Status.OK) applicationStorageManager.deleteApplicationReleaseArtifacts(storedLocation);
.entity("Successfully changed the default version for the " + "release channel " + channel String responseMsg = "Successfully deleted the application release of: " + applicationId + "";
+ " for the application UUID " + applicationUUID).build(); return Response.status(Response.Status.OK).entity(responseMsg).build();
} catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
log.error("Application Release Management Exception while changing the default release for the release " String msg = "Error occurred while deleting the application: " + applicationId;
+ "channel " + channel + " for the application with UUID " + applicationUUID + " for the version " log.error(msg, e);
+ version);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); 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