Skip to content

Commit 3fc6671

Browse files
committed
added data source support
1 parent 89966c5 commit 3fc6671

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/internal/datasources/LevelsMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class LevelsMapper {
3333
@Mapping(
3434
examples = "LEVELS('/content', [\n" +
3535
"\t{regex: '(.+)_(.+)',paramNames: ['param1', 'param2']}, # 1st level\n" +
36-
"\t{excludeRegex: '[^:]+'}, # 2nd level\n" +
36+
"\t{excludeRegex: '.+:.+'}, # 2nd level\n" +
3737
"\t{template: '/apps/test/pageTemplate', resourceType: 'test/pageRenderer'}, # 3rd level\n" +
3838
"\t{properties: [ # 4th level\n" +
3939
"\t\t{name: 'jcr:primaryType', regex: 'cq:Page'},\n" +

app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/internal/datasources/ValueMapMapper.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.cognifide.apm.api.actions.annotations.Mapping;
2525
import com.cognifide.apm.api.actions.annotations.Required;
2626
import com.cognifide.apm.main.actions.ActionGroup;
27+
import java.util.Map;
2728
import org.apache.commons.lang3.NotImplementedException;
2829

2930
@Mapper(value = "VALUEMAP", group = ActionGroup.DATASOURCE)
@@ -39,12 +40,15 @@ public Action mapAction(
3940
}
4041

4142
@Mapping(
42-
examples = "VALUEMAP('/content/dam', '[^:]+')",
43-
reference = "Provides value map with properties which matching given regex for given resource path"
43+
examples = "VALUEMAP('/content/dam', {\n" +
44+
"\tregex: 'prop.+',\n" +
45+
"\texcludeRegex: '.+:.+'\n" +
46+
"})",
47+
reference = "Provides value map with properties which matching given regex expressions for given resource path"
4448
)
4549
public Action mapAction(
4650
@Required(value = "path", description = "Resource path") String path,
47-
@Required(value = "regex", description = "Regex expression") String regex) {
51+
@Required(value = "regexMap", description = "Map of regex expressions") Map<String, String> regex) {
4852
throw new NotImplementedException("");
4953
}
5054
}

app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/ValueMapDataSource.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.InputStream;
3030
import java.util.Arrays;
3131
import java.util.Calendar;
32+
import java.util.Collections;
3233
import java.util.List;
3334
import java.util.Map;
3435
import java.util.regex.Pattern;
@@ -50,8 +51,11 @@ public String getName() {
5051
@Override
5152
public ApmType determine(ResourceResolver resolver, List<Object> parameters) {
5253
String path = (String) parameters.get(0);
53-
String regex = parameters.size() > 1 ? (String) parameters.get(1) : null;
54+
Map<String, String> regexMap = parameters.size() > 1 ? (Map<String, String>) parameters.get(1) : Collections.emptyMap();
55+
String regex = regexMap.get("regex");
5456
Pattern pattern = StringUtils.isNotEmpty(regex) ? Pattern.compile(regex) : null;
57+
String excludeRegex = regexMap.get("excludeRegex");
58+
Pattern excludePattern = StringUtils.isNotEmpty(excludeRegex) ? Pattern.compile(excludeRegex) : null;
5559
Resource resource = resolver.getResource(path);
5660
if (resource == null) {
5761
return new ApmEmpty();
@@ -60,6 +64,7 @@ public ApmType determine(ResourceResolver resolver, List<Object> parameters) {
6064
Map<String, ApmType> map = valueMap.entrySet()
6165
.stream()
6266
.filter(entry -> pattern == null || pattern.matcher(entry.getKey()).matches())
67+
.filter(entry -> excludePattern == null || !excludePattern.matcher(entry.getKey()).matches())
6368
.map(entry -> new ApmPair(entry.getKey(), determineValue(entry.getValue())))
6469
.collect(Collectors.toMap(ApmPair::getKey, ApmPair::getValue));
6570
return new ApmMap(map);

0 commit comments

Comments
 (0)