Modify app release deleting functionality

4.x.x
tcdlpds@gmail.com 4 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,31 +1443,38 @@ 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);
} }
List<ApplicationReleaseDTO> applicationReleaseDTOS = applicationDTO.getApplicationReleaseDTOs();
if (applicationReleaseDTOS.size() == 1) {
isDeletingApp.set(true);
}
for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOS) {
if (releaseUuid.equals(applicationReleaseDTO.getUuid())) {
if (!lifecycleStateManager.isDeletableState(applicationReleaseDTO.getCurrentState())) { if (!lifecycleStateManager.isDeletableState(applicationReleaseDTO.getCurrentState())) {
String msg = "Application state is not in the deletable state. Therefore you are not permitted to " String msg =
"Application state is not in the deletable state. Therefore you are not permitted to "
+ "delete the application release."; + "delete the application release.";
log.error(msg); log.error(msg);
throw new ForbiddenException(msg); throw new ForbiddenException(msg);
} }
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId); .getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId);
if (!deviceSubscriptionDTOS.isEmpty()){ if (!deviceSubscriptionDTOS.isEmpty()) {
String msg = "Application release which has UUID: " + applicationReleaseDTO.getUuid() + 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 " + " either subscribed to device/s or it had subscribed to device/s. Therefore you are not "
+ "permitted to delete the application release."; + "permitted to delete the application release.";
log.error(msg); log.error(msg);
throw new ForbiddenException(msg); throw new ForbiddenException(msg);
@ -1475,6 +1483,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
Collections.singletonList(applicationReleaseDTO.getAppHashValue()), tenantId); Collections.singletonList(applicationReleaseDTO.getAppHashValue()), tenantId);
lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId()); lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId());
applicationReleaseDAO.deleteRelease(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);
}
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