Search in sources :

Example 11 with JSONObject

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

the class VersioningActor method getObjectOfLatestVersion.

private JSONObject getObjectOfLatestVersion(QueryGetRequest request) throws CmisObjectNotFoundException, 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);
    boolean majorVersion = request.getBooleanParameter(QueryGetRequest.PARAM_MAJOR, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    String objectId = request.getObjectId();
    String versionSeriesId = request.getParameter(QueryGetRequest.PARAM_VERSION_SERIES_ID);
    String filter = request.getParameter(QueryGetRequest.PARAM_FILTER);
    Boolean includeAllowableActions = request.getBooleanParameter(QueryGetRequest.PARAM_ALLOWABLE_ACTIONS);
    String renditionFilter = request.getParameter(QueryGetRequest.PARAM_RENDITION_FILTER);
    Boolean includePolicyIds = request.getBooleanParameter(QueryGetRequest.PARAM_POLICY_IDS);
    Boolean includeAcl = request.getBooleanParameter(QueryGetRequest.PARAM_ACL);
    String userName = request.getUserName();
    ObjectData object = CmisVersioningServices.Impl.getObjectOfLatestVersion(request.getRepositoryId(), objectId, versionSeriesId, majorVersion, filter, includeAllowableActions, renditionFilter, includePolicyIds, includeAcl, null, null, userName);
    if (object == null) {
        throw new CmisRuntimeException("object is not present!");
    }
    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 12 with JSONObject

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

the class ServletHelpers method printError.

static void printError(Exception ex, HttpServletRequest request, HttpServletResponse response) {
    int statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    String exceptionName = CmisRuntimeException.EXCEPTION_NAME;
    if (ex instanceof CmisRuntimeException) {
        AkkaCmisBrowserBindingServlet.LOG.error(createLogMessage(ex, request), ex);
        statusCode = getErrorCode((CmisRuntimeException) ex);
    } else if (ex instanceof CmisStorageException) {
        AkkaCmisBrowserBindingServlet.LOG.error(createLogMessage(ex, request), ex);
        statusCode = getErrorCode((CmisStorageException) ex);
        exceptionName = ((CmisStorageException) ex).getExceptionName();
    } else if (ex instanceof CmisBaseException) {
        statusCode = getErrorCode((CmisBaseException) ex);
        exceptionName = ((CmisBaseException) ex).getExceptionName();
        if (statusCode == HttpServletResponse.SC_INTERNAL_SERVER_ERROR) {
            AkkaCmisBrowserBindingServlet.LOG.error(createLogMessage(ex, request), ex);
        }
    } else if (ex instanceof IOException) {
        AkkaCmisBrowserBindingServlet.LOG.warn(createLogMessage(ex, request), ex);
    } else {
        AkkaCmisBrowserBindingServlet.LOG.error(createLogMessage(ex, request), ex);
    }
    if (response.isCommitted()) {
        AkkaCmisBrowserBindingServlet.LOG.warn("Failed to send error message to client. Response is already committed.", ex);
        return;
    }
    String message = ex.getMessage();
    /*
		 * if (!(ex instanceof CmisBaseException)) { message =
		 * "An error occurred!"; }
		 */
    response.resetBuffer();
    response.setStatus(statusCode);
    JSONObject jsonResponse = new JSONObject();
    jsonResponse.put(BrowserConstants.ERROR_EXCEPTION, exceptionName);
    jsonResponse.put(BrowserConstants.MESSAGE, message);
    String st = ExceptionHelper.getStacktraceAsString(ex);
    if (st != null) {
        jsonResponse.put(BrowserConstants.ERROR_STACKTRACE, st);
    }
    if (ex instanceof CmisBaseException) {
        Map<String, String> additionalData = ((CmisBaseException) ex).getAdditionalData();
        if (additionalData != null && !additionalData.isEmpty()) {
            for (Map.Entry<String, String> e : additionalData.entrySet()) {
                if (BrowserConstants.ERROR_EXCEPTION.equalsIgnoreCase(e.getKey()) || BrowserConstants.MESSAGE.equalsIgnoreCase(e.getKey())) {
                    continue;
                }
                jsonResponse.put(e.getKey(), e.getValue());
            }
        }
    }
    try {
        ServletHelpers.writeJSON(jsonResponse, request, response);
    } catch (Exception e) {
        AkkaCmisBrowserBindingServlet.LOG.error(createLogMessage(ex, request), e);
        try {
            response.sendError(statusCode, message);
        } catch (Exception en) {
        // there is nothing else we can do
        }
    }
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) IOException(java.io.IOException) CmisStorageException(org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException) HashMap(java.util.HashMap) Map(java.util.Map) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisServiceUnavailableException(org.apache.chemistry.opencmis.commons.exceptions.CmisServiceUnavailableException) CmisNameConstraintViolationException(org.apache.chemistry.opencmis.commons.exceptions.CmisNameConstraintViolationException) CmisFilterNotValidException(org.apache.chemistry.opencmis.commons.exceptions.CmisFilterNotValidException) CmisTooManyRequestsException(org.apache.chemistry.opencmis.commons.exceptions.CmisTooManyRequestsException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisStorageException(org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException) CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) IOException(java.io.IOException) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisVersioningException(org.apache.chemistry.opencmis.commons.exceptions.CmisVersioningException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)

Example 13 with JSONObject

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

the class AclActor method getAcl.

private JSONObject getAcl(QueryGetRequest t) throws CmisObjectNotFoundException, CmisRuntimeException {
    String permission = t.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(t.getUserName() + " is not authorized to applyAcl.");
    }
    String objectId = t.getObjectId();
    Boolean onlyBasicPermissions = t.getBooleanParameter(QueryGetRequest.PARAM_ONLY_BASIC_PERMISSIONS);
    Acl objectAcl = CmisAclServices.Impl.getAcl(t.getRepositoryId(), objectId, onlyBasicPermissions, null, null, t.getUserObject().getUserDN());
    if (objectAcl == null) {
        throw new CmisRuntimeException("object acl is null!");
    }
    JSONObject jsonObject = JSONConverter.convert(objectAcl);
    return jsonObject;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) Acl(org.apache.chemistry.opencmis.commons.data.Acl) CapabilityAcl(org.apache.chemistry.opencmis.commons.enums.CapabilityAcl)

