Package org.apache.chemistry.opencmis.client.api

Examples of org.apache.chemistry.opencmis.client.api.Document


    String[] rval = new String[documentIdentifiers.length];
    int i = 0;
    while (i < rval.length){
      CmisObject cmisObject = session.getObject(documentIdentifiers[i]);
      if (cmisObject.getBaseType().getId().equals(CMIS_DOCUMENT_BASE_TYPE)) {
        Document document = (Document) cmisObject;
       
        //we have to check if this CMIS repository support versioning
        // or if the versioning is disabled for this content
        if(StringUtils.isNotEmpty(document.getVersionLabel())){
          rval[i] = document.getVersionLabel();
        } else {
        //a CMIS document that doesn't contain versioning information will always be processed
          rval[i] = StringUtils.EMPTY;
        }
      } else {
View Full Code Here


        OperationContext oc = session.createOperationContext();
        oc.setFilterString("*");
        oc.setCacheEnabled(false);

        // set new name and save
        Document doc2 = (Document) session.getObject(id, oc);
        TransientDocument tdoc2 = doc2.getTransientDocument();

        assertEquals(filename1, tdoc2.getName());

        ContentStream cs2 = tdoc2.getContentStream();
        assertNotNull(cs2);
        assertContent(buf1, readContent(cs2));

        String filename2 = UUID.randomUUID().toString();
        tdoc2.setName(filename2);
        assertEquals(filename2, tdoc2.getName());

        ObjectId id2 = tdoc2.save();
        assertNotNull(id2);

        // set new content and save
        Document doc3 = (Document) session.getObject(id2, oc);
        TransientDocument tdoc3 = doc3.getTransientDocument();

        assertEquals(filename2, tdoc3.getName());

        ContentStream cs3 = tdoc3.getContentStream();
        assertNotNull(cs3);
        assertContent(buf1, readContent(cs3));

        String content3 = "Es rauscht noch.";

        byte[] buf3 = content3.getBytes("UTF-8");
        ByteArrayInputStream in3 = new ByteArrayInputStream(buf3);
        ContentStream contentStream3 = session.getObjectFactory()
                .createContentStream(tdoc3.getName(), buf3.length, mimetype,
                        in3);
        assertNotNull(contentStream3);

        tdoc3.setContentStream(contentStream3, true);

        ObjectId id3 = tdoc3.save();
        assertNotNull(id3);

        // set new name, delete content and save
        Document doc4 = (Document) session.getObject(id3, oc);
        TransientDocument tdoc4 = doc4.getTransientDocument();

        assertEquals(tdoc3.getName(), tdoc4.getName());

        ContentStream cs4 = tdoc4.getContentStream();
        assertNotNull(cs4);
        assertContent(buf3, readContent(cs4));

        String filename4 = UUID.randomUUID().toString();
        tdoc4.setName(filename4);
        assertEquals(filename4, tdoc4.getName());

        tdoc4.deleteContentStream();

        ObjectId id4 = tdoc4.save();
        assertNotNull(id4);

        // delete object
        Document doc5 = (Document) session.getObject(id4, oc);
        TransientDocument tdoc5 = doc5.getTransientDocument();

        assertEquals(filename4, tdoc5.getName());

        ContentStream cs5 = tdoc4.getContentStream();
        assertNull(cs5);
View Full Code Here

    @Test
    public void transientDocumentSessionCheck() {
        String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/"
                + FixtureData.DOCUMENT1_NAME;
        Document document1 = (Document) session.getObjectByPath(path);
        assertNotNull("document not found: " + path, document1);

        TransientDocument tdoc = document1.getTransientDocument();
        assertNotNull(tdoc);

        String newDocName = UUID.randomUUID().toString();
        tdoc.setPropertyValue(PropertyIds.NAME, newDocName);

        Document doc2 = (Document) session2.getObjectByPath(path);
        assertNotNull(doc2);
        assertEquals(doc2.getProperty(PropertyIds.NAME).getValueAsString(),
                FixtureData.DOCUMENT1_NAME.toString());
        assertEquals(tdoc.getProperty(PropertyIds.NAME).getValueAsString(),
                newDocName);

        tdoc.save();
        session2.clear();

        ObjectId id = session2.createObjectId(tdoc.getId());

        Document doc3 = (Document) session2.getObject(id);
        assertNotNull(doc3);
        assertEquals(doc3.getProperty(PropertyIds.NAME).getValueAsString(),
                newDocName);
    }
View Full Code Here

        ObjectId id = session.createDocument(properties, parentId, null, VersioningState.NONE);
        assertNotNull(id);

        // set and verify content
        Document doc = (Document) session.getObject(id);
        assertNotNull(doc);
        doc.setContentStream(contentStream, false);

        doc.refresh();
        assertEquals(buf1.length, doc.getContentStreamLength());
        assertEquals(mimetype, doc.getContentStreamMimeType());
        assertEquals(filename, doc.getContentStreamFileName());
        String content2 = getContentAsString(doc.getContentStream());
        assertEquals(content1, content2);
    }
View Full Code Here

        ByteArrayInputStream in2 = new ByteArrayInputStream(buf2);
        ContentStream contentStream2 = session.getObjectFactory().createContentStream(filename2, buf2.length,
                mimetype, in2);
        assertNotNull(contentStream2);

        Document doc = (Document) session.getObject(id);
        assertNotNull(doc);
        doc.setContentStream(contentStream2, true);

        doc.refresh();
        assertEquals(buf2.length, doc.getContentStreamLength());
        assertEquals(mimetype, doc.getContentStreamMimeType());
        assertEquals(filename2, doc.getContentStreamFileName());
        String content3 = getContentAsString(doc.getContentStream());
        assertEquals(content2, content3);
    }
