Ejemplo n.º 1
0
 @Override
 public void remove(List<Statement> statements) {
   Model graph = null;
   GraphConnection graphConnection = null;
   try {
     graphConnection = openGraph();
     graph = graphConnection.getGraph();
     graph.enterCriticalSection(Lock.WRITE);
     for (Statement nuxStmt : statements) {
       com.hp.hpl.jena.graph.Node subject = getJenaNode(nuxStmt.getSubject());
       com.hp.hpl.jena.graph.Node predicate = getJenaNode(nuxStmt.getPredicate());
       com.hp.hpl.jena.graph.Node object = getJenaNode(nuxStmt.getObject());
       Triple jenaTriple = Triple.create(subject, predicate, object);
       com.hp.hpl.jena.rdf.model.Statement jenaStmt = graph.asStatement(jenaTriple);
       graph.remove(jenaStmt);
       // remove properties
       RSIterator it = graph.listReifiedStatements(jenaStmt);
       while (it.hasNext()) {
         ReifiedStatement rs = it.nextRS();
         rs.removeProperties();
       }
       // remove quadlets
       graph.removeAllReifications(jenaStmt);
       // graph.removeReification(reifiedStmt);
     }
   } finally {
     if (graph != null) {
       graph.leaveCriticalSection();
     }
     if (graphConnection != null) {
       graphConnection.close();
     }
   }
 }
  @Override
  public void deleteRelation(CoreSession session, Statement stmt, boolean includeStatementsInEvents)
      throws ClientException {

    // notifications
    Map<String, Serializable> options = new HashMap<String, Serializable>();

    // Find relative document
    DocumentModel eventDocument = null;
    if (stmt.getSubject() instanceof QNameResource) {
      eventDocument =
          (DocumentModel)
              getRelationManager()
                  .getResourceRepresentation(
                      RelationConstants.DOCUMENT_NAMESPACE,
                      (QNameResource) stmt.getSubject(),
                      null);
    } else if (stmt.getObject() instanceof QNameResource) {
      eventDocument =
          (DocumentModel)
              getRelationManager()
                  .getResourceRepresentation(
                      RelationConstants.DOCUMENT_NAMESPACE, (QNameResource) stmt.getObject(), null);
    }

    // Complete event info and send first event
    if (eventDocument != null) {
      String currentLifeCycleState = eventDocument.getCurrentLifeCycleState();
      options.put(CoreEventConstants.DOC_LIFE_CYCLE, currentLifeCycleState);
      options.put(RelationEvents.GRAPH_NAME_EVENT_KEY, RelationConstants.GRAPH_NAME);
      if (includeStatementsInEvents) {
        putStatements(options, stmt);
      }

      // before notification
      notifyEvent(RelationEvents.BEFORE_RELATION_REMOVAL, eventDocument, options, null, session);
    }

    // remove statement
    getRelationManager().getGraphByName(RelationConstants.GRAPH_NAME).remove(stmt);

    if (eventDocument != null) {
      // after notification
      notifyEvent(RelationEvents.AFTER_RELATION_REMOVAL, eventDocument, options, null, session);
    }
  }
Ejemplo n.º 3
0
  @Override
  public void add(List<Statement> statements) {
    Model graph = null;
    GraphConnection graphConnection = null;
    try {
      graphConnection = openGraph();
      graph = graphConnection.getGraph();
      graph.enterCriticalSection(Lock.WRITE);
      for (Statement nuxStmt : statements) {
        com.hp.hpl.jena.graph.Node subject = getJenaNode(nuxStmt.getSubject());
        com.hp.hpl.jena.graph.Node predicate = getJenaNode(nuxStmt.getPredicate());
        com.hp.hpl.jena.graph.Node object = getJenaNode(nuxStmt.getObject());
        Triple jenaTriple = Triple.create(subject, predicate, object);
        com.hp.hpl.jena.rdf.model.Statement jenaStmt = graph.asStatement(jenaTriple);

        // properties
        Map<Resource, Node[]> properties = nuxStmt.getProperties();
        if (properties == null || properties.isEmpty()) {
          // no properties
          graph.add(jenaStmt);
        } else {
          List<com.hp.hpl.jena.rdf.model.Statement> stmts =
              new ArrayList<com.hp.hpl.jena.rdf.model.Statement>();
          stmts.add(jenaStmt);
          // create reified statement if it does not exist
          com.hp.hpl.jena.graph.Node reifiedStmt = graph.getAnyReifiedStatement(jenaStmt).asNode();
          for (Map.Entry<Resource, Node[]> property : properties.entrySet()) {
            com.hp.hpl.jena.graph.Node prop = getJenaNode(property.getKey());
            for (Node node : property.getValue()) {
              com.hp.hpl.jena.graph.Node value = getJenaNode(node);
              Triple propTriple = Triple.create(reifiedStmt, prop, value);
              stmts.add(graph.asStatement(propTriple));
            }
          }
          graph.add(stmts);
        }
      }
    } finally {
      if (graph != null) {
        graph.leaveCriticalSection();
      }
      if (graphConnection != null) {
        graphConnection.close();
      }
    }
  }
Ejemplo n.º 4
0
 /**
  * Gets Jena statement selector corresponding to the NXRelations statement.
  *
  * @param graph the jena graph
  * @param nuxStatement NXRelations statement
  * @return jena statement selector
  */
 private static SimpleSelector getJenaSelector(Model graph, Statement nuxStatement) {
   com.hp.hpl.jena.rdf.model.Resource subjResource = null;
   com.hp.hpl.jena.graph.Node subject = getJenaNode(nuxStatement.getSubject());
   if (subject != null && subject.isURI()) {
     subjResource = graph.getResource(subject.getURI());
   }
   Property predProp = null;
   com.hp.hpl.jena.graph.Node predicate = getJenaNode(nuxStatement.getPredicate());
   if (predicate != null && predicate.isURI()) {
     predProp = graph.getProperty(predicate.getURI());
   }
   com.hp.hpl.jena.graph.Node object = getJenaNode(nuxStatement.getObject());
   RDFNode objRDF = null;
   if (object != null) {
     objRDF = graph.asRDFNode(object);
   }
   return new SimpleSelector(subjResource, predProp, objRDF);
 }
 protected List<StatementInfo> getStatementsInfo(List<Statement> statements)
     throws ClientException {
   if (statements == null) {
     return null;
   }
   List<StatementInfo> infoList = new ArrayList<StatementInfo>();
   for (Statement statement : statements) {
     Subject subject = statement.getSubject();
     // TODO: filter on doc visibility (?)
     NodeInfo subjectInfo = new NodeInfoImpl(subject, getDocumentModel(subject), true);
     Resource predicate = statement.getPredicate();
     Node object = statement.getObject();
     NodeInfo objectInfo = new NodeInfoImpl(object, getDocumentModel(object), true);
     StatementInfo info =
         new StatementInfoImpl(statement, subjectInfo, new NodeInfoImpl(predicate), objectInfo);
     infoList.add(info);
   }
   return infoList;
 }