From ec8137e8dc30fcbb66ea30bb8d7f213768f675cb Mon Sep 17 00:00:00 2001 From: Mark Rogers Date: Wed, 23 Jul 2014 16:56:36 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud) 77259: Merged PLATFORM1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 76447: SOLR node metadata includes getNamePaths, which is a Collection> - JSON serialization stubbed out; fix TODOs in NodesMetaDataGet to transfer serialize to specification - The name paths are the largest list of names of nodes that culminate in the target node. - The top parent is the last highest parent with a cm:name property - ALL paths are introspected but it does not mean that the node path count will always equal the name path count git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@78115 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/repo/solr/NodeMetaData.java | 9 ++++ .../repo/solr/SOLRTrackingComponentImpl.java | 45 +++++++++++++++++++ .../repo/solr/SOLRTrackingComponentTest.java | 41 ++++++++++++----- 3 files changed, 83 insertions(+), 12 deletions(-) diff --git a/source/java/org/alfresco/repo/solr/NodeMetaData.java b/source/java/org/alfresco/repo/solr/NodeMetaData.java index 8cedb17822..5ee8521518 100644 --- a/source/java/org/alfresco/repo/solr/NodeMetaData.java +++ b/source/java/org/alfresco/repo/solr/NodeMetaData.java @@ -44,6 +44,7 @@ public class NodeMetaData private Map properties; private Set aspects; private Collection> paths; + private Collection> namePaths; private List childAssocs; private List parentAssocs; private Long parentAssocsCrc; @@ -75,6 +76,14 @@ public class NodeMetaData { this.paths = paths; } + public Collection> getNamePaths() + { + return namePaths; + } + public void setNamePaths(Collection> namePaths) + { + this.namePaths = namePaths; + } public QName getNodeType() { return nodeType; diff --git a/source/java/org/alfresco/repo/solr/SOLRTrackingComponentImpl.java b/source/java/org/alfresco/repo/solr/SOLRTrackingComponentImpl.java index 6b96028edd..b3827761b6 100644 --- a/source/java/org/alfresco/repo/solr/SOLRTrackingComponentImpl.java +++ b/source/java/org/alfresco/repo/solr/SOLRTrackingComponentImpl.java @@ -55,6 +55,7 @@ import org.alfresco.service.cmr.repository.InvalidNodeRefException; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef.Status; import org.alfresco.service.cmr.repository.Path; +import org.alfresco.service.cmr.repository.Path.ChildAssocElement; import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; import org.alfresco.service.cmr.security.OwnableService; import org.alfresco.service.cmr.security.PermissionService; @@ -841,6 +842,50 @@ public class SOLRTrackingComponentImpl implements SOLRTrackingComponent } nodeMetaData.setPaths(paths); + + // Calculate name path + Collection> namePaths = new ArrayList>(2); + nodeMetaData.setNamePaths(namePaths); + for (Path path : directPaths) + { + boolean added = false; + List namePath = new ArrayList(path.size()); + for (Path.Element pathElement : path) + { + if (!(pathElement instanceof ChildAssocElement)) + { + // This is some path element that is terminal to a cm:name path + break; + } + ChildAssocElement pathChildAssocElement = (ChildAssocElement) pathElement; + NodeRef childNodeRef = pathChildAssocElement.getRef().getChildRef(); + Pair childNodePair = nodeDAO.getNodePair(childNodeRef); + if (childNodePair == null) + { + // Gone + break; + } + Long childNodeId = childNodePair.getFirst(); + String childNodeName = (String) nodeDAO.getNodeProperty(childNodeId, ContentModel.PROP_NAME); + if (childNodeName == null) + { + // We have hit a non-name node, which acts as a root for cm:name + // DH: There is no particular constraint here. This is just a decision made. + namePath.clear(); + // We have to continue down the path as there could be a name path lower down + continue; + } + // We can finally add the name to the path + namePath.add(childNodeName); + // Add the path if this is the first entry in the name path + if (!added) + { + namePaths.add(namePath); + added = true; + } + } + } + } nodeMetaData.setTenantDomain(tenantService.getDomain(nodeRef.getStoreRef().getIdentifier())); diff --git a/source/test-java/org/alfresco/repo/solr/SOLRTrackingComponentTest.java b/source/test-java/org/alfresco/repo/solr/SOLRTrackingComponentTest.java index f35f321bfe..de6e5c3238 100644 --- a/source/test-java/org/alfresco/repo/solr/SOLRTrackingComponentTest.java +++ b/source/test-java/org/alfresco/repo/solr/SOLRTrackingComponentTest.java @@ -21,7 +21,6 @@ package org.alfresco.repo.solr; import java.io.InputStream; import java.io.Serializable; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -243,6 +242,7 @@ public class SOLRTrackingComponentTest extends TestCase /** * Call {@link SOLRTrackingComponent#getAcls(List, Long, int)} in a transaction */ + @SuppressWarnings("unused") private List getAcls(final List aclChangeSetIds, final Long minAclId, final int maxResults) { RetryingTransactionCallback> callback = new RetryingTransactionCallback>() @@ -959,7 +959,8 @@ public class SOLRTrackingComponentTest extends TestCase } @Override - public boolean handleNodeMetaData(NodeMetaData nodeMetaData) { + public boolean handleNodeMetaData(NodeMetaData nodeMetaData) + { actualNodeMetaDataCount++; if(doMetaDataChecks) @@ -1008,6 +1009,32 @@ public class SOLRTrackingComponentTest extends TestCase // List actualPaths = nodeMetaData.getPaths(); // List expectedPaths = nodeService.getPaths(nodeRef, false); // assertEquals("Paths are incorrect", expectedPaths, actualPaths); + + // Include negative checks i.e. make sure we get null if we do NOT expect paths + boolean expectPaths = assertions.isExpectPaths(); + assertTrue("Expecting paths but didn't get any.", expectPaths == (nodeMetaData.getPaths() != null)); + assertTrue("Expecting name path but didn't get it.", expectPaths == (nodeMetaData.getNamePaths() != null)); + if (expectPaths) + { + // Check QName paths + // TODO: Check paths + // Check name paths + Collection> namePaths = nodeMetaData.getNamePaths(); + if (nodeService.getProperty(nodeRef, ContentModel.PROP_NAME) == null) + { + assertEquals("Expect an empty list where there is no cm:name on the node. ", 0, namePaths.size()); + } + else + { + assertTrue("Expect some name paths for the node. ", namePaths.size() > 0); + // Check that the last entry is the name of the current node + String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); + String namePathStr = namePaths.toString(); + assertTrue( + "Did not find node name at end. Have " + namePathStr + " and wanted to see " + name, + namePathStr.endsWith(name + "]]")); + } + } boolean expectAspects = assertions.isExpectAspects(); if(expectAspects && nodeMetaData.getAspects() == null) @@ -1049,16 +1076,6 @@ public class SOLRTrackingComponentTest extends TestCase fail("Not expecting acl id but got acl id"); } - boolean expectPaths = assertions.isExpectPaths(); - if(expectPaths && nodeMetaData.getPaths() == null) - { - fail("Expecting paths but got no paths"); - } - else if(!expectPaths && nodeMetaData.getPaths() != null) - { - fail("Not expecting paths but got paths"); - } - boolean expectAssociations = assertions.isExpectAssociations(); if(expectAssociations && nodeMetaData.getChildAssocs() == null) {