|
|
@ -39,6 +39,7 @@ import org.wso2.carbon.device.application.mgt.common.ApplicationSubscriptionType
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ApplicationType;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ApplicationType;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.CategoryDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.CategoryDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.Filter;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.Filter;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.TagDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.TagDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
|
|
@ -59,6 +60,7 @@ import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
|
|
|
@ -109,6 +111,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
private ApplicationDAO applicationDAO;
|
|
|
|
private ApplicationDAO applicationDAO;
|
|
|
|
private ApplicationReleaseDAO applicationReleaseDAO;
|
|
|
|
private ApplicationReleaseDAO applicationReleaseDAO;
|
|
|
|
private LifecycleStateDAO lifecycleStateDAO;
|
|
|
|
private LifecycleStateDAO lifecycleStateDAO;
|
|
|
|
|
|
|
|
private SubscriptionDAO subscriptionDAO;
|
|
|
|
private LifecycleStateManager lifecycleStateManager;
|
|
|
|
private LifecycleStateManager lifecycleStateManager;
|
|
|
|
|
|
|
|
|
|
|
|
public ApplicationManagerImpl() {
|
|
|
|
public ApplicationManagerImpl() {
|
|
|
@ -121,6 +124,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
|
|
|
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
|
|
|
this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
|
|
|
|
this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
|
|
|
|
this.applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
|
|
|
|
this.applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
|
|
|
|
|
|
|
|
this.subscriptionDAO = ApplicationManagementDAOFactory.getSubscriptionDAO();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
/***
|
|
|
@ -1230,86 +1234,91 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String deleteApplicationRelease(int applicationId, String releaseUuid)
|
|
|
|
public void deleteApplicationRelease(int applicationId, String releaseUuid)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager();
|
|
|
|
ApplicationDTO application;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
application = this.applicationDAO.getApplicationById(applicationId, tenantId);
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO
|
|
|
|
if (application == null) {
|
|
|
|
.getReleaseByUUID(releaseUuid, tenantId);
|
|
|
|
throw new NotFoundException("Couldn't find an application for application ID: " + applicationId);
|
|
|
|
if (applicationReleaseDTO == null) {
|
|
|
|
|
|
|
|
String msg = "Couldn't find an application release for application release UUID: " + releaseUuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION) && !application
|
|
|
|
|
|
|
|
.getUnrestrictedRoles().isEmpty() && hasUserRole(application.getUnrestrictedRoles(), userName)) {
|
|
|
|
if (!applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getInitialState())) {
|
|
|
|
throw new ForbiddenException(
|
|
|
|
String msg = "Application state is not in the initial state: " + lifecycleStateManager.getInitialState()
|
|
|
|
"You don't have permission for deleting application release. ApplicationDTO id: " + applicationId
|
|
|
|
+ ". Therefore you are not permitted to delete the application release.";
|
|
|
|
+ " and release UUID: " + releaseUuid);
|
|
|
|
log.error(msg);
|
|
|
|
}
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
ApplicationReleaseDTO applicationRelease = this.applicationReleaseDAO
|
|
|
|
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
|
|
|
|
.getReleaseByIds(applicationId, releaseUuid, tenantId);
|
|
|
|
.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId);
|
|
|
|
if (applicationRelease == null) {
|
|
|
|
for (DeviceSubscriptionDTO deviceSubscriptionDTO : deviceSubscriptionDTOS) {
|
|
|
|
throw new NotFoundException("Couldn't find an application release for application ID: " + applicationId
|
|
|
|
if (!deviceSubscriptionDTO.isUnsubscribed()) {
|
|
|
|
+ " and release UUID: " + releaseUuid);
|
|
|
|
String msg = "This application is subscribed to device/s. Therefore you are not permitted to delete "
|
|
|
|
}
|
|
|
|
+ "the application release.";
|
|
|
|
LifecycleStateDTO appLifecycleState = this.lifecycleStateDAO
|
|
|
|
log.error(msg);
|
|
|
|
.getLatestLifeCycleState(applicationId, releaseUuid);
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
if (appLifecycleState == null) {
|
|
|
|
|
|
|
|
throw new NotFoundException(
|
|
|
|
|
|
|
|
"Couldn't find an lifecycle sate for application ID: " + applicationId + " and UUID: "
|
|
|
|
|
|
|
|
+ releaseUuid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String currentState = appLifecycleState.getCurrentState();
|
|
|
|
|
|
|
|
if (AppLifecycleState.DEPRECATED.toString().equals(currentState) || AppLifecycleState.REJECTED.toString()
|
|
|
|
|
|
|
|
.equals(currentState) || AppLifecycleState.UNPUBLISHED.toString().equals(currentState)) {
|
|
|
|
|
|
|
|
LifecycleStateDTO newAppLifecycleState = getLifecycleStateInstance(AppLifecycleState.REMOVED.toString(),
|
|
|
|
|
|
|
|
appLifecycleState.getCurrentState());
|
|
|
|
|
|
|
|
if (lifecycleStateManager.isValidStateChange(newAppLifecycleState.getPreviousState(),
|
|
|
|
|
|
|
|
newAppLifecycleState.getCurrentState(), userName, tenantId)) {
|
|
|
|
|
|
|
|
this.lifecycleStateDAO
|
|
|
|
|
|
|
|
.addLifecycleState(newAppLifecycleState, applicationId, applicationRelease.getUuid(),
|
|
|
|
|
|
|
|
tenantId);
|
|
|
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
List<String> lifecycleFlow = searchLifecycleStateFlow(currentState,
|
|
|
|
|
|
|
|
AppLifecycleState.REMOVED.toString());
|
|
|
|
|
|
|
|
for (String nextState : lifecycleFlow) {
|
|
|
|
|
|
|
|
LifecycleStateDTO lifecycleState = getLifecycleStateInstance(nextState, currentState);
|
|
|
|
|
|
|
|
if (lifecycleStateManager.isValidStateChange(currentState, nextState, userName, tenantId)) {
|
|
|
|
|
|
|
|
this.lifecycleStateDAO
|
|
|
|
|
|
|
|
.addLifecycleState(lifecycleState, applicationId, applicationRelease.getUuid(),
|
|
|
|
|
|
|
|
tenantId);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
|
|
|
|
"Can't delete the application release, You have to move the "
|
|
|
|
|
|
|
|
+ "lifecycle state from " + currentState + " to " + nextState);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
currentState = nextState;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
|
|
|
|
"Can't delete the application release, You have to move the " + "lifecycle state from "
|
|
|
|
|
|
|
|
+ currentState + " to acceptable " + "state");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return applicationRelease.getAppHashValue();
|
|
|
|
//todo delete application release data ON delete cascade
|
|
|
|
|
|
|
|
applicationStorageManager.deleteApplicationReleaseArtifacts(applicationReleaseDTO.getAppHashValue());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// LifecycleStateDTO appLifecycleState = this.lifecycleStateDAO
|
|
|
|
|
|
|
|
// .getLatestLifeCycleState(applicationId, releaseUuid);
|
|
|
|
|
|
|
|
// if (appLifecycleState == null) {
|
|
|
|
|
|
|
|
// throw new NotFoundException(
|
|
|
|
|
|
|
|
// "Couldn't find an lifecycle sate for application ID: " + applicationId + " and UUID: "
|
|
|
|
|
|
|
|
// + releaseUuid);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// String currentState = appLifecycleState.getCurrentState();
|
|
|
|
|
|
|
|
// if (AppLifecycleState.DEPRECATED.toString().equals(currentState) || AppLifecycleState.REJECTED.toString()
|
|
|
|
|
|
|
|
// .equals(currentState) || AppLifecycleState.UNPUBLISHED.toString().equals(currentState)) {
|
|
|
|
|
|
|
|
// LifecycleStateDTO newAppLifecycleState = getLifecycleStateInstance(AppLifecycleState.REMOVED.toString(),
|
|
|
|
|
|
|
|
// appLifecycleState.getCurrentState());
|
|
|
|
|
|
|
|
// if (lifecycleStateManager.isValidStateChange(newAppLifecycleState.getPreviousState(),
|
|
|
|
|
|
|
|
// newAppLifecycleState.getCurrentState(), userName, tenantId)) {
|
|
|
|
|
|
|
|
// this.lifecycleStateDAO
|
|
|
|
|
|
|
|
// .addLifecycleState(newAppLifecycleState, applicationId, applicationRelease.getUuid(),
|
|
|
|
|
|
|
|
// tenantId);
|
|
|
|
|
|
|
|
// ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// List<String> lifecycleFlow = searchLifecycleStateFlow(currentState,
|
|
|
|
|
|
|
|
// AppLifecycleState.REMOVED.toString());
|
|
|
|
|
|
|
|
// for (String nextState : lifecycleFlow) {
|
|
|
|
|
|
|
|
// LifecycleStateDTO lifecycleState = getLifecycleStateInstance(nextState, currentState);
|
|
|
|
|
|
|
|
// if (lifecycleStateManager.isValidStateChange(currentState, nextState, userName, tenantId)) {
|
|
|
|
|
|
|
|
// this.lifecycleStateDAO
|
|
|
|
|
|
|
|
// .addLifecycleState(lifecycleState, applicationId, applicationRelease.getUuid(),
|
|
|
|
|
|
|
|
// tenantId);
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
// throw new ApplicationManagementException(
|
|
|
|
|
|
|
|
// "Can't delete the application release, You have to move the "
|
|
|
|
|
|
|
|
// + "lifecycle state from " + currentState + " to " + nextState);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// currentState = nextState;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// throw new ApplicationManagementException(
|
|
|
|
|
|
|
|
// "Can't delete the application release, You have to move the " + "lifecycle state from "
|
|
|
|
|
|
|
|
// + currentState + " to acceptable " + "state");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return applicationReleaseDTO.getAppHashValue();
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
throw new ApplicationManagementDAOException(
|
|
|
|
String msg = "Error ocured when getting application data or application release data for application id of "
|
|
|
|
"Error ocured when getting application data or application release data for application id of "
|
|
|
|
+ applicationId + " application release UUID of the " + releaseUuid;
|
|
|
|
+ applicationId + " application release UUID of the " + releaseUuid);
|
|
|
|
throw new ApplicationManagementDAOException(msg, e);
|
|
|
|
} catch (LifeCycleManagementDAOException e) {
|
|
|
|
} catch (ApplicationStorageManagementException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
String msg = "Error occured when deleteing the application release artifact from the file system. Application release UUID: " + releaseUuid;
|
|
|
|
"Error occured when deleting application release for application ID of " + applicationId
|
|
|
|
log.error(msg);
|
|
|
|
+ " and application release UUID of " + releaseUuid, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
|
|
|
|
"Error occured when checking permission for executing application release update. ApplicationDTO ID: "
|
|
|
|
|
|
|
|
+ applicationId + " and ApplicationDTO UUID: " + releaseUuid);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|