Search in sources :

Example 16 with Need

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

the class UriAlreadyUsedCheckingWonMessageProcessor method checkNeedURI.

private void checkNeedURI(final WonMessage message) {
    if (message.getMessageType() == WonMessageType.CREATE_NEED) {
        URI needURI = WonRdfUtils.NeedUtils.getNeedURI(message.getCompleteDataset());
        Need need = needRepository.findOneByNeedURI(needURI);
        if (need == null) {
            return;
        } else {
            throw new UriAlreadyInUseException(message.getSenderNeedURI().toString());
        }
    }
    return;
}
Also used : Need(won.protocol.model.Need) UriAlreadyInUseException(won.protocol.message.processor.exception.UriAlreadyInUseException) URI(java.net.URI)

Example 17 with Need

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

the class CommentUnrestrictedFacet method connectFromNeed.

@Override
public void connectFromNeed(Connection con, Model content, WonMessage wonMessage) throws NoSuchNeedException, IllegalMessageForNeedStateException, ConnectionAlreadyExistsException {
    super.connectFromNeed(con, content, wonMessage);
    /* send a connect back */
    try {
        // TODO: use new system
        // needFacingConnectionClient.open(con, content, null);
        Need need = needRepository.findOneByNeedURI(con.getNeedURI());
        Model needContent = need.getDatatsetHolder().getDataset().getDefaultModel();
        PrefixMapping prefixMapping = PrefixMapping.Factory.create();
        // prefixMapping.setNsPrefix(SIOC.getURI(),"sioc");
        needContent.withDefaultMappings(prefixMapping);
        needContent.setNsPrefix("sioc", SIOC.getURI());
        Resource post = needContent.createResource(con.getNeedURI().toString(), SIOC.POST);
        Resource reply = needContent.createResource(con.getRemoteNeedURI().toString(), SIOC.POST);
        needContent.add(needContent.createStatement(needContent.getResource(con.getNeedURI().toString()), SIOC.HAS_REPLY, needContent.getResource(con.getRemoteNeedURI().toString())));
        // add WON node link
        logger.debug("linked data:" + RdfUtils.toString(needContent));
        need.getDatatsetHolder().getDataset().setDefaultModel(needContent);
        needRepository.save(need);
    // } catch (NoSuchConnectionException e) {
    // e.printStackTrace();
    // } catch (IllegalMessageForConnectionStateException e) {
    // e.printStackTrace();
    } catch (Exception e) {
        // To change body of catch statement use File | Settings | File Templates.
        e.printStackTrace();
    }
/* when connected change linked data*/
}
Also used : Need(won.protocol.model.Need) PrefixMapping(org.apache.jena.shared.PrefixMapping) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) ConnectionAlreadyExistsException(won.protocol.exception.ConnectionAlreadyExistsException) IllegalMessageForNeedStateException(won.protocol.exception.IllegalMessageForNeedStateException) NoSuchNeedException(won.protocol.exception.NoSuchNeedException)

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