use of won.protocol.model.MessageEventPlaceholder in project webofneeds by researchstudio-sat.
the class LinkedDataServiceImpl method listConnectionEventURIs.
@Override
@Transactional
public Dataset listConnectionEventURIs(final URI connectionUri, boolean deep) throws NoSuchConnectionException {
Model model = ModelFactory.createDefaultModel();
setNsPrefixes(model);
Connection connection = needInformationService.readConnection(connectionUri);
Resource eventContainer = model.createResource(connection.getConnectionURI().toString() + "/events", WON.EVENT_CONTAINER);
// add the events with the new format (only the URI, no content)
List<MessageEventPlaceholder> connectionEvents = messageEventRepository.findByParentURI(connectionUri);
Dataset eventsContainerDataset = newDatasetWithNamedModel(createDataGraphUriFromResource(eventContainer), model);
addBaseUriAndDefaultPrefixes(eventsContainerDataset);
for (MessageEventPlaceholder event : connectionEvents) {
model.add(model.createStatement(eventContainer, RDFS.member, model.getResource(event.getMessageURI().toString())));
if (deep) {
Dataset eventDataset = event.getDatasetHolder().getDataset();
RdfUtils.addDatasetToDataset(eventsContainerDataset, eventDataset);
}
}
return eventsContainerDataset;
}
use of won.protocol.model.MessageEventPlaceholder in project webofneeds by researchstudio-sat.
the class LinkedDataServiceImpl method eventsToContainerPage.
/**
* Returns a container resource with the messageUris of all MessageEventPlaceholder objects in the slice.
* If deep == true, the event datasets are added, too.
* @param containerUri
* @param slice
* @param deep
* @return
*/
private NeedInformationService.PagedResource<Dataset, URI> eventsToContainerPage(String containerUri, Slice<MessageEventPlaceholder> slice, boolean deep) {
List<MessageEventPlaceholder> events = slice.getContent();
URI resumeBefore = null;
URI resumeAfter = null;
if (slice.getSort() != null && !events.isEmpty()) {
Iterator<Sort.Order> sortOrders = slice.getSort().iterator();
if (sortOrders.hasNext()) {
Sort.Order sortOrder = sortOrders.next();
if (sortOrder.getDirection() == Sort.Direction.ASC) {
resumeBefore = events.get(0).getMessageURI();
resumeAfter = events.get(events.size() - 1).getMessageURI();
} else {
resumeBefore = events.get(events.size() - 1).getMessageURI();
resumeAfter = events.get(0).getMessageURI();
}
}
}
Model model = ModelFactory.createDefaultModel();
setNsPrefixes(model);
Resource needListPageResource = null;
needListPageResource = model.createResource(containerUri);
DatasetHolderAggregator aggregator = new DatasetHolderAggregator();
for (MessageEventPlaceholder event : events) {
model.add(model.createStatement(needListPageResource, RDFS.member, model.createResource(event.getMessageURI().toString())));
if (deep) {
aggregator.appendDataset(event.getDatasetHolder());
}
}
Dataset dataset = aggregator.aggregate();
dataset.addNamedModel(createDataGraphUriFromResource(needListPageResource), model);
addBaseUriAndDefaultPrefixes(dataset);
NeedInformationService.PagedResource<Dataset, URI> containerPage = new NeedInformationService.PagedResource(dataset, resumeBefore, resumeAfter);
return containerPage;
}
use of won.protocol.model.MessageEventPlaceholder in project webofneeds by researchstudio-sat.
the class MessageReferencer method updateReferenced.
private void updateReferenced(List<MessageAndPlaceholder> selected) {
selected.stream().forEach((MessageAndPlaceholder m) -> {
MessageEventPlaceholder messageEventPlaceholder = m.getMessageEventPlaceholder();
messageEventPlaceholder.setReferencedByOtherMessage(true);
messageEventRepository.save(messageEventPlaceholder);
});
}
use of won.protocol.model.MessageEventPlaceholder in project webofneeds by researchstudio-sat.
the class MessageReferencer method selectLatestMessage.
/**
* Selects the latest
*
* @param selectedUris
* @param message
*/
private void selectLatestMessage(Set<MessageUriAndParentUri> selectedUris, WonMessage message) {
// initialize a variable for the result
WonMessageType messageType = message.getMessageType();
switch(messageType) {
case SUCCESS_RESPONSE:
case FAILURE_RESPONSE:
// the current message is a response message. We want to reference the message we are responding to.
// we find identify the message with the same parent as our current message and add it
URI isResponseToURI = WonMessageUtils.getLocalIsResponseToURI(message);
MessageEventPlaceholder messageEventPlaceholder = messageEventRepository.findOneByMessageURI(isResponseToURI);
String methodName = "selectLatestMessage::response";
if (messageEventPlaceholder != null) {
selectedUris.add(new MessageUriAndParentUri(messageEventPlaceholder.getMessageURI(), messageEventPlaceholder.getParentURI()));
}
break;
case CREATE_NEED:
// a create message does not reference any other message. It is the root of the message structure
break;
default:
// any other message: reference the latest message in the parent (i.e. the container of the message)
// if we don't find any: reference the create message of the need.
URI parentUri = WonMessageUtils.getParentEntityUri(message);
messageEventPlaceholder = messageEventRepository.findNewestByParentURI(parentUri);
if (messageEventPlaceholder != null) {
selectedUris.add(new MessageUriAndParentUri(messageEventPlaceholder.getMessageURI(), messageEventPlaceholder.getParentURI()));
} else {
// we did not find any message to link to. Choose the create message of the need
// we're starting a conversation, link to the create message of the need.
URI parentNeedUri = WonMessageUtils.getParentNeedUri(message);
List<MessageEventPlaceholder> eventsToSelect = messageEventRepository.findByParentURIAndMessageType(parentNeedUri, WonMessageType.CREATE_NEED);
selectedUris.addAll(eventsToSelect.stream().map(p -> (new MessageUriAndParentUri(p.getMessageURI(), p.getParentURI()))).collect(Collectors.toList()));
}
}
}
Aggregations