Search in sources :

Example 11 with Need

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

the class LinkedDataServiceImpl method getNeedDataset.

@Override
@Transactional
public Dataset getNeedDataset(final URI needUri, boolean deep, Integer deepLayerSize) throws NoSuchNeedException, NoSuchConnectionException, NoSuchMessageException {
    Dataset dataset = getNeedDataset(needUri, null).getData();
    if (deep) {
        Need need = needInformationService.readNeed(needUri);
        if (need.getState() == NeedState.ACTIVE) {
            // only add deep data if need is active
            Slice<URI> slice = needInformationService.listConnectionURIs(needUri, 1, deepLayerSize, null, null);
            NeedInformationService.PagedResource<Dataset, URI> connectionsResource = toContainerPage(this.uriService.createConnectionsURIForNeed(needUri).toString(), slice);
            addDeepConnectionData(connectionsResource.getContent(), slice.getContent());
            RdfUtils.addDatasetToDataset(dataset, connectionsResource.getContent());
            for (URI connectionUri : slice.getContent()) {
                NeedInformationService.PagedResource<Dataset, URI> eventsResource = listConnectionEventURIs(connectionUri, 1, deepLayerSize, null, true);
                RdfUtils.addDatasetToDataset(dataset, eventsResource.getContent());
            }
        }
    }
    return dataset;
}
Also used : NeedInformationService(won.protocol.service.NeedInformationService) UnreadMessageInfoForNeed(won.protocol.model.unread.UnreadMessageInfoForNeed) Need(won.protocol.model.Need) Dataset(org.apache.jena.query.Dataset) URI(java.net.URI) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with Need

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

the class CommentFacet method addDataManagedByFacet.

private void addDataManagedByFacet(final Connection con) {
    Need need = needRepository.findOneByNeedURI(con.getNeedURI());
    Dataset needContent = need.getDatatsetHolder().getDataset();
    Model facetManagedGraph = getFacetManagedGraph(con.getNeedURI(), needContent);
    List<URI> properties = new ArrayList<>();
    PrefixMapping prefixMapping = PrefixMapping.Factory.create();
    // prefixMapping.setNsPrefix(SIOC.getURI(),"sioc");
    facetManagedGraph.withDefaultMappings(prefixMapping);
    facetManagedGraph.setNsPrefix("sioc", SIOC.getURI());
    Resource post = facetManagedGraph.createResource(con.getNeedURI().toString(), SIOC.POST);
    Resource reply = facetManagedGraph.createResource(con.getRemoteNeedURI().toString(), SIOC.POST);
    facetManagedGraph.add(facetManagedGraph.createStatement(facetManagedGraph.getResource(con.getNeedURI().toString()), SIOC.HAS_REPLY, facetManagedGraph.getResource(con.getRemoteNeedURI().toString())));
    // add WON node link
    logger.debug("linked data:" + RdfUtils.toString(facetManagedGraph));
    need.getDatatsetHolder().setDataset(needContent);
    needRepository.save(need);
}
Also used : Need(won.protocol.model.Need) PrefixMapping(org.apache.jena.shared.PrefixMapping) Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) ArrayList(java.util.ArrayList) Resource(org.apache.jena.rdf.model.Resource) URI(java.net.URI)

Example 13 with Need

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

the class NeedManagementService method sendTextMessageToOwner.

public void sendTextMessageToOwner(URI needURI, String message) {
    if (needURI == null) {
        logger.warn("sendTextMessageToOwner called but needUri is null - doing nothing");
        return;
    }
    if (message == null || message.trim().length() == 0) {
        logger.warn("sendTextMessageToOwner called for need {}, but message is null or empty - doing nothing");
        return;
    }
    logger.debug("Sending FromSystem text message to need {}", needURI);
    // check if we have that need (e.g. it's not a need living on another node, or does not exist at all)
    Need need = needRepository.findOneByNeedURI(needURI);
    if (need == null) {
        logger.debug("deactivateNeed called for need {} but that need was not found in the repository - doing nothing");
        return;
    }
    URI wonNodeURI = wonNodeInformationService.getWonNodeUri(needURI);
    if (wonNodeURI == null) {
        logger.debug("deactivateNeed called for need {} but we could not find a WonNodeURI for that need - doing nothing");
        return;
    }
    URI messageURI = wonNodeInformationService.generateEventURI(wonNodeURI);
    WonMessageBuilder builder = WonMessageBuilder.setMessagePropertiesForNeedMessageFromSystem(messageURI, needURI, wonNodeURI);
    builder.setTextMessage(message);
    sendSystemMessage(builder.build());
}
Also used : Need(won.protocol.model.Need) WonMessageBuilder(won.protocol.message.WonMessageBuilder) URI(java.net.URI)

Example 14 with Need

use of won.protocol.model.Need 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);
    }
}
Also used : WonMessageProcessingException(won.protocol.message.processor.exception.WonMessageProcessingException) Need(won.protocol.model.Need) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) URI(java.net.URI)

Example 15 with Need

use of won.protocol.model.Need 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);
}
Also used : WonMessageProcessingException(won.protocol.message.processor.exception.WonMessageProcessingException) Need(won.protocol.model.Need) WonMessage(won.protocol.message.WonMessage) URI(java.net.URI)

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