You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/08/21 12:29:31 UTC
[camel] branch master updated: CAMEL-15417 Add optional fileName
parameter on copyDocument function (#4097)
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 21b0010 CAMEL-15417 Add optional fileName parameter on copyDocument function (#4097)
21b0010 is described below
commit 21b00103f638eb97d15c6498de86fc8d58245b9c
Author: Vladimir Cherepnalkovski <ch...@hotmail.com>
AuthorDate: Fri Aug 21 14:26:58 2020 +0200
CAMEL-15417 Add optional fileName parameter on copyDocument function (#4097)
* Add optional fileName parameter on copyDocument function
* Replace StringUtils utils with ObjectHelper and replace deprecated (getOut) with getMessage method.
* Replace updateProperties with another document copy function that accepts new document properties.
---
.../apache/camel/component/cmis/CMISProducer.java | 10 +++++++--
.../camel/component/cmis/CMISQueryProducer.java | 4 ++--
.../camel/component/cmis/CMISProducerTest.java | 24 ++++++++++++++++++++++
3 files changed, 34 insertions(+), 4 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 4a5b14d..9187dcc 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
@@ -19,6 +19,7 @@ package org.apache.camel.component.cmis;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -79,8 +80,8 @@ public class CMISProducer extends DefaultProducer {
Method method = ReflectionHelper.findMethod(this.getClass(), action.getMethodName(), paramMethod);
Object object = ObjectHelper.invokeMethod(method, this, exchange);
- exchange.getOut().copyFrom(exchange.getIn());
- exchange.getOut().setBody(object);
+ exchange.getMessage().copyFrom(exchange.getIn());
+ exchange.getMessage().setBody(object);
}
/**
@@ -336,6 +337,11 @@ public class CMISProducer extends DefaultProducer {
Document document = (Document) getSessionFacade().getObjectById(objectId);
+ String newDocumentName = message.getHeader(PropertyIds.NAME, String.class);
+ if(org.apache.camel.util.ObjectHelper.isNotEmpty(newDocumentName)) {
+ return document.copy(destinationFolder, Collections.singletonMap(PropertyIds.NAME, newDocumentName), VersioningState.NONE, null, null, null, getSessionFacade().createOperationContext());
+ }
+
return document.copy(destinationFolder);
}
diff --git a/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CMISQueryProducer.java b/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CMISQueryProducer.java
index e338c07..19ce051 100644
--- a/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CMISQueryProducer.java
+++ b/components/camel-cmis/src/main/java/org/apache/camel/component/cmis/CMISQueryProducer.java
@@ -46,8 +46,8 @@ public class CMISQueryProducer extends DefaultProducer {
@Override
public void process(Exchange exchange) throws Exception {
List<Map<String, Object>> nodes = executeQuery(exchange);
- exchange.getOut().setBody(nodes);
- exchange.getOut().setHeader(CamelCMISConstants.CAMEL_CMIS_RESULT_COUNT, nodes.size());
+ exchange.getMessage().setBody(nodes);
+ exchange.getMessage().setHeader(CamelCMISConstants.CAMEL_CMIS_RESULT_COUNT, nodes.size());
}
private List<Map<String, Object>> executeQuery(Exchange exchange) throws Exception {
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 fd200f8..c2bc4a0 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
@@ -342,6 +342,30 @@ public class CMISProducerTest extends CMISTestSupport {
}
@Test
+ void copyDocumentWithNewName() throws UnsupportedEncodingException {
+ Folder destination = createFolderWithName("Destination");
+ Document document = createTextDocument(createSession().getRootFolder(), "This is new test document", "document.txt");
+
+ Exchange exchange = createExchangeWithInBody(null);
+ exchange.getIn().getHeaders().put(PropertyIds.OBJECT_TYPE_ID, CamelCMISConstants.CMIS_DOCUMENT);
+ exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_ACTION, CamelCMISActions.COPY_DOCUMENT);
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "renamedDocument.txt");
+ exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_OBJECT_ID, document.getId());
+ exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_DESTIONATION_FOLDER_ID, destination.getId());
+
+ template.send(exchange);
+
+ Document copy = exchange.getMessage().getBody(Document.class);
+
+ assertNotNull(copy);
+ assertNotEquals(document.getName(), copy.getName());
+ assertEquals(document.getName(), "document.txt");
+ assertEquals(copy.getName(), "renamedDocument.txt");
+ assertEquals(document.getContentStreamLength(), copy.getContentStreamLength());
+ assertEquals(destination.getId(), copy.getParents().get(0).getId());
+ }
+
+ @Test
void copyFolder() {
Folder folder = createFolderWithName("Folder");
Folder destination = createFolderWithName("Destination Folder");