Adding application release creating logic

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent 3e2f757c1e
commit 4c5cdc75fe

@ -153,20 +153,20 @@ public interface ApplicationManager {
void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws ApplicationManagementException;
/**
* To validate the application existence for given application id
* Get the application if application is an accessible one.
*
* @param applicationId ID of the Application.
* @throws ApplicationManagementException Application Management Exception.
*/
Application validateApplication(int applicationId) throws ApplicationManagementException;
Application getApplicationIfAccessible(int applicationId) throws ApplicationManagementException;
/**
* To validate the application release existence for given application release UUID
* Get the application release for given UUID if application release is exists and application id is valid one.
*
* @param releaseUuid UUID of the Application Release.
* @throws ApplicationManagementException Application Management Exception.
*/
ApplicationRelease validateApplicationRelease(int applicationId, String releaseUuid) throws
ApplicationRelease getAppReleaseIfExists(int applicationId, String releaseUuid) throws
ApplicationManagementException;
/**

@ -70,6 +70,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
private DeviceTypeDAO deviceTypeDAO;
private VisibilityDAO visibilityDAO;
private ApplicationDAO applicationDAO;
private LifecycleStateDAO lifecycleStateDAO;
public ApplicationManagerImpl() {
initDataAccessObjects();
@ -79,6 +81,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
this.deviceTypeDAO = ApplicationManagementDAOFactory.getDeviceTypeDAO();
this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
this.lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();;
}
@Override
@ -134,9 +137,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
lifecycleState.setUpdatedBy(userName);
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
lifecycleState.setUpdatedBy(userName);
addLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState);
LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
lifecycleStateDAO.addLifecycleState(lifecycleState, application.getId(), applicationRelease.getId(), tenantId);
this.lifecycleStateDAO
.addLifecycleState(lifecycleState, application.getId(), applicationRelease.getId(), tenantId);
applicationRelease.setLifecycleState(lifecycleState);
applicationReleases.add(applicationRelease);
@ -209,21 +213,36 @@ public class ApplicationManagerImpl implements ApplicationManager {
public ApplicationRelease createRelease(int applicationId, ApplicationRelease applicationRelease) throws
ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Application application = validateApplication(applicationId);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
Application application = getApplicationIfAccessible(applicationId);
validateReleaseCreatingRequest(applicationRelease);
if (log.isDebugEnabled()) {
log.debug("Application release request is received for the application " + application.toString());
}
try {
ConnectionManagerUtil.beginDBTransaction();
// todo consider about lifecycle adding
applicationRelease = ApplicationManagementDAOFactory.getApplicationReleaseDAO().
createRelease(applicationRelease, application.getId(), tenantId);
LifecycleState lifecycleState = new LifecycleState();
lifecycleState.setUpdatedBy(userName);
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
lifecycleState.setUpdatedBy(userName);
addLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState);
this.lifecycleStateDAO
.addLifecycleState(lifecycleState, application.getId(), applicationRelease.getId(), tenantId);
ConnectionManagerUtil.commitDBTransaction();
return applicationRelease;
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw e;
throw new ApplicationManagementException(
"Error occured while adding application release into IoTS app management Application id of the "
+ "application release: " + applicationId, e);
} catch (LifeCycleManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException(
"Error occured while adding application release lifecycle state to IoTS app management. "
+ "Application id of the application release: " + applicationId, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -353,7 +372,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
public List<ApplicationRelease> getReleases(int applicationId) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Application application = validateApplication(applicationId);
Application application = getApplicationIfAccessible(applicationId);
List<ApplicationRelease> applicationReleases;
List<ApplicationRelease> filteredApplicationReleases = new ArrayList<>();
if (log.isDebugEnabled()) {
@ -393,7 +412,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
"need to have admin permission");
}
if (validateApplication(applicationId) == null) {
if (getApplicationIfAccessible(applicationId) == null) {
throw new ApplicationManagementException("Invalid Application");
}
List<ApplicationRelease> applicationReleases = getReleases(applicationId);
@ -427,11 +446,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
throws ApplicationManagementException {
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Application application = validateApplication(applicationId);
Application application = getApplicationIfAccessible(applicationId);
if (application == null) {
throw new ApplicationManagementException("Invalid Application ID is received");
}
ApplicationRelease applicationRelease = validateApplicationRelease(applicationId, releaseUuid);
ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, releaseUuid);
if (applicationRelease == null) {
throw new ApplicationManagementException("Invalid Application Release UUID is received");
}
@ -537,12 +556,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
/**
* To validate the pre-request of the ApplicationRelease.
* Get the application if application is an accessible one.
*
* @param applicationId ID of the Application.
* @return Application related with the UUID
*/
public Application validateApplication(int applicationId) throws ApplicationManagementException {
public Application getApplicationIfAccessible(int applicationId) throws ApplicationManagementException {
if (applicationId <= 0) {
throw new ApplicationManagementException("Application id could,t be a negative integer. Hence please add " +
"valid application id.");
@ -568,7 +587,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
if (!isAppAllowed) {
throw new NotFoundException("Application of the " + applicationId + " does not exist.");
throw new NotFoundException("Application of the " + applicationId
+ " does not exist. Please check whether user have permissions to access the application.");
}
return application;
} catch (UserStoreException e) {
@ -580,12 +600,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
/**
* To validate the pre-request of the ApplicationRelease.
* Get the application release for given UUID if application release is exists and application id is valid one.
*
* @param applicationUuid UUID of the Application.
* @return Application related with the UUID
*/
public ApplicationRelease validateApplicationRelease(int applicationId, String applicationUuid) throws
public ApplicationRelease getAppReleaseIfExists(int applicationId, String applicationUuid) throws
ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationRelease applicationRelease;
@ -694,7 +714,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try {
ConnectionManagerUtil.openDBConnection();
LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
ApplicationRelease applicationRelease = validateApplicationRelease(applicationId, applicationUuid);
ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, applicationUuid);
lifecycleState = lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
lifecycleState.setNextStates(getNextLifecycleStates(lifecycleState.getCurrentState()));
} catch (ApplicationManagementDAOException e) {
@ -712,8 +732,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationManagementException {
try {
ConnectionManagerUtil.openDBConnection();
Application application = validateApplication(applicationId);
ApplicationRelease applicationRelease = validateApplicationRelease(applicationId, applicationUuid);
Application application = getApplicationIfAccessible(applicationId);
ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, applicationUuid);
LifecycleStateDAO lifecycleStateDAO;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -828,7 +848,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
public Application updateApplication(Application application) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Application existingApplication = validateApplication(application.getId());
Application existingApplication = getApplicationIfAccessible(application.getId());
List<UnrestrictedRole> addingRoleList;
List<UnrestrictedRole> removingRoleList;
List<Tag> addingTags;

@ -208,7 +208,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
attachments.add(screenshot.getDataHandler().getInputStream());
}
}
applicationRelease = applicationManager.validateApplicationRelease(appId, applicationUuid);
applicationRelease = applicationManager.getAppReleaseIfExists(appId, applicationUuid);
LifecycleState lifecycleState = applicationManager.getLifecycleState(appId, applicationRelease.getUuid());
if (AppLifecycleState.PUBLISHED.toString().equals(lifecycleState.getCurrentState()) ||
AppLifecycleState.DEPRECATED.toString().equals(lifecycleState.getCurrentState())) {
@ -260,7 +260,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
return APIUtil.getResponse("Uploading artifacts for the application is failed " + applicationUuid,
Response.Status.BAD_REQUEST);
}
applicationRelease = applicationManager.validateApplicationRelease(applicationId, applicationUuid);
applicationRelease = applicationManager.getAppReleaseIfExists(applicationId, applicationUuid);
applicationRelease = applicationStorageManager
.updateReleaseArtifacts(applicationRelease, appType, deviceType,
binaryFile.getDataHandler().getInputStream());
@ -323,7 +323,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
List<InputStream> attachments = new ArrayList<>();
try {
Application application = applicationManager.validateApplication(applicationId);
Application application = applicationManager.getApplicationIfAccessible(applicationId);
if (!applicationManager.isApplicationReleaseUpdateAcceptable(application.getId(),
applicationRelease.getUuid())) {

Loading…
Cancel
Save