From 59d59dc289697ebce3bcb5930e69fd51b15791d6 Mon Sep 17 00:00:00 2001 From: Vitali Ihnatsenka Date: Mon, 18 Mar 2024 12:30:49 +0100 Subject: [PATCH] #18 Provide a settings console instead of the OSGi config - Links type --- .../core/services/data/UiConfigService.java | 1 + .../data/impl/GridResourcesGeneratorImpl.java | 18 ++--------- .../data/impl/UiConfigServiceImpl.java | 7 +++++ .../data/impl/DataFeedServiceImplTest.java | 2 ++ .../impl/GridResourcesGeneratorImplTest.java | 2 +- .../link-inspector-ui/css/console-ui.less | 3 ++ .../link-inspector-ui/js/console-ui.filter.js | 31 ++++++++++++++++++- 7 files changed, 46 insertions(+), 18 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 35c5dbad..56dcb26d 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 @@ -10,4 +10,5 @@ public interface UiConfigService { boolean isSkipContentModifiedAfterActivation(); ZonedDateTime getLastModified(); String[] getExcludedProperties(); + String getLinksType(); } 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 77a1da76..be087609 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 @@ -73,19 +73,6 @@ public class GridResourcesGeneratorImpl implements GridResourcesGenerator { description = "Finds broken links under the specified path for further outputting them in a report" ) @interface Configuration { - @AttributeDefinition( - name = "Links type", - description = "The type of links in the report", - options = { - @Option(label = "Internal", value = "INTERNAL"), - @Option(label = "External", value = "EXTERNAL"), - @Option( - label = GenerationStatsProps.REPORT_LINKS_TYPE_ALL, - value = GenerationStatsProps.REPORT_LINKS_TYPE_ALL - ), - } - ) - String linksType() default GenerationStatsProps.REPORT_LINKS_TYPE_ALL; @AttributeDefinition( name = "Excluded links patterns", @@ -127,7 +114,6 @@ int[] allowedStatusCodes() default { private ExecutorService executorService; - private String reportLinksType; private String[] excludedLinksPatterns; private boolean excludeTags; private int[] allowedStatusCodes; @@ -140,7 +126,6 @@ int[] allowedStatusCodes() default { @Activate @Modified protected void activate(Configuration configuration) { - reportLinksType = configuration.linksType(); excludedLinksPatterns = configuration.excludedLinksPatterns(); excludeTags = configuration.excludeTags(); allowedStatusCodes = configuration.allowedStatusCodes(); @@ -316,6 +301,7 @@ private boolean isAllowedLastModifiedDate(Resource resource) { } private boolean isAllowedLinkType(Link link) { + String reportLinksType = uiConfigService.getLinksType(); return GenerationStatsProps.REPORT_LINKS_TYPE_ALL.equals(reportLinksType) || Link.Type.valueOf(reportLinksType) == link.getType(); } @@ -431,7 +417,7 @@ private Map getGenerationStatsMap(LinksCounter allLinksCounter, stats.put(GenerationStatsProps.PN_LAST_MODIFIED_BOUNDARY, dateToIsoDateTimeString(uiConfigService.getLastModified())); stats.put(GenerationStatsProps.PN_EXCLUDED_PROPERTIES, uiConfigService.getExcludedProperties()); - stats.put(GenerationStatsProps.PN_REPORT_LINKS_TYPE, reportLinksType); + stats.put(GenerationStatsProps.PN_REPORT_LINKS_TYPE, uiConfigService.getLinksType()); stats.put(GenerationStatsProps.PN_EXCLUDED_LINK_PATTERNS, getExcludedLinksPatterns()); stats.put(GenerationStatsProps.PN_EXCLUDED_TAGS, excludeTags); stats.put(GenerationStatsProps.PN_ALLOWED_STATUS_CODES, allowedStatusCodes); 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 42c00656..502faf2c 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 @@ -1,5 +1,6 @@ package com.exadel.etoolbox.linkinspector.core.services.data.impl; +import com.exadel.etoolbox.linkinspector.core.services.data.GenerationStatsProps; import com.exadel.etoolbox.linkinspector.core.services.data.UiConfigService; import com.exadel.etoolbox.linkinspector.core.services.helpers.RepositoryHelper; import org.apache.commons.lang3.StringUtils; @@ -22,6 +23,7 @@ public class UiConfigServiceImpl implements UiConfigService { private static final String PN_LAST_MODIFIED = "lastModifiedBoundary"; private static final String PN_PATH = "path"; private static final String PN_EXCLUDED_PROPERTIES = "excludedProperties"; + private static final String PN_LINKS_TYPE = "linksType"; private static final String DEFAULT_PATH = "/content"; @Reference @@ -65,6 +67,11 @@ public String[] getExcludedProperties() { return getProperty(PN_EXCLUDED_PROPERTIES, String[].class).orElse(new String[0]); } + @Override + public String getLinksType() { + return getProperty(PN_LINKS_TYPE, String.class).orElse(GenerationStatsProps.REPORT_LINKS_TYPE_ALL); + } + 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 1fb41ff6..23392e06 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 @@ -15,6 +15,7 @@ package com.exadel.etoolbox.linkinspector.core.services.data.impl; import com.exadel.etoolbox.linkinspector.core.services.ExternalLinkChecker; +import com.exadel.etoolbox.linkinspector.core.services.data.GenerationStatsProps; import com.exadel.etoolbox.linkinspector.core.services.data.UiConfigService; import com.exadel.etoolbox.linkinspector.core.services.helpers.LinkHelper; import com.exadel.etoolbox.linkinspector.core.services.util.CsvUtil; @@ -186,6 +187,7 @@ private GridResourcesGeneratorImpl getGridResourcesGenerator() throws NoSuchFiel when(uiConfigService.getSearchPath()).thenReturn(TEST_FOLDER_PATH); when(uiConfigService.getExcludedPaths()).thenReturn(new String[0]); when(uiConfigService.getExcludedProperties()).thenReturn(new String[0]); + when(uiConfigService.getLinksType()).thenReturn(GenerationStatsProps.REPORT_LINKS_TYPE_ALL); 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 9ba41031..85ed2df6 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 @@ -146,6 +146,7 @@ void setup() throws NoSuchFieldException { when(uiConfigService.getExcludedPaths()).thenReturn(new String[]{TEST_EXCLUDED_PATH}); when(uiConfigService.getLastModified()).thenReturn(TEST_LAST_MODIFIED_BOUNDARY); when(uiConfigService.getExcludedProperties()).thenReturn(new String[]{TEST_EXCLUDED_PROPERTY}); + when(uiConfigService.getLinksType()).thenReturn(GenerationStatsProps.REPORT_LINKS_TYPE_ALL); PrivateAccessor.setField(fixture, UI_CONFIG_FIELD, uiConfigService); } @@ -368,7 +369,6 @@ private void setUpConfigNoStatusCodes(GridResourcesGeneratorImpl gridResourcesGe private static GridResourcesGeneratorImpl.Configuration mockConfig() { GridResourcesGeneratorImpl.Configuration config = mock(GridResourcesGeneratorImpl.Configuration.class); - when(config.linksType()).thenReturn(GenerationStatsProps.REPORT_LINKS_TYPE_ALL); when(config.threadsPerCore()).thenReturn(60); String[] excludedPatterns = {TEST_EXCLUDED_PATTERN}; 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 e818e851..695a1739 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 @@ -104,4 +104,7 @@ tr.elc-card { .coral3-Checkbox{ display: block; } + .coral3-Select{ + 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 d3e59660..1450dfaa 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 @@ -86,6 +86,33 @@ $('

