From b1d158fc7eb6f522b16cb90e1a422948da023a86 Mon Sep 17 00:00:00 2001 From: Vitali Ihnatsenka Date: Mon, 11 Mar 2024 12:42:13 +0100 Subject: [PATCH] #18 Provide a settings console instead of the OSGi config - excluded paths --- .../core/services/data/UiConfigService.java | 1 + .../data/impl/GridResourcesGeneratorImpl.java | 12 ++-- .../data/impl/UiConfigServiceImpl.java | 6 ++ .../data/impl/DataFeedServiceImplTest.java | 1 + .../impl/GridResourcesGeneratorImplTest.java | 9 +-- .../link-inspector-ui/css/console-ui.less | 9 +++ .../link-inspector-ui/js/console-ui.filter.js | 66 ++++++++++++------- 7 files changed, 68 insertions(+), 36 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 a27720b4..ee3e01d3 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 @@ -3,4 +3,5 @@ public interface UiConfigService { String[] getExcludedLinksPatterns(); String getSearchPath(); + String[] getExcludedPaths(); } 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 cea3131a..4fe338b1 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 @@ -176,8 +176,6 @@ int[] allowedStatusCodes() default { private ExecutorService executorService; - private String searchPath; - private String[] excludedPaths; private boolean checkActivation; private boolean skipModifiedAfterActivation; private ZonedDateTime lastModifiedBoundary; @@ -195,8 +193,6 @@ int[] allowedStatusCodes() default { @Activate @Modified protected void activate(Configuration configuration) { - searchPath = uiConfigService.getSearchPath(); - excludedPaths = configuration.excludedPaths(); checkActivation = configuration.checkActivation(); skipModifiedAfterActivation = configuration.skipModifiedAfterActivation(); lastModifiedBoundary = Optional.of(configuration.lastModifiedBoundary()) @@ -216,8 +212,8 @@ protected void activate(Configuration configuration) { */ @Override public List generateGridResources(String gridResourceType, ResourceResolver resourceResolver) { - uiConfigService.getExcludedLinksPatterns(); StopWatch stopWatch = StopWatch.createStarted(); + String searchPath = uiConfigService.getSearchPath(); LOG.debug("Start broken links collecting, path: {}", searchPath); Resource rootResource = resourceResolver.getResource(searchPath); @@ -401,7 +397,7 @@ private boolean isExcludedProperty(String propertyName) { } private boolean isExcludedPath(String path) { - return isStringMatchAnyPattern(path, excludedPaths); + return isStringMatchAnyPattern(path, uiConfigService.getExcludedPaths()); } private boolean isAllowedErrorCode(int linkStatusCode) { @@ -487,8 +483,8 @@ private Map getGenerationStatsMap(LinksCounter allLinksCounter, stats.put(GenerationStatsProps.PN_LAST_GENERATED, ZonedDateTime.now().format(DateTimeFormatter.RFC_1123_DATE_TIME)); - stats.put(GenerationStatsProps.PN_SEARCH_PATH, searchPath); - stats.put(GenerationStatsProps.PN_EXCLUDED_PATHS, excludedPaths); + stats.put(GenerationStatsProps.PN_SEARCH_PATH, uiConfigService.getSearchPath()); + stats.put(GenerationStatsProps.PN_EXCLUDED_PATHS, uiConfigService.getExcludedPaths()); stats.put(GenerationStatsProps.PN_CHECK_ACTIVATION, checkActivation); stats.put(GenerationStatsProps.PN_SKIP_MODIFIED_AFTER_ACTIVATION, skipModifiedAfterActivation); stats.put(GenerationStatsProps.PN_LAST_MODIFIED_BOUNDARY, dateToIsoDateTimeString(lastModifiedBoundary)); 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 a6cd7bc5..029ea652 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,6 +13,7 @@ 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_EXCLUDED_PATHS = "excludedPaths"; private static final String PN_PATH = "path"; private static final String DEFAULT_PATH = "/content"; @@ -29,6 +30,11 @@ public String getSearchPath() { return getProperty(PN_PATH, String.class).orElse(DEFAULT_PATH); } + @Override + public String[] getExcludedPaths() { + return getProperty(PN_EXCLUDED_PATHS, String[].class).orElse(new String[0]); + } + private Optional getProperty(String name, Class clazz){ try(ResourceResolver resourceResolver = repositoryHelper.getServiceResourceResolver()){ return Optional.ofNullable(resourceResolver.getResource(CONFIG_PATH)) 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 b2794a88..76effcb8 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 @@ -184,6 +184,7 @@ private GridResourcesGeneratorImpl getGridResourcesGenerator() throws NoSuchFiel UiConfigService uiConfigService = mock(UiConfigServiceImpl.class); when(uiConfigService.getExcludedLinksPatterns()).thenReturn(new String[0]); when(uiConfigService.getSearchPath()).thenReturn(TEST_FOLDER_PATH); + when(uiConfigService.getExcludedPaths()).thenReturn(new String[0]); PrivateAccessor.setField(gridResourcesGenerator, UI_CONFIG_FIELD, uiConfigService); GridResourcesGeneratorImplTest.setUpConfig(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 874c5028..b5993a7a 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 @@ -141,6 +141,7 @@ void setup() throws NoSuchFieldException { uiConfigService = mock(UiConfigServiceImpl.class); when(uiConfigService.getExcludedLinksPatterns()).thenReturn(new String[0]); when(uiConfigService.getSearchPath()).thenReturn(TEST_FOLDER_PATH); + when(uiConfigService.getExcludedPaths()).thenReturn(new String[]{TEST_EXCLUDED_PATH}); PrivateAccessor.setField(fixture, UI_CONFIG_FIELD, uiConfigService); } @@ -326,9 +327,6 @@ static void setUpConfig(GridResourcesGeneratorImpl gridResourcesGenerator) { int[] defaultStatusCodes = {HttpStatus.SC_NOT_FOUND}; when(config.allowedStatusCodes()).thenReturn(defaultStatusCodes); - String[] excludedPaths = {TEST_EXCLUDED_PATH}; - when(config.excludedPaths()).thenReturn(excludedPaths); - when(config.checkActivation()).thenReturn(false); gridResourcesGenerator.activate(config); @@ -337,7 +335,7 @@ static void setUpConfig(GridResourcesGeneratorImpl gridResourcesGenerator) { private void setUpConfigNoExcludedPaths(GridResourcesGeneratorImpl gridResourcesGenerator) { GridResourcesGeneratorImpl.Configuration config = mockConfig(); - when(config.excludedPaths()).thenReturn(ArrayUtils.EMPTY_STRING_ARRAY); + when(uiConfigService.getExcludedPaths()).thenReturn(ArrayUtils.EMPTY_STRING_ARRAY); int[] defaultStatusCodes = {HttpStatus.SC_NOT_FOUND}; when(config.allowedStatusCodes()).thenReturn(defaultStatusCodes); @@ -354,8 +352,7 @@ private void setUpConfigCheckActivation(GridResourcesGeneratorImpl gridResources int[] defaultStatusCodes = {HttpStatus.SC_NOT_FOUND}; when(config.allowedStatusCodes()).thenReturn(defaultStatusCodes); - String[] excludedPaths = {TEST_EXCLUDED_PATH}; - when(config.excludedPaths()).thenReturn(excludedPaths); + when(uiConfigService.getExcludedPaths()).thenReturn(new String[]{TEST_EXCLUDED_PATH}); gridResourcesGenerator.activate(config); } diff --git a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/css/console-ui.less b/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/css/console-ui.less index 40ba9163..24bd65f3 100644 --- a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/css/console-ui.less +++ b/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/css/console-ui.less @@ -93,3 +93,12 @@ tr.elc-card { font-weight: bold; } } + +#filter-dialog{ + .coral3-Dialog-wrapper{ + min-width: 50rem; + } + .coral3-Multifield{ + min-width: 48rem; + } +} 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 2e6045b5..15aeb7a2 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 @@ -60,45 +60,67 @@ $cancelBtn.appendTo(dialog.footer); $updateBtn.appendTo(dialog.footer); - const filterMultifield = new Coral.Multifield(); - filterMultifield.template.content.appendChild(new Coral.Textfield()); - - const add = new Coral.Button(); - add.label.textContent = 'Add regexp for filtering'; - add.setAttribute('coral-multifield-add', ''); - filterMultifield.appendChild(add); - + const filterMultifield = createMultifield(); + $('

