Search in sources :

Example 1 with VersioningState

use of org.apache.chemistry.opencmis.commons.enums.VersioningState in project camel by apache.

the class CMISProducer method storeDocument.

private Document storeDocument(Folder parentFolder, Map<String, Object> cmisProperties, ContentStream contentStream) throws Exception {
    if (!cmisProperties.containsKey(PropertyIds.OBJECT_TYPE_ID)) {
        cmisProperties.put(PropertyIds.OBJECT_TYPE_ID, CamelCMISConstants.CMIS_DOCUMENT);
    }
    VersioningState versioningState = VersioningState.NONE;
    if (getSessionFacade().isObjectTypeVersionable((String) cmisProperties.get(PropertyIds.OBJECT_TYPE_ID))) {
        versioningState = VersioningState.MAJOR;
    }
    LOG.debug("Creating document with properties: {}", cmisProperties);
    return parentFolder.createDocument(cmisProperties, contentStream, versioningState);
}
Also used : VersioningState(org.apache.chemistry.opencmis.commons.enums.VersioningState)

Example 2 with VersioningState

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

the class ObjectActor method createDocument.

private JSONObject createDocument(PostRequest request) throws CmisInvalidArgumentException, CmisConstraintException, IllegalArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    String principalId = request.getUserObject().getUserDN();
    IUserGroupObject[] groupsId = request.getUserObject().getGroups();
    if (!Helpers.getGroupPermission(permission, groupsId)) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String folderId = request.getObjectId() != null ? request.getObjectId() : null;
    VersioningState versioningState = request.getEnumParameter(QueryGetRequest.PARAM_VERSIONIG_STATE, VersioningState.class);
    // String token = request.getParameter(request.PARAM_TOKEN);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.CONTROL_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    Properties prop = CmisPropertyConverter.Impl.createNewProperties(request.getPropertyData(), request.getRepositoryId());
    Acl aclImp = CmisUtils.Object.getAcl(request.getAddAcl(), principalId, permission);
    String newObjectId = null;
    if (request.getContentStream() == null) {
        newObjectId = CmisObjectService.Impl.createDocument(request.getRepositoryId(), prop, folderId, null, versioningState, request.getPolicies(), aclImp, request.getRemoveAcl(), request.getUserObject().getUserDN());
    } else {
        newObjectId = CmisObjectService.Impl.createDocument(request.getRepositoryId(), prop, folderId, request.getContentStream(), versioningState, request.getPolicies(), aclImp, request.getRemoveAcl(), request.getUserObject().getUserDN());
    }
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), newObjectId, request.getUserObject().getUserDN(), BaseTypeId.CMIS_DOCUMENT);
    if (object == null) {
        MetricsInputs.markUploadErrorMeter();
        throw new CmisRuntimeException("New document is null!");
    }
    // return object
    JSONObject jsonObject = JSONConverter.convert(object, CmisTypeCacheService.get(request.getRepositoryId()), JSONConverter.PropertyMode.CHANGE, succinct, dateTimeFormat);
    return jsonObject;
}
Also used : IUserGroupObject(com.pogeyan.cmis.api.auth.IUserGroupObject) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) VersioningState(org.apache.chemistry.opencmis.commons.enums.VersioningState) Acl(org.apache.chemistry.opencmis.commons.data.Acl) Properties(org.apache.chemistry.opencmis.commons.data.Properties) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 3 with VersioningState

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

the class ObjectActor method createDocumentFromSource.

