mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
First part of ETHREEOH-3062.
- Fast NodeService.getChildAssocs(types) based API added to ScriptNode for non-xpath based retrieval of file folder child nodes - Optionally retrieve files, folders or both - Optionally ignore certain sub-types e.g. fm:forum - Automatically remove cm:systemfolder sub-types - equivalent to FileFolderService.list() and related methods - Modified Share treenode data webscript to use faster API for child folder node counts git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16980 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -34,7 +34,9 @@ import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -467,6 +469,108 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol
|
||||
return Context.getCurrentContext().newArray(this.scope, getChildrenByXPath(xpath, null, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns a JavaScript array of child file/folder nodes for this nodes.
|
||||
* Automatically retrieves all sub-types of cm:content and cm:folder, also removes
|
||||
* system folder types from the results.
|
||||
* This is equivalent to @see FileFolderService.list()
|
||||
*/
|
||||
public Scriptable childFileFolders()
|
||||
{
|
||||
return childFileFolders(true, true, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param files Return files extending from cm:content
|
||||
* @param folders Return folders extending from cm:folder - ignoring sub-types of cm:systemfolder
|
||||
* @return Returns a JavaScript array of child file/folder nodes for this nodes.
|
||||
* Automatically retrieves all sub-types of cm:content and cm:folder, also removes
|
||||
* system folder types from the results.
|
||||
* This is equivalent to @see FileFolderService.listFiles() and @see FileFolderService.listFolders()
|
||||
*/
|
||||
public Scriptable childFileFolders(boolean files, boolean folders)
|
||||
{
|
||||
return childFileFolders(files, folders, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param files Return files extending from cm:content
|
||||
* @param folders Return folders extending from cm:folder - ignoring sub-types of cm:systemfolder
|
||||
* @return Returns a JavaScript array of child file/folder nodes for this nodes.
|
||||
* Automatically retrieves all sub-types of cm:content and cm:folder, also removes
|
||||
* system folder types from the results.
|
||||
* Also optionally removes additional type qnames. The additional type can be
|
||||
* specified in short or long qname string form as a single string or an Array e.g. "fm:forum".
|
||||
* This is equivalent to @see FileFolderService.listFiles() and @see FileFolderService.listFolders()
|
||||
*/
|
||||
public Scriptable childFileFolders(boolean files, boolean folders, Object ignoreTypes)
|
||||
{
|
||||
Object[] results;
|
||||
|
||||
// Build a list of file and folder types
|
||||
DictionaryService dd = services.getDictionaryService();
|
||||
Set<QName> searchTypeQNames = new HashSet<QName>(16, 1.0f);
|
||||
if (folders)
|
||||
{
|
||||
Collection<QName> qnames = dd.getSubTypes(ContentModel.TYPE_FOLDER, true);
|
||||
searchTypeQNames.addAll(qnames);
|
||||
searchTypeQNames.add(ContentModel.TYPE_FOLDER);
|
||||
}
|
||||
if (files)
|
||||
{
|
||||
Collection<QName> qnames = dd.getSubTypes(ContentModel.TYPE_CONTENT, true);
|
||||
searchTypeQNames.addAll(qnames);
|
||||
searchTypeQNames.add(ContentModel.TYPE_CONTENT);
|
||||
qnames = dd.getSubTypes(ContentModel.TYPE_LINK, true);
|
||||
searchTypeQNames.addAll(qnames);
|
||||
searchTypeQNames.add(ContentModel.TYPE_LINK);
|
||||
}
|
||||
|
||||
// Remove 'system' folder types
|
||||
Collection<QName> qnames = dd.getSubTypes(ContentModel.TYPE_SYSTEM_FOLDER, true);
|
||||
searchTypeQNames.removeAll(qnames);
|
||||
searchTypeQNames.remove(ContentModel.TYPE_SYSTEM_FOLDER);
|
||||
|
||||
// Add user defined types to ignore from the search
|
||||
if (ignoreTypes instanceof ScriptableObject)
|
||||
{
|
||||
Serializable types = getValueConverter().convertValueForRepo((ScriptableObject)ignoreTypes);
|
||||
if (types instanceof List)
|
||||
{
|
||||
for (Serializable typeObj : (List<Serializable>)types)
|
||||
{
|
||||
searchTypeQNames.remove(createQName(typeObj.toString()));
|
||||
}
|
||||
}
|
||||
else if (types instanceof String)
|
||||
{
|
||||
searchTypeQNames.remove(createQName(types.toString()));
|
||||
}
|
||||
}
|
||||
else if (ignoreTypes instanceof String)
|
||||
{
|
||||
searchTypeQNames.remove(createQName(ignoreTypes.toString()));
|
||||
}
|
||||
|
||||
// Perform the query and collect the results
|
||||
if (searchTypeQNames.size() != 0)
|
||||
{
|
||||
List<ChildAssociationRef> childAssocRefs = this.nodeService.getChildAssocs(this.nodeRef, searchTypeQNames);
|
||||
results = new Object[childAssocRefs.size()];
|
||||
for (int i=0; i<childAssocRefs.size(); i++)
|
||||
{
|
||||
ChildAssociationRef assocRef = childAssocRefs.get(i);
|
||||
results[i] = newInstance(assocRef.getChildRef(), this.services, this.scope);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
results = new Object[0];
|
||||
}
|
||||
|
||||
return Context.getCurrentContext().newArray(this.scope, results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the target associations from this Node. As a Map of assoc name to a JavaScript array of Nodes.
|
||||
* The Map returned implements the Scriptable interface to allow access to the assoc arrays via JavaScript
|
||||
|
@@ -0,0 +1,8 @@
|
||||
var results1 = companyhome.childFileFolders();
|
||||
var results2 = companyhome.childFileFolders(true, false);
|
||||
var results3 = companyhome.childFileFolders(false, true);
|
||||
var results4 = companyhome.childFileFolders(false, true, "fm:forums");
|
||||
var types = new Array();
|
||||
types.push("fm:forums");
|
||||
types.push("fm:forum");
|
||||
var results5 = companyhome.childFileFolders(false, true, types);
|
Reference in New Issue
Block a user