From 8d0db44bc6b8234f48f96f2edf3b9b81724fcf92 Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Wed, 2 Apr 2008 16:56:09 +0000 Subject: [PATCH] Merged V2.1-A to HEAD 7970: Added 'writeWithAttachment' method to the contentweb service API. 7972: Added unit test to check CML creation of files and folders with spaces in the names git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8663 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../content/ContentServiceSoapPort.java | 5 ++ .../repo/webservice/content/deploy.wsdd | 24 +++-- .../webservice/content/ContentWebService.java | 90 +++++++++++++++++++ source/web/WEB-INF/server-config.wsdd | 26 +++--- source/wsdl/content-service.wsdl | 46 ++++++++++ 5 files changed, 172 insertions(+), 19 deletions(-) diff --git a/source/generated/org/alfresco/repo/webservice/content/ContentServiceSoapPort.java b/source/generated/org/alfresco/repo/webservice/content/ContentServiceSoapPort.java index d2f660793a..b170c37f44 100644 --- a/source/generated/org/alfresco/repo/webservice/content/ContentServiceSoapPort.java +++ b/source/generated/org/alfresco/repo/webservice/content/ContentServiceSoapPort.java @@ -19,6 +19,11 @@ public interface ContentServiceSoapPort extends java.rmi.Remote { */ public org.alfresco.repo.webservice.content.Content write(org.alfresco.repo.webservice.types.Reference node, java.lang.String property, byte[] content, org.alfresco.repo.webservice.types.ContentFormat format) throws java.rmi.RemoteException, org.alfresco.repo.webservice.content.ContentFault; + /** + * Writes the attached content into the repository. + */ + public org.alfresco.repo.webservice.content.Content writeWithAttachment(org.alfresco.repo.webservice.types.Reference node, java.lang.String property, org.alfresco.repo.webservice.types.ContentFormat format) throws java.rmi.RemoteException, org.alfresco.repo.webservice.content.ContentFault; + /** * Clears content from the repository. */ diff --git a/source/generated/org/alfresco/repo/webservice/content/deploy.wsdd b/source/generated/org/alfresco/repo/webservice/content/deploy.wsdd index 4dc373ee9b..81cfc8107c 100644 --- a/source/generated/org/alfresco/repo/webservice/content/deploy.wsdd +++ b/source/generated/org/alfresco/repo/webservice/content/deploy.wsdd @@ -32,6 +32,12 @@ + + + + + + @@ -45,7 +51,7 @@ - + - + callback = new RetryingTransactionCallback() + { + public Content execute() throws Throwable + { + AttachmentPart[] attachments = getMessageAttachments(); + if (attachments.length != 1) + { + throw new AlfrescoRuntimeException("Expecting only one attachment"); + } + + // create a NodeRef from the parent reference + NodeRef nodeRef = Utils.convertToNodeRef(node, nodeService, searchService, namespaceService); + + // Get the content writer + ContentWriter writer = contentService.getWriter(nodeRef, QName.createQName(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 (just need to get the first in the array since we are only expecting one attachment) + DataHandler dh = attachments[0].getDataHandler(); + InputStream is = dh.getInputStream(); + writer.putContent(is); + + // Debug + if (logger.isDebugEnabled()) + { + logger.debug("Updated content for node with id: " + nodeRef.getId()); + } + + // Return the content object + return createContent(nodeRef, property); + } + }; + return Utils.getRetryingTransactionHelper(MessageContext.getCurrentContext()).doInTransaction(callback); + } + catch (Throwable e) + { + if (logger.isDebugEnabled()) + { + logger.error("Unexpected error occurred", e); + } + throw new ContentFault(0, e.getMessage()); + } + + + } + + @SuppressWarnings("unchecked") + private AttachmentPart[] getMessageAttachments() + throws AxisFault + { + MessageContext msgContext = MessageContext.getCurrentContext(); + Message reqMsg = msgContext.getRequestMessage(); + Attachments messageAttachments = reqMsg.getAttachmentsImpl(); + if (null == messageAttachments) + { + return new AttachmentPart[0]; + } + int attachmentCount = messageAttachments.getAttachmentCount(); + AttachmentPart attachments[] = new AttachmentPart[attachmentCount]; + Iterator it = messageAttachments.getAttachments().iterator(); + int count = 0; + while (it.hasNext()) + { + AttachmentPart part = (AttachmentPart)it.next(); + attachments[count++] = part; + } + + return attachments; + } /** * @see org.alfresco.repo.webservice.content.ContentServiceSoapPort#clear(org.alfresco.repo.webservice.types.Predicate, diff --git a/source/web/WEB-INF/server-config.wsdd b/source/web/WEB-INF/server-config.wsdd index a4ffdc0a1f..672c6cc2b1 100644 --- a/source/web/WEB-INF/server-config.wsdd +++ b/source/web/WEB-INF/server-config.wsdd @@ -898,6 +898,12 @@ + + + + + + @@ -911,7 +917,7 @@ - + - + - + Provides support for collaborative editing of content. diff --git a/source/wsdl/content-service.wsdl b/source/wsdl/content-service.wsdl index 119376c8c2..71ae4aca83 100644 --- a/source/wsdl/content-service.wsdl +++ b/source/wsdl/content-service.wsdl @@ -52,6 +52,25 @@ + + + + + + + + + + + + + + + + + + + @@ -134,6 +153,14 @@ + + + + + + + + @@ -167,6 +194,12 @@ + + Writes the attached content into the repository. + + + + Clears content from the repository. @@ -207,6 +240,19 @@ + + + Writes attached content to the repository. + + + + + + + + + + Clears content from the repository.