Search in sources :

Example 1 with Document

use of org.apache.chemistry.opencmis.client.api.Document 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 2 with Document

use of org.apache.chemistry.opencmis.client.api.Document 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)

Example 3 with Document

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

the class CMISProducerTest method createDocumentAtSpecificPath.

@Test
public void createDocumentAtSpecificPath() throws Exception {
    Folder folder1 = createFolderWithName("Folder1");
    createChildFolderWithName(folder1, "Folder2");
    String existingFolderStructure = "/Folder1/Folder2";
    Exchange exchange = createExchangeWithInBody("Some content to be stored");
    exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
    exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
    exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_FOLDER_PATH, existingFolderStructure);
    template.send(exchange);
    String newNodeId = exchange.getOut().getBody(String.class);
    Document document = (Document) retrieveCMISObjectByIdFromServer(newNodeId);
    String documentFullPath = document.getPaths().get(0);
    assertEquals(existingFolderStructure + "/test.file", documentFullPath);
}
Also used : Exchange(org.apache.camel.Exchange) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) Test(org.junit.Test)

Example 4 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project alfresco-remote-api by Alfresco.

the class TestCMIS method testMNT_10161.

/* MNT-10161 related test - mapping of cmis:description for CMIS 1.1 */
@Test
public void testMNT_10161() throws Exception {
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person1 = network1.createUser(personInfo);
    String person1Id = person1.getId();
    final String siteName = "site" + System.currentTimeMillis();
    final String nodeDescription = "Test description";
    final String nodeName = GUID.generate();
    TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {

        @Override
        public NodeRef doWork() throws Exception {
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            TestSite site = repoService.createSite(null, siteInfo);
            NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), nodeName);
            /* create node with property description */
            return repoService.createDocument(folderNodeRef, nodeName, "title", nodeDescription, "content");
        }
    }, person1Id, network1.getId());
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
    Document doc = (Document) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary/" + nodeName + "/" + nodeName);
    /* ensure we got the node */
    assertNotNull(doc);
    /* get mapped cmis:description */
    Property<?> descrProperty = doc.getProperty(PropertyIds.DESCRIPTION);
    /* ensure that cmis:description is set properly */
    assertTrue(nodeDescription.equals(descrProperty.getValue()));
}
Also used : CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) AlfrescoDocument(org.alfresco.cmis.client.AlfrescoDocument) Document(org.apache.chemistry.opencmis.client.api.Document) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 5 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project alfresco-remote-api by Alfresco.

the class TestCMIS method testContentDisposition_MNT_17477.

@Test
public void testContentDisposition_MNT_17477() throws Exception {
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person1 = network1.createUser(personInfo);
    String person1Id = person1.getId();
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.browser, CMIS_VERSION_11, AlfrescoObjectFactoryImpl.class.getName());
    Folder folder = (Folder) cmisSession.getObjectByPath("/Shared");
    // 
    // Upload test JPG document
    // 
    String name = GUID.generate() + ".jpg";
    Map<String, Object> properties = new HashMap<>();
    {
        properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
        properties.put(PropertyIds.NAME, name);
    }
    ContentStreamImpl fileContent = new ContentStreamImpl();
    {
        fileContent.setMimeType(MimetypeMap.MIMETYPE_IMAGE_JPEG);
        fileContent.setStream(this.getClass().getResourceAsStream("/test.jpg"));
    }
    Document doc = folder.createDocument(properties, fileContent, VersioningState.MAJOR);
    String docId = doc.getId();
    // note: Content-Disposition can be "inline or "attachment" for content types that are white-listed (eg. specific image types & pdf)
    HttpResponse response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/browser/root/Shared/" + name, null);
    assertEquals(200, response.getStatusCode());
    assertTrue(response.getHeaders().get("Content-Disposition").startsWith("inline"));
    response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/browser/root/Shared/" + name + "?download=inline", null);
    assertEquals(200, response.getStatusCode());
    assertTrue(response.getHeaders().get("Content-Disposition").startsWith("inline"));
    response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/browser/root/Shared/" + name + "?download=attachment", null);
    assertEquals(200, response.getStatusCode());
    assertTrue(response.getHeaders().get("Content-Disposition").startsWith("attachment"));
    // note: AtomPub binding (via OpenCMIS) does not support "download" query parameter
    response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/atom/content?id=" + docId, null);
    assertEquals(200, response.getStatusCode());
    assertTrue(response.getHeaders().get("Content-Disposition").startsWith("attachment"));
    // 
    // Create test HTML document
    // 
    name = GUID.generate() + ".html";
    properties = new HashMap<>();
    {
        properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
        properties.put(PropertyIds.NAME, name);
    }
    fileContent = new ContentStreamImpl();
    {
        ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".html"));
        writer.putContent("<html><script>alert(123);</script><body>Hello <b>world</b></body</html>");
        ContentReader reader = writer.getReader();
        fileContent.setMimeType(MimetypeMap.MIMETYPE_HTML);
        fileContent.setStream(reader.getContentInputStream());
    }
    doc = folder.createDocument(properties, fileContent, VersioningState.MAJOR);
    docId = doc.getId();
    // note: Content-Disposition will always be "attachment" for content types that are not white-listed
    response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/browser/root/Shared/" + name, null);
    assertEquals(200, response.getStatusCode());
    assertTrue(response.getHeaders().get("Content-Disposition").startsWith("attachment;"));
    response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/browser/root/Shared/" + name + "?download=inline", null);
    assertEquals(200, response.getStatusCode());
    assertTrue(response.getHeaders().get("Content-Disposition").startsWith("attachment;"));
    // note: AtomPub binding (via OpenCMIS) does not support "download" query parameter
    response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/atom/content?id=" + docId, null);
    assertEquals(200, response.getStatusCode());
    assertTrue(response.getHeaders().get("Content-Disposition").startsWith("attachment;"));
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) HashMap(java.util.HashMap) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) AlfrescoFolder(org.alfresco.cmis.client.AlfrescoFolder) Folder(org.apache.chemistry.opencmis.client.api.Folder) AlfrescoDocument(org.alfresco.cmis.client.AlfrescoDocument) Document(org.apache.chemistry.opencmis.client.api.Document) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Aggregations

Document (org.apache.chemistry.opencmis.client.api.Document)64 Folder (org.apache.chemistry.opencmis.client.api.Folder)39 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)32 HashMap (java.util.HashMap)30 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)25 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)18 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)18 Test (org.junit.Test)18 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)17 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)17 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)17 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)17 ByteArrayInputStream (java.io.ByteArrayInputStream)16 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)16 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)15 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)15 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)15 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)15 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)15 ArrayList (java.util.ArrayList)14