Search in sources :

Example 6 with CmisRuntimeException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException in project copper-cms by PogeyanOSS.

the class ObjectActor method getContent.

private PostFileResponse getContent(QueryGetRequest request) throws CmisObjectNotFoundException, CmisInvalidArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String objectId = request.getObjectId();
    String streamId = request.getParameter(QueryGetRequest.PARAM_STREAM_ID);
    boolean download = false;
    String downloadParam = request.getParameter(QueryGetRequest.PARAM_DOWNLOAD);
    if (downloadParam != null && downloadParam.length() > 0) {
        String downloadParamLower = downloadParam.trim().toLowerCase(Locale.ENGLISH);
        if ("attachment".equals(downloadParamLower)) {
            download = true;
        } else if ("inline".equals(downloadParamLower)) {
            download = false;
        } else {
            throw new CmisInvalidArgumentException("Invalid download parameter value!");
        }
    }
    BigInteger offset = request.getOffset();
    BigInteger length = request.getLength();
    ContentStream content = CmisObjectService.Impl.getContentStream(request.getRepositoryId(), objectId, streamId, offset, length);
    PostFileResponse fileResponse = new PostFileResponse();
    fileResponse.setDownload(download);
    fileResponse.setOffset(offset);
    fileResponse.setContent(content);
    if (Helpers.isPerfMode()) {
        MetricsInputs.get().getCounter("Count_Downloads_" + request.getObjectId()).inc();
    }
    return fileResponse;
/*
		 * if (content == null || content.getStream() == null) { throw new
		 * CmisRuntimeException("Content stream is null!"); }
		 * 
		 * String contentType = content.getMimeType(); if (contentType == null) {
		 * contentType = QueryGetRequest.MEDIATYPE_OCTETSTREAM; }
		 * 
		 * String contentFilename = content.getFileName(); if (contentFilename == null)
		 * { contentFilename = "content"; }
		 * 
		 * // send content InputStream in = content.getStream(); OutputStream out =
		 * null; try { out = new FileOutputStream(content.getFileName());
		 * IOUtils.copy(in, out, QueryGetRequest.BUFFER_SIZE); out.flush(); } catch
		 * (Exception e) { LOG.error("writeContent exception: {}, {}", e.getMessage(),
		 * ExceptionUtils.getStackTrace(e)); throw new
		 * IllegalArgumentException("Could not write content: " + e.getMessage(), e); }
		 * finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(in); } return null;
		 */
}
Also used : ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) BigInteger(java.math.BigInteger) PostFileResponse(com.pogeyan.cmis.api.messages.PostFileResponse)

Example 7 with CmisRuntimeException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException 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 8 with CmisRuntimeException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException 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)

Example 9 with CmisRuntimeException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException in project copper-cms by PogeyanOSS.

the class ObjectActor method setContent.

private JSONObject setContent(PostRequest request) throws 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();
    String changeToken = request.getParameter(QueryGetRequest.PARAM_CHANGE_TOKEN);
    Boolean overwriteFlag = request.getBooleanParameter(QueryGetRequest.PARAM_OVERWRITE_FLAG);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.CONTROL_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    Holder<String> objectIdHolder = new Holder<String>(objectId);
    Holder<String> changeTokenHolder = (changeToken == null ? null : new Holder<String>(changeToken));
    if (request.getContentStream() == null) {
        CmisObjectService.Impl.setContentStream(request.getRepositoryId(), objectIdHolder, overwriteFlag, changeTokenHolder, null);
    } else {
        CmisObjectService.Impl.setContentStream(request.getRepositoryId(), objectIdHolder, overwriteFlag, changeTokenHolder, request.getContentStream());
    }
    String newObjectId = (objectIdHolder.getValue() == null ? objectId : objectIdHolder.getValue());
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), newObjectId, request.getUserObject().getUserDN(), BaseTypeId.CMIS_DOCUMENT);
    if (object == null) {
        MetricsInputs.markUploadErrorMeter();
        throw new CmisRuntimeException("Object is null!");
    }
    // return object
    JSONObject jsonObject = JSONConverter.convert(object, null, JSONConverter.PropertyMode.CHANGE, succinct, dateTimeFormat);
    return jsonObject;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) Holder(org.apache.chemistry.opencmis.commons.spi.Holder) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 10 with CmisRuntimeException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException in project copper-cms by PogeyanOSS.

the class PolicyActor method removePolicy.

private JSONObject removePolicy(PostRequest request) throws CmisInvalidArgumentException, CmisObjectNotFoundException, 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 succinct = request.getBooleanParameter(QueryGetRequest.CONTROL_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    CmisPolicyService.Impl.removePolicy(request.getRepositoryId(), request.getPolicyId(), objectId, request.getUserObject().getUserDN());
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), objectId, request.getUserObject().getUserDN(), BaseTypeId.CMIS_POLICY);
    if (object == null) {
        throw new CmisRuntimeException("Object is null!");
    }
    JSONObject jsonObject = JSONConverter.convert(object, null, JSONConverter.PropertyMode.OBJECT, succinct, dateTimeFormat);
    return jsonObject;
}
Also used : 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) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Aggregations

CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)49 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)35 JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)35 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)22 BigInteger (java.math.BigInteger)10 Properties (org.apache.chemistry.opencmis.commons.data.Properties)10 Acl (org.apache.chemistry.opencmis.commons.data.Acl)8 JSONArray (org.apache.chemistry.opencmis.commons.impl.json.JSONArray)8 Holder (org.apache.chemistry.opencmis.commons.spi.Holder)8 IUserGroupObject (com.pogeyan.cmis.api.auth.IUserGroupObject)6 IncludeRelationships (org.apache.chemistry.opencmis.commons.enums.IncludeRelationships)6 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)6 Map (java.util.Map)4 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)4 IOException (java.io.IOException)3 ObjectList (org.apache.chemistry.opencmis.commons.data.ObjectList)3 TypeDefinition (org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)3 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)3 IBaseObject (com.pogeyan.cmis.api.data.IBaseObject)2 InputStream (java.io.InputStream)2