예제 #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);
   }
 }
예제 #2
0
 private void processCleanLiteralsRequest(VitroRequest vreq) {
   String modelNameStr = vreq.getParameter("modelName");
   Model model = getModel(modelNameStr, vreq);
   doCleanLiterals(model);
   vreq.setAttribute("title", "Ingest Menu");
   vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
 }
예제 #3
0
  private void processCreateModelRequest(
      VitroRequest vreq, ModelMaker maker, WhichService modelType) {
    String modelName = vreq.getParameter("modelName");

    if (modelName != null) {
      try {
        URI graphURI = new URI(modelName);

        if (graphURI.getScheme() == null) {
          String origName = modelName;
          modelName = CREATED_GRAPH_BASE_URI + modelName;
          log.info("The model name has been changed from " + origName + " to " + modelName);
        }

        doCreateModel(modelName, maker);
        showModelList(vreq, maker, modelType);
      } catch (URISyntaxException e) {
        throw new RuntimeException("the model name must be a valid URI");
      }
    } else {
      vreq.setAttribute("modelType", modelType.toString());
      vreq.setAttribute("title", "Create New Model");
      vreq.setAttribute("bodyJsp", CREATE_MODEL_JSP);
    }
  }
예제 #4
0
  private void processMergeResourceRequest(VitroRequest vreq) {
    String uri1 = vreq.getParameter("uri1"); // get primary uri
    String uri2 = vreq.getParameter("uri2"); // get secondary uri
    String usePrimaryLabelOnlyStr = vreq.getParameter("usePrimaryLabelOnly");
    ;
    boolean usePrimaryLabelOnly =
        usePrimaryLabelOnlyStr != null && !usePrimaryLabelOnlyStr.isEmpty();

    if (uri1 != null) {
      JenaIngestUtils utils = new JenaIngestUtils();
      /*
       * get baseOnt and infOnt models
       */
      OntModel baseOntModel = ModelAccess.on(getServletContext()).getOntModel(FULL_ASSERTIONS);
      OntModel tboxOntModel = ModelAccess.on(getServletContext()).getOntModel(TBOX_UNION);

      /*
       * calling method that does the merge operation.
       */
      MergeResult result =
          utils.doMerge(uri1, uri2, baseOntModel, tboxOntModel, usePrimaryLabelOnly);

      vreq.getSession().setAttribute("leftoverModel", result.getLeftoverModel());
      vreq.setAttribute("result", result);
      vreq.setAttribute("title", "Merge Resources");
      vreq.setAttribute("bodyJsp", MERGE_RESULT);
    } else {
      vreq.setAttribute("title", "Merge Resources");
      vreq.setAttribute("bodyJsp", MERGE_RESOURCES);
    }
  }
