Skip to content

Commit

Permalink
Merge branch 'release/2.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
ghenzler committed Jan 25, 2018
2 parents 8b9314c + 4c3f31c commit b70a2f4
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 80 deletions.
2 changes: 1 addition & 1 deletion accesscontroltool-bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>biz.netcentric.cq.tools.accesscontroltool</groupId>
<artifactId>accesscontroltool</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
</parent>

<!-- ====================================================================== -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
* @author ghenzler */
public interface YamlMacroChildNodeObjectsProvider {

List<Object> getValuesForPath(String pathOfChildrenOfClause, InstallationLogger history, Session session);
List<Object> getValuesForPath(String pathOfChildrenOfClause, InstallationLogger history, Session session, boolean includeContent);

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public class YamlMacroChildNodeObjectsProviderImpl implements YamlMacroChildNode
private SlingRepository repository;

@Override
public List<Object> getValuesForPath(String pathOfChildrenOfClause, InstallationLogger history, Session session) {
public List<Object> getValuesForPath(String pathOfChildrenOfClause, InstallationLogger history, Session session, boolean includeContent) {

LOG.debug("FOR Loop: Getting children for " + pathOfChildrenOfClause);
LOG.debug("FOR Loop: Getting children for {} with content {}", pathOfChildrenOfClause, includeContent);

List<Object> results = new ArrayList<Object>();

Expand All @@ -71,34 +71,15 @@ public List<Object> getValuesForPath(String pathOfChildrenOfClause, Installation
childNodeObjectForEl.put("path", childNode.getPath());
childNodeObjectForEl.put("primaryType", childNode.getPrimaryNodeType().toString());

try {
if (childNode.hasNode(JcrConstants.JCR_CONTENT)) {
Node jcrContentNode = childNode.getNode(JcrConstants.JCR_CONTENT);

PropertyIterator propertiesIt = jcrContentNode.getProperties();
Map<String, Object> jcrContentSubNode = new HashMap<String, Object>();
while (propertiesIt.hasNext()) {
Property prop = (Property) propertiesIt.next();
if (prop.isMultiple()) {
jcrContentSubNode.put(prop.getName(), valuesToStringArr(prop.getValues()));
} else {
Value value = prop.getValue();
if (isIrrelevantType(value)) {
continue;
}
String strVal = value.getString();
jcrContentSubNode.put(prop.getName(), strVal);

// add the title also to root map to simplify access
if (JcrConstants.JCR_TITLE.equals(prop.getName())) {
childNodeObjectForEl.put("title", strVal);
}
}

if (jcrContentNode.hasProperty(JcrConstants.JCR_TITLE)) {
childNodeObjectForEl.put("title", jcrContentNode.getProperty(JcrConstants.JCR_TITLE).getString());
}
childNodeObjectForEl.put(JcrConstants.JCR_CONTENT, jcrContentSubNode);

} catch (PathNotFoundException epnf) {
LOG.debug("Node " + node.getPath() + " does not have a jcr content node (legitimate for folders)");
Map<String, Object> jcrContentSubNode = getValuesForNode(jcrContentNode, includeContent);
childNodeObjectForEl.put(JcrConstants.JCR_CONTENT, jcrContentSubNode);
}

results.add(childNodeObjectForEl);
Expand All @@ -117,6 +98,34 @@ public List<Object> getValuesForPath(String pathOfChildrenOfClause, Installation
return results;
}

private Map<String, Object> getValuesForNode(Node node, boolean includeChildren) throws RepositoryException {
PropertyIterator propertiesIt = node.getProperties();
Map<String, Object> values = new HashMap<String, Object>();
while (propertiesIt.hasNext()) {
Property prop = (Property) propertiesIt.next();
if (prop.isMultiple()) {
values.put(prop.getName(), valuesToStringArr(prop.getValues()));
} else {
Value value = prop.getValue();
if (isIrrelevantType(value)) {
continue;
}
String strVal = value.getString();
values.put(prop.getName(), strVal);
}
}

if (includeChildren) {
NodeIterator iterator = node.getNodes();
while (iterator.hasNext()) {
Node child = iterator.nextNode();
values.put(child.getName(), getValuesForNode(child, includeChildren));
}
}

return values;
}

private boolean isIrrelevantType(Value value) {
return value.getType() == PropertyType.BINARY
|| value.getType() == PropertyType.REFERENCE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class YamlMacroProcessorImpl implements YamlMacroProcessor {
private static final Logger LOG = LoggerFactory.getLogger(YamlMacroProcessorImpl.class);

private final Pattern forLoopPattern = Pattern.compile(
"for +(\\w+) +in +(?:\\[([,/\\s\\w\\-]+)\\]|children +of +([^\\s]+)|(\\$\\{[^\\}]+\\}))",
"for +(\\w+)( +with +content)? +in +(?:\\[([,/\\s\\w\\-]+)\\]|children +of +([^\\s]+)|(\\$\\{[^\\}]+\\}))",
Pattern.CASE_INSENSITIVE);
private final Pattern ifPattern = Pattern.compile("if +(\\$\\{[^\\}]+\\})", Pattern.CASE_INSENSITIVE);

Expand Down Expand Up @@ -145,17 +145,18 @@ private Object evaluateDefStatement(Map<String, Object> variables, Matcher varia
private Object evaluateForStatement(Map<String, Object> variables, Object objVal, Matcher forMatcher,
InstallationLogger installLog, Session session) {
String varName = StringUtils.trim(forMatcher.group(1));
String valueOfInClause = StringUtils.trim(forMatcher.group(2));
String pathOfChildrenOfClause = StringUtils.trim(forMatcher.group(3));
String variableForInClause = StringUtils.trim(forMatcher.group(4));
String withClause = StringUtils.trim(forMatcher.group(2));
String valueOfInClause = StringUtils.trim(forMatcher.group(3));
String pathOfChildrenOfClause = StringUtils.trim(forMatcher.group(4));
String variableForInClause = StringUtils.trim(forMatcher.group(5));

List<?> iterationValues;
if(valueOfInClause != null) {
iterationValues = Arrays.asList(valueOfInClause.split(COMMA_SEPARATED_LIST_SPLITTER));
} else if(pathOfChildrenOfClause!=null) {
// allow variables in root path also
pathOfChildrenOfClause = elEvaluator.evaluateEl(pathOfChildrenOfClause, String.class, variables);
iterationValues = yamlMacroChildNodeObjectsProvider.getValuesForPath(pathOfChildrenOfClause, installLog, session);
iterationValues = yamlMacroChildNodeObjectsProvider.getValuesForPath(pathOfChildrenOfClause, installLog, session, StringUtils.isNotBlank(withClause));
} else if(variableForInClause!=null) {
iterationValues = elEvaluator.evaluateEl(variableForInClause, List.class, variables);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.slf4j.LoggerFactory;

import biz.netcentric.cq.tools.actool.history.PersistableInstallationLogger;
import biz.netcentric.cq.tools.actool.history.HistoryEntry;
import biz.netcentric.cq.tools.actool.installhook.impl.AcToolInstallHookService;
import biz.netcentric.cq.tools.actool.installhook.impl.OsgiAwareInstallHook;

Expand Down Expand Up @@ -55,16 +54,17 @@ public void execute(InstallContext context) throws PackageException {
throw new PackageException(
"Could not instanciate AceService. Make sure the ACTool is installed and check the log for errors");
}
//

try {
PersistableInstallationLogger history;
try {
history = acService.installYamlFilesFromPackage(context
.getPackage().getArchive(), context.getSession(), context.getOptions().getListener());

} catch (Exception e) {
log("Exception while installing configurations: " + e,
context.getOptions());
// needed as root cause of PackageException is not reliably logged in AEM 6.2
LOG.error("Exception during execution of install hook: " + e, e);
log("Exception while installing configurations: " + e, context.getOptions());
throw new PackageException(e.getMessage(), e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void testLoopChildrenOf() throws IOException, AcConfigBeanValidationExcep
String contentLocationChildrenFromYamlFile = "/content/test";

doReturn(getExampleValuesForLoopOverChildrenOfPath()).when(yamlMacroChildNodeObjectsProvider)
.getValuesForPath(contentLocationChildrenFromYamlFile, installLog, session);
.getValuesForPath(contentLocationChildrenFromYamlFile, installLog, session, false);

yamlList = yamlMacroProcessor.processMacros(yamlList, installLog, session);

Expand All @@ -200,6 +200,33 @@ public void testLoopChildrenOf() throws IOException, AcConfigBeanValidationExcep

}

@Test
public void testLoopChildrenWithContentOf() throws IOException, AcConfigBeanValidationException, RepositoryException {

List<LinkedHashMap> yamlList = getYamlList("test-loop-children-with-content-of.yaml");

String contentLocationChildrenFromYamlFile = "/content/test";

doReturn(getExampleValuesForLoopOverChildrenOfPath()).when(yamlMacroChildNodeObjectsProvider)
.getValuesForPath(contentLocationChildrenFromYamlFile, installLog, session, true);

yamlList = yamlMacroProcessor.processMacros(yamlList, installLog, session);

// new Yaml().dump(yamlList, new PrintWriter(System.out));

AuthorizablesConfig groups = readGroupConfigs(yamlList);
assertEquals(4, groups.size());

AuthorizableConfigBean group1 = groups.getAuthorizableConfig("content-node1-reader");
assertEquals("/home/groups/test", group1.getPath());
assertEquals("Jcr Content Property with deep content subval1", group1.getName());

AuthorizableConfigBean group2 = groups.getAuthorizableConfig("content-node1-writer");
assertEquals("/home/groups/test", group2.getPath());
assertEquals("Writer of Node 1", group2.getName());

}

private List<Object> getExampleValuesForLoopOverChildrenOfPath() {

List<Object> result = new ArrayList<Object>();
Expand All @@ -212,6 +239,11 @@ private List<Object> getExampleValuesForLoopOverChildrenOfPath() {
{
put("jcr:title", "testJcrTitle");
put("prop", "val1");
put("subnode", new HashMap<String, Object>() {
{
put("prop", "subval1");
}
});
}
});
}
Expand All @@ -227,6 +259,11 @@ private List<Object> getExampleValuesForLoopOverChildrenOfPath() {
{
put("jcr:title", "testJcrTitle");
put("prop", "val2");
put("subnode", new HashMap<String, Object>() {
{
put("prop", "subval2");
}
});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# (C) Copyright 2015 Netcentric AG.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#

- group_config:

- FOR childNode WITH CONTENT IN CHILDREN OF /content/test:

- content-${childNode.name}-reader:

- name: Jcr Content Property with deep content ${childNode['jcr:content'].subnode.prop}
isMemberOf:
path: /home/groups/${ split(childNode.path,'/')[1] }

- content-${childNode.name}-writer:

- name: Writer of ${childNode.title}
isMemberOf:
path: /home/groups/${ split(childNode.path,'/')[1] }


2 changes: 1 addition & 1 deletion accesscontroltool-exampleconfig-package/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>biz.netcentric.cq.tools.accesscontroltool</groupId>
<artifactId>accesscontroltool</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
</parent>

<!-- ====================================================================== -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,75 +1,47 @@
# Service users and groups

- group_config:

- system-tags:

- name:
isMemberOf:
members:
path: s


- system-content:

- name:
isMemberOf:
members:
path: s


- system-home:

- name:
isMemberOf:
members:
path: s
# Service users

- user_config:

- system-tags:
- system-user-tags:

- name:
isMemberOf: system-tags
path: s
path: realProject
isSystemUser: true


- system-content:
- system-user-content:

- name:
isMemberOf: system-content
path: s
path: realProject
isSystemUser: true


- system-home:
- system-user-home:

- name:
isMemberOf: system-home
path: s
path: realProject
isSystemUser: true


- ace_config:

- system-tags:
- system-user-tags:

- path: /etc/tags
permission: allow
actions: read
privileges:


- system-content:
- system-user-content:

- path: /content
permission: allow
actions: read
privileges:


- system-home:
- system-user-home:

- path: /home
permission: allow
Expand Down
2 changes: 1 addition & 1 deletion accesscontroltool-oakindex-package/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>biz.netcentric.cq.tools.accesscontroltool</groupId>
<artifactId>accesscontroltool</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
</parent>

<!-- ====================================================================== -->
Expand Down
2 changes: 1 addition & 1 deletion accesscontroltool-package/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>biz.netcentric.cq.tools.accesscontroltool</groupId>
<artifactId>accesscontroltool</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
</parent>

<!-- ====================================================================== -->
Expand Down
Loading

0 comments on commit b70a2f4

Please sign in to comment.