Search in sources :

Example 21 with CmisRuntimeException

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

the class ContentRangeInputStream method skipBytes.

private void skipBytes() {
    long remainingSkipBytes = offset;
    try {
        while (remainingSkipBytes > 0) {
            long skipped = super.skip(remainingSkipBytes);
            remainingSkipBytes -= skipped;
            if (skipped == 0) {
                // stream might not support skipping
                skipBytesByReading(remainingSkipBytes);
                break;
            }
        }
    } catch (IOException e) {
        LOG.error("skipBytes exception: {}, {}", e.getMessage(), ExceptionUtils.getStackTrace(e));
        throw new CmisRuntimeException("Skipping the stream failed!", e);
    }
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) IOException(java.io.IOException)

Example 22 with CmisRuntimeException

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

the class ContentRangeInputStream method skipBytesByReading.

private void skipBytesByReading(long remainingSkipBytes) {
    try {
        final byte[] buffer = new byte[BUFFER_SIZE];
        while (remainingSkipBytes > 0) {
            long skipped = super.read(buffer, 0, (int) Math.min(buffer.length, remainingSkipBytes));
            if (skipped == -1) {
                break;
            }
            remainingSkipBytes -= skipped;
        }
    } catch (IOException e) {
        LOG.error("skipBytesByReading exception: {}, {}", e.getMessage(), ExceptionUtils.getStackTrace(e));
        throw new CmisRuntimeException("Reading the stream failed!", e);
    }
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) IOException(java.io.IOException)

Example 23 with CmisRuntimeException

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

the class ObjectActor method appendContent.

private JSONObject appendContent(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 isLastChunk = request.getBooleanParameter(QueryGetRequest.CONTROL_IS_LAST_CHUNK, false);
    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.appendContentStream(request.getRepositoryId(), objectIdHolder, changeTokenHolder, null, isLastChunk);
    } else {
        CmisObjectService.Impl.appendContentStream(request.getRepositoryId(), objectIdHolder, changeTokenHolder, request.getContentStream(), isLastChunk);
    }
    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) {
        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 24 with CmisRuntimeException

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

the class ObjectActor method update.

@SuppressWarnings("unused")
private JSONObject update(PostRequest request) throws CmisRuntimeException, CmisObjectNotFoundException, CmisRuntimeException, CmisUpdateConflictException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "post")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String objectId = request.getObjectId();
    IBaseObject data = DBUtils.BaseDAO.getByObjectId(request.getRepositoryId(), objectId, null);
    String typeId = CmisPropertyConverter.Impl.getTypeIdForObject(request.getRepositoryId(), objectId);
    String changeToken = request.getParameter(QueryGetRequest.CONTROL_CHANGE_TOKEN);
    String token = request.getParameter(QueryGetRequest.PARAM_TOKEN);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.CONTROL_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    Holder<String> objectIdHolder = new Holder<String>(objectId.toString());
    Holder<String> changeTokenHolder = (changeToken == null ? null : new Holder<String>(changeToken));
    Properties properties = CmisPropertyConverter.Impl.createUpdateProperties(request.getPropertyData(), typeId, null, Collections.singletonList(objectId.toString()), request.getRepositoryId(), data);
    CmisObjectService.Impl.updateProperties(request.getRepositoryId(), objectIdHolder, changeTokenHolder, properties, null, null, request.getUserObject());
    String newObjectId = (objectIdHolder.getValue() == null ? objectId : objectIdHolder.getValue());
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), newObjectId, request.getUserObject().getUserDN(), request.getBaseTypeId());
    if (object == null) {
        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) Properties(org.apache.chemistry.opencmis.commons.data.Properties) IBaseObject(com.pogeyan.cmis.api.data.IBaseObject) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 25 with CmisRuntimeException

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

the class ObjectActor method createItem.

private JSONObject createItem(PostRequest request) throws CmisInvalidArgumentException, CmisObjectNotFoundException, IllegalArgumentException, 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;
    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.createItem(request.getRepositoryId(), prop, folderId, request.getPolicies(), aclImp, request.getRemoveAcl(), request.getUserObject().getUserDN());
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), newObjectId, request.getUserObject().getUserDN(), BaseTypeId.CMIS_ITEM);
    if (object == null) {
        throw new CmisRuntimeException("New folder 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) Acl(org.apache.chemistry.opencmis.commons.data.Acl) Properties(org.apache.chemistry.opencmis.commons.data.Properties) 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