Search in sources :

Example 16 with JSONObject

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

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

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

Example 19 with JSONObject

use of org.apache.chemistry.opencmis.commons.impl.json.JSONObject in project SearchServices by Alfresco.

the class AbstractAlfrescoSolrTests method assertQueryCollection.

/**
 * Builds and asserts that query returns a collection in the correct order by
 * checking the dbid value of each document is in the correct order.
 *
 * @author Michael Suzuki
 * @param query query used to search
 * @param dbids collection of dbids to compare
 * @throws Exception if error
 */
public static void assertQueryCollection(String query, Integer[] dbids) throws Exception {
    SolrQueryRequest solrReq = req(params("rows", "20", "qt", "/cmis", "q", query, "wt", "json"));
    try {
        String response = h.query(solrReq);
        JSONObject json = (JSONObject) JSONValue.parse(response);
        JSONObject res = (JSONObject) json.get("response");
        JSONArray docs = (JSONArray) res.get("docs");
        Assert.assertTrue(dbids.length == docs.size());
        int count = 0;
        for (Object doc : docs) {
            JSONObject item = (JSONObject) doc;
            BigInteger val = (BigInteger) item.get("DBID");
            Assert.assertEquals(dbids[count].intValue(), val.intValue());
            count++;
        }
    } finally {
        solrReq.close();
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) BigInteger(java.math.BigInteger) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject)

Example 20 with JSONObject

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

the class ObjectActor method appendContent.

private JSONObject appendContent(PostRequest request) throws 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();
    String changeToken = request.getParameter(QueryGetRequest.PARAM_CHANGE_TOKEN);
    boolean isLastChunk = request.getBooleanParameter(QueryGetRequest.CONTROL_IS_LAST_CHUNK, false);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.CONTROL_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    Holder<String> objectIdHolder = new Holder<String>(objectId);
    Holder<String> changeTokenHolder = (changeToken == null ? null : new Holder<String>(changeToken));
    if (request.getContentStream() == null) {
        CmisObjectService.Impl.appendContentStream(request.getRepositoryId(), objectIdHolder, changeTokenHolder, null, isLastChunk);
    } else {
        CmisObjectService.Impl.appendContentStream(request.getRepositoryId(), objectIdHolder, changeTokenHolder, request.getContentStream(), isLastChunk);
    }
    String newObjectId = (objectIdHolder.getValue() == null ? objectId : objectIdHolder.getValue());
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), newObjectId, request.getUserObject().getUserDN(), BaseTypeId.CMIS_DOCUMENT);
    if (object == null) {
        throw new CmisRuntimeException("Object is null!");
    }
    // return object
    JSONObject jsonObject = JSONConverter.convert(object, null, JSONConverter.PropertyMode.CHANGE, succinct, dateTimeFormat);
    return jsonObject;
}
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) 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