Search in sources :

Example 6 with JSONArray

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

the class NavigationActor method getDescendants.

private JSONArray getDescendants(QueryGetRequest request) throws CmisInvalidArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String folderId = request.getObjectId();
    String filter = request.getParameter(QueryGetRequest.PARAM_FILTER);
    BigInteger depth = request.getBigIntegerParameter(QueryGetRequest.PARAM_DEPTH);
    Boolean includeAllowableActions = request.getBooleanParameter(QueryGetRequest.PARAM_ALLOWABLE_ACTIONS);
    includeAllowableActions = includeAllowableActions == null ? false : includeAllowableActions;
    IncludeRelationships includeRelationships = request.getEnumParameter(QueryGetRequest.PARAM_RELATIONSHIPS, IncludeRelationships.class);
    String renditionFilter = request.getParameter(QueryGetRequest.PARAM_RENDITION_FILTER);
    Boolean includePathSegment = request.getBooleanParameter(QueryGetRequest.PARAM_PATH_SEGMENT);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.PARAM_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    List<ObjectInFolderContainer> descendants = CmisNavigationService.Impl.getDescendants(request.getRepositoryId(), folderId, depth, filter, includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, null, request.getUserObject());
    if (descendants == null) {
        throw new CmisRuntimeException("Descendants are null!");
    }
    JSONArray jsonDescendants = new JSONArray();
    for (ObjectInFolderContainer descendant : descendants) {
        jsonDescendants.add(JSONConverter.convert(descendant, CmisTypeCacheService.get(request.getRepositoryId()), succinct, dateTimeFormat));
    }
    return jsonDescendants;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) BigInteger(java.math.BigInteger) IncludeRelationships(org.apache.chemistry.opencmis.commons.enums.IncludeRelationships) ObjectInFolderContainer(org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 7 with JSONArray

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

Example 8 with JSONArray

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

the class JsonReport method printTestResults.

private void printTestResults(CmisTest test, JSONArray jsonTests) throws IOException {
    if (!test.isEnabled()) {
        return;
    }
    JSONObject jsonTest = new JSONObject();
    jsonTests.add(jsonTest);
    jsonTest.put("name", test.getName());
    jsonTest.put("time", test.getTime());
    if (test.getResults() != null && !test.getResults().isEmpty()) {
        JSONArray jsonResults = new JSONArray();
        jsonTest.put("results", jsonResults);
        for (CmisTestResult result : test.getResults()) {
            printResult(result, jsonResults);
        }
    }
}
Also used : JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray)

Example 9 with JSONArray

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

the class JsonReport method printResult.

private void printResult(CmisTestResult result, JSONArray results) throws IOException {
    JSONObject jsonResult = new JSONObject();
    results.add(jsonResult);
    jsonResult.put("status", result.getStatus().toString());
    jsonResult.put("message", result.getMessage());
    if (result.getStackTrace() != null && result.getStackTrace().length > 0) {
        jsonResult.put("file", result.getStackTrace()[0].getFileName() + ":" + result.getStackTrace()[0].getLineNumber());
    }
    if (result.getStatus() == CmisTestResultStatus.UNEXPECTED_EXCEPTION && result.getException() != null) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        result.getException().printStackTrace(pw);
        jsonResult.put("stacktrace", sw.toString());
        if (result.getException() instanceof CmisBaseException) {
            CmisBaseException cbe = (CmisBaseException) result.getException();
            if (cbe.getErrorContent() != null) {
                jsonResult.put("errorcontent", cbe.getErrorContent());
            }
        }
    }
    if (result.getException() != null) {
        jsonResult.put("exception", result.getException().getMessage());
    }
    if (result.getRequest() != null) {
        jsonResult.put("request", result.getRequest());
    }
    if (result.getRequest() != null) {
        jsonResult.put("response", result.getResponse());
    }
    if (!result.getChildren().isEmpty()) {
        JSONArray nextLevel = new JSONArray();
        jsonResult.put("results", nextLevel);
        for (CmisTestResult child : result.getChildren()) {
            printResult(child, nextLevel);
        }
    }
}
Also used : JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) StringWriter(java.io.StringWriter) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) PrintWriter(java.io.PrintWriter)

Example 10 with JSONArray

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

the class JsonReport method createReport.

@Override
public void createReport(Map<String, String> parameters, List<CmisTestGroup> groups, Writer writer) throws IOException {
    JSONObject jsonReport = new JSONObject();
    JSONObject jsonParameters = new JSONObject();
    jsonReport.put("parameters", jsonParameters);
    if (parameters != null) {
        for (Map.Entry<String, String> p : (new TreeMap<String, String>(parameters)).entrySet()) {
            jsonParameters.put(p.getKey(), p.getValue());
        }
    }
    if (groups != null) {
        JSONArray jsonGroups = new JSONArray();
        jsonReport.put("groups", jsonGroups);
        for (CmisTestGroup group : groups) {
            printGroupResults(group, jsonGroups);
        }
    }
    jsonReport.writeJSONString(writer);
    writer.flush();
}
Also used : JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) CmisTestGroup(org.apache.chemistry.opencmis.tck.CmisTestGroup) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

JSONArray (org.apache.chemistry.opencmis.commons.impl.json.JSONArray)13 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)8 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)6 BigInteger (java.math.BigInteger)5 JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)5 IncludeRelationships (org.apache.chemistry.opencmis.commons.enums.IncludeRelationships)3 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)2 ObjectInFolderContainer (org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer)2 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 BulkUpdateObjectIdAndChangeToken (org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken)1 ObjectParentData (org.apache.chemistry.opencmis.commons.data.ObjectParentData)1 Properties (org.apache.chemistry.opencmis.commons.data.Properties)1 RenditionData (org.apache.chemistry.opencmis.commons.data.RenditionData)1 TypeDefinitionContainer (org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer)1 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)1