camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: Added support for secondary types (CMIS 1.1)
Date Sun, 19 Jul 2015 09:32:01 GMT
Repository: camel
Updated Branches:
  refs/heads/master 3b5c6aeef -> c1e500b09


Added support for secondary types (CMIS 1.1)


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e9703d34
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e9703d34
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e9703d34

Branch: refs/heads/master
Commit: e9703d3415733bc1d0a5c607e70cecc7a6d84ebe
Parents: 3b5c6ae
Author: bpeters <bas.peters@alfresco.com>
Authored: Fri Jun 5 10:14:22 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Jul 19 11:33:14 2015 +0200

----------------------------------------------------------------------
 .../camel/component/cmis/CMISProducer.java      | 272 ++++++++++---------
 .../camel/component/cmis/CMISSessionFacade.java |  13 +
 .../camel/component/cmis/CMISProducerTest.java  |  22 ++
 .../camel/component/cmis/CMISTestSupport.java   |   4 +-
 4 files changed, 178 insertions(+), 133 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e9703d34/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CMISProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CMISProducer.java
b/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CMISProducer.java
index b05346d..49e4f80 100644
--- a/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CMISProducer.java
+++ b/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CMISProducer.java
@@ -16,7 +16,9 @@
  */
 package org.apache.camel.component.cmis;
 
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -30,7 +32,6 @@ import org.apache.camel.util.MessageHelper;
 import org.apache.chemistry.opencmis.client.api.CmisObject;
 import org.apache.chemistry.opencmis.client.api.Document;
 import org.apache.chemistry.opencmis.client.api.Folder;
-import org.apache.chemistry.opencmis.client.api.ObjectType;
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
 import org.apache.chemistry.opencmis.commons.enums.VersioningState;
