Search in sources :

Example 1 with Need

use of won.protocol.model.Need 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 2 with Need

use of won.protocol.model.Need 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 3 with Need

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

the class NeedMessageFromSystemProcessor method process.

@Override
public void process(Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.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);
    }
    Need need = needRepository.findOneByNeedURI(senderNeedURI);
    if (need == null) {
        throw new IllegalArgumentException("need not found - cannot send need message to: " + senderNeedURI);
    }
    need.getEventContainer().getEvents().add(messageEventRepository.findOneByMessageURIforUpdate(wonMessage.getMessageURI()));
    need = needRepository.save(need);
}
Also used : Need(won.protocol.model.Need) Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) MissingMessagePropertyException(won.protocol.message.processor.exception.MissingMessagePropertyException) WonMessage(won.protocol.message.WonMessage) URI(java.net.URI)

Example 4 with Need

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

the class NeedManagementService method deactivateNeed.

public void deactivateNeed(URI needURI, String optionalMessage) {
    if (needURI == null) {
        logger.warn("deactivateNeed called but needUri is null - doing nothing");
        return;
    }
    logger.debug("Deactivating need {}", needURI);
    // check if we have that need (e.g. it's not a need living on another node, or does not exist at all)
    Need need = needRepository.findOneByNeedURI(needURI);
    if (need == null) {
        logger.debug("deactivateNeed called for need {} but that need was not found in the repository - doing nothing");
        return;
    }
    URI wonNodeURI = wonNodeInformationService.getWonNodeUri(needURI);
    if (wonNodeURI == null) {
        logger.debug("deactivateNeed called for need {} but we could not find a WonNodeURI for that need - doing nothing");
        return;
    }
    URI messageURI = wonNodeInformationService.generateEventURI(wonNodeURI);
    WonMessageBuilder builder = WonMessageBuilder.setMessagePropertiesForDeactivateFromSystem(messageURI, needURI, wonNodeURI);
    if (optionalMessage != null && optionalMessage.trim().length() > 0) {
        builder.setTextMessage(optionalMessage);
    }
    sendSystemMessage(builder.build());
}
Also used : Need(won.protocol.model.Need) WonMessageBuilder(won.protocol.message.WonMessageBuilder) URI(java.net.URI)

Example 5 with Need

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

the class ActivateNeedMessageProcessor method process.

public void process(Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    URI receiverNeedURI = wonMessage.getReceiverNeedURI();
    logger.debug("ACTIVATING need. needURI:{}", receiverNeedURI);
    if (receiverNeedURI == null)
        throw new IllegalArgumentException("receiverNeedURI is not set");
    Need need = DataAccessUtils.loadNeed(needRepository, receiverNeedURI);
    need.getEventContainer().getEvents().add(messageEventRepository.findOneByMessageURIforUpdate(wonMessage.getMessageURI()));
    need.setState(NeedState.ACTIVE);
    logger.debug("Setting Need State: " + need.getState());
    needRepository.save(need);
}
Also used : Need(won.protocol.model.Need) Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) WonMessage(won.protocol.message.WonMessage) URI(java.net.URI)

Aggregations

Need (won.protocol.model.Need)15 URI (java.net.URI)11 WonMessage (won.protocol.message.WonMessage)6 Dataset (org.apache.jena.query.Dataset)5 Message (org.apache.camel.Message)3 Model (org.apache.jena.rdf.model.Model)3 Resource (org.apache.jena.rdf.model.Resource)3 NoSuchNeedException (won.protocol.exception.NoSuchNeedException)3 WonMessageProcessingException (won.protocol.message.processor.exception.WonMessageProcessingException)3 PrefixMapping (org.apache.jena.shared.PrefixMapping)2 Transactional (org.springframework.transaction.annotation.Transactional)2 WonMessageBuilder (won.protocol.message.WonMessageBuilder)2 Connection (won.protocol.model.Connection)2 UnreadMessageInfoForNeed (won.protocol.model.unread.UnreadMessageInfoForNeed)2 ArrayList (java.util.ArrayList)1 ConnectionAlreadyExistsException (won.protocol.exception.ConnectionAlreadyExistsException)1 IllegalMessageForNeedStateException (won.protocol.exception.IllegalMessageForNeedStateException)1 MissingMessagePropertyException (won.protocol.message.processor.exception.MissingMessagePropertyException)1 UriAlreadyInUseException (won.protocol.message.processor.exception.UriAlreadyInUseException)1 DataWithEtag (won.protocol.model.DataWithEtag)1