Search in sources :

Example 66 with Reference

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

the class VirtualNodeServiceExtension method getChildAssocs.

@Override
public List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern, int maxResults, boolean preload) {
    NodeServiceTrait theTrait = getTrait();
    boolean canVirtualize = canVirtualizeAssocNodeRef(nodeRef);
    if (canVirtualize) {
        Reference reference = smartStore.virtualize(nodeRef);
        List<ChildAssociationRef> virtualAssociations = smartStore.getChildAssocs(reference, typeQNamePattern, qnamePattern, maxResults, preload);
        List<ChildAssociationRef> associations = new LinkedList<>(virtualAssociations);
        if (associations.size() < maxResults) {
            if (smartStore.canMaterialize(reference)) {
                NodeRef materialReference = smartStore.materialize(reference);
                List<ChildAssociationRef> actualAssociations = theTrait.getChildAssocs(materialReference, typeQNamePattern, qnamePattern, maxResults - associations.size(), preload);
                associations.addAll(actualAssociations);
            }
        }
        return associations;
    } else {
        return theTrait.getChildAssocs(nodeRef, typeQNamePattern, qnamePattern, maxResults, preload);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) Reference(org.alfresco.repo.virtual.ref.Reference) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) LinkedList(java.util.LinkedList)

Example 67 with Reference

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

the class VirtualNodeServiceExtension method getChildAssocs.

@Override
public List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern) {
    NodeServiceTrait theTrait = getTrait();
    boolean canVirtualize = canVirtualizeAssocNodeRef(nodeRef);
    if (canVirtualize) {
        Reference reference = smartStore.virtualize(nodeRef);
        List<ChildAssociationRef> virtualAssociations = smartStore.getChildAssocs(reference, typeQNamePattern, qnamePattern, Integer.MAX_VALUE, false);
        List<ChildAssociationRef> associations = new LinkedList<>(virtualAssociations);
        if (smartStore.canMaterialize(reference)) {
            NodeRef materialReference = smartStore.materialize(reference);
            List<ChildAssociationRef> actualAssociations = theTrait.getChildAssocs(materialReference, typeQNamePattern, qnamePattern);
            associations.addAll(actualAssociations);
        }
        return associations;
    } else {
        return theTrait.getChildAssocs(nodeRef, typeQNamePattern, qnamePattern);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) Reference(org.alfresco.repo.virtual.ref.Reference) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) LinkedList(java.util.LinkedList)

Example 68 with Reference

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

the class VirtualStoreImpl method search.

@Override
public List<Reference> search(Reference reference, String namePattern, boolean fileSearch, boolean folderSearch, boolean includeSubFolders) throws VirtualizationException {
    VirtualFolderDefinition structure = resolveVirtualFolderDefinition(reference);
    List<Reference> result = new LinkedList<Reference>();
    List<Reference> childReferences = createChildReferences(reference, structure);
    if (folderSearch) {
        result.addAll(childReferences);
    }
    if (includeSubFolders) {
        for (Reference childRef : childReferences) {
            List<Reference> childResults = search(childRef, namePattern, fileSearch, folderSearch, includeSubFolders);
            result.addAll(childResults);
        }
    }
    if (fileSearch) {
        final VirtualQuery query = structure.getQuery();
        if (query != null) {
            VirtualQueryConstraint vqConstraint = null;
            if (namePattern == null) {
                vqConstraint = BasicConstraint.INSTANCE;
            } else {
                vqConstraint = new NamePatternPropertyValueConstraint(new FilesFoldersConstraint(BasicConstraint.INSTANCE, true, true), ContentModel.PROP_NAME, namePattern, environment.getNamespacePrefixResolver());
            }
            PagingResults<Reference> queryNodes = query.perform(environment, vqConstraint, null, reference);
            result.addAll(queryNodes.getPage());
        }
    }
    return result;
}
Also used : VirtualQueryConstraint(org.alfresco.repo.virtual.template.VirtualQueryConstraint) 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) NamePatternPropertyValueConstraint(org.alfresco.repo.virtual.template.NamePatternPropertyValueConstraint) VirtualFolderDefinition(org.alfresco.repo.virtual.template.VirtualFolderDefinition) LinkedList(java.util.LinkedList)

Example 69 with Reference

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

the class VirtualStoreImpl method canVirtualize.

@Override
public boolean canVirtualize(NodeRef nodeRef) throws VirtualizationException {
    String runAsUser = AuthenticationUtil.getRunAsUser();
    if (runAsUser == null) {
        if (logger.isTraceEnabled()) {
            RuntimeException stackTracingException = new RuntimeException("Stack trace.");
            logger.trace("Virtualization check call in unauthenticated-context - stack trace follows:", stackTracingException);
        }
        return false;
    }
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference != null) {
        return true;
    } else {
        for (VirtualizationMethod vMethod : virtualizationMethods) {
            if (vMethod.canVirtualize(environment, nodeRef)) {
                return true;
            }
        }
        return false;
    }
}
Also used : PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference)

Example 70 with Reference

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

the class VirtualStoreImpl method list.

@Override
public PagingResults<Reference> list(final Reference ref, boolean actual, boolean virtual, final boolean files, final boolean folders, final String pattern, final Set<QName> searchTypeQNames, final Set<QName> ignoreTypeQNames, final Set<QName> ignoreAspectQNames, final List<Pair<QName, Boolean>> sortProps, final PagingRequest pagingRequest) throws VirtualizationException {
    VirtualFolderDefinition structure = resolveVirtualFolderDefinition(ref);
    List<Reference> virtualRefs = null;
    // constraints should handle folder & file filtering
    if (virtual && folders) {
        virtualRefs = createChildReferences(ref, structure);
    } else {
        virtualRefs = Collections.emptyList();
    }
    if (actual) {
        final VirtualQuery query = structure.getQuery();
        if (query != null) {
            // we have a query we must collate results
            PagingResultsSource<Reference> querySourc = new PagingResultsSource<Reference>() {

                @Override
                public PagingResults<Reference> retrieve(PagingRequest pr) throws PageCollationException {
                    try {
                        return query.perform(environment, files, folders, pattern, searchTypeQNames, ignoreTypeQNames, ignoreAspectQNames, sortProps, pr, ref);
                    } catch (VirtualizationException e) {
                        throw new PageCollationException(e);
                    }
                }
            };
            PageCollator<Reference> collator = new PageCollator<>();
            try {
                return collator.collate(virtualRefs, querySourc, pagingRequest, new ReferenceComparator(this, sortProps));
            } catch (PageCollationException e) {
                throw new VirtualizationException(e);
            }
        }
    }
    return new ListBackedPagingResults<>(virtualRefs);
}
Also used : PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) PagingRequest(org.alfresco.query.PagingRequest) PageCollationException(org.alfresco.repo.virtual.page.PageCollationException) VirtualQuery(org.alfresco.repo.virtual.template.VirtualQuery) PageCollator(org.alfresco.repo.virtual.page.PageCollator) PagingResultsSource(org.alfresco.repo.virtual.page.PageCollator.PagingResultsSource) VirtualFolderDefinition(org.alfresco.repo.virtual.template.VirtualFolderDefinition) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException) ListBackedPagingResults(org.alfresco.query.ListBackedPagingResults)

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