Search in sources :

Example 6 with Need

use of won.protocol.model.Need in project webofneeds by researchstudio-sat.

the class OwnerProtocolCommunicationServiceImpl method getWonNodeUriWithConnectionUri.

@Override
public synchronized URI getWonNodeUriWithConnectionUri(URI connectionUri) throws NoSuchConnectionException {
    // TODO: make this more efficient
    Connection con = DataAccessUtils.loadConnection(connectionRepository, connectionUri);
    URI needURI = con.getNeedURI();
    Need need = needRepository.findByNeedURI(needURI).get(0);
    return need.getWonNodeURI();
}
Also used : Need(won.protocol.model.Need) Connection(won.protocol.model.Connection) URI(java.net.URI)

Example 7 with Need

use of won.protocol.model.Need in project webofneeds by researchstudio-sat.

the class ActivateNeedMessageProcessor method process.

public void process(Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    URI receiverNeedURI = wonMessage.getReceiverNeedURI();
    logger.debug("ACTIVATING need. needURI:{}", receiverNeedURI);
    if (receiverNeedURI == null)
        throw new IllegalArgumentException("receiverNeedURI is not set");
    Need need = DataAccessUtils.loadNeed(needRepository, receiverNeedURI);
    need.getEventContainer().getEvents().add(messageEventRepository.findOneByMessageURIforUpdate(wonMessage.getMessageURI()));
    need.setState(NeedState.ACTIVE);
    logger.debug("Setting Need State: " + need.getState());
    needRepository.save(need);
}
Also used : Need(won.protocol.model.Need) Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) WonMessage(won.protocol.message.WonMessage) URI(java.net.URI)

Example 8 with Need

use of won.protocol.model.Need in project webofneeds by researchstudio-sat.

the class CommentFacet method removeDataManagedByFacet.

private void removeDataManagedByFacet(final Connection con) {
    Need need = needRepository.findOneByNeedURI(con.getNeedURI());
    Dataset needContent = need.getDatatsetHolder().getDataset();
    removeFacetManagedGraph(con.getNeedURI(), needContent);
    need.getDatatsetHolder().setDataset(needContent);
    needRepository.save(need);
}
Also used : Need(won.protocol.model.Need) Dataset(org.apache.jena.query.Dataset)

Example 9 with Need

use of won.protocol.model.Need 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 10 with Need

use of won.protocol.model.Need in project webofneeds by researchstudio-sat.

the class AbstractCamelProcessor method sendMessageToOwner.

protected void sendMessageToOwner(WonMessage message, URI needURI, String fallbackOwnerApplicationId) {
    Need need = needRepository.findOneByNeedURI(needURI);
    List<OwnerApplication> ownerApplications = need != null ? need.getAuthorizedApplications() : Collections.EMPTY_LIST;
    List<String> ownerApplicationIds = toStringIds(ownerApplications);
    // if no owner application ids are authorized, we use the fallback specified (if any)
    if (ownerApplicationIds.isEmpty() && fallbackOwnerApplicationId != null) {
        ownerApplicationIds.add(fallbackOwnerApplicationId);
    }
    Map headerMap = new HashMap<String, Object>();
    headerMap.put(WonCamelConstants.OWNER_APPLICATIONS, ownerApplicationIds);
    messagingService.sendInOnlyMessage(null, headerMap, RdfUtils.writeDatasetToString(message.getCompleteDataset(), WonCamelConstants.RDF_LANGUAGE_FOR_MESSAGE), "seda:OwnerProtocolOut");
}
Also used : Need(won.protocol.model.Need) OwnerApplication(won.protocol.model.OwnerApplication)

Aggregations

Need (won.protocol.model.Need)17 URI (java.net.URI)13 WonMessage (won.protocol.message.WonMessage)7 Dataset (org.apache.jena.query.Dataset)5 Message (org.apache.camel.Message)3 Model (org.apache.jena.rdf.model.Model)3 Resource (org.apache.jena.rdf.model.Resource)3 NoSuchNeedException (won.protocol.exception.NoSuchNeedException)3 WonMessageProcessingException (won.protocol.message.processor.exception.WonMessageProcessingException)3 Connection (won.protocol.model.Connection)3 PrefixMapping (org.apache.jena.shared.PrefixMapping)2 Transactional (org.springframework.transaction.annotation.Transactional)2 WonMessageBuilder (won.protocol.message.WonMessageBuilder)2 MissingMessagePropertyException (won.protocol.message.processor.exception.MissingMessagePropertyException)2 UnreadMessageInfoForNeed (won.protocol.model.unread.UnreadMessageInfoForNeed)2 ArrayList (java.util.ArrayList)1 ConnectionAlreadyExistsException (won.protocol.exception.ConnectionAlreadyExistsException)1 IllegalMessageForNeedStateException (won.protocol.exception.IllegalMessageForNeedStateException)1 UriAlreadyInUseException (won.protocol.message.processor.exception.UriAlreadyInUseException)1 DataWithEtag (won.protocol.model.DataWithEtag)1