use of won.protocol.model.MessageEventPlaceholder in project webofneeds by researchstudio-sat.
the class MessageReferencer method selectUnreferenceMessages.
/**
* Selects all unreferenced messages for referencing
*/
private void selectUnreferenceMessages(Set<MessageUriAndParentUri> selectedUris, final WonMessage message) throws WonMessageProcessingException {
if (message.getMessageType() == WonMessageType.CREATE_NEED)
return;
URI parentUri = WonMessageUtils.getParentEntityUri(message);
// find all unreferenced messages for the current message's parent
List<MessageEventPlaceholder> messageEventPlaceholders = messageEventRepository.findByParentURIAndNotReferencedByOtherMessage(parentUri);
// load the WonMessages for the placeholders
selectedUris.addAll(messageEventPlaceholders.stream().map(p -> new MessageUriAndParentUri(p.getMessageURI(), p.getParentURI())).collect(Collectors.toList()));
}
use of won.protocol.model.MessageEventPlaceholder 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.MessageEventPlaceholder in project webofneeds by researchstudio-sat.
the class ResponseResenderProcessor method process.
@Override
public void process(final Exchange exchange) throws Exception {
WonMessage originalMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.ORIGINAL_MESSAGE_HEADER);
if (originalMessage == null) {
logger.debug("Processing an exception. camel header {} was null, assuming original message in header {}", WonCamelConstants.ORIGINAL_MESSAGE_HEADER, WonCamelConstants.MESSAGE_HEADER);
originalMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
}
if (originalMessage == null) {
logger.warn("Could not obtain original message from camel headers {} or {} for error {}", new Object[] { WonCamelConstants.ORIGINAL_MESSAGE_HEADER, WonCamelConstants.MESSAGE_HEADER, exchange.getProperty(Exchange.EXCEPTION_CAUGHT) });
return;
}
logger.warn("an error occurred while processing WON message {}", originalMessage.getMessageURI());
// get the event that was found to be already processed
MessageEventPlaceholder event = messageEventRepository.findOneByMessageURI(originalMessage.getMessageURI());
// get response to this event:
URI responseURI = event.getResponseMessageURI();
Dataset responseDataset = event.getDatasetHolder().getDataset();
WonMessage responseMessage = new WonMessage(responseDataset);
Exception e = (Exception) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
if (WonMessageDirection.FROM_OWNER == originalMessage.getEnvelopeType()) {
sendSystemMessageToOwner(responseMessage);
} else if (WonMessageDirection.FROM_EXTERNAL == originalMessage.getEnvelopeType()) {
sendSystemMessage(responseMessage);
} else {
logger.info(String.format("cannot resend response message for direction of original message, " + "expected FROM_OWNER or FROM_EXTERNAL, but found %s. Original cause is logged.", originalMessage.getEnvelopeType()), e);
}
}
use of won.protocol.model.MessageEventPlaceholder in project webofneeds by researchstudio-sat.
the class LinkedDataServiceImpl method getNeedDataset.
@Transactional
public DataWithEtag<Dataset> getNeedDataset(final URI needUri, String etag) {
DataWithEtag<Need> data = null;
try {
data = needInformationService.readNeed(needUri, etag);
} catch (NoSuchNeedException e) {
return DataWithEtag.dataNotFound();
}
if (data.isNotFound()) {
return DataWithEtag.dataNotFound();
}
if (!data.isChanged()) {
return DataWithEtag.dataNotChanged(data);
}
Need need = data.getData();
String newEtag = data.getEtag();
// load the dataset from storage
Dataset dataset = need.getDatatsetHolder().getDataset();
Model metaModel = needModelMapper.toModel(need);
Resource needResource = metaModel.getResource(needUri.toString());
// add connections
Resource connectionsContainer = metaModel.createResource(need.getNeedURI().toString() + "/connections");
metaModel.add(metaModel.createStatement(needResource, WON.HAS_CONNECTIONS, connectionsContainer));
// add need event container
Resource needEventContainer = metaModel.createResource(need.getNeedURI().toString() + "#events", WON.EVENT_CONTAINER);
metaModel.add(metaModel.createStatement(needResource, WON.HAS_EVENT_CONTAINER, needEventContainer));
// add need event URIs
Collection<MessageEventPlaceholder> messageEvents = need.getEventContainer().getEvents();
for (MessageEventPlaceholder messageEvent : messageEvents) {
metaModel.add(metaModel.createStatement(needEventContainer, RDFS.member, metaModel.getResource(messageEvent.getMessageURI().toString())));
}
// add WON node link
needResource.addProperty(WON.HAS_WON_NODE, metaModel.createResource(this.resourceURIPrefix));
// add meta model to dataset
String needMetaInformationURI = uriService.createNeedSysInfoGraphURI(needUri).toString();
dataset.addNamedModel(needMetaInformationURI, metaModel);
addBaseUriAndDefaultPrefixes(dataset);
return new DataWithEtag<>(dataset, newEtag, etag);
}
use of won.protocol.model.MessageEventPlaceholder in project webofneeds by researchstudio-sat.
the class LinkedDataServiceImpl method getConnectionDataset.
/**
* ETag-aware method for obtaining connection data. Currently does not take into account new events, only changes
* to the connection itself.
* @param connectionUri
* @param includeEventContainer
* @param includeLatestEvent
* @param etag
* @return
*/
@Override
@Transactional
public DataWithEtag<Dataset> getConnectionDataset(final URI connectionUri, final boolean includeEventContainer, final boolean includeLatestEvent, final String etag) {
DataWithEtag<Connection> data = null;
Connection connection = null;
data = needInformationService.readConnection(connectionUri, etag);
if (data.isNotFound()) {
return DataWithEtag.dataNotFound();
}
if (!data.isChanged()) {
return DataWithEtag.dataNotChanged(data);
}
connection = data.getData();
String newEtag = data.getEtag();
// load the model from storage
Model model = connectionModelMapper.toModel(connection);
Model additionalData = connection.getDatasetHolder() == null ? null : connection.getDatasetHolder().getDataset().getDefaultModel();
setNsPrefixes(model);
if (additionalData != null) {
model.add(additionalData);
}
// model.setNsPrefix("", connection.getConnectionURI().toString());
// create connection member
Resource connectionResource = model.getResource(connection.getConnectionURI().toString());
// add WON node link
connectionResource.addProperty(WON.HAS_WON_NODE, model.createResource(this.resourceURIPrefix));
Dataset eventDataset = null;
if (includeEventContainer) {
// create event container and attach it to the member
Resource eventContainer = model.createResource(connection.getConnectionURI().toString() + "/events");
connectionResource.addProperty(WON.HAS_EVENT_CONTAINER, eventContainer);
eventContainer.addProperty(RDF.type, WON.EVENT_CONTAINER);
if (includeLatestEvent) {
// we add the latest event in the connection
Slice<MessageEventPlaceholder> latestEvents = messageEventRepository.findByParentURIFetchDatasetEagerly(connectionUri, new PageRequest(0, 1, new Sort(Sort.Direction.DESC, "creationDate")));
if (latestEvents.hasContent()) {
MessageEventPlaceholder event = latestEvents.getContent().get(0);
// add the event's dataset
eventDataset = setDefaults(event.getDatasetHolder().getDataset());
// connect the event to its container
eventContainer.addProperty(RDFS.member, model.getResource(event.getMessageURI().toString()));
}
}
DatasetHolder datasetHolder = connection.getDatasetHolder();
if (datasetHolder != null) {
addAdditionalData(model, datasetHolder.getDataset().getDefaultModel(), connectionResource);
}
}
Dataset connectionDataset = addBaseUriAndDefaultPrefixes(newDatasetWithNamedModel(createDataGraphUriFromResource(connectionResource), model));
RdfUtils.addDatasetToDataset(connectionDataset, eventDataset);
return new DataWithEtag<>(connectionDataset, newEtag, etag);
}
Aggregations