Derek Hulley f2eab4d8d9 Merged DEV/SWIFT to HEAD
28029: Added more tests for PublishingEventHelper and PublishingQueueImpl. Also added WebPublishingTestSuite.
   28034: Support for ALF-8792: RSOLR 036: SOLR APIs to support index integrity checking
          - ACL and ACLTX support
   28036: WCM QS ML UI tweaks for marking something as the initial translation
   28038: ALF-8548: WPUB: F165: Foundation API: Cancel a scheduled publishing event
          - Code and initial test cases
   28051: Fix for ALF-8836: No permission checks for SolrJSONResultSet
   28057: WCM QS ML support for claiming intermediate non-translated folders when translating documents, with tests
   28058: ML-WQS: Slight refactoring to remove RootNavInterceptor.
          This functionality has been brought into the ApplicationDataInterceptor.
		  The effective root section is now made available to templates and components in the model.
   28059: ALF-8499. SVC 10: Action Forms.
          This checkin adds an ActionFormProcessor which supports the generation and persistence of Forms based on
          Alfresco spring-injected action beans. The form processor produces a form field for each defined action parameter
          as well as the ubiquitous executeAsynchronously boolean for action execution.
          There is no styling of configuration of these forms and therefore NodeRef parameters will allow selection of any
		  cm:cmobject nodes and action constraints like ac-aspects will return every aspect defined in the system.
          To expose these forms in the product, we would need to add form configuration for the built-in actions in order to manage and control such data.
   28064: Fix for ALF-8857: Fix SOLR query caching to respect locale for ordering
   28067: ALF-8846 : Intermittent: DMDeploymentTargetTest
          added more debug logging and throw an explicit exception on trying to create a duplicate directory.
   28068: Publishing: Tidy-up (javadoc and removal of a few unnecessary operations) prior to sprint 1 demo.
   28069: Implemented EnvironmentImpl.checkStatus() method. Also created an AbstractWebPublishingIntegrationTest
          and extended many of the web publishing tests from htis class.
   28076: Publishing: More javadoc
   28078: RINF 11: Canned queries
          - minor: rename CannedQuery "query" to "queryAndFilter" and update/fix related JavaDoc (ALF-8827)
          - update PagingRequest - precursor to merge with (Script) PagingDetails (ALF-8855)
   28079: RINF 40: Lucene Removal: PersonService API (ALF-8805) - W.I.P.
          - add GetChildren CQ support for (initially string) property filtering, including unit tests
          - update GetChildren CQ to allow up to three filter and/or sort props
          - add GetChildren CQ unit test for existing DB-based filtering of child types
          - fix GetChildren CQ sorting, for spoofed referenceable props (including missing name)
   28083: Fix for ALF-8858: Fix cache bugs (TX and ACLTX docs not tracked)
   28097: Fix hard-coded checks for aspect counts following sys:localized changes
   28126: Build/test fix (GetChildrenCannedQueryTest.testPropertyStringFiltering)
   28147: RINF 40: Lucene Removal: PersonService API
          - initial impl w/ unit tests
          - note: separate task required to update JavaScript API (People.getPeople)
   28157: RINF 40: Lucene Removal: PersonService API (ALF-8805)
          - fix People.getPeople - put back FTS option (pending ALF-8924)
   28162: Added PublishWebContentJbpmTest to test the Jbpm publish web content process definiion.
   28178: Build fix. Removing a trailing comma that my ant build objects to.
   28180: Preventing a NPE within TikaCharsetFinder. Was observed as part of tests for ALF-3757.
   28182: RSOLR 037: Integrate CMIS Dictionary into SOLR engine
   28183: ALF-8846 - fix DMDeploymentTarget(Test)
          - make system auth explicit
          - minor: fixup debug logging
   28187: Fix for ALF-7308. The imgpreview thumbnail ... scale up small images...
          I've exposed an ImageMagick configuration option ('>') as a new ImageRenderingEngine parameter, "allowEnlargement".
          It's not mandatory, defaults to true, and is set to false for doclib and imgpreview thumbnails.
          The net result is that doclib and imgpreview thumbnails of small graphics files (e.g. icons) will never have sizes exceeding their original size.
   28191: RINF 09: Update FileFolderService (ALF-7168)
          - minor: clean-up debug/trace logging
   28192: Fix MT for GetChildren CQ
          - FileFolderService -> list (ALF-7168)
          - PersonService -> getPeople (ALF-8805)
   28194: RINF 09: CMIS getChildren sorting fixes (part of ALF-7168)
          - fix sorting by cmis:contentStreamMimeType and/or cmis:contentStreamLength
          - add warning + debug (if some orderBy sort props need to be ignored - eg. too many or unknown)
          - reviewed w/ Florian
   28195: ALF-8910: RSOLR 037: Integrate CMIS Query Parser into SOLR engine
   28211: Changes for ALF-8646: "RINF 38: Text data encryption"
   28227: Changes for ALF-8646: "RINF 38: Text data encryption"
          o fix build issue relating to missing property definition
   28232: ALF-8928 - Performance degradation when loading documents from RepoStore
   28233: Attempt to resolve OOM hangs in SWIFT builds
          - Set mem.size.max=2048m
   28234: Implementation of ALF-8986. Add support for transformation of Apple iWorks files.
             A new transformer transforms (pages, numbers, keynote) iWorks 09 files to image or SWF for doclib & webpreview thumbnailing.
             This transformer extracts an embedded JPEG or PDF file from a well-known location within the iWorks zip structure & uses that
			 to create Alfresco thumbnails. If these zip entries are not present for whatever reason, then the transformation fails in the usual way.
             All of our iWorks 09 test files have an embedded JPEG and more than half have embedded PDFs.
   28243: Init/refresh repo webscripts in single txn
          - found whilst investigating ALF-8928
   28268: Started implementing PublishEventAction. Also updated mapping of nodes from source to live environment to use associations.
   28308: PublishEventAction now supports updating of nodes that have already been published.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28321 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2011-06-10 00:21:55 +00:00

