From b2c2e58bbf2e1f12fb5206506f69fa3f33983766 Mon Sep 17 00:00:00 2001 From: Vitali Ihnatsenka Date: Mon, 11 Mar 2024 15:19:16 +0100 Subject: [PATCH] #18 Provide a settings console instead of the OSGi config - activated content --- .../core/services/data/UiConfigService.java | 1 + .../services/data/impl/GridResourcesGeneratorImpl.java | 6 ++---- .../core/services/data/impl/UiConfigServiceImpl.java | 6 ++++++ .../data/impl/GridResourcesGeneratorImplTest.java | 2 +- .../clientlibs/link-inspector-ui/css/console-ui.less | 3 +++ .../link-inspector-ui/js/console-ui.filter.js | 10 ++++++++-- 6 files changed, 21 insertions(+), 7 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 ee3e01d3..88de8a7c 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 @@ -4,4 +4,5 @@ public interface UiConfigService { String[] getExcludedLinksPatterns(); String getSearchPath(); String[] getExcludedPaths(); + boolean isActivatedContent(); } 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 4fe338b1..fe6a35cb 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,7 +176,6 @@ int[] allowedStatusCodes() default { private ExecutorService executorService; - private boolean checkActivation; private boolean skipModifiedAfterActivation; private ZonedDateTime lastModifiedBoundary; private String[] excludedProperties; @@ -193,7 +192,6 @@ int[] allowedStatusCodes() default { @Activate @Modified protected void activate(Configuration configuration) { - checkActivation = configuration.checkActivation(); skipModifiedAfterActivation = configuration.skipModifiedAfterActivation(); lastModifiedBoundary = Optional.of(configuration.lastModifiedBoundary()) .filter(StringUtils::isNotBlank) @@ -414,7 +412,7 @@ private boolean isAllowedErrorCode(int linkStatusCode) { } private boolean isAllowedReplicationStatus(Resource resource) { - if (checkActivation) { + if (uiConfigService.isActivatedContent()) { if (LinkInspectorResourceUtil.isPageOrAsset(resource)) { return isActivatedPageOrAsset(resource); } else { @@ -485,7 +483,7 @@ private Map getGenerationStatsMap(LinksCounter allLinksCounter, ZonedDateTime.now().format(DateTimeFormatter.RFC_1123_DATE_TIME)); 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_CHECK_ACTIVATION, uiConfigService.isActivatedContent()); stats.put(GenerationStatsProps.PN_SKIP_MODIFIED_AFTER_ACTIVATION, skipModifiedAfterActivation); stats.put(GenerationStatsProps.PN_LAST_MODIFIED_BOUNDARY, dateToIsoDateTimeString(lastModifiedBoundary)); stats.put(GenerationStatsProps.PN_EXCLUDED_PROPERTIES, excludedProperties); 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 029ea652..ada48a1d 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 @@ -14,6 +14,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_ACTIVATED_CONTENT = "activatedContent"; private static final String PN_PATH = "path"; private static final String DEFAULT_PATH = "/content"; @@ -35,6 +36,11 @@ public String[] getExcludedPaths() { return getProperty(PN_EXCLUDED_PATHS, String[].class).orElse(new String[0]); } + @Override + public boolean isActivatedContent() { + return getProperty(PN_ACTIVATED_CONTENT, Boolean.class).orElse(false); + } + 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/GridResourcesGeneratorImplTest.java b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImplTest.java index b5993a7a..4a00ffe6 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 @@ -346,13 +346,13 @@ private void setUpConfigNoExcludedPaths(GridResourcesGeneratorImpl gridResources private void setUpConfigCheckActivation(GridResourcesGeneratorImpl gridResourcesGenerator) { GridResourcesGeneratorImpl.Configuration config = mockConfig(); - when(config.checkActivation()).thenReturn(true); when(config.skipModifiedAfterActivation()).thenReturn(true); int[] defaultStatusCodes = {HttpStatus.SC_NOT_FOUND}; when(config.allowedStatusCodes()).thenReturn(defaultStatusCodes); when(uiConfigService.getExcludedPaths()).thenReturn(new String[]{TEST_EXCLUDED_PATH}); + when(uiConfigService.isActivatedContent()).thenReturn(true); 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 24bd65f3..e818e851 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 @@ -101,4 +101,7 @@ tr.elc-card { .coral3-Multifield{ min-width: 48rem; } + .coral3-Checkbox{ + display: block; + } } 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 15aeb7a2..c5a17045 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 @@ -65,13 +65,16 @@ dialog.content.appendChild(filterMultifield); const $rootPathField = $(''); - $('

').text("Path").appendTo(dialog.content); + $('

').text("Path(The content path for searching broken links. The search path should be located under /content)").appendTo(dialog.content); $rootPathField.appendTo(dialog.content); const excludedPathsMultifield = createMultifield(); - $('

').text("Excluded Paths").appendTo(dialog.content); + $('

').text("Excluded Paths(The list of paths excluded from processing. The specified path and all its children are excluded. The excluded path should not end with slash. Can be specified as a regex)").appendTo(dialog.content); dialog.content.appendChild(excludedPathsMultifield); + const $activatedContentCheckbox = $('Activated Content(If checked, links will be retrieved from activated content only)'); + $activatedContentCheckbox.appendTo(dialog.content); + $.ajax({ type: "GET", url: "/content/etoolbox-link-inspector/data/config.json" @@ -79,6 +82,7 @@ populateMultifield(filterMultifield, data.filter); $rootPathField.val(data.path); populateMultifield(excludedPathsMultifield, data.excludedPaths); + $activatedContentCheckbox.attr("checked", data.activatedContent); }) function createMultifield(){ @@ -121,6 +125,8 @@ "path": $rootPathField.val(), "excludedPaths": getMultifieldValues(excludedPathsMultifield), "excludedPaths@TypeHint": "String[]", + "activatedContent":!!$activatedContentCheckbox.attr("checked"), + "activatedContent@TypeHint": "Boolean" }, dataType: "json", encode: true