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 protected ResponseValues processRequest(VitroRequest vreq) { Map<String, Object> body = new HashMap<String, Object>(); String displayOption = ""; if (vreq.getParameter("displayOption") != null) { displayOption = vreq.getParameter("displayOption"); } else { displayOption = "asserted"; } body.put("displayOption", displayOption); boolean inferred = (displayOption.equals("inferred")); if (inferred) { body.put("pageTitle", "Inferred Class Hierarchy"); } else { body.put("pageTitle", "Asserted Class Hierarchy"); } if (!inferred) { vcDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getVClassDao(); } else { vcDao = vreq.getUnfilteredWebappDaoFactory().getVClassDao(); } String json = new String(); String ontologyUri = vreq.getParameter("ontologyUri"); String startClassUri = vreq.getParameter("vclassUri"); List<VClass> roots = null; if (ontologyUri != null) { roots = vcDao.getOntologyRootClasses(ontologyUri); } else if (startClassUri != null) { roots = new LinkedList<VClass>(); roots.add(vcDao.getVClassByURI(startClassUri)); } else { roots = vcDao.getRootClasses(); } if (roots.isEmpty()) { roots = new LinkedList<VClass>(); roots.add(vreq.getUnfilteredWebappDaoFactory().getVClassDao().getTopConcept()); } sortForPickList(roots, vreq); int counter = 0; Iterator<VClass> rootIt = roots.iterator(); if (!rootIt.hasNext()) { VClass vcw = new VClass(); vcw.setName("<strong>No classes found.</strong>"); json += addVClassDataToResultsList( vreq.getUnfilteredWebappDaoFactory(), vcw, 0, ontologyUri, counter); } else { while (rootIt.hasNext()) { VClass root = (VClass) rootIt.next(); if (root != null) { json += addChildren( vreq.getUnfilteredWebappDaoFactory(), root, 0, ontologyUri, counter, vreq); counter += 1; } } int length = json.length(); if (length > 0) { json += " }"; } } body.put("jsonTree", json); return new TemplateResponseValues(TEMPLATE_NAME, body); }
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); } }