Search in sources :

Example 1 with JSONParseException

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

use of org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParseException 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)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 TypeDefinition (org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)2 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)2 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)2 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)2 JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)2 JSONParseException (org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParseException)2 JSONParser (org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParser)2