Search in sources :

Example 21 with WonMessage

use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.

the class CreateNeedMessageReactionProcessor method process.

@Override
public void process(final Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    Dataset needContent = wonMessage.getMessageContent();
    URI needUri = getNeedURIFromWonMessage(needContent);
    if (needUri == null) {
        logger.warn("could not obtain needURI from message " + wonMessage.getMessageURI());
        return;
    }
    Need need = needRepository.findOneByNeedURI(needUri);
    try {
        WonMessage newNeedNotificationMessage = makeNeedCreatedMessageForMatcher(need);
        matcherProtocolMatcherClient.needCreated(needUri, ModelFactory.createDefaultModel(), newNeedNotificationMessage);
    } catch (Exception e) {
        logger.warn("could not create NeedCreatedNotification", e);
    }
}
Also used : Need(won.protocol.model.Need) Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) Dataset(org.apache.jena.query.Dataset) WonMessage(won.protocol.message.WonMessage) URI(java.net.URI) NoSuchNeedException(won.protocol.exception.NoSuchNeedException)

Example 22 with WonMessage

use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.

the class DeactivateMessageFromSystemProcessor method process.

@Override
public void process(Exchange exchange) throws Exception {
    WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
    URI receiverNeedURI = wonMessage.getReceiverNeedURI();
    URI senderNeedURI = wonMessage.getSenderNeedURI();
    if (receiverNeedURI == null) {
        throw new MissingMessagePropertyException(URI.create(WONMSG.RECEIVER_NEED_PROPERTY.toString()));
    }
    if (senderNeedURI == null) {
        throw new MissingMessagePropertyException(URI.create(WONMSG.SENDER_NEED_PROPERTY.toString()));
    }
    if (!receiverNeedURI.equals(senderNeedURI)) {
        throw new IllegalArgumentException("sender need uri " + senderNeedURI + " does not equal receiver need uri " + receiverNeedURI);
    }
    logger.debug("DEACTIVATING need. needURI:{}", receiverNeedURI);
    Need need = DataAccessUtils.loadNeed(needRepository, receiverNeedURI);
    need.getEventContainer().getEvents().add(messageEventRepository.findOneByMessageURIforUpdate(wonMessage.getMessageURI()));
    need.setState(NeedState.INACTIVE);
    need = needRepository.save(need);
}
Also used : Need(won.protocol.model.Need) MissingMessagePropertyException(won.protocol.message.processor.exception.MissingMessagePropertyException) WonMessage(won.protocol.message.WonMessage) URI(java.net.URI)

Example 23 with WonMessage

use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.

the class DeactivateNeedMessageFromOwnerReactionProcessor method closeConnection.

public void closeConnection(final Need need, final Connection con) {
    // send close from system to each connection
    // the close message is directed at our local connection. It will
    // be routed to the owner and forwarded to to remote connection
    URI messageURI = wonNodeInformationService.generateEventURI();
    WonMessage message = WonMessageBuilder.setMessagePropertiesForClose(messageURI, WonMessageDirection.FROM_SYSTEM, con.getConnectionURI(), con.getNeedURI(), need.getWonNodeURI(), con.getConnectionURI(), con.getNeedURI(), need.getWonNodeURI(), "Closed because Need was deactivated").build();
    sendSystemMessage(message);
}
Also used : WonMessage(won.protocol.message.WonMessage) URI(java.net.URI)

Example 24 with WonMessage

use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.

the class DeactivateNeedMessageFromSystemReactionProcessor method closeConnection.

public void closeConnection(final Need need, final Connection con) {
    // send close from system to each connection
    // the close message is directed at our local connection. It will
    // be routed to the owner and forwarded to to remote connection
    URI messageURI = wonNodeInformationService.generateEventURI();
    WonMessage message = WonMessageBuilder.setMessagePropertiesForClose(messageURI, WonMessageDirection.FROM_SYSTEM, con.getConnectionURI(), con.getNeedURI(), need.getWonNodeURI(), con.getConnectionURI(), con.getNeedURI(), need.getWonNodeURI(), "Closed because Need was deactivated").build();
    sendSystemMessage(message);
}
Also used : WonMessage(won.protocol.message.WonMessage) URI(java.net.URI)

Example 25 with WonMessage

use of won.protocol.message.WonMessage 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)

Aggregations

WonMessage (won.protocol.message.WonMessage)89 URI (java.net.URI)47 Connection (won.protocol.model.Connection)19 Test (org.junit.Test)18 Message (org.apache.camel.Message)17 Dataset (org.apache.jena.query.Dataset)17 Exchange (org.apache.camel.Exchange)13 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)13 DefaultExchange (org.apache.camel.impl.DefaultExchange)13 WonMessageProcessingException (won.protocol.message.processor.exception.WonMessageProcessingException)11 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)10 MissingMessagePropertyException (won.protocol.message.processor.exception.MissingMessagePropertyException)9 Event (won.bot.framework.eventbot.event.Event)8 FailureResponseEvent (won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent)8 EventListener (won.bot.framework.eventbot.listener.EventListener)7 Need (won.protocol.model.Need)7 WonNodeInformationService (won.protocol.service.WonNodeInformationService)7 Model (org.apache.jena.rdf.model.Model)5 WonURI (won.bot.framework.eventbot.action.impl.mail.model.WonURI)5 DefaultNeedModelWrapper (won.protocol.util.DefaultNeedModelWrapper)4