Search in sources :

Example 1 with ListBackedPagingResults

use of org.alfresco.query.ListBackedPagingResults in project alfresco-repository by Alfresco.

the class RemoteCredentialsServiceImpl method listRemoteSystems.

private PagingResults<String> listRemoteSystems(boolean people, boolean shared, PagingRequest paging) {
    List<NodeRef> search = new ArrayList<NodeRef>();
    if (people) {
        // Only search if it has the marker aspect
        NodeRef person = repositoryHelper.getPerson();
        if (nodeService.hasAspect(person, RemoteCredentialsModel.ASPECT_REMOTE_CREDENTIALS_SYSTEM_CONTAINER)) {
            search.add(person);
        }
    }
    if (shared) {
        NodeRef system = getSharedContainerNodeRef(false);
        if (system != null) {
            search.add(system);
        }
    }
    // If no suitable nodes were given, bail out
    if (search.isEmpty()) {
        return new EmptyPagingResults<String>();
    }
    // Look for nodes
    // Because all the information we need is held on the association, we don't
    // really need to use a Canned Query for this
    Set<String> systems = new HashSet<String>();
    for (NodeRef nodeRef : search) {
        List<ChildAssociationRef> refs = nodeService.getChildAssocs(nodeRef, RemoteCredentialsModel.ASSOC_CREDENTIALS_SYSTEM, RegexQNamePattern.MATCH_ALL);
        for (ChildAssociationRef ref : refs) {
            // System Name is the association name, no namespace
            systems.add(ref.getQName().getLocalName());
        }
    }
    // Sort, then wrap as paged results
    List<String> sortedSystems = new ArrayList<String>(systems);
    Collections.sort(sortedSystems);
    return new ListBackedPagingResults<String>(sortedSystems, paging);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) EmptyPagingResults(org.alfresco.query.EmptyPagingResults) ListBackedPagingResults(org.alfresco.query.ListBackedPagingResults) HashSet(java.util.HashSet)

Example 2 with ListBackedPagingResults

use of org.alfresco.query.ListBackedPagingResults 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

ListBackedPagingResults (org.alfresco.query.ListBackedPagingResults)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 EmptyPagingResults (org.alfresco.query.EmptyPagingResults)1 PagingRequest (org.alfresco.query.PagingRequest)1 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)1 VirtualizationException (org.alfresco.repo.virtual.VirtualizationException)1 PageCollationException (org.alfresco.repo.virtual.page.PageCollationException)1 PageCollator (org.alfresco.repo.virtual.page.PageCollator)1 PagingResultsSource (org.alfresco.repo.virtual.page.PageCollator.PagingResultsSource)1 Reference (org.alfresco.repo.virtual.ref.Reference)1 VirtualFolderDefinition (org.alfresco.repo.virtual.template.VirtualFolderDefinition)1 VirtualQuery (org.alfresco.repo.virtual.template.VirtualQuery)1 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1