Search in sources :

Example 1 with Reference

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

the class VirtualFileFolderServiceExtension method list.

@Override
public PagingResults<FileInfo> list(final NodeRef contextNodeRef, final boolean files, final boolean folders, final String pattern, final Set<QName> ignoreQNames, final List<Pair<QName, Boolean>> sortProps, final PagingRequest pagingRequest) {
    final FileFolderServiceTrait theTrait = getTrait();
    if (canVirtualize(contextNodeRef)) {
        final Reference reference = smartStore.virtualize(contextNodeRef);
        Set<QName>[] searchAndIgnore = buildSearchAndIgnore(files, folders, ignoreQNames);
        if (mergeActualNode(reference)) {
            PagingResults<Reference> virtualChildren = smartStore.list(reference, false, true, files, folders, pattern, searchAndIgnore[1], searchAndIgnore[2], sortProps, new PagingRequest(0));
            PagingResultsSource<FileInfo> superSource = new PagingResultsSource<FileInfo>() {

                @Override
                public PagingResults<FileInfo> retrieve(PagingRequest pr) throws PageCollationException {
                    try {
                        PagingResults<FileInfo> result = theTrait.list(actualNodeFrom(reference), files, folders, pattern, ignoreQNames, sortProps, pr);
                        return result;
                    } catch (VirtualizationException e) {
                        throw new PageCollationException(e);
                    }
                }
            };
            FileInfoPropsComparator comparator = (sortProps != null && !sortProps.isEmpty()) ? new FileInfoPropsComparator(sortProps) : null;
            try {
                return new PageCollator<FileInfo>().collate(asFileInfoResults(environment, virtualChildren, smartStore).getPage(), superSource, pagingRequest, comparator);
            } catch (PageCollationException error) {
                throw new VirtualizationException(error);
            }
        } else {
            PagingResults<Reference> children = smartStore.list(reference, true, true, files, folders, pattern, searchAndIgnore[1], searchAndIgnore[2], sortProps, pagingRequest);
            return asFileInfoResults(environment, children, smartStore);
        }
    } else {
        return theTrait.list(contextNodeRef, files, folders, pattern, ignoreQNames, sortProps, pagingRequest);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Reference(org.alfresco.repo.virtual.ref.Reference) PagingRequest(org.alfresco.query.PagingRequest) PageCollationException(org.alfresco.repo.virtual.page.PageCollationException) FileInfo(org.alfresco.service.cmr.model.FileInfo) FileFolderServiceTrait(org.alfresco.repo.model.filefolder.traitextender.FileFolderServiceTrait) PagingResultsSource(org.alfresco.repo.virtual.page.PageCollator.PagingResultsSource) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException)

Example 2 with Reference

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

the class VirtualFileFolderServiceExtension method asFileInfoResults.

public PagingResults<FileInfo> asFileInfoResults(ActualEnvironment environment, final PagingResults<Reference> results, VirtualStore store) throws ReferenceEncodingException, VirtualizationException {
    List<Reference> virtualPage = results.getPage();
    final LinkedList<FileInfo> page = new LinkedList<FileInfo>();
    for (Reference ref : virtualPage) {
        FileInfo fileInfo = asFileInfo(store, environment, ref);
        page.add(fileInfo);
    }
    final boolean hasMoreItems = results.hasMoreItems();
    final Pair<Integer, Integer> totalResultCount = results.getTotalResultCount();
    final String queryExecutionId = results.getQueryExecutionId();
    return new PagingResults<FileInfo>() {

        @Override
        public List<FileInfo> getPage() {
            return page;
        }

        @Override
        public String getQueryExecutionId() {
            return queryExecutionId;
        }

        @Override
        public Pair<Integer, Integer> getTotalResultCount() {
            return totalResultCount;
        }

        @Override
        public boolean hasMoreItems() {
            return hasMoreItems;
        }
    };
}
Also used : PagingResults(org.alfresco.query.PagingResults) FileInfo(org.alfresco.service.cmr.model.FileInfo) Reference(org.alfresco.repo.virtual.ref.Reference) LinkedList(java.util.LinkedList)

Example 3 with Reference

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

the class VirtualPermissionServiceExtension method getSetPermissions.

@Override
public NodePermissionEntry getSetPermissions(NodeRef nodeRef) {
    PermissionServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference == null) {
        return theTrait.getSetPermissions(nodeRef);
    } else {
        NodePermissionEntry virtualSetPermissions = smartStore.getSetPermissions(reference);
        NodeRef nodeToAdhereTo = establishPermisisonAdherence(reference);
        List<? extends PermissionEntry> actualPermissionEntries;
        boolean inheritPermissions = false;
        if (nodeToAdhereTo != null) {
            NodePermissionEntry actualSetPermissions = theTrait.getSetPermissions(nodeToAdhereTo);
            actualPermissionEntries = actualSetPermissions.getPermissionEntries();
            inheritPermissions = actualSetPermissions.inheritPermissions();
        } else {
            actualPermissionEntries = Collections.emptyList();
            inheritPermissions = false;
        }
        List<PermissionEntry> mergedEntries = new LinkedList<>();
        List<? extends PermissionEntry> virtualPermissionEntries = virtualSetPermissions.getPermissionEntries();
        Set<QName> overridenPermissions = new HashSet<>();
        for (PermissionEntry permissionEntry : virtualPermissionEntries) {
            overridenPermissions.add(permissionEntry.getPermissionReference().getQName());
            mergedEntries.add(permissionEntry);
        }
        for (PermissionEntry permissionEntry : actualPermissionEntries) {
            if (!overridenPermissions.contains(permissionEntry.getPermissionReference().getQName())) {
                mergedEntries.add(permissionEntry);
            }
        }
        return new SimpleNodePermissionEntry(nodeRef, inheritPermissions, mergedEntries);
    }
}
Also used : PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) QName(org.alfresco.service.namespace.QName) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) PermissionServiceTrait(org.alfresco.repo.security.permissions.impl.traitextender.PermissionServiceTrait) LinkedList(java.util.LinkedList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) PermissionEntry(org.alfresco.repo.security.permissions.PermissionEntry) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) HashSet(java.util.HashSet)

