|
|
|
@ -2223,7 +2223,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
List<CategoryDTO> existingCategories = applicationDAO.getAllCategories(tenantId);
|
|
|
|
|
List<CategoryDTO> existingCategories = this.getAllCategories();
|
|
|
|
|
List<String> existingCategoryNames = existingCategories.stream().map(CategoryDTO::getCategoryName)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
if(!existingCategoryNames.containsAll(categories)){
|
|
|
|
@ -2395,7 +2395,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
|
|
|
|
|
List<String> updatingAppCategries = applicationUpdateWrapper.getCategories();
|
|
|
|
|
if (updatingAppCategries != null){
|
|
|
|
|
List<CategoryDTO> allCategories = this.applicationDAO.getAllCategories(tenantId);
|
|
|
|
|
List<CategoryDTO> allCategories = this.getAllCategories();
|
|
|
|
|
List<String> allCategoryName = allCategories.stream().map(CategoryDTO::getCategoryName)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
@ -2522,7 +2522,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
List<CategoryDTO> categories = applicationDAO.getAllCategories(tenantId);
|
|
|
|
|
List<CategoryDTO> categories = this.getAllCategories();
|
|
|
|
|
List<Integer> mappedCategoryIds = applicationDAO.getDistinctCategoryIdsInCategoryMapping();
|
|
|
|
|
List<Category> responseCategoryList = new ArrayList<>();
|
|
|
|
|
categories.forEach(category -> {
|
|
|
|
@ -2800,7 +2800,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
try {
|
|
|
|
|
if (categories != null && !categories.isEmpty()) {
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
List<CategoryDTO> registeredCategories = applicationDAO.getAllCategories(tenantId);
|
|
|
|
|
List<CategoryDTO> registeredCategories = this.getAllCategories();
|
|
|
|
|
List<String> registeredCategoryNames = registeredCategories.stream().map(CategoryDTO::getCategoryName)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
@ -3623,7 +3623,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<CategoryDTO> registeredCategories = this.applicationDAO.getAllCategories(tenantId);
|
|
|
|
|
List<CategoryDTO> registeredCategories = this.getAllCategories();
|
|
|
|
|
|
|
|
|
|
if (registeredCategories.isEmpty()) {
|
|
|
|
|
String msg = "Registered application category set is empty. Since it is mandatory to add application "
|
|
|
|
@ -3999,4 +3999,38 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve all categories after sync default categories with database
|
|
|
|
|
* @return List<CategoryDTO> list of CategoryDTO objects
|
|
|
|
|
* @throws ApplicationManagementException throws when constructing all categories
|
|
|
|
|
*/
|
|
|
|
|
private List<CategoryDTO> getAllCategories() throws ApplicationManagementException {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
List<String> defaultCategories = ConfigurationManager.getInstance().getConfiguration().getAppCategories();
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.getDBConnection();
|
|
|
|
|
List<CategoryDTO> existingCategoriesInDB = this.applicationDAO.getAllCategories(tenantId);
|
|
|
|
|
List<String> existingCategoryNames = existingCategoriesInDB.stream().
|
|
|
|
|
map(CategoryDTO::getCategoryName).collect(Collectors.toList());
|
|
|
|
|
List<String> notExistingDefaultCategoryNamesInDB = defaultCategories.stream().
|
|
|
|
|
filter(defaultCategory -> !existingCategoryNames.contains(defaultCategory)).collect(Collectors.toList());
|
|
|
|
|
if(!notExistingDefaultCategoryNamesInDB.isEmpty()) {
|
|
|
|
|
this.applicationDAO.addCategories(notExistingDefaultCategoryNamesInDB, tenantId);
|
|
|
|
|
if(log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Database successfully sync with the default categories");
|
|
|
|
|
}
|
|
|
|
|
existingCategoriesInDB = this.applicationDAO.getAllCategories(tenantId);
|
|
|
|
|
}
|
|
|
|
|
return existingCategoriesInDB;
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
String msg = "Error occurred while getting the database connection";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
String msg = "Error occurred while constructing and syncing categories with the database";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|