').text("Excluded Properties(The list of properties excluded from processing. Each value can be specified as a regex)").appendTo(dialog.content); dialog.content.appendChild(excludedPropertiesMultifield); + const linksTypeSelect = new Coral.Select().set({ + placeholder: "Choose an item" + }); + linksTypeSelect.items.add({ + content:{ + innerHTML: "Internal + External" + }, + value: "Internal + External", + disabled: false + }); + linksTypeSelect.items.add({ + content:{ + innerHTML: "Internal" + }, + value: "INTERNAL", + disabled: false + }); + linksTypeSelect.items.add({ + content:{ + innerHTML: "External" + }, + value: "EXTERNAL", + disabled: false + }); + $('

').text("Links type(The type of links in the report)").appendTo(dialog.content); + dialog.content.appendChild(linksTypeSelect); + $.ajax({ type: "GET", url: "/content/etoolbox-link-inspector/data/config.json" @@ -97,6 +124,7 @@ $skipContentAfterActivationCheckbox.attr("checked", data.skipContentAfterActivation); $lastModifiedContentField.val(data.lastModifiedBoundary); populateMultifield(excludedPropertiesMultifield, data.excludedProperties); + linksTypeSelect.value = data.linksType; }) function createMultifield(){ @@ -145,7 +173,8 @@ "skipContentAfterActivation@TypeHint": "Boolean", "lastModifiedBoundary": $lastModifiedContentField.val(), "excludedProperties": getMultifieldValues(excludedPropertiesMultifield), - "excludedProperties@TypeHint": "String[]" + "excludedProperties@TypeHint": "String[]", + "linksType": linksTypeSelect.value }, dataType: "json", encode: true