Skip to content

Commit

Permalink
#18 Provide a settings console instead of the OSGi config - Exclude tags
Browse files Browse the repository at this point in the history
  • Loading branch information
vihnatsenka committed Mar 18, 2024
1 parent ef2a137 commit 3477e5c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public interface UiConfigService {
ZonedDateTime getLastModified();
String[] getExcludedProperties();
String getLinksType();
boolean isExcludeTags();
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,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 = "Exclude tags",
description = "If checked, the internal links starting with /content/cq:tags will be excluded"
) boolean excludeTags() default true;

@AttributeDefinition(
name = "Status codes",
Expand Down Expand Up @@ -107,7 +103,6 @@ int[] allowedStatusCodes() default {

private ExecutorService executorService;

private boolean excludeTags;
private int[] allowedStatusCodes;
private int threadsPerCore;

Expand All @@ -118,7 +113,6 @@ int[] allowedStatusCodes() default {
@Activate
@Modified
protected void activate(Configuration configuration) {
excludeTags = configuration.excludeTags();
allowedStatusCodes = configuration.allowedStatusCodes();
threadsPerCore = configuration.threadsPerCore();
}
Expand Down Expand Up @@ -307,7 +301,7 @@ private boolean isExcludedByPattern(String href) {
}

private boolean isExcludedTag(String href) {
return excludeTags && href.startsWith(TAGS_LOCATION);
return uiConfigService.isExcludeTags() && href.startsWith(TAGS_LOCATION);
}

private boolean isExcludedProperty(String propertyName) {
Expand Down Expand Up @@ -410,7 +404,7 @@ private Map<String, Object> getGenerationStatsMap(LinksCounter allLinksCounter,

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_EXCLUDED_TAGS, uiConfigService.isExcludeTags());
stats.put(GenerationStatsProps.PN_ALLOWED_STATUS_CODES, allowedStatusCodes);

stats.put(GenerationStatsProps.PN_ALL_INTERNAL_LINKS, allLinksCounter.getInternalLinks());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class UiConfigServiceImpl implements UiConfigService {
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 PN_EXCLUDE_TAGS = "excludeTags";
private static final String DEFAULT_PATH = "/content";

@Reference
Expand Down Expand Up @@ -72,6 +73,11 @@ public String getLinksType() {
return getProperty(PN_LINKS_TYPE, String.class).orElse(GenerationStatsProps.REPORT_LINKS_TYPE_ALL);
}

@Override
public boolean isExcludeTags() {
return getProperty(PN_EXCLUDE_TAGS, Boolean.class).orElse(true);
}

private <T> Optional<T> getProperty(String name, Class<T> clazz){
try(ResourceResolver resourceResolver = repositoryHelper.getServiceResourceResolver()){
return Optional.ofNullable(resourceResolver.getResource(CONFIG_PATH))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void setup() throws NoSuchFieldException {
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);
when(uiConfigService.isExcludeTags()).thenReturn(true);
PrivateAccessor.setField(fixture, UI_CONFIG_FIELD, uiConfigService);
}

Expand Down Expand Up @@ -370,7 +371,6 @@ private static GridResourcesGeneratorImpl.Configuration mockConfig() {
GridResourcesGeneratorImpl.Configuration config = mock(GridResourcesGeneratorImpl.Configuration.class);

when(config.threadsPerCore()).thenReturn(60);
when(config.excludeTags()).thenReturn(true);

return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@
$('<p>').text("Links type(The type of links in the report)").appendTo(dialog.content);
dialog.content.appendChild(linksTypeSelect);

const $excludeTagsCheckbox = $('<coral-checkbox value="excludeTags">Exclude tags(If checked, the internal links starting with /content/cq:tags will be excluded)</coral-checkbox>');
$excludeTagsCheckbox.appendTo(dialog.content);

$.ajax({
type: "GET",
url: "/content/etoolbox-link-inspector/data/config.json"
Expand All @@ -125,6 +128,7 @@
$lastModifiedContentField.val(data.lastModifiedBoundary);
populateMultifield(excludedPropertiesMultifield, data.excludedProperties);
linksTypeSelect.value = data.linksType;
$excludeTagsCheckbox.attr("checked", data.excludeTags);
})

function createMultifield(){
Expand Down Expand Up @@ -174,7 +178,9 @@
"lastModifiedBoundary": $lastModifiedContentField.val(),
"excludedProperties": getMultifieldValues(excludedPropertiesMultifield),
"excludedProperties@TypeHint": "String[]",
"linksType": linksTypeSelect.value
"linksType": linksTypeSelect.value,
"excludeTags":!!$excludeTagsCheckbox.attr("checked"),
"excludeTags@TypeHint": "Boolean"
},
dataType: "json",
encode: true
Expand Down

0 comments on commit 3477e5c

Please sign in to comment.