Modify app release deleting functionality

reporting
tcdlpds@gmail.com 5 years ago
parent 521e4f3098
commit f03c3a0517

@ -101,6 +101,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -1442,39 +1443,54 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public void deleteApplicationRelease(String releaseUuid) public void deleteApplicationRelease(String releaseUuid) throws ApplicationManagementException {
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
AtomicBoolean isDeletingApp = new AtomicBoolean(false);
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO ApplicationDTO applicationDTO = this.applicationDAO.getApplication(releaseUuid, tenantId);
.getReleaseByUUID(releaseUuid, tenantId); if (applicationDTO == null) {
if (applicationReleaseDTO == null) { String msg = "Couldn't find an application which has application release UUID: " + releaseUuid;
String msg = "Couldn't find an application release for application release UUID: " + releaseUuid;
log.error(msg); log.error(msg);
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }
if (!lifecycleStateManager.isDeletableState(applicationReleaseDTO.getCurrentState())) { List<ApplicationReleaseDTO> applicationReleaseDTOS = applicationDTO.getApplicationReleaseDTOs();
String msg = "Application state is not in the deletable state. Therefore you are not permitted to " if (applicationReleaseDTOS.size() == 1) {
+ "delete the application release."; isDeletingApp.set(true);
log.error(msg);
throw new ForbiddenException(msg);
} }
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId); for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOS) {
if (!deviceSubscriptionDTOS.isEmpty()){ if (releaseUuid.equals(applicationReleaseDTO.getUuid())) {
String msg = "Application release which has UUID: " + applicationReleaseDTO.getUuid() + if (!lifecycleStateManager.isDeletableState(applicationReleaseDTO.getCurrentState())) {
" either subscribed to device/s or it had subscribed to device/s. Therefore you are not " String msg =
+ "permitted to delete the application release."; "Application state is not in the deletable state. Therefore you are not permitted to "
log.error(msg); + "delete the application release.";
throw new ForbiddenException(msg); log.error(msg);
throw new ForbiddenException(msg);
}
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId);
if (!deviceSubscriptionDTOS.isEmpty()) {
String msg = "Application release which has UUID: " + applicationReleaseDTO.getUuid()
+ " either subscribed to device/s or it had subscribed to device/s. Therefore you are not "
+ "permitted to delete the application release.";
log.error(msg);
throw new ForbiddenException(msg);
}
applicationStorageManager.deleteAllApplicationReleaseArtifacts(
Collections.singletonList(applicationReleaseDTO.getAppHashValue()), tenantId);
lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId());
applicationReleaseDAO.deleteRelease(applicationReleaseDTO.getId());
break;
}
}
if (isDeletingApp.get()) {
this.applicationDAO.deleteApplicationTags(applicationDTO.getId(), tenantId);
this.applicationDAO.deleteAppCategories(applicationDTO.getId(), tenantId);
this.applicationDAO.deleteApplication(applicationDTO.getId(), tenantId);
} }
applicationStorageManager.deleteAllApplicationReleaseArtifacts(
Collections.singletonList(applicationReleaseDTO.getAppHashValue()), tenantId);
lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId());
applicationReleaseDAO.deleteRelease(applicationReleaseDTO.getId());
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = "Error occurred while observing the database connection to delete application release which " String msg = "Error occurred while observing the database connection to delete application release which "

Loading…
Cancel
Save