Search in sources :

Example 1 with CmisObject

use of org.apache.chemistry.opencmis.client.api.CmisObject in project camel by apache.

the class RecursiveTreeWalker method processFolderRecursively.

int processFolderRecursively(Folder folder) throws Exception {
    processFolderNode(folder);
    OperationContext operationContext = cmisConsumer.createOperationContext();
    operationContext.setMaxItemsPerPage(pageSize);
    int count = 0;
    int pageNumber = 0;
    boolean finished = false;
    ItemIterable<CmisObject> itemIterable = folder.getChildren(operationContext);
    while (!finished) {
        ItemIterable<CmisObject> currentPage = itemIterable.skipTo(count).getPage();
        LOG.debug("Processing page {}", pageNumber);
        for (CmisObject child : currentPage) {
            if (CMISHelper.isFolder(child)) {
                Folder childFolder = (Folder) child;
                processFolderRecursively(childFolder);
            } else {
                processNonFolderNode(child, folder);
            }
            count++;
            if (totalPolled == readCount) {
                finished = true;
                break;
            }
        }
        pageNumber++;
        if (!currentPage.getHasMoreItems()) {
            finished = true;
        }
    }
    return totalPolled;
}
Also used : OperationContext(org.apache.chemistry.opencmis.client.api.OperationContext) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Folder(org.apache.chemistry.opencmis.client.api.Folder)

Example 2 with CmisObject

use of org.apache.chemistry.opencmis.client.api.CmisObject in project camel by apache.

the class RecursiveTreeWalker method processNonFolderNode.

private void processNonFolderNode(CmisObject cmisObject, Folder parentFolder) throws Exception {
    InputStream inputStream = null;
    Map<String, Object> properties = CMISHelper.objectProperties(cmisObject);
    properties.put(CamelCMISConstants.CMIS_FOLDER_PATH, parentFolder.getPath());
    if (CMISHelper.isDocument(cmisObject) && readContent) {
        ContentStream contentStream = ((Document) cmisObject).getContentStream();
        if (contentStream != null) {
            inputStream = contentStream.getStream();
        }
    }
    sendNode(properties, inputStream);
}
Also used : ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) InputStream(java.io.InputStream) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 3 with CmisObject

use of org.apache.chemistry.opencmis.client.api.CmisObject in project camel by apache.

the class CMISProducerTest method emptyBodyAndMissingObjectTypeHeaderCreatesFolderNode.

@Test
public void emptyBodyAndMissingObjectTypeHeaderCreatesFolderNode() throws Exception {
    Exchange exchange = createExchangeWithInBody(null);
    exchange.getIn().getHeaders().put(PropertyIds.NAME, "testFolder");
    template.send(exchange);
    String newNodeId = exchange.getOut().getBody(String.class);
    assertNotNull(newNodeId);
    CmisObject newNode = retrieveCMISObjectByIdFromServer(newNodeId);
    assertEquals("cmis:folder", newNode.getType().getId());
    assertTrue(newNode instanceof Folder);
}
Also used : Exchange(org.apache.camel.Exchange) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Folder(org.apache.chemistry.opencmis.client.api.Folder) Test(org.junit.Test)

Example 4 with CmisObject

use of org.apache.chemistry.opencmis.client.api.CmisObject in project camel by apache.

the class CMISProducerTest method cmisPropertiesAreStored.

@Test
public void cmisPropertiesAreStored() throws Exception {
    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");
    template.send(exchange);
    String newNodeId = exchange.getOut().getBody(String.class);
    CmisObject newNode = retrieveCMISObjectByIdFromServer(newNodeId);
    assertEquals("test.txt", newNode.getPropertyValue(PropertyIds.NAME));
    assertEquals("text/plain; charset=UTF-8", newNode.getPropertyValue(PropertyIds.CONTENT_STREAM_MIME_TYPE));
}
Also used : Exchange(org.apache.camel.Exchange) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Test(org.junit.Test)

Example 5 with CmisObject

use of org.apache.chemistry.opencmis.client.api.CmisObject in project camel by apache.

the class CMISProducerTest method getDocumentMimeTypeFromMessageContentType.

@Test
public void getDocumentMimeTypeFromMessageContentType() throws Exception {
    Exchange exchange = createExchangeWithInBody("Some content to be store");
    exchange.getIn().getHeaders().put(Exchange.CONTENT_TYPE, "text/plain");
    exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
    template.send(exchange);
    String newNodeId = exchange.getOut().getBody(String.class);
    CmisObject cmisObject = retrieveCMISObjectByIdFromServer(newNodeId);
    Document doc = (Document) cmisObject;
    assertEquals("text/plain", doc.getPropertyValue(PropertyIds.CONTENT_STREAM_MIME_TYPE));
}
Also used : Exchange(org.apache.camel.Exchange) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Document(org.apache.chemistry.opencmis.client.api.Document) Test(org.junit.Test)

Aggregations

CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)11 Exchange (org.apache.camel.Exchange)5 Test (org.junit.Test)5 Document (org.apache.chemistry.opencmis.client.api.Document)4 Folder (org.apache.chemistry.opencmis.client.api.Folder)4 InputStream (java.io.InputStream)2 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Message (org.apache.camel.Message)1 OperationContext (org.apache.chemistry.opencmis.client.api.OperationContext)1 Session (org.apache.chemistry.opencmis.client.api.Session)1