Skip to content

Commit

Permalink
#18 Provide a settings console instead of the OSGi config - Last modi…
Browse files Browse the repository at this point in the history
…fied
  • Loading branch information
vihnatsenka committed Mar 18, 2024
1 parent 7f6850d commit 95ee3dc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.exadel.etoolbox.linkinspector.core.services.data;

import java.time.ZonedDateTime;

public interface UiConfigService {
String[] getExcludedLinksPatterns();
String getSearchPath();
String[] getExcludedPaths();
boolean isActivatedContent();
boolean isSkipContentModifiedAfterActivation();
ZonedDateTime getLastModified();
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ int[] allowedStatusCodes() default {

private ExecutorService executorService;

private ZonedDateTime lastModifiedBoundary;
private String[] excludedProperties;
private String reportLinksType;
private String[] excludedLinksPatterns;
Expand All @@ -191,10 +190,6 @@ int[] allowedStatusCodes() default {
@Activate
@Modified
protected void activate(Configuration configuration) {
lastModifiedBoundary = Optional.of(configuration.lastModifiedBoundary())
.filter(StringUtils::isNotBlank)
.map(dateString -> ZonedDateTime.parse(dateString, DateTimeFormatter.ISO_DATE_TIME))
.orElse(null);
excludedProperties = configuration.excludedProperties();
reportLinksType = configuration.linksType();
excludedLinksPatterns = configuration.excludedLinksPatterns();
Expand Down Expand Up @@ -362,6 +357,7 @@ private boolean isAllowedResource(Resource resource) {
}

private boolean isAllowedLastModifiedDate(Resource resource) {
ZonedDateTime lastModifiedBoundary = uiConfigService.getLastModified();
if (lastModifiedBoundary == null) {
return true;
}
Expand Down Expand Up @@ -483,7 +479,7 @@ private Map<String, Object> getGenerationStatsMap(LinksCounter allLinksCounter,
stats.put(GenerationStatsProps.PN_EXCLUDED_PATHS, uiConfigService.getExcludedPaths());
stats.put(GenerationStatsProps.PN_CHECK_ACTIVATION, uiConfigService.isActivatedContent());
stats.put(GenerationStatsProps.PN_SKIP_MODIFIED_AFTER_ACTIVATION, uiConfigService.isSkipContentModifiedAfterActivation());
stats.put(GenerationStatsProps.PN_LAST_MODIFIED_BOUNDARY, dateToIsoDateTimeString(lastModifiedBoundary));
stats.put(GenerationStatsProps.PN_LAST_MODIFIED_BOUNDARY, dateToIsoDateTimeString(uiConfigService.getLastModified()));
stats.put(GenerationStatsProps.PN_EXCLUDED_PROPERTIES, excludedProperties);

stats.put(GenerationStatsProps.PN_REPORT_LINKS_TYPE, reportLinksType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.exadel.etoolbox.linkinspector.core.services.data.UiConfigService;
import com.exadel.etoolbox.linkinspector.core.services.helpers.RepositoryHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Optional;

@Component(service = UiConfigService.class)
Expand All @@ -16,6 +19,7 @@ public class UiConfigServiceImpl implements UiConfigService {
private static final String PN_EXCLUDED_PATHS = "excludedPaths";
private static final String PN_ACTIVATED_CONTENT = "activatedContent";
private static final String PN_SKIP_CONTENT_AFTER_ACTIVATION = "skipContentAfterActivation";
private static final String PN_LAST_MODIFIED = "lastModifiedBoundary";
private static final String PN_PATH = "path";
private static final String DEFAULT_PATH = "/content";

Expand Down Expand Up @@ -47,6 +51,14 @@ public boolean isSkipContentModifiedAfterActivation() {
return getProperty(PN_SKIP_CONTENT_AFTER_ACTIVATION, Boolean.class).orElse(false);
}

@Override
public ZonedDateTime getLastModified() {
return getProperty(PN_LAST_MODIFIED, String.class)
.filter(StringUtils::isNotBlank)
.map(dateString -> ZonedDateTime.parse(dateString, DateTimeFormatter.ISO_DATE_TIME))
.orElse(null);
}

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 @@ -45,6 +45,8 @@
import java.net.URISyntaxException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -80,7 +82,7 @@ class GridResourcesGeneratorImplTest {
private static final String TEST_RESOURCES_TREE_PATH = "/com/exadel/etoolbox/linkinspector/core/services/data/impl/resources.json";
private static final String TEST_FOLDER_PATH = "/content/test-folder";
private static final String TEST_EXCLUDED_PROPERTY = "excluded_prop";
private static final String TEST_LAST_MODIFIED_BOUNDARY = "2021-04-05T05:00:00Z";
private static final ZonedDateTime TEST_LAST_MODIFIED_BOUNDARY = ZonedDateTime.parse("2021-04-05T05:00:00Z", DateTimeFormatter.ISO_DATE_TIME);
private static final String TEST_EXCLUDED_PATTERN = "/content(.*)/test-exclude-pattern(.*)";
private static final String TEST_UI_EXCLUDED_PATTERN = "/content(.*)/test-link-internal-1$";
private static final String TEST_EXCLUDED_PATH = "/content/test-folder/excluded_by_path";
Expand Down Expand Up @@ -142,6 +144,7 @@ void setup() throws NoSuchFieldException {
when(uiConfigService.getExcludedLinksPatterns()).thenReturn(new String[0]);
when(uiConfigService.getSearchPath()).thenReturn(TEST_FOLDER_PATH);
when(uiConfigService.getExcludedPaths()).thenReturn(new String[]{TEST_EXCLUDED_PATH});
when(uiConfigService.getLastModified()).thenReturn(TEST_LAST_MODIFIED_BOUNDARY);
PrivateAccessor.setField(fixture, UI_CONFIG_FIELD, uiConfigService);
}

Expand Down Expand Up @@ -377,8 +380,6 @@ private static GridResourcesGeneratorImpl.Configuration mockConfig() {
String[] excludedProps = {TEST_EXCLUDED_PROPERTY};
when(config.excludedProperties()).thenReturn(excludedProps);

when(config.lastModifiedBoundary()).thenReturn(TEST_LAST_MODIFIED_BOUNDARY);

String[] excludedPatterns = {TEST_EXCLUDED_PATTERN};
when(config.excludedLinksPatterns()).thenReturn(excludedPatterns);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
const $skipContentAfterActivationCheckbox = $('<coral-checkbox value="skipContentAfterActivation">Skip content modified after activation(Works in conjunction with the \'Activated Content\' checkbox only. If checked, links will be retrieved from activated content that is not modified after activation (lastModified is before lastReplicated))</coral-checkbox>');
$skipContentAfterActivationCheckbox.appendTo(dialog.content);

const $lastModifiedContentField = $('<input is="coral-textfield" class="elc-replacement-input" name="lastMidified" value="" required>');
$('<p>').text("Last Modified (The content modified before the specified date will be excluded. Tha date should has the ISO-like date-time format, such as '2011-12-03T10:15:30+01:00')").appendTo(dialog.content);
$lastModifiedContentField.appendTo(dialog.content);

$.ajax({
type: "GET",
url: "/content/etoolbox-link-inspector/data/config.json"
Expand All @@ -87,6 +91,7 @@
populateMultifield(excludedPathsMultifield, data.excludedPaths);
$activatedContentCheckbox.attr("checked", data.activatedContent);
$skipContentAfterActivationCheckbox.attr("checked", data.skipContentAfterActivation);
$lastModifiedContentField.val(data.lastModifiedBoundary);
})

function createMultifield(){
Expand Down Expand Up @@ -132,7 +137,8 @@
"activatedContent":!!$activatedContentCheckbox.attr("checked"),
"activatedContent@TypeHint": "Boolean",
"skipContentAfterActivation":!!$skipContentAfterActivationCheckbox.attr("checked"),
"skipContentAfterActivation@TypeHint": "Boolean"
"skipContentAfterActivation@TypeHint": "Boolean",
"lastModifiedBoundary": $lastModifiedContentField.val()
},
dataType: "json",
encode: true
Expand Down

0 comments on commit 95ee3dc

Please sign in to comment.