Search in sources :

Example 26 with SenderException

use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.

the class CmisSender method sendMessageForActionFind.

private String sendMessageForActionFind(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    Element queryElement = null;
    try {
        if (XmlUtils.isWellFormed(message, "query")) {
            queryElement = XmlUtils.buildElement(message);
        } else {
            queryElement = XmlUtils.buildElement("<query/>");
        }
    } catch (DomBuilderException e) {
        throw new SenderException(e);
    }
    String statement = XmlUtils.getChildTagAsString(queryElement, "statement");
    String maxItems = XmlUtils.getChildTagAsString(queryElement, "maxItems");
    String skipCount = XmlUtils.getChildTagAsString(queryElement, "skipCount");
    String searchAllVersions = XmlUtils.getChildTagAsString(queryElement, "searchAllVersions");
    String includeAllowableActions = XmlUtils.getChildTagAsString(queryElement, "includeAllowableActions");
    OperationContext operationContext = session.createOperationContext();
    if (StringUtils.isNotEmpty(maxItems)) {
        operationContext.setMaxItemsPerPage(Integer.parseInt(maxItems));
    }
    boolean sav = false;
    if (StringUtils.isNotEmpty(searchAllVersions)) {
        sav = Boolean.parseBoolean(searchAllVersions);
    }
    if (StringUtils.isNotEmpty(includeAllowableActions)) {
        operationContext.setIncludeAllowableActions(Boolean.parseBoolean(searchAllVersions));
    }
    ItemIterable<QueryResult> q = session.query(statement, sav, operationContext);
    if (StringUtils.isNotEmpty(skipCount)) {
        long sc = Long.parseLong(skipCount);
        q = q.skipTo(sc);
    }
    if (StringUtils.isNotEmpty(maxItems)) {
        q = q.getPage();
    }
    XmlBuilder cmisXml = new XmlBuilder("cmis");
    XmlBuilder rowsetXml = new XmlBuilder("rowset");
    for (QueryResult qResult : q) {
        XmlBuilder rowXml = new XmlBuilder("row");
        for (PropertyData<?> property : qResult.getProperties()) {
            rowXml.addSubElement(getPropertyXml(property));
        }
        rowsetXml.addSubElement(rowXml);
    }
    cmisXml.addSubElement(rowsetXml);
    return cmisXml.toXML();
}
Also used : OperationContext(org.apache.chemistry.opencmis.client.api.OperationContext) QueryResult(org.apache.chemistry.opencmis.client.api.QueryResult) Element(org.w3c.dom.Element) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 27 with SenderException

use of nl.nn.adapterframework.core.SenderException 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)

Example 28 with SenderException

use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.

the class CmisSender method sendMessageForActionUpdate.

