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);
}
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;
}
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;
}
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);
}
Aggregations