Search in sources :

Example 61 with Document

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

the class CmisSender method sendMessageForActionCreate.

private String sendMessageForActionCreate(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    String fileName = (String) prc.getSession().get(getFileNameSessionKey());
    InputStream inputStream = null;
    if (StringUtils.isNotEmpty(fileInputStreamSessionKey)) {
        inputStream = (FileInputStream) prc.getSession().get(getFileInputStreamSessionKey());
    } else {
        String fileContent = (String) prc.getSession().get(getFileContentSessionKey());
        byte[] bytes = Base64.decodeBase64((String) fileContent);
        inputStream = new ByteArrayInputStream(bytes);
    }
    long fileLength = 0;
    try {
        fileLength = inputStream.available();
    } catch (IOException e) {
        log.warn(getLogPrefix() + "could not determine file size", e);
    }
    String mediaType;
    Map props = new HashMap();
    Element cmisElement;
    try {
        if (XmlUtils.isWellFormed(message, "cmis")) {
            cmisElement = XmlUtils.buildElement(message);
        } else {
            cmisElement = XmlUtils.buildElement("<cmis/>");
        }
        String objectTypeId = XmlUtils.getChildTagAsString(cmisElement, "objectTypeId");
        if (StringUtils.isNotEmpty(objectTypeId)) {
            props.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
        } else {
            props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        }
        String name = XmlUtils.getChildTagAsString(cmisElement, "name");
        if (StringUtils.isEmpty(fileName)) {
            fileName = XmlUtils.getChildTagAsString(cmisElement, "fileName");
        }
        mediaType = XmlUtils.getChildTagAsString(cmisElement, "mediaType");
        if (StringUtils.isNotEmpty(name)) {
            props.put(PropertyIds.NAME, name);
        } else if (StringUtils.isNotEmpty(fileName)) {
            props.put(PropertyIds.NAME, fileName);
        } else {
            props.put(PropertyIds.NAME, "[unknown]");
        }
        Element propertiesElement = XmlUtils.getFirstChildTag(cmisElement, "properties");
        if (propertiesElement != null) {
            processProperties(propertiesElement, props);
        }
    } catch (DomBuilderException e) {
        throw new SenderException(getLogPrefix() + "exception parsing [" + message + "]", e);
    }
    if (StringUtils.isEmpty(mediaType)) {
        mediaType = getDefaultMediaType();
    }
    if (isUseRootFolder()) {
        Folder folder = session.getRootFolder();
        ContentStream contentStream = session.getObjectFactory().createContentStream(fileName, fileLength, mediaType, inputStream);
        Document document = folder.createDocument(props, contentStream, null);
        log.debug(getLogPrefix() + "created new document [ " + document.getId() + "]");
        return document.getId();
    } else {
        ContentStream contentStream = session.getObjectFactory().createContentStream(fileName, fileLength, mediaType, inputStream);
        ObjectId objectId = session.createDocument(props, null, contentStream, null);
        log.debug(getLogPrefix() + "created new document [ " + objectId.getId() + "]");
        return objectId.getId();
    }
}
Also used : HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) IOException(java.io.IOException) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 62 with Document

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

the class OpenCmisLocalTest method testALF10085.

public void testALF10085() throws InterruptedException {
    Repository repository = getRepository("admin", "admin");
    Session session = repository.createSession();
    Folder rootFolder = session.getRootFolder();
    Map<String, String> props = new HashMap<String, String>();
    {
        props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
        props.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
    }
    Document doc1 = rootFolder.createDocument(props, null, null);
    props = new HashMap<String, String>();
    {
        props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
        props.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
    }
    Document doc2 = rootFolder.createDocument(props, null, null);
    Thread.sleep(6000);
    session.getObject(doc1);
    doc1.refresh();
    Calendar doc1LastModifiedBefore = (Calendar) doc1.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
    assertNotNull(doc1LastModifiedBefore);
    doc2.refresh();
    Calendar doc2LastModifiedBefore = (Calendar) doc2.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
    assertNotNull(doc2LastModifiedBefore);
    // Add relationship A to B
    props = new HashMap<String, String>();
    {
        props.put(PropertyIds.OBJECT_TYPE_ID, "R:cmiscustom:assoc");
        props.put(PropertyIds.NAME, "A Relationship");
        props.put(PropertyIds.SOURCE_ID, doc1.getId());
        props.put(PropertyIds.TARGET_ID, doc2.getId());
    }
    session.createRelationship(props);
    doc1.refresh();
    Calendar doc1LastModifiedAfter = (Calendar) doc1.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
    assertNotNull(doc1LastModifiedAfter);
    doc2.refresh();
    Calendar doc2LastModifiedAfter = (Calendar) doc2.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
    assertNotNull(doc2LastModifiedAfter);
    assertEquals(doc1LastModifiedBefore, doc1LastModifiedAfter);
    assertEquals(doc2LastModifiedBefore, doc2LastModifiedAfter);
}
Also used : Repository(org.apache.chemistry.opencmis.client.api.Repository) HashMap(java.util.HashMap) Calendar(java.util.Calendar) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 63 with Document

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

