use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class ConnectMessageFromNodeProcessor method process.
public void process(final Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
// a need wants to connect.
// get the required data from the message and create a connection
URI needUri = wonMessage.getReceiverNeedURI();
URI wonNodeUriFromWonMessage = wonMessage.getReceiverNodeURI();
URI remoteNeedUri = wonMessage.getSenderNeedURI();
URI remoteConnectionUri = wonMessage.getSenderURI();
URI facetURI = WonRdfUtils.FacetUtils.getFacet(wonMessage);
// if the uri is known already, we can load the connection!
URI connectionURI = wonMessage.getReceiverURI();
if (remoteConnectionUri == null)
throw new MissingMessagePropertyException(URI.create(WONMSG.SENDER_PROPERTY.getURI().toString()));
Connection con = null;
if (connectionURI != null) {
con = connectionRepository.findOneByConnectionURIForUpdate(connectionURI);
if (con == null)
throw new NoSuchConnectionException(connectionURI);
} else {
con = connectionRepository.findOneByNeedURIAndRemoteNeedURIAndTypeURIForUpdate(needUri, remoteNeedUri, facetURI);
}
if (con == null) {
// create Connection in Database
URI connectionUri = wonNodeInformationService.generateConnectionURI(wonNodeUriFromWonMessage);
con = dataService.createConnection(connectionUri, needUri, remoteNeedUri, remoteConnectionUri, facetURI, ConnectionState.REQUEST_RECEIVED, ConnectionEventType.PARTNER_OPEN);
}
con.setRemoteConnectionURI(remoteConnectionUri);
con.setState(con.getState().transit(ConnectionEventType.PARTNER_OPEN));
connectionRepository.save(con);
// set the receiver to the newly generated connection uri
wonMessage.addMessageProperty(WONMSG.RECEIVER_PROPERTY, con.getConnectionURI());
}
use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class DeactivateNeedMessageFromOwnerReactionProcessor 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.Connection in project webofneeds by researchstudio-sat.
the class HintFeedbackMessageFromOwnerProcessor method process.
public void process(final Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
Connection con = connectionRepository.findOneByConnectionURIForUpdate(wonMessage.getSenderURI());
logger.debug("HINT_FEEDBACK received from the owner side for connection {}", wonMessage.getSenderURI());
processFeedbackMessage(con, wonMessage);
}
use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class OpenMessageFromOwnerProcessor method process.
public void process(final Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
logger.debug("OPEN received from the owner side for connection {}", wonMessage.getSenderURI());
Connection con = dataService.nextConnectionState(wonMessage.getSenderURI(), ConnectionEventType.OWNER_OPEN);
Objects.requireNonNull(con);
Objects.requireNonNull(con.getRemoteNeedURI());
if (!con.getRemoteNeedURI().equals(wonMessage.getReceiverNeedURI()))
throw new IllegalStateException("remote need uri must be equal to receiver need uri");
if (con.getConnectionURI() == null)
throw new IllegalStateException("connection uri must not be null");
if (!con.getConnectionURI().equals(wonMessage.getSenderURI()))
throw new IllegalStateException("connection uri must be equal to sender uri");
if (wonMessage.getReceiverURI() != null) {
if (!wonMessage.getReceiverURI().equals(con.getRemoteConnectionURI()))
throw new IllegalStateException("remote connection uri must be equal to receiver uri");
if (con.getRemoteConnectionURI() == null) {
// we didn't have it before, now we do:
con.setRemoteConnectionURI(wonMessage.getReceiverURI());
}
} else {
// do nothing. it's not clean, but easier to implement on the client side
// TODO: refactor connection state and open/connect
}
con.setState(con.getState().transit(ConnectionEventType.OWNER_OPEN));
connectionRepository.save(con);
URI remoteMessageUri = wonNodeInformationService.generateEventURI(wonMessage.getReceiverNodeURI());
// add the information about the corresponding message to the local one
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);
exchange.getIn().setHeader(WonCamelConstants.OUTBOUND_MESSAGE_FACTORY_HEADER, outboundMessageFactory);
}
use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class SendMessageFromNodeProcessor method process.
public void process(final Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
URI connectionUri = wonMessage.getReceiverURI();
if (connectionUri == null) {
throw new MissingMessagePropertyException(URI.create(WONMSG.RECEIVER_PROPERTY.toString()));
}
Connection con = connectionRepository.findOneByConnectionURIForUpdate(connectionUri);
if (con.getState() != ConnectionState.CONNECTED) {
throw new IllegalMessageForConnectionStateException(connectionUri, "CONNECTION_MESSAGE", con.getState());
}
}
Aggregations