Search in sources :

Example 1 with GetTemplatePathMethod

use of org.alfresco.repo.virtual.ref.GetTemplatePathMethod in project alfresco-repository by Alfresco.

the class ApplyTemplateMethod method execute.

public VirtualFolderDefinition execute(VirtualProtocol virtualProtocol, Reference reference, VirtualContext context) throws ProtocolMethodException {
    Resource resource = reference.getResource();
    try {
        VirtualFolderDefinition theStructure = resource.processWith(new TemplateResourceProcessor(context));
        String path = reference.execute(new GetTemplatePathMethod());
        if (!path.isEmpty()) {
            String[] pathElements = path.split(PATH_SEPARATOR);
            int startIndex = path.startsWith(PATH_SEPARATOR) ? 1 : 0;
            for (int i = startIndex; i < pathElements.length; i++) {
                theStructure = theStructure.findChildById(pathElements[i]);
                if (theStructure == null) {
                    throw new ProtocolMethodException("Invalid template path in " + reference.toString());
                }
            }
        }
        return theStructure;
    } catch (ResourceProcessingError e) {
        throw new ProtocolMethodException(e);
    }
}
Also used : ResourceProcessingError(org.alfresco.repo.virtual.ref.ResourceProcessingError) ProtocolMethodException(org.alfresco.repo.virtual.ref.ProtocolMethodException) GetTemplatePathMethod(org.alfresco.repo.virtual.ref.GetTemplatePathMethod) Resource(org.alfresco.repo.virtual.ref.Resource)

Example 2 with GetTemplatePathMethod

use of org.alfresco.repo.virtual.ref.GetTemplatePathMethod 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;
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) Path(org.alfresco.service.cmr.repository.Path) NodeRef(org.alfresco.service.cmr.repository.NodeRef) GetTemplatePathMethod(org.alfresco.repo.virtual.ref.GetTemplatePathMethod) ChildAssocElement(org.alfresco.service.cmr.repository.Path.ChildAssocElement) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NamePatternPropertyValueConstraint(org.alfresco.repo.virtual.template.NamePatternPropertyValueConstraint) PropertyValueConstraint(org.alfresco.repo.virtual.template.PropertyValueConstraint) FilesFoldersConstraint(org.alfresco.repo.virtual.template.FilesFoldersConstraint) VirtualQueryConstraint(org.alfresco.repo.virtual.template.VirtualQueryConstraint) BasicConstraint(org.alfresco.repo.virtual.template.BasicConstraint) VirtualFolderDefinition(org.alfresco.repo.virtual.template.VirtualFolderDefinition) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException)

Aggregations

GetTemplatePathMethod (org.alfresco.repo.virtual.ref.GetTemplatePathMethod)2 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)1 VirtualizationException (org.alfresco.repo.virtual.VirtualizationException)1 GetParentReferenceMethod (org.alfresco.repo.virtual.ref.GetParentReferenceMethod)1 ProtocolMethodException (org.alfresco.repo.virtual.ref.ProtocolMethodException)1 Reference (org.alfresco.repo.virtual.ref.Reference)1 Resource (org.alfresco.repo.virtual.ref.Resource)1 ResourceProcessingError (org.alfresco.repo.virtual.ref.ResourceProcessingError)1 BasicConstraint (org.alfresco.repo.virtual.template.BasicConstraint)1 FilesFoldersConstraint (org.alfresco.repo.virtual.template.FilesFoldersConstraint)1 NamePatternPropertyValueConstraint (org.alfresco.repo.virtual.template.NamePatternPropertyValueConstraint)1 PropertyValueConstraint (org.alfresco.repo.virtual.template.PropertyValueConstraint)1 VirtualFolderDefinition (org.alfresco.repo.virtual.template.VirtualFolderDefinition)1 VirtualQueryConstraint (org.alfresco.repo.virtual.template.VirtualQueryConstraint)1 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 Path (org.alfresco.service.cmr.repository.Path)1 ChildAssocElement (org.alfresco.service.cmr.repository.Path.ChildAssocElement)1 QName (org.alfresco.service.namespace.QName)1