Skip to content

Commit

Permalink
#18 Provide a settings console instead of the OSGi config - Links type
Browse files Browse the repository at this point in the history
  • Loading branch information
vihnatsenka committed Mar 18, 2024
1 parent 0c83abf commit 59d59dc
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public interface UiConfigService {
boolean isSkipContentModifiedAfterActivation();
ZonedDateTime getLastModified();
String[] getExcludedProperties();
String getLinksType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -127,7 +114,6 @@ int[] allowedStatusCodes() default {

private ExecutorService executorService;

private String reportLinksType;
private String[] excludedLinksPatterns;
private boolean excludeTags;
private int[] allowedStatusCodes;
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -431,7 +417,7 @@ private Map<String, Object> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 <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 @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,7 @@ tr.elc-card {
.coral3-Checkbox{
display: block;
}
.coral3-Select{
min-width: 48rem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,33 @@
$('<p>').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
});
$('<p>').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"
Expand All @@ -97,6 +124,7 @@
$skipContentAfterActivationCheckbox.attr("checked", data.skipContentAfterActivation);
$lastModifiedContentField.val(data.lastModifiedBoundary);
populateMultifield(excludedPropertiesMultifield, data.excludedProperties);
linksTypeSelect.value = data.linksType;
})

function createMultifield(){
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 59d59dc

Please sign in to comment.