Skip to content

Commit

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

private ExecutorService executorService;

private String searchPath;
private String[] excludedPaths;
private boolean checkActivation;
private boolean skipModifiedAfterActivation;
private ZonedDateTime lastModifiedBoundary;
Expand All @@ -195,8 +193,6 @@ int[] allowedStatusCodes() default {
@Activate
@Modified
protected void activate(Configuration configuration) {
searchPath = uiConfigService.getSearchPath();
excludedPaths = configuration.excludedPaths();
checkActivation = configuration.checkActivation();
skipModifiedAfterActivation = configuration.skipModifiedAfterActivation();
lastModifiedBoundary = Optional.of(configuration.lastModifiedBoundary())
Expand All @@ -216,8 +212,8 @@ protected void activate(Configuration configuration) {
*/
@Override
public List<GridResource> generateGridResources(String gridResourceType, ResourceResolver resourceResolver) {
uiConfigService.getExcludedLinksPatterns();
StopWatch stopWatch = StopWatch.createStarted();
String searchPath = uiConfigService.getSearchPath();
LOG.debug("Start broken links collecting, path: {}", searchPath);

Resource rootResource = resourceResolver.getResource(searchPath);
Expand Down Expand Up @@ -401,7 +397,7 @@ private boolean isExcludedProperty(String propertyName) {
}

private boolean isExcludedPath(String path) {
return isStringMatchAnyPattern(path, excludedPaths);
return isStringMatchAnyPattern(path, uiConfigService.getExcludedPaths());
}

private boolean isAllowedErrorCode(int linkStatusCode) {
Expand Down Expand Up @@ -487,8 +483,8 @@ private Map<String, Object> getGenerationStatsMap(LinksCounter allLinksCounter,

stats.put(GenerationStatsProps.PN_LAST_GENERATED,
ZonedDateTime.now().format(DateTimeFormatter.RFC_1123_DATE_TIME));
stats.put(GenerationStatsProps.PN_SEARCH_PATH, searchPath);
stats.put(GenerationStatsProps.PN_EXCLUDED_PATHS, excludedPaths);
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_SKIP_MODIFIED_AFTER_ACTIVATION, skipModifiedAfterActivation);
stats.put(GenerationStatsProps.PN_LAST_MODIFIED_BOUNDARY, dateToIsoDateTimeString(lastModifiedBoundary));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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_PATH = "path";
private static final String DEFAULT_PATH = "/content";

Expand All @@ -29,6 +30,11 @@ public String getSearchPath() {
return getProperty(PN_PATH, String.class).orElse(DEFAULT_PATH);
}

@Override
public String[] getExcludedPaths() {
return getProperty(PN_EXCLUDED_PATHS, String[].class).orElse(new String[0]);
}

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 @@ -184,6 +184,7 @@ private GridResourcesGeneratorImpl getGridResourcesGenerator() throws NoSuchFiel
UiConfigService uiConfigService = mock(UiConfigServiceImpl.class);
when(uiConfigService.getExcludedLinksPatterns()).thenReturn(new String[0]);
when(uiConfigService.getSearchPath()).thenReturn(TEST_FOLDER_PATH);
when(uiConfigService.getExcludedPaths()).thenReturn(new String[0]);
PrivateAccessor.setField(gridResourcesGenerator, UI_CONFIG_FIELD, uiConfigService);
GridResourcesGeneratorImplTest.setUpConfig(gridResourcesGenerator);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ void setup() throws NoSuchFieldException {
uiConfigService = mock(UiConfigServiceImpl.class);
when(uiConfigService.getExcludedLinksPatterns()).thenReturn(new String[0]);
when(uiConfigService.getSearchPath()).thenReturn(TEST_FOLDER_PATH);
when(uiConfigService.getExcludedPaths()).thenReturn(new String[]{TEST_EXCLUDED_PATH});
PrivateAccessor.setField(fixture, UI_CONFIG_FIELD, uiConfigService);
}

Expand Down Expand Up @@ -326,9 +327,6 @@ static void setUpConfig(GridResourcesGeneratorImpl gridResourcesGenerator) {
int[] defaultStatusCodes = {HttpStatus.SC_NOT_FOUND};
when(config.allowedStatusCodes()).thenReturn(defaultStatusCodes);

String[] excludedPaths = {TEST_EXCLUDED_PATH};
when(config.excludedPaths()).thenReturn(excludedPaths);

when(config.checkActivation()).thenReturn(false);

gridResourcesGenerator.activate(config);
Expand All @@ -337,7 +335,7 @@ static void setUpConfig(GridResourcesGeneratorImpl gridResourcesGenerator) {
private void setUpConfigNoExcludedPaths(GridResourcesGeneratorImpl gridResourcesGenerator) {
GridResourcesGeneratorImpl.Configuration config = mockConfig();

when(config.excludedPaths()).thenReturn(ArrayUtils.EMPTY_STRING_ARRAY);
when(uiConfigService.getExcludedPaths()).thenReturn(ArrayUtils.EMPTY_STRING_ARRAY);

int[] defaultStatusCodes = {HttpStatus.SC_NOT_FOUND};
when(config.allowedStatusCodes()).thenReturn(defaultStatusCodes);
Expand All @@ -354,8 +352,7 @@ private void setUpConfigCheckActivation(GridResourcesGeneratorImpl gridResources
int[] defaultStatusCodes = {HttpStatus.SC_NOT_FOUND};
when(config.allowedStatusCodes()).thenReturn(defaultStatusCodes);

String[] excludedPaths = {TEST_EXCLUDED_PATH};
when(config.excludedPaths()).thenReturn(excludedPaths);
when(uiConfigService.getExcludedPaths()).thenReturn(new String[]{TEST_EXCLUDED_PATH});

gridResourcesGenerator.activate(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,12 @@ tr.elc-card {
font-weight: bold;
}
}

#filter-dialog{
.coral3-Dialog-wrapper{
min-width: 50rem;
}
.coral3-Multifield{
min-width: 48rem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,45 +60,67 @@
$cancelBtn.appendTo(dialog.footer);
$updateBtn.appendTo(dialog.footer);

const filterMultifield = new Coral.Multifield();
filterMultifield.template.content.appendChild(new Coral.Textfield());

const add = new Coral.Button();
add.label.textContent = 'Add regexp for filtering';
add.setAttribute('coral-multifield-add', '');
filterMultifield.appendChild(add);

const filterMultifield = createMultifield();
$('<p>').text("Filter").appendTo(dialog.content);
dialog.content.appendChild(filterMultifield);

const $rootPathField = $('<input is="coral-textfield" class="elc-replacement-input" name="replacement" value="" required>');
$('<p>').text("Path").appendTo(dialog.content);
$rootPathField.appendTo(dialog.content);

const excludedPathsMultifield = createMultifield();
$('<p>').text("Excluded Paths").appendTo(dialog.content);
dialog.content.appendChild(excludedPathsMultifield);

$.ajax({
type: "GET",
url: "/content/etoolbox-link-inspector/data/config.json"
}).done(function (data){
if (data.filter){
for (let f of data.filter){
const item = new Coral.Multifield.Item();
const textField = new Coral.Textfield();
textField.value = f;
item.content.appendChild(textField);
filterMultifield.items.add(item);
}
$rootPathField.val(data.path);
}
populateMultifield(filterMultifield, data.filter);
$rootPathField.val(data.path);
populateMultifield(excludedPathsMultifield, data.excludedPaths);
})

function createMultifield(){
const multifield = new Coral.Multifield();
multifield.template.content.appendChild(new Coral.Textfield());

const add = new Coral.Button();
add.label.textContent = 'Add';
add.setAttribute('coral-multifield-add', '');
multifield.appendChild(add);
return multifield;
}

function populateMultifield(multifield, data){
if(!data){
return;
}
for (let d of data){
const item = new Coral.Multifield.Item();
const textField = new Coral.Textfield();
textField.value = d;
item.content.appendChild(textField);
multifield.items.add(item);
}
}

function getMultifieldValues(multifield){
let multifieldValues = multifield.items.getAll().map((item) => item.content.children[0].value);
return !!multifieldValues.length ? multifieldValues : "";
}

function onSubmit(){
let filterMultifieldValues = filterMultifield.items.getAll().map((item) => item.content.children[0].value);
filterMultifieldValues = !!filterMultifieldValues.length ? filterMultifieldValues : "";
$.ajax({
type: "POST",
url: "/content/etoolbox-link-inspector/data/config",
data: {
'jcr:primaryType': "nt:unstructured",
"filter": filterMultifieldValues,
"filter": getMultifieldValues(filterMultifield),
"filter@TypeHint": "String[]",
"path": $rootPathField.val()
"path": $rootPathField.val(),
"excludedPaths": getMultifieldValues(excludedPathsMultifield),
"excludedPaths@TypeHint": "String[]",
},
dataType: "json",
encode: true
Expand Down

0 comments on commit b1d158f

Please sign in to comment.