View Full Code Here

        ByteArrayInputStream in2 = new ByteArrayInputStream(buf2);
        ContentStream contentStream2 = session.getObjectFactory().createContentStream(filename2, buf2.length,
                mimetype, in2);
        assertNotNull(contentStream2);

        Document doc = (Document) session.getObject(id);
        assertNotNull(doc);
        doc.setContentStream(contentStream2, false);

        doc.refresh();
        assertEquals(buf2.length, doc.getContentStreamLength());
        assertEquals(mimetype, doc.getContentStreamMimeType());
        assertEquals(filename2, doc.getContentStreamFileName());
        String content3 = getContentAsString(doc.getContentStream());
        assertEquals(content2, content3);
    }
View Full Code Here

            if ((row > -1) && (row < model.getCurrentChildren().size())) {
                String id = getValueAt(row, ID_COLUMN).toString();
                CmisObject object = model.getFromCurrentChildren(id);

                if (object instanceof Document) {
                    Document doc = (Document) object;

                    File tempFile = null;
                    try {
                        tempFile = ClientHelper.createTempFileFromDocument(doc, null);
                    } catch (Exception e) {
View Full Code Here

        ObjectId id = session.createDocument(properties, parentId, contentStream, VersioningState.NONE);
        assertNotNull(id);

        // verify content
        Document doc = (Document) session.getObject(id);
        assertNotNull(doc);
        // Assert.assertEquals(buf1.length, doc.getContentStreamLength());
        // Assert.assertEquals(mimetype, doc.getContentStreamMimeType());
        // Assert.assertEquals(filename, doc.getContentStreamFileName());
        String content2 = getContentAsString(doc.getContentStream());
        assertEquals(content1, content2);
    }
View Full Code Here

        ObjectId id = session.createDocument(properties, parentId, null, VersioningState.NONE);
        assertNotNull(id);

        // verify content
        Document doc = (Document) session.getObject(id);
        assertNotNull(doc);

        final int size = 1 * 1024 * 1024 * 1024; // 1GB

        InputStream in = new InputStream() {

            private int counter = -1;

            @Override
            public int read() throws IOException {
                counter++;
                if (counter >= size) {
                    return -1;
                }

                return '0' + (counter / 10);
            }
        };

        ContentStream contentStream = session.getObjectFactory().createContentStream(filename, size, mimetype, in);
        assertNotNull(contentStream);

        long start = System.currentTimeMillis();
        doc.setContentStream(contentStream, true);
        long end = System.currentTimeMillis();

        log.info("setContentStream of " + size + " bytes:" + (end - start) + "ms");
    }
View Full Code Here

    @Test
    public void createDocumentFromSource() throws IOException {
        try {
            // verify content
            String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + FixtureData.DOCUMENT1_NAME;
            Document srcDocument = (Document) session.getObjectByPath(path);
            assertNotNull("Document not found: " + path, srcDocument);
            String srcContent = getContentAsString(srcDocument.getContentStream());

            ObjectId parentFolder = session.createObjectId(fixture.getTestRootId());
            String name = UUID.randomUUID().toString();

            Map<String, Object> properties = new HashMap<String, Object>();
            properties.put(PropertyIds.NAME, name);

            ObjectId dstDocumentId = session.createDocumentFromSource(srcDocument, properties, parentFolder,
                    VersioningState.NONE);
            assertNotNull(dstDocumentId);
            Document dstDocument = (Document) session.getObject(dstDocumentId);
            String dstContent = getContentAsString(dstDocument.getContentStream());
            assertEquals(srcContent, dstContent);

        } catch (CmisNotSupportedException e) {
            // not an error
            log.info(e.getMessage());
View Full Code Here

TOP

Related Classes of org.apache.chemistry.opencmis.client.api.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.