From b991ed22ee44d9a6f55d47ad8261a2d943aa3cd7 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 2 May 2019 03:00:32 +0530 Subject: [PATCH] Improve get applications method --- .../mgt/core/impl/ApplicationManagerImpl.java | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 3007cc8607..c9629d8d06 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -643,49 +643,45 @@ public class ApplicationManagerImpl implements ApplicationManager { validateFilter(filter); appDTOs = applicationDAO.getApplications(filter, deviceType.getId(), tenantId); //todo as a performance improvement get these data from DB. Consider where in clause. - for (ApplicationDTO app : appDTOs) { + for (ApplicationDTO applicationDTO : appDTOs) { boolean isSearchingApp = true; List filteringTags = filter.getTags(); List filteringCategories = filter.getAppCategories(); List filteringUnrestrictedRoles = filter.getUnrestrictedRoles(); - if (!lifecycleStateManager.getEndState().equals(app.getStatus())) { - List appUnrestrictedRoles = visibilityDAO.getUnrestrictedRoles(app.getId(), tenantId); + if (!lifecycleStateManager.getEndState().equals(applicationDTO.getStatus())) { + List appUnrestrictedRoles = visibilityDAO.getUnrestrictedRoles(applicationDTO.getId(), tenantId); if ((appUnrestrictedRoles.isEmpty() || hasUserRole(appUnrestrictedRoles, userName)) && ( filteringUnrestrictedRoles == null || filteringUnrestrictedRoles.isEmpty() || hasAppUnrestrictedRole(appUnrestrictedRoles, filteringUnrestrictedRoles, userName))) { if (filteringCategories != null && !filteringCategories.isEmpty()) { - List appTagList = applicationDAO.getAppCategories(app.getId(), tenantId); - boolean isAppCategory = false; - for (String category : filteringCategories) { - if (appTagList.contains(category)) { - isAppCategory = true; - break; - } - } + List appTagList = applicationDAO.getAppCategories(applicationDTO.getId(), tenantId); + boolean isAppCategory = filteringCategories.stream().anyMatch(appTagList::contains); if (!isAppCategory) { isSearchingApp = false; } } if (filteringTags != null && !filteringTags.isEmpty()) { - List appTagList = applicationDAO.getAppTags(app.getId(), tenantId); - boolean isAppTag = false; - for (String tag : filteringTags) { - if (appTagList.contains(tag)) { - isAppTag = true; - break; - } - } + List appTagList = applicationDAO.getAppTags(applicationDTO.getId(), tenantId); + boolean isAppTag = filteringTags.stream().anyMatch(appTagList::contains); if (!isAppTag) { isSearchingApp = false; } } if (isSearchingApp) { - filteredApplications.add(app); + filteredApplications.add(applicationDTO); } } } + + List filteredApplicationReleaseDTOs = new ArrayList<>(); + for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) { + if (!applicationReleaseDTO.getCurrentState().equals(lifecycleStateManager.getEndState())) { + filteredApplicationReleaseDTOs.add(applicationReleaseDTO); + } + } + applicationDTO.setApplicationReleaseDTOs(filteredApplicationReleaseDTOs); } for(ApplicationDTO appDTO : filteredApplications){