private JSONObject createDocumentFromSource(PostRequest request) throws CmisInvalidArgumentException, CmisConstraintException, CmisObjectNotFoundException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    String principalId = request.getUserObject().getUserDN();
    IUserGroupObject[] groups = request.getUserObject().getGroups();
    if (!Helpers.getGroupPermission(permission, groups)) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String folderId = request.getObjectId() != null ? request.getObjectId() : null;
    VersioningState versioningState = request.getEnumParameter(QueryGetRequest.PARAM_VERSIONIG_STATE, VersioningState.class);
    // String token = request.getParameter(request.PARAM_TOKEN);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.CONTROL_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    String sourceId = request.getParameter(QueryGetRequest.PARAM_SOURCE_ID);
    Acl aclImp = CmisUtils.Object.getAcl(request.getAddAcl(), principalId, permission);
    ObjectData sourceDoc = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), sourceId, request.getUserName(), BaseTypeId.CMIS_DOCUMENT);
    PropertyData<?> sourceTypeId = sourceDoc.getProperties().getProperties().get(PropertyIds.OBJECT_TYPE_ID);
    if (sourceTypeId == null || sourceTypeId.getFirstValue() == null) {
        throw new CmisRuntimeException("Source object has no type!?!");
    }
    Properties prop = CmisPropertyConverter.Impl.createNewProperties(request.getPropertyData(), request.getRepositoryId());
    String newObjectId = CmisObjectService.Impl.createDocumentFromSource(request.getRepositoryId(), sourceId, prop, folderId, versioningState, request.getPolicies(), aclImp, request.getRemoveAcl(), request.getUserObject().getUserDN());
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), newObjectId, request.getUserObject().getUserDN(), BaseTypeId.CMIS_DOCUMENT);
    if (object == null) {
        throw new CmisRuntimeException("New document is null!");
    }
    // return object
    JSONObject jsonObject = JSONConverter.convert(object, null, JSONConverter.PropertyMode.CHANGE, succinct, dateTimeFormat);
    return jsonObject;
}
Also used : IUserGroupObject(com.pogeyan.cmis.api.auth.IUserGroupObject) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) VersioningState(org.apache.chemistry.opencmis.commons.enums.VersioningState) Acl(org.apache.chemistry.opencmis.commons.data.Acl) Properties(org.apache.chemistry.opencmis.commons.data.Properties) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 4 with VersioningState

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

the class AbstractSessionTest method createDocument.

/**
 * Creates a document.
 */
