Search in sources :

Example 1 with QueryGetRequest

use of com.pogeyan.cmis.api.messages.QueryGetRequest in project copper-cms by PogeyanOSS.

the class ServletHelpers method queryHttpToBaseMessage.

static BaseMessage queryHttpToBaseMessage(QueryStringHttpServletRequestWrapper request, String[] pathFragments, IUserObject userObject) {
    QueryGetRequest queryRequest = new QueryGetRequest();
    queryRequest.setParameterMap(request.getParameterMap());
    queryRequest.setBaseUrl((String) request.getAttribute(BrowserConstants.BASE_URL_ATTRIBUTE));
    queryRequest.setScheme(request.getScheme());
    queryRequest.setServerName(request.getServerName());
    queryRequest.setServerPort(request.getServerPort());
    queryRequest.setContextPath(request.getContextPath());
    queryRequest.setServletPath(request.getServletPath());
    queryRequest.setRange(request.getHeader("Range"));
    String objectId = HttpUtils.getStringParameter(request, BrowserConstants.PARAM_OBJECT_ID);
    queryRequest.setObjectId(objectId);
    if (userObject != null) {
        queryRequest.setUserName(userObject.getUserDN());
        queryRequest.setUserObject(userObject);
    }
    if (pathFragments.length > 0) {
        queryRequest.setRepositoryId(pathFragments[0]);
    }
    // selector is the actionName
    String selector = HttpUtils.getStringParameter(request, BrowserConstants.PARAM_SELECTOR);
    if (pathFragments.length > 1) {
        queryRequest.setPathFragments(pathFragments);
        // nested url
        String repositoryId = pathFragments[0];
        try {
            ObjectData object = null;
            // Example objectId format-typeID::primaryKey::primaryKeyValue
            if (objectId != null && objectId.contains("::")) {
                String[] inputs = objectId.split("::");
                // getObjectForRestAPI method is used to get the object.
                object = CmisObjectService.Impl.getObjectForRestAPI(repositoryId, inputs[0], inputs[1], inputs[2], "cmis:objectId,cmis:objectTypeId,cmis:baseTypeId", false, IncludeRelationships.NONE, "cmis:none", false, false, null, "");
            } else {
                object = ServletHelpers.getObjectDataFor(repositoryId, objectId, pathFragments);
            }
            // reset object id again here
            objectId = object.getId();
            queryRequest.setObjectId(objectId);
            String typeId = getStringPropertyValue(object, PropertyIds.OBJECT_TYPE_ID);
            queryRequest.setTypeId(typeId);
            BaseTypeId baseTypeId = BaseTypeId.fromValue(getStringPropertyValue(object, PropertyIds.BASE_TYPE_ID));
            queryRequest.setBaseTypeId(baseTypeId);
            if (selector == null) {
                switch(baseTypeId) {
                    case CMIS_DOCUMENT:
                        selector = BrowserConstants.SELECTOR_CONTENT;
                        break;
                    case CMIS_FOLDER:
                        selector = BrowserConstants.SELECTOR_CHILDREN;
                        break;
                    default:
                        selector = BrowserConstants.SELECTOR_OBJECT;
                        break;
                }
            }
        } catch (Exception e) {
            selector = BrowserConstants.SELECTOR_OBJECT;
        }
    }
    selector = selector == null ? "GetRepositories".toLowerCase() : selector;
    BaseMessage bm = BaseMessage.create("", selector, queryRequest);
    return bm;
}
Also used : BaseMessage(com.pogeyan.cmis.api.BaseMessage) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) QueryGetRequest(com.pogeyan.cmis.api.messages.QueryGetRequest) 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

BaseMessage (com.pogeyan.cmis.api.BaseMessage)1 QueryGetRequest (com.pogeyan.cmis.api.messages.QueryGetRequest)1 IOException (java.io.IOException)1 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)1 BaseTypeId (org.apache.chemistry.opencmis.commons.enums.BaseTypeId)1 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)1 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)1 CmisContentAlreadyExistsException (org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException)1 CmisFilterNotValidException (org.apache.chemistry.opencmis.commons.exceptions.CmisFilterNotValidException)1 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)1 CmisNameConstraintViolationException (org.apache.chemistry.opencmis.commons.exceptions.CmisNameConstraintViolationException)1 CmisNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException)1 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)1 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)1 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)1 CmisServiceUnavailableException (org.apache.chemistry.opencmis.commons.exceptions.CmisServiceUnavailableException)1 CmisStorageException (org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException)1 CmisStreamNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException)1 CmisTooManyRequestsException (org.apache.chemistry.opencmis.commons.exceptions.CmisTooManyRequestsException)1 CmisUpdateConflictException (org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException)1