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