private String sendMessageForActionUpdate(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    String objectId = null;
    Map props = new HashMap();
    Element cmisElement;
    try {
        if (XmlUtils.isWellFormed(message, "cmis")) {
            cmisElement = XmlUtils.buildElement(message);
        } else {
            cmisElement = XmlUtils.buildElement("<cmis/>");
        }
        objectId = XmlUtils.getChildTagAsString(cmisElement, "id");
        Element propertiesElement = XmlUtils.getFirstChildTag(cmisElement, "properties");
        if (propertiesElement != null) {
            processProperties(propertiesElement, props);
        }
    } catch (DomBuilderException e) {
        throw new SenderException(getLogPrefix() + "exception parsing [" + message + "]", e);
    }
    CmisObject object = null;
    try {
        object = session.getObject(session.createObjectId(objectId));
    } catch (CmisObjectNotFoundException e) {
        if (StringUtils.isNotEmpty(getResultOnNotFound())) {
            log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
            return getResultOnNotFound();
        } else {
            throw new SenderException(e);
        }
    }
    object.updateProperties(props);
    return object.getId();
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 29 with SenderException

use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.

the class CmisSender method processProperties.

private void processProperties(Element propertiesElement, Map props) throws SenderException {
    Collection properties = XmlUtils.getChildTags(propertiesElement, "property");
    Iterator iter = properties.iterator();
    while (iter.hasNext()) {
        Element propertyElement = (Element) iter.next();
        String property = XmlUtils.getStringValue(propertyElement);
        if (StringUtils.isNotEmpty(property)) {
            String nameAttr = propertyElement.getAttribute("name");
            String typeAttr = propertyElement.getAttribute("type");
            if (StringUtils.isEmpty(typeAttr) || typeAttr.equalsIgnoreCase("string")) {
                props.put(nameAttr, property);
            } else if (typeAttr.equalsIgnoreCase("datetime")) {
                String formatStringAttr = propertyElement.getAttribute("formatString");
                if (StringUtils.isEmpty(formatStringAttr)) {
                    formatStringAttr = FORMATSTRING_BY_DEFAULT;
                }
                DateFormat df = new SimpleDateFormat(formatStringAttr);
                Date date;
                try {
                    date = df.parse(property);
                } catch (ParseException e) {
                    throw new SenderException(getLogPrefix() + "exception parsing date [" + property + "] using formatString [" + formatStringAttr + "]", e);
                }
                props.put(nameAttr, date);
            } else {
                log.warn(getLogPrefix() + "unknown type [" + typeAttr + "], assuming 'string'");
                props.put(nameAttr, property);
            }
            if (log.isDebugEnabled()) {
                log.debug(getLogPrefix() + "set property name [" + nameAttr + "] value [" + property + "]");
            }
        } else {
            log.debug(getLogPrefix() + "empty property found, ignoring");
        }
    }
}
Also used : Element(org.w3c.dom.Element) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Iterator(java.util.Iterator) Collection(java.util.Collection) ParseException(java.text.ParseException) SenderException(nl.nn.adapterframework.core.SenderException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 30 with SenderException

use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.

the class XmlFileElementIteratorPipe method iterateInput.

protected void iterateInput(Object input, IPipeLineSession session, String correlationID, Map threadContext, ItemCallback callback) throws SenderException, TimeOutException {
    InputStream xmlInput;
    try {
        xmlInput = new FileInputStream((String) input);
    } catch (FileNotFoundException e) {
        throw new SenderException("could not find file [" + input + "]", e);
    }
    ItemCallbackCallingHandler handler = new ItemCallbackCallingHandler(callback);
    log.debug("obtaining list of elements [" + getElementName() + "] using sax parser");
    try {
        SAXParserFactory parserFactory = XmlUtils.getSAXParserFactory();
        parserFactory.setNamespaceAware(true);
        SAXParser saxParser = parserFactory.newSAXParser();
        saxParser.parse(xmlInput, handler);
    } catch (Exception e) {
        if (handler.getTimeOutException() != null) {
            throw handler.getTimeOutException();
        }
        if (!handler.isStopRequested()) {
            throw new SenderException("Could not extract list of elements [" + getElementName() + "] using sax parser", e);
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) SAXParser(javax.xml.parsers.SAXParser) SenderException(nl.nn.adapterframework.core.SenderException) FileInputStream(java.io.FileInputStream) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SAXException(org.xml.sax.SAXException) SenderException(nl.nn.adapterframework.core.SenderException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

SenderException (nl.nn.adapterframework.core.SenderException)130 TimeOutException (nl.nn.adapterframework.core.TimeOutException)41 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)37 IOException (java.io.IOException)36 SQLException (java.sql.SQLException)25 HashMap (java.util.HashMap)21 ParameterException (nl.nn.adapterframework.core.ParameterException)21 PreparedStatement (java.sql.PreparedStatement)20 Map (java.util.Map)20 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)18 Iterator (java.util.Iterator)17 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)16 InputStream (java.io.InputStream)15 ResultSet (java.sql.ResultSet)13 Element (org.w3c.dom.Element)13 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)12 Date (java.util.Date)10 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)10 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9