From 3b3c89849ee4fbce737e14a9371bec7d67f808f2 Mon Sep 17 00:00:00 2001 From: Mohamed Rashd Date: Thu, 28 Apr 2022 16:18:09 +0530 Subject: [PATCH] Fix favourite flag being always false when getting application by uuid --- .../mgt/core/impl/ApplicationManagerImpl.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java index b7fce45b1a..26f97f0caf 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java @@ -961,9 +961,7 @@ public class ApplicationManagerImpl implements ApplicationManager { //Set application categories, tags and unrestricted roles to the application DTO. applicationDTO .setUnrestrictedRoles(visibilityDAO.getUnrestrictedRoles(applicationDTO.getId(), tenantId)); - applicationDTO.setAppCategories(applicationDAO.getAppCategories(applicationDTO.getId(), tenantId)); - applicationDTO.setTags(applicationDAO.getAppTags(applicationDTO.getId(), tenantId)); - applicationDTO.setFavourite(applicationDAO.isFavouriteApp(applicationDTO.getId(), userName, tenantId)); + setApplicationProperties(applicationDTO); if (isFilteringApp(applicationDTO, filter)) { boolean isHideableApp = isHideableApp(applicationDTO.getApplicationReleaseDTOs()); @@ -1586,11 +1584,7 @@ public class ApplicationManagerImpl implements ApplicationManager { return null; } applicationDTO.setApplicationReleaseDTOs(filteredApplicationReleaseDTOs); - - List tags = this.applicationDAO.getAppTags(applicationDTO.getId(), tenantId); - List categories = this.applicationDAO.getAppCategories(applicationDTO.getId(), tenantId); - applicationDTO.setTags(tags); - applicationDTO.setAppCategories(categories); + setApplicationProperties(applicationDTO); List unrestrictedRoles = this.visibilityDAO.getUnrestrictedRoles(applicationDTO.getId(), tenantId); if (!unrestrictedRoles.isEmpty()) { @@ -1630,6 +1624,17 @@ public class ApplicationManagerImpl implements ApplicationManager { } } + /** + * This is useful to set application properties that are mapped in other database tables (I.E: tags and categories) + */ + private void setApplicationProperties(ApplicationDTO applicationDTO) throws ApplicationManagementDAOException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + applicationDTO.setTags(applicationDAO.getAppTags(applicationDTO.getId(), tenantId)); + applicationDTO.setAppCategories(applicationDAO.getAppCategories(applicationDTO.getId(), tenantId)); + applicationDTO.setFavourite(applicationDAO.isFavouriteApp(applicationDTO.getId(), userName, tenantId)); + } + /** * Check whether at least one role is assigned to the given user. *