@@ -42,134 +43,143 @@ import org.slf4j.LoggerFactory;
  * The CMIS producer.
  */
 public class CMISProducer extends DefaultProducer {
-    private static final Logger LOG = LoggerFactory.getLogger(CMISProducer.class);
-    private final CMISSessionFacade cmisSessionFacade;
-
-    public CMISProducer(CMISEndpoint endpoint, CMISSessionFacade cmisSessionFacade) {
-        super(endpoint);
-        this.cmisSessionFacade = cmisSessionFacade;
-    }
-
-    public void process(Exchange exchange) throws Exception {
-        CmisObject cmisObject = createNode(exchange);
-        LOG.debug("Created node with id: {}", cmisObject.getId());
-        exchange.getOut().setBody(cmisObject.getId());
-    }
-
-    private Map<String, Object> filterTypeProperties(Map<String, Object> properties)
{
-        Map<String, Object> result = new HashMap<String, Object>(properties.size());
-        String objectTypeName = CamelCMISConstants.CMIS_DOCUMENT;
-        if (properties.containsKey(PropertyIds.OBJECT_TYPE_ID)) {
-            objectTypeName = (String) properties.get(PropertyIds.OBJECT_TYPE_ID);
-        }
-
-        Set<String> types = cmisSessionFacade.getPropertiesFor(objectTypeName);
-        for (Map.Entry<String, Object> entry : properties.entrySet()) {
-            if (types.contains(entry.getKey())) {
-                result.put(entry.getKey(), entry.getValue());
-            }
-        }
-        return result;
-    }
-
-    private CmisObject createNode(Exchange exchange) throws Exception {
-        validateRequiredHeader(exchange, PropertyIds.NAME);
-
-        Message message = exchange.getIn();
-        String parentFolderPath = parentFolderPathFor(message);
-        Folder parentFolder = getFolderOnPath(exchange, parentFolderPath);
-        Map<String, Object> cmisProperties = filterTypeProperties(message.getHeaders());
-
-        if (isDocument(exchange)) {
-            String fileName = message.getHeader(PropertyIds.NAME, String.class);
-            String mimeType = getMimeType(message);
-            byte[] buf = getBodyData(message);
-            ContentStream contentStream = cmisSessionFacade.createContentStream(fileName,
buf, mimeType);
-            return storeDocument(parentFolder, cmisProperties, contentStream);
-        } else if (isFolder(message)) {
-            return storeFolder(parentFolder, cmisProperties);
-        } else {  //other types
-            return storeDocument(parentFolder, cmisProperties, null);
-        }
-    }
-
-    private Folder getFolderOnPath(Exchange exchange, String path) {
-        try {
-            return (Folder)cmisSessionFacade.getObjectByPath(path);
-        } catch (CmisObjectNotFoundException e) {
-            throw new RuntimeExchangeException("Path not found " + path, exchange, e);
-        }
-    }
-
-    private String parentFolderPathFor(Message message) {
-        String customPath = message.getHeader(CamelCMISConstants.CMIS_FOLDER_PATH, String.class);
-        if (customPath != null) {
-            return customPath;
-        }
-
-        if (isFolder(message)) {
-            String path = (String)message.getHeader(PropertyIds.PATH);
-            String name = (String)message.getHeader(PropertyIds.NAME);
-            if (path != null && path.length() > name.length()) {
-                return path.substring(0, path.length() - name.length());
-            }
-        }
-
-        return "/";
-    }
-
-    private boolean isFolder(Message message) {
-        String baseTypeId = message.getHeader(PropertyIds.OBJECT_TYPE_ID, String.class);
-        if (baseTypeId != null) {
-            return CamelCMISConstants.CMIS_FOLDER.equals(cmisSessionFacade.getCMISTypeFor(baseTypeId));
-        }
-        return message.getBody() == null;
-    }
-
-    private Folder storeFolder(Folder parentFolder, Map<String, Object> cmisProperties)
{
-        if (!cmisProperties.containsKey(PropertyIds.OBJECT_TYPE_ID)) {
-            cmisProperties.put(PropertyIds.OBJECT_TYPE_ID, CamelCMISConstants.CMIS_FOLDER);
-        }
-        LOG.debug("Creating folder with properties: {}", cmisProperties);
-        return parentFolder.createFolder(cmisProperties);
-    }
-
-    private Document storeDocument(Folder parentFolder, Map<String, Object> cmisProperties,
-                                   ContentStream contentStream) {
-        if (!cmisProperties.containsKey(PropertyIds.OBJECT_TYPE_ID)) {
-            cmisProperties.put(PropertyIds.OBJECT_TYPE_ID, CamelCMISConstants.CMIS_DOCUMENT);
-        }
-
-        VersioningState versioningState = VersioningState.NONE;
-        if (cmisSessionFacade
-                .isObjectTypeVersionable((String)cmisProperties.get(PropertyIds.OBJECT_TYPE_ID)))
{
-            versioningState = VersioningState.MAJOR;
-        }
-        LOG.debug("Creating document with properties: {}", cmisProperties);
-        return parentFolder.createDocument(cmisProperties, contentStream, versioningState);
-    }
-
-    private void validateRequiredHeader(Exchange exchange, String name) throws NoSuchHeaderException
{
-        ExchangeHelper.getMandatoryHeader(exchange, name, String.class);
-    }
-
-    private boolean isDocument(Exchange exchange) {
-        String baseTypeId = exchange.getIn().getHeader(PropertyIds.OBJECT_TYPE_ID, String.class);
-        if (baseTypeId != null) {
-            return CamelCMISConstants.CMIS_DOCUMENT.equals(cmisSessionFacade.getCMISTypeFor(baseTypeId));
-        }
-        return exchange.getIn().getBody() != null;
-    }
-
-    private byte[] getBodyData(Message message) {
-        return message.getBody(byte[].class);
-    }
-
-    private String getMimeType(Message message) throws NoSuchHeaderException {
-        String mimeType = message.getHeader(PropertyIds.CONTENT_STREAM_MIME_TYPE, String.class);
-        if (mimeType == null) {
-            mimeType = MessageHelper.getContentType(message);
-        }
-        return mimeType;
-    }
+	private static final Logger LOG = LoggerFactory.getLogger(CMISProducer.class);
+	private final CMISSessionFacade cmisSessionFacade;
+
+	public CMISProducer(CMISEndpoint endpoint, CMISSessionFacade cmisSessionFacade) {
+		super(endpoint);
+		this.cmisSessionFacade = cmisSessionFacade;
+	}
+
+	public void process(Exchange exchange) throws Exception {
+		CmisObject cmisObject = createNode(exchange);
+		LOG.debug("Created node with id: {}", cmisObject.getId());
+		exchange.getOut().setBody(cmisObject.getId());
+	}
+
+	private Map<String, Object> filterTypeProperties(Map<String, Object> properties)
{
+		Map<String, Object> result = new HashMap<String, Object>(properties.size());
+
+		String objectTypeName = CamelCMISConstants.CMIS_DOCUMENT;
+		if (properties.containsKey(PropertyIds.OBJECT_TYPE_ID)) {
+			objectTypeName = (String) properties.get(PropertyIds.OBJECT_TYPE_ID);
+		}
+
+		Set<String> types = new HashSet<String>();
+		types.addAll(cmisSessionFacade.getPropertiesFor(objectTypeName));
+
+		if (cmisSessionFacade.supportsSecondaries() && properties.containsKey(PropertyIds.SECONDARY_OBJECT_TYPE_IDS))
{
+			@SuppressWarnings("unchecked")
+			Collection<String> secondaryTypes = (Collection<String>) properties.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
+			for (String secondaryType : secondaryTypes) {
+				types.addAll(cmisSessionFacade.getPropertiesFor(secondaryType));
+			}
+		}
+
+		for (Map.Entry<String, Object> entry : properties.entrySet()) {
+			if (types.contains(entry.getKey())) {
+				result.put(entry.getKey(), entry.getValue());
+			}
+		}
+		return result;
+	}
+
+	private CmisObject createNode(Exchange exchange) throws Exception {
+		validateRequiredHeader(exchange, PropertyIds.NAME);
+
+		Message message = exchange.getIn();
+		String parentFolderPath = parentFolderPathFor(message);
+		Folder parentFolder = getFolderOnPath(exchange, parentFolderPath);
+		Map<String, Object> cmisProperties = filterTypeProperties(message.getHeaders());
+
+		if (isDocument(exchange)) {
+			String fileName = message.getHeader(PropertyIds.NAME, String.class);
+			String mimeType = getMimeType(message);
+			byte[] buf = getBodyData(message);
+			ContentStream contentStream = cmisSessionFacade.createContentStream(fileName, buf, mimeType);
+			return storeDocument(parentFolder, cmisProperties, contentStream);
+		} else if (isFolder(message)) {
+			return storeFolder(parentFolder, cmisProperties);
+		} else { // other types
+			return storeDocument(parentFolder, cmisProperties, null);
+		}
+	}
+
+	private Folder getFolderOnPath(Exchange exchange, String path) {
+		try {
+			return (Folder) cmisSessionFacade.getObjectByPath(path);
+		} catch (CmisObjectNotFoundException e) {
+			throw new RuntimeExchangeException("Path not found " + path, exchange, e);
+		}
+	}
+
+	private String parentFolderPathFor(Message message) {
+		String customPath = message.getHeader(CamelCMISConstants.CMIS_FOLDER_PATH, String.class);
+		if (customPath != null) {
+			return customPath;
+		}
+
+		if (isFolder(message)) {
+			String path = (String) message.getHeader(PropertyIds.PATH);
+			String name = (String) message.getHeader(PropertyIds.NAME);
+			if (path != null && path.length() > name.length()) {
+				return path.substring(0, path.length() - name.length());
+			}
+		}
+
+		return "/";
+	}
+
+	private boolean isFolder(Message message) {
+		String baseTypeId = message.getHeader(PropertyIds.OBJECT_TYPE_ID, String.class);
+		if (baseTypeId != null) {
+			return CamelCMISConstants.CMIS_FOLDER.equals(cmisSessionFacade.getCMISTypeFor(baseTypeId));
+		}
+		return message.getBody() == null;
+	}
+
+	private Folder storeFolder(Folder parentFolder, Map<String, Object> cmisProperties)
{
+		if (!cmisProperties.containsKey(PropertyIds.OBJECT_TYPE_ID)) {
+			cmisProperties.put(PropertyIds.OBJECT_TYPE_ID, CamelCMISConstants.CMIS_FOLDER);
+		}
+		LOG.debug("Creating folder with properties: {}", cmisProperties);
+		return parentFolder.createFolder(cmisProperties);
+	}
+
+	private Document storeDocument(Folder parentFolder, Map<String, Object> cmisProperties,
ContentStream contentStream) {
+		if (!cmisProperties.containsKey(PropertyIds.OBJECT_TYPE_ID)) {
+			cmisProperties.put(PropertyIds.OBJECT_TYPE_ID, CamelCMISConstants.CMIS_DOCUMENT);
+		}
+
+		VersioningState versioningState = VersioningState.NONE;
+		if (cmisSessionFacade.isObjectTypeVersionable((String) cmisProperties.get(PropertyIds.OBJECT_TYPE_ID)))
{
+			versioningState = VersioningState.MAJOR;
+		}
+		LOG.debug("Creating document with properties: {}", cmisProperties);
+		return parentFolder.createDocument(cmisProperties, contentStream, versioningState);
+	}
+
+	private void validateRequiredHeader(Exchange exchange, String name) throws NoSuchHeaderException
{
+		ExchangeHelper.getMandatoryHeader(exchange, name, String.class);
+	}
+
+	private boolean isDocument(Exchange exchange) {
+		String baseTypeId = exchange.getIn().getHeader(PropertyIds.OBJECT_TYPE_ID, String.class);
+		if (baseTypeId != null) {
+			return CamelCMISConstants.CMIS_DOCUMENT.equals(cmisSessionFacade.getCMISTypeFor(baseTypeId));
+		}
+		return exchange.getIn().getBody() != null;
+	}
+
+	private byte[] getBodyData(Message message) {
+		return message.getBody(byte[].class);
+	}
+
+	private String getMimeType(Message message) throws NoSuchHeaderException {
+		String mimeType = message.getHeader(PropertyIds.CONTENT_STREAM_MIME_TYPE, String.class);
+		if (mimeType == null) {
+			mimeType = MessageHelper.getContentType(message);
+		}
+		return mimeType;
+	}
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/e9703d34/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CMISSessionFacade.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CMISSessionFacade.java
b/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CMISSessionFacade.java
index 898b7e1..34d6a4a 100644
--- a/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CMISSessionFacade.java
+++ b/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CMISSessionFacade.java
@@ -35,7 +35,9 @@ import org.apache.chemistry.opencmis.client.api.Session;
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.SessionParameter;
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.BindingType;
+import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -194,6 +196,17 @@ public class CMISSessionFacade {
         return false;
     }
 
+	public boolean supportsSecondaries() {
+		if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_0)
+			return false;
+		for (ObjectType type : session.getTypeChildren(null, false)) {
+			if (BaseTypeId.CMIS_SECONDARY.value().equals(type.getId())) {
+				return true;
+			}
+		}
+		return false;
+	}
+
     public ContentStream createContentStream(String fileName, byte[] buf, String mimeType)
