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);
}
}
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);
}
}
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);
}
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());
}
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);
}
Aggregations