Example 14 with JSONObject

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

the class DiscoveryActor method getContentChanges.

private JSONObject getContentChanges(QueryGetRequest request) throws CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String changeLogToken = request.getParameter(QueryGetRequest.PARAM_CHANGE_LOG_TOKEN);
    Boolean includeProperties = request.getBooleanParameter(QueryGetRequest.PARAM_PROPERTIES);
    String filter = request.getParameter(QueryGetRequest.PARAM_FILTER);
    Boolean includePolicyIds = request.getBooleanParameter(QueryGetRequest.PARAM_POLICY_IDS);
    Boolean includeAcl = request.getBooleanParameter(QueryGetRequest.PARAM_ACL);
    BigInteger maxItems = request.getBigIntegerParameter(QueryGetRequest.PARAM_MAX_ITEMS);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.PARAM_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    Holder<String> changeLogTokenHolder = new Holder<String>(changeLogToken);
    ObjectList changes = CmisDiscoveryService.Impl.getContentChanges(request.getRepositoryId(), changeLogTokenHolder, includeProperties, filter, includePolicyIds, includeAcl, maxItems, null, request.getUserObject());
    JSONObject jsonChanges = JSONConverter.convert(changes, CmisTypeCacheService.get(request.getRepositoryId()), JSONConverter.PropertyMode.CHANGE, succinct, dateTimeFormat);
    jsonChanges.put(JSONConstants.JSON_OBJECTLIST_CHANGE_LOG_TOKEN, changeLogTokenHolder.getValue());
    return jsonChanges;
}
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) BigInteger(java.math.BigInteger) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 15 with JSONObject

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

the class JsonReport method printGroupResults.

private void printGroupResults(CmisTestGroup group, JSONArray jsonGroups) throws IOException {
    if (!group.isEnabled()) {
        return;
    }
    JSONObject jsonGroup = new JSONObject();
    jsonGroups.add(jsonGroup);
    jsonGroup.put("name", group.getName());
    if (group.getTests() != null && !group.getTests().isEmpty()) {
        JSONArray jsonTests = new JSONArray();
        jsonGroup.put("tests", jsonTests);
        for (CmisTest test : group.getTests()) {
            printTestResults(test, jsonTests);
        }
    }
}
Also used : JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) CmisTest(org.apache.chemistry.opencmis.tck.CmisTest)

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