Search in sources :

Example 1 with MessageOutputStreamCap

use of nl.nn.adapterframework.stream.MessageOutputStreamCap in project iaf by ibissource.

the class MongoDbSender method sendMessage.

@Override
public PipeRunResult sendMessage(Message message, PipeLineSession session, IForwardTarget next) throws SenderException, TimeoutException {
    message.closeOnCloseOf(session, this);
    MongoAction mngaction = getAction();
    try (MessageOutputStream target = mngaction == MongoAction.FINDONE || mngaction == MongoAction.FINDMANY ? MessageOutputStream.getTargetStream(this, session, next) : new MessageOutputStreamCap(this, next)) {
        ParameterValueList pvl = ParameterValueList.get(getParameterList(), message, session);
        MongoDatabase mongoDatabase = getDatabase(pvl);
        MongoCollection<Document> mongoCollection = getCollection(mongoDatabase, pvl);
        switch(mngaction) {
            case INSERTONE:
                renderResult(mongoCollection.insertOne(getDocument(message)), target);
                break;
            case INSERTMANY:
                renderResult(mongoCollection.insertMany(getDocuments(message)), target);
                break;
            case FINDONE:
                renderResult(mongoCollection.find(getFilter(pvl, message)).first(), target);
                break;
            case FINDMANY:
                renderResult(mongoCollection.find(getFilter(pvl, message)).limit(getLimit(pvl)), target);
                break;
            case UPDATEONE:
                renderResult(mongoCollection.updateOne(getFilter(pvl, null), getDocument(message)), target);
                break;
            case UPDATEMANY:
                renderResult(mongoCollection.updateMany(getFilter(pvl, null), getDocument(message)), target);
                break;
            case DELETEONE:
                renderResult(mongoCollection.deleteOne(getFilter(pvl, message)), target);
                break;
            case DELETEMANY:
                renderResult(mongoCollection.deleteMany(getFilter(pvl, message)), target);
                break;
            default:
                throw new SenderException("Unknown action [" + getAction() + "]");
        }
        return target.getPipeRunResult();
    } catch (Exception e) {
        throw new SenderException("Cannot execute action [" + getAction() + "]", e);
    }
}
Also used : MessageOutputStream(nl.nn.adapterframework.stream.MessageOutputStream) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) MessageOutputStreamCap(nl.nn.adapterframework.stream.MessageOutputStreamCap) Document(org.bson.Document) SenderException(nl.nn.adapterframework.core.SenderException) NamingException(javax.naming.NamingException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) StreamingException(nl.nn.adapterframework.stream.StreamingException) SAXException(org.xml.sax.SAXException) SenderException(nl.nn.adapterframework.core.SenderException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterException(nl.nn.adapterframework.core.ParameterException) MongoDatabase(com.mongodb.client.MongoDatabase)

Aggregations

MongoDatabase (com.mongodb.client.MongoDatabase)1 IOException (java.io.IOException)1 NamingException (javax.naming.NamingException)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 ParameterException (nl.nn.adapterframework.core.ParameterException)1 SenderException (nl.nn.adapterframework.core.SenderException)1 TimeoutException (nl.nn.adapterframework.core.TimeoutException)1 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)1 MessageOutputStream (nl.nn.adapterframework.stream.MessageOutputStream)1 MessageOutputStreamCap (nl.nn.adapterframework.stream.MessageOutputStreamCap)1 StreamingException (nl.nn.adapterframework.stream.StreamingException)1 Document (org.bson.Document)1 SAXException (org.xml.sax.SAXException)1