mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged DEV/SWIFT to HEAD
26007: ALF-7070: - null property values - mltext properties include locales and values - content properties include locale, encoding, mimetype, size, id - node pre-loading support - wip - paths include direct paths and category paths 26058: ALF-7070 - fixed null content encoding, mimetype 26301: Merged BRANCHES/DEV/BM to BRANCHES/DEV/SWIFT: 24572: WebDAV - switch lock check (to get prop before status) and use getPrimaryParent 24574: WebDAV - getNodeLockInfo (add request caches for indirect lookup) 24833: BM - WebDAV perf tweak (getNodeLockInfo - including PutMethod / checkNode) (note: related to ALF-6267 / ALF-6224) 26319: Removed System.out messages 26320: Moved away from BaseSpringTest 26321: WIP: ALF-7339: RSOLR 009: Index track and build from SOLR - track simple properties (no locale, no dual tokenisation, no sort, no content, no ml text, no acls) 26322: Merged BRANCHES/DEV/BM to BRANCHES/DEV/SWIFT: 24745: (RECORD ONLY) Adjust Audit Model Registry for Subsystem read write locks 24789: (RECORD ONLY) Remove unsafe use of SimpleDateFormat 24862: (RECORD ONLY) Test content read with larger buffer size 26331: Fixed ibatis -> mybatis merge issues 26350: Build fix: iBatis -> myBatis merge error 26354: Removed svn:mergeinfo git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28257 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -202,13 +202,12 @@ public class GetNodeContent extends StreamContent
|
||||
|
||||
if(transformException != null)
|
||||
{
|
||||
res.setHeader(TRANSFORM_STATUS_HEADER, "failed");
|
||||
res.setHeader(TRANSFORM_STATUS_HEADER, "transformFailed");
|
||||
res.setHeader(TRANSFORM_EXCEPTION_HEADER, transformException.getMessage());
|
||||
res.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||
res.setStatus(HttpStatus.SC_NO_CONTENT);
|
||||
}
|
||||
else
|
||||
{
|
||||
res.setHeader(TRANSFORM_STATUS_HEADER, "ok");
|
||||
res.setStatus(HttpStatus.SC_OK);
|
||||
streamContentImpl(req, res, textReader, false, modified, String.valueOf(modified.getTime()), null);
|
||||
}
|
||||
|
@@ -109,7 +109,29 @@ public class GetNodes extends DeclarativeWebScript
|
||||
includeAspects.add(QName.createQName(aIncludeAspects.getString(i).trim()));
|
||||
}
|
||||
}
|
||||
|
||||
Set<QName> excludeNodeTypes = null;
|
||||
if(o.has("excludeNodeTypes"))
|
||||
{
|
||||
JSONArray aExcludeNodeTypes = o.getJSONArray("excludeNodeTypes");
|
||||
excludeNodeTypes = new HashSet<QName>(aExcludeNodeTypes.length());
|
||||
for(int i = 0; i < aExcludeNodeTypes.length(); i++)
|
||||
{
|
||||
excludeNodeTypes.add(QName.createQName(aExcludeNodeTypes.getString(i).trim()));
|
||||
}
|
||||
}
|
||||
|
||||
Set<QName> includeNodeTypes = null;
|
||||
if(o.has("includeNodeTypes"))
|
||||
{
|
||||
JSONArray aIncludeNodeTypes = o.getJSONArray("includeNodeTypes");
|
||||
includeNodeTypes = new HashSet<QName>(aIncludeNodeTypes.length());
|
||||
for(int i = 0; i < aIncludeNodeTypes.length(); i++)
|
||||
{
|
||||
includeNodeTypes.add(QName.createQName(aIncludeNodeTypes.getString(i).trim()));
|
||||
}
|
||||
}
|
||||
|
||||
// 0 or Integer.MAX_VALUE => ignore
|
||||
int maxResults = o.has("maxResults") ? o.getInt("maxResults") : 0;
|
||||
|
||||
@@ -135,6 +157,8 @@ public class GetNodes extends DeclarativeWebScript
|
||||
nodeParameters.setToNodeId(toNodeId);
|
||||
nodeParameters.setExcludeAspects(excludeAspects);
|
||||
nodeParameters.setIncludeAspects(includeAspects);
|
||||
nodeParameters.setExcludeNodeTypes(excludeNodeTypes);
|
||||
nodeParameters.setIncludeNodeTypes(includeNodeTypes);
|
||||
nodeParameters.setStoreProtocol(storeProtocol);
|
||||
nodeParameters.setStoreIdentifier(storeIdentifier);
|
||||
nodeParameters.setMaxResults(maxResults);
|
||||
|
@@ -36,6 +36,7 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.Path;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
@@ -47,7 +48,6 @@ import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
// TODO how to hook into bulk loading of nodes + properties + aspects?
|
||||
// todo url parameter to remove whitespace in results - make it the default?
|
||||
public class GetNodesMetaData extends DeclarativeWebScript
|
||||
{
|
||||
@@ -217,7 +217,7 @@ public class GetNodesMetaData extends DeclarativeWebScript
|
||||
throw new WebScriptException("Invalid JSON", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Bean to store node meta data for use by FreeMarker templates
|
||||
*/
|
||||
@@ -227,7 +227,7 @@ public class GetNodesMetaData extends DeclarativeWebScript
|
||||
private NodeRef nodeRef;
|
||||
private QName nodeType;
|
||||
private Long aclId;
|
||||
private Map<String, String> properties;
|
||||
private Map<String, PropertyValue> properties;
|
||||
private Set<QName> aspects;
|
||||
private List<String> paths;
|
||||
private List<ChildAssociationRef> childAssocs;
|
||||
@@ -242,30 +242,24 @@ public class GetNodesMetaData extends DeclarativeWebScript
|
||||
|
||||
// convert Paths to Strings
|
||||
List<String> paths = new ArrayList<String>();
|
||||
for(Path path : nodeMetaData.getPaths())
|
||||
for(Pair<Path, QName> pair : nodeMetaData.getPaths())
|
||||
{
|
||||
paths.add(solrSerializer.serializeValue(String.class, path));
|
||||
JSONObject o = new JSONObject();
|
||||
o.put("path", solrSerializer.serializeValue(String.class, pair.getFirst()));
|
||||
o.put("qname", solrSerializer.serializeValue(String.class, pair.getSecond()));
|
||||
paths.add(o.toString(3));
|
||||
}
|
||||
setPaths(paths);
|
||||
|
||||
setChildAssocs(nodeMetaData.getChildAssocs());
|
||||
setAspects(nodeMetaData.getAspects());
|
||||
Map<QName, Serializable> props = nodeMetaData.getProperties();
|
||||
Map<String, String> properties = (props != null ? new HashMap<String, String>(props.size()) : null);
|
||||
Map<String, PropertyValue> properties = (props != null ? new HashMap<String, PropertyValue>(props.size()) : null);
|
||||
for(QName propName : props.keySet())
|
||||
{
|
||||
Serializable value = props.get(propName);
|
||||
// deal with mutli value here
|
||||
// if(value instanceof ContentDataWithId)
|
||||
// {
|
||||
// // special case - ContentDataWithId
|
||||
// properties.put(propName, String.valueOf(((ContentDataWithId)value).getId()));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
properties.put(solrSerializer.serializeValue(String.class, propName),
|
||||
solrSerializer.serialize(propName, value));
|
||||
// }
|
||||
properties.put(solrSerializer.serializeValue(String.class, propName),
|
||||
solrSerializer.serialize(propName, value));
|
||||
}
|
||||
setProperties(properties);
|
||||
}
|
||||
@@ -310,11 +304,11 @@ public class GetNodesMetaData extends DeclarativeWebScript
|
||||
{
|
||||
this.aclId = aclId;
|
||||
}
|
||||
public Map<String, String> getProperties()
|
||||
public Map<String, PropertyValue> getProperties()
|
||||
{
|
||||
return properties;
|
||||
}
|
||||
public void setProperties(Map<String, String> properties)
|
||||
public void setProperties(Map<String, PropertyValue> properties)
|
||||
{
|
||||
this.properties = properties;
|
||||
}
|
||||
|
@@ -1,417 +0,0 @@
|
||||
/*
|
||||
* 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.web.scripts.solr;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Fast and simple JSON stream writer. Wraps a Writer to output a JSON object stream.
|
||||
* No intermediate objects are created - writes are immediate to the underlying stream.
|
||||
* Quoted and correct JSON encoding is performed on string values, - encoding is
|
||||
* not performed on key names - it is assumed they are simple strings. The developer must
|
||||
* call JSONWriter.encodeJSONString() on the key name if required.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
* @author Steve Glover
|
||||
*
|
||||
* Adapted from org.springframework.extensions.webscripts.json.
|
||||
* - added writeValue methods for class versions of primitives
|
||||
*/
|
||||
public final class JSONWriter
|
||||
{
|
||||
private Writer out;
|
||||
private Stack<Boolean> stack = new Stack<Boolean>();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param out The Writer to immediately append values to (no internal buffering)
|
||||
*/
|
||||
public JSONWriter(Writer out)
|
||||
{
|
||||
this.out = out;
|
||||
stack.push(Boolean.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an array structure, the endArray() method must be called later.
|
||||
* NOTE: Within the array, either output objects or use the single arg writeValue() method.
|
||||
*/
|
||||
public void startArray() throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write("[");
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
stack.push(Boolean.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* End an array structure.
|
||||
*/
|
||||
public void endArray() throws IOException
|
||||
{
|
||||
out.write("]");
|
||||
stack.pop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an object structure, the endObject() method must be called later.
|
||||
*/
|
||||
public void startObject() throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write("{");
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
stack.push(Boolean.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* End an object structure.
|
||||
*/
|
||||
public void endObject() throws IOException
|
||||
{
|
||||
out.write("}");
|
||||
stack.pop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a value (outputs just a name key), the endValue() method must be called later.
|
||||
* NOTE: follow with an array or object only.
|
||||
*/
|
||||
public void startValue(String name) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write('"');
|
||||
out.write(name);
|
||||
out.write("\": ");
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
stack.push(Boolean.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* End a value that was started with startValue()
|
||||
*/
|
||||
public void endValue()
|
||||
{
|
||||
stack.pop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a JSON string name and value pair.
|
||||
*/
|
||||
public void writeValue(String name, String value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write('"');
|
||||
out.write(name);
|
||||
out.write("\": \"");
|
||||
out.write(encodeJSONString(value));
|
||||
out.write('"');
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a JSON number name and value pair.
|
||||
*/
|
||||
public void writeValue(String name, int value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write('"');
|
||||
out.write(name);
|
||||
out.write("\": ");
|
||||
out.write(Integer.toString(value));
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
public void writeValue(String name, Integer value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write('"');
|
||||
out.write(name);
|
||||
out.write("\": ");
|
||||
out.write(value.toString());
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a JSON number name and value pair.
|
||||
*/
|
||||
public void writeValue(String name, float value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write('"');
|
||||
out.write(name);
|
||||
out.write("\": ");
|
||||
out.write(Float.toString(value));
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
public void writeValue(String name, Float value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write('"');
|
||||
out.write(name);
|
||||
out.write("\": ");
|
||||
out.write(value.toString());
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Output a JSON boolean name and value pair.
|
||||
*/
|
||||
public void writeValue(String name, boolean value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write('"');
|
||||
out.write(name);
|
||||
out.write("\": ");
|
||||
out.write(Boolean.toString(value));
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
public void writeValue(String name, Boolean value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write('"');
|
||||
out.write(name);
|
||||
out.write("\": ");
|
||||
out.write(value.toString());
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a JSON string value.
|
||||
* NOTE: no name is written - call from within an array structure.
|
||||
*/
|
||||
public void writeValue(String value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(",");
|
||||
out.write('"');
|
||||
out.write(encodeJSONString(value));
|
||||
out.write('"');
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a JSON number value.
|
||||
* NOTE: no name is written - call from within an array structure.
|
||||
*/
|
||||
public void writeValue(int value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write(Integer.toString(value));
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
public void writeValue(Integer value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write(value.toString());
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a JSON long value.
|
||||
* NOTE: no name is written - call from within an array structure.
|
||||
*/
|
||||
public void writeValue(long value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write(Long.toString(value));
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
public void writeValue(Long value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write(value.toString());
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Output a JSON number value.
|
||||
* NOTE: no name is written - call from within an array structure.
|
||||
*/
|
||||
public void writeValue(float value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write(Float.toString(value));
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
public void writeValue(Float value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write(value.toString());
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a JSON boolean value.
|
||||
* NOTE: no name is written - call from within an array structure.
|
||||
*/
|
||||
public void writeValue(boolean value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write(Boolean.toString(value));
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
public void writeValue(Boolean value) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write(value.toString());
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a JSON null value.
|
||||
* NOTE: no name is written - call from within an array structure.
|
||||
*/
|
||||
public void writeNullValue() throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write("null");
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a JSON null value.
|
||||
*/
|
||||
public void writeNullValue(String name) throws IOException
|
||||
{
|
||||
if (stack.peek() == true) out.write(", ");
|
||||
out.write('"');
|
||||
out.write(name);
|
||||
out.write("\": null");
|
||||
stack.pop();
|
||||
stack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Safely encode a JSON string value.
|
||||
* @return encoded string, null is handled and returned as "".
|
||||
*/
|
||||
public static String encodeJSONString(final String s)
|
||||
{
|
||||
if (s == null || s.length() == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
StringBuilder sb = null; // create on demand
|
||||
String enc;
|
||||
char c;
|
||||
int len = s.length();
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
enc = null;
|
||||
c = s.charAt(i);
|
||||
switch (c)
|
||||
{
|
||||
case '\\':
|
||||
enc = "\\\\";
|
||||
break;
|
||||
case '"':
|
||||
enc = "\\\"";
|
||||
break;
|
||||
case '/':
|
||||
enc = "\\/";
|
||||
break;
|
||||
case '\b':
|
||||
enc = "\\b";
|
||||
break;
|
||||
case '\t':
|
||||
enc = "\\t";
|
||||
break;
|
||||
case '\n':
|
||||
enc = "\\n";
|
||||
break;
|
||||
case '\f':
|
||||
enc = "\\f";
|
||||
break;
|
||||
case '\r':
|
||||
enc = "\\r";
|
||||
break;
|
||||
|
||||
default:
|
||||
if (((int)c) >= 0x80)
|
||||
{
|
||||
//encode all non basic latin characters
|
||||
String u = "000" + Integer.toHexString((int)c);
|
||||
enc = "\\u" + u.substring(u.length() - 4);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (enc != null)
|
||||
{
|
||||
if (sb == null)
|
||||
{
|
||||
String soFar = s.substring(0, i);
|
||||
sb = new StringBuilder(i + 8);
|
||||
sb.append(soFar);
|
||||
}
|
||||
sb.append(enc);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sb != null)
|
||||
{
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sb == null)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
else
|
||||
{
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
package org.alfresco.repo.web.scripts.solr;
|
||||
|
||||
/*
|
||||
* Represents a property value to be used by Freemarker
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
class PropertyValue
|
||||
{
|
||||
// is value actually a string or a JSON object or array
|
||||
// if true, enclose the value in double quotes (to represent a JSON string)
|
||||
// when converting to a string.
|
||||
private boolean isString = true;
|
||||
|
||||
private String value;
|
||||
|
||||
public PropertyValue(boolean isString, String value)
|
||||
{
|
||||
super();
|
||||
this.isString = isString;
|
||||
this.value = value;
|
||||
}
|
||||
public boolean isString()
|
||||
{
|
||||
return isString;
|
||||
}
|
||||
public String getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if(isString)
|
||||
{
|
||||
sb.append("\""); // for json strings
|
||||
}
|
||||
sb.append(value);
|
||||
if(isString)
|
||||
{
|
||||
sb.append("\""); // for json strings
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@@ -20,20 +20,22 @@ package org.alfresco.repo.web.scripts.solr;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.domain.node.ContentDataWithId;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.MLText;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.Path;
|
||||
import org.alfresco.service.cmr.repository.Path.AttributeElement;
|
||||
@@ -46,10 +48,11 @@ import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.springframework.extensions.webscripts.json.JSONWriter;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class SOLRSerializer
|
||||
class SOLRSerializer
|
||||
{
|
||||
protected static final Log logger = LogFactory.getLog(SOLRSerializer.class);
|
||||
|
||||
@@ -94,11 +97,12 @@ public class SOLRSerializer
|
||||
return typeConverter.INSTANCE.convert(String.class, value);
|
||||
}
|
||||
|
||||
public String serialize(QName propName, Serializable value) throws IOException
|
||||
@SuppressWarnings("unchecked")
|
||||
public PropertyValue serialize(QName propName, Serializable value) throws IOException, JSONException
|
||||
{
|
||||
if(value == null)
|
||||
{
|
||||
return null;
|
||||
return new PropertyValue(false, "null");
|
||||
}
|
||||
|
||||
PropertyDefinition propertyDef = dictionaryService.getProperty(propName);
|
||||
@@ -106,7 +110,7 @@ public class SOLRSerializer
|
||||
{
|
||||
throw new IllegalArgumentException("Could not find property definition for property " + propName);
|
||||
}
|
||||
|
||||
|
||||
boolean isMulti = propertyDef.isMultiValued();
|
||||
if(isMulti)
|
||||
{
|
||||
@@ -115,27 +119,34 @@ public class SOLRSerializer
|
||||
throw new IllegalArgumentException("Multi value: expected a collection, got " + value.getClass().getName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Serializable> c = (Collection<Serializable>)value;
|
||||
|
||||
StringWriter body = new StringWriter();
|
||||
JSONWriter jsonOut = new JSONWriter(body);
|
||||
jsonOut.startObject();
|
||||
JSONArray body = new JSONArray();
|
||||
for(Serializable o : c)
|
||||
{
|
||||
jsonOut.startArray();
|
||||
for(Serializable o : c)
|
||||
{
|
||||
jsonOut.writeValue(serializeToString(o));
|
||||
}
|
||||
jsonOut.endArray();
|
||||
body.put(serializeValue(String.class, o));
|
||||
}
|
||||
jsonOut.endObject();
|
||||
|
||||
return body.toString();
|
||||
return new PropertyValue(false, body.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
return serializeToString(value);
|
||||
boolean encodeString = true;
|
||||
DataTypeDefinition dataType = propertyDef.getDataType();
|
||||
QName dataTypeName = dataType.getName();
|
||||
if(dataTypeName.equals(DataTypeDefinition.MLTEXT))
|
||||
{
|
||||
encodeString = false;
|
||||
}
|
||||
else if(dataTypeName.equals(DataTypeDefinition.CONTENT))
|
||||
{
|
||||
encodeString = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
encodeString = true;
|
||||
}
|
||||
return new PropertyValue(encodeString, serializeValue(String.class, value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,6 +174,31 @@ public class SOLRSerializer
|
||||
}
|
||||
}
|
||||
|
||||
// MLText
|
||||
INSTANCE.addConverter(MLText.class, String.class, new TypeConverter.Converter<MLText, String>()
|
||||
{
|
||||
public String convert(MLText source)
|
||||
{
|
||||
try
|
||||
{
|
||||
JSONArray array = new JSONArray();
|
||||
for(Locale locale : source.getLocales())
|
||||
{
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("locale", DefaultTypeConverter.INSTANCE.convert(String.class, locale));
|
||||
json.put("value", source.getValue(locale));
|
||||
array.put(json);
|
||||
}
|
||||
|
||||
return array.toString(3);
|
||||
}
|
||||
catch(JSONException e)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Unable to serialize content data to JSON", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// QName
|
||||
INSTANCE.addConverter(QName.class, String.class, new TypeConverter.Converter<QName, String>()
|
||||
{
|
||||
@@ -177,7 +213,23 @@ public class SOLRSerializer
|
||||
{
|
||||
public String convert(ContentDataWithId source)
|
||||
{
|
||||
return String.valueOf(source.getId());
|
||||
JSONObject json = new JSONObject();
|
||||
try
|
||||
{
|
||||
json.put("contentId", String.valueOf(source.getId()));
|
||||
String locale = INSTANCE.convert(String.class, source.getLocale());
|
||||
json.put("locale", locale == null ? JSONObject.NULL : locale);
|
||||
String encoding = source.getEncoding();
|
||||
json.put("encoding", encoding == null ? JSONObject.NULL : encoding);
|
||||
String mimetype = source.getMimetype();
|
||||
json.put("mimetype", mimetype == null ? JSONObject.NULL : mimetype);
|
||||
json.put("size", String.valueOf(source.getSize()));
|
||||
return json.toString(3);
|
||||
}
|
||||
catch(JSONException e)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Unable to serialize content data to JSON", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -300,66 +352,6 @@ public class SOLRSerializer
|
||||
return source.toString();
|
||||
}
|
||||
});
|
||||
|
||||
// TODO should be list of Strings, need to double-check
|
||||
// INSTANCE.addConverter(List.class, Path.class, new TypeConverter.Converter<List, Path>()
|
||||
// {
|
||||
// public Path convert(List source)
|
||||
// {
|
||||
//// try
|
||||
//// {
|
||||
// Path path = new Path();
|
||||
// for(Object pathElementObj : source)
|
||||
// {
|
||||
// String pathElementStr = (String)pathElementObj;
|
||||
// Path.Element pathElement = null;
|
||||
// int idx = pathElementStr.indexOf("|");
|
||||
// if(idx == -1)
|
||||
// {
|
||||
// throw new IllegalArgumentException("Unable to deserialize to Path Element, invalid string " + pathElementStr);
|
||||
// }
|
||||
//
|
||||
// String prefix = pathElementStr.substring(0, idx+1);
|
||||
// String suffix = pathElementStr.substring(idx+1);
|
||||
// if(prefix.equals("a|"))
|
||||
// {
|
||||
// pathElement = INSTANCE.convert(Path.AttributeElement.class, suffix);
|
||||
// }
|
||||
// else if(prefix.equals("p|"))
|
||||
// {
|
||||
// pathElement = INSTANCE.convert(Path.ParentElement.class, suffix);
|
||||
// }
|
||||
// else if(prefix.equals("c|"))
|
||||
// {
|
||||
// pathElement = INSTANCE.convert(Path.ChildAssocElement.class, suffix);
|
||||
// }
|
||||
// else if(prefix.equals("s|"))
|
||||
// {
|
||||
// pathElement = INSTANCE.convert(Path.SelfElement.class, suffix);
|
||||
// }
|
||||
// else if(prefix.equals("ds|"))
|
||||
// {
|
||||
// pathElement = new Path.DescendentOrSelfElement();
|
||||
// }
|
||||
//// else if(prefix.equals("se|"))
|
||||
//// {
|
||||
//// pathElement = new JCRPath.SimpleElement(QName.createQName(suffix));
|
||||
//// }
|
||||
// else
|
||||
// {
|
||||
// throw new IllegalArgumentException("Unable to deserialize to Path, invalid path element string " + pathElementStr);
|
||||
// }
|
||||
//
|
||||
// path.append(pathElement);
|
||||
// }
|
||||
// return path;
|
||||
//// }
|
||||
//// catch(JSONException e)
|
||||
//// {
|
||||
//// throw new IllegalArgumentException(e);
|
||||
//// }
|
||||
// }
|
||||
// });
|
||||
|
||||
// associations
|
||||
INSTANCE.addConverter(ChildAssociationRef.class, String.class, new TypeConverter.Converter<ChildAssociationRef, String>()
|
||||
|
@@ -20,7 +20,6 @@ package org.alfresco.repo.web.scripts.solr;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Serializable;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -171,88 +170,61 @@ public class SOLRWebScriptTest extends BaseWebScriptTest
|
||||
private JSONArray getNodes(GetNodesParameters parameters, int maxResults, int expectedNumNodes) throws Exception
|
||||
{
|
||||
StringBuilder url = new StringBuilder("/api/solr/nodes");
|
||||
StringWriter body = new StringWriter();
|
||||
JSONWriter jsonOut = new JSONWriter(body);
|
||||
|
||||
jsonOut.startObject();
|
||||
JSONObject json = new JSONObject();
|
||||
if(parameters.getTransactionIds() != null)
|
||||
{
|
||||
if(parameters.getTransactionIds() != null)
|
||||
JSONArray array = new JSONArray();
|
||||
for(Long txnId : parameters.getTransactionIds())
|
||||
{
|
||||
jsonOut.startValue("txnIds");
|
||||
{
|
||||
jsonOut.startArray();
|
||||
{
|
||||
for(Long txnId : parameters.getTransactionIds())
|
||||
{
|
||||
jsonOut.writeValue(txnId);
|
||||
}
|
||||
|
||||
}
|
||||
jsonOut.endArray();
|
||||
}
|
||||
jsonOut.endValue();
|
||||
array.put(txnId);
|
||||
}
|
||||
|
||||
if(parameters.getFromNodeId() != null)
|
||||
{
|
||||
jsonOut.writeValue("fromNodeId", parameters.getFromNodeId());
|
||||
}
|
||||
if(parameters.getToNodeId() != null)
|
||||
{
|
||||
jsonOut.writeValue("toNodeId", parameters.getToNodeId());
|
||||
}
|
||||
if(parameters.getExcludeAspects() != null)
|
||||
{
|
||||
jsonOut.startValue("excludeAspects");
|
||||
{
|
||||
jsonOut.startArray();
|
||||
{
|
||||
for(QName excludeAspect : parameters.getExcludeAspects())
|
||||
{
|
||||
jsonOut.writeValue(excludeAspect.toString());
|
||||
}
|
||||
}
|
||||
jsonOut.endArray();
|
||||
}
|
||||
jsonOut.endValue();
|
||||
}
|
||||
if(parameters.getIncludeAspects() != null)
|
||||
{
|
||||
jsonOut.startValue("includeAspects");
|
||||
{
|
||||
jsonOut.startArray();
|
||||
{
|
||||
for(QName includeAspect : parameters.getIncludeAspects())
|
||||
{
|
||||
jsonOut.writeValue(includeAspect.toString());
|
||||
}
|
||||
}
|
||||
jsonOut.endArray();
|
||||
}
|
||||
jsonOut.endValue();
|
||||
}
|
||||
|
||||
if(parameters.getStoreProtocol() != null)
|
||||
{
|
||||
jsonOut.writeValue("storeProtocol", parameters.getStoreProtocol());
|
||||
}
|
||||
|
||||
if(parameters.getStoreIdentifier() != null)
|
||||
{
|
||||
jsonOut.writeValue("storeIdentifier", parameters.getStoreIdentifier());
|
||||
}
|
||||
|
||||
jsonOut.writeValue("maxResults", maxResults);
|
||||
json.put("txnIds", array);
|
||||
}
|
||||
jsonOut.endObject();
|
||||
|
||||
if(parameters.getFromNodeId() != null)
|
||||
{
|
||||
json.put("fromNodeId", parameters.getFromNodeId());
|
||||
}
|
||||
|
||||
// if(maxResults != null)
|
||||
// {
|
||||
// url.append("&maxResults=");
|
||||
// url.append(maxResults);
|
||||
// }
|
||||
if(parameters.getToNodeId() != null)
|
||||
{
|
||||
json.put("toNodeId", parameters.getToNodeId());
|
||||
}
|
||||
|
||||
if(parameters.getExcludeAspects() != null)
|
||||
{
|
||||
JSONArray array = new JSONArray();
|
||||
for(QName excludeAspect : parameters.getExcludeAspects())
|
||||
{
|
||||
array.put(excludeAspect.toString());
|
||||
}
|
||||
json.put("excludeAspects", array);
|
||||
}
|
||||
|
||||
if(parameters.getIncludeAspects() != null)
|
||||
{
|
||||
JSONArray array = new JSONArray();
|
||||
for(QName includeAspect : parameters.getIncludeAspects())
|
||||
{
|
||||
array.put(includeAspect.toString());
|
||||
}
|
||||
json.put("includeAspects", array);
|
||||
}
|
||||
|
||||
TestWebScriptServer.PostRequest req = new TestWebScriptServer.PostRequest(url.toString(), body.toString(), "application/json");
|
||||
if(parameters.getStoreProtocol() != null)
|
||||
{
|
||||
json.put("storeProtocol", parameters.getStoreProtocol());
|
||||
}
|
||||
|
||||
if(parameters.getStoreIdentifier() != null)
|
||||
{
|
||||
json.put("storeIdentifier", parameters.getStoreIdentifier());
|
||||
}
|
||||
|
||||
json.put("maxResults", maxResults);
|
||||
|
||||
TestWebScriptServer.PostRequest req = new TestWebScriptServer.PostRequest(url.toString(), json.toString(), "application/json");
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
Response response = sendRequest(req, Status.STATUS_OK, admin);
|
||||
@@ -265,10 +237,10 @@ public class SOLRWebScriptTest extends BaseWebScriptTest
|
||||
logger.debug(response.getContentAsString());
|
||||
}
|
||||
//System.out.println("getNodes: " + response.getContentAsString());
|
||||
JSONObject json = new JSONObject(response.getContentAsString());
|
||||
json.write(new PrintWriter(System.out));
|
||||
JSONObject jsonResponse = new JSONObject(response.getContentAsString());
|
||||
jsonResponse.write(new PrintWriter(System.out));
|
||||
|
||||
JSONArray nodes = json.getJSONArray("nodes");
|
||||
JSONArray nodes = jsonResponse.getJSONArray("nodes");
|
||||
|
||||
//assertEquals("Node count is incorrect", nodes.length(), json.getInt("count"));
|
||||
|
||||
@@ -565,30 +537,21 @@ public class SOLRWebScriptTest extends BaseWebScriptTest
|
||||
private JSONArray getNodesMetaData(List<Long> nodeIds, int maxResults, int numMetaDataNodes) throws Exception
|
||||
{
|
||||
StringBuilder url = new StringBuilder("/api/solr/metadata");
|
||||
StringWriter body = new StringWriter();
|
||||
JSONWriter jsonOut = new JSONWriter(body);
|
||||
|
||||
jsonOut.startObject();
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
if(nodeIds != null && nodeIds.size() > 0)
|
||||
{
|
||||
if(nodeIds != null && nodeIds.size() > 0)
|
||||
JSONArray array = new JSONArray();
|
||||
for(Long nodeId : nodeIds)
|
||||
{
|
||||
jsonOut.startValue("nodeIds");
|
||||
{
|
||||
jsonOut.startArray();
|
||||
for(Long nodeId : nodeIds)
|
||||
{
|
||||
jsonOut.writeValue(nodeId);
|
||||
}
|
||||
jsonOut.endArray();
|
||||
}
|
||||
jsonOut.endValue();
|
||||
array.put(nodeId);
|
||||
}
|
||||
|
||||
jsonOut.writeValue("maxResults", maxResults);
|
||||
json.put("nodeIds", array);
|
||||
}
|
||||
jsonOut.endObject();
|
||||
|
||||
TestWebScriptServer.PostRequest req = new TestWebScriptServer.PostRequest(url.toString(), body.toString(), "application/json");
|
||||
json.put("maxResults", maxResults);
|
||||
|
||||
TestWebScriptServer.PostRequest req = new TestWebScriptServer.PostRequest(url.toString(), json.toString(), "application/json");
|
||||
long startTime = System.currentTimeMillis();
|
||||
Response response = sendRequest(req, Status.STATUS_OK, admin);
|
||||
long endTime = System.currentTimeMillis();
|
||||
@@ -600,9 +563,9 @@ public class SOLRWebScriptTest extends BaseWebScriptTest
|
||||
logger.debug("nodesMetaData = " + content);
|
||||
}
|
||||
|
||||
JSONObject json = new JSONObject(content);
|
||||
JSONObject jsonResponse = new JSONObject(content);
|
||||
|
||||
JSONArray nodes = json.getJSONArray("nodes");
|
||||
JSONArray nodes = jsonResponse.getJSONArray("nodes");
|
||||
|
||||
System.out.println("Got metadata for " + nodes.length() + " nodes in " + (endTime - startTime) + " ms");
|
||||
|
||||
@@ -648,7 +611,7 @@ public class SOLRWebScriptTest extends BaseWebScriptTest
|
||||
});
|
||||
}
|
||||
|
||||
public void testGetTransactions1() throws Exception
|
||||
/* public void testGetTransactions1() throws Exception
|
||||
{
|
||||
long fromCommitTime = System.currentTimeMillis();
|
||||
|
||||
@@ -1046,7 +1009,7 @@ public class SOLRWebScriptTest extends BaseWebScriptTest
|
||||
parameters.setTransactionIds(transactionIds);
|
||||
parameters.setExcludeAspects(excludeAspects);
|
||||
JSONArray nodes = getNodes(parameters, 0, 51);
|
||||
}
|
||||
}*/
|
||||
|
||||
public void testNodeMetaData() throws Exception
|
||||
{
|
||||
@@ -1092,9 +1055,12 @@ public class SOLRWebScriptTest extends BaseWebScriptTest
|
||||
List<Path> expectedPaths = nodeService.getPaths(expectedNodeRef, false);
|
||||
for(int i = 0; i < paths.length(); i++)
|
||||
{
|
||||
String path = paths.getString(i);
|
||||
JSONObject o = paths.getJSONObject(i);
|
||||
String path = o.getString("path");
|
||||
String qname = o.has("qname") ? o.getString("qname") : null;
|
||||
String expectedPath = expectedPaths.get(i).toString();
|
||||
assertEquals("Path element " + i + " is incorrect", expectedPath, path);
|
||||
assertNull("qname should be null", qname);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user