|
|
@ -940,18 +940,23 @@ ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
log.debug("Creating a new release. App Id:" + appId);
|
|
|
|
log.debug("Creating a new release. App Id:" + appId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String lifeCycleState;
|
|
|
|
String lifeCycleState = lifecycleStateManager.getInitialState();
|
|
|
|
if(isPublished){
|
|
|
|
String[] publishStates= {"IN-REVIEW", "APPROVED", "PUBLISHED"};
|
|
|
|
lifeCycleState = lifecycleStateManager.getInstallableState();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
lifeCycleState = lifecycleStateManager.getInitialState();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
applicationReleaseDTO.setCurrentState(lifeCycleState);
|
|
|
|
applicationReleaseDTO.setCurrentState(lifeCycleState);
|
|
|
|
applicationReleaseDTO = this.applicationReleaseDAO
|
|
|
|
applicationReleaseDTO = this.applicationReleaseDAO.createRelease(applicationReleaseDTO, appId, tenantId);
|
|
|
|
.createRelease(applicationReleaseDTO, appId, tenantId);
|
|
|
|
|
|
|
|
LifecycleState lifecycleState = getLifecycleStateInstance(lifeCycleState, lifeCycleState);
|
|
|
|
LifecycleState lifecycleState = getLifecycleStateInstance(lifeCycleState, lifeCycleState);
|
|
|
|
this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
|
|
|
|
this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(isPublished){
|
|
|
|
|
|
|
|
for (String state: publishStates) {
|
|
|
|
|
|
|
|
LifecycleChanger lifecycleChanger = new LifecycleChanger();
|
|
|
|
|
|
|
|
lifecycleChanger.setAction(state);
|
|
|
|
|
|
|
|
lifecycleChanger.setReason("Updated to " + state);
|
|
|
|
|
|
|
|
this.changeLifecycleState(applicationReleaseDTO, lifecycleChanger);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
applicationReleaseEntities.add(applicationReleaseDTO);
|
|
|
|
applicationReleaseEntities.add(applicationReleaseDTO);
|
|
|
|
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
|
|
|
|
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
|
|
|
|
Application application = APIUtil.appDtoToAppResponse(applicationDTO);
|
|
|
|
Application application = APIUtil.appDtoToAppResponse(applicationDTO);
|
|
|
@ -1011,7 +1016,7 @@ ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ApplicationRelease createEntAppRelease(int applicationId, EntAppReleaseWrapper entAppReleaseWrapper,
|
|
|
|
public ApplicationRelease createEntAppRelease(int applicationId, EntAppReleaseWrapper entAppReleaseWrapper,
|
|
|
|
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
|
|
|
|
ApplicationArtifact applicationArtifact, boolean isPublished) throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Application release creating request is received for the application id: " + applicationId);
|
|
|
|
log.debug("Application release creating request is received for the application id: " + applicationId);
|
|
|
@ -1037,15 +1042,28 @@ ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts(
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts(
|
|
|
|
APIUtil.releaseWrapperToReleaseDTO(entAppReleaseWrapper), applicationArtifact, deviceType.getName(),
|
|
|
|
APIUtil.releaseWrapperToReleaseDTO(entAppReleaseWrapper), applicationArtifact, deviceType.getName(),
|
|
|
|
tenantId, true);
|
|
|
|
tenantId, true);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
String initialstate = lifecycleStateManager.getInitialState();
|
|
|
|
String lifeCycleState = lifecycleStateManager.getInitialState();
|
|
|
|
applicationReleaseDTO.setCurrentState(initialstate);
|
|
|
|
String[] publishStates= {"IN-REVIEW", "APPROVED", "PUBLISHED"};
|
|
|
|
LifecycleState lifecycleState = getLifecycleStateInstance(initialstate, initialstate);
|
|
|
|
|
|
|
|
|
|
|
|
applicationReleaseDTO.setCurrentState(lifeCycleState);
|
|
|
|
|
|
|
|
LifecycleState lifecycleState = getLifecycleStateInstance(lifeCycleState, lifeCycleState);
|
|
|
|
applicationReleaseDTO = this.applicationReleaseDAO
|
|
|
|
applicationReleaseDTO = this.applicationReleaseDAO
|
|
|
|
.createRelease(applicationReleaseDTO, applicationDTO.getId(), tenantId);
|
|
|
|
.createRelease(applicationReleaseDTO, applicationDTO.getId(), tenantId);
|
|
|
|
this.lifecycleStateDAO
|
|
|
|
this.lifecycleStateDAO
|
|
|
|
.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
|
|
|
|
.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(isPublished){
|
|
|
|
|
|
|
|
for (String state: publishStates) {
|
|
|
|
|
|
|
|
LifecycleChanger lifecycleChanger = new LifecycleChanger();
|
|
|
|
|
|
|
|
lifecycleChanger.setAction(state);
|
|
|
|
|
|
|
|
lifecycleChanger.setReason("Updated to " + state);
|
|
|
|
|
|
|
|
this.changeLifecycleState(applicationReleaseDTO, lifecycleChanger);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationRelease applicationRelease = APIUtil.releaseDtoToRelease(applicationReleaseDTO);
|
|
|
|
ApplicationRelease applicationRelease = APIUtil.releaseDtoToRelease(applicationReleaseDTO);
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
return applicationRelease;
|
|
|
|
return applicationRelease;
|
|
|
@ -1890,6 +1908,61 @@ ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ApplicationRelease changeLifecycleState(ApplicationReleaseDTO applicationReleaseDTO, LifecycleChanger lifecycleChanger) throws ApplicationManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
|
|
|
if (lifecycleChanger == null || StringUtils.isEmpty(lifecycleChanger.getAction())) {
|
|
|
|
|
|
|
|
String msg = "The Action is null or empty. Please verify the request.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
if (lifecycleStateManager
|
|
|
|
|
|
|
|
.isValidStateChange(applicationReleaseDTO.getCurrentState(), lifecycleChanger.getAction(), userName,
|
|
|
|
|
|
|
|
tenantId)) {
|
|
|
|
|
|
|
|
if (lifecycleStateManager.isInstallableState(lifecycleChanger.getAction()) && 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 " + lifecycleChanger.getAction();
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
LifecycleState lifecycleState = new LifecycleState();
|
|
|
|
|
|
|
|
lifecycleState.setCurrentState(lifecycleChanger.getAction());
|
|
|
|
|
|
|
|
lifecycleState.setPreviousState(applicationReleaseDTO.getCurrentState());
|
|
|
|
|
|
|
|
lifecycleState.setUpdatedBy(userName);
|
|
|
|
|
|
|
|
lifecycleState.setReasonForChange(lifecycleChanger.getReason());
|
|
|
|
|
|
|
|
applicationReleaseDTO.setCurrentState(lifecycleChanger.getAction());
|
|
|
|
|
|
|
|
if (this.applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId) == null) {
|
|
|
|
|
|
|
|
String msg = "Application release updating is failed/.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
|
|
|
|
|
|
|
|
return APIUtil.releaseDtoToRelease(applicationReleaseDTO);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String msg = "Invalid lifecycle state transition from '" + applicationReleaseDTO.getCurrentState() + "'"
|
|
|
|
|
|
|
|
+ " to '" + lifecycleChanger.getAction() + "'";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred when accessing application release data of application release which has the "
|
|
|
|
|
|
|
|
+ "application release UUID: " + applicationReleaseDTO.getUuid();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (LifeCycleManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Failed to add lifecycle state for Application release UUID: " + applicationReleaseDTO.getUuid();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void addApplicationCategories(List<String> categories) throws ApplicationManagementException {
|
|
|
|
public void addApplicationCategories(List<String> categories) throws ApplicationManagementException {
|
|
|
|