727 lines
27 KiB
Java

/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.node.getchildren;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.query.CannedQueryParameters;
import org.alfresco.query.CannedQuerySortDetails;
import org.alfresco.query.PagingResults;
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
import org.alfresco.repo.domain.node.AuditablePropertiesEntity;
import org.alfresco.repo.domain.node.Node;
import org.alfresco.repo.domain.node.NodeDAO;
import org.alfresco.repo.domain.node.NodeEntity;
import org.alfresco.repo.domain.node.NodePropertyEntity;
import org.alfresco.repo.domain.node.NodePropertyHelper;
import org.alfresco.repo.domain.node.NodePropertyKey;
import org.alfresco.repo.domain.node.NodePropertyValue;
import org.alfresco.repo.domain.node.ReferenceablePropertiesEntity;
import org.alfresco.repo.domain.qname.QNameDAO;
import org.alfresco.repo.domain.query.CannedQueryDAO;
import org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString;
import org.alfresco.repo.security.permissions.impl.acegi.AbstractCannedQueryPermissions;
import org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityInterceptor;
import org.alfresco.repo.security.permissions.impl.acegi.WrappedList;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.MLText;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.alfresco.util.ParameterCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* GetChidren canned query
*
* To get paged list of children of a parent node filtered by child type.
* Also optionally filtered and/or sorted by one or more properties (up to three).
*
* @author janv
* @since 4.0
*/
public class GetChildrenCannedQuery extends AbstractCannedQueryPermissions<NodeRef>
{
private Log logger = LogFactory.getLog(getClass());
private static final String QUERY_NAMESPACE = "alfresco.node";
private static final String QUERY_SELECT_GET_CHILDREN_WITH_PROPS = "select_GetChildrenCannedQueryWithProps";
private static final String QUERY_SELECT_GET_CHILDREN_WITHOUT_PROPS = "select_GetChildrenCannedQueryWithoutProps";
public static final int MAX_FILTER_SORT_PROPS = 3;
// note: speical qnames - originally from Share DocLib default config (however, we do not support arbitrary "fts-alfresco" special sortable fields)
public static final QName SORT_QNAME_CONTENT_SIZE = QName.createQName("http://www.alfresco.org/model/content/1.0", "content.size");
public static final QName SORT_QNAME_CONTENT_MIMETYPE = QName.createQName("http://www.alfresco.org/model/content/1.0", "content.mimetype");
public static final QName SORT_QNAME_NODE_TYPE = QName.createQName("", "TYPE");
private NodeDAO nodeDAO;
private QNameDAO qnameDAO;
private CannedQueryDAO cannedQueryDAO;
private NodePropertyHelper nodePropertyHelper;
private TenantService tenantService;
private boolean applyPostQueryPermissions = false; // if true, the permissions will be applied post-query (else should be applied as part of the "queryAndFilter")
public GetChildrenCannedQuery(
NodeDAO nodeDAO,
QNameDAO qnameDAO,
CannedQueryDAO cannedQueryDAO,
NodePropertyHelper nodePropertyHelper,
TenantService tenantService,
MethodSecurityInterceptor methodSecurityInterceptor,
Method method,
CannedQueryParameters params,
String queryExecutionId)
{
super(params, queryExecutionId, methodSecurityInterceptor, method);
this.nodeDAO = nodeDAO;
this.qnameDAO = qnameDAO;
this.cannedQueryDAO = cannedQueryDAO;
this.nodePropertyHelper = nodePropertyHelper;
this.tenantService = tenantService;
if ((params.getSortDetails() != null) && (params.getSortDetails().getSortPairs().size() > 0))
{
applyPostQueryPermissions = true;
}
// TODO refactor (only apply post query if sorted - as above)
GetChildrenCannedQueryParams paramBean = (GetChildrenCannedQueryParams)params.getParameterBean();
if ((paramBean.getFilterProps()!= null) && (paramBean.getFilterProps().size() > 0))
{
applyPostQueryPermissions = true;
}
}
@Override
protected List<NodeRef> queryAndFilter(CannedQueryParameters parameters)
{
Long start = (logger.isDebugEnabled() ? System.currentTimeMillis() : null);
// Get parameters
GetChildrenCannedQueryParams paramBean = (GetChildrenCannedQueryParams)parameters.getParameterBean();
// Get parent node
NodeRef parentRef = paramBean.getParentRef();
ParameterCheck.mandatory("nodeRef", parentRef);
Pair<Long, NodeRef> nodePair = nodeDAO.getNodePair(parentRef);
if (nodePair == null)
{
throw new InvalidNodeRefException("Parent node does not exist: " + parentRef, parentRef);
}
Long parentNodeId = nodePair.getFirst();
// Set query params - note: currently using SortableChildEntity to hold (supplemental-) query params
FilterSortNodeEntity params = new FilterSortNodeEntity();
// Set parent node id
params.setParentNodeId(parentNodeId);
// Get filter details
Set<QName> childNodeTypeQNames = paramBean.getChildTypeQNames();
final List<FilterProp> filterProps = paramBean.getFilterProps();
// Get sort details
CannedQuerySortDetails sortDetails = parameters.getSortDetails();
@SuppressWarnings("unchecked")
final List<Pair<QName, SortOrder>> sortPairs = (List)sortDetails.getSortPairs();
// Set sort / filter params
Set<QName> sortFilterProps = new HashSet<QName>(filterProps.size() + sortPairs.size());
for (FilterProp filter : filterProps)
{
sortFilterProps.add(filter.getPropName());
}
for (Pair<QName, SortOrder> sort : sortPairs)
{
sortFilterProps.add(sort.getFirst());
}
int filterSortPropCnt = sortFilterProps.size();
if (filterSortPropCnt > MAX_FILTER_SORT_PROPS)
{
throw new AlfrescoRuntimeException("GetChildren: exceeded maximum number filter/sort properties: (max="+MAX_FILTER_SORT_PROPS+", actual="+filterSortPropCnt);
}
filterSortPropCnt = setFilterSortParams(sortFilterProps, params);
// Set child node type qnames (additional filter - performed by DB query)
if (childNodeTypeQNames != null)
{
Set<Long> childNodeTypeQNameIds = qnameDAO.convertQNamesToIds(childNodeTypeQNames, false);
if (childNodeTypeQNameIds.size() > 0)
{
params.setChildNodeTypeQNameIds(new ArrayList<Long>(childNodeTypeQNameIds));
}
}
final List<NodeRef> result;
if (filterSortPropCnt > 0)
{
// filtered and/or sorted - note: permissions will be applied post query
final List<FilterSortNode> children = new ArrayList<FilterSortNode>(100);
final boolean applyFilter = (filterProps.size() > 0);
FilterSortChildQueryCallback callback = new FilterSortChildQueryCallback()
{
public boolean handle(FilterSortNode node)
{
// filter, if needed
if ((! applyFilter) || includeFilter(node.getPropVals(), filterProps))
{
children.add(node);
}
// More results
return true;
}
};
FilterSortResultHandler resultHandler = new FilterSortResultHandler(callback);
cannedQueryDAO.executeQuery(QUERY_NAMESPACE, QUERY_SELECT_GET_CHILDREN_WITH_PROPS, params, 0, Integer.MAX_VALUE, resultHandler);
resultHandler.done();
if (sortPairs.size() > 0)
{
// sort
Collections.sort(children, new PropComparatorAsc(sortPairs));
}
result = new ArrayList<NodeRef>(children.size());
for (FilterSortNode child : children)
{
result.add(tenantService.getBaseName(child.getNodeRef()));
}
}
else
{
// unsorted (apart from any implicit order) - note: permissions are applied during result handling to allow early cutoff
int requestedCount = parameters.getPageDetails().getResultsRequiredForPaging();
int requestTotalCountMax = getParameters().requestTotalResultCountMax();
if ((requestTotalCountMax > 0) && (requestTotalCountMax > requestedCount))
{
requestedCount = requestTotalCountMax;
}
if (requestedCount != Integer.MAX_VALUE)
{
requestedCount++; // add one for "hasMoreItems"
}
final WrappedList<NodeRef> rawResult = new WrappedList<NodeRef>(new ArrayList<NodeRef>(100), requestedCount);
UnsortedChildQueryCallback callback = new UnsortedChildQueryCallback()
{
public boolean handle(NodeRef nodeRef)
{
rawResult.add(tenantService.getBaseName(nodeRef));
// More results ?
return (rawResult.size() < rawResult.getMaxChecks());
}
};
UnsortedResultHandler resultHandler = new UnsortedResultHandler(callback, parameters.getAuthenticationToken());
cannedQueryDAO.executeQuery(QUERY_NAMESPACE, QUERY_SELECT_GET_CHILDREN_WITHOUT_PROPS, params, 0, Integer.MAX_VALUE, resultHandler);
resultHandler.done();
// permissions have been applied
result = new WrappedList<NodeRef>(rawResult.getWrapped(), true, (rawResult.size() == requestedCount));
}
if (start != null)
{
logger.debug("Base query "+(filterSortPropCnt > 0 ? "(sort=y, perms=n)" : "(sort=n, perms=y)")+": "+result.size()+" in "+(System.currentTimeMillis()-start)+" msecs");
}
return result;
}
// Set filter/sort props (between 0 and 3)
private int setFilterSortParams(Set<QName> filterSortProps, FilterSortNodeEntity params)
{
int cnt = 0;
for (QName filterSortProp : filterSortProps)
{
if (AuditablePropertiesEntity.getAuditablePropertyQNames().contains(filterSortProp))
{
params.setAuditableProps(true);
}
else if (filterSortProp.equals(SORT_QNAME_NODE_TYPE))
{
params.setNodeType(true);
}
else
{
Long sortQNameId = getQNameId(filterSortProp);
if (sortQNameId != null)
{
if (cnt == 0)
{
params.setProp1qnameId(sortQNameId);
}
else if (cnt == 1)
{
params.setProp2qnameId(sortQNameId);
}
else if (cnt == 2)
{
params.setProp3qnameId(sortQNameId);
}
else
{
// belts and braces
throw new AlfrescoRuntimeException("GetChildren: unexpected - cannot set sort parameter: "+cnt);
}
}
else
{
logger.warn("Skipping filter/sort param - cannot find: "+filterSortProp);
break;
}
}
cnt++;
}
return cnt;
}
private Long getQNameId(QName sortPropQName)
{
if (sortPropQName.equals(SORT_QNAME_CONTENT_SIZE) || sortPropQName.equals(SORT_QNAME_CONTENT_MIMETYPE))
{
sortPropQName = ContentModel.PROP_CONTENT;
}
Pair<Long, QName> qnamePair = qnameDAO.getQName(sortPropQName);
return (qnamePair == null ? null : qnamePair.getFirst());
}
@Override
protected boolean isApplyPostQuerySorting()
{
// note: sorted as part of the query impl (using SortableNode results)
return false;
}
private class PropComparatorAsc implements Comparator<FilterSortNode>
{
private List<Pair<QName, SortOrder>> sortProps;
private Collator collator;
public PropComparatorAsc(List<Pair<QName, SortOrder>> sortProps)
{
this.sortProps = sortProps;
this.collator = Collator.getInstance(); // note: currently default locale
}
public int compare(FilterSortNode n1, FilterSortNode n2)
{
return compareImpl(n1, n2, sortProps);
}
private int compareImpl(FilterSortNode node1In, FilterSortNode node2In, List<Pair<QName, SortOrder>> sortProps)
{
Object pv1 = null;
Object pv2 = null;
QName sortPropQName = (QName)sortProps.get(0).getFirst();
boolean sortAscending = (sortProps.get(0).getSecond() == SortOrder.ASCENDING);
FilterSortNode node1 = node1In;
FilterSortNode node2 = node2In;
if (sortAscending == false)
{
node1 = node2In;
node2 = node1In;
}
int result = 0;
pv1 = node1.getVal(sortPropQName);
pv2 = node2.getVal(sortPropQName);
if (pv1 == null)
{
return (pv2 == null ? 0 : -1);
}
else if (pv2 == null)
{
return 1;
}
if (pv1 instanceof String)
{
result = collator.compare((String)pv1, (String)pv2); // TODO use collation keys (re: performance)
}
else if (pv1 instanceof Date)
{
result = (((Date)pv1).compareTo((Date)pv2));
}
else if (pv1 instanceof Long)
{
result = (((Long)pv1).compareTo((Long)pv2));
}
else if (pv1 instanceof QName)
{
result = (((QName)pv1).compareTo((QName)pv2));
}
else
{
// TODO other comparisons
throw new RuntimeException("Unsupported sort type: "+pv1.getClass().getName());
}
if ((result == 0) && (sortProps.size() > 1))
{
return compareImpl(node1In, node2In, sortProps.subList(1, sortProps.size()));
}
return result;
}
}
// note: currently inclusive and OR-based
private boolean includeFilter(Map<QName, Serializable> propVals, List<FilterProp> filterProps)
{
for (FilterProp filterProp : filterProps)
{
Serializable propVal = propVals.get(filterProp.getPropName());
if (propVal != null)
{
if ((filterProp instanceof FilterPropString) && (propVal instanceof String))
{
String val = (String)propVal;
String filter = (String)filterProp.getPropVal();
switch ((FilterTypeString)filterProp.getFilterType())
{
case STARTSWITH:
if (val.startsWith(filter))
{
return true;
}
break;
case STARTSWITH_IGNORECASE:
if (val.toLowerCase().startsWith(filter.toLowerCase()))
{
return true;
}
break;
case EQUALS:
if (val.equals(filter))
{
return true;
}
break;
case EQUALS_IGNORECASE:
if (val.equalsIgnoreCase(filter))
{
return true;
}
break;
default:
}
}
}
}
return false;
}
@Override
protected boolean isApplyPostQueryPermissions()
{
return applyPostQueryPermissions; // true if sorted (if unsorted then permissions are applied as part of the query impl)
}
@Override
protected PagingResults<NodeRef> applyPostQueryPermissions(List<NodeRef> results, String authenticationToken, int requestedCount)
{
Long start = (logger.isDebugEnabled() ? System.currentTimeMillis() : null);
int requestTotalCountMax = getParameters().requestTotalResultCountMax();
int maxChecks = (((requestTotalCountMax > 0) && (requestTotalCountMax > requestedCount)) ? requestTotalCountMax : requestedCount);
int cnt = results.size();
int toIdx = (maxChecks > cnt ? cnt : maxChecks);
// note: assume user has read access to most/majority of the items hence pre-load up to max checks
preload(results.subList(0, toIdx));
PagingResults<NodeRef> ret = super.applyPostQueryPermissions(results, authenticationToken, requestedCount);
if (start != null)
{
logger.debug("Post-query perms: "+ret.getPage().size()+" in "+(System.currentTimeMillis()-start)+" msecs");
}
return ret;
}
private void preload(List<NodeRef> nodeRefs)
{
Long start = (logger.isTraceEnabled() ? System.currentTimeMillis() : null);
nodeDAO.cacheNodes(nodeRefs);
if (start != null)
{
logger.trace("Pre-load: "+nodeRefs.size()+" in "+(System.currentTimeMillis()-start)+" msecs");
}
}
private interface FilterSortChildQueryCallback
{
boolean handle(FilterSortNode node);
}
private interface UnsortedChildQueryCallback
{
boolean handle(NodeRef nodeRef);
}
private class FilterSortResultHandler implements CannedQueryDAO.ResultHandler<FilterSortNodeEntity>
{
private final FilterSortChildQueryCallback resultsCallback;
private boolean more = true;
private FilterSortResultHandler(FilterSortChildQueryCallback resultsCallback)
{
this.resultsCallback = resultsCallback;
}
public boolean handleResult(FilterSortNodeEntity result)
{
// Do nothing if no further results are required
if (!more)
{
return false;
}
Node node = result.getNode();
NodeRef nodeRef = node.getNodeRef();
Map<NodePropertyKey, NodePropertyValue> propertyValues = new HashMap<NodePropertyKey, NodePropertyValue>(3);
NodePropertyEntity prop1 = result.getProp1();
if (prop1 != null)
{
propertyValues.put(prop1.getKey(), prop1.getValue());
}
NodePropertyEntity prop2 = result.getProp2();
if (prop2 != null)
{
propertyValues.put(prop2.getKey(), prop2.getValue());
}
NodePropertyEntity prop3 = result.getProp3();
if (prop3 != null)
{
propertyValues.put(prop3.getKey(), prop3.getValue());
}
Map<QName, Serializable> propVals = nodePropertyHelper.convertToPublicProperties(propertyValues);
// Add referenceable / spoofed properties (including spoofed name if null)
ReferenceablePropertiesEntity.addReferenceableProperties(node, propVals);
// special cases
// MLText (eg. cm:title, cm:description, ...)
for (Map.Entry<QName, Serializable> entry : propVals.entrySet())
{
if (entry.getValue() instanceof MLText)
{
propVals.put(entry.getKey(), DefaultTypeConverter.INSTANCE.convert(String.class, (MLText)entry.getValue()));
}
}
// ContentData (eg. cm:content.size, cm:content.mimetype)
ContentData contentData = (ContentData)propVals.get(ContentModel.PROP_CONTENT);
if (contentData != null)
{
propVals.put(SORT_QNAME_CONTENT_SIZE, contentData.getSize());
propVals.put(SORT_QNAME_CONTENT_MIMETYPE, contentData.getMimetype());
}
// Auditable props (eg. cm:creator, cm:created, cm:modifier, cm:modified, ...)
AuditablePropertiesEntity auditableProps = node.getAuditableProperties();
if (auditableProps != null)
{
for (Map.Entry<QName, Serializable> entry : auditableProps.getAuditableProperties().entrySet())
{
propVals.put(entry.getKey(), entry.getValue());
}
}
// Node type
Long nodeTypeQNameId = node.getTypeQNameId();
if (nodeTypeQNameId != null)
{
Pair<Long, QName> pair = qnameDAO.getQName(nodeTypeQNameId);
if (pair != null)
{
propVals.put(SORT_QNAME_NODE_TYPE, pair.getSecond());
}
}
// Call back
boolean more = resultsCallback.handle(new FilterSortNode(nodeRef, propVals));
if (!more)
{
this.more = false;
}
return more;
}
public void done()
{
}
}
private class FilterSortNode
{
private NodeRef nodeRef;
private Map<QName, Serializable> propVals; // subset of nodes properties - used for filtering and/or sorting
public FilterSortNode(NodeRef nodeRef, Map<QName, Serializable> propVals)
{
this.nodeRef = nodeRef;
this.propVals = propVals;
}
public NodeRef getNodeRef()
{
return nodeRef;
}
public Serializable getVal(QName prop)
{
return propVals.get(prop);
}
public Map<QName, Serializable> getPropVals()
{
return propVals;
}
}
private class UnsortedResultHandler implements CannedQueryDAO.ResultHandler<NodeEntity>
{
private final UnsortedChildQueryCallback resultsCallback;
private final String authenticationToken;
private boolean more = true;
private static final int BATCH_SIZE = 256 * 4;
private final List<NodeRef> nodeRefs;
private UnsortedResultHandler(UnsortedChildQueryCallback resultsCallback, String authenticationToken)
{
this.resultsCallback = resultsCallback;
this.authenticationToken = authenticationToken;
nodeRefs = new LinkedList<NodeRef>();
}
public boolean handleResult(NodeEntity result)
{
// Do nothing if no further results are required
if (!more)
{
return false;
}
NodeRef nodeRef = result.getNodeRef();
if (nodeRefs.size() >= BATCH_SIZE)
{
// batch
preloadAndApplyPermissions();
}
nodeRefs.add(nodeRef);
return more;
}
private void preloadAndApplyPermissions()
{
preload(nodeRefs);
// TODO track total time for incremental permission checks ... and cutoff (eg. based on some config)
PagingResults<NodeRef> results = applyPermissions(nodeRefs, authenticationToken, nodeRefs.size());
for (NodeRef nodeRef : results.getPage())
{
// Call back
boolean more = resultsCallback.handle(nodeRef);
if (!more)
{
this.more = false;
break;
}
}
nodeRefs.clear();
}
public void done()
{
if (nodeRefs.size() >= 0)
{
// finish batch
preloadAndApplyPermissions();
}
}
}
}