From 426b213db7e9b798b6c2fef444bf36fe5c5f5721 Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Mon, 30 May 2011 16:15:56 +0000 Subject: [PATCH] Merged DEV/SWIFT to HEAD 25834: ALF-7070: more tweaks to node properties serialization ALF-7071: initial checkin SOLR API client library: node metadata, node text content 25869: ALF-6862 - When performing XML Metadata Extraction on a file with a DTD, if the DTD cannot be found then re-try the extraction with a parser that ignores DTDs. Includes unit tests for a file with and without a DTD, showing we now correctly process both. 25892: OpenCMIS - add multi-filing support to CMIS getObjectParents() - update OpenCMIS libraries 25905: Push the DataList model namespace definition into a constant in NameSpaceService in the usual pattern, rather than being hard coded in a util class 25922: (RECORD ONLY) Fix version number git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28115 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../solr/getNodeContent.get.desc.xml | 3 +- .../org/alfresco/repository/solr/solr.lib.ftl | 16 +- .../web-scripts-application-context.xml | 7 +- .../repo/web/scripts/solr/GetNodeContent.java | 204 ++++ .../web/scripts/solr/GetNodesMetaData.java | 65 +- .../repo/web/scripts/solr/NodeMetaData.java | 9 + .../repo/web/scripts/solr/SOLRSerializer.java | 397 +++++++ .../web/scripts/solr/SOLRWebScriptTest.java | 1006 ++++++++--------- .../solr/test/SOLRSerializerTests.java | 257 ----- 9 files changed, 1170 insertions(+), 794 deletions(-) create mode 100644 source/java/org/alfresco/repo/web/scripts/solr/GetNodeContent.java create mode 100644 source/java/org/alfresco/repo/web/scripts/solr/SOLRSerializer.java delete mode 100644 source/java/org/alfresco/repo/web/scripts/solr/test/SOLRSerializerTests.java diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/getNodeContent.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/getNodeContent.get.desc.xml index 3322d660a2..f994c2a04e 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/getNodeContent.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/getNodeContent.get.desc.xml @@ -1,7 +1,8 @@ Get node property content as text Get the content for the node property as text. - /api/solr/{nodeId}/{propertyQName?}/textContent + /api/solr/textContent/{nodeId} + /api/solr/textContent/{nodeId}/{propertyQName} argument admin required diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/solr.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/solr.lib.ftl index 0f5d86858f..0794a417cb 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/solr.lib.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/solr.lib.ftl @@ -26,8 +26,11 @@ TODO property values: string, number, date (at the moment all output as string) "aclId": <#if filter.includeAclId??><#if nodeMetaData.aclId??>${nodeMetaData.aclId?c}<#else>null, <#if filter.includeProperties??> "properties": { - <#list nodeMetaData.properties?keys as propQName> - <@qNameJSON qName=propQName/>: ${nodeMetaData.properties[propQName]}<#if propQName_has_next>, + <#list nodeMetaData.properties?keys as propName> + "${propName}": "${nodeMetaData.properties[propName]}"<#if propName_has_next>, +<#-- + <@qNameJSON qName=propQName/>: "${nodeMetaData.properties[propQName]}"<#if propQName_has_next>, +--> }, @@ -41,7 +44,10 @@ TODO property values: string, number, date (at the moment all output as string) <#if filter.includePaths??> "paths": [ <#list nodeMetaData.paths as path> + "${path}"<#if path_has_next>, +<#-- <@pathJSON path=path indent=""/><#if path_has_next>, +--> ] @@ -49,7 +55,11 @@ TODO property values: string, number, date (at the moment all output as string) <#macro pathJSON path indent=""> -${indent}"${path.toString()}" +${indent}[ +<#list path as element> +${indent}"${element}"<#if element_has_next>, + +${indent}] <#macro qNameJSON qName indent=""> diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 0375c344ff..9540c9e2ed 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1226,8 +1226,9 @@ - + + - + diff --git a/source/java/org/alfresco/repo/web/scripts/solr/GetNodeContent.java b/source/java/org/alfresco/repo/web/scripts/solr/GetNodeContent.java new file mode 100644 index 0000000000..767c359563 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/solr/GetNodeContent.java @@ -0,0 +1,204 @@ +package org.alfresco.repo.web.scripts.solr; + +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.Map; + +import javax.servlet.http.HttpServletResponse; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.content.MimetypeMap; +import org.alfresco.repo.content.transform.ContentTransformer; +import org.alfresco.repo.domain.node.NodeDAO; +import org.alfresco.repo.web.scripts.content.StreamContent; +import org.alfresco.service.cmr.repository.ContentIOException; +import org.alfresco.service.cmr.repository.ContentReader; +import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.TransformationOptions; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.Pair; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.extensions.webscripts.WebScriptException; +import org.springframework.extensions.webscripts.WebScriptRequest; +import org.springframework.extensions.webscripts.WebScriptResponse; + +/** + * + * A web service to return the text content (transformed if required) of a node's + * content property. + * + * @since 4.0 + * + */ +public class GetNodeContent extends StreamContent +{ + private static final Log logger = LogFactory.getLog(GetNodeContent.class); + + /** + * format definied by RFC 822, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3 + */ + private static final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE', 'dd' 'MMM' 'yyyy' 'HH:mm:ss' 'Z", Locale.US); + + private NodeDAO nodeDAO; + private NodeService nodeService; + private ContentService contentService; + + public void setNodeDAO(NodeDAO nodeDAO) + { + this.nodeDAO = nodeDAO; + } + + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + public void setContentService(ContentService contentService) + { + this.contentService = contentService; + } + + /** + * @see org.alfresco.web.scripts.WebScript#execute(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse) + */ + public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException + { + ContentReader textReader = null; + Exception transformException = null; + Map templateVars = req.getServiceMatch().getTemplateVars(); + + String nodeIDString = templateVars.get("nodeId"); + if(nodeIDString == null) + { + throw new WebScriptException("nodeID parameter is required for GetNodeContent"); + } + long nodeId = Long.valueOf(nodeIDString).longValue(); + + String propertyQName = templateVars.get("propertyQName"); + QName propertyName = null; + if(propertyQName == null) + { + propertyName = ContentModel.PROP_CONTENT; + } + else + { + propertyName = QName.createQName(propertyQName); + } + Pair pair = nodeDAO.getNodePair(nodeId); + if(pair == null) + { + throw new WebScriptException("Node id does not exist"); + } + NodeRef nodeRef = pair.getSecond(); + + // check If-Modified-Since header and set Last-Modified header as appropriate + Date modified = (Date)nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED); + long modifiedSince = -1; + String modifiedSinceStr = req.getHeader("If-Modified-Since"); + if(modifiedSinceStr != null) + { + try + { + modifiedSince = dateFormat.parse(modifiedSinceStr).getTime(); + } + catch (Throwable e) + { + if (logger.isInfoEnabled()) + { + logger.info("Browser sent badly-formatted If-Modified-Since header: " + modifiedSinceStr); + } + } + + if (modifiedSince > 0L) + { + // round the date to the ignore millisecond value which is not supplied by header + long modDate = (modified.getTime() / 1000L) * 1000L; + if (modDate <= modifiedSince) + { + res.setStatus(HttpServletResponse.SC_NOT_MODIFIED); + return; + } + } + } + + ContentReader reader = contentService.getReader(nodeRef, propertyName); + if(reader == null) + { + res.setStatus(HttpStatus.SC_NO_CONTENT); + return; + } + + // optimisation - already text so just return the content directly + // TODO - better way of doing this? + if(reader.getMimetype().startsWith("text/")) + { + textReader = reader; + } + else + { + ContentWriter writer = contentService.getTempWriter(); + writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); + writer.setEncoding("UTF-8"); + + TransformationOptions options = new TransformationOptions(); + ContentTransformer transformer = contentService.getTransformer(reader.getMimetype(), MimetypeMap.MIMETYPE_TEXT_PLAIN); + if(transformer == null) + { + res.setStatus(HttpStatus.SC_NO_CONTENT); + return; + } + + + try + { + // TODO how to ensure UTF-8? + transformer.transform(reader, writer); + } + catch (ContentIOException e) + { + transformException = e; + } + + if(transformException == null) + { + // point the reader to the new-written content + textReader = writer.getReader(); + // Check that the reader is a view onto something concrete + if (textReader == null || !textReader.exists()) + { + transformException = new ContentIOException("The transformation did not write any content, yet: \n" + + " transformer: " + transformer + "\n" + " temp writer: " + writer); + } + } + } + + if(transformException != null) + { + res.setHeader("XAlfresco-transformException", transformException.getMessage()); + res.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); + } + else + { + streamContentImpl(req, res, textReader, false, modified, String.valueOf(modified.getTime()), null); + } + + /* writer.addListener(new ContentStreamListener() + { + + @Override + public void contentStreamClosed() throws ContentIOException + { + // TODO Auto-generated method stub + + } + + });*/ + } +} diff --git a/source/java/org/alfresco/repo/web/scripts/solr/GetNodesMetaData.java b/source/java/org/alfresco/repo/web/scripts/solr/GetNodesMetaData.java index e342b0ae1d..3eb63b770f 100644 --- a/source/java/org/alfresco/repo/web/scripts/solr/GetNodesMetaData.java +++ b/source/java/org/alfresco/repo/web/scripts/solr/GetNodesMetaData.java @@ -8,7 +8,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.alfresco.repo.domain.node.ContentDataWithId; +import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.domain.solr.MetaDataResultsFilter; import org.alfresco.repo.domain.solr.NodeMetaData; import org.alfresco.repo.domain.solr.NodeMetaDataParameters; @@ -18,7 +18,6 @@ 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.SOLRSerializer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONArray; @@ -160,8 +159,15 @@ public class GetNodesMetaData extends DeclarativeWebScript { // need to perform data structure conversions that are compatible with Freemarker // e.g. Serializable -> String, QName -> String (because map keys must be string, number) - FreemarkerNodeMetaData fNodeMetaData = new FreemarkerNodeMetaData(solrSerializer, nodeMetaData); - nodesMetaData.add(fNodeMetaData); + try + { + FreemarkerNodeMetaData fNodeMetaData = new FreemarkerNodeMetaData(solrSerializer, nodeMetaData); + nodesMetaData.add(fNodeMetaData); + } + catch(Exception e) + { + throw new AlfrescoRuntimeException("Problem converting to Freemarker", e); + } if(noSizeCalculated && --counter == 0) { @@ -194,47 +200,54 @@ public class GetNodesMetaData extends DeclarativeWebScript } } + /* + * Bean to store node meta data for use by FreeMarker templates + */ public static class FreemarkerNodeMetaData { private Long nodeId; private NodeRef nodeRef; private QName nodeType; private Long aclId; - private Map properties; + private Map properties; private Set aspects; - private List paths; + private List paths; private List childAssocs; - - public FreemarkerNodeMetaData(SOLRSerializer solrSerializer, NodeMetaData nodeMetaData) + + @SuppressWarnings("unchecked") + public FreemarkerNodeMetaData(SOLRSerializer solrSerializer, NodeMetaData nodeMetaData) throws IOException, JSONException { setNodeId(nodeMetaData.getNodeId()); setAclId(nodeMetaData.getAclId()); setNodeRef(nodeMetaData.getNodeRef()); setNodeType(nodeMetaData.getNodeType()); - // TODO need to use SOLRTypeConverter to serialize Path + // convert Paths to Strings + List paths = new ArrayList(); for(Path path : nodeMetaData.getPaths()) { - + paths.add(solrSerializer.serializeValue(String.class, path)); } - setPaths(nodeMetaData.getPaths()); + setPaths(paths); + setChildAssocs(nodeMetaData.getChildAssocs()); setAspects(nodeMetaData.getAspects()); Map props = nodeMetaData.getProperties(); - Map properties = (props != null ? new HashMap(props.size()) : null); + Map properties = (props != null ? new HashMap(props.size()) : null); for(QName propName : props.keySet()) { Serializable value = props.get(propName); - - if(value instanceof ContentDataWithId) - { - // special case - ContentDataWithId - properties.put(propName.toString(), ((ContentDataWithId)value).getId()); - } - else - { - properties.put(propName.toString(), solrSerializer.serialize(propName, value)); - } +// 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)); +// } } setProperties(properties); } @@ -247,11 +260,11 @@ public class GetNodesMetaData extends DeclarativeWebScript { this.nodeRef = nodeRef; } - public List getPaths() + public List getPaths() { return paths; } - public void setPaths(List paths) + public void setPaths(List paths) { this.paths = paths; } @@ -279,11 +292,11 @@ public class GetNodesMetaData extends DeclarativeWebScript { this.aclId = aclId; } - public Map getProperties() + public Map getProperties() { return properties; } - public void setProperties(Map properties) + public void setProperties(Map properties) { this.properties = properties; } diff --git a/source/java/org/alfresco/repo/web/scripts/solr/NodeMetaData.java b/source/java/org/alfresco/repo/web/scripts/solr/NodeMetaData.java index e97194583a..6fff5955c4 100644 --- a/source/java/org/alfresco/repo/web/scripts/solr/NodeMetaData.java +++ b/source/java/org/alfresco/repo/web/scripts/solr/NodeMetaData.java @@ -73,4 +73,13 @@ public class NodeMetaData { this.paths = paths; } + + @Override + public String toString() + { + return "NodeMetaData [id=" + id + ", nodeRef=" + nodeRef + ", type=" + type + ", aclId=" + aclId + + ", properties=" + properties + ", aspects=" + aspects + ", paths=" + paths + "]"; + } + + } diff --git a/source/java/org/alfresco/repo/web/scripts/solr/SOLRSerializer.java b/source/java/org/alfresco/repo/web/scripts/solr/SOLRSerializer.java new file mode 100644 index 0000000000..12f663a846 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/solr/SOLRSerializer.java @@ -0,0 +1,397 @@ +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.Map; +import java.util.Set; + +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.NodeRef; +import org.alfresco.service.cmr.repository.Path; +import org.alfresco.service.cmr.repository.Path.AttributeElement; +import org.alfresco.service.cmr.repository.Path.ChildAssocElement; +import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; +import org.alfresco.service.cmr.repository.datatype.TypeConverter; +import org.alfresco.service.cmr.repository.datatype.TypeConverter.Converter; +import org.alfresco.service.namespace.NamespaceService; +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.JSONException; +import org.springframework.extensions.webscripts.json.JSONWriter; + +public class SOLRSerializer +{ + protected static final Log logger = LogFactory.getLog(SOLRSerializer.class); + + private Set NUMBER_TYPES; + + private DictionaryService dictionaryService; + private NamespaceService namespaceService; + + private SOLRTypeConverter typeConverter; + + public void init() + { + PropertyCheck.mandatory(this, "dictionaryService", dictionaryService); + PropertyCheck.mandatory(this, "namespaceService", namespaceService); + + NUMBER_TYPES = new HashSet(4); + NUMBER_TYPES.add(DataTypeDefinition.DOUBLE); + NUMBER_TYPES.add(DataTypeDefinition.FLOAT); + NUMBER_TYPES.add(DataTypeDefinition.INT); + NUMBER_TYPES.add(DataTypeDefinition.LONG); + + typeConverter = new SOLRTypeConverter(namespaceService); + } + + public void setDictionaryService(DictionaryService dictionaryService) + { + this.dictionaryService = dictionaryService; + } + + public void setNamespaceService(NamespaceService namespaceService) + { + this.namespaceService = namespaceService; + } + + public T serializeValue(Class targetClass, Object value) throws JSONException + { + return typeConverter.INSTANCE.convert(targetClass, value); + } + + public String serializeToString(Serializable value) + { + return typeConverter.INSTANCE.convert(String.class, value); + } + + public String serialize(QName propName, Serializable value) throws IOException + { + if(value == null) + { + return null; + } + + PropertyDefinition propertyDef = dictionaryService.getProperty(propName); + if(propertyDef == null) + { + throw new IllegalArgumentException("Could not find property definition for property " + propName); + } + + boolean isMulti = propertyDef.isMultiValued(); + if(isMulti) + { + if(!(value instanceof Collection)) + { + throw new IllegalArgumentException("Multi value: expected a collection, got " + value.getClass().getName()); + } + + @SuppressWarnings("unchecked") + Collection c = (Collection)value; + + StringWriter body = new StringWriter(); + JSONWriter jsonOut = new JSONWriter(body); + jsonOut.startObject(); + { + jsonOut.startArray(); + for(Serializable o : c) + { + jsonOut.writeValue(serializeToString(o)); + } + jsonOut.endArray(); + } + jsonOut.endObject(); + + return body.toString(); + } + else + { + return serializeToString(value); + } + } + + @SuppressWarnings("rawtypes") + private class SOLRTypeConverter + { + private NamespaceService namespaceService; + TypeConverter INSTANCE = new TypeConverter(); + + @SuppressWarnings("unchecked") + SOLRTypeConverter(NamespaceService namespaceService) + { + this.namespaceService = namespaceService; + + // add all default converters to this converter + // TODO find a better way of doing this + Map, Map, Converter>> converters = DefaultTypeConverter.INSTANCE.getConverters(); + for(Class source : converters.keySet()) + { + Map, Converter> converters1 = converters.get(source); + for(Class dest : converters1.keySet()) + { + Converter converter = converters1.get(dest); + INSTANCE.addConverter(source, dest, converter); + } + } + + // QName + INSTANCE.addConverter(QName.class, String.class, new TypeConverter.Converter() + { + public String convert(QName source) + { + return source.toPrefixString(SOLRTypeConverter.this.namespaceService); + } + }); + + // content + INSTANCE.addConverter(ContentDataWithId.class, String.class, new TypeConverter.Converter() + { + public String convert(ContentDataWithId source) + { + return String.valueOf(source.getId()); + } + }); + + // node refs + INSTANCE.addConverter(NodeRef.class, String.class, new TypeConverter.Converter() + { + public String convert(NodeRef source) + { + return source.toString(); + } + }); + + INSTANCE.addConverter(String.class, NodeRef.class, new TypeConverter.Converter() + { + public NodeRef convert(String source) + { + return new NodeRef(source); + } + }); + + // paths + INSTANCE.addConverter(AttributeElement.class, String.class, new TypeConverter.Converter() + { + public String convert(AttributeElement source) + { + return source.toString(); + } + }); + + INSTANCE.addConverter(ChildAssocElement.class, String.class, new TypeConverter.Converter() + { + public String convert(ChildAssocElement source) + { + return source.getRef().toString(); + } + }); + + INSTANCE.addConverter(Path.DescendentOrSelfElement.class, String.class, new TypeConverter.Converter() + { + public String convert(Path.DescendentOrSelfElement source) + { + return source.toString(); + } + }); + + INSTANCE.addConverter(Path.ParentElement.class, String.class, new TypeConverter.Converter() + { + public String convert(Path.ParentElement source) + { + return source.toString(); + } + }); + + INSTANCE.addConverter(Path.SelfElement.class, String.class, new TypeConverter.Converter() + { + public String convert(Path.SelfElement source) + { + return source.toString(); + } + }); + + INSTANCE.addConverter(String.class, AttributeElement.class, new TypeConverter.Converter() + { + public AttributeElement convert(String source) + { + return new Path.AttributeElement(source); + } + }); + + INSTANCE.addConverter(String.class, ChildAssocElement.class, new TypeConverter.Converter() + { + public ChildAssocElement convert(String source) + { + return new Path.ChildAssocElement(INSTANCE.convert(ChildAssociationRef.class, source)); + } + }); + + INSTANCE.addConverter(String.class, Path.DescendentOrSelfElement.class, new TypeConverter.Converter() + { + public Path.DescendentOrSelfElement convert(String source) + { + return new Path.DescendentOrSelfElement(); + } + }); + + INSTANCE.addConverter(String.class, Path.ParentElement.class, new TypeConverter.Converter() + { + public Path.ParentElement convert(String source) + { + return new Path.ParentElement(); + } + }); + + INSTANCE.addConverter(String.class, Path.SelfElement.class, new TypeConverter.Converter() + { + public Path.SelfElement convert(String source) + { + return new Path.SelfElement(); + } + }); + + + INSTANCE.addConverter(Path.class, List.class, new TypeConverter.Converter() + { + public List convert(Path source) + { + List pathArray = new ArrayList(source.size()); + for(Path.Element element : source) + { + pathArray.add(INSTANCE.convert(String.class, element)); + } + return pathArray; + } + }); + + INSTANCE.addConverter(Path.class, String.class, new TypeConverter.Converter() + { + public String convert(Path source) + { + return source.toString(); + } + }); + + // TODO should be list of Strings, need to double-check +// INSTANCE.addConverter(List.class, Path.class, new TypeConverter.Converter() +// { +// 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() + { + public String convert(ChildAssociationRef source) + { + return source.toString(); + } + }); + + INSTANCE.addConverter(String.class, ChildAssociationRef.class, new TypeConverter.Converter() + { + public ChildAssociationRef convert(String source) + { + return new ChildAssociationRef(source); + } + }); + + INSTANCE.addConverter(AssociationRef.class, String.class, new TypeConverter.Converter() + { + public String convert(AssociationRef source) + { + return source.toString(); + } + }); + + INSTANCE.addConverter(String.class, AssociationRef.class, new TypeConverter.Converter() + { + public AssociationRef convert(String source) + { + return new AssociationRef(source); + } + }); + + INSTANCE.addConverter(Number.class, String.class, new TypeConverter.Converter() + { + public String convert(Number source) + { + return source.toString(); + } + }); + + INSTANCE.addConverter(Boolean.class, String.class, new TypeConverter.Converter() + { + public String convert(Boolean source) + { + return source.toString(); + } + }); + + } + } +} diff --git a/source/java/org/alfresco/repo/web/scripts/solr/SOLRWebScriptTest.java b/source/java/org/alfresco/repo/web/scripts/solr/SOLRWebScriptTest.java index d2b57a1f22..c2f4dce8bb 100644 --- a/source/java/org/alfresco/repo/web/scripts/solr/SOLRWebScriptTest.java +++ b/source/java/org/alfresco/repo/web/scripts/solr/SOLRWebScriptTest.java @@ -314,6 +314,69 @@ public class SOLRWebScriptTest extends BaseWebScriptTest }); } + private void buildTransactions2() + { + txnHelper.doInTransaction(new RetryingTransactionCallback() + { + public Void execute() throws Throwable + { + PropertyMap props = new PropertyMap(); + props.put(ContentModel.PROP_NAME, "Container2"); + container2 = nodeService.createNode( + rootNodeRef, + ContentModel.ASSOC_CHILDREN, + ContentModel.ASSOC_CHILDREN, + ContentModel.TYPE_FOLDER, + props).getChildRef(); + container2NodeID = getNodeID(container2); + if(logger.isDebugEnabled()) + { + logger.debug("container2 = " + container2); + } + + FileInfo content1Info = fileFolderService.create(container2, "Content1", ContentModel.TYPE_CONTENT); + content1 = content1Info.getNodeRef(); + content1NodeID = getNodeID(content1); + + if(logger.isDebugEnabled()) + { + logger.debug("content1 = " + content1); + } + + FileInfo content2Info = fileFolderService.create(container2, "Content2", ContentModel.TYPE_CONTENT); + content2 = content2Info.getNodeRef(); + content2NodeID = getNodeID(content2); + if(logger.isDebugEnabled()) + { + logger.debug("content2 = " + content2); + } + + return null; + } + }); + + txnHelper.doInTransaction(new RetryingTransactionCallback() + { + public Void execute() throws Throwable + { + FileInfo content3Info = fileFolderService.create(container2, "Content3", ContentModel.TYPE_CONTENT); + content3 = content3Info.getNodeRef(); + content3NodeID = getNodeID(content3); + if(logger.isDebugEnabled()) + { + logger.debug("content3 = " + content3); + } + + nodeService.addAspect(content1, ContentModel.ASPECT_TEMPORARY, null); + fileFolderService.delete(content1); + + nodeService.setProperty(content3, ContentModel.PROP_NAME, "Content 3 New Name"); + + return null; + } + }); + } + private List getTransactionIds(JSONArray transactions) throws JSONException { List txnIds = new ArrayList(transactions.length()); @@ -339,388 +402,7 @@ public class SOLRWebScriptTest extends BaseWebScriptTest } return buffer.toString(); } - - public void testGetTransactions1() throws Exception - { - long fromCommitTime = System.currentTimeMillis(); - buildTransactions1(); - - String url = "/api/solr/transactions?fromCommitTime=" + fromCommitTime; - TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url); - Response response = sendRequest(req, Status.STATUS_OK, admin); - -// assertEquals("Expected application/json content type", "application/json[;charset=UTF-8]", response.getContentType()); - -// System.out.println(response.getContentAsString()); - JSONObject json = new JSONObject(response.getContentAsString()); - - JSONArray transactions = json.getJSONArray("transactions"); - assertEquals("Number of transactions is incorrect", 2, transactions.length()); - - int[] updates = new int[] {1, 1}; - int[] deletes = new int[] {0, 1}; - //StringBuilder txnIds = new StringBuilder(); - int numTxns = transactions.length(); - List transactionIds = getTransactionIds(transactions); - for(int i = 0; i < numTxns; i++) - { - JSONObject txn = transactions.getJSONObject(i); - assertEquals("Number of deletes is incorrect", deletes[i], txn.getLong("deletes")); - assertEquals("Number of updates is incorrect", updates[i], txn.getLong("updates")); - -// txnIds.append(txn.getString("id")); -// if(i < (numTxns - 1)) -// { -// txnIds.append(","); -// } - } - - // get all nodes at once - if(logger.isDebugEnabled()) - { - logger.debug("txnIds = " + transactions.toString()); - } - - GetNodesParameters parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - JSONArray nodes = getNodes(parameters, 0, 3); - if(logger.isDebugEnabled()) - { - logger.debug("nodes:"); - logger.debug(nodes.toString(3)); - } - - JSONObject lastNode = nodes.getJSONObject(2); - assertTrue("nodeID is missing", lastNode.has("id")); - Long fromNodeId = lastNode.getLong("id"); - if(logger.isDebugEnabled()) - { - logger.debug("fromNodeId = " + fromNodeId); - } - assertNotNull("Unexpected null fromNodeId", fromNodeId); - - firstNode = nodes.getJSONObject(0); - secondNode = nodes.getJSONObject(1); - //assertEquals("Expected transaction ids to be the same", firstNode.getLong("txnID") == secondNode.getLong("txnID")); - assertEquals("Expected node update", "u", firstNode.getString("status")); - assertEquals("Expected node deleted", "d", secondNode.getString("status")); - assertEquals("Node id is incorrect", container1NodeID, firstNode.getLong("id")); - assertEquals("Node id is incorrect", content1NodeID, secondNode.getLong("id")); - - // get first 2 nodes - parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - nodes = getNodes(parameters, 2, 2); - if(logger.isDebugEnabled()) - { - logger.debug("nodes:"); - logger.debug(nodes.toString(3)); - } - - lastNode = nodes.getJSONObject(1); - assertTrue("nodeID is missing", lastNode.has("id")); - fromNodeId = lastNode.getLong("id"); - if(logger.isDebugEnabled()) - { - logger.debug("fromNodeId = " + fromNodeId); - } - assertNotNull("Unexpected null fromNodeId", fromNodeId); - - // get 4 nodes starting with fromNodeId, should return only 2 nodes (including fromNodeId) - parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - parameters.setFromNodeId(fromNodeId); - nodes = getNodes(parameters, 4, 2); - if(logger.isDebugEnabled()) - { - logger.debug("nodes:"); - logger.debug(nodes.toString(3)); - } - - firstNode = nodes.getJSONObject(0); - secondNode = nodes.getJSONObject(1); - assertEquals("Expected node deleted", "d", firstNode.getString("status")); - assertEquals("Expected node updated", "u", secondNode.getString("status")); - assertEquals("Node id is incorrect", content1NodeID, firstNode.getLong("id")); - assertEquals("Node id is incorrect", content2NodeID, secondNode.getLong("id")); - - // get 0 (all) nodes starting with fromNodeId, should return 2 nodes - parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - parameters.setFromNodeId(fromNodeId); - nodes = getNodes(parameters, 0, 2); - if(logger.isDebugEnabled()) - { - logger.debug("nodes:"); - logger.debug(nodes.toString(3)); - } - - // get 2 nodes ending with toNodeId, should return 2 nodes - long toNodeId = content2NodeID; - parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - parameters.setToNodeId(toNodeId); - nodes = getNodes(parameters, 2, 2); - if(logger.isDebugEnabled()) - { - logger.debug("nodes:"); - logger.debug(nodes.toString(3)); - } - - firstNode = nodes.getJSONObject(0); - secondNode = nodes.getJSONObject(1); - assertEquals("Expected node deleted", "u", firstNode.getString("status")); - assertEquals("Node id is incorrect", container1NodeID, firstNode.getLong("id")); - assertEquals("Expected node updated", "d", secondNode.getString("status")); - assertEquals("Node id is incorrect", content1NodeID, secondNode.getLong("id")); - - // get 1 node ending with toNodeId, should return 1 nodes - toNodeId = content2NodeID; - parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - parameters.setToNodeId(toNodeId); - nodes = getNodes(parameters, 1, 1); - if(logger.isDebugEnabled()) - { - logger.debug("nodes:"); - logger.debug(nodes.toString(3)); - } - - firstNode = nodes.getJSONObject(0); - assertEquals("Expected node updated", "u", firstNode.getString("status")); - assertEquals("Node id is incorrect", container1NodeID, firstNode.getLong("id")); - - // get 3 nodes ending with toNodeId, should return 3 nodes - toNodeId = content2NodeID; - parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - parameters.setToNodeId(toNodeId); - nodes = getNodes(parameters, 3, 3); - if(logger.isDebugEnabled()) - { - logger.debug("nodes:"); - logger.debug(nodes.toString(3)); - } - - firstNode = nodes.getJSONObject(0); - assertEquals("Expected node updated", "u", firstNode.getString("status")); - assertEquals("Node id is incorrect", container1NodeID, firstNode.getLong("id")); - - secondNode = nodes.getJSONObject(1); - assertEquals("Expected node deleted", "d", secondNode.getString("status")); - assertEquals("Node id is incorrect", content1NodeID, secondNode.getLong("id")); - - thirdNode = nodes.getJSONObject(2); - assertEquals("Expected node updated", "u", thirdNode.getString("status")); - assertEquals("Node id is incorrect", content2NodeID, thirdNode.getLong("id")); - } - - private void buildTransactions2() - { - txnHelper.doInTransaction(new RetryingTransactionCallback() - { - public Void execute() throws Throwable - { - PropertyMap props = new PropertyMap(); - props.put(ContentModel.PROP_NAME, "Container2"); - container2 = nodeService.createNode( - rootNodeRef, - ContentModel.ASSOC_CHILDREN, - ContentModel.ASSOC_CHILDREN, - ContentModel.TYPE_FOLDER, - props).getChildRef(); - container2NodeID = getNodeID(container2); - if(logger.isDebugEnabled()) - { - logger.debug("container2 = " + container2); - } - - FileInfo content1Info = fileFolderService.create(container2, "Content1", ContentModel.TYPE_CONTENT); - content1 = content1Info.getNodeRef(); - content1NodeID = getNodeID(content1); - - if(logger.isDebugEnabled()) - { - logger.debug("content1 = " + content1); - } - - FileInfo content2Info = fileFolderService.create(container2, "Content2", ContentModel.TYPE_CONTENT); - content2 = content2Info.getNodeRef(); - content2NodeID = getNodeID(content2); - if(logger.isDebugEnabled()) - { - logger.debug("content2 = " + content2); - } - - return null; - } - }); - - txnHelper.doInTransaction(new RetryingTransactionCallback() - { - public Void execute() throws Throwable - { - FileInfo content3Info = fileFolderService.create(container2, "Content3", ContentModel.TYPE_CONTENT); - content3 = content3Info.getNodeRef(); - content3NodeID = getNodeID(content3); - if(logger.isDebugEnabled()) - { - logger.debug("content3 = " + content3); - } - - nodeService.addAspect(content1, ContentModel.ASPECT_TEMPORARY, null); - fileFolderService.delete(content1); - - nodeService.setProperty(content3, ContentModel.PROP_NAME, "Content 3 New Name"); - - return null; - } - }); - } - - public void testGetTransactions2() throws Exception - { - long fromCommitTime = System.currentTimeMillis(); - - buildTransactions2(); - - String url = "/api/solr/transactions?fromCommitTime=" + fromCommitTime; - TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url); - Response response = sendRequest(req, Status.STATUS_OK, admin); - - if(logger.isDebugEnabled()) - { - logger.debug("txns ="); - logger.debug(response.getContentAsString()); - } - JSONObject json = new JSONObject(response.getContentAsString()); - - JSONArray transactions = json.getJSONArray("transactions"); - assertEquals("Number of transactions is incorrect", 2, transactions.length()); - - // first txn has 2 updates rather than three because content1 is deleted in txn 2 and therefore - // "belongs" to that txn (because txn2 was the last to alter the node) - int[] updates = new int[] {2, 1}; - int[] deletes = new int[] {0, 1}; - StringBuilder txnIds = new StringBuilder(); - int numTxns = transactions.length(); - for(int i = 0; i < numTxns; i++) - { - JSONObject txn = transactions.getJSONObject(i); - assertEquals("Number of deletes is incorrect", deletes[i], txn.getLong("deletes")); - assertEquals("Number of updates is incorrect", updates[i], txn.getLong("updates")); - - txnIds.append(txn.getString("id")); - if(i < (numTxns - 1)) - { - txnIds.append(","); - } - } - - // get all nodes at once - if(logger.isDebugEnabled()) - { - logger.debug("txnIds = " + txnIds.toString()); - } - - List transactionIds = getTransactionIds(transactions); - - // get all nodes in the txns - GetNodesParameters parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - JSONArray nodes = getNodes(parameters, 0, 4); - JSONObject lastNode = nodes.getJSONObject(nodes.length() - 1); - Long fromNodeId = lastNode.getLong("id"); - assertNotNull("Unexpected null fromNodeId", fromNodeId); - - // get first 2 nodes - parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - nodes = getNodes(parameters, 2, 2); - if(logger.isDebugEnabled()) - { - logger.debug("nodes:"); - logger.debug(nodes.toString(3)); - } - - firstNode = nodes.getJSONObject(0); - assertTrue("nodeID is missing", firstNode.has("id")); - secondNode = nodes.getJSONObject(1); - assertTrue("nodeID is missing", secondNode.has("id")); - fromNodeId = secondNode.getLong("id"); - if(logger.isDebugEnabled()) - { - logger.debug("fromNodeId = " + fromNodeId); - } - assertNotNull("Unexpected null nodeID", fromNodeId); - - //assertEquals("Expected transaction ids to be the same", firstNode.getLong("txnID"), secondNode.getLong("txnID")); - assertEquals("Expected node update", "u", firstNode.getString("status")); - assertEquals("Expected node delete", "d", secondNode.getString("status")); - assertEquals("Incorrect node id", container2NodeID, firstNode.getLong("id")); - assertEquals("Incorrect node id", content1NodeID, secondNode.getLong("id")); - - // get 10 nodes (including fromNodeId) starting with fromNodeId, should return only 3 nodes - parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - parameters.setFromNodeId(fromNodeId); - nodes = getNodes(parameters, 10, 3); - - firstNode = nodes.getJSONObject(0); - assertTrue("nodeID is missing", firstNode.has("id")); - secondNode = nodes.getJSONObject(1); - assertTrue("nodeID is missing", secondNode.has("id")); - thirdNode = nodes.getJSONObject(2); - assertTrue("nodeID is missing", thirdNode.has("id")); - - assertEquals("Expected node delete", "d", firstNode.getString("status")); - assertEquals("Expected node update", "u", secondNode.getString("status")); - assertEquals("Expected node update", "u", thirdNode.getString("status")); - assertEquals("Incorrect node id", content1NodeID, firstNode.getLong("id")); - assertEquals("Incorrect node id", content2NodeID, secondNode.getLong("id")); - assertEquals("Incorrect node id", content3NodeID, thirdNode.getLong("id")); - - // test with from and to node ids - parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - parameters.setFromNodeId(container2NodeID); - parameters.setToNodeId(content3NodeID); - nodes = getNodes(parameters, 2, 2); - - firstNode = nodes.getJSONObject(0); - assertTrue("nodeID is missing", firstNode.has("id")); - secondNode = nodes.getJSONObject(1); - assertTrue("nodeID is missing", secondNode.has("id")); - assertEquals("Incorrect node id", container2NodeID, firstNode.getLong("id")); - assertEquals("Incorrect node id", content1NodeID, secondNode.getLong("id")); - - // test right truncation - parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - parameters.setToNodeId(content3NodeID); - nodes = getNodes(parameters, 2, 2); - - firstNode = nodes.getJSONObject(0); - assertTrue("nodeID is missing", firstNode.has("id")); - secondNode = nodes.getJSONObject(1); - assertTrue("nodeID is missing", secondNode.has("id")); - assertEquals("Incorrect node id", container2NodeID, firstNode.getLong("id")); - assertEquals("Incorrect node id", content1NodeID, secondNode.getLong("id")); - - // test left truncation, specifying from node only - parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - parameters.setFromNodeId(container2NodeID); - nodes = getNodes(parameters, 2, 2); - - firstNode = nodes.getJSONObject(0); - assertTrue("nodeID is missing", firstNode.has("id")); - secondNode = nodes.getJSONObject(1); - assertTrue("nodeID is missing", secondNode.has("id")); - assertEquals("Incorrect node id", container2NodeID, firstNode.getLong("id")); - assertEquals("Incorrect node id", content1NodeID, secondNode.getLong("id")); - } private void buildTransactions3() { @@ -759,41 +441,6 @@ public class SOLRWebScriptTest extends BaseWebScriptTest } }); } - - public void testGetNodesExcludeAspects() throws Exception - { - long fromCommitTime = System.currentTimeMillis(); - - buildTransactions3(); - - String url = "/api/solr/transactions?fromCommitTime=" + fromCommitTime; - TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url); - Response response = sendRequest(req, Status.STATUS_OK, admin); - - if(logger.isDebugEnabled()) - { - logger.debug("txns = "); - logger.debug(response.getContentAsString()); - } - JSONObject json = new JSONObject(response.getContentAsString()); - - JSONArray transactions = json.getJSONArray("transactions"); - assertEquals("Number of transactions is incorrect", 1, transactions.length()); - - // first txn has 2 updates rather than three because content1 is deleted in txn 2 and therefore - // "belongs" to that txn (because txn2 was the last to alter the node) - - List transactionIds = getTransactionIds(transactions); - - Set excludeAspects = new HashSet(1); - excludeAspects.add(ContentModel.ASPECT_TEMPORARY); - - // get all nodes, exclude nodes with temporary aspect - GetNodesParameters parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - parameters.setExcludeAspects(excludeAspects); - JSONArray nodes = getNodes(parameters, 0, 51); - } private void buildTransactions4() { @@ -867,52 +514,6 @@ public class SOLRWebScriptTest extends BaseWebScriptTest } }); } - - public void testGetNodesStoreName() throws Exception - { - long fromCommitTime = System.currentTimeMillis(); - - buildTransactions4(); - - String url = "/api/solr/transactions?fromCommitTime=" + fromCommitTime; - TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url); - Response response = sendRequest(req, Status.STATUS_OK, admin); - - if(logger.isDebugEnabled()) - { - logger.debug(response.getContentAsString()); - } - JSONObject json = new JSONObject(response.getContentAsString()); - - JSONArray transactions = json.getJSONArray("transactions"); - assertEquals("Number of transactions is incorrect", 2, transactions.length()); - - // first txn has 2 updates rather than three because content1 is deleted in txn 2 and therefore - // "belongs" to that txn (because txn2 was the last to alter the node) - - List transactionIds = getTransactionIds(transactions); - - // exact store name - GetNodesParameters parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - parameters.setStoreProtocol(storeRef.getProtocol()); - parameters.setStoreIdentifier(storeRef.getIdentifier()); - JSONArray nodes = getNodes(parameters, 0, 101); - - nodes = getNodes(parameters, 50, 50); - - // store protocol - parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - parameters.setStoreProtocol(storeRef.getProtocol()); - nodes = getNodes(parameters, 0, 202); - - // store identifier - parameters = new GetNodesParameters(); - parameters.setTransactionIds(transactionIds); - parameters.setStoreIdentifier(storeRef.getIdentifier()); - nodes = getNodes(parameters, 0, 101); - } private NodeRef container6; @@ -992,6 +593,443 @@ public class SOLRWebScriptTest extends BaseWebScriptTest return nodes; } + private void buildTransactions6() + { + txnHelper.doInTransaction(new RetryingTransactionCallback() + { + public Void execute() throws Throwable + { + PropertyMap props = new PropertyMap(); + props.put(ContentModel.PROP_NAME, "Container6"); + NodeRef container6 = nodeService.createNode( + rootNodeRef, + ContentModel.ASSOC_CHILDREN, + ContentModel.ASSOC_CHILDREN, + ContentModel.TYPE_FOLDER, + props).getChildRef(); + long container6NodeID = getNodeID(container6); + if(logger.isDebugEnabled()) + { + logger.debug("container6 = " + container6); + } + + for(int i = 0; i < 2000; i++) + { + FileInfo content1Info = fileFolderService.create(container6, "Content" + i, ContentModel.TYPE_CONTENT); + NodeRef nodeRef = content1Info.getNodeRef(); + contents.add(nodeRef); + + if(i % 2 == 1) + { + nodeService.addAspect(nodeRef, ContentModel.ASPECT_TEMPORARY, null); + } + } + + return null; + } + }); + } + +/* public void testGetTransactions1() throws Exception + { + long fromCommitTime = System.currentTimeMillis(); + + buildTransactions1(); + + String url = "/api/solr/transactions?fromCommitTime=" + fromCommitTime; + TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url); + Response response = sendRequest(req, Status.STATUS_OK, admin); + +// assertEquals("Expected application/json content type", "application/json[;charset=UTF-8]", response.getContentType()); + +// System.out.println(response.getContentAsString()); + JSONObject json = new JSONObject(response.getContentAsString()); + + JSONArray transactions = json.getJSONArray("transactions"); + assertEquals("Number of transactions is incorrect", 2, transactions.length()); + + int[] updates = new int[] {1, 1}; + int[] deletes = new int[] {0, 1}; + //StringBuilder txnIds = new StringBuilder(); + int numTxns = transactions.length(); + List transactionIds = getTransactionIds(transactions); + for(int i = 0; i < numTxns; i++) + { + JSONObject txn = transactions.getJSONObject(i); + assertEquals("Number of deletes is incorrect", deletes[i], txn.getLong("deletes")); + assertEquals("Number of updates is incorrect", updates[i], txn.getLong("updates")); + +// txnIds.append(txn.getString("id")); +// if(i < (numTxns - 1)) +// { +// txnIds.append(","); +// } + } + + // get all nodes at once + if(logger.isDebugEnabled()) + { + logger.debug("txnIds = " + transactions.toString()); + } + + GetNodesParameters parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + JSONArray nodes = getNodes(parameters, 0, 3); + if(logger.isDebugEnabled()) + { + logger.debug("nodes:"); + logger.debug(nodes.toString(3)); + } + + JSONObject lastNode = nodes.getJSONObject(2); + assertTrue("nodeID is missing", lastNode.has("id")); + Long fromNodeId = lastNode.getLong("id"); + if(logger.isDebugEnabled()) + { + logger.debug("fromNodeId = " + fromNodeId); + } + assertNotNull("Unexpected null fromNodeId", fromNodeId); + + firstNode = nodes.getJSONObject(0); + secondNode = nodes.getJSONObject(1); + //assertEquals("Expected transaction ids to be the same", firstNode.getLong("txnID") == secondNode.getLong("txnID")); + assertEquals("Expected node update", "u", firstNode.getString("status")); + assertEquals("Expected node deleted", "d", secondNode.getString("status")); + assertEquals("Node id is incorrect", container1NodeID, firstNode.getLong("id")); + assertEquals("Node id is incorrect", content1NodeID, secondNode.getLong("id")); + + // get first 2 nodes + parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + nodes = getNodes(parameters, 2, 2); + if(logger.isDebugEnabled()) + { + logger.debug("nodes:"); + logger.debug(nodes.toString(3)); + } + + lastNode = nodes.getJSONObject(1); + assertTrue("nodeID is missing", lastNode.has("id")); + fromNodeId = lastNode.getLong("id"); + if(logger.isDebugEnabled()) + { + logger.debug("fromNodeId = " + fromNodeId); + } + assertNotNull("Unexpected null fromNodeId", fromNodeId); + + // get 4 nodes starting with fromNodeId, should return only 2 nodes (including fromNodeId) + parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + parameters.setFromNodeId(fromNodeId); + nodes = getNodes(parameters, 4, 2); + if(logger.isDebugEnabled()) + { + logger.debug("nodes:"); + logger.debug(nodes.toString(3)); + } + + firstNode = nodes.getJSONObject(0); + secondNode = nodes.getJSONObject(1); + assertEquals("Expected node deleted", "d", firstNode.getString("status")); + assertEquals("Expected node updated", "u", secondNode.getString("status")); + assertEquals("Node id is incorrect", content1NodeID, firstNode.getLong("id")); + assertEquals("Node id is incorrect", content2NodeID, secondNode.getLong("id")); + + // get 0 (all) nodes starting with fromNodeId, should return 2 nodes + parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + parameters.setFromNodeId(fromNodeId); + nodes = getNodes(parameters, 0, 2); + if(logger.isDebugEnabled()) + { + logger.debug("nodes:"); + logger.debug(nodes.toString(3)); + } + + // get 2 nodes ending with toNodeId, should return 2 nodes + long toNodeId = content2NodeID; + parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + parameters.setToNodeId(toNodeId); + nodes = getNodes(parameters, 2, 2); + if(logger.isDebugEnabled()) + { + logger.debug("nodes:"); + logger.debug(nodes.toString(3)); + } + + firstNode = nodes.getJSONObject(0); + secondNode = nodes.getJSONObject(1); + assertEquals("Expected node deleted", "u", firstNode.getString("status")); + assertEquals("Node id is incorrect", container1NodeID, firstNode.getLong("id")); + assertEquals("Expected node updated", "d", secondNode.getString("status")); + assertEquals("Node id is incorrect", content1NodeID, secondNode.getLong("id")); + + // get 1 node ending with toNodeId, should return 1 nodes + toNodeId = content2NodeID; + parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + parameters.setToNodeId(toNodeId); + nodes = getNodes(parameters, 1, 1); + if(logger.isDebugEnabled()) + { + logger.debug("nodes:"); + logger.debug(nodes.toString(3)); + } + + firstNode = nodes.getJSONObject(0); + assertEquals("Expected node updated", "u", firstNode.getString("status")); + assertEquals("Node id is incorrect", container1NodeID, firstNode.getLong("id")); + + // get 3 nodes ending with toNodeId, should return 3 nodes + toNodeId = content2NodeID; + parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + parameters.setToNodeId(toNodeId); + nodes = getNodes(parameters, 3, 3); + if(logger.isDebugEnabled()) + { + logger.debug("nodes:"); + logger.debug(nodes.toString(3)); + } + + firstNode = nodes.getJSONObject(0); + assertEquals("Expected node updated", "u", firstNode.getString("status")); + assertEquals("Node id is incorrect", container1NodeID, firstNode.getLong("id")); + + secondNode = nodes.getJSONObject(1); + assertEquals("Expected node deleted", "d", secondNode.getString("status")); + assertEquals("Node id is incorrect", content1NodeID, secondNode.getLong("id")); + + thirdNode = nodes.getJSONObject(2); + assertEquals("Expected node updated", "u", thirdNode.getString("status")); + assertEquals("Node id is incorrect", content2NodeID, thirdNode.getLong("id")); + } + + public void testGetNodesStoreName() throws Exception + { + long fromCommitTime = System.currentTimeMillis(); + + buildTransactions4(); + + String url = "/api/solr/transactions?fromCommitTime=" + fromCommitTime; + TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url); + Response response = sendRequest(req, Status.STATUS_OK, admin); + + if(logger.isDebugEnabled()) + { + logger.debug(response.getContentAsString()); + } + JSONObject json = new JSONObject(response.getContentAsString()); + + JSONArray transactions = json.getJSONArray("transactions"); + assertEquals("Number of transactions is incorrect", 2, transactions.length()); + + // first txn has 2 updates rather than three because content1 is deleted in txn 2 and therefore + // "belongs" to that txn (because txn2 was the last to alter the node) + + List transactionIds = getTransactionIds(transactions); + + // exact store name + GetNodesParameters parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + parameters.setStoreProtocol(storeRef.getProtocol()); + parameters.setStoreIdentifier(storeRef.getIdentifier()); + JSONArray nodes = getNodes(parameters, 0, 101); + + nodes = getNodes(parameters, 50, 50); + + // store protocol + parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + parameters.setStoreProtocol(storeRef.getProtocol()); + nodes = getNodes(parameters, 0, 202); + + // store identifier + parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + parameters.setStoreIdentifier(storeRef.getIdentifier()); + nodes = getNodes(parameters, 0, 101); + } + + public void testGetTransactions2() throws Exception + { + long fromCommitTime = System.currentTimeMillis(); + + buildTransactions2(); + + String url = "/api/solr/transactions?fromCommitTime=" + fromCommitTime; + TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url); + Response response = sendRequest(req, Status.STATUS_OK, admin); + + if(logger.isDebugEnabled()) + { + logger.debug("txns ="); + logger.debug(response.getContentAsString()); + } + JSONObject json = new JSONObject(response.getContentAsString()); + + JSONArray transactions = json.getJSONArray("transactions"); + assertEquals("Number of transactions is incorrect", 2, transactions.length()); + + // first txn has 2 updates rather than three because content1 is deleted in txn 2 and therefore + // "belongs" to that txn (because txn2 was the last to alter the node) + int[] updates = new int[] {2, 1}; + int[] deletes = new int[] {0, 1}; + StringBuilder txnIds = new StringBuilder(); + int numTxns = transactions.length(); + for(int i = 0; i < numTxns; i++) + { + JSONObject txn = transactions.getJSONObject(i); + assertEquals("Number of deletes is incorrect", deletes[i], txn.getLong("deletes")); + assertEquals("Number of updates is incorrect", updates[i], txn.getLong("updates")); + + txnIds.append(txn.getString("id")); + if(i < (numTxns - 1)) + { + txnIds.append(","); + } + } + + // get all nodes at once + if(logger.isDebugEnabled()) + { + logger.debug("txnIds = " + txnIds.toString()); + } + + List transactionIds = getTransactionIds(transactions); + + // get all nodes in the txns + GetNodesParameters parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + JSONArray nodes = getNodes(parameters, 0, 4); + JSONObject lastNode = nodes.getJSONObject(nodes.length() - 1); + Long fromNodeId = lastNode.getLong("id"); + assertNotNull("Unexpected null fromNodeId", fromNodeId); + + // get first 2 nodes + parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + nodes = getNodes(parameters, 2, 2); + if(logger.isDebugEnabled()) + { + logger.debug("nodes:"); + logger.debug(nodes.toString(3)); + } + + firstNode = nodes.getJSONObject(0); + assertTrue("nodeID is missing", firstNode.has("id")); + secondNode = nodes.getJSONObject(1); + assertTrue("nodeID is missing", secondNode.has("id")); + fromNodeId = secondNode.getLong("id"); + if(logger.isDebugEnabled()) + { + logger.debug("fromNodeId = " + fromNodeId); + } + assertNotNull("Unexpected null nodeID", fromNodeId); + + //assertEquals("Expected transaction ids to be the same", firstNode.getLong("txnID"), secondNode.getLong("txnID")); + assertEquals("Expected node update", "u", firstNode.getString("status")); + assertEquals("Expected node delete", "d", secondNode.getString("status")); + assertEquals("Incorrect node id", container2NodeID, firstNode.getLong("id")); + assertEquals("Incorrect node id", content1NodeID, secondNode.getLong("id")); + + // get 10 nodes (including fromNodeId) starting with fromNodeId, should return only 3 nodes + parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + parameters.setFromNodeId(fromNodeId); + nodes = getNodes(parameters, 10, 3); + + firstNode = nodes.getJSONObject(0); + assertTrue("nodeID is missing", firstNode.has("id")); + secondNode = nodes.getJSONObject(1); + assertTrue("nodeID is missing", secondNode.has("id")); + thirdNode = nodes.getJSONObject(2); + assertTrue("nodeID is missing", thirdNode.has("id")); + + assertEquals("Expected node delete", "d", firstNode.getString("status")); + assertEquals("Expected node update", "u", secondNode.getString("status")); + assertEquals("Expected node update", "u", thirdNode.getString("status")); + assertEquals("Incorrect node id", content1NodeID, firstNode.getLong("id")); + assertEquals("Incorrect node id", content2NodeID, secondNode.getLong("id")); + assertEquals("Incorrect node id", content3NodeID, thirdNode.getLong("id")); + + // test with from and to node ids + parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + parameters.setFromNodeId(container2NodeID); + parameters.setToNodeId(content3NodeID); + nodes = getNodes(parameters, 2, 2); + + firstNode = nodes.getJSONObject(0); + assertTrue("nodeID is missing", firstNode.has("id")); + secondNode = nodes.getJSONObject(1); + assertTrue("nodeID is missing", secondNode.has("id")); + assertEquals("Incorrect node id", container2NodeID, firstNode.getLong("id")); + assertEquals("Incorrect node id", content1NodeID, secondNode.getLong("id")); + + // test right truncation + parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + parameters.setToNodeId(content3NodeID); + nodes = getNodes(parameters, 2, 2); + + firstNode = nodes.getJSONObject(0); + assertTrue("nodeID is missing", firstNode.has("id")); + secondNode = nodes.getJSONObject(1); + assertTrue("nodeID is missing", secondNode.has("id")); + assertEquals("Incorrect node id", container2NodeID, firstNode.getLong("id")); + assertEquals("Incorrect node id", content1NodeID, secondNode.getLong("id")); + + // test left truncation, specifying from node only + parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + parameters.setFromNodeId(container2NodeID); + nodes = getNodes(parameters, 2, 2); + + firstNode = nodes.getJSONObject(0); + assertTrue("nodeID is missing", firstNode.has("id")); + secondNode = nodes.getJSONObject(1); + assertTrue("nodeID is missing", secondNode.has("id")); + assertEquals("Incorrect node id", container2NodeID, firstNode.getLong("id")); + assertEquals("Incorrect node id", content1NodeID, secondNode.getLong("id")); + } + + public void testGetNodesExcludeAspects() throws Exception + { + long fromCommitTime = System.currentTimeMillis(); + + buildTransactions3(); + + String url = "/api/solr/transactions?fromCommitTime=" + fromCommitTime; + TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url); + Response response = sendRequest(req, Status.STATUS_OK, admin); + + if(logger.isDebugEnabled()) + { + logger.debug("txns = "); + logger.debug(response.getContentAsString()); + } + JSONObject json = new JSONObject(response.getContentAsString()); + + JSONArray transactions = json.getJSONArray("transactions"); + assertEquals("Number of transactions is incorrect", 1, transactions.length()); + + // first txn has 2 updates rather than three because content1 is deleted in txn 2 and therefore + // "belongs" to that txn (because txn2 was the last to alter the node) + + List transactionIds = getTransactionIds(transactions); + + Set excludeAspects = new HashSet(1); + excludeAspects.add(ContentModel.ASPECT_TEMPORARY); + + // get all nodes, exclude nodes with temporary aspect + GetNodesParameters parameters = new GetNodesParameters(); + parameters.setTransactionIds(transactionIds); + parameters.setExcludeAspects(excludeAspects); + JSONArray nodes = getNodes(parameters, 0, 51); + }*/ + public void testNodeMetaData() throws Exception { long fromCommitTime = System.currentTimeMillis(); @@ -1040,48 +1078,8 @@ public class SOLRWebScriptTest extends BaseWebScriptTest String expectedPath = expectedPaths.get(i).toString(); assertEquals("Path element " + i + " is incorrect", expectedPath, path); } - - - //assertEquals("Node id is incorrect", containsProperty(properties, ContentModel.PROP_AUTHOR, "steve")); } - - private void buildTransactions6() - { - txnHelper.doInTransaction(new RetryingTransactionCallback() - { - public Void execute() throws Throwable - { - PropertyMap props = new PropertyMap(); - props.put(ContentModel.PROP_NAME, "Container6"); - NodeRef container6 = nodeService.createNode( - rootNodeRef, - ContentModel.ASSOC_CHILDREN, - ContentModel.ASSOC_CHILDREN, - ContentModel.TYPE_FOLDER, - props).getChildRef(); - long container6NodeID = getNodeID(container6); - if(logger.isDebugEnabled()) - { - logger.debug("container6 = " + container6); - } - - for(int i = 0; i < 2000; i++) - { - FileInfo content1Info = fileFolderService.create(container6, "Content" + i, ContentModel.TYPE_CONTENT); - NodeRef nodeRef = content1Info.getNodeRef(); - contents.add(nodeRef); - - if(i % 2 == 1) - { - nodeService.addAspect(nodeRef, ContentModel.ASPECT_TEMPORARY, null); - } - } - - return null; - } - }); - } - +/* public void testNodeMetaDataManyNodes() throws Exception { long fromCommitTime = System.currentTimeMillis(); @@ -1129,7 +1127,7 @@ public class SOLRWebScriptTest extends BaseWebScriptTest nodeDAO.clear(); nodesMetaData = getNodesMetaData(nodeIds, 0, 2001); - } + }*/ private boolean containsAspect(JSONArray aspectsArray, QName aspect) throws Exception { diff --git a/source/java/org/alfresco/repo/web/scripts/solr/test/SOLRSerializerTests.java b/source/java/org/alfresco/repo/web/scripts/solr/test/SOLRSerializerTests.java deleted file mode 100644 index f3f0315fd3..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/solr/test/SOLRSerializerTests.java +++ /dev/null @@ -1,257 +0,0 @@ -package org.alfresco.repo.web.scripts.solr.test; - -import java.io.InputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.domain.node.ContentDataWithId; -import org.alfresco.repo.security.authentication.AuthenticationComponent; -import org.alfresco.repo.transaction.RetryingTransactionHelper; -import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; -import org.alfresco.repo.web.scripts.BaseWebScriptTest; -import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.admin.RepoAdminService; -import org.alfresco.service.cmr.dictionary.DictionaryService; -import org.alfresco.service.cmr.model.FileFolderService; -import org.alfresco.service.cmr.model.FileInfo; -import org.alfresco.service.cmr.repository.AssociationRef; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.ContentService; -import org.alfresco.service.cmr.repository.ContentWriter; -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.Path; -import org.alfresco.service.cmr.repository.Period; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; -import org.alfresco.service.transaction.TransactionService; -import org.alfresco.util.PropertyMap; -import org.alfresco.util.SOLRDeserializer; -import org.alfresco.util.SOLRSerializer; - -public class SOLRSerializerTests extends BaseWebScriptTest -{ - static final String SOLR_TEST_MODEL_1_0_URI = "http://www.alfresco.org/model/solrtest/1.0"; - static final QName TYPE_TEST_OBJECT = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "testobject"); - static final QName PROP_MLTEXT = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "mlTextProp"); - static final QName PROP_BOOL = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "boolProp"); - static final QName PROP_LONG = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "longProp"); - static final QName PROP_FLOAT = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "floatProp"); - static final QName PROP_DOUBLE = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "doubleProp"); - static final QName PROP_DATE = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "dateProp"); - static final QName PROP_DATETIME = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "dateTimeProp"); - static final QName PROP_QNAME = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "qnameProp"); - static final QName PROP_NODEREF = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "nodeRefProp"); - static final QName PROP_CHILDASSOC = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "childAssocProp"); - static final QName PROP_ASSOC = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "assocProp"); - static final QName PROP_PATH = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "pathProp"); - static final QName PROP_CATEGORY = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "categoryProp"); - static final QName PROP_LOCALE = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "localeProp"); - static final QName PROP_PERIOD = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "periodProp"); - static final QName PROP_ANY = QName.createQName(SOLR_TEST_MODEL_1_0_URI, "anyProp"); - - private AuthenticationComponent authenticationComponent; - private TransactionService transactionService; - private RetryingTransactionHelper txnHelper; - private NodeService nodeService; - private FileFolderService fileFolderService; - private ContentService contentService; - private DictionaryService dictionaryService; - private RepoAdminService repoAdminService; - - private SOLRSerializer solrSerializer; - private SOLRDeserializer solrDeserializer; - - private StoreRef storeRef; - private NodeRef rootNodeRef; - - @Override - public void setUp() throws Exception - { - ServiceRegistry serviceRegistry = (ServiceRegistry) getServer().getApplicationContext().getBean(ServiceRegistry.SERVICE_REGISTRY); - transactionService = serviceRegistry.getTransactionService(); - txnHelper = transactionService.getRetryingTransactionHelper(); - fileFolderService = serviceRegistry.getFileFolderService(); - contentService = serviceRegistry.getContentService(); - nodeService = serviceRegistry.getNodeService(); - dictionaryService = serviceRegistry.getDictionaryService(); - authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent"); - repoAdminService = (RepoAdminService)getServer().getApplicationContext().getBean("repoAdminService"); - - solrSerializer = (SOLRSerializer)getServer().getApplicationContext().getBean("solrSerializer"); - solrDeserializer = new SOLRDeserializer(dictionaryService); - - authenticationComponent.setSystemUserAsCurrentUser(); - - InputStream modelStream = getClass().getClassLoader().getResourceAsStream("solr/solr-test-model.xml"); - repoAdminService.deployModel(modelStream, "solr-test-model"); - - storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis()); - rootNodeRef = nodeService.getRootNode(storeRef); - } - - private NodeRef solrNode; - private Date date; - private MLText mlText; - private ChildAssociationRef childAssoc; - private AssociationRef assoc; - private List multiCategory; - private NodeRef category; - - private static String[] mlOrderable_en = new String[] { "AAAA BBBB", "EEEE FFFF", "II", "KK", "MM", "OO", "QQ", "SS", "UU", "AA", "CC" }; - - private static String[] mlOrderable_fr = new String[] { "CCCC DDDD", "GGGG HHHH", "JJ", "LL", "NN", "PP", "RR", "TT", "VV", "BB", "DD" }; - - private MLText makeMLText() - { - return makeMLText(0); - } - - private MLText makeMLText(int position) - { - MLText ml = new MLText(); - ml.addValue(Locale.ENGLISH, mlOrderable_en[position]); - ml.addValue(Locale.FRENCH, mlOrderable_fr[position]); - return ml; - } - - private void buildTransaction() - { - PropertyMap props = new PropertyMap(); - props.put(ContentModel.PROP_NAME, "Container1"); - NodeRef container = nodeService.createNode( - rootNodeRef, - ContentModel.ASSOC_CHILDREN, - ContentModel.ASSOC_CHILDREN, - ContentModel.TYPE_FOLDER, - props).getChildRef(); - - FileInfo contentInfo = fileFolderService.create(container, "SolrNode", TYPE_TEST_OBJECT); - solrNode = contentInfo.getNodeRef(); - ContentWriter writer = contentService.getWriter(solrNode, ContentModel.PROP_CONTENT, true); - writer.putContent("Some Content"); - - date = new Date(); - mlText = makeMLText(); - childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, - new NodeRef("testProtocol", "testID", "abcde"), - QName.createQName("testProtocol", "testID"), - new NodeRef("testProtocol", "testID", "xyz")); - assoc = new AssociationRef( - new NodeRef("testProtocol", "testID", "abcde"), - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "parts"), - new NodeRef("testProtocol", "testID", "xyz")); - - Map properties = new HashMap(); - properties.put(PROP_BOOL, Boolean.TRUE); - properties.put(PROP_LONG, Long.valueOf(42)); - properties.put(PROP_FLOAT, Float.valueOf(42.0f)); - properties.put(PROP_DOUBLE, Double.valueOf(42.0)); - properties.put(PROP_DATE, date); - properties.put(PROP_DATETIME, date); - properties.put(PROP_NODEREF, container); - properties.put(PROP_LOCALE, Locale.ITALY); - properties.put(PROP_QNAME, PROP_QNAME); - //properties.put(PROP_VERSION, new VersionNumber("1.0")); - properties.put(PROP_PERIOD, new Period("period|12")); - Path path = new Path(); - Path.Element element0 = new Path.ChildAssocElement(new ChildAssociationRef(null, null, null, new NodeRef("testProtocol", "testID", "abcde"))); - path.prepend(element0); - properties.put(PROP_PATH, path); - properties.put(PROP_ASSOC, assoc); - category = new NodeRef("testProtocol", "testID", "cat1"); - properties.put(PROP_CATEGORY, (Serializable)category); - properties.put(PROP_CHILDASSOC, childAssoc); - properties.put(PROP_MLTEXT, mlText); - - nodeService.setProperties(solrNode, properties); - } - - public void testAll() - { - txnHelper.doInTransaction(new RetryingTransactionCallback() - { - public Void execute() throws Throwable - { - buildTransaction(); - - Serializable value = nodeService.getProperty(solrNode, ContentModel.PROP_NAME); - Object serialized = solrSerializer.serialize(ContentModel.PROP_NAME, value); - Serializable deserialized = solrDeserializer.deserialize(ContentModel.PROP_NAME, serialized); - assertEquals(value, deserialized); - - value = nodeService.getProperty(solrNode, PROP_MLTEXT); - serialized = solrSerializer.serialize(PROP_MLTEXT, value); - deserialized = solrDeserializer.deserialize(PROP_MLTEXT, serialized); - assertEquals(value, deserialized); - - value = nodeService.getProperty(solrNode, ContentModel.PROP_CONTENT); - assertTrue("Expected ContentDataId, got " + value.getClass().getName(), value instanceof ContentDataWithId); - serialized = solrSerializer.serialize(ContentModel.PROP_CONTENT, value); - deserialized = solrDeserializer.deserialize(ContentModel.PROP_CONTENT, serialized); - assertEquals(value, deserialized); - - value = nodeService.getProperty(solrNode, PROP_BOOL); - serialized = solrSerializer.serialize(PROP_BOOL, value); - deserialized = solrDeserializer.deserialize(PROP_BOOL, serialized); - assertEquals(value, deserialized); - - value = nodeService.getProperty(solrNode, PROP_DATE); - assertTrue("Expected Date object, got " + value.getClass().getName(), value instanceof Date); - serialized = solrSerializer.serialize(PROP_DATE, value); - deserialized = solrDeserializer.deserialize(PROP_DATE, serialized); - assertEquals(value, deserialized); - - value = nodeService.getProperty(solrNode, PROP_DATETIME); - assertTrue("Expected Date object, got " + value.getClass().getName(), value instanceof Date); - serialized = solrSerializer.serialize(PROP_DATETIME, value); - deserialized = solrDeserializer.deserialize(PROP_DATETIME, serialized); - assertEquals(value, deserialized); - - value = nodeService.getProperty(solrNode, PROP_DOUBLE); - assertTrue("Expected Double object, got " + value.getClass().getName(), value instanceof Double); - serialized = solrSerializer.serialize(PROP_DATETIME, value); - deserialized = solrDeserializer.deserialize(PROP_DATETIME, serialized); - assertEquals(value, deserialized); - - value = nodeService.getProperty(solrNode, PROP_FLOAT); - assertTrue("Expected Float object, got " + value.getClass().getName(), value instanceof Float); - serialized = solrSerializer.serialize(PROP_FLOAT, value); - deserialized = solrDeserializer.deserialize(PROP_FLOAT, serialized); - assertEquals(value, deserialized); - - value = nodeService.getProperty(solrNode, PROP_LONG); - assertTrue("Expected Long object, got " + value.getClass().getName(), value instanceof Long); - serialized = solrSerializer.serialize(PROP_LONG, value); - deserialized = solrDeserializer.deserialize(PROP_LONG, serialized); - assertEquals(value, deserialized); - - value = nodeService.getProperty(solrNode, PROP_CHILDASSOC); - serialized = solrSerializer.serialize(PROP_CHILDASSOC, value); - deserialized = solrDeserializer.deserialize(PROP_CHILDASSOC, serialized); - assertEquals(value, deserialized); - - value = nodeService.getProperty(solrNode, PROP_ASSOC); - serialized = solrSerializer.serialize(PROP_ASSOC, value); - deserialized = solrDeserializer.deserialize(PROP_ASSOC, serialized); - assertEquals(value, deserialized); - - value = nodeService.getProperty(solrNode, PROP_CATEGORY); - serialized = solrSerializer.serialize(PROP_ASSOC, value); - deserialized = solrDeserializer.deserialize(PROP_ASSOC, serialized); - assertEquals(value, deserialized); - - return null; - } - }); - } - -}