Search in sources :

Example 1 with ConnectionAlreadyExistsException

use of won.protocol.exception.ConnectionAlreadyExistsException 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

Model (org.apache.jena.rdf.model.Model)1 Resource (org.apache.jena.rdf.model.Resource)1 PrefixMapping (org.apache.jena.shared.PrefixMapping)1 ConnectionAlreadyExistsException (won.protocol.exception.ConnectionAlreadyExistsException)1 IllegalMessageForNeedStateException (won.protocol.exception.IllegalMessageForNeedStateException)1 NoSuchNeedException (won.protocol.exception.NoSuchNeedException)1 Need (won.protocol.model.Need)1