|
|
@ -1153,48 +1153,49 @@ 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<ApplicationReleaseDTO> filteredApplicationReleaseDTOs = new ArrayList<>();
|
|
|
|
List<String> categories = this.applicationDAO.getAppCategories(appId, tenantId);
|
|
|
|
AtomicBoolean isDeletableApp = new AtomicBoolean(true);
|
|
|
|
applicationDTO.setTags(tags);
|
|
|
|
AtomicBoolean isHideableApp = new AtomicBoolean(true);
|
|
|
|
if (!categories.isEmpty()){
|
|
|
|
for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) {
|
|
|
|
applicationDTO.setAppCategories(categories);
|
|
|
|
if (!applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getEndState())) {
|
|
|
|
|
|
|
|
if (isHideableApp.get()) {
|
|
|
|
|
|
|
|
isHideableApp.set(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDeletableApp.get() && !lifecycleStateManager
|
|
|
|
List<String> unrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(appId, tenantId);
|
|
|
|
.isDeletableState(applicationReleaseDTO.getCurrentState())) {
|
|
|
|
if (!unrestrictedRoles.isEmpty()) {
|
|
|
|
isDeletableApp.set(false);
|
|
|
|
if (hasUserRole(unrestrictedRoles, userName)) {
|
|
|
|
|
|
|
|
isVisibleApp = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (state == null || state.equals(applicationReleaseDTO.getCurrentState())) {
|
|
|
|
isVisibleApp = true;
|
|
|
|
filteredApplicationReleaseDTOs.add(applicationReleaseDTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!isVisibleApp) {
|
|
|
|
|
|
|
|
String msg = "You are trying to access visibility restricted application. You don't have required "
|
|
|
|
|
|
|
|
+ "roles to view this application,";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return APIUtil.appDtoToAppResponse(applicationDTO);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
applicationDTO.setApplicationReleaseDTOs(filteredApplicationReleaseDTOs);
|
|
|
|
|
|
|
|
applicationDTO.setTags(this.applicationDAO.getAppTags(appId, tenantId));
|
|
|
|
|
|
|
|
applicationDTO.setAppCategories(this.applicationDAO.getAppCategories(appId, tenantId));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Application application = APIUtil.appDtoToAppResponse(applicationDTO);
|
|
|
|
|
|
|
|
application.setHideableApp(isHideableApp.get());
|
|
|
|
|
|
|
|
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 =
|
|
|
|
|
|
|
|
"Error occurred while obtaining the database connection to get application for application ID: "
|
|
|
|
+ appId;
|
|
|
|
+ appId;
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, 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) {
|
|
|
|