mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
fix for AR-654 - saving multi value properties on JavaScript node object
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3078 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -20,6 +20,7 @@ import java.io.Serializable;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -51,7 +52,6 @@ import org.alfresco.service.namespace.QName;
|
|||||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.mozilla.javascript.NativeArray;
|
|
||||||
import org.mozilla.javascript.ScriptableObject;
|
import org.mozilla.javascript.ScriptableObject;
|
||||||
import org.mozilla.javascript.Wrapper;
|
import org.mozilla.javascript.Wrapper;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
@@ -87,7 +87,6 @@ public final class Node implements Serializable
|
|||||||
private NodeRef nodeRef;
|
private NodeRef nodeRef;
|
||||||
private String name;
|
private String name;
|
||||||
private QName type;
|
private QName type;
|
||||||
private String path;
|
|
||||||
private String id;
|
private String id;
|
||||||
private Set<QName> aspects = null;
|
private Set<QName> aspects = null;
|
||||||
private ScriptableQNameMap<String, Serializable> properties = null;
|
private ScriptableQNameMap<String, Serializable> properties = null;
|
||||||
@@ -101,6 +100,7 @@ public final class Node implements Serializable
|
|||||||
private TemplateImageResolver imageResolver = null;
|
private TemplateImageResolver imageResolver = null;
|
||||||
private Node parent = null;
|
private Node parent = null;
|
||||||
private ChildAssociationRef primaryParentAssoc = null;
|
private ChildAssociationRef primaryParentAssoc = null;
|
||||||
|
// NOTE: see the reset() method when adding new cached members!
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
@@ -321,7 +321,7 @@ public final class Node implements Serializable
|
|||||||
for (AssociationRef ref : refs)
|
for (AssociationRef ref : refs)
|
||||||
{
|
{
|
||||||
String qname = ref.getTypeQName().toString();
|
String qname = ref.getTypeQName().toString();
|
||||||
Node[] nodes = (Node[])assocs.get(qname);
|
Node[] nodes = (Node[])this.assocs.get(qname);
|
||||||
if (nodes == null)
|
if (nodes == null)
|
||||||
{
|
{
|
||||||
// first access for the list for this qname
|
// first access for the list for this qname
|
||||||
@@ -333,7 +333,7 @@ public final class Node implements Serializable
|
|||||||
System.arraycopy(nodes, 0, newNodes, 0, nodes.length);
|
System.arraycopy(nodes, 0, newNodes, 0, nodes.length);
|
||||||
nodes = newNodes;
|
nodes = newNodes;
|
||||||
}
|
}
|
||||||
nodes[nodes.length] = new Node(ref.getTargetRef(), this.services, this.imageResolver);
|
nodes[nodes.length - 1] = new Node(ref.getTargetRef(), this.services, this.imageResolver);
|
||||||
|
|
||||||
this.assocs.put(ref.getTypeQName().toString(), nodes);
|
this.assocs.put(ref.getTypeQName().toString(), nodes);
|
||||||
}
|
}
|
||||||
@@ -801,6 +801,37 @@ public final class Node implements Serializable
|
|||||||
// unwrap a Java object from a JavaScript wrapper
|
// unwrap a Java object from a JavaScript wrapper
|
||||||
value = (Serializable)((Wrapper)value).unwrap();
|
value = (Serializable)((Wrapper)value).unwrap();
|
||||||
}
|
}
|
||||||
|
else if (value instanceof ScriptableObject)
|
||||||
|
{
|
||||||
|
// a scriptable object will probably indicate a multi-value property
|
||||||
|
// set using a JavaScript Array object
|
||||||
|
ScriptableObject values = (ScriptableObject)value;
|
||||||
|
|
||||||
|
// convert JavaScript array of values to a List of Serializable objects
|
||||||
|
Object[] propIds = values.getIds();
|
||||||
|
List<Serializable> propValues = new ArrayList<Serializable>(propIds.length);
|
||||||
|
for (int i=0; i<propIds.length; i++)
|
||||||
|
{
|
||||||
|
// work on each key in turn
|
||||||
|
Object propId = propIds[i];
|
||||||
|
|
||||||
|
// we are only interested in keys that indicate a list of values
|
||||||
|
if (propId instanceof Integer)
|
||||||
|
{
|
||||||
|
// get the value out for the specified key - make sure it is Serializable
|
||||||
|
Object val = values.get((Integer)propId, values);
|
||||||
|
if (val instanceof Wrapper)
|
||||||
|
{
|
||||||
|
val = ((Wrapper)val).unwrap();
|
||||||
|
}
|
||||||
|
if (val instanceof Serializable)
|
||||||
|
{
|
||||||
|
propValues.add((Serializable)val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
value = (Serializable)propValues;
|
||||||
|
}
|
||||||
props.put(createQName(key), value);
|
props.put(createQName(key), value);
|
||||||
}
|
}
|
||||||
this.nodeService.setProperties(this.nodeRef, props);
|
this.nodeService.setProperties(this.nodeRef, props);
|
||||||
@@ -920,6 +951,9 @@ public final class Node implements Serializable
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.nodeService.deleteNode(this.nodeRef);
|
this.nodeService.deleteNode(this.nodeRef);
|
||||||
|
|
||||||
|
reset();
|
||||||
|
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
catch (AccessDeniedException accessErr)
|
catch (AccessDeniedException accessErr)
|
||||||
@@ -1004,7 +1038,10 @@ public final class Node implements Serializable
|
|||||||
destination.getNodeRef(),
|
destination.getNodeRef(),
|
||||||
ContentModel.ASSOC_CONTAINS,
|
ContentModel.ASSOC_CONTAINS,
|
||||||
getPrimaryParentAssoc().getQName());
|
getPrimaryParentAssoc().getQName());
|
||||||
this.parent = null; // has been changed - so reset it
|
|
||||||
|
// reset cached values
|
||||||
|
reset();
|
||||||
|
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1083,8 +1120,8 @@ public final class Node implements Serializable
|
|||||||
this.nodeService.addAspect(this.nodeRef, aspectQName, aspectProps);
|
this.nodeService.addAspect(this.nodeRef, aspectQName, aspectProps);
|
||||||
|
|
||||||
// reset the relevant cached node members
|
// reset the relevant cached node members
|
||||||
this.aspects = null;
|
reset();
|
||||||
this.properties = null;
|
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
catch (InvalidAspectException aspectErr)
|
catch (InvalidAspectException aspectErr)
|
||||||
@@ -1117,6 +1154,26 @@ public final class Node implements Serializable
|
|||||||
return qname;
|
return qname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the Node cached state
|
||||||
|
*/
|
||||||
|
private void reset()
|
||||||
|
{
|
||||||
|
this.name = null;
|
||||||
|
this.type = null;
|
||||||
|
this.properties = null;
|
||||||
|
this.aspects = null;
|
||||||
|
this.assocs = null;
|
||||||
|
this.children = null;
|
||||||
|
this.displayPath = null;
|
||||||
|
this.isDocument = null;
|
||||||
|
this.isContainer = null;
|
||||||
|
this.mimetype = null;
|
||||||
|
this.size = null;
|
||||||
|
this.parent = null;
|
||||||
|
this.primaryParentAssoc = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override Object.toString() to provide useful debug output
|
* Override Object.toString() to provide useful debug output
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user