protected void setRequestAttributes(HttpServletRequest request, EditProcessObject epo) { VitroRequest vreq = new VitroRequest(request); request.setAttribute("epoKey", epo.getKey()); request.setAttribute("epo", epo); request.setAttribute("globalErrorMsg", epo.getAttribute("globalErrorMsg")); request.setAttribute( "css", "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + vreq.getAppBean().getThemeDir() + "css/edit.css\"/>"); }
protected EditProcessObject createEpo(HttpServletRequest request, boolean forceNew) { /* this is actually a bit of a misnomer, because we will reuse an epo if an epoKey parameter is passed */ EditProcessObject epo = null; HashMap epoHash = getEpoHash(request); String existingEpoKey = request.getParameter("_epoKey"); if (!forceNew && existingEpoKey != null && epoHash.get(existingEpoKey) != null) { epo = (EditProcessObject) epoHash.get(existingEpoKey); epo.setKey(existingEpoKey); epo.setUseRecycledBean(true); } else { LinkedList epoKeylist = getEpoKeylist(request); if (epoHash.size() == MAX_EPOS) { try { epoHash.remove(epoKeylist.getFirst()); epoKeylist.removeFirst(); } catch (Exception e) { // see JIRA issue VITRO-340, "Odd exception from backend editing" // possible rare concurrency issue here log.error("Error removing old EPO", e); } } Random rand = new Random(); String epoKey = createEpoKey(); while (epoHash.get(epoKey) != null) { epoKey += Integer.toHexString(rand.nextInt()); } epo = new EditProcessObject(); epoHash.put(epoKey, epo); epoKeylist.add(epoKey); epo.setKey(epoKey); epo.setReferer( (forceNew) ? request.getRequestURL().append('?').append(request.getQueryString()).toString() : request.getHeader("Referer")); epo.setSession(request.getSession()); } return epo; }
private void tryRestriction( OntClass theClass, VClassDao vcDao, ObjectPropertyDao opDao, IndividualDao iDao, ArrayList results, String vClassURI) { if (theClass.isRestriction()) { Restriction rest = (Restriction) theClass.as(Restriction.class); try { results.add("XX"); Property onProperty = rest.getOnProperty(); ObjectProperty op = opDao.getObjectPropertyByURI(onProperty.getURI()); results.add(op.getLocalNameWithPrefix()); if (rest.isAllValuesFromRestriction()) { results.add("all values from"); AllValuesFromRestriction avfrest = (AllValuesFromRestriction) rest.as(AllValuesFromRestriction.class); Resource allValuesFrom = avfrest.getAllValuesFrom(); results.add(printAsClass(vcDao, allValuesFrom)); } else if (rest.isSomeValuesFromRestriction()) { results.add("some values from"); SomeValuesFromRestriction svfrest = (SomeValuesFromRestriction) rest.as(SomeValuesFromRestriction.class); Resource someValuesFrom = svfrest.getSomeValuesFrom(); results.add(printAsClass(vcDao, someValuesFrom)); } else if (rest.isHasValueRestriction()) { results.add("has value"); HasValueRestriction hvrest = (HasValueRestriction) rest.as(HasValueRestriction.class); RDFNode hasValue = hvrest.getHasValue(); if (hasValue.isResource()) { Resource hasValueRes = (Resource) hasValue.as(Resource.class); try { if (hasValueRes.getURI() != null) { Individual ind = iDao.getIndividualByURI(hasValueRes.getURI()); if (ind.getName() != null) { results.add(ind.getName()); } } } catch (Exception e) { results.add("???"); } } } else if (rest.isMinCardinalityRestriction()) { MinCardinalityRestriction crest = (MinCardinalityRestriction) rest.as(MinCardinalityRestriction.class); results.add("at least " + crest.getMinCardinality()); results.add(LAMBDA); } else if (rest.isMaxCardinalityRestriction()) { MaxCardinalityRestriction crest = (MaxCardinalityRestriction) rest.as(MaxCardinalityRestriction.class); results.add("at most " + crest.getMaxCardinality()); results.add(LAMBDA); } else if (rest.isCardinalityRestriction()) { CardinalityRestriction crest = (CardinalityRestriction) rest.as(CardinalityRestriction.class); results.add("exactly " + crest.getCardinality()); results.add(LAMBDA); } results.add( "<form action=\"addRestriction\" method=\"post\">" + "<input type=\"hidden\" name=\"_action\" value=\"delete\"/>" + "<input type=\"submit\" value=\"Delete\"/>" + "<input type=\"hidden\" name=\"_epoKey\" value=\"" + epo.getKey() + "\"/>" + "<input type=\"hidden\" name=\"classUri\" value=\"" + vClassURI + "\"/>" + "<input type=\"hidden\" name=\"restrictionId\" value=\"" + ((rest.getId() != null) ? rest.getId() : rest.getURI()) + "\"/>" + "</form>"); } catch (Exception e) { e.printStackTrace(); // results.add("unknown property"); } } }
@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()); } }
public void doPost(HttpServletRequest request, HttpServletResponse response) { final int NUM_COLS = 17; if (!checkLoginStatus(request, response)) return; try { super.doGet(request, response); } catch (Exception e) { log.error("PropertyEditController caught exception calling doGet()"); } VitroRequest vreq = new VitroRequest(request); Portal portal = vreq.getPortal(); ObjectPropertyDao propDao = vreq.getFullWebappDaoFactory().getObjectPropertyDao(); VClassDao vcDao = vreq.getFullWebappDaoFactory().getVClassDao(); PropertyGroupDao pgDao = vreq.getFullWebappDaoFactory().getPropertyGroupDao(); ObjectProperty p = (ObjectProperty) propDao.getObjectPropertyByURI(request.getParameter("uri")); request.setAttribute("property", p); ArrayList<String> results = new ArrayList<String>(); results.add("Property"); // column 1 results.add("parent property"); // column 2 results.add("domain"); // column 3 results.add("range"); // column 4 results.add("display name"); // column 5 results.add("group"); // column 6 results.add("display tier"); // column 7 results.add("example"); // column 8 results.add("description"); // column 9 results.add("public description"); // column 10 results.add("display level"); // column 11 results.add("update level"); // column 12 results.add("custom entry form"); // column 13 results.add("select from existing"); // column 14 results.add("offer create new option"); // column 15 results.add("force stub object deletion"); // column 16 results.add("URI"); // column 17 String displayName = (p.getDomainPublic() == null) ? p.getLocalName() : p.getDomainPublic(); try { results.add( "<a href=\"propertyEdit?uri=" + URLEncoder.encode(p.getURI(), "UTF-8") + "\">" + displayName + "</a> <em>" + p.getLocalNameWithPrefix() + "</em>"); // column 1 } catch (UnsupportedEncodingException e) { log.error( "Could not encode URI for property (domain public: " + p.getDomainPublic() + ", local name with prefix: " + p.getLocalNameWithPrefix() + ", URI: " + p.getURI() + ")."); results.add(displayName + "<em>" + p.getLocalNameWithPrefix() + "</em>"); // column 1 } String parentPropertyStr = ""; if (p.getParentURI() != null) { ObjectProperty parent = propDao.getObjectPropertyByURI(p.getParentURI()); if (parent != null && parent.getURI() != null) { try { parentPropertyStr = "<a href=\"propertyEdit?uri=" + URLEncoder.encode(parent.getURI(), "UTF-8") + "&home=" + portal.getPortalId() + "\">" + parent.getLocalNameWithPrefix() + "</a>"; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } results.add(parentPropertyStr); // column 2 String domainStr = ""; if (p.getDomainVClassURI() != null) { VClass domainClass = vcDao.getVClassByURI(p.getDomainVClassURI()); if (domainClass != null && domainClass.getURI() != null && domainClass.getLocalNameWithPrefix() != null) { try { if (domainClass.isAnonymous()) { domainStr = domainClass.getLocalNameWithPrefix(); } else { domainStr = "<a href=\"vclassEdit?uri=" + URLEncoder.encode(domainClass.getURI(), "UTF-8") + "&home=" + portal.getPortalId() + "\">" + domainClass.getLocalNameWithPrefix() + "</a>"; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } results.add(domainStr); // column 3 String rangeStr = ""; if (p.getRangeVClassURI() != null) { VClass rangeClass = vcDao.getVClassByURI(p.getRangeVClassURI()); if (rangeClass != null && rangeClass.getURI() != null && rangeClass.getLocalNameWithPrefix() != null) { try { if (rangeClass.isAnonymous()) { rangeStr = rangeClass.getLocalNameWithPrefix(); } else { rangeStr = "<a href=\"vclassEdit?uri=" + URLEncoder.encode(rangeClass.getURI(), "UTF-8") + "&home=" + portal.getPortalId() + "\">" + rangeClass.getLocalNameWithPrefix() + "</a>"; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } results.add(rangeStr); // column 4 results.add(p.getDomainPublic() == null ? "" : p.getDomainPublic()); // column 5 if (p.getGroupURI() != null) { PropertyGroup pGroup = pgDao.getGroupByURI(p.getGroupURI()); if (pGroup != null) { results.add(pGroup.getName()); // column 6 } else { results.add("unnamed group"); // column 6 } } else { results.add("unspecified"); // column 6 } results.add( "domain: " + p.getDomainDisplayTier() + ", range: " + p.getRangeDisplayTier()); // column 7 String exampleStr = (p.getExample() == null) ? "" : p.getExample(); results.add(exampleStr); // column 8 String descriptionStr = (p.getDescription() == null) ? "" : p.getDescription(); results.add(descriptionStr); // column 9 String publicDescriptionStr = (p.getPublicDescription() == null) ? "" : p.getPublicDescription(); results.add(publicDescriptionStr); // column 10 results.add( p.getHiddenFromDisplayBelowRoleLevel() == null ? "unspecified" : p.getHiddenFromDisplayBelowRoleLevel().getLabel()); // column 11 results.add( p.getProhibitedFromUpdateBelowRoleLevel() == null ? "unspecified" : p.getProhibitedFromUpdateBelowRoleLevel().getLabel()); // column 12 results.add( p.getCustomEntryForm() == null ? "unspecified" : p.getCustomEntryForm()); // column 13 results.add(p.getSelectFromExisting() ? "true" : "false"); // column 14 results.add(p.getOfferCreateNewOption() ? "true" : "false"); // column 15 results.add(p.getStubObjectRelation() ? "true" : "false"); // column 16 results.add(p.getURI()); // column 17 request.setAttribute("results", results); request.setAttribute("columncount", NUM_COLS); request.setAttribute("suppressquery", "true"); boolean FORCE_NEW = true; EditProcessObject epo = super.createEpo(request, FORCE_NEW); FormObject foo = new FormObject(); HashMap OptionMap = new HashMap(); foo.setOptionLists(OptionMap); epo.setFormObject(foo); // superproperties and subproperties ObjectPropertyDao opDao; if (vreq.getAssertionsWebappDaoFactory() != null) { opDao = vreq.getAssertionsWebappDaoFactory().getObjectPropertyDao(); } else { opDao = vreq.getFullWebappDaoFactory().getObjectPropertyDao(); } List superURIs = opDao.getSuperPropertyURIs(p.getURI(), false); List superProperties = new ArrayList(); Iterator superURIit = superURIs.iterator(); while (superURIit.hasNext()) { String superURI = (String) superURIit.next(); if (superURI != null) { ObjectProperty superProperty = opDao.getObjectPropertyByURI(superURI); if (superProperty != null) { superProperties.add(superProperty); } } } request.setAttribute("superproperties", superProperties); List subURIs = opDao.getSubPropertyURIs(p.getURI()); List subProperties = new ArrayList(); Iterator subURIit = subURIs.iterator(); while (subURIit.hasNext()) { String subURI = (String) subURIit.next(); ObjectProperty subProperty = opDao.getObjectPropertyByURI(subURI); if (subProperty != null) { subProperties.add(subProperty); } } request.setAttribute("subproperties", subProperties); List eqURIs = opDao.getEquivalentPropertyURIs(p.getURI()); List eqProperties = new ArrayList(); Iterator eqURIit = eqURIs.iterator(); while (eqURIit.hasNext()) { String eqURI = (String) eqURIit.next(); ObjectProperty eqProperty = opDao.getObjectPropertyByURI(eqURI); if (eqProperty != null) { eqProperties.add(eqProperty); } } request.setAttribute("equivalentProperties", eqProperties); RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); request.setAttribute("epoKey", epo.getKey()); request.setAttribute("propertyWebapp", p); request.setAttribute("bodyJsp", "/templates/edit/specific/props_edit.jsp"); request.setAttribute("portalBean", portal); request.setAttribute("title", "Object Property Control Panel"); request.setAttribute( "css", "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + portal.getThemeDir() + "css/edit.css\"/>"); try { rd.forward(request, response); } catch (Exception e) { log.error("PropertyEditController could not forward to view."); log.error(e.getMessage()); log.error(e.getStackTrace()); } }