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