Пример #1
0
 private void processRenameBNodesURISelectRequest(VitroRequest vreq, ModelMaker maker) {
   String namespaceEtcStr = vreq.getParameter("namespaceEtcStr");
   String pattern = vreq.getParameter("pattern");
   String concatenate = vreq.getParameter("concatenate");
   String[] sourceModel = vreq.getParameterValues("sourceModelName");
   if (namespaceEtcStr != null) {
     if (namespaceEtcStr.isEmpty()) {
       if ("true".equals(vreq.getParameter("csv2rdf"))) {
         processCsv2rdfRequest(vreq);
         return;
       } else {
         vreq.setAttribute("errorMsg", "Please enter a value.");
         processRenameBNodesRequest(vreq, maker);
         return;
       }
     }
     if (concatenate.equals("integer")) {
       doRenameBNodes(vreq, namespaceEtcStr, false, null, sourceModel);
     } else {
       pattern = pattern.trim();
       doRenameBNodes(vreq, namespaceEtcStr, true, pattern, sourceModel);
     }
     vreq.setAttribute("title", "Ingest Menu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else {
     vreq.setAttribute("title", "URI Select");
     vreq.setAttribute("bodyJsp", RENAME_BNODES_URI_SELECT_JSP);
   }
 }
 protected Collection<String> getStringParameters(String key) {
   String[] values = vreq.getParameterValues(key);
   if (values == null) {
     return Collections.emptySet();
   } else {
     return new HashSet<String>(Arrays.asList(values));
   }
 }
Пример #3
0
 private long doExecuteSparql(VitroRequest vreq) {
   OntModel jenaOntModel = ModelAccess.on(getServletContext()).getOntModel();
   OntModel source = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
   String[] sourceModel = vreq.getParameterValues("sourceModelName");
   for (int i = 0; i < sourceModel.length; i++) {
     Model m = getModel(sourceModel[i], vreq);
     source.addSubModel(m);
   }
   Model destination = getModel(vreq.getParameter("destinationModelName"), vreq);
   String sparqlQueryStr = vreq.getParameter("sparqlQueryStr");
   String savedQueryURIStr = vreq.getParameter("savedQuery");
   String queryStr;
   if (savedQueryURIStr.length() == 0) {
     log.debug("Using entered query");
     queryStr = sparqlQueryStr;
   } else {
     Property queryStrProp = ResourceFactory.createProperty(SPARQL_QUERYSTR_PROP);
     jenaOntModel.enterCriticalSection(Lock.READ);
     try {
       Individual ind = jenaOntModel.getIndividual(savedQueryURIStr);
       log.debug("Using query " + savedQueryURIStr);
       queryStr = ((Literal) ind.getPropertyValue(queryStrProp)).getLexicalForm();
       queryStr =
           StringEscapeUtils.unescapeHtml(
               queryStr); // !!! We need to turn off automatic HTML-escaping for data property
                          // editing.
     } finally {
       jenaOntModel.leaveCriticalSection();
     }
   }
   Model tempModel = ModelFactory.createDefaultModel();
   Query query = SparqlQueryUtils.create(queryStr);
   QueryExecution qexec = QueryExecutionFactory.create(query, source);
   try {
     qexec.execConstruct(tempModel);
   } catch (QueryExecException qee) {
     qexec.execDescribe(tempModel);
   }
   destination.enterCriticalSection(Lock.WRITE);
   try {
     if (destination instanceof OntModel) {
       ((OntModel) destination).getBaseModel().notifyEvent(new EditEvent(null, true));
     } else {
       destination.notifyEvent(new EditEvent(null, true));
     }
     destination.add(tempModel);
   } finally {
     if (destination instanceof OntModel) {
       ((OntModel) destination).getBaseModel().notifyEvent(new EditEvent(null, false));
     } else {
       destination.notifyEvent(new EditEvent(null, false));
     }
     destination.leaveCriticalSection();
   }
   return tempModel.size();
 }
Пример #4
0
 public void doGenerateTBox(VitroRequest vreq) {
   OntModel source = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
   String[] sourceModel = vreq.getParameterValues("sourceModelName");
   for (int i = 0; i < sourceModel.length; i++) {
     Model m = getModel(sourceModel[i], vreq);
     source.addSubModel(m);
   }
   String destinationModelStr = vreq.getParameter("destinationModelName");
   Model destination = getModel(destinationModelStr, vreq);
   destination.add((new JenaIngestUtils()).generateTBox(source));
 }
Пример #5
0
  @Override
  protected void doRequest(VitroRequest vreq, HttpServletResponse response) {

    String errorMsg = null;
    String rankPredicate = vreq.getParameter(RANK_PREDICATE_PARAMETER_NAME);
    if (rankPredicate == null) {
      errorMsg = "No rank parameter specified";
      log.error(errorMsg);
      doError(response, errorMsg, HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    String[] individualUris = vreq.getParameterValues(INDIVIDUAL_PREDICATE_PARAMETER_NAME);
    if (individualUris == null || individualUris.length == 0) {
      errorMsg = "No individuals specified";
      log.error(errorMsg);
      doError(response, errorMsg, HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    WebappDaoFactory wadf = vreq.getWebappDaoFactory();
    if (vreq.getWebappDaoFactory() == null) {
      errorMsg = "No WebappDaoFactory available";
      log.error(errorMsg);
      doError(response, errorMsg, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }

    DataPropertyStatementDao dpsDao = wadf.getDataPropertyStatementDao();
    if (dpsDao == null) {
      errorMsg = "No DataPropertyStatementDao available";
      log.error(errorMsg);
      doError(response, errorMsg, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }

    // check permissions
    // TODO: (bdc34)This is not yet implemented, must check the IDs against the policies for
    // permissons before doing an edit!
    // rjy7 This should be inherited from the superclass
    boolean hasPermission = true;
    if (!hasPermission) {
      // if not okay, send error message
      doError(response, "Insufficent permissions", HttpStatus.SC_UNAUTHORIZED);
      return;
    }

    // This may not be the most efficient way. Should we instead build up a Model of retractions and
    // additions, so
    // we only hit the database once?
    reorderIndividuals(individualUris, vreq, rankPredicate);

    response.setStatus(HttpServletResponse.SC_OK);
  }
Пример #6
0
 private void doSmushSingleModel(VitroRequest vreq) {
   OntModel source = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
   String[] sourceModel = vreq.getParameterValues("sourceModelName");
   for (int i = 0; i < sourceModel.length; i++) {
     Model m = getModel(sourceModel[i], vreq);
     source.addSubModel(m);
   }
   Model destination = getModel(vreq.getParameter("destinationModelName"), vreq);
   String propertyURIStr = vreq.getParameter("propertyURI");
   Property prop = ResourceFactory.createProperty(propertyURIStr);
   JenaIngestUtils utils = new JenaIngestUtils();
   destination.enterCriticalSection(Lock.WRITE);
   try {
     destination.add(utils.smushResources(source, prop));
   } finally {
     destination.leaveCriticalSection();
   }
 }
Пример #7
0
 private void processRenameBNodesRequest(VitroRequest vreq, ModelMaker maker) {
   String[] sourceModel = vreq.getParameterValues("sourceModelName");
   JenaIngestUtils utils = new JenaIngestUtils();
   if (sourceModel != null && sourceModel.length != 0) {
     List<Model> sourceModelList = new ArrayList<Model>();
     for (int i = 0; i < sourceModel.length; i++) {
       Model m = maker.getModel(sourceModel[i]);
       if (m != null) {
         sourceModelList.add(m);
       }
     }
     Map<String, LinkedList<String>> propertyMap =
         utils.generatePropertyMap(sourceModelList, maker);
     List<String> sourceModelNameList = Arrays.asList(sourceModel);
     vreq.setAttribute("sourceModel", sourceModelNameList);
     vreq.setAttribute("propertyMap", propertyMap);
     vreq.setAttribute("enablePropertyPatternURIs", !propertyMap.isEmpty());
     vreq.setAttribute("title", "URI Select");
     vreq.setAttribute("bodyJsp", RENAME_BNODES_URI_SELECT_JSP);
   } else {
     vreq.setAttribute("title", "Rename Blank Nodes");
     vreq.setAttribute("bodyJsp", RENAME_BNODES_JSP);
   }
 }
Пример #8
0
 private void processExecuteSparqlRequest(VitroRequest vreq) {
   String sparqlQueryStr = vreq.getParameter("sparqlQueryStr");
   OntModel jenaOntModel = ModelAccess.on(getServletContext()).getOntModel();
   jenaOntModel.enterCriticalSection(Lock.READ);
   List<Individual> savedQueryList = new LinkedList<Individual>();
   try {
     Resource sparqlConstructClassRes = ResourceFactory.createResource(SPARQL_CONSTRUCT_CLASS);
     savedQueryList.addAll(jenaOntModel.listIndividuals(sparqlConstructClassRes).toList());
   } finally {
     jenaOntModel.leaveCriticalSection();
   }
   /*ass92*/
   OntologyDao daoObj = vreq.getUnfilteredWebappDaoFactory().getOntologyDao();
   List<Ontology> ontologiesObj = daoObj.getAllOntologies();
   List<String> prefixList = new ArrayList<>();
   if (ontologiesObj != null && ontologiesObj.size() > 0) {
     Iterator<Ontology> ontItr = ontologiesObj.iterator();
     while (ontItr.hasNext()) {
       Ontology ont = ontItr.next();
       prefixList.add(ont.getPrefix() == null ? "(not yet specified)" : ont.getPrefix());
       prefixList.add(ont.getURI() == null ? "" : ont.getURI());
     }
   } else {
     prefixList.add("<strong>" + "No Ontologies added" + "</strong>");
     prefixList.add("<strong>" + "Load Ontologies" + "</strong>");
   }
   vreq.setAttribute("prefixList", prefixList);
   /*complete*/
   if (sparqlQueryStr != null) {
     String validationMessage = "";
     if (vreq.getParameterValues("sourceModelName") == null) {
       validationMessage += "<p>Please select one or more source models.</p>";
     }
     if (vreq.getParameter("destinationModelName") == null) {
       validationMessage += "<p>Please select a destination model</p>";
     }
     if (validationMessage.length() > 0) {
       vreq.setAttribute("validationMessage", validationMessage);
     } else {
       long constructedStmtCount = 0;
       try {
         constructedStmtCount = doExecuteSparql(vreq);
       } catch (QueryParseException qpe) {
         String errorMsg = "<p>Unable to parse query:</p>";
         if (qpe.getMessage() != null) {
           errorMsg += "<p>" + qpe.getMessage() + "</p>";
         }
         vreq.setAttribute("errorMsg", errorMsg);
       } catch (InconsistentOntologyException ioe) {
         String errorMsg = "<p>Inconsistent source ontology:</p>";
         if (ioe.getMessage() != null) {
           errorMsg += "<p>" + ioe.getMessage() + "</p>";
         }
         vreq.setAttribute("errorMsg", errorMsg);
       }
       vreq.setAttribute("constructedStmtCount", constructedStmtCount);
     }
     vreq.setAttribute("savedQueries", savedQueryList);
     vreq.setAttribute("title", "SPARQL CONSTRUCT result");
     vreq.setAttribute("bodyJsp", EXECUTE_SPARQL_JSP);
   } else {
     vreq.setAttribute("savedQueries", savedQueryList);
     vreq.setAttribute("title", "Execute SPARQL Construct");
     vreq.setAttribute("bodyJsp", EXECUTE_SPARQL_JSP);
   }
 }