From 86ab6d98fc86388c0fb08672c23c2da54eb426a9 Mon Sep 17 00:00:00 2001 From: Vitali Ihnatsenka Date: Wed, 6 Mar 2024 14:14:43 +0100 Subject: [PATCH] #18 Provide a settings console instead of the OSGi config --- .../core/services/data/UiConfigService.java | 1 + .../data/impl/GridResourcesGeneratorImpl.java | 2 +- .../data/impl/UiConfigServiceImpl.java | 14 ++++++- .../data/impl/DataFeedServiceImplTest.java | 8 ++-- .../impl/GridResourcesGeneratorImplTest.java | 3 +- .../link-inspector-ui/js/console-ui.filter.js | 37 +++++++++++-------- 6 files changed, 40 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/UiConfigService.java b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/UiConfigService.java index d2ff987c..a27720b4 100644 --- a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/UiConfigService.java +++ b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/UiConfigService.java @@ -2,4 +2,5 @@ public interface UiConfigService { String[] getExcludedLinksPatterns(); + String getSearchPath(); } diff --git a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImpl.java b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImpl.java index a0a8ee93..cea3131a 100644 --- a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImpl.java +++ b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImpl.java @@ -195,7 +195,7 @@ int[] allowedStatusCodes() default { @Activate @Modified protected void activate(Configuration configuration) { - searchPath = configuration.searchPath(); + searchPath = uiConfigService.getSearchPath(); excludedPaths = configuration.excludedPaths(); checkActivation = configuration.checkActivation(); skipModifiedAfterActivation = configuration.skipModifiedAfterActivation(); diff --git a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/UiConfigServiceImpl.java b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/UiConfigServiceImpl.java index 4dcf1033..a6cd7bc5 100644 --- a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/UiConfigServiceImpl.java +++ b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/UiConfigServiceImpl.java @@ -13,17 +13,27 @@ public class UiConfigServiceImpl implements UiConfigService { private static final String CONFIG_PATH = "/content/etoolbox-link-inspector/data/config"; private static final String PN_FILTER = "filter"; + private static final String PN_PATH = "path"; + private static final String DEFAULT_PATH = "/content"; @Reference private RepositoryHelper repositoryHelper; @Override public String[] getExcludedLinksPatterns() { + return getProperty(PN_FILTER, String[].class).orElse(new String[0]); + } + + @Override + public String getSearchPath() { + return getProperty(PN_PATH, String.class).orElse(DEFAULT_PATH); + } + + private Optional getProperty(String name, Class clazz){ try(ResourceResolver resourceResolver = repositoryHelper.getServiceResourceResolver()){ return Optional.ofNullable(resourceResolver.getResource(CONFIG_PATH)) .map(Resource::getValueMap) - .map(vm->vm.get(PN_FILTER, String[].class)) - .orElse(new String[0]); + .map(vm->vm.get(name, clazz)); } } } diff --git a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/DataFeedServiceImplTest.java b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/DataFeedServiceImplTest.java index d2b5f30f..b2794a88 100644 --- a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/DataFeedServiceImplTest.java +++ b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/DataFeedServiceImplTest.java @@ -181,13 +181,13 @@ private GridResourcesGeneratorImpl getGridResourcesGenerator() throws NoSuchFiel ExternalLinkChecker externalLinkChecker = mock(ExternalLinkChecker.class); PrivateAccessor.setField(linkHelper, EXTERNAL_LINK_CHECKER_FIELD, externalLinkChecker); PrivateAccessor.setField(gridResourcesGenerator, LINK_HELPER_FIELD, linkHelper); - GridResourcesGeneratorImplTest.setUpConfig(gridResourcesGenerator); - - when(externalLinkChecker.checkLink(anyString())).thenReturn(HttpStatus.SC_NOT_FOUND); - UiConfigService uiConfigService = mock(UiConfigServiceImpl.class); when(uiConfigService.getExcludedLinksPatterns()).thenReturn(new String[0]); + when(uiConfigService.getSearchPath()).thenReturn(TEST_FOLDER_PATH); PrivateAccessor.setField(gridResourcesGenerator, UI_CONFIG_FIELD, uiConfigService); + GridResourcesGeneratorImplTest.setUpConfig(gridResourcesGenerator); + + when(externalLinkChecker.checkLink(anyString())).thenReturn(HttpStatus.SC_NOT_FOUND); return gridResourcesGenerator; } diff --git a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImplTest.java b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImplTest.java index 7cc54f86..874c5028 100644 --- a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImplTest.java +++ b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImplTest.java @@ -140,6 +140,7 @@ void setup() throws NoSuchFieldException { uiConfigService = mock(UiConfigServiceImpl.class); when(uiConfigService.getExcludedLinksPatterns()).thenReturn(new String[0]); + when(uiConfigService.getSearchPath()).thenReturn(TEST_FOLDER_PATH); PrivateAccessor.setField(fixture, UI_CONFIG_FIELD, uiConfigService); } @@ -155,8 +156,6 @@ void testGenerateGridResources() throws NoSuchFieldException, IOException, URISy assertTrue(CollectionUtils.isEqualCollection(expectedGridResources, gridResources)); } - - @Test void testGenerateFilteredGridResources() throws NoSuchFieldException, IOException, URISyntaxException { setUpConfig(fixture); diff --git a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/js/console-ui.filter.js b/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/js/console-ui.filter.js index 41a00c44..2e6045b5 100644 --- a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/js/console-ui.filter.js +++ b/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/js/console-ui.filter.js @@ -18,12 +18,12 @@ */ (function (window, document, $, ELC, Granite, Coral) { 'use strict'; - var DIALOG_TITLE_LABEL = Granite.I18n.get('Filter Options'); - var SUCCESS_DIALOG_TITLE_LABEL = Granite.I18n.get('Filter Options Applied'); - var CANCEL_LABEL = Granite.I18n.get('Cancel'); - var SUBMIT_FILTER_LABEL = Granite.I18n.get('Apply'); + const DIALOG_TITLE_LABEL = Granite.I18n.get('Filter Options'); + const SUCCESS_DIALOG_TITLE_LABEL = Granite.I18n.get('Filter Options Applied'); + const CANCEL_LABEL = Granite.I18n.get('Cancel'); + const SUBMIT_FILTER_LABEL = Granite.I18n.get('Apply'); - var successDialog = new Coral.Dialog().set({ + const successDialog = new Coral.Dialog().set({ id : "filter-dialog-success", closable: Coral.Dialog.closable.ON, variant: "success", @@ -39,12 +39,12 @@ }); function onFilterAction(name, el, config, collection, selections) { - var dialog = document.querySelector('#filter-dialog'); + const dialog = document.querySelector('#filter-dialog'); dialog.show(); } function initActionDialog(){ - var dialog = new Coral.Dialog().set({ + const dialog = new Coral.Dialog().set({ id : 'filter-dialog', closable: Coral.Dialog.closable.ON, backdrop: Coral.Dialog.backdrop.STATIC, @@ -54,38 +54,42 @@ } }); - var $cancelBtn = $('