Search in sources :

Example 1 with JSONObject

use of org.apache.chemistry.opencmis.commons.impl.json.JSONObject 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 2 with JSONObject

use of org.apache.chemistry.opencmis.commons.impl.json.JSONObject in project copper-cms by PogeyanOSS.

the class ObjectActor method getProperties.

private JSONObject getProperties(QueryGetRequest t) throws CmisInvalidArgumentException, IllegalArgumentException, CmisRuntimeException {
    String permission = t.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(t.getUserName() + " is not authorized to applyAcl.");
    }
    String objectId = t.getObjectId();
    ReturnVersion returnVersion = t.getEnumParameter(QueryGetRequest.PARAM_RETURN_VERSION, ReturnVersion.class);
    String filter = t.getParameter(QueryGetRequest.PARAM_FILTER);
    boolean succinct = t.getBooleanParameter(QueryGetRequest.PARAM_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = t.getDateTimeFormatParameter();
    LOG.info("getObject->ObjectID{}", objectId);
    if (returnVersion == ReturnVersion.LATEST || returnVersion == ReturnVersion.LASTESTMAJOR) {
        // TODO: implement version
        return null;
    } else {
        ObjectData object = CmisObjectService.Impl.getObject(t.getRepositoryId(), objectId, filter, true, IncludeRelationships.NONE, "cmis:none", false, false, null, t.getUserObject().getUserDN(), t.getBaseTypeId());
        Properties properties = object.getProperties();
        if (properties == null) {
            throw new CmisRuntimeException("Properties are null!");
        }
        JSONObject result = JSONConverter.convert(properties, objectId.toString(), CmisTypeCacheService.get(t.getRepositoryId()), JSONConverter.PropertyMode.CHANGE, succinct, dateTimeFormat);
        return result;
    }
}
Also used : ReturnVersion(org.apache.chemistry.opencmis.commons.impl.ReturnVersion) 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) Properties(org.apache.chemistry.opencmis.commons.data.Properties) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 3 with JSONObject

use of org.apache.chemistry.opencmis.commons.impl.json.JSONObject in project copper-cms by PogeyanOSS.

the class ObjectActor method createFolders.

private JSONObject createFolders(PostRequest request) throws CmisObjectNotFoundException, IllegalArgumentException, CmisInvalidArgumentException, CmisRuntimeException {
    String folderId = request.getObjectId() != null ? request.getObjectId() : null;
    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.");
    }
    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 = CmisObjectService.Impl.createFolder(request.getRepositoryId(), folderId, prop, request.getPolicies(), aclImp, request.getRemoveAcl(), request.getUserObject().getUserDN());
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), newObjectId, request.getUserObject().getUserDN(), BaseTypeId.CMIS_FOLDER);
    if (object == null) {
        throw new CmisRuntimeException("New folder is null!");
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("createFolder complete with id: {}", object.getId());
    }
    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) 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 JSONObject

use of org.apache.chemistry.opencmis.commons.impl.json.JSONObject 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 5 with JSONObject

use of org.apache.chemistry.opencmis.commons.impl.json.JSONObject in project copper-cms by PogeyanOSS.

the class ObjectActor method deleteTree.

private static JSONObject deleteTree(PostRequest request) throws CmisObjectNotFoundException, CmisInvalidArgumentException, CmisNotSupportedException, CmisStorageException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "post")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String objectId = request.getObjectId();
    Boolean allVersions = request.getBooleanParameter(QueryGetRequest.PARAM_ALL_VERSIONS);
    UnfileObject unfileObjects = request.getEnumParameter(QueryGetRequest.PARAM_UNFILE_OBJECTS, UnfileObject.class);
    Boolean continueOnFailure = request.getBooleanParameter(QueryGetRequest.PARAM_CONTINUE_ON_FAILURE);
    FailedToDeleteData ftd = CmisObjectService.Impl.deleteTree(request.getRepositoryId(), objectId, allVersions, unfileObjects, continueOnFailure, request.getUserObject());
    if (ftd != null && CmisPropertyConverter.Impl.isNotEmpty(ftd.getIds())) {
        JSONObject JSONObject = JSONConverter.convert(ftd);
        return JSONObject;
    }
    return null;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) UnfileObject(org.apache.chemistry.opencmis.commons.enums.UnfileObject) FailedToDeleteData(org.apache.chemistry.opencmis.commons.data.FailedToDeleteData)

Aggregations

JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)42 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)36 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)29 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)20 Properties (org.apache.chemistry.opencmis.commons.data.Properties)9 Acl (org.apache.chemistry.opencmis.commons.data.Acl)8 Holder (org.apache.chemistry.opencmis.commons.spi.Holder)8 IUserGroupObject (com.pogeyan.cmis.api.auth.IUserGroupObject)6 BigInteger (java.math.BigInteger)6 Map (java.util.Map)5 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)5 JSONArray (org.apache.chemistry.opencmis.commons.impl.json.JSONArray)5 ObjectList (org.apache.chemistry.opencmis.commons.data.ObjectList)3 TypeDefinition (org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)3 IncludeRelationships (org.apache.chemistry.opencmis.commons.enums.IncludeRelationships)3 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)3 IBaseObject (com.pogeyan.cmis.api.data.IBaseObject)2 IRepository (com.pogeyan.cmis.api.repo.IRepository)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2