Example 4 with Reference

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

the class VirtualPermissionServiceExtension method getPermissions.

@Override
public Set<AccessPermission> getPermissions(NodeRef nodeRef) {
    PermissionServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference == null) {
        return theTrait.getPermissions(nodeRef);
    } else {
        Set<AccessPermission> virtualSetPermissions = smartStore.getAllSetPermissions(reference);
        NodeRef nodeToAdhereTo = establishPermisisonAdherence(reference);
        Set<AccessPermission> mergedEntries = new HashSet<>(virtualSetPermissions);
        if (nodeToAdhereTo != null) {
            Set<AccessPermission> actualSetPermissions = theTrait.getPermissions(nodeToAdhereTo);
            mergedEntries.addAll(actualSetPermissions);
        }
        return mergedEntries;
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) AccessPermission(org.alfresco.service.cmr.security.AccessPermission) PermissionServiceTrait(org.alfresco.repo.security.permissions.impl.traitextender.PermissionServiceTrait) HashSet(java.util.HashSet)

Example 5 with Reference

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

the class VirtualPermissionServiceExtension method getAllSetPermissions.

@Override
public Set<AccessPermission> getAllSetPermissions(NodeRef nodeRef) {
    PermissionServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference == null) {
        return theTrait.getAllSetPermissions(nodeRef);
    } else {
        Set<AccessPermission> virtualSetPermissions = smartStore.getAllSetPermissions(reference);
        NodeRef nodeToAdhereTo = establishPermisisonAdherence(reference);
        Set<AccessPermission> actualSetPermissions;
        if (nodeToAdhereTo != null) {
            actualSetPermissions = theTrait.getAllSetPermissions(nodeToAdhereTo);
        } else {
            actualSetPermissions = Collections.emptySet();
        }
        Set<String> overridenPermissions = new HashSet<>();
        Set<AccessPermission> mergedEntries = new HashSet<>();
        for (AccessPermission permission : virtualSetPermissions) {
            overridenPermissions.add(permission.getPermission());
            mergedEntries.add(permission);
        }
        for (AccessPermission permission : actualSetPermissions) {
            if (!overridenPermissions.contains(permission.getPermission())) {
                mergedEntries.add(permission);
            }
        }
        return mergedEntries;
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) AccessPermission(org.alfresco.service.cmr.security.AccessPermission) PermissionServiceTrait(org.alfresco.repo.security.permissions.impl.traitextender.PermissionServiceTrait) HashSet(java.util.HashSet)

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