|
|
@ -737,8 +737,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("ApplicationDTO release request is received for the application id: " + applicationId);
|
|
|
|
log.debug("ApplicationDTO release request is received for the application id: " + applicationId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO = getApplication(applicationId);
|
|
|
|
ApplicationDTO applicationDTO = getApplication(applicationId);
|
|
|
|
|
|
|
|
try {
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = uploadReleaseArtifacts(applicationReleaseWrapper,
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = uploadReleaseArtifacts(applicationReleaseWrapper,
|
|
|
|
applicationDTO, applicationArtifact);
|
|
|
|
applicationDTO, applicationArtifact);
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
@ -819,11 +820,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
public Application getApplicationById(int appId, String state) throws ApplicationManagementException {
|
|
|
|
public Application getApplicationById(int appId, String state) throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
ApplicationDTO applicationDTO;
|
|
|
|
|
|
|
|
boolean isVisibleApp = false;
|
|
|
|
boolean isVisibleApp = false;
|
|
|
|
try {
|
|
|
|
ApplicationDTO applicationDTO = getApplication(appId);
|
|
|
|
applicationDTO = getApplication(appId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
List<ApplicationReleaseDTO> filteredApplicationReleaseDTOs = new ArrayList<>();
|
|
|
|
List<ApplicationReleaseDTO> filteredApplicationReleaseDTOs = new ArrayList<>();
|
|
|
|
for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) {
|
|
|
|
for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) {
|
|
|
@ -1162,39 +1162,49 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteApplication(int applicationId) throws ApplicationManagementException {
|
|
|
|
public void deleteApplication(int applicationId) throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager();
|
|
|
|
|
|
|
|
List<String> storedLocations = new ArrayList<>();
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager();
|
|
|
|
applicationDTO = this.applicationDAO.getApplicationById(applicationId, tenantId);
|
|
|
|
ApplicationDTO applicationDTO = getApplication(applicationId);
|
|
|
|
|
|
|
|
|
|
|
|
if (applicationDTO == null) {
|
|
|
|
|
|
|
|
throw new NotFoundException("Couldn't found an application for Application ID: " + applicationId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<ApplicationReleaseDTO> applicationReleaseDTOs = applicationDTO.getApplicationReleaseDTOs();
|
|
|
|
List<ApplicationReleaseDTO> applicationReleaseDTOs = applicationDTO.getApplicationReleaseDTOs();
|
|
|
|
List<ApplicationReleaseDTO> activeApplicationReleaseDTOs = new ArrayList<>();
|
|
|
|
|
|
|
|
for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) {
|
|
|
|
for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) {
|
|
|
|
if (!applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getEndState())){
|
|
|
|
if (!lifecycleStateManager.isDeletableState(applicationReleaseDTO.getCurrentState())){
|
|
|
|
activeApplicationReleaseDTOs.add(applicationReleaseDTO);
|
|
|
|
String msg = "Application release which has application release UUID: " +
|
|
|
|
|
|
|
|
applicationReleaseDTO.getUuid() + " is not in a deletable state. Therefore Application "
|
|
|
|
|
|
|
|
+ "deletion is not permitted. In order to delete the application, all application releases "
|
|
|
|
|
|
|
|
+ "of the application has to be in a deletable state.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
storedLocations.add(applicationReleaseDTO.getAppHashValue());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!activeApplicationReleaseDTOs.isEmpty()) {
|
|
|
|
|
|
|
|
String msg = "There are application releases which are not in the state " + lifecycleStateManager
|
|
|
|
try {
|
|
|
|
.getEndState() + ". Hence you are not allowed to delete the application";
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
|
|
|
List<Integer> deletingAppReleaseIds = new ArrayList<>();
|
|
|
|
|
|
|
|
for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) {
|
|
|
|
|
|
|
|
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);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.applicationDAO.retireApplication(applicationId);
|
|
|
|
applicationStorageManager.deleteApplicationReleaseArtifacts(applicationReleaseDTO.getAppHashValue());
|
|
|
|
|
|
|
|
deletingAppReleaseIds.add(applicationReleaseDTO.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.lifecycleStateDAO.deleteLifecycleStates(deletingAppReleaseIds);
|
|
|
|
|
|
|
|
this.applicationReleaseDAO.deleteReleases(deletingAppReleaseIds);
|
|
|
|
|
|
|
|
this.applicationDAO.deleteTagMapping(applicationId, tenantId);
|
|
|
|
|
|
|
|
this.applicationDAO.deleteCategoryMapping(applicationId, tenantId);
|
|
|
|
|
|
|
|
this.applicationDAO.deleteApplication(applicationId, tenantId);
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
applicationStorageManager.deleteAllApplicationReleaseArtifacts(storedLocations);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
String msg = "Error occurred when getting application data for application id: " + applicationId;
|
|
|
|
String msg = "Error occurred when getting application data for application id: " + applicationId;
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
@ -1203,6 +1213,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
+ applicationId;
|
|
|
|
+ applicationId;
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
|
|
|
|
} catch (LifeCycleManagementDAOException e) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
String msg = "Error occured while deleting life-cycle state data of application releases of the application"
|
|
|
|
|
|
|
|
+ " which has application ID: " + applicationId;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1210,19 +1226,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void retireApplication(int applicationId) throws ApplicationManagementException {
|
|
|
|
public void retireApplication(int applicationId) throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO = getApplication(applicationId);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
applicationDTO = this.applicationDAO.getApplicationById(applicationId, tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (applicationDTO == null) {
|
|
|
|
|
|
|
|
throw new NotFoundException("Couldn't found an application for Application ID: " + applicationId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<ApplicationReleaseDTO> applicationReleaseDTOs = applicationDTO.getApplicationReleaseDTOs();
|
|
|
|
List<ApplicationReleaseDTO> applicationReleaseDTOs = applicationDTO.getApplicationReleaseDTOs();
|
|
|
|
List<ApplicationReleaseDTO> activeApplicationReleaseDTOs = new ArrayList<>();
|
|
|
|
List<ApplicationReleaseDTO> activeApplicationReleaseDTOs = new ArrayList<>();
|
|
|
|
for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) {
|
|
|
|
for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) {
|
|
|
@ -1655,19 +1665,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
ApplicationDTO applicationDTO;
|
|
|
|
ApplicationDTO applicationDTO = getApplication(applicationId);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
applicationDTO = this.applicationDAO.getApplicationById(applicationId, tenantId);
|
|
|
|
|
|
|
|
if (applicationDTO == null) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
String msg = "Tried to update Application which is not in the publisher. Please verify "
|
|
|
|
|
|
|
|
+ "application details";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(applicationUpdateWrapper.getName())){
|
|
|
|
if (!StringUtils.isEmpty(applicationUpdateWrapper.getName())){
|
|
|
|
Filter filter = new Filter();
|
|
|
|
Filter filter = new Filter();
|
|
|
|
filter.setFullMatch(true);
|
|
|
|
filter.setFullMatch(true);
|
|
|
|