Search in sources :

Example 6 with VersioningState

use of org.apache.chemistry.opencmis.commons.enums.VersioningState in project copper-cms by PogeyanOSS.

the class CreateDocumentWithoutContent method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    String objectTypeId = getDocumentTestTypeId();
    TypeDefinition type = session.getTypeDefinition(objectTypeId);
    if (!(type instanceof DocumentTypeDefinition)) {
        addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
        return;
    }
    DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
    if (docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
        addResult(createResult(SKIPPED, "The test document type does not support documents without content. Test skipped!"));
        return;
    }
    // create a test folder
    Folder testFolder = createTestFolder(session);
    try {
        String name = "nocontent";
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.NAME, name);
        properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
        VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
        // create and fetch the document
        ObjectId id = session.createDocument(properties, testFolder, null, versioningState);
        Document doc = (Document) session.getObject(id, SELECT_ALL_NO_CACHE_OC);
        // check the new document
        addResult(checkObject(session, doc, getAllProperties(doc), "New document object spec compliance"));
        // check the MIME type
        f = createResult(FAILURE, "The document has no content but a MIME type!", true);
        assertNull(doc.getContentStreamMimeType(), null, f);
        // check the content size
        if (doc.getContentStreamLength() == 0) {
            addResult(createResult(WARNING, "The document has no content but the content length is set to 0! " + "The content length shouldn't be set."));
        } else if (doc.getContentStreamLength() > 0) {
            addResult(createResult(FAILURE, "The document has no content but the content length is set and >0! " + "(content length: " + doc.getContentStreamLength() + ")"));
        }
        // delete it
        doc.delete(true);
    } finally {
        // delete the test folder
        deleteTestFolder();
    }
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) VersioningState(org.apache.chemistry.opencmis.commons.enums.VersioningState) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition) DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)

Example 7 with VersioningState

use of org.apache.chemistry.opencmis.commons.enums.VersioningState in project copper-cms by PogeyanOSS.

the class CreateBigDocument method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    // create a test folder
    Folder testFolder = createTestFolder(session);
    try {
        String name = "bigdoc";
        String objectTypeId = getDocumentTestTypeId();
        String mimetype = "application/octet-stream";
        // 10 MiB
        final long size = 10 * 1024 * 1024;
        InputStream in = new InputStream() {

            private int counter = -1;

            @Override
            public int read() throws IOException {
                counter++;
                if (counter >= size) {
                    return -1;
                }
                return '0' + (counter / 10);
            }
        };
        // create stream and properties
        ContentStream contentStream = session.getObjectFactory().createContentStream(name, size, mimetype, in);
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.NAME, name);
        properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
        // check type
        TypeDefinition type = session.getTypeDefinition(objectTypeId);
        if (!(type instanceof DocumentTypeDefinition)) {
            addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
            return;
        }
        DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
        VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
        // create and fetch the document
        ObjectId id = session.createDocument(properties, testFolder, contentStream, versioningState);
        Document doc = (Document) session.getObject(id, SELECT_ALL_NO_CACHE_OC);
        // check the new document
        addResult(checkObject(session, doc, getAllProperties(doc), "New document object spec compliance"));
        // check the size
        f = createResult(FAILURE, "Content stream length doesn't match the uploaded content!", true);
        assertEquals(size, doc.getContentStreamLength(), null, f);
    // delete it
    // doc.delete(true);
    } finally {
    // delete the test folder
    // deleteTestFolder();
    }
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) InputStream(java.io.InputStream) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition) DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) VersioningState(org.apache.chemistry.opencmis.commons.enums.VersioningState)

Aggregations

VersioningState (org.apache.chemistry.opencmis.commons.enums.VersioningState)7 Document (org.apache.chemistry.opencmis.client.api.Document)4 Folder (org.apache.chemistry.opencmis.client.api.Folder)4 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)4 HashMap (java.util.HashMap)3 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)3 IUserGroupObject (com.pogeyan.cmis.api.auth.IUserGroupObject)2 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)2 Acl (org.apache.chemistry.opencmis.commons.data.Acl)2 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)2 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)2 Properties (org.apache.chemistry.opencmis.commons.data.Properties)2 TypeDefinition (org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)2 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)2 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)2 JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)1