From 0fe356421ea0628b0d5fbf16574297e0538ae8a5 Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Fri, 25 Aug 2006 15:47:57 +0000 Subject: [PATCH] - Added writeContent statement to CML git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3615 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/webservice/repository/deploy.wsdd | 8 + .../alfresco/repo/webservice/types/CML.java | 54 ++++ .../webservice/types/CMLWriteContent.java | 273 ++++++++++++++++++ .../org/alfresco/repo/webservice/CMLUtil.java | 50 ++++ .../alfresco/repo/webservice/CMLUtilTest.java | 33 +++ .../java/web-services-application-context.xml | 3 + source/wsdl/cml.xsd | 13 +- 7 files changed, 433 insertions(+), 1 deletion(-) create mode 100644 source/generated/org/alfresco/repo/webservice/types/CMLWriteContent.java diff --git a/source/generated/org/alfresco/repo/webservice/repository/deploy.wsdd b/source/generated/org/alfresco/repo/webservice/repository/deploy.wsdd index 4b05fb852d..48f55771a5 100644 --- a/source/generated/org/alfresco/repo/webservice/repository/deploy.wsdd +++ b/source/generated/org/alfresco/repo/webservice/repository/deploy.wsdd @@ -225,6 +225,14 @@ deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory" encodingStyle="" /> + CML>writeContent")); + elemField.setMinOccurs(0); + elemField.setNillable(false); + elemField.setMaxOccursUnbounded(true); + typeDesc.addFieldDesc(elemField); + elemField = new org.apache.axis.description.ElementDesc(); elemField.setFieldName("delete"); elemField.setXmlName(new javax.xml.namespace.QName("http://www.alfresco.org/ws/cml/1.0", "delete")); elemField.setXmlType(new javax.xml.namespace.QName("http://www.alfresco.org/ws/cml/1.0", ">CML>delete")); diff --git a/source/generated/org/alfresco/repo/webservice/types/CMLWriteContent.java b/source/generated/org/alfresco/repo/webservice/types/CMLWriteContent.java new file mode 100644 index 0000000000..12cd785356 --- /dev/null +++ b/source/generated/org/alfresco/repo/webservice/types/CMLWriteContent.java @@ -0,0 +1,273 @@ +/** + * CMLWriteContent.java + * + * This file was auto-generated from WSDL + * by the Apache Axis 1.3 Oct 05, 2005 (05:23:37 EDT) WSDL2Java emitter. + */ + +package org.alfresco.repo.webservice.types; + +public class CMLWriteContent implements java.io.Serializable { + private java.lang.String property; + + private byte[] content; + + private org.alfresco.repo.webservice.types.ContentFormat format; + + private org.alfresco.repo.webservice.types.Predicate where; + + private java.lang.String where_id; + + public CMLWriteContent() { + } + + public CMLWriteContent( + java.lang.String property, + byte[] content, + org.alfresco.repo.webservice.types.ContentFormat format, + org.alfresco.repo.webservice.types.Predicate where, + java.lang.String where_id) { + this.property = property; + this.content = content; + this.format = format; + this.where = where; + this.where_id = where_id; + } + + + /** + * Gets the property value for this CMLWriteContent. + * + * @return property + */ + public java.lang.String getProperty() { + return property; + } + + + /** + * Sets the property value for this CMLWriteContent. + * + * @param property + */ + public void setProperty(java.lang.String property) { + this.property = property; + } + + + /** + * Gets the content value for this CMLWriteContent. + * + * @return content + */ + public byte[] getContent() { + return content; + } + + + /** + * Sets the content value for this CMLWriteContent. + * + * @param content + */ + public void setContent(byte[] content) { + this.content = content; + } + + + /** + * Gets the format value for this CMLWriteContent. + * + * @return format + */ + public org.alfresco.repo.webservice.types.ContentFormat getFormat() { + return format; + } + + + /** + * Sets the format value for this CMLWriteContent. + * + * @param format + */ + public void setFormat(org.alfresco.repo.webservice.types.ContentFormat format) { + this.format = format; + } + + + /** + * Gets the where value for this CMLWriteContent. + * + * @return where + */ + public org.alfresco.repo.webservice.types.Predicate getWhere() { + return where; + } + + + /** + * Sets the where value for this CMLWriteContent. + * + * @param where + */ + public void setWhere(org.alfresco.repo.webservice.types.Predicate where) { + this.where = where; + } + + + /** + * Gets the where_id value for this CMLWriteContent. + * + * @return where_id + */ + public java.lang.String getWhere_id() { + return where_id; + } + + + /** + * Sets the where_id value for this CMLWriteContent. + * + * @param where_id + */ + public void setWhere_id(java.lang.String where_id) { + this.where_id = where_id; + } + + private java.lang.Object __equalsCalc = null; + public synchronized boolean equals(java.lang.Object obj) { + if (!(obj instanceof CMLWriteContent)) return false; + CMLWriteContent other = (CMLWriteContent) obj; + if (obj == null) return false; + if (this == obj) return true; + if (__equalsCalc != null) { + return (__equalsCalc == obj); + } + __equalsCalc = obj; + boolean _equals; + _equals = true && + ((this.property==null && other.getProperty()==null) || + (this.property!=null && + this.property.equals(other.getProperty()))) && + ((this.content==null && other.getContent()==null) || + (this.content!=null && + java.util.Arrays.equals(this.content, other.getContent()))) && + ((this.format==null && other.getFormat()==null) || + (this.format!=null && + this.format.equals(other.getFormat()))) && + ((this.where==null && other.getWhere()==null) || + (this.where!=null && + this.where.equals(other.getWhere()))) && + ((this.where_id==null && other.getWhere_id()==null) || + (this.where_id!=null && + this.where_id.equals(other.getWhere_id()))); + __equalsCalc = null; + return _equals; + } + + private boolean __hashCodeCalc = false; + public synchronized int hashCode() { + if (__hashCodeCalc) { + return 0; + } + __hashCodeCalc = true; + int _hashCode = 1; + if (getProperty() != null) { + _hashCode += getProperty().hashCode(); + } + if (getContent() != null) { + for (int i=0; + iCML>writeContent")); + org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc(); + elemField.setFieldName("property"); + elemField.setXmlName(new javax.xml.namespace.QName("http://www.alfresco.org/ws/cml/1.0", "property")); + elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string")); + elemField.setNillable(false); + typeDesc.addFieldDesc(elemField); + elemField = new org.apache.axis.description.ElementDesc(); + elemField.setFieldName("content"); + elemField.setXmlName(new javax.xml.namespace.QName("http://www.alfresco.org/ws/cml/1.0", "content")); + elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "base64Binary")); + elemField.setNillable(false); + typeDesc.addFieldDesc(elemField); + elemField = new org.apache.axis.description.ElementDesc(); + elemField.setFieldName("format"); + elemField.setXmlName(new javax.xml.namespace.QName("http://www.alfresco.org/ws/cml/1.0", "format")); + elemField.setXmlType(new javax.xml.namespace.QName("http://www.alfresco.org/ws/model/content/1.0", "ContentFormat")); + elemField.setNillable(false); + typeDesc.addFieldDesc(elemField); + elemField = new org.apache.axis.description.ElementDesc(); + elemField.setFieldName("where"); + elemField.setXmlName(new javax.xml.namespace.QName("http://www.alfresco.org/ws/cml/1.0", "where")); + elemField.setXmlType(new javax.xml.namespace.QName("http://www.alfresco.org/ws/model/content/1.0", "Predicate")); + elemField.setMinOccurs(0); + elemField.setNillable(true); + typeDesc.addFieldDesc(elemField); + elemField = new org.apache.axis.description.ElementDesc(); + elemField.setFieldName("where_id"); + elemField.setXmlName(new javax.xml.namespace.QName("http://www.alfresco.org/ws/cml/1.0", "where_id")); + elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string")); + elemField.setMinOccurs(0); + elemField.setNillable(true); + typeDesc.addFieldDesc(elemField); + } + + /** + * Return type metadata object + */ + public static org.apache.axis.description.TypeDesc getTypeDesc() { + return typeDesc; + } + + /** + * Get Custom Serializer + */ + public static org.apache.axis.encoding.Serializer getSerializer( + java.lang.String mechType, + java.lang.Class _javaType, + javax.xml.namespace.QName _xmlType) { + return + new org.apache.axis.encoding.ser.BeanSerializer( + _javaType, _xmlType, typeDesc); + } + + /** + * Get Custom Deserializer + */ + public static org.apache.axis.encoding.Deserializer getDeserializer( + java.lang.String mechType, + java.lang.Class _javaType, + javax.xml.namespace.QName _xmlType) { + return + new org.apache.axis.encoding.ser.BeanDeserializer( + _javaType, _xmlType, typeDesc); + } + +} diff --git a/source/java/org/alfresco/repo/webservice/CMLUtil.java b/source/java/org/alfresco/repo/webservice/CMLUtil.java index f6876c57d7..78a05795d4 100644 --- a/source/java/org/alfresco/repo/webservice/CMLUtil.java +++ b/source/java/org/alfresco/repo/webservice/CMLUtil.java @@ -16,6 +16,8 @@ */ package org.alfresco.repo.webservice; +import java.io.ByteArrayInputStream; +import java.io.InputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; @@ -35,11 +37,15 @@ import org.alfresco.repo.webservice.types.CMLRemoveAspect; import org.alfresco.repo.webservice.types.CMLRemoveAssociation; import org.alfresco.repo.webservice.types.CMLRemoveChild; import org.alfresco.repo.webservice.types.CMLUpdate; +import org.alfresco.repo.webservice.types.CMLWriteContent; +import org.alfresco.repo.webservice.types.ContentFormat; import org.alfresco.repo.webservice.types.NamedValue; import org.alfresco.repo.webservice.types.ParentReference; import org.alfresco.repo.webservice.types.Predicate; import org.alfresco.repo.webservice.types.Reference; import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.CopyService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; @@ -64,12 +70,14 @@ public class CMLUtil private static final String REMOVE_CHILD = "removeChild"; private static final String CREATE_ASSOCIATION = "createAssociation"; private static final String REMOVE_ASSOCIATION = "removeAssociation"; + private static final String WRITE_CONTENT = "writeContent"; private NodeService nodeService; private SearchService searchService; private NamespaceService namespaceService; private CopyService copyService; private DictionaryService dictionaryService; + private ContentService contentService; public void setNodeService(NodeService nodeService) { @@ -96,6 +104,11 @@ public class CMLUtil this.dictionaryService = dictionaryService; } + public void setContentService(ContentService contentService) + { + this.contentService = contentService; + } + /** * Execute a cml update query. * @@ -147,6 +160,15 @@ public class CMLUtil } } + CMLWriteContent[] writes = cml.getWriteContent(); + if (writes != null) + { + for (CMLWriteContent write : writes) + { + executeCMLWriteContent(write, context, results); + } + } + // Execute delete CMLDelete[] deletes = cml.getDelete(); if (deletes != null) @@ -375,6 +397,34 @@ public class CMLUtil } } + private void executeCMLWriteContent(CMLWriteContent write, ExecutionContext context, List results) + { + // Get the nodes and content property + List nodeRefs = getNodeRefList(write.getWhere_id(), write.getWhere(), context); + QName property = QName.createQName(write.getProperty()); + ContentFormat format = write.getFormat(); + byte[] content = write.getContent(); + + for (NodeRef nodeRef : nodeRefs) + { + //Get the content writer + ContentWriter writer = this.contentService.getWriter(nodeRef, property, true); + + // Set the content format details (if they have been specified) + if (format != null) + { + writer.setEncoding(format.getEncoding()); + writer.setMimetype(format.getMimetype()); + } + + // Write the content + InputStream is = new ByteArrayInputStream(content); + writer.putContent(is); + + results.add(createResult(WRITE_CONTENT, null, nodeRef, nodeRef)); + } + } + private void executeCMLDelete(CMLDelete delete, ExecutionContext context, List results) { List nodeRefs = Utils.resolvePredicate(delete.getWhere(), this.nodeService, this.searchService, this.namespaceService); diff --git a/source/java/org/alfresco/repo/webservice/CMLUtilTest.java b/source/java/org/alfresco/repo/webservice/CMLUtilTest.java index c231362f47..895ac5b6a6 100644 --- a/source/java/org/alfresco/repo/webservice/CMLUtilTest.java +++ b/source/java/org/alfresco/repo/webservice/CMLUtilTest.java @@ -34,6 +34,8 @@ import org.alfresco.repo.webservice.types.CMLRemoveAspect; import org.alfresco.repo.webservice.types.CMLRemoveAssociation; import org.alfresco.repo.webservice.types.CMLRemoveChild; import org.alfresco.repo.webservice.types.CMLUpdate; +import org.alfresco.repo.webservice.types.CMLWriteContent; +import org.alfresco.repo.webservice.types.ContentFormat; import org.alfresco.repo.webservice.types.NamedValue; import org.alfresco.repo.webservice.types.ParentReference; import org.alfresco.repo.webservice.types.Predicate; @@ -41,6 +43,8 @@ import org.alfresco.repo.webservice.types.Reference; import org.alfresco.service.cmr.repository.AssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ContentData; +import org.alfresco.service.cmr.repository.ContentReader; +import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; @@ -57,6 +61,7 @@ public class CMLUtilTest extends BaseSpringTest { private static final ContentData CONTENT_DATA_TEXT_UTF8 = new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, "UTF-8"); private static final ContentData CONTENT_DATA_HTML_UTF16 = new ContentData(null, MimetypeMap.MIMETYPE_HTML, 0L, "UTF-16"); + private static final String TEST_CONTENT = "This is some test content"; private CMLUtil cmlUtil; private NodeService nodeService; @@ -67,6 +72,7 @@ public class CMLUtilTest extends BaseSpringTest private SearchService searchService; private NodeRef folderNodeRef; private AuthenticationComponent authenticationComponent; + private ContentService contentService; @Override protected String[] getConfigLocations() @@ -82,6 +88,7 @@ public class CMLUtilTest extends BaseSpringTest this.searchService = (SearchService)this.applicationContext.getBean("searchService"); this.namespaceService = (NamespaceService)this.applicationContext.getBean("namespaceService"); this.authenticationComponent = (AuthenticationComponent) this.applicationContext.getBean("authenticationComponent"); + this.contentService = (ContentService)this.applicationContext.getBean("contentService"); this.authenticationComponent.setSystemUserAsCurrentUser(); @@ -212,6 +219,32 @@ public class CMLUtilTest extends BaseSpringTest assertEquals(CONTENT_DATA_HTML_UTF16, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_CONTENT)); } + public void testWriteContent() + { + CMLWriteContent write = new CMLWriteContent(); + write.setWhere(createPredicate(this.nodeRef)); + write.setProperty(ContentModel.PROP_CONTENT.toString()); + ContentFormat format = new ContentFormat(MimetypeMap.MIMETYPE_TEXT_PLAIN, "UTF-8"); + write.setFormat(format); + write.setContent(TEST_CONTENT.getBytes()); + + CML cml = new CML(); + cml.setWriteContent(new CMLWriteContent[]{write}); + + UpdateResult[] result = this.cmlUtil.executeCML(cml); + assertNotNull(result); + assertEquals(1, result.length); + + UpdateResult updateResult = result[0]; + assertEquals("writeContent", updateResult.getStatement()); + assertNotNull(updateResult.getSource()); + assertNotNull(updateResult.getDestination()); + + ContentReader reader = this.contentService.getReader(this.nodeRef, ContentModel.PROP_CONTENT); + assertNotNull(reader); + assertEquals(reader.getContentString(), TEST_CONTENT); + } + public void testDelete() { CMLDelete delete = new CMLDelete(); diff --git a/source/java/web-services-application-context.xml b/source/java/web-services-application-context.xml index e3ac65b950..56905676b6 100644 --- a/source/java/web-services-application-context.xml +++ b/source/java/web-services-application-context.xml @@ -49,6 +49,9 @@ + + + diff --git a/source/wsdl/cml.xsd b/source/wsdl/cml.xsd index 25f2414040..ce011f9d04 100644 --- a/source/wsdl/cml.xsd +++ b/source/wsdl/cml.xsd @@ -52,7 +52,18 @@ - + + + + + + + + + + + +