Search in sources :

Example 11 with RepositoryInfo

use of org.apache.chemistry.opencmis.commons.data.RepositoryInfo in project iaf by ibissource.

the class CmisSender method sendMessageForDynamicActions.

private Message sendMessageForDynamicActions(Session cmisSession, Message message, PipeLineSession session) throws SenderException, TimeoutException {
    XmlBuilder resultXml = new XmlBuilder("cmis");
    Element requestElement = null;
    try {
        if (XmlUtils.isWellFormed(message, "cmis")) {
            requestElement = XmlUtils.buildElement(message);
        } else {
            requestElement = XmlUtils.buildElement("<cmis/>");
        }
    } catch (DomBuilderException e) {
        throw new SenderException(e);
    }
    CmisEvent event = CmisEvent.GET_OBJECT;
    try {
        String cmisEvent = session.getMessage(CmisEventDispatcher.CMIS_EVENT_KEY).asString();
        if (StringUtils.isNotEmpty(cmisEvent)) {
            event = EnumUtils.parse(CmisEvent.class, cmisEvent, true);
        }
    } catch (IOException | IllegalArgumentException e) {
        throw new SenderException("unable to parse CmisEvent", e);
    }
    switch(event) {
        case DELETE_OBJECT:
            getCmisObject(cmisSession, requestElement).delete(true);
            resultXml.addAttribute("deleted", true);
            break;
        case CREATE_DOCUMENT:
            Map<String, Object> props = new HashMap<>();
            Element propertiesElement = XmlUtils.getFirstChildTag(requestElement, "properties");
            if (propertiesElement != null) {
                processProperties(propertiesElement, props);
            }
            ObjectId folderId = null;
            String folderIdstr = XmlUtils.getChildTagAsString(requestElement, "folderId");
            if (StringUtils.isNotEmpty(folderIdstr))
                folderId = cmisSession.createObjectId(folderIdstr);
            String versioningStatestr = XmlUtils.getChildTagAsString(requestElement, "versioningState");
            VersioningState state = VersioningState.valueOf(versioningStatestr);
            Element contentStreamXml = XmlUtils.getFirstChildTag(requestElement, "contentStream");
            Message stream = session.getMessage("ContentStream");
            String fileName = contentStreamXml.getAttribute("filename");
            long fileLength = Long.parseLong(contentStreamXml.getAttribute("length"));
            String mediaType = contentStreamXml.getAttribute("mimeType");
            ContentStream contentStream;
            try {
                contentStream = cmisSession.getObjectFactory().createContentStream(fileName, fileLength, mediaType, stream.asInputStream());
            } catch (IOException e) {
                throw new SenderException("unable to parse ContentStream as InputStream", e);
            }
            ObjectId createdDocumentId = cmisSession.createDocument(props, folderId, contentStream, state);
            XmlBuilder cmisId = new XmlBuilder("id");
            cmisId.setValue(createdDocumentId.getId());
            resultXml.addSubElement(cmisId);
            break;
        case UPDATE_PROPERTIES:
            Map<String, Object> propss = new HashMap<String, Object>();
            Element propertiesElements = XmlUtils.getFirstChildTag(requestElement, "properties");
            if (propertiesElements != null) {
                processProperties(propertiesElements, propss);
            }
            getCmisObject(cmisSession, requestElement).updateProperties(propss);
            resultXml.addAttribute("updated", true);
            break;
        case GET_CONTENTSTREAM:
            String streamId = XmlUtils.getChildTagAsString(requestElement, "streamId");
            long offsetStr = XmlUtils.getChildTagAsLong(requestElement, "offset");
            BigInteger offset = BigInteger.valueOf(offsetStr);
            long lengthStr = XmlUtils.getChildTagAsLong(requestElement, "length");
            BigInteger length = BigInteger.valueOf(lengthStr);
            ObjectId objectIdforContentStream = getCmisObject(cmisSession, requestElement);
            ContentStream getContentStream = cmisSession.getContentStream(objectIdforContentStream, streamId, offset, length);
            XmlBuilder objectIdStream = new XmlBuilder("id");
            objectIdStream.setValue(objectIdforContentStream.getId());
            resultXml.addSubElement(objectIdStream);
            XmlBuilder contentStreamBuilder = new XmlBuilder("contentStream");
            contentStreamBuilder.addAttribute("filename", getContentStream.getFileName());
            contentStreamBuilder.addAttribute("length", getContentStream.getLength());
            contentStreamBuilder.addAttribute("mimeType", getContentStream.getMimeType());
            resultXml.addSubElement(contentStreamBuilder);
            session.put("ContentStream", getContentStream.getStream());
            break;
        case GET_TYPE_DEFINITION:
            String typeId = XmlUtils.getChildTagAsString(requestElement, "typeId");
            ObjectType objectType = cmisSession.getTypeDefinition(typeId);
            XmlBuilder typesXml = new XmlBuilder("typeDefinitions");
            typesXml.addSubElement(CmisUtils.typeDefinition2Xml(objectType));
            resultXml.addSubElement(typesXml);
            break;
        case GET_TYPE_DESCENDANTS:
            String typeDescId = XmlUtils.getChildTagAsString(requestElement, "typeId");
            int depth = Integer.parseInt(XmlUtils.getChildTagAsString(requestElement, "depth"));
            boolean includePropertyDefinitions = XmlUtils.getChildTagAsBoolean(requestElement, "includePropertyDefinitions");
            List<Tree<ObjectType>> objectTypes = cmisSession.getTypeDescendants(typeDescId, depth, includePropertyDefinitions);
            resultXml.addSubElement(CmisUtils.typeDescendants2Xml(objectTypes));
            break;
        case GET_REPOSITORIES:
            List<RepositoryInfo> repositories = cmisSession.getBinding().getRepositoryService().getRepositoryInfos(null);
            XmlBuilder repositoriesXml = new XmlBuilder("repositories");
            for (RepositoryInfo repository : repositories) {
                repositoriesXml.addSubElement(CmisUtils.repositoryInfo2xml(repository));
            }
            resultXml.addSubElement(repositoriesXml);
            break;
        case GET_REPOSITORY_INFO:
            String repositoryId = XmlUtils.getChildTagAsString(requestElement, "repositoryId");
            RepositoryInfo repository = cmisSession.getBinding().getRepositoryService().getRepositoryInfo(repositoryId, null);
            XmlBuilder repositoryInfoXml = new XmlBuilder("repositories");
            repositoryInfoXml.addSubElement(CmisUtils.repositoryInfo2xml(repository));
            resultXml.addSubElement(repositoryInfoXml);
            break;
        case QUERY:
            String repositoryQueryId = XmlUtils.getChildTagAsString(requestElement, "repositoryId");
            String statement = XmlUtils.getChildTagAsString(requestElement, "statement");
            Boolean searchAllVersions = XmlUtils.getChildTagAsBoolean(requestElement, "searchAllVersions");
            Boolean includeAllowableActions = XmlUtils.getChildTagAsBoolean(requestElement, "includeAllowableActions");
            String includeRelationshipsEnum = XmlUtils.getChildTagAsString(requestElement, "includeRelationships");
            IncludeRelationships includeRelationships = IncludeRelationships.valueOf(includeRelationshipsEnum);
            String renditionFilter = XmlUtils.getChildTagAsString(requestElement, "renditionFilter");
            BigInteger maxItems = null;
            String maxItemsString = XmlUtils.getChildTagAsString(requestElement, "maxItems");
            if (StringUtils.isNotEmpty(maxItemsString)) {
                maxItems = BigInteger.valueOf(Long.parseLong(maxItemsString));
            }
            BigInteger skipCount = null;
            String skipCountString = XmlUtils.getChildTagAsString(requestElement, "skipCount");
            if (StringUtils.isNotEmpty(skipCountString)) {
                skipCount = BigInteger.valueOf(Long.parseLong(skipCountString));
            }
            // Create a operationContext and do session.query?
            // OperationContext context = session.createOperationContext();
            // context.setIncludeAllowableActions(includeAllowableActions);
            // context.setIncludeRelationships(includeRelationships);
            // context.setRenditionFilterString(renditionFilter);
            ObjectList result = cmisSession.getBinding().getDiscoveryService().query(repositoryQueryId, statement, searchAllVersions, includeAllowableActions, includeRelationships, renditionFilter, maxItems, skipCount, null);
            resultXml.addSubElement(CmisUtils.objectList2xml(result));
            break;
        case GET_CHILDREN:
            String rid = XmlUtils.getChildTagAsString(requestElement, "repositoryId");
            String fid = XmlUtils.getChildTagAsString(requestElement, "folderId");
            String getChildren_repositoryFilter = XmlUtils.getChildTagAsString(requestElement, "filter");
            String getChildren_repositoryOrderBy = XmlUtils.getChildTagAsString(requestElement, "orderBy");
            Boolean getChildren_includeAllowableActions = XmlUtils.getChildTagAsBoolean(requestElement, "includeAllowableActions");
            IncludeRelationships getChildren_includeRelationships = IncludeRelationships.valueOf(XmlUtils.getChildTagAsString(requestElement, "includeRelationships"));
            String getChildren_renditionFilter = XmlUtils.getChildTagAsString(requestElement, "renditionFilter");
            Boolean getChildren_includePathSegment = XmlUtils.getChildTagAsBoolean(requestElement, "includePathSegment");
            BigInteger getChildren_maxItems = BigInteger.valueOf(XmlUtils.getChildTagAsLong(requestElement, "maxItems"));
            BigInteger getChildren_skipCount = BigInteger.valueOf(XmlUtils.getChildTagAsLong(requestElement, "skipCount"));
            ObjectInFolderList oifs = cmisSession.getBinding().getNavigationService().getChildren(rid, fid, getChildren_repositoryFilter, getChildren_repositoryOrderBy, getChildren_includeAllowableActions, getChildren_includeRelationships, getChildren_renditionFilter, getChildren_includePathSegment, getChildren_maxItems, getChildren_skipCount, null);
            resultXml.addSubElement(CmisUtils.objectInFolderList2xml(oifs));
            break;
        case GET_PROPERTIES:
        case GET_OBJECT:
        case GET_OBJECT_BY_PATH:
        case GET_ALLOWABLE_ACTIONS:
            CmisObject object = getCmisObject(cmisSession, requestElement);
            session.put(CmisUtils.ORIGINAL_OBJECT_KEY, object);
            CmisUtils.cmisObject2Xml(resultXml, object);
            break;
        default:
            throw new CmisNotSupportedException("Operation not implemented");
    }
    return new Message(resultXml.toXML());
}
Also used : CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) Message(nl.nn.adapterframework.stream.Message) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) IncludeRelationships(org.apache.chemistry.opencmis.commons.enums.IncludeRelationships) ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) Tree(org.apache.chemistry.opencmis.client.api.Tree) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) IOException(java.io.IOException) ObjectInFolderList(org.apache.chemistry.opencmis.commons.data.ObjectInFolderList) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) BigInteger(java.math.BigInteger) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) VersioningState(org.apache.chemistry.opencmis.commons.enums.VersioningState) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException) CmisEvent(nl.nn.adapterframework.extensions.cmis.server.CmisEvent)

Aggregations

RepositoryInfo (org.apache.chemistry.opencmis.commons.data.RepositoryInfo)11 ArrayList (java.util.ArrayList)3 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)3 IRepository (com.pogeyan.cmis.api.repo.IRepository)2 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)2 JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)2 Element (org.w3c.dom.Element)2 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 SenderException (nl.nn.adapterframework.core.SenderException)1 CmisEvent (nl.nn.adapterframework.extensions.cmis.server.CmisEvent)1 Message (nl.nn.adapterframework.stream.Message)1 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)1 PagingRequest (org.alfresco.query.PagingRequest)1 Network (org.alfresco.repo.tenant.Network)1 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)1 Folder (org.apache.chemistry.opencmis.client.api.Folder)1