protected Document createDocument(Session session, Folder parent, String name, String objectTypeId, String[] secondaryTypeIds, String content) {
    if (parent == null) {
        throw new IllegalArgumentException("Parent is not set!");
    }
    if (name == null) {
        throw new IllegalArgumentException("Name is not set!");
    }
    if (objectTypeId == null) {
        throw new IllegalArgumentException("Object Type ID is not set!");
    }
    if (content == null) {
        content = "";
    }
    // check type
    ObjectType type;
    try {
        type = session.getTypeDefinition(objectTypeId);
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Document type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
        return null;
    }
    if (Boolean.FALSE.equals(type.isCreatable())) {
        addResult(createResult(SKIPPED, "Document type '" + objectTypeId + "' is not creatable!", true));
        return null;
    }
    // create
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.NAME, name);
    properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
    if (secondaryTypeIds != null) {
        properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, Arrays.asList(secondaryTypeIds));
    }
    type = session.getTypeDefinition(objectTypeId);
    if (!(type instanceof DocumentTypeDefinition)) {
        addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
        return null;
    }
    DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
    VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
    byte[] contentBytes = null;
    Document result = null;
    try {
        contentBytes = IOUtils.toUTF8Bytes(content);
        ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes));
        // create the document
        result = parent.createDocument(properties, contentStream, versioningState, null, null, null, SELECT_ALL_NO_CACHE_OC);
        contentStream.getStream().close();
    } catch (Exception e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Document could not be created! Exception: " + e.getMessage(), e, true));
        return null;
    }
    try {
        CmisTestResult f;
        // check document name
        f = createResult(FAILURE, "Document name does not match!", false);
        addResult(assertEquals(name, result.getName(), null, f));
        // check content length
        f = createResult(WARNING, "Content length does not match!", false);
        addResult(assertEquals((long) contentBytes.length, result.getContentStreamLength(), null, f));
        // check the new document
        addResult(checkObject(session, result, getAllProperties(result), "New document object spec compliance"));
        // check content
        try {
            ContentStream contentStream = result.getContentStream();
            f = createResult(WARNING, "Document filename and the filename of the content stream do not match!", false);
            addResult(assertEquals(name, contentStream.getFileName(), null, f));
            f = createResult(WARNING, "cmis:contentStreamFileName and the filename of the content stream do not match!", false);
            addResult(assertEquals(result.getContentStreamFileName(), contentStream.getFileName(), null, f));
            String fetchedContent = getStringFromContentStream(result.getContentStream());
            if (!content.equals(fetchedContent)) {
                addResult(createResult(FAILURE, "Content of newly created document doesn't match the orign content!"));
            }
        } catch (IOException e) {
            addResult(createResult(UNEXPECTED_EXCEPTION, "Content of newly created document couldn't be read! Exception: " + e.getMessage(), e, true));
        }
    } catch (CmisBaseException e) {
        addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created document is invalid! Exception: " + e.getMessage(), e, true));
    }
    // check parents
    List<Folder> parents = result.getParents(SELECT_ALL_NO_CACHE_OC);
    boolean found = false;
    for (Folder folder : parents) {
        if (parent.getId().equals(folder.getId())) {
            found = true;
            break;
        }
    }
    if (!found) {
        addResult(createResult(FAILURE, "The folder the document has been created in is not in the list of the document parents!"));
    }
    return result;
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) HashMap(java.util.HashMap) IOException(java.io.IOException) Document(org.apache.chemistry.opencmis.client.api.Document) Folder(org.apache.chemistry.opencmis.client.api.Folder) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) IOException(java.io.IOException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) ByteArrayInputStream(java.io.ByteArrayInputStream) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) VersioningState(org.apache.chemistry.opencmis.commons.enums.VersioningState)

Example 5 with VersioningState

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

the class CopyTest method run.

@Override
public void run(Session session) {
    // if (getBinding() == BindingType.ATOMPUB) {
    // addResult(createResult(SKIPPED,
    // "AtomPub binding does not support createDocumentFromSource(). Test Skipped!"));
    // return;
    // }
    CmisTestResult f;
    try {
        // create folders
        Folder testFolder = createTestFolder(session);
        Folder folder1 = createFolder(session, testFolder, "copyfolder1");
        Folder folder2 = createFolder(session, testFolder, "copyfolder2");
        // create document
        Document doc1 = createDocument(session, folder1, "copytestdoc.txt", "copy test");
        VersioningState versioningState = VersioningState.MAJOR;
        if (!((DocumentTypeDefinition) doc1.getType()).isVersionable()) {
            versioningState = VersioningState.NONE;
        }
        // copy
        Document doc2 = doc1.copy(folder2, null, versioningState, null, null, null, SELECT_ALL_NO_CACHE_OC);
        if (doc2 == null) {
            addResult(createResult(FAILURE, "Copied document is null!"));
        } else {
            addResult(checkObject(session, doc2, getAllProperties(doc2), "Copied document check. Id: + " + doc2.getName()));
            f = createResult(FAILURE, "Content streams don't match!");
            addResult(assertEquals(doc1.getContentStream(), doc2.getContentStream(), null, f));
        }
        int count1 = countFolderChildren(folder1);
        f = createResult(FAILURE, "Source folder should have exactly one child but has " + count1 + " children!");
        addResult(assertEquals(1, count1, null, f));
        int count2 = countFolderChildren(folder2);
        f = createResult(FAILURE, "Target folder should have exactly one child but has " + count2 + " children!");
        addResult(assertEquals(1, count2, null, f));
        deleteObject(doc2);
        deleteObject(doc1);
    } finally {
    // clean up
    // deleteTestFolder();
    }
}
Also used : 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)

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