Fix issues in lifecycle adding method

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent a3d75df8a0
commit 6d4252a5dd

@ -181,7 +181,7 @@ public interface ApplicationReleaseDAO {
boolean isActiveReleaseExisitForPackageName(String packageName, int tenantId, String inactiveState) boolean isActiveReleaseExisitForPackageName(String packageName, int tenantId, String inactiveState)
throws ApplicationManagementDAOException; throws ApplicationManagementDAOException;
boolean hasExisitInstallableAppRelease(String releaseUuid, String installableStateName, int tenantId) boolean hasExistInstallableAppRelease(String releaseUuid, String installableStateName, int tenantId)
throws ApplicationManagementDAOException; throws ApplicationManagementDAOException;
} }

@ -753,7 +753,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} }
@Override @Override
public boolean hasExisitInstallableAppRelease(String releaseUuid, String installableStateName, int tenantId) public boolean hasExistInstallableAppRelease(String releaseUuid, String installableStateName, int tenantId)
throws ApplicationManagementDAOException{ throws ApplicationManagementDAOException{
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Verifying application release existence in the installable state: :" + installableStateName); log.debug("Verifying application release existence in the installable state: :" + installableStateName);

@ -1598,7 +1598,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(releaseUuid, tenantId); ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO
.getReleaseByUUID(releaseUuid, tenantId);
if (applicationReleaseDTO == null) { if (applicationReleaseDTO == null) {
String msg = "Couldn't found an application release for the UUID: " + releaseUuid; String msg = "Couldn't found an application release for the UUID: " + releaseUuid;
@ -1606,57 +1607,41 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }
if (lifecycleStateManager.isValidStateChange(applicationReleaseDTO.getCurrentState(), stateName, userName, tenantId)){ if (lifecycleStateManager
.isValidStateChange(applicationReleaseDTO.getCurrentState(), stateName, userName, tenantId)) {
if (lifecycleStateManager.isInstallableState(stateName) && applicationReleaseDAO
.hasExistInstallableAppRelease(applicationReleaseDTO.getUuid(),
lifecycleStateManager.getInstallableState(), tenantId)) {
String msg = "Installable application release is already registered for the application. "
+ "Therefore it is not permitted to change the lifecycle state from "
+ applicationReleaseDTO.getCurrentState() + " to " + stateName;
log.error(msg);
throw new ForbiddenException(msg);
}
LifecycleState lifecycleState = new LifecycleState(); LifecycleState lifecycleState = new LifecycleState();
lifecycleState.setCurrentState(stateName); lifecycleState.setCurrentState(stateName);
lifecycleState.setPreviousState(applicationReleaseDTO.getCurrentState()); lifecycleState.setPreviousState(applicationReleaseDTO.getCurrentState());
lifecycleState.setUpdatedBy(userName); lifecycleState.setUpdatedBy(userName);
applicationReleaseDTO.setCurrentState(stateName);
this.applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId);
this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
}
if (!this.applicationDAO.verifyApplicationExistenceById(applicationId, tenantId)) {
throw new NotFoundException("Couldn't find application for the application Id: " + applicationId);
}
if (!this.applicationReleaseDAO.verifyReleaseExistence(applicationId, releaseUuid, tenantId)) {
throw new NotFoundException("Couldn't find application release for the application Id: " + applicationId
+ " application release uuid: " + releaseUuid);
}
LifecycleState currentState = this.lifecycleStateDAO.getLatestLifeCycleState(applicationId, releaseUuid);
if (currentState == null) {
throw new ApplicationManagementException(
"Couldn't find latest lifecycle state for the appId: " + applicationId
+ " and application release UUID: " + releaseUuid);
}
stateName.setPreviousState(currentState.getCurrentState());
if (stateName.getCurrentState() != null && stateName.getPreviousState() != null) {
if (lifecycleStateManager.isValidStateChange(stateName.getPreviousState(), stateName.getCurrentState(),
userName, 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(stateName, applicationId, releaseUuid, tenantId);
ConnectionManagerUtil.commitDBTransaction();
} else { } else {
ConnectionManagerUtil.rollbackDBTransaction(); String msg = "Invalid lifecycle state transition from '" + applicationReleaseDTO.getCurrentState() + "'"
log.error("Invalid lifecycle state transition from '" + stateName.getPreviousState() + "'" + " to '" + " to '" + stateName + "'";
+ stateName.getCurrentState() + "'"); log.error(msg);
throw new ApplicationManagementException( throw new ApplicationManagementException(msg);
"Lifecycle State Validation failed. ApplicationDTO Id: " + applicationId
+ " ApplicationDTO release UUID: " + releaseUuid);
}
} }
} catch (LifeCycleManagementDAOException e) { } catch (LifeCycleManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException( String msg = "Failed to add lifecycle state for Application release UUID: " + releaseUuid;
"Failed to add lifecycle state. ApplicationDTO Id: " + applicationId + " ApplicationDTO release UUID: " log.error(msg);
+ releaseUuid, e); throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
//todo ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException(""); String msg = "Error occurred when accessing application release data of application release which has the "
+ "application release UUID: " + releaseUuid;
log.error(msg);
throw new ApplicationManagementException(msg);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }

@ -478,9 +478,6 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
} }
} }
/*
//todo ----------------------
*/
@POST @POST
@Path("/life-cycle/{uuid}") @Path("/life-cycle/{uuid}")
public Response addLifecycleState( public Response addLifecycleState(
@ -496,8 +493,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
applicationManager.changeLifecycleState( applicationUuid, action); applicationManager.changeLifecycleState( applicationUuid, action);
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Could,t find application release for application id: " + applicationId String msg = "Could,t find application release for application release uuid: " + applicationUuid;
+ " and application release uuid: " + applicationUuid;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).build(); return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {

Loading…
Cancel
Save