Search in sources :

Example 31 with JSONObject

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

the class RepositoryActor method getTypeChildren.

private JSONObject getTypeChildren(QueryGetRequest request) throws IllegalArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String typeId = request.getParameter(QueryGetRequest.PARAM_TYPE_ID);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    boolean includePropertyDefinitions = request.getBooleanParameter(QueryGetRequest.PARAM_PROPERTY_DEFINITIONS, false);
    BigInteger maxItems = request.getBigIntegerParameter(QueryGetRequest.PARAM_MAX_ITEMS);
    BigInteger skipCount = request.getBigIntegerParameter(QueryGetRequest.PARAM_SKIP_COUNT);
    TypeDefinitionList typeList = CmisTypeServices.Impl.getTypeChildren(request.getRepositoryId(), typeId, includePropertyDefinitions, maxItems, skipCount, null);
    JSONObject jsonTypeList = JSONConverter.convert(typeList, dateTimeFormat);
    return jsonTypeList;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) TypeDefinitionList(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList) BigInteger(java.math.BigInteger) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 32 with JSONObject

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

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

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

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

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