|
|
@ -50,7 +50,6 @@ import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
import org.wso2.carbon.user.api.UserRealm;
|
|
|
|
import org.wso2.carbon.user.api.UserRealm;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
@ -67,7 +66,6 @@ import java.util.List;
|
|
|
|
public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
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 VisibilityDAO visibilityDAO;
|
|
|
|
private VisibilityDAO visibilityDAO;
|
|
|
|
private ApplicationDAO applicationDAO;
|
|
|
|
private ApplicationDAO applicationDAO;
|
|
|
|
private ApplicationReleaseDAO applicationReleaseDAO;
|
|
|
|
private ApplicationReleaseDAO applicationReleaseDAO;
|
|
|
@ -81,7 +79,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initDataAccessObjects() {
|
|
|
|
private void initDataAccessObjects() {
|
|
|
|
this.deviceTypeDAO = ApplicationManagementDAOFactory.getDeviceTypeDAO();
|
|
|
|
|
|
|
|
this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
|
|
|
|
this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
|
|
|
|
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
|
|
|
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
|
|
|
this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
|
|
|
|
this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
|
|
|
@ -97,7 +94,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
log.debug("Create Application received for the tenant : " + tenantId + " From" + " the user : " + userName);
|
|
|
|
log.debug("Create Application received for the tenant : " + tenantId + " From" + " the user : " + userName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
validateAppCreatingRequest(application);
|
|
|
|
validateAppCreatingRequest(application);
|
|
|
|
validateAppReleasePayload(application.getApplicationReleases().get(0));
|
|
|
|
validateAppReleasePayload(application.getApplicationReleases().get(0));
|
|
|
@ -164,8 +160,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
LifecycleState lifecycleState = new LifecycleState();
|
|
|
|
LifecycleState lifecycleState = new LifecycleState();
|
|
|
|
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
|
|
|
|
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
|
|
|
|
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
|
|
|
|
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
|
|
|
|
changeLifecycleState(appId, applicationRelease.getUuid(), lifecycleState, false,
|
|
|
|
changeLifecycleState(appId, applicationRelease.getUuid(), lifecycleState, false);
|
|
|
|
applicationRelease.getId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
applicationRelease.setLifecycleState(lifecycleState);
|
|
|
|
applicationRelease.setLifecycleState(lifecycleState);
|
|
|
|
applicationReleases.add(applicationRelease);
|
|
|
|
applicationReleases.add(applicationRelease);
|
|
|
@ -249,7 +244,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
LifecycleState lifecycleState = new LifecycleState();
|
|
|
|
LifecycleState lifecycleState = new LifecycleState();
|
|
|
|
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
|
|
|
|
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
|
|
|
|
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
|
|
|
|
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
|
|
|
|
changeLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState, true, 0);
|
|
|
|
changeLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState, true);
|
|
|
|
|
|
|
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
return applicationRelease;
|
|
|
|
return applicationRelease;
|
|
|
@ -283,8 +278,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
List<ApplicationRelease> applicationReleases;
|
|
|
|
List<ApplicationRelease> applicationReleases;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
application = ApplicationManagementDAOFactory.getApplicationDAO()
|
|
|
|
application = this.applicationDAO.getApplicationById(id, tenantId);
|
|
|
|
.getApplicationById(id, tenantId);
|
|
|
|
|
|
|
|
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
|
|
|
|
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
|
|
|
|
applicationReleases = getReleases(application, requirePublishedReleases);
|
|
|
|
applicationReleases = getReleases(application, requirePublishedReleases);
|
|
|
|
application.setApplicationReleases(applicationReleases);
|
|
|
|
application.setApplicationReleases(applicationReleases);
|
|
|
@ -347,8 +341,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
List<ApplicationRelease> applicationReleases;
|
|
|
|
List<ApplicationRelease> applicationReleases;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
application = ApplicationManagementDAOFactory.getApplicationDAO()
|
|
|
|
application = this.applicationDAO.getApplication(appName, appType, tenantId);
|
|
|
|
.getApplication(appName, appType, tenantId);
|
|
|
|
|
|
|
|
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
|
|
|
|
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
|
|
|
|
applicationReleases = getReleases(application, false);
|
|
|
|
applicationReleases = getReleases(application, false);
|
|
|
|
application.setApplicationReleases(applicationReleases);
|
|
|
|
application.setApplicationReleases(applicationReleases);
|
|
|
@ -385,8 +378,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
Application application;
|
|
|
|
Application application;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
application = ApplicationManagementDAOFactory.getApplicationDAO()
|
|
|
|
application = this.applicationDAO.getApplicationByRelease(appReleaseUUID, tenantId);
|
|
|
|
.getApplicationByRelease(appReleaseUUID, tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (application.getUnrestrictedRoles().isEmpty() || isRoleExists(application.getUnrestrictedRoles(),
|
|
|
|
if (application.getUnrestrictedRoles().isEmpty() || isRoleExists(application.getUnrestrictedRoles(),
|
|
|
|
userName)) {
|
|
|
|
userName)) {
|
|
|
@ -401,11 +393,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Boolean verifyApplicationExistenceById(int appId) throws ApplicationManagementException {
|
|
|
|
public boolean verifyApplicationExistenceById(int appId) throws ApplicationManagementException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Boolean isAppExist;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
boolean isAppExist;
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
isAppExist = ApplicationManagementDAOFactory.getApplicationDAO().verifyApplicationExistenceById(appId);
|
|
|
|
isAppExist = this.applicationDAO.verifyApplicationExistenceById(appId, tenantId);
|
|
|
|
return isAppExist;
|
|
|
|
return isAppExist;
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
@ -422,35 +415,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// todo
|
|
|
|
|
|
|
|
// public List<ApplicationRelease> getinstallableReleases(int applicationId) throws ApplicationManagementException {
|
|
|
|
|
|
|
|
// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Application application = getApplicationIfAccessible(applicationId);
|
|
|
|
|
|
|
|
// List<ApplicationRelease> applicationReleases;
|
|
|
|
|
|
|
|
// List<ApplicationRelease> filteredApplicationReleases = new ArrayList<>();
|
|
|
|
|
|
|
|
// if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
// log.debug("Request is received to retrieve all the releases related with the application " + application
|
|
|
|
|
|
|
|
// .toString());
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// ConnectionManagerUtil.getDBConnection();
|
|
|
|
|
|
|
|
// applicationReleases = this.applicationReleaseDAO.getReleases(application.getName(), application.getType(), tenantId);
|
|
|
|
|
|
|
|
// for (ApplicationRelease applicationRelease : applicationReleases) {
|
|
|
|
|
|
|
|
// LifecycleState lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO().
|
|
|
|
|
|
|
|
// getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
|
|
|
|
|
|
|
|
// if (lifecycleState != null) {
|
|
|
|
|
|
|
|
// applicationRelease.setLifecycleState(lifecycleState);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (!AppLifecycleState.REMOVED.toString()
|
|
|
|
|
|
|
|
// .equals(applicationRelease.getLifecycleState().getCurrentState())) {
|
|
|
|
|
|
|
|
// filteredApplicationReleases.add(applicationRelease);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return filteredApplicationReleases;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<ApplicationRelease> getReleases(Application application, boolean requirePublishedRelease)
|
|
|
|
private List<ApplicationRelease> getReleases(Application application, boolean requirePublishedRelease)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
@ -463,8 +427,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
ConnectionManagerUtil.getDBConnection();
|
|
|
|
ConnectionManagerUtil.getDBConnection();
|
|
|
|
applicationReleases = this.applicationReleaseDAO.getReleases(application.getId(), tenantId);
|
|
|
|
applicationReleases = this.applicationReleaseDAO.getReleases(application.getId(), tenantId);
|
|
|
|
for (ApplicationRelease applicationRelease : applicationReleases) {
|
|
|
|
for (ApplicationRelease applicationRelease : applicationReleases) {
|
|
|
|
LifecycleState lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO().
|
|
|
|
LifecycleState lifecycleState = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO().
|
|
|
|
getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
|
|
|
|
getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
|
|
|
|
|
|
|
|
} catch (LifeCycleManagementDAOException e) {
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
|
|
|
|
"Error occurred while getting the latest lifecycle state for the application release UUID: "
|
|
|
|
|
|
|
|
+ applicationRelease.getUuid(), e);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (lifecycleState != null) {
|
|
|
|
if (lifecycleState != null) {
|
|
|
|
applicationRelease.setLifecycleState(lifecycleState);
|
|
|
|
applicationRelease.setLifecycleState(lifecycleState);
|
|
|
|
|
|
|
|
|
|
|
@ -520,11 +491,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
LifecycleState newAppLifecycleState = new LifecycleState();
|
|
|
|
LifecycleState newAppLifecycleState = new LifecycleState();
|
|
|
|
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
|
|
|
|
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
|
|
|
|
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
|
|
|
|
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
|
|
|
|
changeLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState, true, 0);
|
|
|
|
changeLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState, true);
|
|
|
|
storedLocations.add(applicationRelease.getAppHashValue());
|
|
|
|
storedLocations.add(applicationRelease.getAppHashValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ApplicationManagementDAOFactory.getApplicationDAO().deleteApplication(applicationId);
|
|
|
|
this.applicationDAO.deleteApplication(applicationId);
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "Error occured while check whether current user has the permission to delete an application";
|
|
|
|
String msg = "Error occured while check whether current user has the permission to delete an application";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -551,7 +522,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
LifecycleState newAppLifecycleState = new LifecycleState();
|
|
|
|
LifecycleState newAppLifecycleState = new LifecycleState();
|
|
|
|
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
|
|
|
|
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
|
|
|
|
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
|
|
|
|
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
|
|
|
|
changeLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState, true, 0);
|
|
|
|
changeLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState, true);
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
throw new ApplicationManagementException("Can't delete the application release, You have to move the " +
|
|
|
|
throw new ApplicationManagementException("Can't delete the application release, You have to move the " +
|
|
|
|
"lifecycle state from "+ currentState + " to acceptable " +
|
|
|
|
"lifecycle state from "+ currentState + " to acceptable " +
|
|
|
@ -658,8 +629,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
Application application;
|
|
|
|
Application application;
|
|
|
|
boolean isAppAllowed = false;
|
|
|
|
boolean isAppAllowed = false;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
application = ApplicationManagementDAOFactory.getApplicationDAO()
|
|
|
|
application = this.applicationDAO.getApplicationById(applicationId, tenantId);
|
|
|
|
.getApplicationById(applicationId, tenantId);
|
|
|
|
|
|
|
|
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
|
|
|
|
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
|
|
|
|
return application;
|
|
|
|
return application;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -785,24 +755,22 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public LifecycleState getLifecycleState(int applicationId, String applicationUuid) throws
|
|
|
|
public LifecycleState getLifecycleState(int applicationId, String releaseUuid) throws
|
|
|
|
ApplicationManagementException {
|
|
|
|
ApplicationManagementException {
|
|
|
|
LifecycleState lifecycleState;
|
|
|
|
LifecycleState lifecycleState;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationId);
|
|
|
|
lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleState(applicationId, releaseUuid);
|
|
|
|
if (lifecycleState == null) {
|
|
|
|
if (lifecycleState == null) {
|
|
|
|
throw new NotFoundException(
|
|
|
|
throw new NotFoundException(
|
|
|
|
"Couldn't find the lifecycle data for appid: " + applicationId + " and app release UUID: "
|
|
|
|
"Couldn't find the lifecycle data for appid: " + applicationId + " and app release UUID: "
|
|
|
|
+ applicationUuid);
|
|
|
|
+ releaseUuid);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lifecycleState.setNextStates(new ArrayList<>(lifecycleStateManger.
|
|
|
|
lifecycleState.setNextStates(new ArrayList<>(getLifecycleManagementService().
|
|
|
|
getNextLifecycleStates(lifecycleState.getCurrentState())));
|
|
|
|
getNextLifecycleStates(lifecycleState.getCurrentState())));
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (LifeCycleManagementDAOException e) {
|
|
|
|
throw new ApplicationManagementException("Failed to get lifecycle state", e);
|
|
|
|
throw new ApplicationManagementException("Failed to get lifecycle state from database", e);
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
|
|
|
|
throw new ApplicationManagementException("Failed to get application and application management", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -810,34 +778,48 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void changeLifecycleState(int applicationId, String applicationUuid, LifecycleState state, Boolean
|
|
|
|
public void changeLifecycleState(int applicationId, String releaseUuid, LifecycleState state, Boolean checkExist)
|
|
|
|
checkExist, int releaseId) throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
if (checkExist) {
|
|
|
|
if (checkExist) {
|
|
|
|
getApplicationIfAccessible(applicationId);
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
|
|
|
if (!this.applicationDAO.verifyApplicationExistenceById(applicationId, tenantId)){
|
|
|
|
|
|
|
|
throw new NotFoundException(
|
|
|
|
|
|
|
|
"Couldn't found application for the application Id: " + applicationId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (releaseId < 1) {
|
|
|
|
if (!this.applicationReleaseDAO.verifyReleaseExistence(applicationId, releaseUuid, tenantId)){
|
|
|
|
releaseId = getAppReleaseIfExists(applicationId, applicationUuid).getId();
|
|
|
|
throw new NotFoundException(
|
|
|
|
|
|
|
|
"Couldn't found application release for the application Id: " + applicationId
|
|
|
|
|
|
|
|
+ " application release uuid: " + releaseUuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
state.setUpdatedBy(userName);
|
|
|
|
state.setUpdatedBy(userName);
|
|
|
|
|
|
|
|
|
|
|
|
if (state.getCurrentState() != null && state.getPreviousState() != null) {
|
|
|
|
if (state.getCurrentState() != null && state.getPreviousState() != null) {
|
|
|
|
|
|
|
|
if (getLifecycleManagementService()
|
|
|
|
if (getLifecycleManagementService().isValidStateChange(state.getPreviousState(), state.getCurrentState())) {
|
|
|
|
.isValidStateChange(state.getPreviousState(), state.getCurrentState())) {
|
|
|
|
this.lifecycleStateDAO
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
.addLifecycleState(state, applicationId, releaseId, tenantId);
|
|
|
|
//todo if current state of the adding lifecycle state is PUBLISHED, need to check whether is there
|
|
|
|
|
|
|
|
//todo any other application release in PUBLISHED state for the application( i.e for the appid)
|
|
|
|
|
|
|
|
this.lifecycleStateDAO.addLifecycleState(state, applicationId, releaseUuid, tenantId);
|
|
|
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
log.error("Invalid lifecycle state transition from '" + state.getPreviousState() + "'"
|
|
|
|
log.error("Invalid lifecycle state transition from '" + state.getPreviousState() + "'" + " to '"
|
|
|
|
+ " to '" + state.getCurrentState() + "'");
|
|
|
|
+ state.getCurrentState() + "'");
|
|
|
|
throw new ApplicationManagementException("Lifecycle State Validation failed");
|
|
|
|
throw new ApplicationManagementException("Lifecycle State Validation failed. Application Id: " +
|
|
|
|
|
|
|
|
applicationId + " Application release UUID: " + releaseUuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (LifeCycleManagementDAOException | DBConnectionException e) {
|
|
|
|
} catch (LifeCycleManagementDAOException e) {
|
|
|
|
throw new ApplicationManagementException("Failed to add lifecycle state", e);
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
throw new ApplicationManagementException("Lifecycle State Validation failed", e);
|
|
|
|
"Failed to add lifecycle state. Application Id: " + applicationId + " Application release UUID: "
|
|
|
|
|
|
|
|
+ releaseUuid, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|