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