camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [camel] branch master updated: Camel 14325/add new functions (#3439)
Date Wed, 25 Dec 2019 12:10:27 GMT
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 0801147  Camel 14325/add new functions (#3439)
0801147 is described below

commit 080114734341101b4b6e127489b7960c50b7f2b5
Author: cherepnalkovski <cherepnalkovski@hotmail.com>
AuthorDate: Wed Dec 25 13:10:17 2019 +0100

    Camel 14325/add new functions (#3439)
    
    * Add new functions and change return type of the existing functions
    
    * Resolve pull request comments
---
 .../apache/camel/component/cmis/CMISProducer.java  | 178 +++++++++++++++++----
 .../camel/component/cmis/CamelCMISActions.java     |  14 +-
 .../camel/component/cmis/CamelCMISConstants.java   |   2 +
 .../camel/component/cmis/CMISProducerTest.java     |  12 +-
 .../camel/component/cmis/CMISTestSupport.java      |   6 +-
 5 files changed, 173 insertions(+), 39 deletions(-)

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 73f33e9..609b130 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
@@ -38,8 +38,10 @@ import org.apache.camel.support.ObjectHelper;
 import org.apache.camel.util.ReflectionHelper;
 import org.apache.chemistry.opencmis.client.api.CmisObject;
 import org.apache.chemistry.opencmis.client.api.Document;
+import org.apache.chemistry.opencmis.client.api.FileableCmisObject;
 import org.apache.chemistry.opencmis.client.api.Folder;
 import org.apache.chemistry.opencmis.client.api.ItemIterable;
+import org.apache.chemistry.opencmis.client.api.ObjectId;
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
 import org.apache.chemistry.opencmis.commons.enums.Action;
@@ -65,7 +67,6 @@ public class CMISProducer extends DefaultProducer {
         return (CMISEndpoint) super.getEndpoint();
     }
 
-    @Override
     public void process(Exchange exchange) throws Exception {
 
         CamelCMISActions action = exchange.getIn().getHeader(CamelCMISConstants.CMIS_ACTION,
CamelCMISActions.class);
@@ -78,6 +79,80 @@ public class CMISProducer extends DefaultProducer {
         exchange.getOut().setBody(object);
     }
 
+    /**
+     * This method is called via reflection.
+     * It is not safe to delete it or rename it!
+     * Method's name are defined and retrieved from {@link CamelCMISActions}.
+     */
+    @SuppressWarnings("unused")
+    public CmisObject findObjectById(Exchange exchange) throws Exception {
+        validateRequiredHeader(exchange, CamelCMISConstants.CMIS_OBJECT_ID);
+        Message message = exchange.getIn();
+
+        String objectId = message.getHeader(CamelCMISConstants.CMIS_OBJECT_ID, String.class);
+
+        return getSessionFacade().getObjectById(objectId);
+    }
+
+    /**
+     * This method is called via reflection.
+     * It is not safe to delete it or rename it!
+     * Method's name are defined and retrieved from {@link CamelCMISActions}.
+     */
+    @SuppressWarnings("unused")
+    public CmisObject findObjectByPath(Exchange exchange) throws Exception {
+        validateRequiredHeader(exchange, PropertyIds.PATH);
+        Message message = exchange.getIn();
+
+        String path = message.getHeader(PropertyIds.PATH, String.class);
+
+        try {
+            return getSessionFacade().getObjectByPath(path);
+        } catch (Exception e) {
+            throw new CamelCmisObjectNotFoundException("Can not find object by path :" +
path, e);
+        }
+    }
+
+    /**
+     * This method is called via reflection.
+     * It is not safe to delete it or rename it!
+     * Method's name are defined and retrieved from {@link CamelCMISActions}.
+     */
+    @SuppressWarnings("unused")
+    public ContentStream downloadDocument(Exchange exchange) throws Exception {
+        validateRequiredHeader(exchange, CamelCMISConstants.CMIS_OBJECT_ID);
+        Message message = exchange.getIn();
+
+        String objectId = message.getHeader(CamelCMISConstants.CMIS_OBJECT_ID, String.class);
+
+        CmisObject result = getSessionFacade().getObjectById(objectId);
+
+        if (result instanceof Document) {
+            return ((Document) result).getContentStream();
+        } else {
+            throw new CamelCmisException("Unable to get contentStream for document with id:
" + objectId);
+        }
+    }
+
+    /**
+     * This method is called via reflection.
+     * It is not safe to delete it or rename it!
+     * Method's name are defined and retrieved from {@link CamelCMISActions}.
+     */
+    @SuppressWarnings("unused")
+    public Folder getFolder(Exchange exchange) throws Exception {
+        validateRequiredHeader(exchange, CamelCMISConstants.CMIS_OBJECT_ID);
+        Message message = exchange.getIn();
+
+        String objectId = message.getHeader(CamelCMISConstants.CMIS_OBJECT_ID, String.class);
+        CmisObject result = getSessionFacade().getObjectById(objectId);
+        if (result instanceof Folder) {
+            return (Folder) result;
+        } else {
+            throw new CamelCmisObjectNotFoundException();
+        }
+    }
+
     private Map<String, Object> filterTypeProperties(Map<String, Object> properties)
throws Exception {
         Map<String, Object> result = new HashMap<>(properties.size());
 
@@ -138,6 +213,29 @@ public class CMISProducer extends DefaultProducer {
      * Method's name are defined and retrieved from {@link CamelCMISActions}.
      */
     @SuppressWarnings("unused")
+    public Folder createFolderByPath(Exchange exchange) throws Exception {
+        validateRequiredHeader(exchange, PropertyIds.PATH);
+        validateRequiredHeader(exchange, PropertyIds.NAME);
+
+        Message message = exchange.getIn();
+        Map<String, Object> cmisProperties = filterTypeProperties(message.getHeaders());
+        String parentPath = message.getHeader(PropertyIds.PATH, String.class);
+
+        CmisObject result = getSessionFacade().getObjectByPath(parentPath);
+
+        if (result instanceof Folder) {
+            return ((Folder) result).createFolder(cmisProperties);
+        }
+
+        throw new CamelCmisException("Can not create folder on path:" + parentPath);
+    }
+
+    /**
+     * This method is called via reflection.
+     * It is not safe to delete it or rename it!
+     * Method's name are defined and retrieved from {@link CamelCMISActions}.
+     */
+    @SuppressWarnings("unused")
     public List<String> deleteFolder(Exchange exchange) throws Exception {
         validateRequiredHeader(exchange, CamelCMISConstants.CMIS_OBJECT_ID);
 
@@ -160,9 +258,11 @@ public class CMISProducer extends DefaultProducer {
         Message message = exchange.getIn();
 
         String objectId = message.getHeader(CamelCMISConstants.CMIS_OBJECT_ID, String.class);
+        Boolean allVersions = message.getHeader(CamelCMISConstants.ALL_VERSIONS, Boolean.class);
+
         Document document = (Document) getSessionFacade().getObjectById(objectId);
 
-        document.deleteAllVersions();
+        document.delete(allVersions);
     }
 
     /**
@@ -171,7 +271,7 @@ public class CMISProducer extends DefaultProducer {
      * Method's name are defined and retrieved from {@link CamelCMISActions}.
      */
     @SuppressWarnings("unused")
-    public void moveDocument(Exchange exchange) throws Exception {
+    public CmisObject moveDocument(Exchange exchange) throws Exception {
         validateRequiredHeader(exchange, CamelCMISConstants.CMIS_DESTIONATION_FOLDER_ID);
         validateRequiredHeader(exchange, CamelCMISConstants.CMIS_SOURCE_FOLDER_ID);
         validateRequiredHeader(exchange, CamelCMISConstants.CMIS_OBJECT_ID);
@@ -194,13 +294,13 @@ public class CMISProducer extends DefaultProducer {
             }
 
             try {
-                document.move(sourceFolder, targetFolder);
-                log.info("Moved document from " + sourceFolder.getName() + " to " + targetFolder.getName());
+                log.info("Moving document from " + sourceFolder.getName() + " to " + targetFolder.getName());
+                return  document.move(sourceFolder, targetFolder);
             } catch (Exception e) {
                 throw new CamelCmisException("Cannot move document to folder " + targetFolder.getName()
+ " : " + e.getMessage(), e);
             }
         } else {
-            log.error("Document is null, cannot move!");
+            throw new CamelCmisException("Document is null, cannot move!");
         }
     }
 
@@ -210,7 +310,7 @@ public class CMISProducer extends DefaultProducer {
      * Method's name are defined and retrieved from {@link CamelCMISActions}.
      */
     @SuppressWarnings("unused")
-    public Map<String, String> moveFolder(Exchange exchange) throws Exception {
+    public FileableCmisObject moveFolder(Exchange exchange) throws Exception {
         validateRequiredHeader(exchange, CamelCMISConstants.CMIS_DESTIONATION_FOLDER_ID);
         validateRequiredHeader(exchange, CamelCMISConstants.CMIS_OBJECT_ID);
 
@@ -221,11 +321,7 @@ public class CMISProducer extends DefaultProducer {
 
         Folder toBeMoved = (Folder) getSessionFacade().getObjectById(objectId);
         Folder targetFolder = (Folder) getSessionFacade().getObjectById(destinationFolderId);
-
-        Map<String, String> folders = copyFolderRecursive(targetFolder, toBeMoved);
-        toBeMoved.deleteTree(true, UnfileObject.DELETE, true);
-
-        return folders;
+        return toBeMoved.move(toBeMoved.getFolderParent(), targetFolder);
     }
 
     /**
@@ -255,7 +351,7 @@ public class CMISProducer extends DefaultProducer {
      * Method's name are defined and retrieved from {@link CamelCMISActions}.
      */
     @SuppressWarnings("unused")
-    public Map<String, String> copyFolder(Exchange exchange) throws Exception {
+    public Map<String, CmisObject> copyFolder(Exchange exchange) throws Exception {
         validateRequiredHeader(exchange, CamelCMISConstants.CMIS_DESTIONATION_FOLDER_ID);
         validateRequiredHeader(exchange, CamelCMISConstants.CMIS_OBJECT_ID);
 
@@ -267,27 +363,45 @@ public class CMISProducer extends DefaultProducer {
         Folder destinationFolder = (Folder) getSessionFacade().getObjectById(destinationFolderId);
         Folder toCopyFolder = (Folder) getSessionFacade().getObjectById(toCopyFolderId);
 
-        return copyFolderRecursive(destinationFolder, toCopyFolder);
+        Map<String, CmisObject> result = new HashMap<>();
+        return copyFolderRecursive(destinationFolder, toCopyFolder, result);
+    }
+
+    /**
+     * This method is called via reflection.
+     * It is not safe to delete it or rename it!
+     * Method's name are defined and retrieved from {@link CamelCMISActions}.
+     */
+    @SuppressWarnings("unused")
+    public ItemIterable<CmisObject> listFolder(Exchange exchange) throws Exception
{
+        validateRequiredHeader(exchange, CamelCMISConstants.CMIS_OBJECT_ID);
+
+        Message message = exchange.getIn();
+
+        String sourceFolderId = message.getHeader(CamelCMISConstants.CMIS_OBJECT_ID, String.class);
+        Folder sourceFolder = (Folder) getSessionFacade().getObjectById(sourceFolderId);
+
+        return sourceFolder.getChildren();
     }
 
-    private Map<String, String> copyFolderRecursive(Folder destinationFolder, Folder
toCopyFolder) {
+    private Map<String, CmisObject> copyFolderRecursive(Folder destinationFolder, Folder
toCopyFolder, Map<String, CmisObject> result) {
         Map<String, Object> folderProperties = new HashMap<>();
         folderProperties.put(PropertyIds.NAME, toCopyFolder.getName());
         folderProperties.put(PropertyIds.OBJECT_TYPE_ID, toCopyFolder.getBaseTypeId().value());
-        Map<String, String> folders = new HashMap<>();
         Folder newFolder = destinationFolder.createFolder(folderProperties);
-        folders.put(toCopyFolder.getId(), newFolder.getId());
-        copyChildren(newFolder, toCopyFolder);
-        return folders;
+        result.put(toCopyFolder.getId(), newFolder);
+        copyChildren(newFolder, toCopyFolder, result);
+        return result;
     }
 
-    private void copyChildren(Folder destinationFolder, Folder toCopyFolder) {
+    private void copyChildren(Folder destinationFolder, Folder toCopyFolder, Map<String,
CmisObject> result) {
         ItemIterable<CmisObject> immediateChildren = toCopyFolder.getChildren();
         for (CmisObject child : immediateChildren) {
             if (child instanceof Document) {
-                ((Document) child).copy(destinationFolder);
+                Document newDocument = ((Document) child).copy(destinationFolder);
+                result.put(child.getId(), newDocument);
             } else if (child instanceof Folder) {
-                copyFolderRecursive(destinationFolder, (Folder) child);
+                copyFolderRecursive(destinationFolder, (Folder) child, result);
             }
         }
     }
@@ -312,7 +426,7 @@ public class CMISProducer extends DefaultProducer {
 
             return object;
         } catch (Exception e) {
-            throw new CamelCmisObjectNotFoundException("Object with id: " + objectId + "
can not be found!");
+            throw new CamelCmisObjectNotFoundException("Object with id: " + objectId + "
can not be found!", e);
         }
     }
 
@@ -322,7 +436,7 @@ public class CMISProducer extends DefaultProducer {
      * Method's name are defined and retrieved from {@link CamelCMISActions}.
      */
     @SuppressWarnings("unused")
-    public void checkIn(Exchange exchange) throws Exception {
+    public ObjectId checkIn(Exchange exchange) throws Exception {
         validateRequiredHeader(exchange, CamelCMISConstants.CMIS_OBJECT_ID);
 
         Message message = exchange.getIn();
@@ -335,12 +449,19 @@ public class CMISProducer extends DefaultProducer {
 
         byte[] bytes = message.getBody(byte[].class);
         Document document = (Document) getSessionFacade().getObjectById(objectId);
+        if (fileName == null) {
+            fileName = document.getName();
+        }
         Map<String, Object> properties = filterTypeProperties(message.getHeaders());
 
         ContentStream contentStream = getSessionFacade().createContentStream(fileName, bytes,
mimeType);
 
-        document.checkIn(true, properties, contentStream, checkInComment);
-
+        try {
+            return document.checkIn(true, properties, contentStream, checkInComment);
+        } catch (Exception e) {
+            document.cancelCheckOut();
+            throw e;
+        }
     }
 
     /**
@@ -349,7 +470,7 @@ public class CMISProducer extends DefaultProducer {
      * Method's name are defined and retrieved from {@link CamelCMISActions}.
      */
     @SuppressWarnings("unused")
-    public void checkOut(Exchange exchange) throws Exception {
+    public ObjectId checkOut(Exchange exchange) throws Exception {
         validateRequiredHeader(exchange, CamelCMISConstants.CMIS_OBJECT_ID);
 
         Message message = exchange.getIn();
@@ -357,7 +478,8 @@ public class CMISProducer extends DefaultProducer {
         String objectId = message.getHeader(CamelCMISConstants.CMIS_OBJECT_ID, String.class);
 
         Document document = (Document) getSessionFacade().getObjectById(objectId);
-        document.checkOut();
+
+        return document.checkOut();
     }
 
     /**
diff --git a/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CamelCMISActions.java
b/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CamelCMISActions.java
index c7163c8..fa4861c 100644
--- a/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CamelCMISActions.java
+++ b/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CamelCMISActions.java
@@ -38,7 +38,19 @@ public enum CamelCMISActions {
     CHECK_OUT { public String getMethodName() {
             return "checkOut"; }},
     CANCEL_CHECK_OUT { public String getMethodName() {
-            return "cancelCheckOut"; }};
+            return "cancelCheckOut"; }},
+    GET_FOLDER { public String getMethodName() {
+            return "getFolder"; }},
+    LIST_FOLDER { public String getMethodName() {
+            return "listFolder"; }},
+    FIND_OBJECT_BY_ID { public String getMethodName() {
+            return "findObjectById"; }},
+    FIND_OBJECT_BY_PATH { public String getMethodName() {
+            return "findObjectByPath"; }},
+    CREATE_FOLDER_BY_PATH { public String getMethodName() {
+            return "createFolderByPath"; }},
+    DOWNLOAD_DOCUMENT { public String getMethodName() {
+            return "downloadDocument"; }};
 
     public abstract String getMethodName();
 }
diff --git a/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CamelCMISConstants.java
b/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CamelCMISConstants.java
index 029b11a..1a380e8 100644
--- a/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CamelCMISConstants.java
+++ b/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CamelCMISConstants.java
@@ -29,5 +29,7 @@ public interface CamelCMISConstants {
     String CAMEL_CMIS_RETRIEVE_CONTENT = "CamelCMISRetrieveContent";
     String CAMEL_CMIS_READ_SIZE = "CamelCMISReadSize";
     String CAMEL_CMIS_CONTENT_STREAM = "CamelCMISContent";
+    String ALL_VERSIONS = "CamelCMISAllVersions";
 }
 
+
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 e6e1299..14a0efb 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
@@ -31,6 +31,7 @@ import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.chemistry.opencmis.client.api.CmisObject;
 import org.apache.chemistry.opencmis.client.api.Document;
+import org.apache.chemistry.opencmis.client.api.FileableCmisObject;
 import org.apache.chemistry.opencmis.client.api.Folder;
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
@@ -285,12 +286,9 @@ public class CMISProducerTest extends CMISTestSupport {
 
         template.send(exchange);
 
-        Map<String, String> movedFolders = exchange.getOut().getBody(HashMap.class);
+        FileableCmisObject movedFolder = exchange.getOut().getBody(FileableCmisObject.class);
 
-
-        Folder movedFolder = (Folder) createSession().getObject(movedFolders.get(toBeMoved.getId()));
-
-        assertEquals(movedFolder.getParentId(), destinationFolder.getId());
+        assertEquals(movedFolder.getParents().get(0).getId(), destinationFolder.getId());
     }
 
     @Test
@@ -346,10 +344,10 @@ public class CMISProducerTest extends CMISTestSupport {
 
         template.send(exchange);
 
-        Map<String, String> copiedFolders = exchange.getOut().getBody(HashMap.class);
+        Map<String, CmisObject> copiedFolders = exchange.getOut().getBody(HashMap.class);
 
         Folder copy = (Folder) createSession().getObject(copiedFolders.get(folder.getId()));
         assertEquals(folder.getName(), copy.getName());
         assertNotEquals(folder.getId(), copy.getId());
     }
-}
+}
\ No newline at end of file
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 f95b00f..edafa51 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/atom11";
+            = "http://localhost:%s/chemistry-opencmis-server-inmemory/atom11";
     protected static final String OPEN_CMIS_SERVER_WAR_PATH
-        = "target/dependency/chemistry-opencmis-server-inmemory.war";
+            = "target/dependency/chemistry-opencmis-server-inmemory.war";
 
     protected static Server cmisServer;
     protected static int port;
@@ -135,7 +135,7 @@ public class CMISTestSupport extends CamelTestSupport {
     }
 
     protected Document createTextDocument(Folder newFolder, String content, String fileName)
-        throws UnsupportedEncodingException {
+            throws UnsupportedEncodingException {
         byte[] buf = content.getBytes("UTF-8");
         ByteArrayInputStream input = new ByteArrayInputStream(buf);
         ContentStream contentStream = createSession().getObjectFactory()


Mime
View raw message