Search in sources :

Example 31 with Connection

use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.

the class ConnectMessageFromNodeProcessor method process.

public void process(final Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    // a need wants to connect.
    // get the required data from the message and create a connection
    URI needUri = wonMessage.getReceiverNeedURI();
    URI wonNodeUriFromWonMessage = wonMessage.getReceiverNodeURI();
    URI remoteNeedUri = wonMessage.getSenderNeedURI();
    URI remoteConnectionUri = wonMessage.getSenderURI();
    URI facetURI = WonRdfUtils.FacetUtils.getFacet(wonMessage);
    // if the uri is known already, we can load the connection!
    URI connectionURI = wonMessage.getReceiverURI();
    if (remoteConnectionUri == null)
        throw new MissingMessagePropertyException(URI.create(WONMSG.SENDER_PROPERTY.getURI().toString()));
    Connection con = null;
    if (connectionURI != null) {
        con = connectionRepository.findOneByConnectionURIForUpdate(connectionURI);
        if (con == null)
            throw new NoSuchConnectionException(connectionURI);
    } else {
        con = connectionRepository.findOneByNeedURIAndRemoteNeedURIAndTypeURIForUpdate(needUri, remoteNeedUri, facetURI);
    }
    if (con == null) {
        // create Connection in Database
        URI connectionUri = wonNodeInformationService.generateConnectionURI(wonNodeUriFromWonMessage);
        con = dataService.createConnection(connectionUri, needUri, remoteNeedUri, remoteConnectionUri, facetURI, ConnectionState.REQUEST_RECEIVED, ConnectionEventType.PARTNER_OPEN);
    }
    con.setRemoteConnectionURI(remoteConnectionUri);
    con.setState(con.getState().transit(ConnectionEventType.PARTNER_OPEN));
    connectionRepository.save(con);
    // set the receiver to the newly generated connection uri
    wonMessage.addMessageProperty(WONMSG.RECEIVER_PROPERTY, con.getConnectionURI());
}
Also used : Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) MissingMessagePropertyException(won.protocol.message.processor.exception.MissingMessagePropertyException) NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) URI(java.net.URI)

Example 32 with Connection

use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.

the class DeactivateNeedMessageFromOwnerReactionProcessor method process.

public void process(final Exchange exchange) throws Exception {
    WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
    URI receiverNeedURI = wonMessage.getReceiverNeedURI();
    logger.debug("DEACTIVATING need. needURI:{}", receiverNeedURI);
    if (receiverNeedURI == null)
        throw new WonMessageProcessingException("receiverNeedURI is not set");
    Need need = DataAccessUtils.loadNeed(needRepository, receiverNeedURI);
    matcherProtocolMatcherClient.needDeactivated(need.getNeedURI(), wonMessage);
    // close all connections
    Collection<Connection> conns = connectionRepository.getConnectionsByNeedURIAndNotInStateForUpdate(need.getNeedURI(), ConnectionState.CLOSED);
    for (Connection con : conns) {
        closeConnection(need, con);
    }
}
Also used : WonMessageProcessingException(won.protocol.message.processor.exception.WonMessageProcessingException) Need(won.protocol.model.Need) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) URI(java.net.URI)

Example 33 with Connection

use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.

the class HintFeedbackMessageFromOwnerProcessor method process.

public void process(final Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    Connection con = connectionRepository.findOneByConnectionURIForUpdate(wonMessage.getSenderURI());
    logger.debug("HINT_FEEDBACK received from the owner side for connection {}", wonMessage.getSenderURI());
    processFeedbackMessage(con, wonMessage);
}
Also used : Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection)

Example 34 with Connection

use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.

the class OpenMessageFromOwnerProcessor method process.

