Search in sources :

Example 6 with Connection

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

the class LockMessageParentWonMessageProcessor method lockParent.

private void lockParent(WonMessage message) {
    // get the parent's URI (either a connection or a need
    URI parentURI = WonMessageUtils.getParentEntityUri(message);
    // try a connection:
    Connection con = connectionRepository.findOneByConnectionURIForUpdate(parentURI);
    if (con != null) {
        connectionEventContainerRepository.findOneByParentUriForUpdate(parentURI);
    } else {
        needRepository.findOneByNeedURIForUpdate(parentURI);
        needEventContainerRepository.findOneByParentUriForUpdate(parentURI);
    }
}
Also used : Connection(won.protocol.model.Connection) URI(java.net.URI)

Example 7 with Connection

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

the class ConnectMessageFromOwnerProcessor method onSuccessResponse.

@Override
public void onSuccessResponse(final Exchange exchange) throws Exception {
    WonMessage responseMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
    MessageEventPlaceholder mep = this.messageEventRepository.findOneByCorrespondingRemoteMessageURI(responseMessage.getIsResponseToMessageURI());
    // update the connection database: set the remote connection URI just obtained from the response
    Connection con = this.connectionRepository.findOneByConnectionURIForUpdate(mep.getSenderURI());
    con.setRemoteConnectionURI(responseMessage.getSenderURI());
    this.connectionRepository.save(con);
}
Also used : WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) MessageEventPlaceholder(won.protocol.model.MessageEventPlaceholder)

Example 8 with Connection

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

the class ConnectMessageFromOwnerProcessor method process.

public void process(final Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    URI senderNeedURI = wonMessage.getSenderNeedURI();
    URI senderNodeURI = wonMessage.getSenderNodeURI();
    URI receiverNeedURI = wonMessage.getReceiverNeedURI();
    URI facetURI = WonRdfUtils.FacetUtils.getFacet(wonMessage);
    // if the uri is known already, we can load the connection!
    URI connectionURI = wonMessage.getSenderURI();
    Connection con = null;
    if (connectionURI != null) {
        con = connectionRepository.findOneByConnectionURIForUpdate(connectionURI);
        if (con == null)
            throw new NoSuchConnectionException(connectionURI);
    } else {
        con = connectionRepository.findOneByNeedURIAndRemoteNeedURIAndTypeURIForUpdate(senderNeedURI, receiverNeedURI, facetURI);
    }
    if (con == null) {
        // create Connection in Database
        URI connectionUri = wonNodeInformationService.generateConnectionURI(senderNodeURI);
        con = dataService.createConnection(connectionUri, senderNeedURI, receiverNeedURI, null, facetURI, ConnectionState.REQUEST_SENT, ConnectionEventType.OWNER_OPEN);
    }
    con.setState(con.getState().transit(ConnectionEventType.OWNER_OPEN));
    connectionRepository.save(con);
    // prepare the message to pass to the remote node
    URI remoteMessageUri = wonNodeInformationService.generateEventURI(wonMessage.getReceiverNodeURI());
    // set the sender uri in the envelope TODO: TwoMsgs: do not set sender here
    wonMessage.addMessageProperty(WONMSG.SENDER_PROPERTY, con.getConnectionURI());
    // add the information about the new local connection to the original message
    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);
    message.setHeader(WonCamelConstants.OUTBOUND_MESSAGE_FACTORY_HEADER, outboundMessageFactory);
}
Also used : Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) URI(java.net.URI)

Example 9 with Connection

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

the class DeactivateNeedMessageFromSystemReactionProcessor 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 10 with Connection

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

the class HintMessageProcessor method process.

public void process(Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    logger.debug("STORING message with id {}", wonMessage.getMessageURI());
    URI needURIFromWonMessage = wonMessage.getReceiverNeedURI();
    URI wonNodeFromWonMessage = wonMessage.getReceiverNodeURI();
    URI otherNeedURIFromWonMessage = URI.create(RdfUtils.findOnePropertyFromResource(wonMessage.getMessageContent(), wonMessage.getMessageURI(), WON.HAS_MATCH_COUNTERPART).asResource().getURI());
    double wmScore = RdfUtils.findOnePropertyFromResource(wonMessage.getMessageContent(), wonMessage.getMessageURI(), WON.HAS_MATCH_SCORE).asLiteral().getDouble();
    URI wmOriginator = wonMessage.getSenderNodeURI();
    if (wmScore < 0 || wmScore > 1)
        throw new IllegalArgumentException("score is not in [0,1]");
    if (wmOriginator == null)
        throw new IllegalArgumentException("originator is not set");
    URI facet = WonRdfUtils.FacetUtils.getFacet(wonMessage);
    if (facet == null) {
        // get the first one of the need's supported facets. TODO: implement some sort of strategy for choosing a facet here (and in the matcher)
        Collection<URI> facets = dataService.getSupportedFacets(needURIFromWonMessage);
        if (facets.isEmpty())
            throw new IllegalArgumentException("hint does not specify facets, falling back to using one of the need's supported facets failed as the need does not support any facets");
        // add the facet to the model.
        facet = facets.iterator().next();
    }
    // create Connection in Database
    Connection con = connectionRepository.findOneByNeedURIAndRemoteNeedURIAndTypeURIForUpdate(needURIFromWonMessage, otherNeedURIFromWonMessage, facet);
    if (con == null) {
        URI connectionUri = wonNodeInformationService.generateConnectionURI(wonNodeFromWonMessage);
        con = dataService.createConnection(connectionUri, needURIFromWonMessage, otherNeedURIFromWonMessage, null, facet, ConnectionState.SUGGESTED, ConnectionEventType.MATCHER_HINT);
    }
    // build message to send to owner, put in header
    // 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) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) 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