Search in sources :

Example 6 with CmisObject

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

the class CMISTestSupport method deleteAllContent.

protected void deleteAllContent() {
    Session session = createSession();
    Folder rootFolder = session.getRootFolder();
    ItemIterable<CmisObject> children = rootFolder.getChildren();
    for (CmisObject cmisObject : children) {
        if ("cmis:folder".equals(cmisObject.getPropertyValue(PropertyIds.OBJECT_TYPE_ID))) {
            List<String> notDeltedIdList = ((Folder) cmisObject).deleteTree(true, UnfileObject.DELETE, true);
            if (notDeltedIdList != null && notDeltedIdList.size() > 0) {
                throw new RuntimeException("Cannot empty repo");
            }
        } else {
            cmisObject.delete(true);
        }
    }
    session.getBinding().close();
}
Also used : CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Folder(org.apache.chemistry.opencmis.client.api.Folder) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 7 with CmisObject

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

the class CMISProducer method createNode.

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 = getSessionFacade().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);
    }
}
Also used : ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) Message(org.apache.camel.Message) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Folder(org.apache.chemistry.opencmis.client.api.Folder)

Example 8 with CmisObject

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

the class CMISProducer method process.

public void process(Exchange exchange) throws Exception {
    CmisObject cmisObject = createNode(exchange);
    LOG.debug("Created node with id: {}", cmisObject.getId());
    // copy the header of in message to the out message
    exchange.getOut().copyFrom(exchange.getIn());
    exchange.getOut().setBody(cmisObject.getId());
}
Also used : CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject)

Example 9 with CmisObject

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

the class CMISProducerTest method createDocumentWithoutContentByExplicitlySpecifyingObjectTypeHeader.

@Test
public void createDocumentWithoutContentByExplicitlySpecifyingObjectTypeHeader() throws Exception {
    Exchange exchange = createExchangeWithInBody(null);
    exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
    exchange.getIn().getHeaders().put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
    exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
    template.send(exchange);
    String newNodeId = exchange.getOut().getBody(String.class);
    assertNotNull(newNodeId);
    CmisObject cmisObject = retrieveCMISObjectByIdFromServer(newNodeId);
    Document doc = (Document) cmisObject;
    assertEquals("cmis:document", doc.getPropertyValue(PropertyIds.OBJECT_TYPE_ID));
}
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)

Example 10 with CmisObject

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

the class CMISProducerTest method cmisSecondaryTypePropertiesAreStored.

@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"));
}
Also used : Exchange(org.apache.camel.Exchange) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) 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