Search in sources :

Example 36 with Reference

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

the class ReferenceComparator method compareImpl.

private int compareImpl(Reference ref1In, Reference ref2In, List<Pair<QName, Boolean>> sortProps) throws VirtualizationException {
    Object pv1 = null;
    Object pv2 = null;
    QName sortPropQName = (QName) sortProps.get(0).getFirst();
    boolean sortAscending = sortProps.get(0).getSecond();
    Reference ref1 = ref1In;
    Reference ref2 = ref2In;
    if (sortAscending == false) {
        ref1 = ref2In;
        ref2 = ref1In;
    }
    int result = 0;
    Map<QName, Serializable> properties1 = smartStore.getProperties(ref1);
    pv1 = properties1.get(sortPropQName);
    Map<QName, Serializable> properties2 = smartStore.getProperties(ref2);
    pv2 = properties2.get(sortPropQName);
    if (pv1 == null) {
        if (pv2 == null && sortProps.size() > 1) {
            return compareImpl(ref1In, ref2In, sortProps.subList(1, sortProps.size()));
        } else {
            return (pv2 == null ? 0 : -1);
        }
    } else if (pv2 == null) {
        return 1;
    }
    if (pv1 instanceof String) {
        // TODO: use collation keys (re: performance)
        result = collator.compare((String) pv1, (String) pv2);
    } else if (pv1 instanceof Date) {
        result = (((Date) pv1).compareTo((Date) pv2));
    } else if (pv1 instanceof Long) {
        result = (((Long) pv1).compareTo((Long) pv2));
    } else if (pv1 instanceof Integer) {
        result = (((Integer) pv1).compareTo((Integer) pv2));
    } else if (pv1 instanceof QName) {
        result = (((QName) pv1).compareTo((QName) pv2));
    } else if (pv1 instanceof Boolean) {
        result = (((Boolean) pv1).compareTo((Boolean) pv2));
    } else {
        throw new RuntimeException("Unsupported sort type: " + pv1.getClass().getName());
    }
    if ((result == 0) && (sortProps.size() > 1)) {
        return compareImpl(ref1In, ref2In, sortProps.subList(1, sortProps.size()));
    }
    return result;
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) Reference(org.alfresco.repo.virtual.ref.Reference) Date(java.util.Date)

Example 37 with Reference

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

the class VirtualStoreImpl method createChildReferences.

private List<Reference> createChildReferences(Reference parent, VirtualFolderDefinition structure) throws ProtocolMethodException {
    List<VirtualFolderDefinition> structureChildren = structure.getChildren();
    List<Reference> childReferences = new LinkedList<Reference>();
    for (VirtualFolderDefinition child : structureChildren) {
        childReferences.add(parent.execute(new GetChildByIdMethod(child.getId())));
    }
    return childReferences;
}
Also used : PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) VirtualFolderDefinition(org.alfresco.repo.virtual.template.VirtualFolderDefinition) LinkedList(java.util.LinkedList) GetChildByIdMethod(org.alfresco.repo.virtual.ref.GetChildByIdMethod)

Example 38 with Reference

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

the class VirtualStoreImpl method list.

@Override
public List<Reference> list(Reference reference) throws VirtualizationException {
    VirtualFolderDefinition structure = resolveVirtualFolderDefinition(reference);
    List<Reference> result = createChildReferences(reference, structure);
    final VirtualQuery query = structure.getQuery();
    if (query != null) {
        PagingResults<Reference> queryNodes = query.perform(environment, new FilesFoldersConstraint(BasicConstraint.INSTANCE, true, true), null, reference);
        result.addAll(queryNodes.getPage());
    }
    return result;
}
Also used : VirtualQuery(org.alfresco.repo.virtual.template.VirtualQuery) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) FilesFoldersConstraint(org.alfresco.repo.virtual.template.FilesFoldersConstraint) VirtualFolderDefinition(org.alfresco.repo.virtual.template.VirtualFolderDefinition)

Example 39 with Reference

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

the class VirtualStoreImpl method nodeProtocolNodeRef.

private NodeRef nodeProtocolNodeRef(NodeRef nodeRef) throws ProtocolMethodException, ReferenceParseException, ReferenceEncodingException {
    NodeRef theNodeRef = nodeRef;
    Reference ref = Reference.fromNodeRef(theNodeRef);
    if (ref != null) {
        if (Protocols.NODE.protocol.equals(ref.getProtocol())) {
            theNodeRef = ref.execute(new GetActualNodeRefMethod(environment));
        }
    }
    return theNodeRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) GetActualNodeRefMethod(org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)

Example 40 with Reference

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

the class GetChildAssocsMethod method execute.

@Override
public List<ChildAssociationRef> execute(VirtualProtocol virtualProtocol, Reference reference) throws ProtocolMethodException {
    if (typeQNamePattern.isMatch(ContentModel.ASSOC_CONTAINS)) {
        List<ChildAssociationRef> childAssocs = new LinkedList<>();
        List<Reference> children = smartStore.list(reference);
        NodeRef nodeRefReference = reference.toNodeRef();
        int count = 0;
        for (Reference child : children) {
            if (count >= maxResults) {
                break;
            }
            NodeRef childNodeRef = child.toNodeRef();
            Serializable childName = environment.getProperty(childNodeRef, ContentModel.PROP_NAME);
            QName childAssocQName = QName.createQNameWithValidLocalName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, childName.toString());
            if (qnamePattern.isMatch(childAssocQName)) {
                ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, nodeRefReference, childAssocQName, childNodeRef, true, -1);
                childAssocs.add(childAssoc);
                count++;
            }
        }
        return childAssocs;
    } else {
        return Collections.emptyList();
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) Reference(org.alfresco.repo.virtual.ref.Reference) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) LinkedList(java.util.LinkedList)

Aggregations

Reference (org.alfresco.repo.virtual.ref.Reference)81 NodeRef (org.alfresco.service.cmr.repository.NodeRef)59 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)23 VersionServiceTrait (org.alfresco.repo.version.traitextender.VersionServiceTrait)16 LinkedList (java.util.LinkedList)15 VirtualizationIntegrationTest (org.alfresco.repo.virtual.VirtualizationIntegrationTest)15 Test (org.junit.Test)15 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)13 NodeServiceTrait (org.alfresco.repo.node.db.traitextender.NodeServiceTrait)12 QName (org.alfresco.service.namespace.QName)10 Serializable (java.io.Serializable)9 GetParentReferenceMethod (org.alfresco.repo.virtual.ref.GetParentReferenceMethod)9 Version (org.alfresco.service.cmr.version.Version)9 GetActualNodeRefMethod (org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)8 VirtualFolderDefinition (org.alfresco.repo.virtual.template.VirtualFolderDefinition)6 FileInfo (org.alfresco.service.cmr.model.FileInfo)6 PermissionServiceTrait (org.alfresco.repo.security.permissions.impl.traitextender.PermissionServiceTrait)5 VirtualizationException (org.alfresco.repo.virtual.VirtualizationException)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4