Search in sources :

Example 36 with CmisRuntimeException

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

the class RepositoryActor method createType.

private JSONObject createType(PostRequest request) throws IllegalArgumentException, CmisInvalidArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "post")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String typeStr = request.getParameter(QueryGetRequest.CONTROL_TYPE);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    if (typeStr == null) {
        throw new CmisInvalidArgumentException("Type definition missing!");
    }
    // convert type definition
    JSONParser parser = new JSONParser();
    Object typeJson = null;
    try {
        typeJson = parser.parse(typeStr);
    } catch (JSONParseException e) {
        LOG.error("JSON Parser error: {}", ExceptionUtils.getStackTrace(e));
    }
    if (!(typeJson instanceof Map)) {
        throw new CmisInvalidArgumentException("Invalid type definition!");
    }
    @SuppressWarnings("unchecked") TypeDefinition typeIn = JSONConverter.convertTypeDefinition((Map<String, Object>) typeJson);
    TypeDefinition typeOut = CmisTypeServices.Impl.createType(request.getRepositoryId(), typeIn, null, request.getUserName());
    JSONObject jsonType = JSONConverter.convert(typeOut, dateTimeFormat);
    return jsonType;
}
Also used : JSONParseException(org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParseException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) JSONParser(org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParser) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)

Example 37 with CmisRuntimeException

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

the class RepositoryActor method updateType.

private JSONObject updateType(PostRequest request) throws CmisInvalidArgumentException, IllegalArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "post")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String typeStr = request.getParameter(QueryGetRequest.CONTROL_TYPE);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    if (typeStr == null) {
        throw new CmisInvalidArgumentException("Type definition missing!");
    }
    // convert type definition
    JSONParser parser = new JSONParser();
    Object typeJson = null;
    try {
        typeJson = parser.parse(typeStr);
    } catch (JSONParseException e) {
        LOG.error("JSON parse exception: {}", ExceptionUtils.getStackTrace(e));
    }
    if (!(typeJson instanceof Map)) {
        throw new CmisInvalidArgumentException("Invalid type definition!");
    }
    @SuppressWarnings("unchecked") TypeDefinition typeIn = JSONConverter.convertTypeDefinition((Map<String, Object>) typeJson);
    TypeDefinition typeOut = CmisTypeServices.Impl.updateType(request.getRepositoryId(), typeIn, null);
    JSONObject jsonType = JSONConverter.convert(typeOut, dateTimeFormat);
    return jsonType;
}
Also used : JSONParseException(org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParseException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) JSONParser(org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParser) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)

Example 38 with CmisRuntimeException

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

the class VersioningActor method checkIn.

private JSONObject checkIn(PostRequest request) throws CmisObjectNotFoundException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "post")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    // get parameters
    String objectId = request.getObjectId();
    Boolean major = request.getBooleanParameter(QueryGetRequest.PARAM_MAJOR);
    String checkinComment = request.getParameter(QueryGetRequest.PARAM_CHECKIN_COMMENT);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.CONTROL_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    // execute
    Holder<String> objectIdHolder = new Holder<String>(objectId);
    Map<String, List<String>> listProperties = request.getPropertyData();
    Map<String, Object> properties = new HashMap<String, Object>();
    if (listProperties != null) {
        for (Map.Entry<String, List<String>> entry : listProperties.entrySet()) {
            if (entry.getValue() == null || StringUtils.isBlank(entry.getValue().get(0))) {
                continue;
            } else {
                properties.put(entry.getKey(), entry.getValue());
            }
        }
    }
    /*
		 * if (listProperties != null) { properties =
		 * listProperties.entrySet().stream().collect(Collectors.toMap(p ->
		 * p.getKey(), p -> p.getValue() !=
		 * null||!StringUtils.isBlank(p.getValue().get(0)) ? p.getValue().get(0)
		 * :null)); }
		 */
    String versionId = CmisVersioningServices.Impl.checkIn(request.getRepositoryId(), properties, request.getContentStream(), objectIdHolder, major, checkinComment, null, request.getUserName());
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), versionId, request.getUserName(), BaseTypeId.CMIS_DOCUMENT);
    if (object == null) {
        throw new CmisRuntimeException("New document is null!");
    }
    // return object
    JSONObject jsonObject = JSONConverter.convert(object, CmisTypeCacheService.get(request.getRepositoryId()), JSONConverter.PropertyMode.OBJECT, succinct, dateTimeFormat);
    return jsonObject;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) HashMap(java.util.HashMap) Holder(org.apache.chemistry.opencmis.commons.spi.Holder) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) List(java.util.List) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 39 with CmisRuntimeException

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

the class VersioningActor method cancelCheckOut.

private JSONObject cancelCheckOut(PostRequest request) throws CmisUpdateConflictException, CmisUpdateConflictException, 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();
    String docId = CmisVersioningServices.Impl.cancelCheckOut(request.getRepositoryId(), objectId, null, request.getUserName());
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), docId, request.getUserName(), BaseTypeId.CMIS_DOCUMENT);
    if (object == null) {
        throw new CmisRuntimeException("New document is null!");
    }
    // return object
    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)

Example 40 with CmisRuntimeException

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

the class VersioningActor method getAllVersions.

private JSONArray getAllVersions(QueryGetRequest request) throws CmisObjectNotFoundException, CmisUpdateConflictException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    boolean succinct = request.getBooleanParameter(QueryGetRequest.PARAM_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    String objectId = request.getObjectId();
    String filter = request.getParameter(QueryGetRequest.PARAM_FILTER);
    String versionSeriesId = request.getParameter(QueryGetRequest.PARAM_VERSION_SERIES_ID);
    Boolean includeAllowableActions = request.getBooleanParameter(QueryGetRequest.PARAM_ALLOWABLE_ACTIONS);
    String userName = request.getUserName();
    List<ObjectData> versions = CmisVersioningServices.Impl.getAllVersions(request.getRepositoryId(), objectId, versionSeriesId, filter, includeAllowableActions, null, null, userName);
    if (versions == null) {
        throw new CmisRuntimeException("version are null!");
    }
    JSONArray allVersions = new JSONArray();
    for (ObjectData version1 : versions) {
        allVersions.add(JSONConverter.convert(version1, null, JSONConverter.PropertyMode.OBJECT, succinct, dateTimeFormat));
    }
    return allVersions;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) 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