Skip to content

Commit 53a1ca8

Browse files
committed
refactor
1 parent b533975 commit 53a1ca8

File tree

1 file changed

+17
-10
lines changed
  • app/aem/actions.main/src/main/java/com/cognifide/apm/main/permissions

1 file changed

+17
-10
lines changed

app/aem/actions.main/src/main/java/com/cognifide/apm/main/permissions/Restrictions.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import javax.jcr.Value;
3333
import javax.jcr.ValueFactory;
3434
import javax.jcr.ValueFormatException;
35+
import org.apache.commons.collections4.CollectionUtils;
3536
import org.apache.commons.lang3.StringUtils;
3637

3738
public class Restrictions {
@@ -40,12 +41,14 @@ public class Restrictions {
4041

4142
private static final String REP_GLOB_PROPERTY = "rep:glob";
4243

44+
private static final String REP_GLOBS_PROPERTY = "rep:globs";
45+
4346
private static final String REP_NT_NAMES_PROPERTY = "rep:ntNames";
4447

4548
private static final String REP_ITEM_NAMES_PROPERTY = "rep:itemNames";
4649

4750
private static final Set<String> MULTI_VALUE_REP_PROPERTIES = ImmutableSet.of(
48-
REP_NT_NAMES_PROPERTY, REP_ITEM_NAMES_PROPERTY, "rep:prefixes", "rep:current", "rep:globs",
51+
REP_NT_NAMES_PROPERTY, REP_ITEM_NAMES_PROPERTY, REP_GLOBS_PROPERTY, "rep:prefixes", "rep:current",
4952
"rep:subtrees", "sling:resourceTypes", "sling:resourceTypesWithDescendants"
5053
);
5154

@@ -91,11 +94,15 @@ public Map<String, Value> getSingleValueRestrictions(ValueFactory valueFactory)
9194

9295
private void addRestriction(ValueFactory valueFactory, Map<String, Value> result, String key, String value) throws ValueFormatException {
9396
if (StringUtils.isNotBlank(value)) {
94-
if (REP_GLOB_PROPERTY.equals(key)) {
95-
result.put(key, normalizeGlob(valueFactory));
96-
} else {
97-
result.put(key, valueFactory.createValue(value, determinePropertyType(key)));
98-
}
97+
result.put(key, createValue(valueFactory, key, value));
98+
}
99+
}
100+
101+
private Value createValue(ValueFactory valueFactory, String key, String value) throws ValueFormatException {
102+
if (StringUtils.equalsAny(key, REP_GLOB_PROPERTY, REP_GLOBS_PROPERTY)) {
103+
return normalizeGlob(valueFactory);
104+
} else {
105+
return valueFactory.createValue(value, determinePropertyType(key));
99106
}
100107
}
101108

@@ -125,15 +132,15 @@ public Map<String, Value[]> getMultiValueRestrictions(ValueFactory valueFactory)
125132
}
126133

127134
private void addRestrictions(ValueFactory valueFactory, Map<String, Value[]> result, String key, List<String> names) throws ValueFormatException {
128-
if (names != null && !names.isEmpty()) {
129-
result.put(key, createRestrictions(valueFactory, names, determinePropertyType(key)));
135+
if (!CollectionUtils.isEmpty(names)) {
136+
result.put(key, createRestrictions(valueFactory, key, names));
130137
}
131138
}
132139

133-
private Value[] createRestrictions(ValueFactory valueFactory, List<String> names, int propertyType) throws ValueFormatException {
140+
private Value[] createRestrictions(ValueFactory valueFactory, String key, List<String> names) throws ValueFormatException {
134141
Value[] values = new Value[names.size()];
135142
for (int index = 0; index < names.size(); index++) {
136-
values[index] = valueFactory.createValue(names.get(index), propertyType);
143+
values[index] = createValue(valueFactory, key, names.get(index));
137144
}
138145
return values;
139146
}

0 commit comments

Comments
 (0)