Skip to content

Commit

Permalink
#18 Provide a settings console instead of the OSGi config - activated…
Browse files Browse the repository at this point in the history
… content
  • Loading branch information
vihnatsenka committed Mar 11, 2024
1 parent b1d158f commit b2c2e58
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public interface UiConfigService {
String[] getExcludedLinksPatterns();
String getSearchPath();
String[] getExcludedPaths();
boolean isActivatedContent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ int[] allowedStatusCodes() default {

private ExecutorService executorService;

private boolean checkActivation;
private boolean skipModifiedAfterActivation;
private ZonedDateTime lastModifiedBoundary;
private String[] excludedProperties;
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -485,7 +483,7 @@ private Map<String, Object> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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 <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 @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@ tr.elc-card {
.coral3-Multifield{
min-width: 48rem;
}
.coral3-Checkbox{
display: block;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,24 @@
dialog.content.appendChild(filterMultifield);

const $rootPathField = $('<input is="coral-textfield" class="elc-replacement-input" name="replacement" value="" required>');
$('<p>').text("Path").appendTo(dialog.content);
$('<p>').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();
$('<p>').text("Excluded Paths").appendTo(dialog.content);
$('<p>').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 = $('<coral-checkbox value="activatedContent">Activated Content(If checked, links will be retrieved from activated content only)</coral-checkbox>');
$activatedContentCheckbox.appendTo(dialog.content);

$.ajax({
type: "GET",
url: "/content/etoolbox-link-inspector/data/config.json"
}).done(function (data){
populateMultifield(filterMultifield, data.filter);
$rootPathField.val(data.path);
populateMultifield(excludedPathsMultifield, data.excludedPaths);
$activatedContentCheckbox.attr("checked", data.activatedContent);
})

function createMultifield(){
Expand Down Expand Up @@ -121,6 +125,8 @@
"path": $rootPathField.val(),
"excludedPaths": getMultifieldValues(excludedPathsMultifield),
"excludedPaths@TypeHint": "String[]",
"activatedContent":!!$activatedContentCheckbox.attr("checked"),
"activatedContent@TypeHint": "Boolean"
},
dataType: "json",
encode: true
Expand Down

0 comments on commit b2c2e58

Please sign in to comment.