Search in sources :

Example 1 with NodeRefQueryCallback

use of org.alfresco.repo.domain.node.NodeDAO.NodeRefQueryCallback in project alfresco-repository by Alfresco.

the class ImapUnsubscribedAspectPatch method applyInternal.

@Override
protected String applyInternal() throws Exception {
    final List<ChildAssociationRef> users = nodeService.getChildAssocs(personService.getPeopleContainer(), ContentModel.ASSOC_CHILDREN, RegexQNamePattern.MATCH_ALL);
    final long maxNodeId = patchDAO.getMaxAdmNodeID();
    BatchProcessWorkProvider<NodeRef> workProvider = new BatchProcessWorkProvider<NodeRef>() {

        final List<NodeRef> result = new ArrayList<NodeRef>();

        public int getTotalEstimatedWorkSize() {
            return result.size();
        }

        public Collection<NodeRef> getNextWork() {
            result.clear();
            while (result.isEmpty() && minSearchNodeId < maxNodeId) {
                nodeDAO.getNodesWithAspects(Collections.singleton(ASPECT_NON_SUBSCRIBED), minSearchNodeId, minSearchNodeId + count, new NodeRefQueryCallback() {

                    public boolean handle(Pair<Long, NodeRef> nodePair) {
                        result.add(nodePair.getSecond());
                        return true;
                    }
                });
                minSearchNodeId = minSearchNodeId + count + 1;
            }
            return result;
        }
    };
    BatchProcessor<NodeRef> batchProcessor = new BatchProcessor<NodeRef>("ImapUnsubscribedAspectPatch", transactionService.getRetryingTransactionHelper(), workProvider, batchThreads, batchSize, applicationEventPublisher, null, 1000);
    BatchProcessWorker<NodeRef> worker = new BatchProcessWorker<NodeRef>() {

        public void afterProcess() throws Throwable {
        }

        public void beforeProcess() throws Throwable {
        }

        public String getIdentifier(NodeRef entry) {
            return entry.toString();
        }

        public void process(NodeRef entry) throws Throwable {
            nodeService.removeAspect(entry, ImapModel.ASPECT_IMAP_FOLDER_NONSUBSCRIBED);
            for (ChildAssociationRef userRef : users) {
                nodeService.createAssociation(userRef.getChildRef(), entry, ImapModel.ASSOC_IMAP_UNSUBSCRIBED);
            }
        }
    };
    batchProcessor.process(worker, true);
    return I18NUtil.getMessage(MSG_NONSUBSCRIBED_ASPECT_REMOVED);
}
Also used : NodeRefQueryCallback(org.alfresco.repo.domain.node.NodeDAO.NodeRefQueryCallback) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) BatchProcessWorkProvider(org.alfresco.repo.batch.BatchProcessWorkProvider) BatchProcessWorker(org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker) NodeRef(org.alfresco.service.cmr.repository.NodeRef) BatchProcessor(org.alfresco.repo.batch.BatchProcessor) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with NodeRefQueryCallback

use of org.alfresco.repo.domain.node.NodeDAO.NodeRefQueryCallback in project alfresco-repository by Alfresco.

the class HiddenAspectTest method getHiddenNodes.

private List<NodeRef> getHiddenNodes(final StoreRef storeRef) {
    final List<NodeRef> nodes = new ArrayList<NodeRef>(20);
    NodeRefQueryCallback resultsCallback = new NodeRefQueryCallback() {

        @Override
        public boolean handle(Pair<Long, NodeRef> nodePair) {
            if (storeRef == null || nodePair.getSecond().getStoreRef().equals(storeRef)) {
                nodes.add(nodePair.getSecond());
            }
            return true;
        }
    };
    nodeDAO.getNodesWithAspects(Collections.singleton(ContentModel.ASPECT_HIDDEN), 0l, Long.MAX_VALUE, resultsCallback);
    return nodes;
}
Also used : NodeRefQueryCallback(org.alfresco.repo.domain.node.NodeDAO.NodeRefQueryCallback) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) Pair(org.alfresco.util.Pair)

Example 3 with NodeRefQueryCallback

use of org.alfresco.repo.domain.node.NodeDAO.NodeRefQueryCallback in project alfresco-repository by Alfresco.

the class GetNodesWithAspectCannedQuery method queryAndFilter.

@Override
protected List<NodeRef> queryAndFilter(CannedQueryParameters parameters) {
    Long start = (logger.isDebugEnabled() ? System.currentTimeMillis() : null);
    // Get parameters
    GetNodesWithAspectCannedQueryParams paramBean = (GetNodesWithAspectCannedQueryParams) parameters.getParameterBean();
    // Get store, if requested
    final StoreRef storeRef = paramBean.getStoreRef();
    // Note - doesn't currently support sorting
    // Get filter details
    final Set<QName> aspectQNames = paramBean.getAspectQNames();
    // Find all the available nodes
    // Doesn't limit them here, as permissions will be applied post-query
    // TODO Improve this to permission check and page in-line, so we
    // can stop the query earlier if possible
    final List<NodeRef> result = new ArrayList<NodeRef>(100);
    nodeDAO.getNodesWithAspects(aspectQNames, Long.MIN_VALUE, Long.MAX_VALUE, new NodeRefQueryCallback() {

        @Override
        public boolean handle(Pair<Long, NodeRef> nodePair) {
            NodeRef nodeRef = nodePair.getSecond();
            if (storeRef == null || nodeRef.getStoreRef().equals(storeRef)) {
                result.add(nodeRef);
            }
            // Always ask for the next one
            return true;
        }
    });
    if (start != null) {
        logger.debug("Base query: " + result.size() + " in " + (System.currentTimeMillis() - start) + " msecs");
    }
    return result;
}
Also used : NodeRefQueryCallback(org.alfresco.repo.domain.node.NodeDAO.NodeRefQueryCallback) StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList)

Example 4 with NodeRefQueryCallback

use of org.alfresco.repo.domain.node.NodeDAO.NodeRefQueryCallback in project alfresco-repository by Alfresco.

the class NodeDAOTest method testGetNodesWithAspects.

public void testGetNodesWithAspects() throws Throwable {
    final NodeRefQueryCallback callback = new NodeRefQueryCallback() {

        public boolean handle(Pair<Long, NodeRef> nodePair) {
            // Don't need more
            return false;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            nodeDAO.getNodesWithAspects(Collections.singleton(ContentModel.ASPECT_AUDITABLE), 1L, 1000L, callback);
            return null;
        }
    }, true);
}
Also used : NodeRefQueryCallback(org.alfresco.repo.domain.node.NodeDAO.NodeRefQueryCallback) Pair(org.alfresco.util.Pair)

Aggregations

NodeRefQueryCallback (org.alfresco.repo.domain.node.NodeDAO.NodeRefQueryCallback)4 ArrayList (java.util.ArrayList)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 Pair (org.alfresco.util.Pair)2 List (java.util.List)1 BatchProcessWorkProvider (org.alfresco.repo.batch.BatchProcessWorkProvider)1 BatchProcessor (org.alfresco.repo.batch.BatchProcessor)1 BatchProcessWorker (org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker)1 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)1 StoreRef (org.alfresco.service.cmr.repository.StoreRef)1 QName (org.alfresco.service.namespace.QName)1