mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged DEV/SWIFT to HEAD
27125: Subtasks of ALF-7072: RSOLR 013: Remote API to get ACLs and readers - ALF-8334: RSOLR 013: Modify ACL schema to record change times - ALF-8336: RSOLR 013: DB upgrade scripts for ACL changes - TODO: Query APIs 27128: Added TooManyResultsException as a concurrency detection trigger - Usually too many results indicates that the DB table key is not as specific as it should be, but it's AVM that showed this up. 27132: Clean up: javadocs; non-javadocs; uncommented fields; @since tags; etc. 27134: Removed empty directory 27135: Fix for ALF-8333: CMIS query: JOIN on an aspect results in CmisInvalidArgumentException - incorrect scope used when building orderings 27139: Fixed SORL transaction tracking queries - Queries were using incompatible boolean comparisons - Added SOLRDAO to test suite - Cleaned up code and reformatted code 27141: Minor additions to CannedQuery interface - get parameter bean - construct sort details from a list - ALF-7167: Canned queries 27146: RINF 09 / RINF 10: DB-based paged query for get children (DocLib & CMIS) - milestone check-in for sprint demo & review (WIP) - added new FileFolderService (paged) list query (public API is subject to change) - moved temp JavaScript sorting to Java - example usage by DocLib (via ScriptNode) and CMIS (via AlfrescoCmisService) - implemented as demo "canned query" including embedded use of "list" permission interceptor - ALF-7402 / ALF-7168 27150: RINF 09 / RINF 10: DB-based paged query for get children (DocLib & CMIS) - missed file (follow-on to r27146) 27158: ALF-7070, ALF-7072: SOLR tracking (node and changeset) - Pulled non-DAO code into SOLRTrackingComponent - DAO code and related tests just test basic CRUD - SOLRTrackingComponent does complex cross-schema manipulation 27159: Fixed line ending and removed svn:eol-style 27160: ALF-8334: RSOLR 013: Fixed SQL Server syntax 27165: RINF 09 / RINF 10: DB-based paged query for get children (DocLib & CMIS) - fix listDeepFolders (causing Imap*Test to fail) - all private methods now order files followed by folders (consistent with existing public APIs such as FileFolderService.search & ScriptNode.childFileFolders*) - follow-on to r27146 28271: Consolidate diagnostic logging for max perm checks (ALF-8388 + ALF-8419) - note: this should be a trivial merge to HEAD git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28292 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -34,7 +34,14 @@ import java.util.Stack;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.CannedQueryFactory;
|
||||
import org.alfresco.query.CannedQueryPageDetails;
|
||||
import org.alfresco.query.CannedQueryParameters;
|
||||
import org.alfresco.query.CannedQueryResults;
|
||||
import org.alfresco.query.CannedQuerySortDetails;
|
||||
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
|
||||
import org.alfresco.repo.search.QueryParameterDefImpl;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.model.FileExistsException;
|
||||
@@ -43,6 +50,8 @@ import org.alfresco.service.cmr.model.FileFolderServiceType;
|
||||
import org.alfresco.service.cmr.model.FileFolderUtil;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.model.FileNotFoundException;
|
||||
import org.alfresco.service.cmr.model.PagingFileInfoResults;
|
||||
import org.alfresco.service.cmr.model.PagingSortRequest;
|
||||
import org.alfresco.service.cmr.model.SubFolderFilter;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
@@ -55,6 +64,7 @@ import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.PagingSortProp;
|
||||
import org.alfresco.service.cmr.repository.Path;
|
||||
import org.alfresco.service.cmr.search.QueryParameterDefinition;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
@@ -63,7 +73,9 @@ import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.alfresco.util.SearchLanguageConversion;
|
||||
import org.alfresco.util.registry.NamedObjectRegistry;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
@@ -115,6 +127,8 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
private SearchService searchService;
|
||||
private ContentService contentService;
|
||||
private MimetypeService mimetypeService;
|
||||
private NamedObjectRegistry<CannedQueryFactory> cannedQueryRegistry;
|
||||
|
||||
private Set<String> systemNamespaces;
|
||||
|
||||
// TODO: Replace this with a more formal means of identifying "system" folders (i.e. aspect or UUID)
|
||||
@@ -162,6 +176,14 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
{
|
||||
this.mimetypeService = mimetypeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the registry of {@link CannedQueryFactory canned queries}
|
||||
*/
|
||||
public void setCannedQueryRegistry(NamedObjectRegistry<CannedQueryFactory> cannedQueryRegistry)
|
||||
{
|
||||
this.cannedQueryRegistry = cannedQueryRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the namespaces that should be treated as 'system' namespaces.
|
||||
@@ -202,11 +224,16 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
List<FileInfo> results = new ArrayList<FileInfo>(nodeRefs.size());
|
||||
for (NodeRef nodeRef : nodeRefs)
|
||||
{
|
||||
if (nodeService.exists(nodeRef))
|
||||
try
|
||||
{
|
||||
FileInfo fileInfo = toFileInfo(nodeRef, true);
|
||||
results.add(fileInfo);
|
||||
}
|
||||
catch (InvalidNodeRefException inre)
|
||||
{
|
||||
logger.warn("toFileInfo: "+inre);
|
||||
// skip
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
@@ -223,7 +250,7 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
boolean isFolder = isFolder(typeQName);
|
||||
|
||||
// Construct the file info and add to the results
|
||||
FileInfo fileInfo = new FileInfoImpl(nodeRef, isFolder, properties);
|
||||
FileInfo fileInfo = new FileInfoImpl(nodeRef, typeQName, isFolder, properties);
|
||||
// Done
|
||||
return fileInfo;
|
||||
}
|
||||
@@ -301,9 +328,101 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
}
|
||||
|
||||
public List<FileInfo> list(NodeRef contextNodeRef)
|
||||
{
|
||||
return list(contextNodeRef, true, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.model.FileFolderService#list(org.alfresco.service.cmr.repository.NodeRef, boolean, boolean, java.util.Set, org.alfresco.service.cmr.model.PagingSortRequest)
|
||||
*/
|
||||
public PagingFileInfoResults list(NodeRef contextNodeRef, boolean files, boolean folders, Set<QName> ignoreQNameTypes, PagingSortRequest pagingRequest)
|
||||
{
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
Set<QName> searchTypeQNames = buildTypes(files, folders, ignoreQNameTypes);
|
||||
|
||||
// specific query params
|
||||
GetChildrenCannedQueryParams paramBean = new GetChildrenCannedQueryParams(contextNodeRef, searchTypeQNames);
|
||||
|
||||
CannedQueryPageDetails cqpd = null;
|
||||
CannedQuerySortDetails cqsd = null;
|
||||
boolean requestTotalCount = true;
|
||||
Integer pageSize = null;
|
||||
int skipCount = -1;
|
||||
int maxItems = -1;
|
||||
|
||||
if (pagingRequest != null)
|
||||
{
|
||||
skipCount = (pagingRequest.getSkipCount() == -1 ? CannedQueryPageDetails.DEFAULT_SKIP_RESULTS : pagingRequest.getSkipCount());
|
||||
maxItems = (pagingRequest.getMaxItems() == -1 ? CannedQueryPageDetails.DEFAULT_PAGE_SIZE : pagingRequest.getMaxItems());
|
||||
|
||||
// page details
|
||||
pageSize = (maxItems == CannedQueryPageDetails.DEFAULT_PAGE_SIZE ? maxItems : maxItems + 1); // TODO: add 1 to support hasMore (see below) - push down to canned query fwk
|
||||
cqpd = new CannedQueryPageDetails(skipCount, pageSize, CannedQueryPageDetails.DEFAULT_PAGE_NUMBER, CannedQueryPageDetails.DEFAULT_PAGE_COUNT);
|
||||
|
||||
// sort details
|
||||
if (pagingRequest.getSortProps() != null)
|
||||
{
|
||||
List<Pair<? extends Object, SortOrder>> sortPairs = new ArrayList<Pair<? extends Object, SortOrder>>(pagingRequest.getSortProps().size());
|
||||
for (PagingSortProp sortProp : pagingRequest.getSortProps())
|
||||
{
|
||||
sortPairs.add(new Pair<QName, SortOrder>(sortProp.getSortProp(), (sortProp.isAscending() ? SortOrder.ASCENDING : SortOrder.DESCENDING)));
|
||||
}
|
||||
|
||||
cqsd = new CannedQuerySortDetails(sortPairs);
|
||||
}
|
||||
|
||||
requestTotalCount = pagingRequest.requestTotalCount();
|
||||
}
|
||||
|
||||
// create query params holder
|
||||
CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, cqsd, AuthenticationUtil.getRunAsUser(), requestTotalCount, null);
|
||||
|
||||
// get canned query
|
||||
GetChildrenCannedQueryFactory<NodeRef> getChildrenCannedQueryFactory = (GetChildrenCannedQueryFactory<NodeRef>)cannedQueryRegistry.getNamedObject("getChildrenCannedQueryFactory");
|
||||
GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(params);
|
||||
|
||||
// execute canned query
|
||||
CannedQueryResults<NodeRef> results = cq.execute();
|
||||
|
||||
List<NodeRef> nodeRefs = results.getPages().get(0);
|
||||
|
||||
boolean hasMore = false;
|
||||
if ((pageSize != null) && (results.getPagedResultCount() == pageSize))
|
||||
{
|
||||
// TODO: remove 1 to support hasMore (see above) - push down to canned query fwk
|
||||
hasMore = true;
|
||||
nodeRefs.remove(nodeRefs.size() - 1);
|
||||
}
|
||||
|
||||
List<FileInfo> nodeInfos = new ArrayList<FileInfo>(nodeRefs.size());
|
||||
for (NodeRef nodeRef : nodeRefs)
|
||||
{
|
||||
nodeInfos.add(toFileInfo(nodeRef, true));
|
||||
}
|
||||
|
||||
long totalCount = new Long(results.getTotalResultCount());
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
if ((skipCount == -1) && (maxItems == -1))
|
||||
{
|
||||
logger.info("List: "+nodeInfos.size()+" items [total="+totalCount+"] in "+(System.currentTimeMillis()-start)+" msecs");
|
||||
}
|
||||
else
|
||||
{
|
||||
int pageNum = (skipCount / maxItems) + 1;
|
||||
logger.info("List: page "+pageNum+" of "+nodeInfos.size()+" items [skip="+skipCount+",max="+maxItems+",total="+totalCount+"] in "+(System.currentTimeMillis()-start)+" msecs");
|
||||
}
|
||||
}
|
||||
|
||||
return new PagingFileInfoResultsImpl(nodeInfos, hasMore, totalCount);
|
||||
}
|
||||
|
||||
private List<FileInfo> list(NodeRef contextNodeRef, boolean files, boolean folders)
|
||||
{
|
||||
// execute the query
|
||||
List<NodeRef> nodeRefs = listSimple(contextNodeRef, true, true);
|
||||
List<NodeRef> nodeRefs = listSimple(contextNodeRef, files, folders);
|
||||
// convert the noderefs
|
||||
List<FileInfo> results = toFileInfo(nodeRefs);
|
||||
// done
|
||||
@@ -319,7 +438,7 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
public List<FileInfo> listFiles(NodeRef contextNodeRef)
|
||||
{
|
||||
// execute the query
|
||||
List<NodeRef> nodeRefs = listSimple(contextNodeRef, false, true);
|
||||
List<NodeRef> nodeRefs = listSimple(contextNodeRef, true, false);
|
||||
// convert the noderefs
|
||||
List<FileInfo> results = toFileInfo(nodeRefs);
|
||||
// done
|
||||
@@ -335,7 +454,7 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
public List<FileInfo> listFolders(NodeRef contextNodeRef)
|
||||
{
|
||||
// execute the query
|
||||
List<NodeRef> nodeRefs = listSimple(contextNodeRef, true, false);
|
||||
List<NodeRef> nodeRefs = listSimple(contextNodeRef, false, true);
|
||||
// convert the noderefs
|
||||
List<FileInfo> results = toFileInfo(nodeRefs);
|
||||
// done
|
||||
@@ -351,7 +470,7 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
public List<FileInfo> listDeepFolders(NodeRef contextNodeRef,
|
||||
SubFolderFilter filter)
|
||||
{
|
||||
List<NodeRef> nodeRefs = listSimpleDeep(contextNodeRef, true, false, filter);
|
||||
List<NodeRef> nodeRefs = listSimpleDeep(contextNodeRef, false, true, filter);
|
||||
|
||||
List<FileInfo> results = toFileInfo(nodeRefs);
|
||||
|
||||
@@ -494,11 +613,11 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
// This is search for any name
|
||||
if(includeSubFolders)
|
||||
{
|
||||
nodeRefs = listSimpleDeep(contextNodeRef, folderSearch, fileSearch, null);
|
||||
nodeRefs = listSimpleDeep(contextNodeRef, fileSearch, folderSearch, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeRefs = listSimple(contextNodeRef, folderSearch, fileSearch);
|
||||
nodeRefs = listSimple(contextNodeRef, fileSearch, folderSearch);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -558,9 +677,38 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
return nodeRefs;
|
||||
}
|
||||
|
||||
private List<NodeRef> listSimple(NodeRef contextNodeRef, boolean folders, boolean files)
|
||||
private List<NodeRef> listSimple(NodeRef contextNodeRef, boolean files, boolean folders)
|
||||
{
|
||||
Set<QName> searchTypeQNames = new HashSet<QName>(10);
|
||||
return listSimple(contextNodeRef, files, folders, null);
|
||||
}
|
||||
|
||||
private List<NodeRef> listSimple(NodeRef contextNodeRef, boolean files, boolean folders, Set<QName> ignoreQNameTypes)
|
||||
{
|
||||
Set<QName> searchTypeQNames = buildTypes(files, folders, ignoreQNameTypes);
|
||||
|
||||
// Shortcut
|
||||
if (searchTypeQNames.size() == 0)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// Do the query
|
||||
List<ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(contextNodeRef, searchTypeQNames);
|
||||
|
||||
List<NodeRef> result = new ArrayList<NodeRef>(childAssocRefs.size());
|
||||
for (ChildAssociationRef assocRef : childAssocRefs)
|
||||
{
|
||||
result.add(assocRef.getChildRef());
|
||||
}
|
||||
|
||||
// Done
|
||||
return result;
|
||||
}
|
||||
|
||||
private Set<QName> buildTypes(boolean files, boolean folders, Set<QName> ignoreQNameTypes)
|
||||
{
|
||||
Set<QName> searchTypeQNames = new HashSet<QName>(100);
|
||||
|
||||
// Build a list of file and folder types
|
||||
if (folders)
|
||||
{
|
||||
@@ -581,20 +729,13 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
Collection<QName> qnames = dictionaryService.getSubTypes(ContentModel.TYPE_SYSTEM_FOLDER, true);
|
||||
searchTypeQNames.removeAll(qnames);
|
||||
searchTypeQNames.remove(ContentModel.TYPE_SYSTEM_FOLDER);
|
||||
// Shortcut
|
||||
if (searchTypeQNames.size() == 0)
|
||||
|
||||
if (ignoreQNameTypes != null)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
searchTypeQNames.removeAll(ignoreQNameTypes);
|
||||
}
|
||||
// Do the query
|
||||
List<ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(contextNodeRef, searchTypeQNames);
|
||||
List<NodeRef> result = new ArrayList<NodeRef>(childAssocRefs.size());
|
||||
for (ChildAssociationRef assocRef : childAssocRefs)
|
||||
{
|
||||
result.add(assocRef.getChildRef());
|
||||
}
|
||||
// Done
|
||||
return result;
|
||||
|
||||
return searchTypeQNames;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -616,7 +757,7 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
* XPath which is awful or adding new methods to the NodeService/DB This is also a dangerous method in that it can return a
|
||||
* lot of data and take a long time.
|
||||
*/
|
||||
private List<NodeRef> listSimpleDeep(NodeRef contextNodeRef, boolean folders, boolean files, SubFolderFilter folderFilter)
|
||||
private List<NodeRef> listSimpleDeep(NodeRef contextNodeRef, boolean files, boolean folders, SubFolderFilter folderFilter)
|
||||
{
|
||||
if(logger.isDebugEnabled())
|
||||
{
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -43,16 +43,20 @@ public class FileInfoImpl implements FileInfo
|
||||
private boolean isFolder;
|
||||
private boolean isLink;
|
||||
private Map<QName, Serializable> properties;
|
||||
private QName typeQName;
|
||||
|
||||
/**
|
||||
* Package-level constructor
|
||||
*/
|
||||
/* package */ FileInfoImpl(
|
||||
NodeRef nodeRef,
|
||||
QName typeQName,
|
||||
boolean isFolder,
|
||||
Map<QName, Serializable> properties)
|
||||
{
|
||||
this.nodeRef = nodeRef;
|
||||
this.typeQName = typeQName;
|
||||
|
||||
this.isFolder = isFolder;
|
||||
this.properties = properties;
|
||||
|
||||
@@ -160,4 +164,9 @@ public class FileInfoImpl implements FileInfo
|
||||
{
|
||||
return properties;
|
||||
}
|
||||
|
||||
public QName getType()
|
||||
{
|
||||
return typeQName;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,318 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 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.model.filefolder;
|
||||
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import net.sf.acegisecurity.Authentication;
|
||||
import net.sf.acegisecurity.ConfigAttributeDefinition;
|
||||
import net.sf.acegisecurity.context.Context;
|
||||
import net.sf.acegisecurity.context.ContextHolder;
|
||||
import net.sf.acegisecurity.context.security.SecureContext;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.AbstractCannedQuery;
|
||||
import org.alfresco.query.CannedQueryParameters;
|
||||
import org.alfresco.query.CannedQuerySortDetails;
|
||||
import org.alfresco.query.CannedQuerySortDetails.SortOrder;
|
||||
import org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityInterceptor;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.MLText;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Canned query to get children of a parent node
|
||||
*
|
||||
* @author janv
|
||||
* @since 4.0
|
||||
*/
|
||||
public class GetChildrenCannedQuery extends AbstractCannedQuery<NodeRef>
|
||||
{
|
||||
private Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private NodeService nodeService;
|
||||
private MethodSecurityInterceptor methodSecurityInterceptor;
|
||||
|
||||
public GetChildrenCannedQuery(
|
||||
NodeService nodeService,
|
||||
MethodSecurityInterceptor methodSecurityInterceptor,
|
||||
CannedQueryParameters params,
|
||||
String queryExecutionId)
|
||||
{
|
||||
super(params, queryExecutionId);
|
||||
|
||||
this.nodeService = nodeService;
|
||||
this.methodSecurityInterceptor = methodSecurityInterceptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<NodeRef> query(CannedQueryParameters parameters)
|
||||
{
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
GetChildrenCannedQueryParams paramBean = (GetChildrenCannedQueryParams)parameters.getParameterBean();
|
||||
List<ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(paramBean.getParentRef(), paramBean.getSearchTypeQNames());
|
||||
|
||||
List<NodeRef> result = new ArrayList<NodeRef>(childAssocRefs.size());
|
||||
for (ChildAssociationRef assocRef : childAssocRefs)
|
||||
{
|
||||
result.add(assocRef.getChildRef());
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Raw query: "+result.size()+" in "+(System.currentTimeMillis()-start)+" msecs");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isApplyPostQuerySorting()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<NodeRef> applyPostQuerySorting(List<NodeRef> results, CannedQuerySortDetails sortDetails)
|
||||
{
|
||||
if (sortDetails.getSortPairs().size() == 0)
|
||||
{
|
||||
// Nothing to sort on
|
||||
return results;
|
||||
}
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
List<NodeRef> ret = new ArrayList<NodeRef>(results);
|
||||
|
||||
List<Pair<? extends Object, SortOrder>> sortPairs = sortDetails.getSortPairs();
|
||||
|
||||
Collections.sort(ret, new PropComparatorAsc(sortPairs));
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Post query sort: "+ret.size()+" in "+(System.currentTimeMillis()-start)+" msecs");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private class PropComparatorAsc implements Comparator<NodeRef>
|
||||
{
|
||||
private List<Pair<? extends Object, SortOrder>> sortProps;
|
||||
|
||||
public PropComparatorAsc(List<Pair<? extends Object, SortOrder>> sortProps)
|
||||
{
|
||||
this.sortProps = sortProps;
|
||||
}
|
||||
|
||||
public int compare(NodeRef n1, NodeRef n2)
|
||||
{
|
||||
return compareImpl(n1, n2, sortProps);
|
||||
}
|
||||
|
||||
private int compareImpl(NodeRef node1In, NodeRef node2In, List<Pair<? extends Object, SortOrder>> sortProps)
|
||||
{
|
||||
Object pv1 = null;
|
||||
Object pv2 = null;
|
||||
|
||||
QName sortPropQName = (QName)sortProps.get(0).getFirst();
|
||||
boolean sortAscending = (sortProps.get(0).getSecond() == SortOrder.ASCENDING);
|
||||
|
||||
NodeRef node1 = node1In;
|
||||
NodeRef node2 = node2In;
|
||||
|
||||
if (sortAscending == false)
|
||||
{
|
||||
node1 = node2In;
|
||||
node2 = node1In;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
|
||||
if (sortPropQName.equals(QName.createQName(".size")) || sortPropQName.equals(QName.createQName(".mimetype")))
|
||||
{
|
||||
// content data properties (size or mimetype)
|
||||
|
||||
ContentData cd1 = (ContentData)nodeService.getProperty(node1, ContentModel.PROP_CONTENT);
|
||||
ContentData cd2 = (ContentData)nodeService.getProperty(node2, ContentModel.PROP_CONTENT);
|
||||
|
||||
if (cd1 == null)
|
||||
{
|
||||
return (cd2 == null ? 0 : 1);
|
||||
}
|
||||
else if (cd2 == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sortPropQName.equals(QName.createQName(".size")))
|
||||
{
|
||||
result = ((Long)cd1.getSize()).compareTo((Long)cd2.getSize());
|
||||
}
|
||||
else if (sortPropQName.equals(QName.createQName(".mimetype")))
|
||||
{
|
||||
result = (cd1.getMimetype()).compareTo(cd2.getMimetype());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// property other than content size / mimetype
|
||||
pv1 = nodeService.getProperty(node1, sortPropQName);
|
||||
pv2 = nodeService.getProperty(node2, sortPropQName);
|
||||
|
||||
if (pv1 == null)
|
||||
{
|
||||
return (pv2 == null ? 0 : 1);
|
||||
}
|
||||
else if (pv2 == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pv1 instanceof String)
|
||||
{
|
||||
result = (((String)pv1).compareTo((String)pv2));
|
||||
}
|
||||
else if (pv1 instanceof MLText) // eg. title, description
|
||||
{
|
||||
String sv1 = DefaultTypeConverter.INSTANCE.convert(String.class, (MLText)pv1);
|
||||
String sv2 = DefaultTypeConverter.INSTANCE.convert(String.class, (MLText)pv2);
|
||||
|
||||
result = (sv1.compareTo(sv2));
|
||||
}
|
||||
else if (pv1 instanceof Date)
|
||||
{
|
||||
result = (((Date)pv1).compareTo((Date)pv2));
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO other comparisons
|
||||
throw new RuntimeException("Unsupported sort type");
|
||||
}
|
||||
}
|
||||
|
||||
if ((result == 0) && (sortProps.size() > 1))
|
||||
{
|
||||
return compareImpl(node1In, node2In, sortProps.subList(1, sortProps.size()-1));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected boolean isApplyPostQueryPermissions()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected List<NodeRef> applyPostQueryPermissions(List<NodeRef> results, String authenticationToken, int requestedCount)
|
||||
{
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
// TODO push down cut-off (as option within permission interceptor)
|
||||
//boolean cutoffAllowed = !getParameters().isReturnTotalResultCount();
|
||||
|
||||
List<NodeRef> ret = new ArrayList<NodeRef>(results.size());
|
||||
|
||||
Context context = ContextHolder.getContext();
|
||||
if ((context == null) || !(context instanceof SecureContext))
|
||||
{
|
||||
return ret; // empty list
|
||||
}
|
||||
|
||||
Authentication authentication = (((SecureContext) context).getAuthentication());
|
||||
|
||||
Method listMethod = null;
|
||||
for (Method method : FileFolderServiceImpl.class.getMethods())
|
||||
{
|
||||
if (method.getName().equals("list"))
|
||||
{
|
||||
// found one of the list methods
|
||||
listMethod = method;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (listMethod == null)
|
||||
{
|
||||
return ret; // empty list
|
||||
}
|
||||
|
||||
// TODO ALF-8419
|
||||
ConfigAttributeDefinition listCad = methodSecurityInterceptor.getObjectDefinitionSource().getAttributes(new InternalMethodInvocation(listMethod));
|
||||
ret = (List<NodeRef>)methodSecurityInterceptor.getAfterInvocationManager().decide(authentication, null, listCad, results); // need to be able to cut-off etc ...
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Post query perms: "+ret.size()+" in "+(System.currentTimeMillis()-start)+" msecs");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
class InternalMethodInvocation implements MethodInvocation {
|
||||
Method method;
|
||||
|
||||
public InternalMethodInvocation(Method method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
protected InternalMethodInvocation() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Object[] getArguments() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Method getMethod() {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
public AccessibleObject getStaticPart() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Object getThis() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Object proceed() throws Throwable {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 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.model.filefolder;
|
||||
|
||||
import org.alfresco.query.AbstractCannedQueryFactory;
|
||||
import org.alfresco.query.CannedQuery;
|
||||
import org.alfresco.query.CannedQueryParameters;
|
||||
import org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityInterceptor;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
|
||||
/**
|
||||
* GetChildren (paged list of FileInfo)
|
||||
*
|
||||
* @author janv
|
||||
* @since 4.0
|
||||
*/
|
||||
public class GetChildrenCannedQueryFactory<FileInfo> extends AbstractCannedQueryFactory<FileInfo>
|
||||
{
|
||||
private NodeService nodeService;
|
||||
private MethodSecurityInterceptor methodSecurityInterceptor;
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
public void setMethodSecurityInterceptor(MethodSecurityInterceptor methodSecurityInterceptor)
|
||||
{
|
||||
this.methodSecurityInterceptor = methodSecurityInterceptor;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public CannedQuery<FileInfo> getCannedQuery(CannedQueryParameters parameters)
|
||||
{
|
||||
String queryExecutionId = super.getQueryExecutionId(parameters);
|
||||
return (CannedQuery<FileInfo>) new GetChildrenCannedQuery(nodeService, methodSecurityInterceptor, parameters, queryExecutionId);
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 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.model.filefolder;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* GetChildren CQ Parameters
|
||||
*
|
||||
* @author janv
|
||||
* @since 4.0
|
||||
*/
|
||||
public class GetChildrenCannedQueryParams
|
||||
{
|
||||
private NodeRef parentRef;
|
||||
private Set<QName> searchTypeQNames;
|
||||
|
||||
public GetChildrenCannedQueryParams(NodeRef parentRef, Set<QName> searchTypeQNames)
|
||||
{
|
||||
this.parentRef = parentRef;
|
||||
this.searchTypeQNames = searchTypeQNames;
|
||||
}
|
||||
|
||||
public NodeRef getParentRef()
|
||||
{
|
||||
return parentRef;
|
||||
}
|
||||
|
||||
public Set<QName> getSearchTypeQNames()
|
||||
{
|
||||
return searchTypeQNames;
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.model.filefolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.model.PagingFileInfoResults;
|
||||
|
||||
/**
|
||||
* TEMP
|
||||
*
|
||||
* @deprecated for review (API is subject to change)
|
||||
*/
|
||||
/* package */ class PagingFileInfoResultsImpl implements PagingFileInfoResults
|
||||
{
|
||||
private List<FileInfo> nodeInfos;
|
||||
private Boolean hasMore; // null => unknown
|
||||
private Long totalCount; // null => not requested (or unknown)
|
||||
|
||||
public PagingFileInfoResultsImpl(List<FileInfo> nodeInfos, Boolean hasMore, Long totalCount)
|
||||
{
|
||||
this.nodeInfos = nodeInfos;
|
||||
this.hasMore = hasMore;
|
||||
this.totalCount= totalCount;
|
||||
}
|
||||
|
||||
public List<FileInfo> getResultsForPage()
|
||||
{
|
||||
return nodeInfos;
|
||||
}
|
||||
|
||||
public Boolean hasMore()
|
||||
{
|
||||
return hasMore;
|
||||
}
|
||||
public Long getTotalCount()
|
||||
{
|
||||
return totalCount;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user