public void process(final Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    logger.debug("OPEN received from the owner side for connection {}", wonMessage.getSenderURI());
    Connection con = dataService.nextConnectionState(wonMessage.getSenderURI(), ConnectionEventType.OWNER_OPEN);
    Objects.requireNonNull(con);
    Objects.requireNonNull(con.getRemoteNeedURI());
    if (!con.getRemoteNeedURI().equals(wonMessage.getReceiverNeedURI()))
        throw new IllegalStateException("remote need uri must be equal to receiver need uri");
    if (con.getConnectionURI() == null)
        throw new IllegalStateException("connection uri must not be null");
    if (!con.getConnectionURI().equals(wonMessage.getSenderURI()))
        throw new IllegalStateException("connection uri must be equal to sender uri");
    if (wonMessage.getReceiverURI() != null) {
        if (!wonMessage.getReceiverURI().equals(con.getRemoteConnectionURI()))
            throw new IllegalStateException("remote connection uri must be equal to receiver uri");
        if (con.getRemoteConnectionURI() == null) {
            // we didn't have it before, now we do:
            con.setRemoteConnectionURI(wonMessage.getReceiverURI());
        }
    } else {
    // do nothing. it's not clean, but easier to implement on the client side
    // TODO: refactor connection state and open/connect
    }
    con.setState(con.getState().transit(ConnectionEventType.OWNER_OPEN));
    connectionRepository.save(con);
    URI remoteMessageUri = wonNodeInformationService.generateEventURI(wonMessage.getReceiverNodeURI());
    // add the information about the corresponding message to the local one
    wonMessage.addMessageProperty(WONMSG.HAS_CORRESPONDING_REMOTE_MESSAGE, remoteMessageUri);
    // the persister will pick it up later
    // put the factory into the outbound message factory header. It will be used to generate the outbound message
    // after the wonMessage has been processed and saved, to make sure that the outbound message contains
    // all the data that we also store locally
    OutboundMessageFactory outboundMessageFactory = new OutboundMessageFactory(remoteMessageUri, con);
    exchange.getIn().setHeader(WonCamelConstants.OUTBOUND_MESSAGE_FACTORY_HEADER, outboundMessageFactory);
}
Also used : Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) URI(java.net.URI)

Example 35 with Connection

use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.

the class SendMessageFromNodeProcessor method process.

public void process(final Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    URI connectionUri = wonMessage.getReceiverURI();
    if (connectionUri == null) {
        throw new MissingMessagePropertyException(URI.create(WONMSG.RECEIVER_PROPERTY.toString()));
    }
    Connection con = connectionRepository.findOneByConnectionURIForUpdate(connectionUri);
    if (con.getState() != ConnectionState.CONNECTED) {
        throw new IllegalMessageForConnectionStateException(connectionUri, "CONNECTION_MESSAGE", con.getState());
    }
}
Also used : Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) MissingMessagePropertyException(won.protocol.message.processor.exception.MissingMessagePropertyException) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) IllegalMessageForConnectionStateException(won.protocol.exception.IllegalMessageForConnectionStateException) URI(java.net.URI)

Aggregations

Connection (won.protocol.model.Connection)50 URI (java.net.URI)30 WonMessage (won.protocol.message.WonMessage)20 Message (org.apache.camel.Message)12 Model (org.apache.jena.rdf.model.Model)12 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)9 Dataset (org.apache.jena.query.Dataset)6 WonURI (won.bot.framework.eventbot.action.impl.mail.model.WonURI)6 Resource (org.apache.jena.rdf.model.Resource)5 ConnectionMessageCommandEvent (won.bot.framework.eventbot.event.impl.command.connectionmessage.ConnectionMessageCommandEvent)5 MissingMessagePropertyException (won.protocol.message.processor.exception.MissingMessagePropertyException)5 BaseEventBotAction (won.bot.framework.eventbot.action.BaseEventBotAction)4 EventBus (won.bot.framework.eventbot.bus.EventBus)4 Event (won.bot.framework.eventbot.event.Event)4 CloseCommandEvent (won.bot.framework.eventbot.event.impl.command.close.CloseCommandEvent)4 EventListener (won.bot.framework.eventbot.listener.EventListener)4 WonRdfUtils (won.protocol.util.WonRdfUtils)4 Message (org.telegram.telegrambots.api.objects.Message)3 TelegramBotContextWrapper (won.bot.framework.bot.context.TelegramBotContextWrapper)3 BaseNeedAndConnectionSpecificEvent (won.bot.framework.eventbot.event.BaseNeedAndConnectionSpecificEvent)3