Search in sources :

Example 1 with Property

use of org.apache.chemistry.opencmis.client.api.Property in project iaf by ibissource.

the class CmisSender method sendMessageForActionGet.

private String sendMessageForActionGet(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    if (StringUtils.isEmpty(message)) {
        throw new SenderException(getLogPrefix() + "input string cannot be empty but must contain a documentId");
    }
    CmisObject object = null;
    try {
        object = session.getObject(session.createObjectId(message));
    } catch (CmisObjectNotFoundException e) {
        if (StringUtils.isNotEmpty(getResultOnNotFound())) {
            log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
            return getResultOnNotFound();
        } else {
            throw new SenderException(e);
        }
    }
    Document document = (Document) object;
    ContentStream contentStream = document.getContentStream();
    try {
        InputStream inputStream = contentStream.getStream();
        if (isStreamResultToServlet()) {
            HttpServletResponse response = (HttpServletResponse) prc.getSession().get(IPipeLineSession.HTTP_RESPONSE_KEY);
            String contentType = contentStream.getMimeType();
            if (StringUtils.isNotEmpty(contentType)) {
                log.debug(getLogPrefix() + "setting response Content-Type header [" + contentType + "]");
                response.setHeader("Content-Type", contentType);
            }
            String contentDisposition = "attachment; filename=\"" + contentStream.getFileName() + "\"";
            log.debug(getLogPrefix() + "setting response Content-Disposition header [" + contentDisposition + "]");
            response.setHeader("Content-Disposition", contentDisposition);
            OutputStream outputStream;
            outputStream = response.getOutputStream();
            Misc.streamToStream(inputStream, outputStream);
            log.debug(getLogPrefix() + "copied document content input stream [" + inputStream + "] to output stream [" + outputStream + "]");
            return "";
        } else if (isGetProperties()) {
            if (StringUtils.isNotEmpty(fileInputStreamSessionKey)) {
                prc.getSession().put(getFileInputStreamSessionKey(), inputStream);
            } else {
                byte[] bytes = Misc.streamToBytes(inputStream);
                prc.getSession().put(getFileContentSessionKey(), Base64.encodeBase64String(bytes));
            }
            XmlBuilder cmisXml = new XmlBuilder("cmis");
            XmlBuilder propertiesXml = new XmlBuilder("properties");
            for (Iterator it = document.getProperties().iterator(); it.hasNext(); ) {
                Property property = (Property) it.next();
                propertiesXml.addSubElement(getPropertyXml(property));
            }
            cmisXml.addSubElement(propertiesXml);
            return cmisXml.toXML();
        } else {
            return Misc.streamToString(inputStream, null, false);
        }
    } catch (IOException e) {
        throw new SenderException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Document(org.apache.chemistry.opencmis.client.api.Document) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) SenderException(nl.nn.adapterframework.core.SenderException) Property(org.apache.chemistry.opencmis.client.api.Property)

Example 2 with Property

use of org.apache.chemistry.opencmis.client.api.Property in project iaf by ibissource.

the class CmisSender method sendMessageForActionFetch.

private String sendMessageForActionFetch(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    Element queryElement = null;
    try {
        if (XmlUtils.isWellFormed(message, "cmis")) {
            queryElement = XmlUtils.buildElement(message);
        } else {
            queryElement = XmlUtils.buildElement("<cmis/>");
        }
    } catch (DomBuilderException e) {
        throw new SenderException(e);
    }
    String objectIdstr = XmlUtils.getChildTagAsString(queryElement, "objectId");
    String filter = XmlUtils.getChildTagAsString(queryElement, "filter");
    boolean includeAllowableActions = XmlUtils.getChildTagAsBoolean(queryElement, "includeAllowableActions");
    boolean includePolicies = XmlUtils.getChildTagAsBoolean(queryElement, "includePolicies");
    boolean includeAcl = XmlUtils.getChildTagAsBoolean(queryElement, "includeAcl");
    OperationContext operationContext = session.createOperationContext();
    if (StringUtils.isNotEmpty(filter))
        operationContext.setFilterString(filter);
    operationContext.setIncludeAllowableActions(includeAllowableActions);
    operationContext.setIncludePolicies(includePolicies);
    operationContext.setIncludeAcls(includeAcl);
    CmisObject object = null;
    try {
        object = session.getObject(session.createObjectId(objectIdstr), operationContext);
    } catch (CmisObjectNotFoundException e) {
        if (StringUtils.isNotEmpty(getResultOnNotFound())) {
            log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
            return getResultOnNotFound();
        } else {
            throw new SenderException(e);
        }
    }
    XmlBuilder cmisXml = new XmlBuilder("cmis");
    XmlBuilder propertiesXml = new XmlBuilder("properties");
    for (Iterator it = object.getProperties().iterator(); it.hasNext(); ) {
        Property property = (Property) it.next();
        propertiesXml.addSubElement(getPropertyXml(property));
    }
    cmisXml.addSubElement(propertiesXml);
    XmlBuilder allowableActionsXml = new XmlBuilder("allowableActions");
    Set<Action> actions = object.getAllowableActions().getAllowableActions();
    for (Action action : actions) {
        XmlBuilder actionXml = new XmlBuilder("action");
        actionXml.setValue(action.value());
        allowableActionsXml.addSubElement(actionXml);
    }
    cmisXml.addSubElement(allowableActionsXml);
    XmlBuilder isExactAclXml = new XmlBuilder("isExactAcl");
    if (object.getAcl() != null)
        isExactAclXml.setValue(object.getAcl().isExact().toString());
    cmisXml.addSubElement(isExactAclXml);
    XmlBuilder policiesXml = new XmlBuilder("policyIds");
    List<ObjectId> policies = object.getPolicyIds();
    if (policies != null) {
        for (ObjectId objectId : policies) {
            XmlBuilder policyXml = new XmlBuilder("policyId");
            policyXml.setValue(objectId.getId());
            policiesXml.addSubElement(policyXml);
        }
    }
    cmisXml.addSubElement(policiesXml);
    XmlBuilder relationshipsXml = new XmlBuilder("relationships");
    List<Relationship> relationships = object.getRelationships();
    if (relationships != null) {
        for (Relationship relation : relationships) {
            XmlBuilder policyXml = new XmlBuilder("relation");
            policyXml.setValue(relation.getId());
            relationshipsXml.addSubElement(policyXml);
        }
    }
    cmisXml.addSubElement(relationshipsXml);
    return cmisXml.toXML();
}
Also used : OperationContext(org.apache.chemistry.opencmis.client.api.OperationContext) Action(org.apache.chemistry.opencmis.commons.enums.Action) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) Element(org.w3c.dom.Element) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) Relationship(org.apache.chemistry.opencmis.client.api.Relationship) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException) Property(org.apache.chemistry.opencmis.client.api.Property)

Aggregations

Iterator (java.util.Iterator)2 SenderException (nl.nn.adapterframework.core.SenderException)2 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)2 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)2 Property (org.apache.chemistry.opencmis.client.api.Property)2 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)1 Document (org.apache.chemistry.opencmis.client.api.Document)1 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)1 OperationContext (org.apache.chemistry.opencmis.client.api.OperationContext)1 Relationship (org.apache.chemistry.opencmis.client.api.Relationship)1 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)1 Action (org.apache.chemistry.opencmis.commons.enums.Action)1 Element (org.w3c.dom.Element)1