Search in sources :

Example 1 with MessageEventPlaceholder

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()));
}
Also used : URI(java.net.URI) MessageEventPlaceholder(won.protocol.model.MessageEventPlaceholder)

Example 2 with MessageEventPlaceholder

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);
}
Also used : WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) MessageEventPlaceholder(won.protocol.model.MessageEventPlaceholder)

Example 3 with MessageEventPlaceholder

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);
    }
}
Also used : Dataset(org.apache.jena.query.Dataset) WonMessage(won.protocol.message.WonMessage) URI(java.net.URI) MessageEventPlaceholder(won.protocol.model.MessageEventPlaceholder)

Example 4 with MessageEventPlaceholder

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);
}
Also used : UnreadMessageInfoForNeed(won.protocol.model.unread.UnreadMessageInfoForNeed) Need(won.protocol.model.Need) Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) NoSuchNeedException(won.protocol.exception.NoSuchNeedException) DataWithEtag(won.protocol.model.DataWithEtag) MessageEventPlaceholder(won.protocol.model.MessageEventPlaceholder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with MessageEventPlaceholder

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);
}
Also used : DatasetHolder(won.protocol.model.DatasetHolder) PageRequest(org.springframework.data.domain.PageRequest) Dataset(org.apache.jena.query.Dataset) Connection(won.protocol.model.Connection) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Sort(org.springframework.data.domain.Sort) DataWithEtag(won.protocol.model.DataWithEtag) MessageEventPlaceholder(won.protocol.model.MessageEventPlaceholder) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

MessageEventPlaceholder (won.protocol.model.MessageEventPlaceholder)9 Dataset (org.apache.jena.query.Dataset)5 URI (java.net.URI)4 Model (org.apache.jena.rdf.model.Model)4 Resource (org.apache.jena.rdf.model.Resource)4 Transactional (org.springframework.transaction.annotation.Transactional)3 Connection (won.protocol.model.Connection)3 Sort (org.springframework.data.domain.Sort)2 WonMessage (won.protocol.message.WonMessage)2 DataWithEtag (won.protocol.model.DataWithEtag)2 PageRequest (org.springframework.data.domain.PageRequest)1 NoSuchNeedException (won.protocol.exception.NoSuchNeedException)1 DatasetHolder (won.protocol.model.DatasetHolder)1 DatasetHolderAggregator (won.protocol.model.DatasetHolderAggregator)1 Need (won.protocol.model.Need)1 UnreadMessageInfoForNeed (won.protocol.model.unread.UnreadMessageInfoForNeed)1 NeedInformationService (won.protocol.service.NeedInformationService)1