|
|
@ -1153,49 +1153,50 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
public Application getApplicationById(int appId, String state) 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();
|
|
|
|
boolean isVisibleApp = false;
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO = getApplication(appId);
|
|
|
|
ApplicationDTO applicationDTO = getApplication(appId);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
List<ApplicationReleaseDTO> filteredApplicationReleaseDTOs = new ArrayList<>();
|
|
|
|
List<String> unrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(appId, tenantId);
|
|
|
|
for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) {
|
|
|
|
if (!unrestrictedRoles.isEmpty() && !hasUserRole(unrestrictedRoles, userName)) {
|
|
|
|
if (!applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getEndState()) && (
|
|
|
|
String msg = "You are trying to access visibility restricted application and you are not assigned"
|
|
|
|
state == null || applicationReleaseDTO.getCurrentState().equals(state))) {
|
|
|
|
+ " required roles to view this application,";
|
|
|
|
filteredApplicationReleaseDTOs.add(applicationReleaseDTO);
|
|
|
|
log.error(msg);
|
|
|
|
}
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (state != null && filteredApplicationReleaseDTOs.isEmpty()) {
|
|
|
|
if (lifecycleStateManager.getEndState().equals(applicationDTO.getStatus())) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
applicationDTO.setApplicationReleaseDTOs(filteredApplicationReleaseDTOs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> tags = this.applicationDAO.getAppTags(appId, tenantId);
|
|
|
|
|
|
|
|
List<String> categories = this.applicationDAO.getAppCategories(appId, tenantId);
|
|
|
|
|
|
|
|
applicationDTO.setTags(tags);
|
|
|
|
|
|
|
|
if (!categories.isEmpty()){
|
|
|
|
|
|
|
|
applicationDTO.setAppCategories(categories);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> unrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(appId, tenantId);
|
|
|
|
List<ApplicationReleaseDTO> filteredApplicationReleaseDTOs = new ArrayList<>();
|
|
|
|
if (!unrestrictedRoles.isEmpty()) {
|
|
|
|
AtomicBoolean isDeletableApp = new AtomicBoolean(true);
|
|
|
|
if (hasUserRole(unrestrictedRoles, userName)) {
|
|
|
|
AtomicBoolean isHideableApp = new AtomicBoolean(true);
|
|
|
|
isVisibleApp = true;
|
|
|
|
for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) {
|
|
|
|
|
|
|
|
if (!applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getEndState())) {
|
|
|
|
|
|
|
|
if (isHideableApp.get()) {
|
|
|
|
|
|
|
|
isHideableApp.set(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDeletableApp.get() && !lifecycleStateManager
|
|
|
|
|
|
|
|
.isDeletableState(applicationReleaseDTO.getCurrentState())) {
|
|
|
|
|
|
|
|
isDeletableApp.set(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state == null || state.equals(applicationReleaseDTO.getCurrentState())) {
|
|
|
|
|
|
|
|
filteredApplicationReleaseDTOs.add(applicationReleaseDTO);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
isVisibleApp = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!isVisibleApp) {
|
|
|
|
applicationDTO.setApplicationReleaseDTOs(filteredApplicationReleaseDTOs);
|
|
|
|
String msg = "You are trying to access visibility restricted application. You don't have required "
|
|
|
|
applicationDTO.setTags(this.applicationDAO.getAppTags(appId, tenantId));
|
|
|
|
+ "roles to view this application,";
|
|
|
|
applicationDTO.setAppCategories(this.applicationDAO.getAppCategories(appId, tenantId));
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
Application application = APIUtil.appDtoToAppResponse(applicationDTO);
|
|
|
|
}
|
|
|
|
application.setHideableApp(isHideableApp.get());
|
|
|
|
return APIUtil.appDtoToAppResponse(applicationDTO);
|
|
|
|
application.setDeletableApp(isDeletableApp.get());
|
|
|
|
|
|
|
|
return application;
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
String msg = "Error occurred while obtaining the database connection to get application for application ID: "
|
|
|
|
String msg =
|
|
|
|
+ appId;
|
|
|
|
"Error occurred while obtaining the database connection to get application for application ID: "
|
|
|
|
|
|
|
|
+ appId;
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} catch (LifecycleManagementException e) {
|
|
|
|
} catch (LifecycleManagementException e) {
|
|
|
@ -1219,7 +1220,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
public Application getApplicationByUuid(String releaseUuid) throws ApplicationManagementException{
|
|
|
|
public Application getApplicationByUuid(String releaseUuid) throws ApplicationManagementException{
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
boolean isVisibleApp = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
@ -1230,34 +1230,36 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<String> tags = this.applicationDAO.getAppTags(applicationDTO.getId(), tenantId);
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
|
|
|
|
List<String> categories = this.applicationDAO.getAppCategories(applicationDTO.getId(), tenantId);
|
|
|
|
if (lifecycleStateManager.isEndState(applicationReleaseDTO.getCurrentState())) {
|
|
|
|
applicationDTO.setTags(tags);
|
|
|
|
return null;
|
|
|
|
applicationDTO.setAppCategories(categories);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> unrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(applicationDTO.getId(), tenantId);
|
|
|
|
|
|
|
|
if (!unrestrictedRoles.isEmpty()) {
|
|
|
|
|
|
|
|
if (hasUserRole(unrestrictedRoles, userName)) {
|
|
|
|
|
|
|
|
isVisibleApp = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
isVisibleApp = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!isVisibleApp) {
|
|
|
|
List<String> unrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(applicationDTO.getId(), tenantId);
|
|
|
|
|
|
|
|
if (!unrestrictedRoles.isEmpty() && !hasUserRole(unrestrictedRoles, userName)) {
|
|
|
|
String msg = "You are trying to access visibility restricted application. You don't have required "
|
|
|
|
String msg = "You are trying to access visibility restricted application. You don't have required "
|
|
|
|
+ "roles to view this application,";
|
|
|
|
+ "roles to view this application,";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return APIUtil.appDtoToAppResponse(applicationDTO);
|
|
|
|
|
|
|
|
|
|
|
|
applicationDTO.setTags(this.applicationDAO.getAppTags(applicationDTO.getId(), tenantId));
|
|
|
|
|
|
|
|
applicationDTO.setAppCategories(this.applicationDAO.getAppCategories(applicationDTO.getId(), tenantId));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Application application = APIUtil.appDtoToAppResponse(applicationDTO);
|
|
|
|
|
|
|
|
if (lifecycleStateManager.isDeletableState(applicationReleaseDTO.getCurrentState())) {
|
|
|
|
|
|
|
|
ApplicationDTO entireApplication = applicationDAO.getApplication(applicationDTO.getId(), tenantId);
|
|
|
|
|
|
|
|
application.setDeletableApp(isDeletableApp(entireApplication.getApplicationReleaseDTOs()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return application;
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
String msg = "Error occurred while obtaining the database connection to get application for application "
|
|
|
|
String msg = "Error occurred while obtaining the database connection to get application for application "
|
|
|
|
+ "release UUID: " + releaseUuid;
|
|
|
|
+ "release UUID: " + releaseUuid;
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "User-store exception occurred while getting application for application release UUID " + releaseUuid;
|
|
|
|
String msg = "User-store exception occurred while getting application for application release UUID "
|
|
|
|
|
|
|
|
+ releaseUuid;
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|