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);
}
}
}
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);
}
}
}
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();
}
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();
}
}
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;
}
Aggregations