Package org.apache.chemistry.opencmis.commons.data

Examples of org.apache.chemistry.opencmis.commons.data.ContentStream


        checkIsVersionableObject(so);

        VersionedDocument verDoc = getVersionedDocumentOfObjectId(so);

        ContentStream content = null;

        if (so instanceof DocumentVersion) {
            // get document the version is contained in to c
            content = ((DocumentVersion) so).getContent(0, -1);
        } else {
View Full Code Here


import org.apache.chemistry.opencmis.inmemory.storedobj.api.VersionedDocument;

public class PropertyUtil {
   
    public static Object getProperty(StoredObject so, String propertyId) {
        ContentStream content = null;
        DocumentVersion ver = null;
        VersionedDocument verDoc = null;
        Folder folder = null;
        Document doc = null;

        if (so instanceof Content)
            content = ((Content) so).getContent(0, 0);
        if (so instanceof DocumentVersion)
            ver = (DocumentVersion) so;
        if (so instanceof VersionedDocument)
            verDoc = (VersionedDocument) so;
        if (so instanceof Folder)
            folder = (Folder) so;
        if (so instanceof Document)
            doc = (Document) so;

        // generic properties:
        if (propertyId.equals(PropertyIds.NAME)) {
            return so.getName();
        }
        if (propertyId.equals(PropertyIds.OBJECT_ID)) {
            return so.getId();
        }
        if (propertyId.equals(PropertyIds.OBJECT_TYPE_ID)) {
            return so.getTypeId();
        }
        if (propertyId.equals(PropertyIds.BASE_TYPE_ID)) {
            return null; // TOODO: return so.getBaseTypeId());
        }
        if (propertyId.equals(PropertyIds.CREATED_BY)) {
            return so.getCreatedBy();
        }
        if (propertyId.equals(PropertyIds.CREATION_DATE)) {
            return so.getCreatedAt();
        }
        if (propertyId.equals(PropertyIds.LAST_MODIFIED_BY)) {
            return so.getModifiedBy();
        }
        if (propertyId.equals(PropertyIds.LAST_MODIFICATION_DATE)) {
            return so.getModifiedAt();
        }
        if (propertyId.equals(PropertyIds.CHANGE_TOKEN)) {
            return so.getChangeToken();
        }

        if (ver != null) {
            // get version related properties
            // not support on a version, only on a versioned document:
            // VERSION_SERIES_ID, IS_VERSION_SERIES_CHECKED_OUT,
            // VERSION_SERIES_CHECKED_OUT_BY,
            // VERSION_SERIES_CHECKED_OUT_ID, IS_LATEST_MAJOR_VERSION,
            // IS_LATEST_VERSION
            if (propertyId.equals(PropertyIds.IS_MAJOR_VERSION)) {
                return ver.isMajor();
            }

            if (propertyId.equals(PropertyIds.CHECKIN_COMMENT)) {
                return ver.getCheckinComment();
            }
            if (propertyId.equals(PropertyIds.VERSION_LABEL)) {
                return ver.getVersionLabel();
            }
            if (propertyId.equals(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID)) {
                return ver.isPwc() ? ver.getId() : null;
            }
        }

        // get versioned document related properties
        if (verDoc != null) {
            if (propertyId.equals(PropertyIds.VERSION_SERIES_ID)) {
                return verDoc.getId();
            }
            if (propertyId.equals(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT)) {
                return verDoc.isCheckedOut();
            }
            if (propertyId.equals(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY)) {
                return verDoc.getCheckedOutBy();
            }
        }

        // Set the content related properties
        if (null != content) {
            // omit: PropertyIds.CMIS_CONTENT_STREAM_ID
            if (propertyId.equals(PropertyIds.CONTENT_STREAM_FILE_NAME)) {
                return content.getFileName();
            }

            if (propertyId.equals(PropertyIds.CONTENT_STREAM_LENGTH)) {
                return content.getBigLength();
            }
            if (propertyId.equals(PropertyIds.CONTENT_STREAM_MIME_TYPE)) {
                return content.getMimeType();
            }
        }

        if (folder != null) {
            // not supported: ALLOWED_CHILD_OBJECT_TYPE_IDS
View Full Code Here

        propList.add(getObjectFactory().createPropertyStringData(PropertyIds.NAME, name));
        propList.add(getObjectFactory().createPropertyIdData(PropertyIds.OBJECT_TYPE_ID, getDefaultDocumentType()));

        Properties properties = getObjectFactory().createPropertiesData(propList);

        ContentStream contentStream = createContentStreamData(contentType, content);

        return createDocument(properties, folderId, contentStream, vs, null, null, null);
    }
View Full Code Here

    /**
     * Gets a content stream.
     */
    protected ContentStream getContent(String objectId, String streamId) {
        ContentStream contentStream = getBinding().getObjectService().getContentStream(getTestRepositoryId(), objectId,
                streamId, null, null, null);
        assertNotNull(contentStream);
        assertNotNull(contentStream.getMimeType());
        assertNotNull(contentStream.getStream());

        return contentStream;
    }
View Full Code Here

        return id;
    }

    protected String createDocumentNoCatch(String name, String folderId, String typeId, VersioningState versioningState,
            boolean withContent) {
        ContentStream contentStream = null;
        List<String> policies = null;
        Acl addACEs = null;
        Acl removeACEs = null;
        ExtensionsData extension = null;
View Full Code Here

        BigInteger offset = context.getOffset();
        BigInteger length = context.getLength();

        // execute
        ContentStream content = service.getContentStream(repositoryId, objectId, streamId, offset, length, null);

        if (content == null || content.getStream() == null) {
            throw new CmisRuntimeException("Content stream is null!");
        }

        String contentType = content.getMimeType();
        if (contentType == null) {
            contentType = MEDIATYPE_OCTETSTREAM;
        }

        // set headers
        if (offset == null && length == null) {
            response.setStatus(HttpServletResponse.SC_OK);
        } else {
            response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
        }
        response.setContentType(contentType);

        // send content
        InputStream in = new BufferedInputStream(content.getStream(), BUFFER_SIZE);
        OutputStream out = new BufferedOutputStream(response.getOutputStream());

        byte[] buffer = new byte[BUFFER_SIZE];
        int b;
        while ((b = in.read(buffer)) > -1) {
View Full Code Here

        // version and version series should be checked out now
//        assertTrue(isCheckedOut(docId));
        assertTrue(isCheckedOut(pwcId));

        // Set a new content and modify property
        ContentStream altContent = fCreator.createAlternateContent();
        idHolder = new Holder<String>(pwcId);
        Holder<String> tokenHolder = new Holder<String>(changeToken);
        fObjSvc.setContentStream(fRepositoryId, idHolder, true, tokenHolder, altContent, null);
        fCreator.updateProperty(idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW);

        // Test that a check-in as same user is possible
        String checkinComment = "Checkin without content and properties.";
        fVerSvc.checkIn(fRepositoryId, idHolder, true, null, null, checkinComment, null, null, null, null);
        // Neither the version nor the version series should be checked out any
        // longer:
        assertFalse(isCheckedOut(idHolder.getValue()));
//        assertFalse(isCheckedOut(docId));
        ContentStream retrievedContent = fObjSvc.getContentStream(fRepositoryId, idHolder.getValue(), null, BigInteger
                .valueOf(-1) /* offset */, BigInteger.valueOf(-1) /* length */, null);
        assertTrue(fCreator.verifyContent(fCreator.createAlternateContent(), retrievedContent));
        assertTrue(fCreator.verifyProperty(idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID,
                PROP_VALUE_NEW));

View Full Code Here

        // be version
        // series?
        fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
        String pwcId = idHolder.getValue();

        ContentStream altContent = fCreator.createAlternateContent();
        Properties newProps = fCreator.getUpdatePropertyList(VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW);
        idHolder = new Holder<String>(pwcId);
//        assertTrue(isCheckedOut(docId));
        assertTrue(isCheckedOut(pwcId));

        // Test check-in and pass content and properties
        String checkinComment = "Checkin with content and properties.";
        fVerSvc.checkIn(fRepositoryId, idHolder, true, newProps, altContent, checkinComment, null, null, null, null);
        // Neither the version nor the version series should be checked out any
        // longer:
        assertFalse(isCheckedOut(idHolder.getValue()));
//        assertFalse(isCheckedOut(docId));
        ContentStream retrievedContent = fObjSvc.getContentStream(fRepositoryId, idHolder.getValue(), null, BigInteger
                .valueOf(-1) /* offset */, BigInteger.valueOf(-1) /* length */, null);

        // New content and property should be set
        assertTrue(fCreator.verifyContent(fCreator.createAlternateContent(), retrievedContent));
        assertTrue(fCreator.verifyProperty(idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID,
View Full Code Here

            fail("updateProperty in a document as another user should fail.");
        } catch (Exception e) {
            assertTrue(e instanceof CmisUpdateConflictException);
        }

        ContentStream altContent = fCreator.createAlternateContent();
        Holder<String> pwcHolder = new Holder<String>(pwcId);
        try {
            fObjSvc.setContentStream(fRepositoryId, pwcHolder, true, null, altContent, null);
            fail("setContentStream in a document as another user should fail.");
        } catch (Exception e) {
            assertTrue(e instanceof CmisUpdateConflictException);
        }

        setRuntimeContext(TEST_USER);
        // Test that a check-in as same user is possible
        fVerSvc.checkIn(fRepositoryId, pwcHolder, true, null, null, "testCheckOutAndOtherUser", null, null, null, null);

        // Because nothing was changed we should have a new version with
        // identical content
        ContentStream retrievedContent = fObjSvc.getContentStream(fRepositoryId, pwcHolder.getValue(), null, BigInteger
                .valueOf(-1) /* offset */, BigInteger.valueOf(-1) /* length */, null);
        assertTrue(fCreator.verifyContent(retrievedContent, fCreator.createContent()));
        assertTrue(fCreator.verifyProperty(idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE));
    }
View Full Code Here

        String pwcId = idHolder.getValue();

        // Set a new content and modify property
        Properties props = fObjSvc.getProperties(fRepositoryId, pwcId, "*", null);
        String changeToken = (String) props.getProperties().get(PropertyIds.CHANGE_TOKEN).getFirstValue();
        ContentStream altContent = fCreator.createAlternateContent();
        idHolder = new Holder<String>(pwcId);
        Holder<String> tokenHolder = new Holder<String>(changeToken);
        fObjSvc.setContentStream(fRepositoryId, idHolder, true, tokenHolder, altContent, null);
        fCreator.updateProperty(idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW);

        // cancel checkout
        fVerSvc.cancelCheckOut(fRepositoryId, pwcId, null);
        try {
            // Verify that pwc no longer exists
            fObjSvc.getObject(fRepositoryId, pwcId, "*", false, IncludeRelationships.NONE, null, false, false, null);
            fail("Getting pwc after cancel checkout should fail.");
        } catch (CmisObjectNotFoundException e1) {
        } catch (Exception e2) {
            fail("Expected a CmisObjectNotFoundException after cancel checkin, but got a " + e2.getClass().getName());
        }

        // verify that the old content and properties are still valid
        assertTrue(fCreator.verifyProperty(idOfLastVersion, VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE));
        ContentStream retrievedContent = fObjSvc.getContentStream(fRepositoryId, idOfLastVersion, null, BigInteger
                .valueOf(-1) /* offset */, BigInteger.valueOf(-1) /* length */, null);
        assertTrue(fCreator.verifyContent(retrievedContent, fCreator.createContent()));
    }
View Full Code Here

TOP

Related Classes of org.apache.chemistry.opencmis.commons.data.ContentStream

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.