Search in sources :

Example 11 with CmisRuntimeException

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;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) BigInteger(java.math.BigInteger) TypeDefinitionContainer(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 12 with CmisRuntimeException

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;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)

Example 13 with CmisRuntimeException

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;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) IRepository(com.pogeyan.cmis.api.repo.IRepository)

Example 14 with CmisRuntimeException

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;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 15 with CmisRuntimeException

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
        }
    }
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) IOException(java.io.IOException) CmisStorageException(org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException) HashMap(java.util.HashMap) Map(java.util.Map) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisServiceUnavailableException(org.apache.chemistry.opencmis.commons.exceptions.CmisServiceUnavailableException) CmisNameConstraintViolationException(org.apache.chemistry.opencmis.commons.exceptions.CmisNameConstraintViolationException) CmisFilterNotValidException(org.apache.chemistry.opencmis.commons.exceptions.CmisFilterNotValidException) CmisTooManyRequestsException(org.apache.chemistry.opencmis.commons.exceptions.CmisTooManyRequestsException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisStorageException(org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException) CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) IOException(java.io.IOException) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisVersioningException(org.apache.chemistry.opencmis.commons.exceptions.CmisVersioningException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)

Aggregations

CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)49 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)35 JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)35 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)22 BigInteger (java.math.BigInteger)10 Properties (org.apache.chemistry.opencmis.commons.data.Properties)10 Acl (org.apache.chemistry.opencmis.commons.data.Acl)8 JSONArray (org.apache.chemistry.opencmis.commons.impl.json.JSONArray)8 Holder (org.apache.chemistry.opencmis.commons.spi.Holder)8 IUserGroupObject (com.pogeyan.cmis.api.auth.IUserGroupObject)6 IncludeRelationships (org.apache.chemistry.opencmis.commons.enums.IncludeRelationships)6 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)6 Map (java.util.Map)4 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)4 IOException (java.io.IOException)3 ObjectList (org.apache.chemistry.opencmis.commons.data.ObjectList)3 TypeDefinition (org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)3 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)3 IBaseObject (com.pogeyan.cmis.api.data.IBaseObject)2 InputStream (java.io.InputStream)2