mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
New NodeType and AspectName evaluators that use metadata webscript
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13675 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -31,6 +31,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -2367,12 +2369,12 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol
|
|||||||
/**
|
/**
|
||||||
* Returns the JSON representation of this node.
|
* Returns the JSON representation of this node.
|
||||||
*
|
*
|
||||||
* NOTE: This is a temporary method to support the /api/metadata web script
|
* @param useShortQNames if true short-form qnames will be returned, else long-form.
|
||||||
*
|
|
||||||
* @return The JSON representation of this node
|
* @return The JSON representation of this node
|
||||||
*/
|
*/
|
||||||
public String toJSON()
|
public String toJSON(boolean useShortQNames)
|
||||||
{
|
{
|
||||||
|
// This method is used by the /api/metadata web script
|
||||||
String jsonStr = "{}";
|
String jsonStr = "{}";
|
||||||
|
|
||||||
if (this.nodeService.exists(nodeRef))
|
if (this.nodeService.exists(nodeRef))
|
||||||
@@ -2385,14 +2387,47 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol
|
|||||||
{
|
{
|
||||||
// add type info
|
// add type info
|
||||||
json.put("nodeRef", this.getNodeRef().toString());
|
json.put("nodeRef", this.getNodeRef().toString());
|
||||||
json.put("type", this.getType());
|
|
||||||
|
String typeString = useShortQNames ? getShortQName(this.getQNameType())
|
||||||
|
: this.getType();
|
||||||
|
json.put("type", typeString);
|
||||||
json.put("mimetype", this.getMimetype());
|
json.put("mimetype", this.getMimetype());
|
||||||
|
|
||||||
// add properties
|
// add properties
|
||||||
json.put("properties", this.nodeService.getProperties(this.nodeRef));
|
Map<QName, Serializable> nodeProperties = this.nodeService.getProperties(this.nodeRef);
|
||||||
|
if (useShortQNames)
|
||||||
|
{
|
||||||
|
Map<String, Serializable> nodePropertiesShortQNames
|
||||||
|
= new LinkedHashMap<String, Serializable>(nodeProperties.size());
|
||||||
|
for (QName nextLongQName : nodeProperties.keySet())
|
||||||
|
{
|
||||||
|
String nextShortQName = getShortQName(nextLongQName);
|
||||||
|
nodePropertiesShortQNames.put(nextShortQName, nodeProperties.get(nextLongQName));
|
||||||
|
}
|
||||||
|
json.put("properties", nodePropertiesShortQNames);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
json.put("properties", nodeProperties);
|
||||||
|
}
|
||||||
|
|
||||||
// add aspects as an array
|
// add aspects as an array
|
||||||
json.put("aspects", this.nodeService.getAspects(this.nodeRef));
|
Set<QName> nodeAspects = this.nodeService.getAspects(this.nodeRef);
|
||||||
|
if (useShortQNames)
|
||||||
|
{
|
||||||
|
Set<String> nodeAspectsShortQNames
|
||||||
|
= new LinkedHashSet<String>(nodeAspects.size());
|
||||||
|
for (QName nextLongQName : nodeAspects)
|
||||||
|
{
|
||||||
|
String nextShortQName = getShortQName(nextLongQName);
|
||||||
|
nodeAspectsShortQNames.add(nextShortQName);
|
||||||
|
}
|
||||||
|
json.put("aspects", nodeAspectsShortQNames);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
json.put("aspects", nodeAspects);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (JSONException error)
|
catch (JSONException error)
|
||||||
{
|
{
|
||||||
@@ -2406,6 +2441,29 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol
|
|||||||
return jsonStr;
|
return jsonStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the JSON representation of this node. Long-form QNames are used in the
|
||||||
|
* result.
|
||||||
|
*
|
||||||
|
* @return The JSON representation of this node
|
||||||
|
*/
|
||||||
|
public String toJSON()
|
||||||
|
{
|
||||||
|
return this.toJSON(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a long-form QName, this method uses the namespace service to create a
|
||||||
|
* short-form QName string.
|
||||||
|
*
|
||||||
|
* @param longQName
|
||||||
|
* @return the short form of the QName string, e.g. "cm:content"
|
||||||
|
*/
|
||||||
|
private String getShortQName(QName longQName)
|
||||||
|
{
|
||||||
|
return longQName.toPrefixString(services.getNamespaceService());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to create a QName from either a fully qualified or short-name QName string
|
* Helper to create a QName from either a fully qualified or short-name QName string
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user