use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class LockMessageParentWonMessageProcessor method lockParent.
private void lockParent(WonMessage message) {
// get the parent's URI (either a connection or a need
URI parentURI = WonMessageUtils.getParentEntityUri(message);
// try a connection:
Connection con = connectionRepository.findOneByConnectionURIForUpdate(parentURI);
if (con != null) {
connectionEventContainerRepository.findOneByParentUriForUpdate(parentURI);
} else {
needRepository.findOneByNeedURIForUpdate(parentURI);
needEventContainerRepository.findOneByParentUriForUpdate(parentURI);
}
}
use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class ConnectMessageFromOwnerProcessor method onSuccessResponse.
@Override
public void onSuccessResponse(final Exchange exchange) throws Exception {
WonMessage responseMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
MessageEventPlaceholder mep = this.messageEventRepository.findOneByCorrespondingRemoteMessageURI(responseMessage.getIsResponseToMessageURI());
// update the connection database: set the remote connection URI just obtained from the response
Connection con = this.connectionRepository.findOneByConnectionURIForUpdate(mep.getSenderURI());
con.setRemoteConnectionURI(responseMessage.getSenderURI());
this.connectionRepository.save(con);
}
use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class ConnectMessageFromOwnerProcessor method process.
public void process(final Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
URI senderNeedURI = wonMessage.getSenderNeedURI();
URI senderNodeURI = wonMessage.getSenderNodeURI();
URI receiverNeedURI = wonMessage.getReceiverNeedURI();
URI facetURI = WonRdfUtils.FacetUtils.getFacet(wonMessage);
// if the uri is known already, we can load the connection!
URI connectionURI = wonMessage.getSenderURI();
Connection con = null;
if (connectionURI != null) {
con = connectionRepository.findOneByConnectionURIForUpdate(connectionURI);
if (con == null)
throw new NoSuchConnectionException(connectionURI);
} else {
con = connectionRepository.findOneByNeedURIAndRemoteNeedURIAndTypeURIForUpdate(senderNeedURI, receiverNeedURI, facetURI);
}
if (con == null) {
// create Connection in Database
URI connectionUri = wonNodeInformationService.generateConnectionURI(senderNodeURI);
con = dataService.createConnection(connectionUri, senderNeedURI, receiverNeedURI, null, facetURI, ConnectionState.REQUEST_SENT, ConnectionEventType.OWNER_OPEN);
}
con.setState(con.getState().transit(ConnectionEventType.OWNER_OPEN));
connectionRepository.save(con);
// prepare the message to pass to the remote node
URI remoteMessageUri = wonNodeInformationService.generateEventURI(wonMessage.getReceiverNodeURI());
// set the sender uri in the envelope TODO: TwoMsgs: do not set sender here
wonMessage.addMessageProperty(WONMSG.SENDER_PROPERTY, con.getConnectionURI());
// add the information about the new local connection to the original message
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);
message.setHeader(WonCamelConstants.OUTBOUND_MESSAGE_FACTORY_HEADER, outboundMessageFactory);
}
use of won.protocol.model.Connection 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.Connection in project webofneeds by researchstudio-sat.
the class HintMessageProcessor method process.
public void process(Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
logger.debug("STORING message with id {}", wonMessage.getMessageURI());
URI needURIFromWonMessage = wonMessage.getReceiverNeedURI();
URI wonNodeFromWonMessage = wonMessage.getReceiverNodeURI();
URI otherNeedURIFromWonMessage = URI.create(RdfUtils.findOnePropertyFromResource(wonMessage.getMessageContent(), wonMessage.getMessageURI(), WON.HAS_MATCH_COUNTERPART).asResource().getURI());
double wmScore = RdfUtils.findOnePropertyFromResource(wonMessage.getMessageContent(), wonMessage.getMessageURI(), WON.HAS_MATCH_SCORE).asLiteral().getDouble();
URI wmOriginator = wonMessage.getSenderNodeURI();
if (wmScore < 0 || wmScore > 1)
throw new IllegalArgumentException("score is not in [0,1]");
if (wmOriginator == null)
throw new IllegalArgumentException("originator is not set");
URI facet = WonRdfUtils.FacetUtils.getFacet(wonMessage);
if (facet == null) {
// get the first one of the need's supported facets. TODO: implement some sort of strategy for choosing a facet here (and in the matcher)
Collection<URI> facets = dataService.getSupportedFacets(needURIFromWonMessage);
if (facets.isEmpty())
throw new IllegalArgumentException("hint does not specify facets, falling back to using one of the need's supported facets failed as the need does not support any facets");
// add the facet to the model.
facet = facets.iterator().next();
}
// create Connection in Database
Connection con = connectionRepository.findOneByNeedURIAndRemoteNeedURIAndTypeURIForUpdate(needURIFromWonMessage, otherNeedURIFromWonMessage, facet);
if (con == null) {
URI connectionUri = wonNodeInformationService.generateConnectionURI(wonNodeFromWonMessage);
con = dataService.createConnection(connectionUri, needURIFromWonMessage, otherNeedURIFromWonMessage, null, facet, ConnectionState.SUGGESTED, ConnectionEventType.MATCHER_HINT);
}
// build message to send to owner, put in header
// set the receiver to the newly generated connection uri
wonMessage.addMessageProperty(WONMSG.RECEIVER_PROPERTY, con.getConnectionURI());
}
Aggregations