use of org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException in project copper-cms by PogeyanOSS.
the class RepositoryActor method getTypeDescendants.
private JSONArray getTypeDescendants(QueryGetRequest request) throws IllegalArgumentException, CmisInvalidArgumentException, CmisRuntimeException {
String permission = request.getUserObject().getPermission();
if (!Helpers.checkingUserPremission(permission, "get")) {
throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
}
String typeId = request.getParameter(QueryGetRequest.PARAM_TYPE_ID);
DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
BigInteger depth = request.getBigIntegerParameter(QueryGetRequest.PARAM_DEPTH);
boolean includePropertyDefinitions = request.getBooleanParameter(QueryGetRequest.PARAM_PROPERTY_DEFINITIONS, false);
List<TypeDefinitionContainer> typeTree = CmisTypeServices.Impl.getTypeDescendants(request.getRepositoryId(), typeId, depth, includePropertyDefinitions, null);
if (typeTree == null) {
throw new CmisRuntimeException("Type tree is null!");
}
JSONArray jsonTypeTree = new JSONArray();
for (TypeDefinitionContainer container : typeTree) {
jsonTypeTree.add(JSONConverter.convert(container, dateTimeFormat));
}
return jsonTypeTree;
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException in project copper-cms by PogeyanOSS.
the class RepositoryActor method getTypeDefinition.
private JSONObject getTypeDefinition(QueryGetRequest request) throws CmisRuntimeException, IllegalArgumentException {
String permission = request.getUserObject().getPermission();
if (!Helpers.checkingUserPremission(permission, "get")) {
throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
}
String typeId = request.getParameter(QueryGetRequest.PARAM_TYPE_ID);
DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
TypeDefinition type = CmisTypeServices.Impl.getTypeDefinition(request.getRepositoryId(), typeId, null);
JSONObject resultType = JSONConverter.convert(type, dateTimeFormat);
return resultType;
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException in project copper-cms by PogeyanOSS.
the class RepositoryActor method getRepositoryInfo.
private JSONObject getRepositoryInfo(QueryGetRequest t) throws CmisRuntimeException {
String permission = t.getUserObject().getPermission();
if (!Helpers.checkingUserPremission(permission, "get")) {
throw new CmisRuntimeException(t.getUserName() + " is not authorized to applyAcl.");
}
// call DB and get the repositoryInfo
String rootId = CmisObjectService.Impl.addRootFolder(t.getRepositoryId(), t.getUserName());
IRepository repository = RepositoryManagerFactory.getInstance().getRepositoryStore().getRepository(t.getRepositoryId());
RepositoryInfo repo = createRepositoryInfo(t.getRepositoryId(), repository.getRepositoryName() == null ? "" : repository.getRepositoryName(), CmisVersion.CMIS_1_1, rootId, repository.getDescription() == null ? "" : repository.getDescription());
String repositoryUrl = HttpUtils.compileRepositoryUrl(t.getBaseUrl(), t.getScheme(), t.getServerName(), t.getServerPort(), t.getContextPath(), t.getServletPath(), repo.getId()).toString();
String rootUrl = HttpUtils.compileRootUrl(t.getBaseUrl(), t.getScheme(), t.getServerName(), t.getServerPort(), t.getContextPath(), t.getServletPath(), repo.getId()).toString();
JSONObject result = new JSONObject();
result.put(repo.getId(), JSONConverter.convert(repo, repositoryUrl, rootUrl, true));
return result;
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException 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.exceptions.CmisRuntimeException 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
}
}
}
Aggregations