NIHVIVO-3771 new object and data property hierarchies and listings
This commit is contained in:
parent
3646a214a5
commit
8ee4d7cd8e
11 changed files with 1250 additions and 33 deletions
|
@ -0,0 +1,160 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Datatype;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
|
||||
public class ListDatatypePropertiesController extends FreemarkerHttpServlet {
|
||||
|
||||
private static Log log = LogFactory.getLog( ListDatatypePropertiesController.class );
|
||||
|
||||
private static final String TEMPLATE_NAME = "siteAdmin-objectPropHierarchy.ftl";
|
||||
|
||||
@Override
|
||||
protected Actions requiredActions(VitroRequest vreq) {
|
||||
return SimplePermission.EDIT_ONTOLOGY.ACTIONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
try {
|
||||
|
||||
body.put("displayOption", "all");
|
||||
body.put("pageTitle", "All Data Properties");
|
||||
body.put("propertyType", "data");
|
||||
|
||||
String noResultsMsgStr = "No data properties found";
|
||||
|
||||
String ontologyUri = vreq.getParameter("ontologyUri");
|
||||
|
||||
DataPropertyDao dao = vreq.getFullWebappDaoFactory().getDataPropertyDao();
|
||||
VClassDao vcDao = vreq.getFullWebappDaoFactory().getVClassDao();
|
||||
DatatypeDao dDao = vreq.getFullWebappDaoFactory().getDatatypeDao();
|
||||
PropertyGroupDao pgDao = vreq.getFullWebappDaoFactory().getPropertyGroupDao();
|
||||
|
||||
List<DataProperty> props = new ArrayList<DataProperty>();
|
||||
if (vreq.getParameter("propsForClass") != null) {
|
||||
noResultsMsgStr = "There are no data properties that apply to this class.";
|
||||
Collection <DataProperty> dataProps = dao.getDataPropertiesForVClass(vreq.getParameter("vclassUri"));
|
||||
Iterator<DataProperty> dataPropIt = dataProps.iterator();
|
||||
HashSet<String> propURIs = new HashSet<String>();
|
||||
while (dataPropIt.hasNext()) {
|
||||
DataProperty dp = dataPropIt.next();
|
||||
if (!(propURIs.contains(dp.getURI()))) {
|
||||
propURIs.add(dp.getURI());
|
||||
DataProperty prop = dao.getDataPropertyByURI(dp.getURI());
|
||||
if (prop != null) {
|
||||
props.add(prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
props = dao.getAllDataProperties();
|
||||
}
|
||||
|
||||
if (ontologyUri != null) {
|
||||
List<DataProperty> scratch = new ArrayList<DataProperty>();
|
||||
for (DataProperty p: props) {
|
||||
if (p.getNamespace().equals(ontologyUri)) {
|
||||
scratch.add(p);
|
||||
}
|
||||
}
|
||||
props = scratch;
|
||||
}
|
||||
|
||||
if (props != null) {
|
||||
Collections.sort(props);
|
||||
}
|
||||
|
||||
String json = new String();
|
||||
int counter = 0;
|
||||
|
||||
if (props != null) {
|
||||
if (props.size()==0) {
|
||||
json = "{ \"name\": \"" + noResultsMsgStr + "\" }";
|
||||
} else {
|
||||
for (DataProperty prop: props) {
|
||||
if ( counter > 0 ) {
|
||||
json += ", ";
|
||||
}
|
||||
|
||||
String nameStr = prop.getPublicName()==null ? prop.getName()==null ? prop.getURI()==null ? "(no name)" : prop.getURI() : prop.getName() : prop.getPublicName();
|
||||
try {
|
||||
json += "{ \"name\": \"<a href='datapropEdit?uri="+URLEncoder.encode(prop.getURI(),"UTF-8")+"'>" + nameStr + "</a>\", ";
|
||||
} catch (Exception e) {
|
||||
json += "{ \"name\": \"" + nameStr + "\", ";
|
||||
}
|
||||
|
||||
json += "\"data\": { \"internalName\": \"" + prop.getLocalNameWithPrefix() + "\", ";
|
||||
|
||||
/* VClass vc = null;
|
||||
String domainStr="";
|
||||
if (prop.getDomainClassURI() != null) {
|
||||
vc = vcDao.getVClassByURI(prop.getDomainClassURI());
|
||||
if (vc != null) {
|
||||
try {
|
||||
domainStr="<a href=\"vclassEdit?uri="+URLEncoder.encode(prop.getDomainClassURI(),"UTF-8")+"\">"+vc.getName()+"</a>";
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
VClass vc = (prop.getDomainClassURI() != null) ? vcDao.getVClassByURI(prop.getDomainClassURI()) : null;
|
||||
String domainStr = (vc != null) ? vc.getLocalNameWithPrefix() : "";
|
||||
json += "\"domainVClass\": \"" + domainStr + "\", " ;
|
||||
|
||||
Datatype rangeDatatype = dDao.getDatatypeByURI(prop.getRangeDatatypeURI());
|
||||
String rangeDatatypeStr = (rangeDatatype==null)?prop.getRangeDatatypeURI():rangeDatatype.getName();
|
||||
json += "\"rangeVClass\": \"" + rangeDatatypeStr + "\", " ;
|
||||
|
||||
if (prop.getGroupURI() != null) {
|
||||
PropertyGroup pGroup = pgDao.getGroupByURI(prop.getGroupURI());
|
||||
json += "\"group\": \"" + ((pGroup == null) ? "unknown group" : pGroup.getName()) + "\" } } " ;
|
||||
} else {
|
||||
json += "\"group\": \"unspecified\" } }" ;
|
||||
}
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
body.put("jsonTree",json);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
return new TemplateResponseValues(TEMPLATE_NAME, body);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,190 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyInstance;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
|
||||
public class ListPropertyWebappsController extends FreemarkerHttpServlet {
|
||||
private static Log log = LogFactory.getLog( ListPropertyWebappsController.class );
|
||||
|
||||
private static final String TEMPLATE_NAME = "siteAdmin-objectPropHierarchy.ftl";
|
||||
|
||||
@Override
|
||||
protected Actions requiredActions(VitroRequest vreq) {
|
||||
return SimplePermission.EDIT_ONTOLOGY.ACTIONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
try {
|
||||
|
||||
body.put("displayOption", "all");
|
||||
body.put("pageTitle", "All Object Properties");
|
||||
body.put("propertyType", "object");
|
||||
|
||||
String noResultsMsgStr = "No object properties found";
|
||||
|
||||
String ontologyUri = vreq.getParameter("ontologyUri");
|
||||
|
||||
ObjectPropertyDao dao = vreq.getFullWebappDaoFactory().getObjectPropertyDao();
|
||||
PropertyInstanceDao piDao = vreq.getFullWebappDaoFactory().getPropertyInstanceDao();
|
||||
VClassDao vcDao = vreq.getFullWebappDaoFactory().getVClassDao();
|
||||
PropertyGroupDao pgDao = vreq.getFullWebappDaoFactory().getPropertyGroupDao();
|
||||
|
||||
String vclassURI = vreq.getParameter("vclassUri");
|
||||
|
||||
List props = new ArrayList();
|
||||
if (vreq.getParameter("propsForClass") != null) {
|
||||
noResultsMsgStr = "There are no object properties that apply to this class.";
|
||||
|
||||
// incomplete list of classes to check, but better than before
|
||||
List<String> superclassURIs = vcDao.getAllSuperClassURIs(vclassURI);
|
||||
superclassURIs.add(vclassURI);
|
||||
superclassURIs.addAll(vcDao.getEquivalentClassURIs(vclassURI));
|
||||
|
||||
Map<String, PropertyInstance> propInstMap = new HashMap<String, PropertyInstance>();
|
||||
for (String classURI : superclassURIs) {
|
||||
Collection<PropertyInstance> propInsts = piDao.getAllPropInstByVClass(classURI);
|
||||
for (PropertyInstance propInst : propInsts) {
|
||||
propInstMap.put(propInst.getPropertyURI(), propInst);
|
||||
}
|
||||
}
|
||||
List<PropertyInstance> propInsts = new ArrayList<PropertyInstance>();
|
||||
propInsts.addAll(propInstMap.values());
|
||||
Collections.sort(propInsts);
|
||||
|
||||
Iterator propInstIt = propInsts.iterator();
|
||||
HashSet propURIs = new HashSet();
|
||||
while (propInstIt.hasNext()) {
|
||||
PropertyInstance pi = (PropertyInstance) propInstIt.next();
|
||||
if (!(propURIs.contains(pi.getPropertyURI()))) {
|
||||
propURIs.add(pi.getPropertyURI());
|
||||
ObjectProperty prop = (ObjectProperty) dao.getObjectPropertyByURI(pi.getPropertyURI());
|
||||
if (prop != null) {
|
||||
props.add(prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
props = (vreq.getParameter("iffRoot")!=null)
|
||||
? dao.getRootObjectProperties()
|
||||
: dao.getAllObjectProperties();
|
||||
}
|
||||
|
||||
OntologyDao oDao = vreq.getFullWebappDaoFactory().getOntologyDao();
|
||||
HashMap<String,String> ontologyHash = new HashMap<String,String>();
|
||||
|
||||
Iterator propIt = props.iterator();
|
||||
List<ObjectProperty> scratch = new ArrayList();
|
||||
while (propIt.hasNext()) {
|
||||
ObjectProperty p = (ObjectProperty) propIt.next();
|
||||
if (p.getNamespace()!=null) {
|
||||
if( !ontologyHash.containsKey( p.getNamespace() )){
|
||||
Ontology o = (Ontology)oDao.getOntologyByURI(p.getNamespace());
|
||||
if (o==null) {
|
||||
if (!VitroVocabulary.vitroURI.equals(p.getNamespace())) {
|
||||
log.debug("doGet(): no ontology object found for the namespace "+p.getNamespace());
|
||||
}
|
||||
} else {
|
||||
ontologyHash.put(p.getNamespace(), o.getName() == null ? p.getNamespace() : o.getName());
|
||||
}
|
||||
}
|
||||
if (ontologyUri != null && p.getNamespace().equals(ontologyUri)) {
|
||||
scratch.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ontologyUri != null) {
|
||||
props = scratch;
|
||||
}
|
||||
|
||||
if (props != null) {
|
||||
Collections.sort(props, new ShowObjectPropertyHierarchyController.ObjectPropertyAlphaComparator());
|
||||
}
|
||||
|
||||
String json = new String();
|
||||
int counter = 0;
|
||||
|
||||
if (props != null) {
|
||||
if (props.size()==0) {
|
||||
json = "{ \"name\": \"" + noResultsMsgStr + "\" }";
|
||||
} else {
|
||||
Iterator propsIt = props.iterator();
|
||||
while (propsIt.hasNext()) {
|
||||
if ( counter > 0 ) {
|
||||
json += ", ";
|
||||
}
|
||||
ObjectProperty prop = (ObjectProperty) propsIt.next();
|
||||
|
||||
String propNameStr = ShowObjectPropertyHierarchyController.getDisplayLabel(prop);
|
||||
try {
|
||||
json += "{ \"name\": \"<a href='./propertyEdit?uri="+URLEncoder.encode(prop.getURI(),"UTF-8")+"'>"
|
||||
+ propNameStr + "</a>\", ";
|
||||
} catch (Exception e) {
|
||||
json += "{ \"name\": \"" + propNameStr + "\", ";
|
||||
}
|
||||
|
||||
json += "\"data\": { \"internalName\": \"" + prop.getLocalNameWithPrefix() + "\", ";
|
||||
|
||||
VClass vc = (prop.getDomainVClassURI() != null) ? vcDao.getVClassByURI(prop.getDomainVClassURI()) : null;
|
||||
String domainStr = (vc != null) ? vc.getLocalNameWithPrefix() : "";
|
||||
json += "\"domainVClass\": \"" + domainStr + "\", " ;
|
||||
|
||||
vc = (prop.getRangeVClassURI() != null) ? vcDao.getVClassByURI(prop.getRangeVClassURI()) : null;
|
||||
String rangeStr = (vc != null) ? vc.getLocalNameWithPrefix() : "";
|
||||
json += "\"rangeVClass\": \"" + rangeStr + "\", " ;
|
||||
|
||||
if (prop.getGroupURI() != null) {
|
||||
PropertyGroup pGroup = pgDao.getGroupByURI(prop.getGroupURI());
|
||||
json += "\"group\": \"" + ((pGroup == null) ? "unknown group" : pGroup.getName()) + "\" } } " ;
|
||||
} else {
|
||||
json += "\"group\": \"unspecified\" } }" ;
|
||||
}
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
body.put("jsonTree",json);
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
return new TemplateResponseValues(TEMPLATE_NAME, body);
|
||||
}
|
||||
}
|
|
@ -11,7 +11,6 @@ import java.util.Iterator;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
@ -30,7 +29,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
|||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.email.FreemarkerEmailFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
|
||||
|
@ -47,8 +45,6 @@ public class ShowClassHierarchyController extends FreemarkerHttpServlet {
|
|||
private VClassDao vcDao = null;
|
||||
|
||||
private int previous_posn = 0;
|
||||
private int childCount = 0;
|
||||
private int uriCounter = 0;
|
||||
|
||||
@Override
|
||||
protected Actions requiredActions(VitroRequest vreq) {
|
||||
|
@ -116,7 +112,7 @@ public class ShowClassHierarchyController extends FreemarkerHttpServlet {
|
|||
while (rootIt.hasNext()) {
|
||||
VClass root = (VClass) rootIt.next();
|
||||
if (root != null) {
|
||||
json += addChildren(vreq.getFullWebappDaoFactory(), root, 0, ontologyUri,counter,"parent");
|
||||
json += addChildren(vreq.getFullWebappDaoFactory(), root, 0, ontologyUri,counter);
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +130,7 @@ public class ShowClassHierarchyController extends FreemarkerHttpServlet {
|
|||
return new TemplateResponseValues(TEMPLATE_NAME, body);
|
||||
}
|
||||
|
||||
private String addChildren(WebappDaoFactory wadf, VClass parent, int position, String ontologyUri, int counter, String status) {
|
||||
private String addChildren(WebappDaoFactory wadf, VClass parent, int position, String ontologyUri, int counter) {
|
||||
String rowElts = addVClassDataToResultsList(wadf, parent, position, ontologyUri, counter);
|
||||
int childShift = (rowElts.length() > 0) ? 1 : 0; // if addVClassDataToResultsList filtered out the result, don't shift the children over
|
||||
int length = rowElts.length();
|
||||
|
@ -157,7 +153,7 @@ public class ShowClassHierarchyController extends FreemarkerHttpServlet {
|
|||
Iterator childClassIt = childClasses.iterator();
|
||||
while (childClassIt.hasNext()) {
|
||||
VClass child = (VClass) childClassIt.next();
|
||||
leaves += addChildren(wadf, child, position + childShift, ontologyUri, counter, "child");
|
||||
leaves += addChildren(wadf, child, position + childShift, ontologyUri, counter);
|
||||
if (!childClassIt.hasNext()) {
|
||||
if ( ontologyUri == null ) {
|
||||
leaves += " }] ";
|
||||
|
@ -166,15 +162,12 @@ public class ShowClassHierarchyController extends FreemarkerHttpServlet {
|
|||
// need this for when we show the classes associated with an ontology
|
||||
String ending = leaves.substring(leaves.length() - 2, leaves.length());
|
||||
if ( ending.equals("] ") ) {
|
||||
log.debug("[1] leaves += }]");
|
||||
leaves += "}]";
|
||||
}
|
||||
else if ( ending.equals(" [") ){
|
||||
log.debug("[2] leaves += ]");
|
||||
leaves += "] ";
|
||||
}
|
||||
else {
|
||||
log.debug("[3] leaves += }]");
|
||||
leaves += "}]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,251 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Datatype;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
|
||||
public class ShowDataPropertyHierarchyController extends FreemarkerHttpServlet {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ShowDataPropertyHierarchyController.class.getName());
|
||||
|
||||
private static final String TEMPLATE_NAME = "siteAdmin-objectPropHierarchy.ftl";
|
||||
private int MAXDEPTH = 5;
|
||||
|
||||
private DataPropertyDao dpDao = null;
|
||||
private VClassDao vcDao = null;
|
||||
private PropertyGroupDao pgDao = null;
|
||||
private DatatypeDao dDao = null;
|
||||
|
||||
private int previous_posn = 0;
|
||||
|
||||
@Override
|
||||
protected Actions requiredActions(VitroRequest vreq) {
|
||||
return SimplePermission.EDIT_ONTOLOGY.ACTIONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
try {
|
||||
|
||||
String displayOption = "";
|
||||
|
||||
if ( vreq.getParameter("displayOption") != null ) {
|
||||
displayOption = vreq.getParameter("displayOption");
|
||||
}
|
||||
else {
|
||||
displayOption = "hierarchy";
|
||||
}
|
||||
body.put("displayOption", displayOption);
|
||||
|
||||
if ( displayOption.equals("all") ) {
|
||||
body.put("pageTitle", "All Data Properties");
|
||||
}
|
||||
else {
|
||||
body.put("pageTitle", "Data Property Hierarchy");
|
||||
}
|
||||
|
||||
body.put("propertyType", "data");
|
||||
|
||||
dpDao = vreq.getAssertionsWebappDaoFactory().getDataPropertyDao();
|
||||
vcDao = vreq.getAssertionsWebappDaoFactory().getVClassDao();
|
||||
pgDao = vreq.getAssertionsWebappDaoFactory().getPropertyGroupDao();
|
||||
dDao = vreq.getAssertionsWebappDaoFactory().getDatatypeDao();
|
||||
|
||||
String json = new String();
|
||||
|
||||
String ontologyUri = vreq.getParameter("ontologyUri");
|
||||
String startPropertyUri = vreq.getParameter("propertyUri");
|
||||
|
||||
List<DataProperty> roots = null;
|
||||
|
||||
if (startPropertyUri != null) {
|
||||
roots = new LinkedList<DataProperty>();
|
||||
roots.add(dpDao.getDataPropertyByURI(startPropertyUri));
|
||||
} else {
|
||||
roots = dpDao.getRootDataProperties();
|
||||
if (roots!=null){
|
||||
Collections.sort(roots);
|
||||
}
|
||||
}
|
||||
|
||||
int counter = 0;
|
||||
|
||||
if (roots!=null) {
|
||||
Iterator<DataProperty> rootIt = roots.iterator();
|
||||
if (!rootIt.hasNext()) {
|
||||
DataProperty dp = new DataProperty();
|
||||
dp.setURI(ontologyUri+"fake");
|
||||
String notFoundMessage = "<strong>No data properties found.</strong>";
|
||||
dp.setName(notFoundMessage);
|
||||
dp.setName(notFoundMessage);
|
||||
json += addDataPropertyDataToResultsList(dp, 0, ontologyUri, counter);
|
||||
} else {
|
||||
while (rootIt.hasNext()) {
|
||||
DataProperty root = rootIt.next();
|
||||
if ( (ontologyUri==null) || ( (ontologyUri!=null) && (root.getNamespace()!=null) && (ontologyUri.equals(root.getNamespace())) ) ) {
|
||||
json += addChildren(root, 0, ontologyUri, counter);
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
int length = json.length();
|
||||
if ( length > 0 ) {
|
||||
json += " }";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
body.put("jsonTree",json);
|
||||
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
return new TemplateResponseValues(TEMPLATE_NAME, body);
|
||||
}
|
||||
|
||||
private String addChildren(DataProperty parent, int position, String ontologyUri, int counter) {
|
||||
if (parent == null) {
|
||||
return "";
|
||||
}
|
||||
String details = addDataPropertyDataToResultsList(parent, position, ontologyUri, counter);
|
||||
int length = details.length();
|
||||
String leaves = "";
|
||||
leaves += details;
|
||||
List childURIstrs = dpDao.getSubPropertyURIs(parent.getURI());
|
||||
if ((childURIstrs.size()>0) && position<MAXDEPTH) {
|
||||
List childProps = new ArrayList();
|
||||
Iterator childURIstrIt = childURIstrs.iterator();
|
||||
while (childURIstrIt.hasNext()) {
|
||||
String URIstr = (String) childURIstrIt.next();
|
||||
DataProperty child = (DataProperty) dpDao.getDataPropertyByURI(URIstr);
|
||||
childProps.add(child);
|
||||
}
|
||||
Collections.sort(childProps);
|
||||
Iterator childPropIt = childProps.iterator();
|
||||
while (childPropIt.hasNext()) {
|
||||
DataProperty child = (DataProperty) childPropIt.next();
|
||||
leaves += addChildren(child, position+1, ontologyUri, counter);
|
||||
if (!childPropIt.hasNext()) {
|
||||
if ( ontologyUri == null ) {
|
||||
leaves += " }] ";
|
||||
}
|
||||
else if ( ontologyUri != null && length > 0 ) {
|
||||
// need this for when we show the classes associated with an ontology
|
||||
String ending = leaves.substring(leaves.length() - 2, leaves.length());
|
||||
if ( ending.equals("] ") ) {
|
||||
leaves += "}]";
|
||||
}
|
||||
else if ( ending.equals(" [") ){
|
||||
leaves += "] ";
|
||||
}
|
||||
else {
|
||||
leaves += "}]";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( ontologyUri == null ) {
|
||||
leaves += "] ";
|
||||
}
|
||||
else if ( ontologyUri != null && length > 0 ) {
|
||||
leaves += "] ";
|
||||
}
|
||||
}
|
||||
return leaves;
|
||||
}
|
||||
|
||||
private String addDataPropertyDataToResultsList(DataProperty dp, int position, String ontologyUri, int counter) {
|
||||
String tempString = "";
|
||||
if (dp == null) {
|
||||
return tempString;
|
||||
}
|
||||
if (ontologyUri == null || ( (dp.getNamespace()!=null) && (dp.getNamespace().equals(ontologyUri)) ) ) {
|
||||
if ( counter < 1 && position < 1 ) {
|
||||
tempString += "{ \"name\": ";
|
||||
}
|
||||
else if ( position == previous_posn ) {
|
||||
tempString += "}, { \"name\": ";
|
||||
}
|
||||
else if ( position > previous_posn ) {
|
||||
tempString += " { \"name\": ";
|
||||
}
|
||||
else if ( position < previous_posn ) {
|
||||
tempString += "}, { \"name\": ";
|
||||
}
|
||||
|
||||
String nameStr = dp.getPublicName()==null ? dp.getName()==null ? dp.getURI()==null ? "(no name)" : dp.getURI() : dp.getName() : dp.getPublicName();
|
||||
try {
|
||||
tempString += "\"<a href='datapropEdit?uri="+URLEncoder.encode(dp.getURI(),"UTF-8")+"'>" + nameStr + "</a>\", ";
|
||||
} catch (Exception e) {
|
||||
tempString += "\"" + nameStr + "\", ";
|
||||
log.error("Unsupported: URLEncoder.encode() with UTF-8");
|
||||
}
|
||||
|
||||
tempString += "\"data\": { \"internalName\": \"" + dp.getLocalNameWithPrefix() + "\", ";
|
||||
|
||||
VClass tmp = null;
|
||||
try {
|
||||
tempString += "\"domainVClass\": \"" + (((tmp = vcDao.getVClassByURI(dp.getDomainClassURI())) != null && (tmp.getLocalNameWithPrefix() == null)) ? "" : vcDao.getVClassByURI(dp.getDomainClassURI()).getLocalNameWithPrefix()) + "\", " ;
|
||||
} catch (NullPointerException e) {
|
||||
tempString += "\"domainVClass\": \"\",";
|
||||
}
|
||||
try {
|
||||
Datatype rangeDatatype = dDao.getDatatypeByURI(dp.getRangeDatatypeURI());
|
||||
String rangeDatatypeStr = (rangeDatatype==null)?dp.getRangeDatatypeURI():rangeDatatype.getName();
|
||||
tempString += "\"rangeVClass\": \"" + ((rangeDatatypeStr != null) ? rangeDatatypeStr : "") + "\", " ;
|
||||
} catch (NullPointerException e) {
|
||||
tempString += "\"rangeVClass\": \"\",";
|
||||
}
|
||||
if (dp.getGroupURI() != null) {
|
||||
PropertyGroup pGroup = pgDao.getGroupByURI(dp.getGroupURI());
|
||||
tempString += "\"group\": \"" + ((pGroup == null) ? "unknown group" : pGroup.getName()) + "\" " ;
|
||||
} else {
|
||||
tempString += "\"group\": \"unspecified\"";
|
||||
}
|
||||
tempString += "}, \"children\": [";
|
||||
|
||||
previous_posn = position;
|
||||
}
|
||||
return tempString;
|
||||
}
|
||||
|
||||
private class DataPropertyAlphaComparator implements Comparator {
|
||||
public int compare(Object o1, Object o2) {
|
||||
return Collator.getInstance().compare( ((DataProperty)o1).getName(), ((DataProperty)o2).getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,275 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
|
||||
public class ShowObjectPropertyHierarchyController extends FreemarkerHttpServlet {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ShowObjectPropertyHierarchyController.class.getName());
|
||||
|
||||
private static final String TEMPLATE_NAME = "siteAdmin-objectPropHierarchy.ftl";
|
||||
|
||||
private int MAXDEPTH = 5;
|
||||
|
||||
private ObjectPropertyDao opDao = null;
|
||||
private VClassDao vcDao = null;
|
||||
private PropertyGroupDao pgDao = null;
|
||||
|
||||
private int previous_posn = 0;
|
||||
|
||||
@Override
|
||||
protected Actions requiredActions(VitroRequest vreq) {
|
||||
return SimplePermission.EDIT_ONTOLOGY.ACTIONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
try {
|
||||
|
||||
String displayOption = "";
|
||||
|
||||
if ( vreq.getParameter("displayOption") != null ) {
|
||||
displayOption = vreq.getParameter("displayOption");
|
||||
}
|
||||
else {
|
||||
displayOption = "hierarchy";
|
||||
}
|
||||
body.put("displayOption", displayOption);
|
||||
|
||||
if ( displayOption.equals("all") ) {
|
||||
body.put("pageTitle", "All Object Properties");
|
||||
}
|
||||
else {
|
||||
body.put("pageTitle", "Object Property Hierarchy");
|
||||
}
|
||||
|
||||
body.put("propertyType", "object");
|
||||
|
||||
opDao = vreq.getAssertionsWebappDaoFactory().getObjectPropertyDao();
|
||||
vcDao = vreq.getAssertionsWebappDaoFactory().getVClassDao();
|
||||
pgDao = vreq.getAssertionsWebappDaoFactory().getPropertyGroupDao();
|
||||
|
||||
String json = new String();
|
||||
|
||||
String ontologyUri = vreq.getParameter("ontologyUri");
|
||||
String startPropertyUri = vreq.getParameter("propertyUri");
|
||||
|
||||
List<ObjectProperty> roots = null;
|
||||
|
||||
if (startPropertyUri != null) {
|
||||
roots = new LinkedList<ObjectProperty>();
|
||||
ObjectProperty op = opDao.getObjectPropertyByURI(startPropertyUri);
|
||||
if (op == null) {
|
||||
op = new ObjectProperty();
|
||||
op.setURI(startPropertyUri);
|
||||
}
|
||||
roots.add(op);
|
||||
} else {
|
||||
roots = opDao.getRootObjectProperties();
|
||||
if (roots!=null){
|
||||
Collections.sort(roots, new ObjectPropertyAlphaComparator()); // sorts by domain public
|
||||
}
|
||||
}
|
||||
|
||||
int counter = 0;
|
||||
|
||||
if (roots != null) {
|
||||
Iterator<ObjectProperty> rootIt = roots.iterator();
|
||||
if (!rootIt.hasNext()) {
|
||||
ObjectProperty op = new ObjectProperty();
|
||||
op.setURI(ontologyUri+"fake");
|
||||
String notFoundMessage = "<strong>No object properties found.</strong>";
|
||||
op.setDomainPublic(notFoundMessage);
|
||||
json += addObjectPropertyDataToResultsList(op, 0, ontologyUri, counter);
|
||||
} else {
|
||||
while (rootIt.hasNext()) {
|
||||
ObjectProperty root = rootIt.next();
|
||||
if ( (ontologyUri==null) ||
|
||||
( (ontologyUri != null)
|
||||
&& (root.getNamespace() != null)
|
||||
&& (ontologyUri.equals(root.getNamespace())) ) ) {
|
||||
json += addChildren(root, 0, ontologyUri, counter);
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
int length = json.length();
|
||||
if ( length > 0 ) {
|
||||
json += " }";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
body.put("jsonTree",json);
|
||||
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
return new TemplateResponseValues(TEMPLATE_NAME, body);
|
||||
|
||||
}
|
||||
|
||||
private String addChildren(ObjectProperty parent, int position, String ontologyUri, int counter) {
|
||||
String details = addObjectPropertyDataToResultsList(parent, position, ontologyUri, counter);
|
||||
int length = details.length();
|
||||
String leaves = "";
|
||||
leaves += details;
|
||||
List childURIstrs = opDao.getSubPropertyURIs(parent.getURI());
|
||||
if ((childURIstrs.size()>0) && position<MAXDEPTH) {
|
||||
List childProps = new ArrayList();
|
||||
Iterator childURIstrIt = childURIstrs.iterator();
|
||||
while (childURIstrIt.hasNext()) {
|
||||
String URIstr = (String) childURIstrIt.next();
|
||||
ObjectProperty child = (ObjectProperty) opDao.getObjectPropertyByURI(URIstr);
|
||||
childProps.add(child);
|
||||
}
|
||||
Collections.sort(childProps);
|
||||
Iterator childPropIt = childProps.iterator();
|
||||
while (childPropIt.hasNext()) {
|
||||
ObjectProperty child = (ObjectProperty) childPropIt.next();
|
||||
leaves += addChildren(child, position+1, ontologyUri, counter);
|
||||
if (!childPropIt.hasNext()) {
|
||||
if ( ontologyUri == null ) {
|
||||
leaves += " }] ";
|
||||
}
|
||||
else if ( ontologyUri != null && length > 0 ) {
|
||||
// need this for when we show the classes associated with an ontology
|
||||
String ending = leaves.substring(leaves.length() - 2, leaves.length());
|
||||
if ( ending.equals("] ") ) {
|
||||
leaves += "}]";
|
||||
}
|
||||
else if ( ending.equals(" [") ){
|
||||
leaves += "] ";
|
||||
}
|
||||
else {
|
||||
leaves += "}]";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( ontologyUri == null ) {
|
||||
leaves += "] ";
|
||||
}
|
||||
else if ( ontologyUri != null && length > 0 ) {
|
||||
leaves += "] ";
|
||||
}
|
||||
}
|
||||
return leaves;
|
||||
}
|
||||
|
||||
private String addObjectPropertyDataToResultsList(ObjectProperty op, int position, String ontologyUri, int counter) {
|
||||
String tempString = "";
|
||||
if (ontologyUri == null || ( (op.getNamespace()!=null) && (op.getNamespace().equals(ontologyUri)) ) ) {
|
||||
// first if statement ensures that the first class begins with correct format
|
||||
if ( counter < 1 && position < 1 ) {
|
||||
tempString += "{ \"name\": ";
|
||||
}
|
||||
else if ( position == previous_posn ) {
|
||||
tempString += "}, { \"name\": ";
|
||||
}
|
||||
else if ( position > previous_posn ) {
|
||||
tempString += " { \"name\": ";
|
||||
}
|
||||
else if ( position < previous_posn ) {
|
||||
tempString += "}, { \"name\": ";
|
||||
}
|
||||
|
||||
try {
|
||||
tempString += "\"<a href='propertyEdit?uri="+URLEncoder.encode(op.getURI(),"UTF-8") + "'>" + getDisplayLabel(op)+"</a>\", ";
|
||||
} catch (UnsupportedEncodingException uee) {
|
||||
tempString += "\"" + getDisplayLabel(op) + "\"";
|
||||
log.error("Unsupported: URLEncoder.encode() with UTF-8");
|
||||
}
|
||||
|
||||
tempString += "\"data\": { \"internalName\": \"" + op.getLocalNameWithPrefix() + "\", ";
|
||||
|
||||
VClass tmp = null;
|
||||
|
||||
try {
|
||||
tempString += "\"domainVClass\": \"" + (((tmp = vcDao.getVClassByURI(op.getDomainVClassURI())) != null && (tmp.getLocalNameWithPrefix() == null)) ? "" : vcDao.getVClassByURI(op.getDomainVClassURI()).getLocalNameWithPrefix()) + "\", " ;
|
||||
} catch (NullPointerException e) {
|
||||
tempString += "\"domainVClass\": \"\",";
|
||||
}
|
||||
try {
|
||||
tempString += "\"rangeVClass\": \"" + (((tmp = vcDao.getVClassByURI(op.getRangeVClassURI())) != null && (tmp.getLocalNameWithPrefix() == null)) ? "" : vcDao.getVClassByURI(op.getRangeVClassURI()).getLocalNameWithPrefix()) + "\", " ;
|
||||
} catch (NullPointerException e) {
|
||||
tempString += "\"rangeVClass\": \"\",";
|
||||
}
|
||||
if (op.getGroupURI() != null) {
|
||||
PropertyGroup pGroup = pgDao.getGroupByURI(op.getGroupURI());
|
||||
tempString += "\"group\": \"" + ((pGroup == null) ? "unknown group" : pGroup.getName()) + "\" " ;
|
||||
} else {
|
||||
tempString += "\"group\": \"unspecified\"";
|
||||
}
|
||||
tempString += "}, \"children\": [";
|
||||
|
||||
previous_posn = position;
|
||||
}
|
||||
return tempString;
|
||||
}
|
||||
|
||||
public static class ObjectPropertyAlphaComparator implements Comparator<ObjectProperty> {
|
||||
public int compare(ObjectProperty op1, ObjectProperty op2) {
|
||||
if (op1 == null) {
|
||||
return 1;
|
||||
} else if (op2 == null) {
|
||||
return -1;
|
||||
}
|
||||
String propLabel1 = getDisplayLabel(op1);
|
||||
String propLabel2 = getDisplayLabel(op2);
|
||||
if (propLabel1 == null) {
|
||||
return 1;
|
||||
} else if (propLabel2 == null) {
|
||||
return -1;
|
||||
} else {
|
||||
return Collator.getInstance().compare( propLabel1, propLabel2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* should never be null
|
||||
*/
|
||||
public static String getDisplayLabel(ObjectProperty op) {
|
||||
String domainPublic = op.getDomainPublic();
|
||||
String displayLabel = (domainPublic != null && domainPublic.length() > 0)
|
||||
? domainPublic
|
||||
: op.getLocalName();
|
||||
return (displayLabel != null) ? displayLabel : "[object property]" ;
|
||||
}
|
||||
|
||||
}
|
|
@ -786,38 +786,38 @@
|
|||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>ObjectPropertyHierarchyListingController</servlet-name>
|
||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.edit.listing.ObjectPropertyHierarchyListingController</servlet-class>
|
||||
<servlet-name>ShowObjectPropertyHierarchyController</servlet-name>
|
||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.ShowObjectPropertyHierarchyController</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>ObjectPropertyHierarchyListingController</servlet-name>
|
||||
<servlet-name>ShowObjectPropertyHierarchyController</servlet-name>
|
||||
<url-pattern>/showObjectPropertyHierarchy</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>DataPropertyHierarchyListingController</servlet-name>
|
||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.edit.listing.DataPropertyHierarchyListingController</servlet-class>
|
||||
<servlet-name>ShowDataPropertyHierarchyController</servlet-name>
|
||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.ShowDataPropertyHierarchyController</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>DataPropertyHierarchyListingController</servlet-name>
|
||||
<servlet-name>ShowDataPropertyHierarchyController</servlet-name>
|
||||
<url-pattern>/showDataPropertyHierarchy</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>PropertyWebappsListingController</servlet-name>
|
||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.edit.listing.PropertyWebappsListingController</servlet-class>
|
||||
<servlet-name>ListPropertyWebappsController</servlet-name>
|
||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.ListPropertyWebappsController</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>PropertyWebappsListingController</servlet-name>
|
||||
<servlet-name>ListPropertyWebappsController</servlet-name>
|
||||
<url-pattern>/listPropertyWebapps</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>DatatypePropertiesListingController</servlet-name>
|
||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.edit.listing.DatatypePropertiesListingController</servlet-class>
|
||||
<servlet-name>ListDatatypePropertiesController</servlet-name>
|
||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.ListDatatypePropertiesController</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>DatatypePropertiesListingController</servlet-name>
|
||||
<servlet-name>ListDatatypePropertiesController</servlet-name>
|
||||
<url-pattern>/listDatatypeProperties</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
|
|
|
@ -65,6 +65,11 @@ span#expandAll {
|
|||
float: right;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
span.rangeClass {
|
||||
color:#064D68;
|
||||
padding-left:22px;
|
||||
padding-right:8px;
|
||||
}
|
||||
div#expandLink {
|
||||
margin-top:-10px;
|
||||
width:100%;
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
this.form = $('form#classHierarchyForm');
|
||||
this.select = $('select#displayOption');
|
||||
this.addClass = $('input#addClass');
|
||||
this.addGroup = $('input#addGroup');
|
||||
},
|
||||
|
||||
bindEventListeners: function() {
|
||||
|
@ -49,6 +50,10 @@
|
|||
classHierarchyUtils.form.attr("action", "vclass_retry");
|
||||
classHierarchyUtils.form.submit();
|
||||
});
|
||||
this.addGroup.click(function() {
|
||||
classHierarchyUtils.form.attr("action", "editForm?controller=Classgroup");
|
||||
classHierarchyUtils.form.submit();
|
||||
});
|
||||
},
|
||||
|
||||
buildClassHierarchyHtml: function() {
|
||||
|
@ -148,13 +153,13 @@
|
|||
$clickableHeader.click(function() {
|
||||
if ( $clickableHeader.attr('view') == "less" ) {
|
||||
$clickableHeader.addClass("headerSpanMinus");
|
||||
$('table#classHierarchy' + ctr).find('span').addClass("subclassExpandMinus");
|
||||
$('table#classHierarchy' + ctr).find('span.subclassExpandPlus').addClass("subclassExpandMinus");
|
||||
$('table#classHierarchy' + ctr).find('table.subclassTable').show();
|
||||
$clickableHeader.attr('view', 'more' );
|
||||
}
|
||||
else {
|
||||
$clickableHeader.removeClass("headerSpanMinus");
|
||||
$('table#classHierarchy' + ctr).find('span').removeClass("subclassExpandMinus");
|
||||
$('table#classHierarchy' + ctr).find('span.subclassExpandPlus').removeClass("subclassExpandMinus");
|
||||
$('table#classHierarchy' + ctr).find('table.subclassTable').hide();
|
||||
$clickableHeader.attr('view', 'less' );
|
||||
}
|
||||
|
@ -187,14 +192,14 @@
|
|||
if ( classHierarchyUtils.expandAll.text() == "expand all" ) {
|
||||
classHierarchyUtils.expandAll.text("collapse all");
|
||||
$('span.headerSpanPlus').addClass("headerSpanMinus");
|
||||
$('table.classHierarchy').find('span').addClass("subclassExpandMinus");
|
||||
$('table.classHierarchy').find('span.subclassExpandPlus').addClass("subclassExpandMinus");
|
||||
$('table.classHierarchy').find('table.subclassTable').show();
|
||||
$('section#container').find('span.headerSpanPlus').attr('view','more');
|
||||
}
|
||||
else {
|
||||
classHierarchyUtils.expandAll.text("expand all");
|
||||
$('span.headerSpanPlus').removeClass("headerSpanMinus");
|
||||
$('table.classHierarchy').find('span').removeClass("subclassExpandMinus");
|
||||
$('table.classHierarchy').find('span.subclassExpandPlus').removeClass("subclassExpandMinus");
|
||||
$('table.classHierarchy').find('table.subclassTable').hide();
|
||||
$('section#container').find('span.headerSpanPlus').attr('view','less');
|
||||
}
|
||||
|
|
293
webapp/web/js/siteAdmin/objectPropertyHierarchyUtils.js
Normal file
293
webapp/web/js/siteAdmin/objectPropertyHierarchyUtils.js
Normal file
|
@ -0,0 +1,293 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
var objectPropHierarchyUtils = {
|
||||
onLoad: function(urlBase,displayOption,type) {
|
||||
this.imagePath = urlBase + "/images/";
|
||||
this.propType = type;
|
||||
this.initObjects();
|
||||
this.expandAll.hide();
|
||||
this.checkJsonTree();
|
||||
|
||||
if ( noProps ) {
|
||||
this.buildNoPropsHtml();
|
||||
}
|
||||
else if ( displayOption == "all" ) {
|
||||
this.buildAllPropsHtml();
|
||||
}
|
||||
else {
|
||||
this.buildPropertyHierarchyHtml();
|
||||
this.wireExpandLink();
|
||||
}
|
||||
|
||||
if ( displayOption == "hierarchy" ) {
|
||||
this.expandAll.show();
|
||||
}
|
||||
this.bindEventListeners();
|
||||
},
|
||||
|
||||
initObjects: function() {
|
||||
this.expandAll = $('span#expandAll').find('a');
|
||||
this.classCounter = 1;
|
||||
this.expandCounter = 1;
|
||||
this.classHtml = "";
|
||||
this.clickableSpans = [] ;
|
||||
this.form = $('form#classHierarchyForm');
|
||||
this.select = $('select#displayOption');
|
||||
this.addProperty = $('input#addProperty');
|
||||
noProps = new Boolean;
|
||||
},
|
||||
|
||||
bindEventListeners: function() {
|
||||
if ( this.propType == "object" ) {
|
||||
this.select.change(function() {
|
||||
if ( objectPropHierarchyUtils.select.val() == "all") {
|
||||
objectPropHierarchyUtils.form.attr("action", "listPropertyWebapps");
|
||||
}
|
||||
else {
|
||||
objectPropHierarchyUtils.form.attr("action", "showObjectPropertyHierarchy");
|
||||
}
|
||||
objectPropHierarchyUtils.form.submit();
|
||||
});
|
||||
|
||||
this.addProperty.click(function() {
|
||||
objectPropHierarchyUtils.form.attr("action", "editForm?controller=Property");
|
||||
objectPropHierarchyUtils.form.submit();
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.select.change(function() {
|
||||
if ( objectPropHierarchyUtils.select.val() == "all") {
|
||||
objectPropHierarchyUtils.form.attr("action", "listDatatypeProperties");
|
||||
}
|
||||
else {
|
||||
objectPropHierarchyUtils.form.attr("action", "showDataPropertyHierarchy");
|
||||
}
|
||||
objectPropHierarchyUtils.form.submit();
|
||||
});
|
||||
|
||||
this.addProperty.click(function() {
|
||||
objectPropHierarchyUtils.form.attr("action", "editForm?controller=Dataprop");
|
||||
objectPropHierarchyUtils.form.submit();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
checkJsonTree: function() {
|
||||
if ( json.length == 1 ) {
|
||||
$.each(json, function() {
|
||||
// check to see whether we have a 'no properties' message or an actual json tree
|
||||
if ( this.name.indexOf("properties") != -1 && this.data == undefined ) {
|
||||
noProps = true;
|
||||
}
|
||||
else {
|
||||
noProps = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
noProps = false;
|
||||
}
|
||||
},
|
||||
|
||||
buildPropertyHierarchyHtml: function() {
|
||||
|
||||
$.each(json, function() {
|
||||
$newClassSection = jQuery("<section></section>", {
|
||||
id: "classContainer" + objectPropHierarchyUtils.classCounter
|
||||
});
|
||||
var descendants = "";
|
||||
var headerSpan = "";
|
||||
|
||||
if ( this.children.length ) {
|
||||
descendants = objectPropHierarchyUtils.getTheChildren(this);
|
||||
headerSpan = "<span class='headerSpanPlus' id='headerSpan" + objectPropHierarchyUtils.classCounter
|
||||
+ "' view='less'> </span>";
|
||||
}
|
||||
|
||||
objectPropHierarchyUtils.classHtml += "<div>" + this.name + headerSpan + "</div>" + "<table class='classHierarchy' id='classHierarchy"
|
||||
+ objectPropHierarchyUtils.classCounter + "'>" ;
|
||||
|
||||
objectPropHierarchyUtils.classHtml += "<tr><td class='classDetail'>Local Name:</td><td>"
|
||||
+ (this.data.internalName.length > 0 ? this.data.internalName : "none" ) + "</td></tr>";
|
||||
|
||||
objectPropHierarchyUtils.classHtml += "<tr><td class='classDetail'>Group:</td><td>"
|
||||
+ (this.data.group.length > 0 ? this.data.group : "unspecified" ) + "</td></tr>";
|
||||
|
||||
objectPropHierarchyUtils.classHtml += "<tr><td class='classDetail'>Domain Class:</td><td>"
|
||||
+ (this.data.domainVClass.length > 0 ? this.data.domainVClass : "none" ) + " ";
|
||||
|
||||
objectPropHierarchyUtils.classHtml += "<span class='rangeClass'>Range Class:</span>"
|
||||
+ (this.data.rangeVClass.length > 0 ? this.data.rangeVClass : "none" ) + "</td></tr>";
|
||||
|
||||
|
||||
objectPropHierarchyUtils.classHtml += descendants;
|
||||
|
||||
objectPropHierarchyUtils.classHtml += "</table>";
|
||||
// alert(objectPropHierarchyUtils.classHtml);
|
||||
$newClassSection.html(objectPropHierarchyUtils.classHtml);
|
||||
$newClassSection.appendTo($('section#container'));
|
||||
objectPropHierarchyUtils.makeHeaderSpansClickable(objectPropHierarchyUtils.classCounter);
|
||||
objectPropHierarchyUtils.makeSubpropertySpansClickable();
|
||||
objectPropHierarchyUtils.clickableSpans = [] ;
|
||||
objectPropHierarchyUtils.classHtml = "";
|
||||
objectPropHierarchyUtils.classCounter += 1;
|
||||
});
|
||||
},
|
||||
|
||||
getTheChildren: function(node) {
|
||||
var childDetails = "";
|
||||
var subclassString = " ";
|
||||
var ctr = 0
|
||||
$.each(node.children, function() {
|
||||
if ( ctr == 0 ) {
|
||||
childDetails += "<tr><td class='classDetail'>Subproperties:</td>";
|
||||
ctr = ctr + 1;
|
||||
}
|
||||
else {
|
||||
childDetails += "<tr><td></td>" ;
|
||||
}
|
||||
|
||||
if ( this.children.length == 1 ) {
|
||||
subclassString += "<span style='font-size:0.8em'> (1 subclass)</span>";
|
||||
}
|
||||
else if ( this.children.length > 1 ) {
|
||||
subclassString += "<span style='font-size:0.8em'> (" + this.children.length + " subclasses)</span>";
|
||||
}
|
||||
|
||||
childDetails += "<td class='subclassCell' colspan='2'><span class='subclassExpandPlus' id='subclassExpand"
|
||||
+ objectPropHierarchyUtils.expandCounter + "'> </span>"
|
||||
+ this.name + subclassString + "</td></tr><tr><td></td><td colspan='2'><table id='subclassTable"
|
||||
+ objectPropHierarchyUtils.expandCounter + "' class='subclassTable'>";
|
||||
|
||||
subclassString = " ";
|
||||
|
||||
objectPropHierarchyUtils.clickableSpans.push('subclassExpand' + objectPropHierarchyUtils.expandCounter);
|
||||
|
||||
objectPropHierarchyUtils.expandCounter += 1;
|
||||
|
||||
childDetails += "<tr><td class='classDetail'>Local Name:</td><td>"
|
||||
+ (this.data.internalName.length > 0 ? this.data.internalName : "none" ) + "</td></tr>";
|
||||
|
||||
childDetails += "<tr><td class='classDetail'>Group:</td><td>"
|
||||
+ (this.data.group.length > 0 ? this.data.group : "unspecified" ) + "</td></tr>";
|
||||
|
||||
childDetails += "<tr><td class='classDetail'>Domain Class:</td><td>"
|
||||
+ (this.data.domainVClass.length > 0 ? this.data.domainVClass : "none" ) + " ";
|
||||
|
||||
childDetails += "<span class='rangeClass'>Range Class:</span>"
|
||||
+ (this.data.rangeVClass.length > 0 ? this.data.rangeVClass : "none" ) + "</td></tr>";
|
||||
|
||||
if ( this.children ) {
|
||||
var grandChildren = objectPropHierarchyUtils.getTheChildren(this);
|
||||
childDetails += grandChildren;
|
||||
}
|
||||
});
|
||||
childDetails += "</table></td></tr>";
|
||||
return childDetails;
|
||||
},
|
||||
|
||||
makeHeaderSpansClickable: function(ctr) {
|
||||
|
||||
var $clickableHeader = $('section#classContainer' + ctr).find('span.headerSpanPlus');
|
||||
|
||||
$clickableHeader.click(function() {
|
||||
if ( $clickableHeader.attr('view') == "less" ) {
|
||||
$clickableHeader.addClass("headerSpanMinus");
|
||||
$('table#classHierarchy' + ctr).find('span.subclassExpandPlus').addClass("subclassExpandMinus");
|
||||
$('table#classHierarchy' + ctr).find('table.subclassTable').show();
|
||||
$clickableHeader.attr('view', 'more' );
|
||||
}
|
||||
else {
|
||||
$clickableHeader.removeClass("headerSpanMinus");
|
||||
$('table#classHierarchy' + ctr).find('span.subclassExpandPlus').removeClass("subclassExpandMinus");
|
||||
$('table#classHierarchy' + ctr).find('table.subclassTable').hide();
|
||||
$clickableHeader.attr('view', 'less' );
|
||||
}
|
||||
});
|
||||
},// $('myOjbect').css('background-image', 'url(' + imageUrl + ')');
|
||||
|
||||
makeSubpropertySpansClickable: function() {
|
||||
$.each(objectPropHierarchyUtils.clickableSpans, function() {
|
||||
var currentSpan = this;
|
||||
var $clickableSpan = $('section#container').find('span#' + currentSpan);
|
||||
var $subclassTable = $('section#container').find('table#subclassTable' + currentSpan.replace("subclassExpand",""));
|
||||
|
||||
$clickableSpan.click(function() {
|
||||
if ( $subclassTable.is(':visible') ) {
|
||||
$subclassTable.hide();
|
||||
$subclassTable.find('table.subclassTable').hide();
|
||||
$subclassTable.find('span').removeClass("subclassExpandMinus");
|
||||
$clickableSpan.removeClass("subclassExpandMinus");
|
||||
}
|
||||
else {
|
||||
$subclassTable.show();
|
||||
$clickableSpan.addClass("subclassExpandMinus");
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
wireExpandLink: function() {
|
||||
this.expandAll.click(function() {
|
||||
if ( objectPropHierarchyUtils.expandAll.text() == "expand all" ) {
|
||||
objectPropHierarchyUtils.expandAll.text("collapse all");
|
||||
$('span.headerSpanPlus').addClass("headerSpanMinus");
|
||||
$('table.classHierarchy').find('span.subclassExpandPlus').addClass("subclassExpandMinus");
|
||||
$('table.classHierarchy').find('table.subclassTable').show();
|
||||
$('section#container').find('span.headerSpanPlus').attr('view','more');
|
||||
}
|
||||
else {
|
||||
objectPropHierarchyUtils.expandAll.text("expand all");
|
||||
$('span.headerSpanPlus').removeClass("headerSpanMinus");
|
||||
$('table.classHierarchy').find('span.subclassExpandPlus').removeClass("subclassExpandMinus");
|
||||
$('table.classHierarchy').find('table.subclassTable').hide();
|
||||
$('section#container').find('span.headerSpanPlus').attr('view','less');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
buildAllPropsHtml: function() {
|
||||
|
||||
$.each(json, function() {
|
||||
$newClassSection = jQuery("<section></section>", {
|
||||
id: "classContainer" + objectPropHierarchyUtils.classCounter
|
||||
});
|
||||
|
||||
objectPropHierarchyUtils.classHtml += "<div>" + this.name + "</div>" + "<table class='classHierarchy' id='classHierarchy"
|
||||
+ objectPropHierarchyUtils.classCounter + "'>" ;
|
||||
|
||||
objectPropHierarchyUtils.classHtml += "<tr><td class='classDetail'>Local Name:</td><td>"
|
||||
+ (this.data.internalName.length > 0 ? this.data.internalName : "none" ) + "</td></tr>";
|
||||
|
||||
objectPropHierarchyUtils.classHtml += "<tr><td class='classDetail'>Group:</td><td>"
|
||||
+ (this.data.group.length > 0 ? this.data.group : "unspecified" ) + "</td></tr>";
|
||||
|
||||
objectPropHierarchyUtils.classHtml += "<tr><td class='classDetail'>Domain Class:</td><td>"
|
||||
+ (this.data.domainVClass.length > 0 ? this.data.domainVClass : "none" ) + " ";
|
||||
|
||||
objectPropHierarchyUtils.classHtml += "<span class='rangeClass'>Range Class:</span>"
|
||||
+ (this.data.rangeVClass.length > 0 ? this.data.rangeVClass : "none" ) + "</td></tr>";
|
||||
|
||||
objectPropHierarchyUtils.classHtml += "</table>";
|
||||
|
||||
$newClassSection.html(objectPropHierarchyUtils.classHtml);
|
||||
$newClassSection.appendTo($('section#container'));
|
||||
objectPropHierarchyUtils.classHtml = "";
|
||||
objectPropHierarchyUtils.classCounter += 1;
|
||||
});
|
||||
},
|
||||
|
||||
buildNoPropsHtml: function() {
|
||||
|
||||
$.each(json, function() {
|
||||
$newClassSection = jQuery("<section></section>", {
|
||||
id: "classContainer" + objectPropHierarchyUtils.classCounter
|
||||
});
|
||||
|
||||
objectPropHierarchyUtils.classHtml = "<h4>" + this.name + "</h4>";
|
||||
$newClassSection.html(objectPropHierarchyUtils.classHtml);
|
||||
$newClassSection.appendTo($('section#container'));
|
||||
objectPropHierarchyUtils.classHtml = "";
|
||||
});
|
||||
}
|
||||
}
|
|
@ -16,14 +16,10 @@
|
|||
<option value="group" <#if displayOption == "group">selected</#if> >Classes by Class Group</option>
|
||||
</select>
|
||||
<input id="addClass" value="Add New Class" class="form-button" type="submit" />
|
||||
<#if displayOption == "group">
|
||||
<input type="submit" id="addGroup" class="form-button" value="Add New Group"/>
|
||||
</#if>
|
||||
</form>
|
||||
<#if displayOption == "group"><div style="float:right;padding-right:280px;margin-top:-50px">
|
||||
<form action="editForm" method="get">
|
||||
<input type="submit" class="form-button" value="Add New Group"/>
|
||||
<input type="hidden" name="controller" value="Classgroup"/>
|
||||
</form>
|
||||
</div>
|
||||
</#if>
|
||||
|
||||
<div id="expandLink"><span id="expandAll" ><a href="#" title="expand all">expand all</a></span></div>
|
||||
<section id="container">
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<#--
|
||||
Used to display both the object and data property hierarchies, though there are
|
||||
separate controllers for those. Also used to display lists of "all" object and
|
||||
data properties, though there are separate controllers for those, too.
|
||||
-->
|
||||
|
||||
|
||||
<section role="region">
|
||||
|
||||
<h2>${pageTitle!}</h2>
|
||||
|
||||
<#if !displayOption?has_content>
|
||||
<#assign displayOption = "hierarchy">
|
||||
</#if>
|
||||
|
||||
<form name="classHierarchyForm" id="classHierarchyForm" action="show<#if propertyType == "object">Object<#else>Data</#if>PropertyHierarchy" method="post" role="classHierarchy">
|
||||
<label id="displayOptionLabel" class="inline">Display Options</label>
|
||||
<select id="displayOption" name="displayOption">
|
||||
<option value="hierarchy" <#if displayOption == "asserted">selected</#if> >Property Hierarchy</option>
|
||||
<option value="all" <#if displayOption == "all">selected</#if> >All Properties</option>
|
||||
</select>
|
||||
<input type="submit" class="form-button" id="addProperty" value="Add new <#if propertyType == "object">object<#else>data</#if> property"/>
|
||||
</form>
|
||||
|
||||
<div id="expandLink"><span id="expandAll" ><a href="#" title="expand all">expand all</a></span></div>
|
||||
|
||||
<section id="container">
|
||||
</section>
|
||||
|
||||
</section>
|
||||
<script language="javascript" type="text/javascript" >
|
||||
var json = [${jsonTree!}];
|
||||
</script>
|
||||
|
||||
|
||||
<script language="javascript" type="text/javascript" >
|
||||
$(document).ready(function() {
|
||||
objectPropHierarchyUtils.onLoad("${urls.base!}","${displayOption!}","${propertyType}");
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/css/classHierarchy.css" />')}
|
||||
|
||||
${scripts.add('<script type="text/javascript" src="${urls.base}/js/jquery-ui/js/jquery-ui-1.8.9.custom.min.js"></script>',
|
||||
'<script type="text/javascript" src="${urls.base}/js/siteAdmin/objectPropertyHierarchyUtils.js"></script>')}
|
||||
|
Loading…
Add table
Reference in a new issue