|
|
@ -101,7 +101,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
validateAppCreatingRequest(application);
|
|
|
|
validateAppCreatingRequest(application, tenantId);
|
|
|
|
validateAppReleasePayload(application.getApplicationReleases().get(0));
|
|
|
|
validateAppReleasePayload(application.getApplicationReleases().get(0));
|
|
|
|
DeviceType deviceType;
|
|
|
|
DeviceType deviceType;
|
|
|
|
ApplicationRelease applicationRelease;
|
|
|
|
ApplicationRelease applicationRelease;
|
|
|
@ -210,7 +210,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.getDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
applicationList = applicationDAO.getApplications(filter, tenantId);
|
|
|
|
applicationList = applicationDAO.getApplications(filter, tenantId);
|
|
|
|
if(applicationList != null && applicationList.getApplications() != null && !applicationList
|
|
|
|
if(applicationList != null && applicationList.getApplications() != null && !applicationList
|
|
|
|
.getApplications().isEmpty()) {
|
|
|
|
.getApplications().isEmpty()) {
|
|
|
@ -218,7 +218,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
applicationList = getRoleRestrictedApplicationList(applicationList, userName);
|
|
|
|
applicationList = getRoleRestrictedApplicationList(applicationList, userName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (Application application : applicationList.getApplications()) {
|
|
|
|
for (Application application : applicationList.getApplications()) {
|
|
|
|
applicationReleases = getReleases(application, filter.isRequirePublishedRelease());
|
|
|
|
applicationReleases = getReleases(application, filter.getCurrentAppReleaseState());
|
|
|
|
application.setApplicationReleases(applicationReleases);
|
|
|
|
application.setApplicationReleases(applicationReleases);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -230,6 +230,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
"DAO exception while getting applications for the user " + userName + " of tenant " + tenantId, e);
|
|
|
|
"DAO exception while getting applications for the user " + userName + " of tenant " + tenantId, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -273,19 +275,24 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Application getApplicationById(int appId, String state, boolean handleConnections) throws ApplicationManagementException {
|
|
|
|
public Application getApplicationById(int appId, String state) throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
Application application;
|
|
|
|
Application application;
|
|
|
|
boolean isAppAllowed = false;
|
|
|
|
boolean isAppAllowed = false;
|
|
|
|
|
|
|
|
boolean isOpenConnection = false;
|
|
|
|
List<ApplicationRelease> applicationReleases = null;
|
|
|
|
List<ApplicationRelease> applicationReleases = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (handleConnections) {
|
|
|
|
if (state != null) {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
|
|
|
isOpenConnection = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
application = this.applicationDAO.getApplicationById(appId, tenantId);
|
|
|
|
application = this.applicationDAO.getApplicationById(appId, tenantId);
|
|
|
|
|
|
|
|
if (application == null) {
|
|
|
|
|
|
|
|
throw new NotFoundException("Couldn't find an application for application Id: " + appId);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
|
|
|
|
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
|
|
|
|
applicationReleases = getReleaseInState(appId, state, tenantId);
|
|
|
|
applicationReleases = getReleases(application, state);
|
|
|
|
application.setApplicationReleases(applicationReleases);
|
|
|
|
application.setApplicationReleases(applicationReleases);
|
|
|
|
return application;
|
|
|
|
return application;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -301,14 +308,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
if (!isAppAllowed) {
|
|
|
|
if (!isAppAllowed) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
applicationReleases = getReleaseInState(appId, state, tenantId);
|
|
|
|
applicationReleases = getReleases(application, state);
|
|
|
|
application.setApplicationReleases(applicationReleases);
|
|
|
|
application.setApplicationReleases(applicationReleases);
|
|
|
|
return application;
|
|
|
|
return application;
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
"User-store exception while getting application with the application id " + appId);
|
|
|
|
"User-store exception while getting application with the application id " + appId);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
if (handleConnections) {
|
|
|
|
if (isOpenConnection) {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -349,7 +356,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
application = this.applicationDAO.getApplication(appName, appType, tenantId);
|
|
|
|
application = this.applicationDAO.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, null);
|
|
|
|
application.setApplicationReleases(applicationReleases);
|
|
|
|
application.setApplicationReleases(applicationReleases);
|
|
|
|
return application;
|
|
|
|
return application;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -366,7 +373,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
applicationReleases = getReleases(application, false);
|
|
|
|
applicationReleases = getReleases(application, null);
|
|
|
|
application.setApplicationReleases(applicationReleases);
|
|
|
|
application.setApplicationReleases(applicationReleases);
|
|
|
|
return application;
|
|
|
|
return application;
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
@ -421,16 +428,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<ApplicationRelease> getReleases(Application application, boolean requirePublishedRelease)
|
|
|
|
private List<ApplicationRelease> getReleases(Application application, String releaseState)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
List<ApplicationRelease> applicationReleases;
|
|
|
|
List<ApplicationRelease> applicationReleases;
|
|
|
|
List<ApplicationRelease> filteredApplicationReleases = new ArrayList<>();
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Request is received to retrieve all the releases related with the application " + application
|
|
|
|
log.debug("Request is received to retrieve all the releases related with the application " + application
|
|
|
|
.toString());
|
|
|
|
.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 = null;
|
|
|
|
LifecycleState lifecycleState = null;
|
|
|
@ -443,47 +448,26 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lifecycleState != null) {
|
|
|
|
if (lifecycleState != null) {
|
|
|
|
applicationRelease.setLifecycleState(lifecycleState);
|
|
|
|
applicationRelease.setLifecycleState(lifecycleState);
|
|
|
|
|
|
|
|
|
|
|
|
if (!AppLifecycleState.REMOVED.toString()
|
|
|
|
|
|
|
|
.equals(applicationRelease.getLifecycleState().getCurrentState())) {
|
|
|
|
|
|
|
|
if (requirePublishedRelease){
|
|
|
|
|
|
|
|
if (AppLifecycleState.PUBLISHED.toString()
|
|
|
|
|
|
|
|
.equals(applicationRelease.getLifecycleState().getCurrentState())){
|
|
|
|
|
|
|
|
filteredApplicationReleases.add(applicationRelease);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
filteredApplicationReleases.add(applicationRelease);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return filterAppReleaseByCurrentState(applicationReleases, releaseState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (requirePublishedRelease && filteredApplicationReleases.size() > 1) {
|
|
|
|
|
|
|
|
log.error("There are more than one published application releases for application ID: " + application
|
|
|
|
|
|
|
|
.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return filteredApplicationReleases;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
private List<ApplicationRelease> filterAppReleaseByCurrentState(List<ApplicationRelease> applicationReleases,
|
|
|
|
|
|
|
|
String state) {
|
|
|
|
private List<ApplicationRelease> getReleaseInState(int applicationId, String state, int tenantId)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
List<ApplicationRelease> applicationReleases;
|
|
|
|
|
|
|
|
List<ApplicationRelease> filteredReleases = new ArrayList<>();
|
|
|
|
List<ApplicationRelease> filteredReleases = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
// todo check whether this rquired or not
|
|
|
|
|
|
|
|
Application application = getApplicationIfAccessible(applicationId);
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Request is received to retrieve all the releases related with the application " + application
|
|
|
|
|
|
|
|
.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
applicationReleases = this.applicationReleaseDAO.getReleases(applicationId, tenantId);
|
|
|
|
|
|
|
|
if (state != null && !state.isEmpty()) {
|
|
|
|
if (state != null && !state.isEmpty()) {
|
|
|
|
for (ApplicationRelease applicationRelease : applicationReleases) {
|
|
|
|
for (ApplicationRelease applicationRelease : applicationReleases) {
|
|
|
|
if (state.equals(applicationRelease.getLifecycleState().getCurrentState())) {
|
|
|
|
if (state.equals(applicationRelease.getLifecycleState().getCurrentState())) {
|
|
|
|
filteredReleases.add(applicationRelease);
|
|
|
|
filteredReleases.add(applicationRelease);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (AppLifecycleState.PUBLISHED.toString()
|
|
|
|
|
|
|
|
.equals(state) && filteredReleases.size() > 1) {
|
|
|
|
|
|
|
|
log.warn("There are more than one application releases is found which is in PUBLISHED state");
|
|
|
|
|
|
|
|
}
|
|
|
|
return filteredReleases;
|
|
|
|
return filteredReleases;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return applicationReleases;
|
|
|
|
return applicationReleases;
|
|
|
@ -507,7 +491,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
if ( application == null) {
|
|
|
|
if ( application == null) {
|
|
|
|
throw new ApplicationManagementException("Invalid Application");
|
|
|
|
throw new ApplicationManagementException("Invalid Application");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<ApplicationRelease> applicationReleases = getReleases(application, false);
|
|
|
|
List<ApplicationRelease> applicationReleases = getReleases(application, null);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Request is received to delete applications which are related with the application id " +
|
|
|
|
log.debug("Request is received to delete applications which are related with the application id " +
|
|
|
|
applicationId);
|
|
|
|
applicationId);
|
|
|
@ -589,7 +573,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
* @param application Application that need to be created
|
|
|
|
* @param application Application that need to be created
|
|
|
|
* @throws ValidationException Validation Exception
|
|
|
|
* @throws ValidationException Validation Exception
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void validateAppCreatingRequest(Application application) throws ValidationException {
|
|
|
|
private void validateAppCreatingRequest(Application application, int tenantId) throws ValidationException {
|
|
|
|
|
|
|
|
|
|
|
|
Boolean isValidApplicationType;
|
|
|
|
Boolean isValidApplicationType;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -611,7 +595,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
"App Type contains in the application creating payload doesn't match with supported app types");
|
|
|
|
"App Type contains in the application creating payload doesn't match with supported app types");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
validateApplicationExistence(application);
|
|
|
|
validateApplicationExistence(application, tenantId);
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
throw new ValidationException("Error occured while validating whether there is already an application "
|
|
|
|
throw new ValidationException("Error occured while validating whether there is already an application "
|
|
|
|
+ "registered with same name.", e);
|
|
|
|
+ "registered with same name.", e);
|
|
|
@ -633,14 +617,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
* @param application Application that need to be validated
|
|
|
|
* @param application Application that need to be validated
|
|
|
|
* @throws ValidationException Validation Exception
|
|
|
|
* @throws ValidationException Validation Exception
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void validateApplicationExistence(Application application) throws ApplicationManagementException {
|
|
|
|
private void validateApplicationExistence(Application application, int tenantId) throws ApplicationManagementException {
|
|
|
|
Filter filter = new Filter();
|
|
|
|
Filter filter = new Filter();
|
|
|
|
filter.setFullMatch(true);
|
|
|
|
filter.setFullMatch(true);
|
|
|
|
filter.setAppName(application.getName().trim());
|
|
|
|
filter.setAppName(application.getName().trim());
|
|
|
|
filter.setOffset(0);
|
|
|
|
filter.setOffset(0);
|
|
|
|
filter.setLimit(1);
|
|
|
|
filter.setLimit(1);
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationList applicationList = getApplications(filter);
|
|
|
|
ApplicationList applicationList = applicationDAO.getApplications(filter, tenantId);
|
|
|
|
if (applicationList != null && applicationList.getApplications() != null && !applicationList.getApplications()
|
|
|
|
if (applicationList != null && applicationList.getApplications() != null && !applicationList.getApplications()
|
|
|
|
.isEmpty()) {
|
|
|
|
.isEmpty()) {
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
throw new ApplicationManagementException(
|
|
|
@ -765,10 +749,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager();
|
|
|
|
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager();
|
|
|
|
ApplicationRelease applicationRelease;
|
|
|
|
ApplicationRelease applicationRelease;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.getDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
applicationRelease = getAppReleaseIfExists(appId, uuid);
|
|
|
|
applicationRelease = getAppReleaseIfExists(appId, uuid);
|
|
|
|
|
|
|
|
|
|
|
|
Application application = getApplicationById(appId, null, false);
|
|
|
|
Application application = getApplicationById(appId, null);
|
|
|
|
|
|
|
|
|
|
|
|
List<DeviceType> deviceTypes = Util.getDeviceManagementService().getDeviceTypes();
|
|
|
|
List<DeviceType> deviceTypes = Util.getDeviceManagementService().getDeviceTypes();
|
|
|
|
for (DeviceType deviceType:deviceTypes) {
|
|
|
|
for (DeviceType deviceType:deviceTypes) {
|
|
|
|