').text("Filter").appendTo(dialog.content); dialog.content.appendChild(filterMultifield); + const $rootPathField = $(''); $('

').text("Path").appendTo(dialog.content); $rootPathField.appendTo(dialog.content); + + const excludedPathsMultifield = createMultifield(); + $('

').text("Excluded Paths").appendTo(dialog.content); + dialog.content.appendChild(excludedPathsMultifield); + $.ajax({ type: "GET", url: "/content/etoolbox-link-inspector/data/config.json" }).done(function (data){ - if (data.filter){ - for (let f of data.filter){ - const item = new Coral.Multifield.Item(); - const textField = new Coral.Textfield(); - textField.value = f; - item.content.appendChild(textField); - filterMultifield.items.add(item); - } - $rootPathField.val(data.path); - } + populateMultifield(filterMultifield, data.filter); + $rootPathField.val(data.path); + populateMultifield(excludedPathsMultifield, data.excludedPaths); }) + function createMultifield(){ + const multifield = new Coral.Multifield(); + multifield.template.content.appendChild(new Coral.Textfield()); + + const add = new Coral.Button(); + add.label.textContent = 'Add'; + add.setAttribute('coral-multifield-add', ''); + multifield.appendChild(add); + return multifield; + } + + function populateMultifield(multifield, data){ + if(!data){ + return; + } + for (let d of data){ + const item = new Coral.Multifield.Item(); + const textField = new Coral.Textfield(); + textField.value = d; + item.content.appendChild(textField); + multifield.items.add(item); + } + } + + function getMultifieldValues(multifield){ + let multifieldValues = multifield.items.getAll().map((item) => item.content.children[0].value); + return !!multifieldValues.length ? multifieldValues : ""; + } + function onSubmit(){ - let filterMultifieldValues = filterMultifield.items.getAll().map((item) => item.content.children[0].value); - filterMultifieldValues = !!filterMultifieldValues.length ? filterMultifieldValues : ""; $.ajax({ type: "POST", url: "/content/etoolbox-link-inspector/data/config", data: { 'jcr:primaryType': "nt:unstructured", - "filter": filterMultifieldValues, + "filter": getMultifieldValues(filterMultifield), "filter@TypeHint": "String[]", - "path": $rootPathField.val() + "path": $rootPathField.val(), + "excludedPaths": getMultifieldValues(excludedPathsMultifield), + "excludedPaths@TypeHint": "String[]", }, dataType: "json", encode: true