the class OpenCmisLocalTest method testDownloadEvent.

public void testDownloadEvent() throws InterruptedException {
    Repository repository = getRepository("admin", "admin");
    Session session = repository.createSession();
    Folder rootFolder = session.getRootFolder();
    String docname = "mydoc-" + GUID.generate() + ".txt";
    Map<String, String> props = new HashMap<String, String>();
    {
        props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
        props.put(PropertyIds.NAME, docname);
    }
    // content
    byte[] byteContent = "Hello from Download testing class".getBytes();
    InputStream stream = new ByteArrayInputStream(byteContent);
    ContentStream contentStream = new ContentStreamImpl(docname, BigInteger.valueOf(byteContent.length), "text/plain", stream);
    Document doc1 = rootFolder.createDocument(props, contentStream, VersioningState.MAJOR);
    NodeRef doc1NodeRef = cmisIdToNodeRef(doc1.getId());
    ContentStream content = doc1.getContentStream();
    assertNotNull(content);
    // range request
    content = doc1.getContentStream(BigInteger.valueOf(2), BigInteger.valueOf(4));
    assertNotNull(content);
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.apache.chemistry.opencmis.client.api.Repository) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 64 with Document

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

the class OpenCmisLocalTest method testEncodingForCreateContentStream.

public void testEncodingForCreateContentStream() {
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    FileFolderService ffs = serviceRegistry.getFileFolderService();
    // Authenticate as system
    AuthenticationComponent authenticationComponent = (AuthenticationComponent) ctx.getBean(BEAN_NAME_AUTHENTICATION_COMPONENT);
    authenticationComponent.setSystemUserAsCurrentUser();
    try {
        /* Create the document using openCmis services */
        Repository repository = getRepository("admin", "admin");
        Session session = repository.createSession();
        Folder rootFolder = session.getRootFolder();
        Document document = createDocument(rootFolder, "test_file_" + GUID.generate() + ".txt", session);
        ContentStream content = document.getContentStream();
        assertNotNull(content);
        content = document.getContentStream(BigInteger.valueOf(2), BigInteger.valueOf(4));
        assertNotNull(content);
        NodeRef doc1NodeRef = cmisIdToNodeRef(document.getId());
        FileInfo fileInfo = ffs.getFileInfo(doc1NodeRef);
        Map<QName, Serializable> properties = fileInfo.getProperties();
        ContentDataWithId contentData = (ContentDataWithId) properties.get(QName.createQName("{http://www.alfresco.org/model/content/1.0}content"));
        String encoding = contentData.getEncoding();
        assertEquals("ISO-8859-1", encoding);
    } finally {
        authenticationComponent.clearCurrentSecurityContext();
    }
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) ContentDataWithId(org.alfresco.repo.domain.node.ContentDataWithId) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.apache.chemistry.opencmis.client.api.Repository) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) AuthenticationComponent(org.alfresco.repo.security.authentication.AuthenticationComponent) FileInfo(org.alfresco.service.cmr.model.FileInfo) ServiceRegistry(org.alfresco.service.ServiceRegistry) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 65 with Document

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

the class CmisIntegrationTest method getDocumentContentAsString.

private String getDocumentContentAsString(String nodeId) throws Exception {
    CmisObject cmisObject = retrieveCMISObjectByIdFromServer(nodeId);
    Document doc = (Document) cmisObject;
    InputStream inputStream = doc.getContentStream().getStream();
    return readFromStream(inputStream);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Document(org.apache.chemistry.opencmis.client.api.Document)

Aggregations

Document (org.apache.chemistry.opencmis.client.api.Document)101 Folder (org.apache.chemistry.opencmis.client.api.Folder)62 HashMap (java.util.HashMap)43 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)41 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)40 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)36 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)30 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)28 ByteArrayInputStream (java.io.ByteArrayInputStream)27 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)25 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)23 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)21 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)20 ArrayList (java.util.ArrayList)19 Test (org.junit.Test)19 InputStream (java.io.InputStream)18 NodeRef (org.alfresco.service.cmr.repository.NodeRef)17 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)17 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)16 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)16