throws Exception {
         return buf != null ? session.getObjectFactory()
                 .createContentStream(fileName, buf.length, mimeType, new ByteArrayInputStream(buf))
: null;

http://git-wip-us.apache.org/repos/asf/camel/blob/e9703d34/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISProducerTest.java
b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISProducerTest.java
index 10fc7ce..6cb0445 100644
--- a/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISProducerTest.java
+++ b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISProducerTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.component.cmis;
 
+import java.util.Arrays;
+import java.util.List;
+
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.NoSuchHeaderException;
@@ -124,6 +127,25 @@ public class CMISProducerTest extends CMISTestSupport {
                 newNode.getPropertyValue(PropertyIds.CONTENT_STREAM_MIME_TYPE));
     }
 
+	@Test
+	public void cmisSecondaryTypePropertiesAreStored() throws Exception {
+
+		List<String> secondaryTypes = Arrays.asList("MySecondaryType");
+
+		Exchange exchange = createExchangeWithInBody("Some content to be store");
+		exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
+		exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.txt");
+		exchange.getIn().getHeaders().put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
+		exchange.getIn().getHeaders().put("SecondaryStringProp", "secondaryTypePropValue");
+
+		template.send(exchange);
+		String newNodeId = exchange.getOut().getBody(String.class);
+		CmisObject newNode = retrieveCMISObjectByIdFromServer(newNodeId);
+
+		assertEquals(1, newNode.getSecondaryTypes().size());
+		assertEquals("secondaryTypePropValue", newNode.getPropertyValue("SecondaryStringProp"));
+	}
+
     @Test(expected = ResolveEndpointFailedException.class)
     public void failConnectingToNonExistingRepository() throws Exception {
         Endpoint endpoint = context.getEndpoint("cmis://" + getUrl()

http://git-wip-us.apache.org/repos/asf/camel/blob/e9703d34/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISTestSupport.java
b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISTestSupport.java
index 6f2bd32..1c0bc9e 100644
--- a/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISTestSupport.java
+++ b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISTestSupport.java
@@ -51,9 +51,9 @@ import org.junit.BeforeClass;
 
 public class CMISTestSupport extends CamelTestSupport {
     protected static final String CMIS_ENDPOINT_TEST_SERVER
-        = "http://localhost:%s/chemistry-opencmis-server-inmemory/atom";
+        = "http://localhost:%s/chemistry-opencmis-server-inmemory/atom11";
     protected static final String OPEN_CMIS_SERVER_WAR_PATH
-        = "target/dependency/chemistry-opencmis-server-inmemory-0.8.0.war";
+        = "target/dependency/chemistry-opencmis-server-inmemory-0.13.0.war";
 
     protected static Server cmisServer;
     protected static int port;


Mime
View raw message