public int insertNewDataPropertyStatement(
     DataPropertyStatement dataPropertyStmt, OntModel ontModel) {
   ontModel.enterCriticalSection(Lock.WRITE);
   getOntModel()
       .getBaseModel()
       .notifyEvent(
           new IndividualUpdateEvent(
               getWebappDaoFactory().getUserURI(), true, dataPropertyStmt.getIndividualURI()));
   DataProperty dp =
       getWebappDaoFactory()
           .getDataPropertyDao()
           .getDataPropertyByURI(dataPropertyStmt.getDatapropURI());
   if ((dataPropertyStmt.getDatatypeURI() == null)
       && (dp != null)
       && (dp.getRangeDatatypeURI() != null)) {
     dataPropertyStmt.setDatatypeURI(dp.getRangeDatatypeURI());
   }
   Property prop = ontModel.getProperty(dataPropertyStmt.getDatapropURI());
   try {
     Resource res = ontModel.getResource(dataPropertyStmt.getIndividualURI());
     Literal literal = jenaLiteralFromDataPropertyStatement(dataPropertyStmt, ontModel);
     if (res != null
         && prop != null
         && literal != null
         && dataPropertyStmt.getData().length() > 0) {
       res.addProperty(prop, literal);
     }
   } finally {
     getOntModel()
         .getBaseModel()
         .notifyEvent(
             new IndividualUpdateEvent(
                 getWebappDaoFactory().getUserURI(), false, dataPropertyStmt.getIndividualURI()));
     ontModel.leaveCriticalSection();
   }
   return 0;
 }
Example #2
0
  private void reorderIndividuals(
      String[] individualUris, VitroRequest vreq, String rankPredicate) {
    // Testing new mechanism
    OntModel writeModel = vreq.getOntModelSelector().getABoxModel();
    Model additions = ModelFactory.createDefaultModel();
    Model retractions = ModelFactory.createDefaultModel();
    Property rankPredicateProperty = ResourceFactory.createProperty(rankPredicate);
    DataProperty dp =
        vreq.getWebappDaoFactory().getDataPropertyDao().getDataPropertyByURI(rankPredicate);
    String datapropURI = dp.getRangeDatatypeURI();
    int counter = 1;
    for (String individualUri : individualUris) {
      Resource individualResource = ResourceFactory.createResource(individualUri);
      // Deletions are all old statements with rank predicate
      retractions.add(
          writeModel.listStatements(individualResource, rankPredicateProperty, (RDFNode) null));
      log.debug("retractions = " + retractions);
      // New statement is new literal with the data property from
      Literal dataLiteral = null;
      if (datapropURI != null && datapropURI.length() > 0) {
        dataLiteral =
            ResourceFactory.createTypedLiteral(
                String.valueOf(counter), TypeMapper.getInstance().getSafeTypeByName(datapropURI));
      } else {
        dataLiteral = ResourceFactory.createPlainLiteral(String.valueOf(counter));
      }
      additions.add(individualResource, rankPredicateProperty, dataLiteral);
      log.debug("additions = " + additions);
      counter++;
    }

    Lock lock = null;
    try {
      lock = writeModel.getLock();
      lock.enterCriticalSection(Lock.WRITE);
      writeModel.getBaseModel().notifyEvent(new EditEvent(null, true));
      writeModel.remove(retractions);
      writeModel.add(additions);
    } catch (Throwable t) {
      log.error("error adding edit change n3required model to in memory model \n" + t.getMessage());
    } finally {
      writeModel.getBaseModel().notifyEvent(new EditEvent(null, false));
      lock.leaveCriticalSection();
    }

    // old code that for some reason doesn't seem to actually commit the changes
    /*
    * int counter = 1;
      for (String individualUri : individualUris) {
          // Retract all existing rank statements for this individual
          dpsDao.deleteDataPropertyStatementsForIndividualByDataProperty(individualUri, rankPredicate);

          // Then add the new rank statement for this individual
          // insertNewDataPropertyStatement will insert the rangeDatatype of the property, so we don't need to set that here.
          dpsDao.insertNewDataPropertyStatement(new DataPropertyStatementImpl(individualUri, rankPredicate, String.valueOf(counter)));

          counter++;
      }

    */

  }