use of won.protocol.message.WonMessage 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.message.WonMessage in project webofneeds by researchstudio-sat.
the class CreateNeedMessageProcessor method storeNeed.
private Need storeNeed(final WonMessage wonMessage) {
Dataset needContent = wonMessage.getMessageContent();
List<WonMessage.AttachmentHolder> attachmentHolders = wonMessage.getAttachments();
// remove attachment and its signature from the needContent
removeAttachmentsFromNeedContent(needContent, attachmentHolders);
URI needURI = getNeedURIFromWonMessage(needContent);
if (!needURI.equals(wonMessage.getSenderNeedURI()))
throw new IllegalArgumentException("receiverNeedURI and NeedURI of the content are not equal");
Need need = new Need();
need.setState(NeedState.ACTIVE);
need.setNeedURI(needURI);
// ToDo (FS) check if the WON node URI corresponds with the WON node (maybe earlier in the message layer)
NeedEventContainer needEventContainer = needEventContainerRepository.findOneByParentUri(needURI);
if (needEventContainer == null) {
needEventContainer = new NeedEventContainer(need, need.getNeedURI());
} else {
throw new UriAlreadyInUseException("Found a NeedEventContainer for the need we're about to create (" + needURI + ") - aborting");
}
need.setWonNodeURI(wonMessage.getReceiverNodeURI());
ConnectionContainer connectionContainer = new ConnectionContainer(need);
need.setConnectionContainer(connectionContainer);
need.setEventContainer(needEventContainer);
// store the need content
DatasetHolder datasetHolder = new DatasetHolder(needURI, needContent);
// store attachments
List<DatasetHolder> attachments = new ArrayList<>(attachmentHolders.size());
for (WonMessage.AttachmentHolder attachmentHolder : attachmentHolders) {
datasetHolder = new DatasetHolder(attachmentHolder.getDestinationUri(), attachmentHolder.getAttachmentDataset());
attachments.add(datasetHolder);
}
// add everything to the need model class and save it
need.setDatatsetHolder(datasetHolder);
need.setAttachmentDatasetHolders(attachments);
need = needRepository.save(need);
connectionContainerRepository.save(connectionContainer);
NeedModelWrapper needModelWrapper = new NeedModelWrapper(needContent);
Collection<String> facets = needModelWrapper.getFacetUris();
if (facets.size() == 0)
throw new IllegalArgumentException("at least one property won:hasFacet required ");
for (String facetUri : facets) {
// TODO: check if there is a implementation for the facet on the node
Facet f = new Facet();
f.setNeedURI(needURI);
f.setTypeURI(URI.create(facetUri));
facetRepository.save(f);
}
return need;
}
use of won.protocol.message.WonMessage 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.message.WonMessage in project webofneeds by researchstudio-sat.
the class DeactivateNeedMessageProcessor 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);
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 FailureResponseFromSystemToNodeProcessor method process.
@Override
public void process(Exchange exchange) throws Exception {
WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
// prepare the message to pass to the remote node
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);
exchange.getIn().setHeader(WonCamelConstants.OUTBOUND_MESSAGE_FACTORY_HEADER, outboundMessageFactory);
}
Aggregations