From 95ee3dce0edd3c4f7736936a092d93f2d0ef7eb0 Mon Sep 17 00:00:00 2001 From: Vitali Ihnatsenka Date: Mon, 18 Mar 2024 11:12:52 +0100 Subject: [PATCH] #18 Provide a settings console instead of the OSGi config - Last modified --- .../core/services/data/UiConfigService.java | 3 +++ .../data/impl/GridResourcesGeneratorImpl.java | 8 ++------ .../core/services/data/impl/UiConfigServiceImpl.java | 12 ++++++++++++ .../data/impl/GridResourcesGeneratorImplTest.java | 7 ++++--- .../link-inspector-ui/js/console-ui.filter.js | 8 +++++++- 5 files changed, 28 insertions(+), 10 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 3f024ed9..cfedb47e 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 @@ -1,9 +1,12 @@ package com.exadel.etoolbox.linkinspector.core.services.data; +import java.time.ZonedDateTime; + public interface UiConfigService { String[] getExcludedLinksPatterns(); String getSearchPath(); String[] getExcludedPaths(); boolean isActivatedContent(); boolean isSkipContentModifiedAfterActivation(); + ZonedDateTime getLastModified(); } 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 f8bcfc73..8bb3275f 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 ZonedDateTime lastModifiedBoundary; private String[] excludedProperties; private String reportLinksType; private String[] excludedLinksPatterns; @@ -191,10 +190,6 @@ int[] allowedStatusCodes() default { @Activate @Modified protected void activate(Configuration configuration) { - lastModifiedBoundary = Optional.of(configuration.lastModifiedBoundary()) - .filter(StringUtils::isNotBlank) - .map(dateString -> ZonedDateTime.parse(dateString, DateTimeFormatter.ISO_DATE_TIME)) - .orElse(null); excludedProperties = configuration.excludedProperties(); reportLinksType = configuration.linksType(); excludedLinksPatterns = configuration.excludedLinksPatterns(); @@ -362,6 +357,7 @@ private boolean isAllowedResource(Resource resource) { } private boolean isAllowedLastModifiedDate(Resource resource) { + ZonedDateTime lastModifiedBoundary = uiConfigService.getLastModified(); if (lastModifiedBoundary == null) { return true; } @@ -483,7 +479,7 @@ private Map getGenerationStatsMap(LinksCounter allLinksCounter, stats.put(GenerationStatsProps.PN_EXCLUDED_PATHS, uiConfigService.getExcludedPaths()); stats.put(GenerationStatsProps.PN_CHECK_ACTIVATION, uiConfigService.isActivatedContent()); stats.put(GenerationStatsProps.PN_SKIP_MODIFIED_AFTER_ACTIVATION, uiConfigService.isSkipContentModifiedAfterActivation()); - stats.put(GenerationStatsProps.PN_LAST_MODIFIED_BOUNDARY, dateToIsoDateTimeString(lastModifiedBoundary)); + stats.put(GenerationStatsProps.PN_LAST_MODIFIED_BOUNDARY, dateToIsoDateTimeString(uiConfigService.getLastModified())); stats.put(GenerationStatsProps.PN_EXCLUDED_PROPERTIES, excludedProperties); stats.put(GenerationStatsProps.PN_REPORT_LINKS_TYPE, reportLinksType); 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 539ca229..c5c83960 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 @@ -2,11 +2,14 @@ import com.exadel.etoolbox.linkinspector.core.services.data.UiConfigService; import com.exadel.etoolbox.linkinspector.core.services.helpers.RepositoryHelper; +import org.apache.commons.lang3.StringUtils; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.Optional; @Component(service = UiConfigService.class) @@ -16,6 +19,7 @@ public class UiConfigServiceImpl implements UiConfigService { private static final String PN_EXCLUDED_PATHS = "excludedPaths"; private static final String PN_ACTIVATED_CONTENT = "activatedContent"; private static final String PN_SKIP_CONTENT_AFTER_ACTIVATION = "skipContentAfterActivation"; + private static final String PN_LAST_MODIFIED = "lastModifiedBoundary"; private static final String PN_PATH = "path"; private static final String DEFAULT_PATH = "/content"; @@ -47,6 +51,14 @@ public boolean isSkipContentModifiedAfterActivation() { return getProperty(PN_SKIP_CONTENT_AFTER_ACTIVATION, Boolean.class).orElse(false); } + @Override + public ZonedDateTime getLastModified() { + return getProperty(PN_LAST_MODIFIED, String.class) + .filter(StringUtils::isNotBlank) + .map(dateString -> ZonedDateTime.parse(dateString, DateTimeFormatter.ISO_DATE_TIME)) + .orElse(null); + } + 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 af55b1c5..2ea15abb 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 @@ -45,6 +45,8 @@ import java.net.URISyntaxException; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -80,7 +82,7 @@ class GridResourcesGeneratorImplTest { private static final String TEST_RESOURCES_TREE_PATH = "/com/exadel/etoolbox/linkinspector/core/services/data/impl/resources.json"; private static final String TEST_FOLDER_PATH = "/content/test-folder"; private static final String TEST_EXCLUDED_PROPERTY = "excluded_prop"; - private static final String TEST_LAST_MODIFIED_BOUNDARY = "2021-04-05T05:00:00Z"; + private static final ZonedDateTime TEST_LAST_MODIFIED_BOUNDARY = ZonedDateTime.parse("2021-04-05T05:00:00Z", DateTimeFormatter.ISO_DATE_TIME); private static final String TEST_EXCLUDED_PATTERN = "/content(.*)/test-exclude-pattern(.*)"; private static final String TEST_UI_EXCLUDED_PATTERN = "/content(.*)/test-link-internal-1$"; private static final String TEST_EXCLUDED_PATH = "/content/test-folder/excluded_by_path"; @@ -142,6 +144,7 @@ void setup() throws NoSuchFieldException { when(uiConfigService.getExcludedLinksPatterns()).thenReturn(new String[0]); when(uiConfigService.getSearchPath()).thenReturn(TEST_FOLDER_PATH); when(uiConfigService.getExcludedPaths()).thenReturn(new String[]{TEST_EXCLUDED_PATH}); + when(uiConfigService.getLastModified()).thenReturn(TEST_LAST_MODIFIED_BOUNDARY); PrivateAccessor.setField(fixture, UI_CONFIG_FIELD, uiConfigService); } @@ -377,8 +380,6 @@ private static GridResourcesGeneratorImpl.Configuration mockConfig() { String[] excludedProps = {TEST_EXCLUDED_PROPERTY}; when(config.excludedProperties()).thenReturn(excludedProps); - when(config.lastModifiedBoundary()).thenReturn(TEST_LAST_MODIFIED_BOUNDARY); - String[] excludedPatterns = {TEST_EXCLUDED_PATTERN}; when(config.excludedLinksPatterns()).thenReturn(excludedPatterns); 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 96ee5384..064ff563 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 @@ -78,6 +78,10 @@ const $skipContentAfterActivationCheckbox = $('Skip content modified after activation(Works in conjunction with the \'Activated Content\' checkbox only. If checked, links will be retrieved from activated content that is not modified after activation (lastModified is before lastReplicated))'); $skipContentAfterActivationCheckbox.appendTo(dialog.content); + const $lastModifiedContentField = $(''); + $('

').text("Last Modified (The content modified before the specified date will be excluded. Tha date should has the ISO-like date-time format, such as '2011-12-03T10:15:30+01:00')").appendTo(dialog.content); + $lastModifiedContentField.appendTo(dialog.content); + $.ajax({ type: "GET", url: "/content/etoolbox-link-inspector/data/config.json" @@ -87,6 +91,7 @@ populateMultifield(excludedPathsMultifield, data.excludedPaths); $activatedContentCheckbox.attr("checked", data.activatedContent); $skipContentAfterActivationCheckbox.attr("checked", data.skipContentAfterActivation); + $lastModifiedContentField.val(data.lastModifiedBoundary); }) function createMultifield(){ @@ -132,7 +137,8 @@ "activatedContent":!!$activatedContentCheckbox.attr("checked"), "activatedContent@TypeHint": "Boolean", "skipContentAfterActivation":!!$skipContentAfterActivationCheckbox.attr("checked"), - "skipContentAfterActivation@TypeHint": "Boolean" + "skipContentAfterActivation@TypeHint": "Boolean", + "lastModifiedBoundary": $lastModifiedContentField.val() }, dataType: "json", encode: true