use of org.alfresco.service.cmr.repository.Path.ChildAssocElement in project alfresco-repository by Alfresco.
the class PathUtil method getNodeIdsInReverse.
/**
* Return the node ids from the specified node Path, so that
* the first element is the immediate parent.
*
* @param path the node's path object
* @param showLeaf whether to process the final leaf element of the path
* @return list of node ids
*/
public static List<String> getNodeIdsInReverse(Path path, boolean showLeaf) {
int count = path.size() - (showLeaf ? 1 : 2);
if (count < 0) {
return Collections.emptyList();
}
List<String> nodeIds = new ArrayList<>(count);
// Add in reverse order (so the first element is the immediate parent)
for (int i = count; i >= 0; i--) {
Path.Element element = path.get(i);
if (element instanceof ChildAssocElement) {
ChildAssocElement childAssocElem = (ChildAssocElement) element;
NodeRef childNodeRef = childAssocElem.getRef().getChildRef();
nodeIds.add(childNodeRef.getId());
}
}
return nodeIds;
}
use of org.alfresco.service.cmr.repository.Path.ChildAssocElement in project alfresco-repository by Alfresco.
the class AbstractEventsService method getNodeIds.
/**
* For each path, construct a list of ancestor node ids starting with the leaf path element node id first.
*
* @param nodePaths
* @return
*/
protected List<List<String>> getNodeIds(List<Path> nodePaths) {
// TODO use fileFolderService.getNamePath instead?
List<List<String>> pathNodeIds = new ArrayList<List<String>>(nodePaths.size());
for (Path path : nodePaths) {
List<String> nodeIds = new ArrayList<String>(path.size());
// add in reverse order (so the first element is the immediate parent)
for (int i = path.size() - 1; i >= 0; i--) {
Path.Element element = path.get(i);
if (element instanceof ChildAssocElement) {
ChildAssocElement childAssocElem = (ChildAssocElement) element;
NodeRef childNodeRef = childAssocElem.getRef().getChildRef();
nodeIds.add(childNodeRef.getId());
}
}
pathNodeIds.add(nodeIds);
}
return pathNodeIds;
}
use of org.alfresco.service.cmr.repository.Path.ChildAssocElement in project alfresco-repository by Alfresco.
the class VirtualStoreImpl method getPath.
@Override
public Path getPath(Reference reference) throws VirtualizationException {
Reference virtualPathElement = reference;
Reference virtualPathParent = reference.execute(new GetParentReferenceMethod());
Path virtualPath = new Path();
while (virtualPathElement != null && virtualPathParent != null) {
NodeRef parentNodeRef;
parentNodeRef = virtualPathParent.toNodeRef();
NodeRef parent = parentNodeRef;
NodeRef virtualPathNodeRef = virtualPathElement.toNodeRef();
// TODO: extract node reference name into protocol method in order
// to enforce path processing code reuse and consistency
String templatePath = virtualPathElement.execute(new GetTemplatePathMethod()).trim();
final String pathSeparator = "/";
if (pathSeparator.equals(templatePath)) {
// found root
break;
} else if (templatePath.endsWith(pathSeparator)) {
templatePath = templatePath.substring(0, templatePath.length() - 1);
}
int lastSeparator = templatePath.lastIndexOf(pathSeparator);
String childId = templatePath.substring(lastSeparator + 1);
VirtualFolderDefinition structure = resolveVirtualFolderDefinition(virtualPathParent);
VirtualFolderDefinition child = structure.findChildById(childId);
if (child == null) {
throw new VirtualizationException("Invalid reference: " + reference.encode());
}
String childName = child.getName();
QName childQName = QName.createQName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, childName);
ChildAssociationRef assocRef = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, parent, childQName, virtualPathNodeRef, true, -1);
ChildAssocElement assocRefElement = new ChildAssocElement(assocRef);
virtualPath.prepend(assocRefElement);
virtualPathElement = virtualPathParent;
virtualPathParent = virtualPathParent.execute(new GetParentReferenceMethod());
}
return virtualPath;
}
Aggregations