Skip to content

Commit

Permalink
added data source support
Browse files Browse the repository at this point in the history
  • Loading branch information
dprzybyl committed Oct 19, 2023
1 parent ba7e222 commit f789da3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@
import java.util.List;
import org.apache.commons.lang3.NotImplementedException;

@Mapper(value = "TRAVERSE", group = ActionGroup.DATASOURCE)
public class TraverseMapper {
@Mapper(value = "LEVELS", group = ActionGroup.DATASOURCE)
public class LevelsMapper {

@Mapping(
examples = "TRAVERSE('/content', [<br>" +
"&nbsp;&nbsp;&nbsp;&nbsp;{regex: '(.+)_(.+)', paramNames: ['param1', 'param2']},<br>" +
"&nbsp;&nbsp;&nbsp;&nbsp;{excludeRegex: '[^:]+'},<br>" +
"&nbsp;&nbsp;&nbsp;&nbsp;{template: '/apps/test/pageTemplate', resourceType: 'test/pageRenderer'}<br>" +
examples = "LEVELS('/content', [<br>" +
"&nbsp;&nbsp;&nbsp;&nbsp;{regex: '(.+)_(.+)',paramNames: ['param1', 'param2']}, # 1st level<br>" +
"&nbsp;&nbsp;&nbsp;&nbsp;{excludeRegex: '[^:]+'}, # 2nd level<br>" +
"&nbsp;&nbsp;&nbsp;&nbsp;{template: '/apps/test/pageTemplate', resourceType: 'test/pageRenderer'}, # 3rd level<br>" +
"&nbsp;&nbsp;&nbsp;&nbsp;{properties: [ # 4rd level<br>" +
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{name: 'jcr:primaryType', regex: 'cq:Page'},<br>" +
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{name: 'jcr:primaryType', excludeRegex: 'cq:PageContent'},<br>" +
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{name: 'jcr:content/cq:template', regex: '/apps/test/pageTemplate'},<br>" +
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{name: 'jcr:content/sling:resourceType', regex: 'test/pageRenderer'}<br>" +
"&nbsp;&nbsp;&nbsp;&nbsp;]}<br>" +
"])",
reference = "Traverse content structure for given resource path matching given content structure map"
reference = "Provides levels of content for given resource path matching given content structure map"
)
public Action mapAction(
@Required(value = "rootPath", description = "Root path") String rootPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
import org.osgi.service.component.annotations.Component;

@Component
public class TraverseDataSource implements DataSource {
public class LevelsDataSource implements DataSource {

@Override
public String getName() {
return "TRAVERSE";
return "LEVELS";
}

@Override
Expand Down Expand Up @@ -104,7 +104,7 @@ private static class Config {

private final List<String> paramNames;

private final List<ConfigProperty> matchProperties;
private final List<ConfigProperty> properties;

public Config(Map<String, Object> map) {
String regex = (String) map.get("excludeRegex");
Expand All @@ -117,7 +117,7 @@ public Config(Map<String, Object> map) {
if (StringUtils.countMatches(regex, "(") != paramNames.size()) {
throw new IllegalArgumentException("Number of paramNames must match number of regex groups");
}
matchProperties = ((List<Object>) map.getOrDefault("matchProperties", Collections.emptyList()))
properties = ((List<Object>) map.getOrDefault("properties", Collections.emptyList()))
.stream()
.map(it -> (Map<String, Object>) it)
.map(ConfigProperty::new)
Expand Down Expand Up @@ -146,8 +146,8 @@ public boolean isValid(Resource resource) {
result = StringUtils.isEmpty(template) || StringUtils.equals(template, valueMap.get(NameConstants.PN_TEMPLATE, String.class));
result &= StringUtils.isEmpty(resourceType) || StringUtils.equals(resourceType, valueMap.get(ResourceResolver.PROPERTY_RESOURCE_TYPE, String.class));
}
if (result && CollectionUtils.isNotEmpty(matchProperties)) {
result = matchProperties.stream()
if (result && CollectionUtils.isNotEmpty(properties)) {
result = properties.stream()
.allMatch(property -> property.isValid(resource));
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ data class ApmString(val value: String) : ApmType() {
}

override fun prettyPrint(depth: Int, prefixDepth: Int): String {
return "\t".repeat(min(depth, prefixDepth)) + "\"$value\""
return "\t".repeat(min(depth, prefixDepth)) + "'$value'"
}
}

Expand Down

0 comments on commit f789da3

Please sign in to comment.