public List<DataPropertyStatement> getDataPropertyStatements(
     DataProperty dp, int startIndex, int endIndex) {
   getOntModel().enterCriticalSection(Lock.READ);
   List<DataPropertyStatement> dpss = new ArrayList<DataPropertyStatement>();
   try {
     Property prop = ResourceFactory.createProperty(dp.getURI());
     ClosableIterator dpsIt = getOntModel().listStatements(null, prop, (Literal) null);
     try {
       int count = 0;
       while ((dpsIt.hasNext()) && ((endIndex < 0) || (count < endIndex))) {
         ++count;
         Statement stmt = (Statement) dpsIt.next();
         if (startIndex < 0 || startIndex <= count) {
           Literal lit = (Literal) stmt.getObject();
           DataPropertyStatement dps = new DataPropertyStatementImpl();
           dps.setDatapropURI(dp.getURI());
           dps.setIndividualURI(stmt.getSubject().getURI());
           fillDataPropertyStatementWithJenaLiteral(dps, lit);
           dpss.add(dps);
         }
       }
     } finally {
       dpsIt.close();
     }
   } finally {
     getOntModel().leaveCriticalSection();
   }
   return dpss;
 }
  // Check for "back button" confusion specifically for data property editing although need to check
  // if this applies to object property editing?
  // TODO: Check if only applicable to data property editing
  private boolean checkForBackButtonConfusion(
      EditConfigurationVTwo editConfig, VitroRequest vreq, Model model) {
    // back button confusion limited to data property
    if (EditConfigurationUtils.isObjectProperty(editConfig.getPredicateUri(), vreq)) {
      return false;
    }

    WebappDaoFactory wdf = vreq.getWebappDaoFactory();
    if (!editConfig.isDataPropertyUpdate()) return false;

    Integer dpropHash = editConfig.getDatapropKey();
    DataPropertyStatement dps =
        RdfLiteralHash.getPropertyStmtByHash(
            editConfig.getSubjectUri(), editConfig.getPredicateUri(), dpropHash, model);
    if (dps != null) return false;

    DataProperty dp = wdf.getDataPropertyDao().getDataPropertyByURI(editConfig.getPredicateUri());
    if (dp != null) {
      if (dp.getDisplayLimit() == 1 /* || dp.isFunctional() */) return false;
      else return true;
    }
    return false;
  }
 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;
 }
 @Override
 public List<Literal> getDataPropertyValuesForIndividualByProperty(
     Individual subject, DataProperty property) {
   return getDataPropertyValuesForIndividualByProperty(subject.getURI(), property.getURI());
 }
 public void deleteDataPropertyStatementsForIndividualByDataProperty(
     Individual individual, DataProperty dataProperty) {
   this.deleteDataPropertyStatementsForIndividualByDataProperty(
       individual.getURI(), dataProperty.getURI());
 }
Beispiel #6
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++;
      }

    */

  }