예제 #5
0
 private void processProcessStringsRequest(VitroRequest vreq) {
   String className = vreq.getParameter("className");
   if (className != null) {
     doProcessStrings(vreq);
     vreq.setAttribute("title", "IngestMenu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else {
     vreq.setAttribute("title", "Process Strings");
     vreq.setAttribute("bodyJsp", PROCESS_STRINGS_JSP);
   }
 }
예제 #6
0
 private void processSubtractModelRequest(VitroRequest vreq) {
   String modela = vreq.getParameter("modela");
   if (modela != null) {
     doSubtractModels(vreq);
     vreq.setAttribute("title", "IngestMenu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else {
     vreq.setAttribute("title", "Subtract Models");
     vreq.setAttribute("bodyJsp", SUBTRACT_MODELS_JSP);
   }
 }
예제 #7
0
 private void processSmushSingleModelRequest(VitroRequest vreq) {
   String propertyURIStr = vreq.getParameter("propertyURI");
   if (propertyURIStr != null) {
     doSmushSingleModel(vreq);
     vreq.setAttribute("title", "Ingest Menu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else {
     vreq.setAttribute("title", "Smush Resources");
     vreq.setAttribute("bodyJsp", SMUSH_JSP);
   }
 }
예제 #8
0
 private void processGenerateTBoxRequest(VitroRequest vreq) {
   String testParam = vreq.getParameter("sourceModelName");
   if (testParam != null) {
     doGenerateTBox(vreq);
     vreq.setAttribute("title", "Ingest Menu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else {
     vreq.setAttribute("title", "Generate TBox from Assertions Data");
     vreq.setAttribute("bodyJsp", GENERATE_TBOX_JSP);
   }
 }
예제 #9
0
 private void processSplitPropertyValuesRequest(VitroRequest vreq) {
   String splitRegex = vreq.getParameter("splitRegex");
   if (splitRegex != null) {
     doSplitPropertyValues(vreq);
     vreq.setAttribute("title", "IngestMenu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else {
     vreq.setAttribute("title", "Split PropertyValues");
     vreq.setAttribute("bodyJsp", SPLIT_PROPERTY_VALUES_JSP);
   }
 }
예제 #10
0
 private void processCsv2rdfRequest(VitroRequest vreq) {
   String csvUrl = vreq.getParameter("csvUrl");
   if (csvUrl != null) {
     /*doExecuteCsv2Rdf(vreq);*/
     vreq.setAttribute("title", "IngestMenu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else {
     vreq.setAttribute("title", "Convert CSV to RDF");
     vreq.setAttribute("bodyJsp", CSV2RDF_JSP);
   }
 }
예제 #11
0
 private void processLoadRDFDataRequest(VitroRequest vreq, ModelMaker maker) {
   String docLoc = vreq.getParameter("docLoc");
   String filePath = vreq.getParameter("filePath");
   String modelName = vreq.getParameter("modelName");
   String languageParam = null;
   String language =
       ((languageParam = vreq.getParameter("language")) != null) ? languageParam : "RDF/XML";
   if (docLoc != null && modelName != null) {
     doLoadRDFData(modelName, docLoc, filePath, language, maker);
     vreq.setAttribute("title", "Ingest Menu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else {
     vreq.setAttribute("title", "Load RDF Data");
     vreq.setAttribute("bodyJsp", LOAD_RDF_DATA_JSP);
   }
 }
예제 #12
0
 private void processRenameResourceRequest(VitroRequest vreq) {
   String oldNamespace = vreq.getParameter("oldNamespace");
   String newNamespace = vreq.getParameter("newNamespace");
   String errorMsg = "";
   if (oldNamespace != null) {
     if (oldNamespace.isEmpty() && !newNamespace.isEmpty()) {
       errorMsg = "Please enter the old namespace to be changed.";
     } else if (!oldNamespace.isEmpty() && newNamespace.isEmpty()) {
       errorMsg = "Please enter the new namespace.";
     } else if (oldNamespace.isEmpty() && newNamespace.isEmpty()) {
       errorMsg = "Please enter the namespaces.";
     } else if (oldNamespace.equals(newNamespace)) {
       errorMsg = "Please enter two different namespaces.";
     }
     if (!errorMsg.isEmpty()) {
       vreq.setAttribute("errorMsg", errorMsg);
       vreq.setAttribute("oldNamespace", oldNamespace);
       vreq.setAttribute("newNamespace", newNamespace);
       vreq.setAttribute("title", "Rename Resource");
       vreq.setAttribute("bodyJsp", RENAME_RESOURCE);
     } else {
       String result = doRename(oldNamespace, newNamespace);
       vreq.setAttribute("result", result);
       vreq.setAttribute("title", "Rename Resources");
       vreq.setAttribute("bodyJsp", RENAME_RESULT);
     }
   } else {
     vreq.setAttribute("title", "Rename Resource");
     vreq.setAttribute("bodyJsp", RENAME_RESOURCE);
   }
 }
예제 #13
0
 private void processExecuteWorkflowRequest(VitroRequest vreq) {
   String workflowURIStr = vreq.getParameter("workflowURI");
   String workflowStepURIStr = vreq.getParameter("workflowStepURI");
   if (workflowURIStr != null && workflowStepURIStr != null) {
     doExecuteWorkflow(vreq);
     vreq.setAttribute("title", "IngestMenu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   } else if (workflowURIStr != null) {
     // Select the workflow step at which to start
     OntModel jenaOntModel = (OntModel) getModel("vitro:jenaOntModel", vreq);
     vreq.setAttribute(
         "workflowSteps",
         new JenaIngestWorkflowProcessor(
                 jenaOntModel.getIndividual(workflowURIStr), getModelMaker(vreq))
             .getWorkflowSteps(null));
     vreq.setAttribute("title", "Choose Workflow Step");
     vreq.setAttribute("bodyJsp", WORKFLOW_STEP_JSP);
   } else {
     OntModel jenaOntModel = ModelAccess.on(getServletContext()).getOntModel();
     jenaOntModel.enterCriticalSection(Lock.READ);
     List<Individual> savedQueryList = new LinkedList<Individual>();
     try {
       Resource workflowClassRes = WorkflowOntology.Workflow;
       savedQueryList.addAll(jenaOntModel.listIndividuals(workflowClassRes).toList());
     } finally {
       jenaOntModel.leaveCriticalSection();
     }
     vreq.setAttribute("workflows", savedQueryList);
     vreq.setAttribute("title", "Execute Workflow");
     vreq.setAttribute("bodyJsp", EXECUTE_WORKFLOW_JSP);
   }
 }
  private ResponseValues doValidationErrors(
      VitroRequest vreq,
      EditConfigurationVTwo editConfiguration,
      MultiValueEditSubmission submission) {

    Map<String, String> errors = submission.getValidationErrors();

    if (errors != null && !errors.isEmpty()) {
      String form = editConfiguration.getFormUrl();
      vreq.setAttribute("formUrl", form);
      vreq.setAttribute("view", vreq.getParameter("view"));
      // Need to ensure that edit key is set so that the correct
      // edit configuration and edit submission are retrieved
      // This can also be set as a parameter instead
      String formUrl = editConfiguration.getFormUrl();
      formUrl += "&editKey=" + editConfiguration.getEditKey();
      return new RedirectResponseValues(formUrl);
    }
    return null; // no errors
  }
예제 #15
0
 protected void showModelList(VitroRequest vreq, ModelMaker maker, WhichService modelType) {
   vreq.setAttribute("modelType", modelType.toString());
   if (modelType == CONTENT) {
     vreq.setAttribute("infoLine", "Main Store models");
   } else {
     vreq.setAttribute("infoLine", "Configuration models");
   }
   vreq.setAttribute("modelNames", maker.listModels().toList());
   vreq.setAttribute("bodyAttr", "onLoad=\"init()\"");
   vreq.setAttribute("title", "Available Models");
   vreq.setAttribute("bodyJsp", LIST_MODELS_JSP);
 }
예제 #16
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);
   }
 }
예제 #17
0
 private void processPermanentURIRequest(VitroRequest vreq, ModelMaker maker) {
   String modelName = vreq.getParameter("modelName");
   String oldModel = vreq.getParameter("oldModel");
   String newModel = vreq.getParameter("newModel");
   String oldNamespace = vreq.getParameter("oldNamespace");
   String newNamespace = vreq.getParameter("newNamespace");
   String dNamespace = vreq.getParameter("defaultNamespace");
   newNamespace = (newNamespace == null || newNamespace.isEmpty()) ? oldNamespace : newNamespace;
   newNamespace = (dNamespace != null) ? dNamespace : newNamespace;
   if (modelName != null) {
     Model m = maker.getModel(modelName);
     List<String> namespaceList = new ArrayList<>();
     ResIterator resItr = m.listResourcesWithProperty((Property) null);
     if (resItr != null) {
       while (resItr.hasNext()) {
         String namespace = resItr.nextResource().getNameSpace();
         if (!namespaceList.contains(namespace)) {
           namespaceList.add(namespace);
         }
       }
     } else {
       namespaceList.add("no resources present");
     }
     String defaultNamespace = vreq.getUnfilteredWebappDaoFactory().getDefaultNamespace();
     vreq.setAttribute("modelName", modelName);
     vreq.setAttribute("defaultNamespace", defaultNamespace);
     vreq.setAttribute("namespaceList", namespaceList);
     vreq.setAttribute("title", "Permanent URI");
     vreq.setAttribute("bodyJsp", PERMANENT_URI);
   } else if (oldModel != null) {
     JenaIngestUtils utils = new JenaIngestUtils();
     utils.doPermanentURI(oldModel, newModel, oldNamespace, newNamespace, maker, vreq);
     vreq.setAttribute("title", "Ingest Menu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   }
 }
  @Override
  public void doPost(HttpServletRequest req, HttpServletResponse response) {
    if (!isAuthorizedToDisplayPage(req, response, new Actions(new EditOntology()))) {
      return;
    }

    VitroRequest request = new VitroRequest(req);

    EditProcessObject epo = super.createEpo(request);
    request.setAttribute("epoKey", epo.getKey());

    OntologyDao oDao = request.getFullWebappDaoFactory().getOntologyDao();
    Ontology o = null;
    if (request.getParameter("uri") == null) {
      log.error("doPost() expects non-null uri parameter");
    } else {
      o = oDao.getOntologyByURI(request.getParameter("uri"));
      if (o == null) {
        if (!VitroVocabulary.vitroURI.equals(request.getParameter("uri"))) {
          log.debug(
              "doPost(): no ontology object found for the namespace "
                  + request.getParameter("uri"));
        }
      } else {
        request.setAttribute("Ontology", o);
      }
    }
    ArrayList<String> results = new ArrayList<String>();
    results.add("Ontology");
    results.add("Namespace");
    results.add("Prefix");
    String name = o == null ? "" : (o.getName() == null) ? "" : o.getName();
    results.add(name);
    String namespace = o == null ? "" : (o.getURI() == null) ? "" : o.getURI();
    results.add(namespace);
    String prefix = o == null ? "" : (o.getPrefix() == null) ? "" : o.getPrefix();
    results.add(prefix);
    request.setAttribute("results", results);
    request.setAttribute("columncount", 3);
    request.setAttribute("suppressquery", "true");

    epo.setDataAccessObject(oDao);
    FormObject foo = new FormObject();
    HashMap<String, List<Option>> OptionMap = new HashMap<String, List<Option>>();

    HashMap formSelect =
        new HashMap(); // tells the JSP what select lists are populated, and thus should be
                       // displayed
    request.setAttribute("formSelect", formSelect);

    // add the options
    foo.setOptionLists(OptionMap);
    epo.setFormObject(foo);

    // funky hack because Ontology.getURI() will append a hash for a hash namespace
    // See OntologyDaoJena.ontologyFromOntologyResource() comments
    String realURI = OntologyDaoJena.adjustOntologyURI(o.getURI());
    request.setAttribute("realURI", realURI);
    request.setAttribute("exportURL", request.getContextPath() + Controllers.EXPORT_RDF);

    RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
    request.setAttribute("epoKey", epo.getKey());
    request.setAttribute("bodyJsp", "/templates/edit/specific/ontologies_edit.jsp");
    request.setAttribute("title", "Ontology Control Panel");
    request.setAttribute(
        "css",
        "<link rel=\"stylesheet\" type=\"text/css\" href=\""
            + request.getAppBean().getThemeDir()
            + "css/edit.css\"/>");

    try {
      rd.forward(request, response);
    } catch (Exception e) {
      log.error("OntologyEditController could not forward to view.");
      log.error(e.getMessage());
      log.error(e.getStackTrace());
    }
  }
예제 #19
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);
   }
 }