Merge branch 'develop' of git://github.com/vivo-project/Vitro into develop

This commit is contained in:
Jim Blake 2017-05-29 16:31:08 -04:00
commit dad1ce83cc
61 changed files with 3210 additions and 584 deletions

2
.gitignore vendored
View file

@ -2,7 +2,6 @@
/.classpath /.classpath
/.project /.project
/.settings /.settings
/bin/
/webapp/config/deploy.properties /webapp/config/deploy.properties
/webapp/config/build.properties /webapp/config/build.properties
/webapp/config/runtime.properties /webapp/config/runtime.properties
@ -22,3 +21,4 @@ utilities/sdb_to_tdb/.work
**/.settings **/.settings
**/.classpath **/.classpath
**/.project **/.project
**/bin/

View file

@ -7,8 +7,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.sf.json.util.JSONUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -21,6 +19,7 @@ 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.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
import edu.cornell.mannlib.vitro.webapp.utils.json.JacksonUtils;
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder; import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
@ -61,9 +60,9 @@ public class ListClassGroupsController extends FreemarkerHttpServlet {
publicName = "(unnamed group)"; publicName = "(unnamed group)";
} }
try { try {
json += "{ \"name\": " + JSONUtils.quote("<a href='./editForm?uri="+URLEncoder.encode(vcg.getURI())+"&amp;controller=Classgroup'>"+publicName+"</a>") + ", "; json += "{ \"name\": " + JacksonUtils.quote("<a href='./editForm?uri="+URLEncoder.encode(vcg.getURI())+"&amp;controller=Classgroup'>"+publicName+"</a>") + ", ";
} catch (Exception e) { } catch (Exception e) {
json += "{ \"name\": " + JSONUtils.quote(publicName) + ", "; json += "{ \"name\": " + JacksonUtils.quote(publicName) + ", ";
} }
Integer t; Integer t;
@ -77,16 +76,16 @@ public class ListClassGroupsController extends FreemarkerHttpServlet {
VClass vcw = classIt.next(); VClass vcw = classIt.next();
if (vcw.getName() != null && vcw.getURI() != null) { if (vcw.getName() != null && vcw.getURI() != null) {
try { try {
json += "{ \"name\": " + JSONUtils.quote("<a href='vclassEdit?uri="+URLEncoder.encode(vcw.getURI())+"'>"+vcw.getName()+"</a>") + ", "; json += "{ \"name\": " + JacksonUtils.quote("<a href='vclassEdit?uri="+URLEncoder.encode(vcw.getURI())+"'>"+vcw.getName()+"</a>") + ", ";
} catch (Exception e) { } catch (Exception e) {
json += "" + JSONUtils.quote(vcw.getName()) + ", "; json += "" + JacksonUtils.quote(vcw.getName()) + ", ";
} }
} else { } else {
json += "\"\", "; json += "\"\", ";
} }
String shortDefStr = (vcw.getShortDef() == null) ? "" : vcw.getShortDef(); String shortDefStr = (vcw.getShortDef() == null) ? "" : vcw.getShortDef();
json += "\"data\": { \"shortDef\": " + JSONUtils.quote(shortDefStr) + "}, \"children\": [] "; json += "\"data\": { \"shortDef\": " + JacksonUtils.quote(shortDefStr) + "}, \"children\": [] ";
if (classIt.hasNext()) if (classIt.hasNext())
json += "} , "; json += "} , ";
else else

View file

@ -10,8 +10,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.sf.json.util.JSONUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -28,6 +26,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao; import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.utils.json.JacksonUtils;
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder; import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
public class ListDatatypePropertiesController extends FreemarkerHttpServlet { public class ListDatatypePropertiesController extends FreemarkerHttpServlet {
@ -113,12 +112,12 @@ public class ListDatatypePropertiesController extends FreemarkerHttpServlet {
String nameStr = prop.getPickListName()==null ? prop.getName()==null ? prop.getURI()==null ? "(no name)" : prop.getURI() : prop.getName() : prop.getPickListName(); String nameStr = prop.getPickListName()==null ? prop.getName()==null ? prop.getURI()==null ? "(no name)" : prop.getURI() : prop.getName() : prop.getPickListName();
try { try {
json += "{ \"name\": " + JSONUtils.quote("<a href='datapropEdit?uri="+ URLEncoder.encode(prop.getURI())+"'>" + nameStr + "</a>") + ", "; json += "{ \"name\": " + JacksonUtils.quote("<a href='datapropEdit?uri="+ URLEncoder.encode(prop.getURI())+"'>" + nameStr + "</a>") + ", ";
} catch (Exception e) { } catch (Exception e) {
json += "{ \"name\": " + JSONUtils.quote(nameStr) + ", "; json += "{ \"name\": " + JacksonUtils.quote(nameStr) + ", ";
} }
json += "\"data\": { \"internalName\": " + JSONUtils.quote(prop.getPickListName()) + ", "; json += "\"data\": { \"internalName\": " + JacksonUtils.quote(prop.getPickListName()) + ", ";
/* VClass vc = null; /* VClass vc = null;
String domainStr=""; String domainStr="";
@ -138,15 +137,15 @@ public class ListDatatypePropertiesController extends FreemarkerHttpServlet {
dpLangNeut = prop; dpLangNeut = prop;
} }
String domainStr = getVClassNameFromURI(dpLangNeut.getDomainVClassURI(), vcDao, vcDaoLangNeut); String domainStr = getVClassNameFromURI(dpLangNeut.getDomainVClassURI(), vcDao, vcDaoLangNeut);
json += "\"domainVClass\": " + JSONUtils.quote(domainStr) + ", " ; json += "\"domainVClass\": " + JacksonUtils.quote(domainStr) + ", " ;
Datatype rangeDatatype = dDao.getDatatypeByURI(prop.getRangeDatatypeURI()); Datatype rangeDatatype = dDao.getDatatypeByURI(prop.getRangeDatatypeURI());
String rangeDatatypeStr = (rangeDatatype==null)?prop.getRangeDatatypeURI():rangeDatatype.getName(); String rangeDatatypeStr = (rangeDatatype==null)?prop.getRangeDatatypeURI():rangeDatatype.getName();
json += "\"rangeVClass\": " + JSONUtils.quote(rangeDatatypeStr) + ", " ; json += "\"rangeVClass\": " + JacksonUtils.quote(rangeDatatypeStr) + ", " ;
if (prop.getGroupURI() != null) { if (prop.getGroupURI() != null) {
PropertyGroup pGroup = pgDao.getGroupByURI(prop.getGroupURI()); PropertyGroup pGroup = pgDao.getGroupByURI(prop.getGroupURI());
json += "\"group\": " + JSONUtils.quote((pGroup == null) ? "unknown group" : pGroup.getName()) + " } } " ; json += "\"group\": " + JacksonUtils.quote((pGroup == null) ? "unknown group" : pGroup.getName()) + " } } " ;
} else { } else {
json += "\"group\": \"unspecified\" } }" ; json += "\"group\": \"unspecified\" } }" ;
} }

View file

@ -2,19 +2,12 @@
package edu.cornell.mannlib.vitro.webapp.controller.freemarker; package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import net.sf.json.util.JSONUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -23,15 +16,12 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationReques
import edu.cornell.mannlib.vitro.webapp.beans.FauxProperty; import edu.cornell.mannlib.vitro.webapp.beans.FauxProperty;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup; import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; 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.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.dao.FauxPropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.FauxPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
public class ListFauxPropertiesController extends FreemarkerHttpServlet { public class ListFauxPropertiesController extends FreemarkerHttpServlet {

View file

@ -8,8 +8,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.sf.json.util.JSONUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -24,6 +22,7 @@ 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.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
import edu.cornell.mannlib.vitro.webapp.utils.json.JacksonUtils;
public class ListPropertyGroupsController extends FreemarkerHttpServlet { public class ListPropertyGroupsController extends FreemarkerHttpServlet {
@ -62,9 +61,9 @@ public class ListPropertyGroupsController extends FreemarkerHttpServlet {
publicName = "(unnamed group)"; publicName = "(unnamed group)";
} }
try { try {
json += "{ \"name\": " + JSONUtils.quote("<a href='./editForm?uri="+URLEncoder.encode(pg.getURI(),"UTF-8")+"&amp;controller=PropertyGroup'>" + publicName + "</a>") + ", "; json += "{ \"name\": " + JacksonUtils.quote("<a href='./editForm?uri="+URLEncoder.encode(pg.getURI(),"UTF-8")+"&amp;controller=PropertyGroup'>" + publicName + "</a>") + ", ";
} catch (Exception e) { } catch (Exception e) {
json += "{ \"name\": " + JSONUtils.quote(publicName) + ", "; json += "{ \"name\": " + JacksonUtils.quote(publicName) + ", ";
} }
Integer t; Integer t;
@ -89,10 +88,10 @@ public class ListPropertyGroupsController extends FreemarkerHttpServlet {
} }
if (prop.getURI() != null) { if (prop.getURI() != null) {
try { try {
json += "{ \"name\": " + JSONUtils.quote("<a href='" + controllerStr json += "{ \"name\": " + JacksonUtils.quote("<a href='" + controllerStr
+ "?uri="+URLEncoder.encode(prop.getURI(),"UTF-8")+"'>"+ nameStr +"</a>") + ", "; + "?uri="+URLEncoder.encode(prop.getURI(),"UTF-8")+"'>"+ nameStr +"</a>") + ", ";
} catch (Exception e) { } catch (Exception e) {
json += JSONUtils.quote(nameStr) + ", "; json += JacksonUtils.quote(nameStr) + ", ";
} }
} else { } else {
json += "\"\", "; json += "\"\", ";

View file

@ -11,8 +11,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.sf.json.util.JSONUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -32,6 +30,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao; import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.utils.json.JacksonUtils;
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder; import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
public class ListPropertyWebappsController extends FreemarkerHttpServlet { public class ListPropertyWebappsController extends FreemarkerHttpServlet {
@ -154,27 +153,27 @@ public class ListPropertyWebappsController extends FreemarkerHttpServlet {
String propNameStr = ShowObjectPropertyHierarchyController.getDisplayLabel(prop); String propNameStr = ShowObjectPropertyHierarchyController.getDisplayLabel(prop);
try { try {
json += "{ \"name\": " + JSONUtils.quote("<a href='./propertyEdit?uri="+URLEncoder.encode(prop.getURI())+"'>" json += "{ \"name\": " + JacksonUtils.quote("<a href='./propertyEdit?uri="+URLEncoder.encode(prop.getURI())+"'>"
+ propNameStr + "</a>") + ", "; + propNameStr + "</a>") + ", ";
} catch (Exception e) { } catch (Exception e) {
json += "{ \"name\": \"" + propNameStr + "\", "; json += "{ \"name\": \"" + propNameStr + "\", ";
} }
json += "\"data\": { \"internalName\": " + JSONUtils.quote(prop.getLocalNameWithPrefix()) + ", "; json += "\"data\": { \"internalName\": " + JacksonUtils.quote(prop.getLocalNameWithPrefix()) + ", ";
ObjectProperty opLangNeut = opDaoLangNeut.getObjectPropertyByURI(prop.getURI()); ObjectProperty opLangNeut = opDaoLangNeut.getObjectPropertyByURI(prop.getURI());
if(opLangNeut == null) { if(opLangNeut == null) {
opLangNeut = prop; opLangNeut = prop;
} }
String domainStr = getVClassNameFromURI(opLangNeut.getDomainVClassURI(), vcDao, vcDaoLangNeut); String domainStr = getVClassNameFromURI(opLangNeut.getDomainVClassURI(), vcDao, vcDaoLangNeut);
json += "\"domainVClass\": " + JSONUtils.quote(domainStr) + ", " ; json += "\"domainVClass\": " + JacksonUtils.quote(domainStr) + ", " ;
String rangeStr = getVClassNameFromURI(opLangNeut.getRangeVClassURI(), vcDao, vcDaoLangNeut); String rangeStr = getVClassNameFromURI(opLangNeut.getRangeVClassURI(), vcDao, vcDaoLangNeut);
json += "\"rangeVClass\": " + JSONUtils.quote(rangeStr) + ", " ; json += "\"rangeVClass\": " + JacksonUtils.quote(rangeStr) + ", " ;
if (prop.getGroupURI() != null) { if (prop.getGroupURI() != null) {
PropertyGroup pGroup = pgDao.getGroupByURI(prop.getGroupURI()); PropertyGroup pGroup = pgDao.getGroupByURI(prop.getGroupURI());
json += "\"group\": " + JSONUtils.quote((pGroup == null) ? "unknown group" : pGroup.getName()) + " } } " ; json += "\"group\": " + JacksonUtils.quote((pGroup == null) ? "unknown group" : pGroup.getName()) + " } } " ;
} else { } else {
json += "\"group\": \"unspecified\" } }" ; json += "\"group\": \"unspecified\" } }" ;
} }

View file

@ -8,8 +8,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.sf.json.util.JSONUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -26,6 +24,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.PropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.utils.json.JacksonUtils;
public class ListVClassWebappsController extends FreemarkerHttpServlet { public class ListVClassWebappsController extends FreemarkerHttpServlet {
@ -90,15 +89,15 @@ public class ListVClassWebappsController extends FreemarkerHttpServlet {
if ( (ontologyURI==null) || ( (ontologyURI != null) && (cls.getNamespace()!=null) && (ontologyURI.equals(cls.getNamespace())) ) ) { if ( (ontologyURI==null) || ( (ontologyURI != null) && (cls.getNamespace()!=null) && (ontologyURI.equals(cls.getNamespace())) ) ) {
if (cls.getName() != null) if (cls.getName() != null)
try { try {
json += "{ \"name\": " + JSONUtils.quote("<a href='./vclassEdit?uri="+URLEncoder.encode(cls.getURI(),"UTF-8")+"'>"+cls.getPickListName()+"</a>") + ", "; json += "{ \"name\": " + JacksonUtils.quote("<a href='./vclassEdit?uri="+URLEncoder.encode(cls.getURI(),"UTF-8")+"'>"+cls.getPickListName()+"</a>") + ", ";
} catch (Exception e) { } catch (Exception e) {
json += "{ \"name\": " + JSONUtils.quote(cls.getPickListName()) + ", "; json += "{ \"name\": " + JacksonUtils.quote(cls.getPickListName()) + ", ";
} }
else else
json += "{ \"name\": \"\""; json += "{ \"name\": \"\"";
String shortDef = (cls.getShortDef() == null) ? "" : cls.getShortDef(); String shortDef = (cls.getShortDef() == null) ? "" : cls.getShortDef();
json += "\"data\": { \"shortDef\": " + JSONUtils.quote(shortDef) + ", "; json += "\"data\": { \"shortDef\": " + JacksonUtils.quote(shortDef) + ", ";
// get group name // get group name
WebappDaoFactory wadf = vreq.getUnfilteredWebappDaoFactory(); WebappDaoFactory wadf = vreq.getUnfilteredWebappDaoFactory();
@ -113,7 +112,7 @@ public class ListVClassWebappsController extends FreemarkerHttpServlet {
} }
} }
json += "\"classGroup\": " + JSONUtils.quote(groupName) + ", "; json += "\"classGroup\": " + JacksonUtils.quote(groupName) + ", ";
// get ontology name // get ontology name
OntologyDao ontDao = wadf.getOntologyDao(); OntologyDao ontDao = wadf.getOntologyDao();
@ -122,7 +121,7 @@ public class ListVClassWebappsController extends FreemarkerHttpServlet {
if (ont != null && ont.getName() != null) { if (ont != null && ont.getName() != null) {
ontName = ont.getName(); ontName = ont.getName();
} }
json += "\"ontology\": " + JSONUtils.quote(ontName) + "} }"; json += "\"ontology\": " + JacksonUtils.quote(ontName) + "} }";
counter++; counter++;

View file

@ -10,11 +10,8 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.sf.json.util.JSONUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.jena.vocabulary.OWL; import org.apache.jena.vocabulary.OWL;
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
@ -29,6 +26,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.utils.json.JacksonUtils;
public class ShowClassHierarchyController extends FreemarkerHttpServlet { public class ShowClassHierarchyController extends FreemarkerHttpServlet {
@ -196,16 +194,16 @@ public class ShowClassHierarchyController extends FreemarkerHttpServlet {
tempString += "}, { \"name\": "; tempString += "}, { \"name\": ";
} }
try { try {
tempString += JSONUtils.quote("<a href='vclassEdit?uri=" + tempString += JacksonUtils.quote("<a href='vclassEdit?uri=" +
URLEncoder.encode(vcw.getURI(),"UTF-8") + "'>" + URLEncoder.encode(vcw.getURI(),"UTF-8") + "'>" +
vcw.getPickListName() + "</a>") +", "; vcw.getPickListName() + "</a>") +", ";
} catch (Exception e) { } catch (Exception e) {
tempString += JSONUtils.quote(((vcw.getPickListName() == null) tempString += JacksonUtils.quote(((vcw.getPickListName() == null)
? "" : vcw.getPickListName())) + ", "; ? "" : vcw.getPickListName())) + ", ";
} }
String shortDef = ((vcw.getShortDef() == null) ? "" : vcw.getShortDef()) ; String shortDef = ((vcw.getShortDef() == null) ? "" : vcw.getShortDef()) ;
tempString += "\"data\": { \"shortDef\": " + JSONUtils.quote(shortDef) + ", "; tempString += "\"data\": { \"shortDef\": " + JacksonUtils.quote(shortDef) + ", ";
// Get group name if it exists // Get group name if it exists
VClassGroupDao groupDao= wadf.getVClassGroupDao(); VClassGroupDao groupDao= wadf.getVClassGroupDao();
@ -218,7 +216,7 @@ public class ShowClassHierarchyController extends FreemarkerHttpServlet {
groupName = classGroup.getPublicName(); groupName = classGroup.getPublicName();
} }
} }
tempString += "\"classGroup\": " + JSONUtils.quote( tempString += "\"classGroup\": " + JacksonUtils.quote(
(groupName == null) ? "" : groupName) + ", "; (groupName == null) ? "" : groupName) + ", ";
// Get ontology name // Get ontology name
OntologyDao ontDao = wadf.getOntologyDao(); OntologyDao ontDao = wadf.getOntologyDao();
@ -227,7 +225,7 @@ public class ShowClassHierarchyController extends FreemarkerHttpServlet {
if (ont != null && ont.getName() != null) { if (ont != null && ont.getName() != null) {
ontName = ont.getName(); ontName = ont.getName();
} }
tempString += "\"ontology\": " + JSONUtils.quote( tempString += "\"ontology\": " + JacksonUtils.quote(
(ontName == null) ? "" : ontName) + "}, \"children\": ["; (ontName == null) ? "" : ontName) + "}, \"children\": [";
previous_posn = position; previous_posn = position;

View file

@ -9,8 +9,6 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.sf.json.util.JSONUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -27,6 +25,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao; import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.utils.json.JacksonUtils;
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder; import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
public class ShowDataPropertyHierarchyController extends FreemarkerHttpServlet { public class ShowDataPropertyHierarchyController extends FreemarkerHttpServlet {
@ -211,11 +210,11 @@ public class ShowDataPropertyHierarchyController extends FreemarkerHttpServlet {
? dp.getURI() == null ? dp.getURI() == null
? "(no name)" : dp.getURI() : dp.getName() : dp.getPickListName(); ? "(no name)" : dp.getURI() : dp.getName() : dp.getPickListName();
tempString += JSONUtils.quote( tempString += JacksonUtils.quote(
"<a href='datapropEdit?uri=" + URLEncoder.encode( "<a href='datapropEdit?uri=" + URLEncoder.encode(
dp.getURI()) + "'>" + nameStr + "</a>") + ", "; dp.getURI()) + "'>" + nameStr + "</a>") + ", ";
tempString += "\"data\": { \"internalName\": " + JSONUtils.quote( tempString += "\"data\": { \"internalName\": " + JacksonUtils.quote(
dp.getPickListName()) + ", "; dp.getPickListName()) + ", ";
DataProperty dpLangNeut = dpDaoLangNeut.getDataPropertyByURI(dp.getURI()); DataProperty dpLangNeut = dpDaoLangNeut.getDataPropertyByURI(dp.getURI());
@ -225,20 +224,20 @@ public class ShowDataPropertyHierarchyController extends FreemarkerHttpServlet {
String domainStr = getVClassNameFromURI(dpLangNeut.getDomainVClassURI(), vcDao, vcDaoLangNeut); String domainStr = getVClassNameFromURI(dpLangNeut.getDomainVClassURI(), vcDao, vcDaoLangNeut);
try { try {
tempString += "\"domainVClass\": " + JSONUtils.quote(domainStr) + ", " ; tempString += "\"domainVClass\": " + JacksonUtils.quote(domainStr) + ", " ;
} catch (NullPointerException e) { } catch (NullPointerException e) {
tempString += "\"domainVClass\": \"\","; tempString += "\"domainVClass\": \"\",";
} }
try { try {
Datatype rangeDatatype = dDao.getDatatypeByURI(dp.getRangeDatatypeURI()); Datatype rangeDatatype = dDao.getDatatypeByURI(dp.getRangeDatatypeURI());
String rangeDatatypeStr = (rangeDatatype==null)?dp.getRangeDatatypeURI():rangeDatatype.getName(); String rangeDatatypeStr = (rangeDatatype==null)?dp.getRangeDatatypeURI():rangeDatatype.getName();
tempString += "\"rangeVClass\": " + JSONUtils.quote((rangeDatatypeStr != null) ? rangeDatatypeStr : "") + ", " ; tempString += "\"rangeVClass\": " + JacksonUtils.quote((rangeDatatypeStr != null) ? rangeDatatypeStr : "") + ", " ;
} catch (NullPointerException e) { } catch (NullPointerException e) {
tempString += "\"rangeVClass\": \"\","; tempString += "\"rangeVClass\": \"\",";
} }
if (dp.getGroupURI() != null) { if (dp.getGroupURI() != null) {
PropertyGroup pGroup = pgDao.getGroupByURI(dp.getGroupURI()); PropertyGroup pGroup = pgDao.getGroupByURI(dp.getGroupURI());
tempString += "\"group\": " + JSONUtils.quote((pGroup == null) ? "unknown group" : pGroup.getName()); tempString += "\"group\": " + JacksonUtils.quote((pGroup == null) ? "unknown group" : pGroup.getName());
} else { } else {
tempString += "\"group\": \"unspecified\""; tempString += "\"group\": \"unspecified\"";
} }

View file

@ -12,8 +12,6 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.sf.json.util.JSONUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -28,6 +26,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Tem
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.utils.json.JacksonUtils;
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder; import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
public class ShowObjectPropertyHierarchyController extends FreemarkerHttpServlet { public class ShowObjectPropertyHierarchyController extends FreemarkerHttpServlet {
@ -210,11 +209,11 @@ public class ShowObjectPropertyHierarchyController extends FreemarkerHttpServlet
String nameStr = getDisplayLabel(op) == null ? "(no name)" : getDisplayLabel(op); String nameStr = getDisplayLabel(op) == null ? "(no name)" : getDisplayLabel(op);
tempString += JSONUtils.quote( tempString += JacksonUtils.quote(
"<a href='propertyEdit?uri=" + URLEncoder.encode( "<a href='propertyEdit?uri=" + URLEncoder.encode(
op.getURI()) + "'>" + nameStr + "</a>") + ", "; op.getURI()) + "'>" + nameStr + "</a>") + ", ";
tempString += "\"data\": { \"internalName\": " + JSONUtils.quote( tempString += "\"data\": { \"internalName\": " + JacksonUtils.quote(
op.getLocalNameWithPrefix()) + ", "; op.getLocalNameWithPrefix()) + ", ";
ObjectProperty opLangNeut = opDaoLangNeut.getObjectPropertyByURI(op.getURI()); ObjectProperty opLangNeut = opDaoLangNeut.getObjectPropertyByURI(op.getURI());
@ -225,18 +224,18 @@ public class ShowObjectPropertyHierarchyController extends FreemarkerHttpServlet
String rangeStr = getVClassNameFromURI(opLangNeut.getRangeVClassURI(), vcDao, vcDaoLangNeut); String rangeStr = getVClassNameFromURI(opLangNeut.getRangeVClassURI(), vcDao, vcDaoLangNeut);
try { try {
tempString += "\"domainVClass\": " + JSONUtils.quote(domainStr) + ", " ; tempString += "\"domainVClass\": " + JacksonUtils.quote(domainStr) + ", " ;
} catch (NullPointerException e) { } catch (NullPointerException e) {
tempString += "\"domainVClass\": \"\","; tempString += "\"domainVClass\": \"\",";
} }
try { try {
tempString += "\"rangeVClass\": " + JSONUtils.quote(rangeStr) + ", " ; tempString += "\"rangeVClass\": " + JacksonUtils.quote(rangeStr) + ", " ;
} catch (NullPointerException e) { } catch (NullPointerException e) {
tempString += "\"rangeVClass\": \"\","; tempString += "\"rangeVClass\": \"\",";
} }
if (op.getGroupURI() != null) { if (op.getGroupURI() != null) {
PropertyGroup pGroup = pgDao.getGroupByURI(op.getGroupURI()); PropertyGroup pGroup = pgDao.getGroupByURI(op.getGroupURI());
tempString += "\"group\": " + JSONUtils.quote( tempString += "\"group\": " + JacksonUtils.quote(
(pGroup == null) ? "unknown group" : pGroup.getName()); (pGroup == null) ? "unknown group" : pGroup.getName());
} else { } else {
tempString += "\"group\": \"unspecified\""; tempString += "\"group\": \"unspecified\"";

View file

@ -12,12 +12,8 @@ import java.util.Map;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.jena.ontology.OntModel; import org.apache.jena.ontology.OntModel;
import org.apache.jena.query.Query; import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution; import org.apache.jena.query.QueryExecution;
@ -31,6 +27,10 @@ import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory; import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.vocabulary.XSD; import org.apache.jena.vocabulary.XSD;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
@ -258,7 +258,7 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
String pageUri, String pageUri,
OntModel queryModel) { OntModel queryModel) {
//Create json array to be set within form specific data //Create json array to be set within form specific data
JSONArray jsonArray = new JSONArray(); ArrayNode jsonArray = new ObjectMapper().createArrayNode();
String querystr = getExistingDataGettersQuery(); String querystr = getExistingDataGettersQuery();
//Bind pageUri to query //Bind pageUri to query
QuerySolutionMap initialBindings = new QuerySolutionMap(); QuerySolutionMap initialBindings = new QuerySolutionMap();
@ -291,7 +291,7 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
} }
} }
private void addJSONArrayToFormSpecificData(JSONArray jsonArray, EditConfigurationVTwo editConfig) { private void addJSONArrayToFormSpecificData(ArrayNode jsonArray, EditConfigurationVTwo editConfig) {
HashMap<String, Object> data = editConfig.getFormSpecificData(); HashMap<String, Object> data = editConfig.getFormSpecificData();
data.put("existingPageContentUnits", jsonArray.toString()); data.put("existingPageContentUnits", jsonArray.toString());
//Experimenting with putting actual array in //Experimenting with putting actual array in
@ -300,7 +300,7 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
} }
private void processExistingDataGetter(int counter, String dataGetterURI, String dgClassName, private void processExistingDataGetter(int counter, String dataGetterURI, String dgClassName,
EditConfigurationVTwo editConfig, OntModel queryModel, JSONArray jsonArray, ServletContext context) { EditConfigurationVTwo editConfig, OntModel queryModel, ArrayNode jsonArray, ServletContext context) {
ProcessDataGetterN3 pn = ProcessDataGetterN3Utils.getDataGetterProcessorN3(dgClassName, null); ProcessDataGetterN3 pn = ProcessDataGetterN3Utils.getDataGetterProcessorN3(dgClassName, null);
//Add N3 Optional as well //Add N3 Optional as well
@ -323,10 +323,10 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
//including: (i) The JSON object representing the existing information to be returned to template //including: (i) The JSON object representing the existing information to be returned to template
//Takes data getter information, packs within JSON object to send back to the form //Takes data getter information, packs within JSON object to send back to the form
private void addDataGetterSpecificFormData(String dataGetterURI, ProcessDataGetterN3 pn, OntModel queryModel, JSONArray jsonArray, ServletContext context) { private void addDataGetterSpecificFormData(String dataGetterURI, ProcessDataGetterN3 pn, OntModel queryModel, ArrayNode jsonArray, ServletContext context) {
JSONObject jo = pn.getExistingValuesJSON(dataGetterURI, queryModel, context); ObjectNode jo = pn.getExistingValuesJSON(dataGetterURI, queryModel, context);
//Add dataGetterURI to jsonObject //Add dataGetterURI to jsonObject
jo.element("URI", dataGetterURI); jo.put("URI", dataGetterURI);
jsonArray.add(jo); jsonArray.add(jo);
} }

View file

@ -8,15 +8,14 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.jena.rdf.model.Literal; import org.apache.jena.rdf.model.Literal;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.BaseEditSubmissionPreprocessorVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.BaseEditSubmissionPreprocessorVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
@ -27,6 +26,7 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfigu
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.ManagePageGenerator; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.ManagePageGenerator;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessDataGetterN3; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessDataGetterN3;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessDataGetterN3Utils; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessDataGetterN3Utils;
import edu.cornell.mannlib.vitro.webapp.utils.json.JacksonUtils;
public class ManagePagePreprocessor extends public class ManagePagePreprocessor extends
BaseEditSubmissionPreprocessorVTwo { BaseEditSubmissionPreprocessorVTwo {
@ -39,7 +39,7 @@ public class ManagePagePreprocessor extends
private static Map<String, List<String>> transformedLiteralsFromForm = null; private static Map<String, List<String>> transformedLiteralsFromForm = null;
private static Map<String, List<String>> urisFromForm = null; private static Map<String, List<String>> urisFromForm = null;
private static List<String> pageContentUnits = null;//String submission from form private static List<String> pageContentUnits = null;//String submission from form
private static List<JSONObject> pageContentUnitsJSON = null;//converted to JSON objects that can be read private static List<ObjectNode> pageContentUnitsJSON = null;//converted to JSON objects that can be read
// String datatype // String datatype
// Will be editing the edit configuration as well as edit submission here // Will be editing the edit configuration as well as edit submission here
@ -131,7 +131,7 @@ public class ManagePagePreprocessor extends
private void processDataGetters() { private void processDataGetters() {
convertToJson(); convertToJson();
int counter = 0; int counter = 0;
for(JSONObject jsonObject:pageContentUnitsJSON) { for(ObjectNode jsonObject:pageContentUnitsJSON) {
String dataGetterClass = getDataGetterClass(jsonObject); String dataGetterClass = getDataGetterClass(jsonObject);
ProcessDataGetterN3 pn = ProcessDataGetterN3Utils.getDataGetterProcessorN3(dataGetterClass, jsonObject); ProcessDataGetterN3 pn = ProcessDataGetterN3Utils.getDataGetterProcessorN3(dataGetterClass, jsonObject);
//UPDATE: using class type to indicate class type/ could also get it from //UPDATE: using class type to indicate class type/ could also get it from
@ -175,12 +175,12 @@ public class ManagePagePreprocessor extends
private void convertToJson() { private void convertToJson() {
//Iterate through list of inputs //Iterate through list of inputs
pageContentUnitsJSON = new ArrayList<JSONObject>(); pageContentUnitsJSON = new ArrayList<ObjectNode>();
//page content units might return null in case self-contained template is selected //page content units might return null in case self-contained template is selected
//otherwise there should be page content units returned from the form //otherwise there should be page content units returned from the form
if(pageContentUnits != null) { if(pageContentUnits != null) {
for(String pageContentUnit: pageContentUnits) { for(String pageContentUnit: pageContentUnits) {
JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON( pageContentUnit ); ObjectNode jsonObject = (ObjectNode) JacksonUtils.parseJson(pageContentUnit);
pageContentUnitsJSON.add(jsonObject); pageContentUnitsJSON.add(jsonObject);
} }
} }
@ -190,29 +190,29 @@ public class ManagePagePreprocessor extends
//Each field name will correspond to the names of the fileds/uris on form/literals on form //Each field name will correspond to the names of the fileds/uris on form/literals on form
//generated here //generated here
private void addInputsToSubmission(ProcessDataGetterN3 pn, int counter, JSONObject jsonObject) { private void addInputsToSubmission(ProcessDataGetterN3 pn, int counter, ObjectNode jsonObject) {
List<String> literalLabels = pn.getLiteralVarNamesBase(); List<String> literalLabels = pn.getLiteralVarNamesBase();
List<String> uriLabels = pn.getUriVarNamesBase(); List<String> uriLabels = pn.getUriVarNamesBase();
for(String literalLabel:literalLabels) { for(String literalLabel:literalLabels) {
List<String> literalValues = new ArrayList<String>(); List<String> literalValues = new ArrayList<String>();
Object jsonValue = jsonObject.get(literalLabel); JsonNode jsonValue = jsonObject.get(literalLabel);
//Var names will depend on which data getter object this is on the page, so depends on counter //Var names will depend on which data getter object this is on the page, so depends on counter
String submissionLiteralName = pn.getVarName(literalLabel, counter); String submissionLiteralName = pn.getVarName(literalLabel, counter);
//Single value //Single value
if(jsonValue instanceof String) { if(jsonValue.isTextual()) {
//TODO: Deal with multiple submission values //TODO: Deal with multiple submission values
//This retrieves the value for this particular json object //This retrieves the value for this particular json object
String jsonString = jsonObject.getString(literalLabel); String jsonString = jsonObject.get(literalLabel).asText();
jsonString = pn.replaceEncodedQuotesWithEscapedQuotes(jsonString); jsonString = pn.replaceEncodedQuotesWithEscapedQuotes(jsonString);
literalValues.add(jsonString); literalValues.add(jsonString);
} else if(jsonValue instanceof JSONArray) { } else if(jsonValue.isArray()) {
JSONArray values = jsonObject.getJSONArray(literalLabel); ArrayNode values = (ArrayNode) jsonObject.get(literalLabel);
literalValues = (List<String>) JSONSerializer.toJava(values); literalValues = JacksonUtils.jsonArrayToStrings(values);
//Replacing encoded quotes here as well //Replacing encoded quotes here as well
this.replaceEncodedQuotesInList(pn, literalValues); this.replaceEncodedQuotesInList(pn, literalValues);
} else if(jsonValue instanceof Boolean) { } else if(jsonValue.isBoolean()) {
Boolean booleanValue = jsonObject.getBoolean(literalLabel); Boolean booleanValue = jsonObject.get(literalLabel).asBoolean();
//Adds string version //Adds string version
literalValues.add(booleanValue.toString()); literalValues.add(booleanValue.toString());
} }
@ -227,19 +227,19 @@ public class ManagePagePreprocessor extends
for(String uriLabel:uriLabels) { for(String uriLabel:uriLabels) {
List<String> uriValues = new ArrayList<String>(); List<String> uriValues = new ArrayList<String>();
Object jsonValue = jsonObject.get(uriLabel); JsonNode jsonValue = jsonObject.get(uriLabel);
//Var names will depend on which data getter object this is on the page, so depends on counter //Var names will depend on which data getter object this is on the page, so depends on counter
String submissionUriName = pn.getVarName(uriLabel, counter); String submissionUriName = pn.getVarName(uriLabel, counter);
//if single value, then, add to values //if single value, then, add to values
if(jsonValue instanceof String) { if(jsonValue.isTextual()) {
//Var names will depend on which data getter object this is on the page, so depends on counter //Var names will depend on which data getter object this is on the page, so depends on counter
//This retrieves the value for this particular json object and adds to list //This retrieves the value for this particular json object and adds to list
uriValues.add(jsonObject.getString(uriLabel)); uriValues.add(jsonObject.get(uriLabel).asText());
} else if(jsonValue instanceof JSONArray) { } else if(jsonValue.isArray()) {
//multiple values //multiple values
JSONArray values = jsonObject.getJSONArray(uriLabel); ArrayNode values = (ArrayNode) jsonObject.get(uriLabel);
uriValues = (List<String>) JSONSerializer.toJava(values); uriValues = JacksonUtils.jsonArrayToStrings(values);
} else { } else {
//This may include JSON Objects but no way to deal with these right now //This may include JSON Objects but no way to deal with these right now
@ -257,8 +257,8 @@ public class ManagePagePreprocessor extends
//Although this is editing an existing page, new content might have been added which would not include //Although this is editing an existing page, new content might have been added which would not include
//existing data getter URIs, so important to check whether the key exists within the json object in the first place //existing data getter URIs, so important to check whether the key exists within the json object in the first place
String dataGetterURISubmissionName = pn.getDataGetterVarName(counter); String dataGetterURISubmissionName = pn.getDataGetterVarName(counter);
if(jsonObject.containsKey("URI")) { if(jsonObject.has("URI")) {
String URIValue = jsonObject.getString("URI"); String URIValue = jsonObject.get("URI").asText();
if(URIValue != null) { if(URIValue != null) {
log.debug("Existing URI for data getter found: " + URIValue); log.debug("Existing URI for data getter found: " + URIValue);
submission.addUriToForm(editConfiguration, dataGetterURISubmissionName, new String[]{URIValue}); submission.addUriToForm(editConfiguration, dataGetterURISubmissionName, new String[]{URIValue});
@ -366,8 +366,8 @@ public class ManagePagePreprocessor extends
//Each JSON Object will indicate the type of the data getter within it //Each JSON Object will indicate the type of the data getter within it
private String getDataGetterClass(JSONObject jsonObject) { private String getDataGetterClass(ObjectNode jsonObject) {
String javaURI = jsonObject.getString("dataGetterClass"); String javaURI = jsonObject.get("dataGetterClass").asText();
return getQualifiedDataGetterName(javaURI); return getQualifiedDataGetterName(javaURI);

View file

@ -8,12 +8,8 @@ import java.util.List;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.jena.ontology.OntModel; import org.apache.jena.ontology.OntModel;
import org.apache.jena.query.Query; import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution; import org.apache.jena.query.QueryExecution;
@ -23,6 +19,10 @@ import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet; import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Resource; import org.apache.jena.rdf.model.Resource;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
@ -153,10 +153,10 @@ public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract {
return query; return query;
} }
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) { public ObjectNode getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) {
JSONObject jObject = new JSONObject(); ObjectNode jObject = new ObjectMapper().createObjectNode();
jObject.element("dataGetterClass", classType); jObject.put("dataGetterClass", classType);
jObject.element(classTypeVarBase, classType); jObject.put(classTypeVarBase, classType);
//Get class group //Get class group
getExistingClassGroup(dataGetterURI, jObject, queryModel); getExistingClassGroup(dataGetterURI, jObject, queryModel);
//Get classes within class group //Get classes within class group
@ -164,7 +164,7 @@ public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract {
return jObject; return jObject;
} }
private void getExistingClassGroup(String dataGetterURI, JSONObject jObject, OntModel queryModel) { private void getExistingClassGroup(String dataGetterURI, ObjectNode jObject, OntModel queryModel) {
String querystr = getExistingValuesClassGroup(dataGetterURI); String querystr = getExistingValuesClassGroup(dataGetterURI);
QueryExecution qe = null; QueryExecution qe = null;
try{ try{
@ -175,7 +175,7 @@ public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract {
QuerySolution qs = results.nextSolution(); QuerySolution qs = results.nextSolution();
Resource classGroupResource = qs.getResource("classGroup"); Resource classGroupResource = qs.getResource("classGroup");
//Put both literals in existing literals //Put both literals in existing literals
jObject.element(classGroupVarBase, classGroupResource.getURI()); jObject.put(classGroupVarBase, classGroupResource.getURI());
} }
} catch(Exception ex) { } catch(Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex); log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
@ -186,10 +186,10 @@ public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract {
//Assumes JSON Object received will have the class group resource URI within it //Assumes JSON Object received will have the class group resource URI within it
//TODO: Refactor to take advantage of existing code that uses OTHER JSON library //TODO: Refactor to take advantage of existing code that uses OTHER JSON library
protected void getExistingClassesInClassGroup(ServletContext context, String dataGetterURI, JSONObject jObject) { protected void getExistingClassesInClassGroup(ServletContext context, String dataGetterURI, ObjectNode jObject) {
//Check for class group resource within json object //Check for class group resource within json object
if(jObject.containsKey(classGroupVarBase)) { if(jObject.has(classGroupVarBase)) {
String classGroupURI = jObject.getString(classGroupVarBase); String classGroupURI = jObject.get(classGroupVarBase).asText();
//Get classes for classGroupURI and include in //Get classes for classGroupURI and include in
VClassGroupCache vcgc = VClassGroupCache.getVClassGroupCache(context); VClassGroupCache vcgc = VClassGroupCache.getVClassGroupCache(context);
VClassGroup group = vcgc.getGroup(classGroupURI); VClassGroup group = vcgc.getGroup(classGroupURI);
@ -201,20 +201,21 @@ public class ProcessClassGroupDataGetterN3 extends ProcessDataGetterAbstract {
//JSONObject will include results JSON object that will include classes JSON Arrya as well as //JSONObject will include results JSON object that will include classes JSON Arrya as well as
//class group information //class group information
protected void populateClassesInClassGroupJSON(JSONObject jObject, VClassGroup group) { protected void populateClassesInClassGroupJSON(ObjectNode jObject, VClassGroup group) {
JSONArray classes = new JSONArray(); ObjectMapper mapper = new ObjectMapper();
ArrayNode classes = mapper.createArrayNode();
for( VClass vc : group){ for( VClass vc : group){
JSONObject vcObj = new JSONObject(); ObjectNode vcObj = mapper.createObjectNode();
vcObj.element("name", vc.getName()); vcObj.put("name", vc.getName());
vcObj.element("URI", vc.getURI()); vcObj.put("URI", vc.getURI());
classes.add(vcObj); classes.add(vcObj);
} }
JSONObject results = new JSONObject(); ObjectNode results = mapper.createObjectNode();
results.element("classes", classes); results.set("classes", classes);
results.element("classGroupName", group.getPublicName()); results.put("classGroupName", group.getPublicName());
results.element("classGroupUri", group.getURI()); results.put("classGroupUri", group.getURI());
jObject.element("results", results); jObject.set("results", results);
} }
} }

View file

@ -2,16 +2,16 @@
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils; package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.sf.json.JSONObject;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import org.apache.jena.ontology.OntModel; import org.apache.jena.ontology.OntModel;
import org.apache.jena.rdf.model.Literal; import org.apache.jena.rdf.model.Literal;
import com.fasterxml.jackson.databind.node.ObjectNode;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
//Returns the appropriate n3 based on data getter //Returns the appropriate n3 based on data getter
@ -36,7 +36,7 @@ public interface ProcessDataGetterN3 {
public Map<String, List<Literal>> retrieveExistingLiteralValues(); public Map<String, List<Literal>> retrieveExistingLiteralValues();
public Map<String, List<String>> retrieveExistingUriValues(); public Map<String, List<String>> retrieveExistingUriValues();
public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel); public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel);
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context); public ObjectNode getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context);
public String replaceEncodedQuotesWithEscapedQuotes(String inputStr); public String replaceEncodedQuotesWithEscapedQuotes(String inputStr);
} }

View file

@ -5,18 +5,18 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocess
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.HashMap; import java.util.HashMap;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
/* /*
* This class determines what n3 should be returned for a particular data getter and can be overwritten or extended in VIVO. * This class determines what n3 should be returned for a particular data getter and can be overwritten or extended in VIVO.
*/ */
public class ProcessDataGetterN3Utils { public class ProcessDataGetterN3Utils {
private static final Log log = LogFactory.getLog(ProcessDataGetterN3Utils.class); private static final Log log = LogFactory.getLog(ProcessDataGetterN3Utils.class);
public static ProcessDataGetterN3 getDataGetterProcessorN3(String dataGetterClass, JSONObject jsonObject) { public static ProcessDataGetterN3 getDataGetterProcessorN3(String dataGetterClass, ObjectNode jsonObject) {
HashMap<String, String> map = ProcessDataGetterN3Map.getDataGetterTypeToProcessorMap(); HashMap<String, String> map = ProcessDataGetterN3Map.getDataGetterTypeToProcessorMap();
// //
if(map.containsKey(dataGetterClass)) { if(map.containsKey(dataGetterClass)) {
@ -32,7 +32,7 @@ public class ProcessDataGetterN3Utils {
return null; return null;
} }
private static ProcessDataGetterN3 instantiateClass(String processorClass, JSONObject jsonObject) { private static ProcessDataGetterN3 instantiateClass(String processorClass, ObjectNode jsonObject) {
ProcessDataGetterN3 pn = null; ProcessDataGetterN3 pn = null;
try { try {
Class<?> clz = Class.forName(processorClass); Class<?> clz = Class.forName(processorClass);

View file

@ -5,13 +5,11 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocess
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.servlet.ServletContext;
import net.sf.json.JSONObject; import javax.servlet.ServletContext;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.jena.ontology.OntModel; import org.apache.jena.ontology.OntModel;
import org.apache.jena.query.Query; import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution; import org.apache.jena.query.QueryExecution;
@ -21,6 +19,9 @@ import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet; import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Literal; import org.apache.jena.rdf.model.Literal;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
//Returns the appropriate n3 based on data getter //Returns the appropriate n3 based on data getter
public class ProcessFixedHTMLN3 extends ProcessDataGetterAbstract { public class ProcessFixedHTMLN3 extends ProcessDataGetterAbstract {
@ -136,10 +137,10 @@ public class ProcessFixedHTMLN3 extends ProcessDataGetterAbstract {
//Method to create a JSON object with existing values to return to form //Method to create a JSON object with existing values to return to form
//There may be a better way to do this without having to run the query twice //There may be a better way to do this without having to run the query twice
//TODO: Refactor code if required //TODO: Refactor code if required
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) { public ObjectNode getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) {
JSONObject jObject = new JSONObject(); ObjectNode jObject = new ObjectMapper().createObjectNode();
jObject.element("dataGetterClass", classType); jObject.put("dataGetterClass", classType);
jObject.element(classTypeVarBase, classType); jObject.put(classTypeVarBase, classType);
String querystr = getExistingValuesSparqlQuery(dataGetterURI); String querystr = getExistingValuesSparqlQuery(dataGetterURI);
QueryExecution qe = null; QueryExecution qe = null;
try{ try{
@ -152,9 +153,9 @@ public class ProcessFixedHTMLN3 extends ProcessDataGetterAbstract {
Literal htmlValueLiteral = qs.getLiteral("htmlValue"); Literal htmlValueLiteral = qs.getLiteral("htmlValue");
String htmlValueString = htmlValueLiteral.getString(); String htmlValueString = htmlValueLiteral.getString();
htmlValueString = this.replaceQuotes(htmlValueString); htmlValueString = this.replaceQuotes(htmlValueString);
jObject.element("saveToVar", saveToVarLiteral.getString()); jObject.put("saveToVar", saveToVarLiteral.getString());
//TODO: Handle single and double quotes within string and escape properlyu //TODO: Handle single and double quotes within string and escape properlyu
jObject.element("htmlValue", htmlValueString); jObject.put("htmlValue", htmlValueString);
} }
} catch(Exception ex) { } catch(Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex); log.error("Exception occurred in retrieving existing values with query " + querystr, ex);

View file

@ -2,16 +2,14 @@
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils; package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils;
import java.util.Collection;
import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.jena.ontology.OntModel; import org.apache.jena.ontology.OntModel;
import org.apache.jena.query.Query; import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution; import org.apache.jena.query.QueryExecution;
@ -19,16 +17,15 @@ import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory; import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.QuerySolution; import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet; import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Literal;
import org.apache.jena.rdf.model.Resource; import org.apache.jena.rdf.model.Resource;
import javax.servlet.ServletContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
//Returns the appropriate n3 for selection of classes from within class group //Returns the appropriate n3 for selection of classes from within class group
public class ProcessIndividualsForClassesDataGetterN3 extends ProcessClassGroupDataGetterN3 { public class ProcessIndividualsForClassesDataGetterN3 extends ProcessClassGroupDataGetterN3 {
private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter"; private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter";
@ -174,11 +171,11 @@ public class ProcessIndividualsForClassesDataGetterN3 extends ProcessClassGroup
} }
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) { public ObjectNode getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) {
JSONObject jObject = new JSONObject(); ObjectNode jObject = new ObjectMapper().createObjectNode();
jObject.element("dataGetterClass", classType); jObject.put("dataGetterClass", classType);
//Update to include class type as variable //Update to include class type as variable
jObject.element(classTypeVarBase, classType); jObject.put(classTypeVarBase, classType);
//Get selected class group and which classes were selected //Get selected class group and which classes were selected
getExistingClassGroupAndIndividuals(dataGetterURI, jObject, queryModel); getExistingClassGroupAndIndividuals(dataGetterURI, jObject, queryModel);
//Get all classes within the class group //Get all classes within the class group
@ -186,14 +183,14 @@ public class ProcessIndividualsForClassesDataGetterN3 extends ProcessClassGroup
return jObject; return jObject;
} }
private void getExistingClassGroupAndIndividuals(String dataGetterURI, JSONObject jObject, OntModel queryModel) { private void getExistingClassGroupAndIndividuals(String dataGetterURI, ObjectNode jObject, OntModel queryModel) {
String querystr = getExistingValuesIndividualsForClasses(dataGetterURI); String querystr = getExistingValuesIndividualsForClasses(dataGetterURI);
QueryExecution qe = null; QueryExecution qe = null;
try{ try{
Query query = QueryFactory.create(querystr); Query query = QueryFactory.create(querystr);
qe = QueryExecutionFactory.create(query, queryModel); qe = QueryExecutionFactory.create(query, queryModel);
ResultSet results = qe.execSelect(); ResultSet results = qe.execSelect();
JSONArray individualsForClasses = new JSONArray(); ArrayNode individualsForClasses = new ObjectMapper().createArrayNode();
String classGroupURI = null; String classGroupURI = null;
while( results.hasNext()){ while( results.hasNext()){
QuerySolution qs = results.nextSolution(); QuerySolution qs = results.nextSolution();
@ -207,9 +204,9 @@ public class ProcessIndividualsForClassesDataGetterN3 extends ProcessClassGroup
} }
jObject.element("classGroup", classGroupURI); jObject.put("classGroup", classGroupURI);
//this is a json array //this is a json array
jObject.element(individualClassVarNameBase, individualsForClasses); jObject.set(individualClassVarNameBase, individualsForClasses);
} catch(Exception ex) { } catch(Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex); log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
} }

View file

@ -5,13 +5,11 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocess
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.servlet.ServletContext;
import net.sf.json.JSONObject; import javax.servlet.ServletContext;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.jena.ontology.OntModel; import org.apache.jena.ontology.OntModel;
import org.apache.jena.query.Query; import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution; import org.apache.jena.query.QueryExecution;
@ -22,6 +20,9 @@ import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Literal; import org.apache.jena.rdf.model.Literal;
import org.apache.jena.rdf.model.Resource; import org.apache.jena.rdf.model.Resource;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
//Returns the appropriate n3 based on data getter //Returns the appropriate n3 based on data getter
public class ProcessSearchIndividualsDataGetterN3 extends ProcessDataGetterAbstract { public class ProcessSearchIndividualsDataGetterN3 extends ProcessDataGetterAbstract {
@ -138,10 +139,10 @@ public class ProcessSearchIndividualsDataGetterN3 extends ProcessDataGetterAbst
//Method to create a JSON object with existing values to return to form //Method to create a JSON object with existing values to return to form
//There may be a better way to do this without having to run the query twice //There may be a better way to do this without having to run the query twice
//TODO: Refactor code if required //TODO: Refactor code if required
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) { public ObjectNode getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) {
JSONObject jObject = new JSONObject(); ObjectNode jObject = new ObjectMapper().createObjectNode();
jObject.element("dataGetterClass", classType); jObject.put("dataGetterClass", classType);
jObject.element(classTypeVarBase, classType); jObject.put(classTypeVarBase, classType);
String querystr = getExistingValuesSparqlQuery(dataGetterURI); String querystr = getExistingValuesSparqlQuery(dataGetterURI);
QueryExecution qe = null; QueryExecution qe = null;
try{ try{
@ -153,9 +154,9 @@ public class ProcessSearchIndividualsDataGetterN3 extends ProcessDataGetterAbst
Literal saveToVarLiteral = qs.getLiteral("saveToVar"); Literal saveToVarLiteral = qs.getLiteral("saveToVar");
Resource vclassUriResource = qs.getResource("vclassUri"); Resource vclassUriResource = qs.getResource("vclassUri");
String vclassUriString = vclassUriResource.getURI(); String vclassUriString = vclassUriResource.getURI();
jObject.element("saveToVar", saveToVarLiteral.getString()); jObject.put("saveToVar", saveToVarLiteral.getString());
//TODO: Handle single and double quotes within string and escape properlyu //TODO: Handle single and double quotes within string and escape properlyu
jObject.element("vclassUri", vclassUriString); jObject.put("vclassUri", vclassUriString);
} }
} catch(Exception ex) { } catch(Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex); log.error("Exception occurred in retrieving existing values with query " + querystr, ex);

View file

@ -2,15 +2,14 @@
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils; package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils;
import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.jena.ontology.OntModel; import org.apache.jena.ontology.OntModel;
import org.apache.jena.query.Query; import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution; import org.apache.jena.query.QueryExecution;
@ -20,12 +19,12 @@ import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet; import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Literal; import org.apache.jena.rdf.model.Literal;
import org.apache.jena.rdf.model.Resource; import org.apache.jena.rdf.model.Resource;
import javax.servlet.ServletContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
//Returns the appropriate n3 based on data getter //Returns the appropriate n3 based on data getter
public class ProcessSparqlDataGetterN3 extends ProcessDataGetterAbstract { public class ProcessSparqlDataGetterN3 extends ProcessDataGetterAbstract {
private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter"; private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter";
@ -157,10 +156,10 @@ public class ProcessSparqlDataGetterN3 extends ProcessDataGetterAbstract {
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) { public ObjectNode getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) {
JSONObject jObject = new JSONObject(); ObjectNode jObject = new ObjectMapper().createObjectNode();
jObject.element("dataGetterClass", classType); jObject.put("dataGetterClass", classType);
jObject.element(classTypeVarBase, classType); jObject.put(classTypeVarBase, classType);
String querystr = getExistingValuesSparqlQuery(dataGetterURI); String querystr = getExistingValuesSparqlQuery(dataGetterURI);
QueryExecution qe = null; QueryExecution qe = null;
try{ try{
@ -179,12 +178,12 @@ public class ProcessSparqlDataGetterN3 extends ProcessDataGetterAbstract {
//or incorrect html //or incorrect html
queryString = replaceQuotes(queryString); queryString = replaceQuotes(queryString);
Resource queryModelResource = qs.getResource("queryModel"); Resource queryModelResource = qs.getResource("queryModel");
jObject.element("saveToVar", saveToVarLiteral.getString()); jObject.put("saveToVar", saveToVarLiteral.getString());
jObject.element("query",queryString); jObject.put("query", queryString);
if(queryModelResource != null) { if(queryModelResource != null) {
jObject.element("queryModel", queryModelResource.getURI()); jObject.put("queryModel", queryModelResource.getURI());
} else { } else {
jObject.element("queryModel", ""); jObject.put("queryModel", "");
} }
} }

View file

@ -0,0 +1,81 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.utils.json;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.core.io.JsonStringEncoder;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
/**
* Some utility methods to ease the transition from net.sf.json to Jackson.
*/
public class JacksonUtils {
private static final String QUOTE = "\"";
/**
* A "clean room" replacement for net.sf.json.util.JSONUtils.quote().
*/
public static String quote(String raw) {
if (raw == null) {
// Null string is treated like an empty string.
return QUOTE + QUOTE;
} else {
return new StringBuilder(QUOTE)
.append(JsonStringEncoder.getInstance().quoteAsString(raw))
.append(QUOTE).toString();
}
}
/**
* net.sf.json could parse a JSON string without throwing a checked
* exception. Make it so we can do the same with Jackson.
*/
public static JsonNode parseJson(String json) {
try {
return new ObjectMapper().readTree(json);
} catch (IOException e) {
throw new JacksonUtilsException(e);
}
}
/**
* net.sf.json provided this method (assuming that 'values' is an array of
* JSON objects that contain Strings.
*
* literalValues = (List<String>) JSONSerializer.toJava(values);
*
* So here is a replacement for that.
*/
public static List<String> jsonArrayToStrings(ArrayNode values) {
List<String> strings = new ArrayList<>();
for (JsonNode node : values) {
strings.add(node.asText());
}
return strings;
}
public static class JacksonUtilsException extends RuntimeException {
public JacksonUtilsException() {
super();
}
public JacksonUtilsException(String message, Throwable cause) {
super(message, cause);
}
public JacksonUtilsException(String message) {
super(message);
}
public JacksonUtilsException(Throwable cause) {
super(cause);
}
}
}

View file

@ -11,7 +11,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.jena.query.QuerySolution; import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet; import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.RDFNode; import org.apache.jena.rdf.model.RDFNode;

View file

@ -0,0 +1,148 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.PolicyOption.POLICY_NEUTRAL;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
import stubs.javax.servlet.http.HttpServletRequestStub;
/**
* Not a well-formed set of unit tests. But it's a pretty good exercise of the
* different possibilities in the output stage.
*
* Test plan:
*
* <pre>
* No data - roots is null -- NONSENSICAL
* No data - roots is empty
*
* name
* no name
*
* displayRank
* no displayRank
*
* no child classes
* child classes
*
* child class has name
* child class has no name
*
* child class has shortDef
* child class has no shortDef
*
* G1 no name, displayRank, no classes
* G2 name, no displayRank, classes
* G2C1 no name, no shortDef
* G2C2 name, shortdef
*
* Try once with no data
* Try with all data
* </pre>
*/
public class ListClassGroupsControllerTest extends ListControllerTestBase {
private static final String LINK_FORMAT_GROUP = "<a href='./editForm?uri=%s&amp;controller=Classgroup'>%s</a>";
private static final String LINK_FORMAT_CLASS = "<a href='vclassEdit?uri=%s'>%s</a>";
private static final String GROUP1 = "http://ont1/group1";
private static final String GROUP2 = "http://ont1/group2";
private static final String CLASS1 = "http://ont1/class1";
private static final String CLASS2 = "http://ont1/class2";
private static final String CLASS2_NAME = "The Second Class";
private static final String CLASS2_SHORT_DEF = "A Marvelous Class";
private static final int GROUP1_RANK = 5;
private static final String GROUP2_NAME = "The Second Group";
private static final JsonNode JSON_EMPTY_RESPONSE = arrayOf();
private static final JsonNode JSON_FULL_RESPONSE = arrayOf(
groupListNode(LINK_FORMAT_GROUP, GROUP1, "(unnamed group)",
"" + GROUP1_RANK),
groupListNode(LINK_FORMAT_GROUP, GROUP2, GROUP2_NAME, "",
groupMemberNode("", "", "", ""),
groupMemberNode(LINK_FORMAT_CLASS, CLASS2, CLASS2_NAME,
CLASS2_SHORT_DEF)));
private ListClassGroupsController controller;
private HttpServletRequestStub req;
private ModelAccessFactoryStub modelsFactory;
private WebappDaoFactoryStub wadf;
private VClassGroupDaoStub vcgDao;
@Before
public void setup() {
controller = new ListClassGroupsController();
req = new HttpServletRequestStub();
vcgDao = new VClassGroupDaoStub();
wadf = new WebappDaoFactoryStub();
wadf.setVClassGroupDao(vcgDao);
modelsFactory = new ModelAccessFactoryStub();
modelsFactory.get(req).setWebappDaoFactory(wadf, POLICY_NEUTRAL);
}
// ----------------------------------------------------------------------
// The tests
// ----------------------------------------------------------------------
@Test
public void noData() throws Exception {
assertMatchingJson(controller, req, JSON_EMPTY_RESPONSE);
}
@Test
public void basicJsonTest() throws Exception {
populate();
/*
* The controller attempts to handle the case of a class with no name,
* but instead it returns invalid json.
*/
String rawResponse = getJsonFromController(controller, req);
String kluged = rawResponse.replace("[\"\"", "[ {\"name\": \"\"");
assertKlugedJson(JSON_FULL_RESPONSE, kluged);
// assertMatchingJson(controller, req, JSON_FULL_RESPONSE);
}
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
private void populate() {
vcgDao.setGroups(vClassGroup(GROUP1, null, GROUP1_RANK),
vClassGroup(GROUP2, GROUP2_NAME, -1, vclass(CLASS1, null, null),
vclass(CLASS2, CLASS2_NAME, CLASS2_SHORT_DEF)));
}
private VClassGroup vClassGroup(String uri, String name, int rank,
VClass... vClasses) {
VClassGroup group = new VClassGroup(uri, name, rank);
for (VClass vClass : vClasses) {
group.add(vClass);
}
return group;
}
private VClass vclass(String uri, String name, String shortDef) {
VClass vc = new VClass(uri);
vc.setName(name);
vc.setShortDef(shortDef);
return vc;
}
}

View file

@ -0,0 +1,185 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import javax.servlet.http.HttpServletRequest;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
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;
/**
* Some useful methods for assembling JSON structures that will match the test
* results.
*
* Also, some methods for running the tests, with and without kluging the
* results.
*/
public class ListControllerTestBase extends AbstractTestClass {
protected static ObjectMapper mapper = new ObjectMapper();
/**
* Create a JSON array from nodes.
*/
protected static ArrayNode arrayOf(JsonNode... nodes) {
ArrayNode array = mapper.createArrayNode();
for (JsonNode node : nodes) {
array.add(node);
}
return array;
}
/**
* Show a DataProperty or an ObjectProperty in a list.
*/
protected static ObjectNode propertyListNode(String path, String uri,
String name, String internalName, String domainVClass,
String rangeVClass, String group) {
String nameString = String.format("<a href='%s?uri=%s'>%s</a>", path,
urlEncode(uri), name);
ObjectNode propNode = mapper.createObjectNode().put("name", nameString);
propNode.putObject("data").put("internalName", internalName)
.put("domainVClass", domainVClass)
.put("rangeVClass", rangeVClass).put("group", group);
return propNode;
}
/**
* Show a DataProperty or an ObjectProperty in a hierarchy.
*/
protected static ObjectNode propertyHierarchyNode(String path, String uri,
String name, String internalName, String domainVClass,
String rangeVClass, String group, ObjectNode... children) {
ObjectNode propNode = propertyListNode(path, uri, name, internalName,
domainVClass, rangeVClass, group);
propNode.set("children", arrayOf(children));
return propNode;
}
/**
* Show a VClass in a list.
*/
protected static ObjectNode degenerateVclassListNode(String name,
String shortDef, String classGroup, String ontology) {
ObjectNode vcNode = mapper.createObjectNode().put("name", name);
vcNode.putObject("data").put("shortDef", shortDef)
.put("classGroup", classGroup).put("ontology", ontology);
return vcNode;
}
/**
* Show a VClass in a list.
*/
protected static ObjectNode vclassListNode(String path, String uri,
String name, String shortDef, String classGroup, String ontology) {
String nameString = String.format("<a href='%s?uri=%s'>%s</a>", path,
urlEncode(uri), name);
ObjectNode vcNode = mapper.createObjectNode().put("name", nameString);
vcNode.putObject("data").put("shortDef", shortDef)
.put("classGroup", classGroup).put("ontology", ontology);
return vcNode;
}
/**
* Show a VClass in a hierarchy.
*/
protected static ObjectNode vclassHierarchyNode(String path, String uri,
String name, String shortDef, String classGroup, String ontology,
ObjectNode... children) {
ObjectNode vcNode = vclassListNode(path, uri, name, shortDef,
classGroup, ontology);
vcNode.set("children", arrayOf(children));
return vcNode;
}
/**
* Show a ClassGroup or PropertyGroup in a list.
*/
protected static ObjectNode groupListNode(String linkFormat, String uri,
String name, String displayRank, ObjectNode... children) {
String nameString = String.format(linkFormat, urlEncode(uri), name);
ObjectNode gNode = mapper.createObjectNode().put("name", nameString);
gNode.putObject("data").put("displayRank", displayRank);
gNode.set("children", arrayOf(children));
return gNode;
}
/**
* Show a Class or Property as part of a Group.
*/
protected static ObjectNode groupMemberNode(String linkFormat, String uri,
String name, String shortDef, ObjectNode... children) {
String nameString = String.format(linkFormat, urlEncode(uri), name);
ObjectNode memberNode = mapper.createObjectNode().put("name",
nameString);
memberNode.putObject("data").put("shortDef", shortDef);
memberNode.set("children", arrayOf(children));
return memberNode;
}
/**
* Based on the fact that each of these controllers returns a
* TemplateResponseValues object with a "jsonTree" in the body map.
*
* That jsonTree would be an standard JSON array, except that it is missing
* the enclosing brackets, so we need to add them before comparing to the
* expected value.
*
* Add the brackets, read the strings, and compare.
*/
protected static void assertMatchingJson(FreemarkerHttpServlet controller,
HttpServletRequest req, JsonNode expected) throws Exception {
String jsonString = getJsonFromController(controller, req);
JsonNode actual = mapper.readTree("[" + jsonString + "]");
assertEquals(expected, actual);
}
/**
* Some of the controllers have edge cases that produce invalid JSON, even
* when wrapped in enclosing brackets. For those cases, call this method,
* massage the result to form valid JSON, and call assertKlugedJson().
*/
protected static String getJsonFromController(
FreemarkerHttpServlet controller, HttpServletRequest req)
throws Exception {
ResponseValues rv = controller.processRequest(new VitroRequest(req));
assertTrue(rv instanceof TemplateResponseValues);
TemplateResponseValues trv = (TemplateResponseValues) rv;
Object o = trv.getMap().get("jsonTree");
assertTrue(o instanceof String);
String jsonString = (String) o;
return jsonString;
}
/**
* If it was necessary to manipulate the response from the controller, this
* is how to test it.
*/
protected void assertKlugedJson(JsonNode expected,
String klugedActualString) throws Exception {
JsonNode actual = mapper.readTree("[" + klugedActualString + "]");
assertEquals(expected, actual);
}
private static String urlEncode(String uri) {
try {
return URLEncoder.encode(uri, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return uri;
}
}
}

View file

@ -0,0 +1,255 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.LanguageOption.LANGUAGE_NEUTRAL;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.PolicyOption.POLICY_NEUTRAL;
import java.text.Collator;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
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.VitroRequest;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.DatatypeDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.VClassDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
import stubs.javax.servlet.http.HttpServletRequestStub;
/**
* Not a well-formed set of unit tests. But it's a pretty good exercise of the
* different possibilities in the output stage.
*
* Test plan:
*
* <pre>
* No data - roots is null -- NONSENSICAL
* No data - roots is empty
*
* Ontology is not specified
* Ontology is specified and matches
* Ontology is specified and does not match
* DataProperty does not match Ontology, but has child properties that do.
*
* Name from picklistName
* Name from getName
* Name from getUri
* Name no URL? -- NONSENSICAL
*
* InternalName from picklistName
* InternalName missing.
*
* Domain class no class URI
* Domain class no class for URI
* Domain class get picklistName from Language Aware DAO
* Domain class use picklistName from Language Neutral DAO
*
* Range no range URI
* Range no datatype for URI
* Range datatype has no name
* Range has a name
*
* Group no group URI
* Group no group for URI
* Group no name
* Group has a name
*
* DP1 Ont1, no name, no picklistName, no domainClass, no RangeClass, no GroupURI
* DP2 Ont2, name, no picklistName, no domain class for URI, no range datatype for URI, no group for GroupURI
* DP3 Ont1, picklistname, domainclass no picklistname, range datatype with no name, group has no name
* DP4 Ont1, picklistname, domainclass w/picklistname, range datatype with name, group with name
*
* Try once with no data
* Try with all data and no ontology specified
* Try with all data and Ont1, Ont2, Ont3
* </pre>
*/
public class ListDatatypePropertiesControllerTest
extends ListControllerTestBase {
private static final String PATH = "datapropEdit";
private static final String ONT1 = "http://ont1/";
private static final String ONT2 = "http://ont2/";
private static final String ONT3 = "http://ont3/";
private static final String DP1 = ONT1 + "first";
private static final String DP2 = ONT2 + "second";
private static final String DP3 = ONT1 + "third";
private static final String DP4 = ONT1 + "fourth";
private static final String DP2_NAME = "TWO";
private static final String DP3_NAME = "THREE";
private static final String DP4_NAME = "FOUR";
private static final String DP3_PICK_NAME = "The third one";
private static final String DP4_PICK_NAME = "The fourth one";
private static final String DOMAIN_NONE = "http://domain/noSuchDomain";
private static final String DOMAIN_NO_NAME = "http://domain/domainWithNoName";
private static final String DOMAIN_W_NAME = "http://domain/namedDomain";
private static final String NAME_DOMAIN = "An excellent domain";
private static final String RANGE_NONE = "http://domain/noSuchRange";
private static final String RANGE_NO_NAME = "http://domain/rangeWithNoName";
private static final String RANGE_W_NAME = "http://domain/namedRange";
private static final String NAME_RANGE = "Home on the range";
private static final String GROUP_NONE = "http://domain/noSuchGroup";
private static final String GROUP_NO_NAME = "http://domain/groupWithNoName";
private static final String GROUP_W_NAME = "http://domain/namedGroup";
private static final String NAME_GROUP = "The Groupsters";
private static final ArrayNode NO_DATA_RESPONSE = arrayOf(
mapper.createObjectNode().put("name", "No data properties found"));
private static final JsonNode RESPONSE_UNFILTERED = arrayOf(
propertyListNode(PATH, DP1, "first", "first", "", "",
"unspecified"),
propertyListNode(PATH, DP2, "second", "second", "", RANGE_NONE,
"unknown group"),
propertyListNode(PATH, DP4, DP4_PICK_NAME, DP4_PICK_NAME,
NAME_DOMAIN, NAME_RANGE, NAME_GROUP),
propertyListNode(PATH, DP3, DP3_PICK_NAME, DP3_PICK_NAME,
"domainWithNoName", "", ""));
private static final JsonNode RESPONSE_FILTERED_BY_ONT1 = arrayOf(
propertyListNode(PATH, DP1, "first", "first", "", "",
"unspecified"),
propertyListNode(PATH, DP4, DP4_PICK_NAME, DP4_PICK_NAME,
NAME_DOMAIN, NAME_RANGE, NAME_GROUP),
propertyListNode(PATH, DP3, DP3_PICK_NAME, DP3_PICK_NAME,
"domainWithNoName", "", ""));
private static final JsonNode RESPONSE_FILTERED_BY_ONT2 = arrayOf(
propertyListNode(PATH, DP2, "second", "second", "", RANGE_NONE,
"unknown group"));
private static final JsonNode RESPONSE_FILTERED_BY_ONT3 = arrayOf(
mapper.createObjectNode().put("name", "No data properties found"));
private ListDatatypePropertiesController controller;
private HttpServletRequestStub req;
private ModelAccessFactoryStub modelsFactory;
private WebappDaoFactoryStub wadf;
private DataPropertyDaoStub dpdao;
private DatatypeDaoStub dtdao;
private VClassDaoStub vcdao;
private PropertyGroupDaoStub pgdao;
@Before
public void setup() {
controller = new ListDatatypePropertiesController();
req = new HttpServletRequestStub();
new VitroRequest(req).setCollator(Collator.getInstance());
dpdao = new DataPropertyDaoStub();
dtdao = new DatatypeDaoStub();
vcdao = new VClassDaoStub();
pgdao = new PropertyGroupDaoStub();
wadf = new WebappDaoFactoryStub();
wadf.setDataPropertyDao(dpdao);
wadf.setDatatypeDao(dtdao);
wadf.setVClassDao(vcdao);
wadf.setPropertyGroupDao(pgdao);
modelsFactory = new ModelAccessFactoryStub();
modelsFactory.get(req).setWebappDaoFactory(wadf, POLICY_NEUTRAL);
modelsFactory.get(req).setWebappDaoFactory(wadf, LANGUAGE_NEUTRAL,
POLICY_NEUTRAL);
}
// ----------------------------------------------------------------------
// The tests
// ----------------------------------------------------------------------
@Test
public void noDataProperties() throws Exception {
assertMatchingJson(controller, req, NO_DATA_RESPONSE);
}
@Test
public void unfiltered() throws Exception {
populate();
assertMatchingJson(controller, req, RESPONSE_UNFILTERED);
}
@Test
public void filteredByOnt1() throws Exception {
populate();
req.addParameter("ontologyUri", ONT1);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT1);
}
@Test
public void filteredByOnt2() throws Exception {
populate();
req.addParameter("ontologyUri", ONT2);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT2);
}
@Test
public void filteredByOnt3() throws Exception {
populate();
req.addParameter("ontologyUri", ONT3);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT3);
}
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
private void populate() {
vcdao.setVClass(vclass(DOMAIN_NO_NAME, null));
vcdao.setVClass(vclass(DOMAIN_W_NAME, NAME_DOMAIN));
dtdao.addDatatype(datatype(RANGE_NO_NAME, null));
dtdao.addDatatype(datatype(RANGE_W_NAME, NAME_RANGE));
pgdao.addPropertyGroup(propertyGroup(GROUP_NO_NAME, null));
pgdao.addPropertyGroup(propertyGroup(GROUP_W_NAME, NAME_GROUP));
dpdao.addDataProperty(dataProperty(DP1, null, null, null, null, null));
dpdao.addDataProperty(dataProperty(DP2, DP2_NAME, null, DOMAIN_NONE,
RANGE_NONE, GROUP_NONE));
dpdao.addDataProperty(dataProperty(DP3, DP3_NAME, DP3_PICK_NAME,
DOMAIN_NO_NAME, RANGE_NO_NAME, GROUP_NO_NAME));
dpdao.addDataProperty(dataProperty(DP4, DP4_NAME, DP4_PICK_NAME,
DOMAIN_W_NAME, RANGE_W_NAME, GROUP_W_NAME));
}
private DataProperty dataProperty(String uri, String name,
String pickListName, String domainClassUri, String rangeDatatypeUri,
String groupUri) {
DataProperty dp = new DataProperty();
dp.setURI(uri);
dp.setName(name);
dp.setPickListName(pickListName);
dp.setDomainClassURI(domainClassUri);
dp.setRangeDatatypeURI(rangeDatatypeUri);
dp.setGroupURI(groupUri);
return dp;
}
private Datatype datatype(String uri, String name) {
Datatype dt = new Datatype();
dt.setUri(uri);
dt.setName(name);
return dt;
}
private VClass vclass(String uri, String pickListName) {
VClass vc = new VClass();
vc.setURI(uri);
vc.setPickListName(pickListName);
return vc;
}
private PropertyGroup propertyGroup(String uri, String name) {
PropertyGroup pg = new PropertyGroup();
pg.setURI(uri);
pg.setName(name);
return pg;
}
}

View file

@ -0,0 +1,170 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.PolicyOption.POLICY_NEUTRAL;
import java.util.ArrayList;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.beans.Property;
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
import stubs.javax.servlet.http.HttpServletRequestStub;
/**
* Not a well-formed set of unit tests. But it's a pretty good exercise of the
* different possibilities in the output stage.
*
* Test plan:
*
* <pre>
* No data - roots is null -- NONSENSICAL
* No data - roots is empty
*
* name
* no name - (unnamed group)
*
* display rank
* no display rank
*
* no child properties
* child property is data property
* child properti is object property
*
* child data property has no name
* child data property has name
* child object property has no domainPublic
* child object property has domainPublic
*
* G1 no name, displayRank, no classes
* G2 name, no displayRank, classes
* G2DP1 no name, no shortDef
* G2DP2 name, shortdef
* G2OP1 no domainPublic, no shortDef
* G2OP2 domainPublic, shortdef
*
* Try once with no data
* Try with all data
* </pre>
*/
public class ListPropertyGroupsControllerTest extends ListControllerTestBase {
private static final String LINK_FORMAT_GROUP = "<a href='./editForm?uri=%s&amp;controller=PropertyGroup'>%s</a>";
private static final String LINK_FORMAT_DATA_PROPERTY = "<a href='datapropEdit?uri=%s'>%s</a>";
private static final String LINK_FORMAT_OBJECT_PROPERTY = "<a href='propertyEdit?uri=%s'>%s</a>";
private static final String GROUP1 = "http://ont1/group1";
private static final String GROUP2 = "http://ont1/group2";
private static final String DP1 = "http://ont1/dp1";
private static final String DP2 = "http://ont1/dp2";
private static final String OP1 = "http://ont1/op1";
private static final String OP2 = "http://ont1/op2";
private static final String DP2_NAME = "A second data property";
private static final String OP2_DOMAIN_PUBLIC = "The second domain";
private static final int GROUP1_RANK = 5;
private static final String GROUP2_NAME = "The Second Group";
private static final JsonNode JSON_EMPTY_RESPONSE = arrayOf();
private static final JsonNode JSON_FULL_RESPONSE = arrayOf(
groupListNode(LINK_FORMAT_GROUP, GROUP2, GROUP2_NAME, "",
groupMemberNode(LINK_FORMAT_DATA_PROPERTY, DP1, null, ""),
groupMemberNode(LINK_FORMAT_DATA_PROPERTY, DP2, DP2_NAME,
""),
groupMemberNode(LINK_FORMAT_OBJECT_PROPERTY, OP1, null, ""),
groupMemberNode(LINK_FORMAT_OBJECT_PROPERTY, OP2,
OP2_DOMAIN_PUBLIC, "")),
groupListNode(LINK_FORMAT_GROUP, GROUP1, "(unnamed group)",
"" + GROUP1_RANK));
private ListPropertyGroupsController controller;
private HttpServletRequestStub req;
private ModelAccessFactoryStub modelsFactory;
private WebappDaoFactoryStub wadf;
private PropertyGroupDaoStub pgdao;
@Before
public void setup() {
controller = new ListPropertyGroupsController();
req = new HttpServletRequestStub();
pgdao = new PropertyGroupDaoStub();
wadf = new WebappDaoFactoryStub();
wadf.setPropertyGroupDao(pgdao);
modelsFactory = new ModelAccessFactoryStub();
modelsFactory.get(req).setWebappDaoFactory(wadf, POLICY_NEUTRAL);
}
// ----------------------------------------------------------------------
// The tests
// ----------------------------------------------------------------------
@Test
public void noData() throws Exception {
assertMatchingJson(controller, req, JSON_EMPTY_RESPONSE);
}
@Test
public void basicJsonTest() throws Exception {
populate();
// /*
// * The controller attempts to handle the case of a class with no name,
// * but instead it returns invalid json.
// */
// String rawResponse = getJsonFromController(controller, req);
// String kluged = rawResponse.replace("[\"\"", "[ {\"name\": \"\"");
// assertKlugedJson(JSON_FULL_RESPONSE, kluged);
assertMatchingJson(controller, req, JSON_FULL_RESPONSE);
}
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
private void populate() {
pgdao.addPropertyGroup(propertyGroup(GROUP1, "", GROUP1_RANK));
pgdao.addPropertyGroup(
propertyGroup(GROUP2, GROUP2_NAME, -1, dataProperty(DP1, null),
dataProperty(DP2, DP2_NAME), objectProperty(OP1, null),
objectProperty(OP2, OP2_DOMAIN_PUBLIC)));
}
private PropertyGroup propertyGroup(String uri, String name,
int displayRank, Property... properties) {
PropertyGroup pg = new PropertyGroup();
pg.setURI(uri);
pg.setName(name);
pg.setDisplayRank(displayRank);
pg.setPropertyList(new ArrayList<>(Arrays.asList(properties)));
return pg;
}
private ObjectProperty objectProperty(String uri, String name) {
ObjectProperty op = new ObjectProperty();
op.setURI(uri);
op.setDomainPublic(name);
return op;
}
private DataProperty dataProperty(String uri, String name) {
DataProperty dp = new DataProperty();
dp.setURI(uri);
dp.setName(name);
return dp;
}
}

View file

@ -0,0 +1,253 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.LanguageOption.LANGUAGE_NEUTRAL;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.PolicyOption.POLICY_NEUTRAL;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.beans.Property;
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.OntologyDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.VClassDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
import stubs.javax.servlet.http.HttpServletRequestStub;
/**
* Not a well-formed set of unit tests. But it's a pretty good exercise of the
* different possibilities in the output stage.
*
* Test plan:
*
* <pre>
* No data - roots is null -- NONSENSICAL
* No data - roots is empty
*
* Ontology is not specified
* Ontology is specified and matches
* Ontology is specified and does not match
* DataProperty does not match Ontology, but has child properties that do.
*
* Name from picklistName
* Name from getUri
* Name no URL? -- NONSENSICAL
*
* InternalName from localNameWithPrefix
* InternalName from localName
* InternalName from URI
*
* Domain class no class URI
* Domain class no class for URI
* Domain class use picklistName
*
* Range class no class URI
* Range class no class for URI
* Range class use picklistName
*
* Group no group URI
* Group no group for URI
* Group no name
* Group has a name
*
* OP1 Ont1, no picklistName, no localNameWithPrefix, no domainClass, no rangeClass, no GroupURI
* OP2 Ont2, picklistName, no localNameWithPrefix, no domain class for URI, no range class for URI, no group for GroupURI
* OP3 Ont1, picklistName, localNameWithPrefix, domainclass no picklistname, range class no picklistname, group has no name
* OP4 Ont1, picklistName, localNameWithPrefix, domainclass w/picklistname, range class w/picklistname, group with name
*
* Try once with no data
* Try with all data and no ontology specified
* Try with all data and Ont1, Ont2, Ont3
* </pre>
*/
public class ListPropertyWebappsControllerTest extends ListControllerTestBase {
private static final String PATH = "./propertyEdit";
private static final String ONT1 = "http://ont1/";
private static final String ONT2 = "http://ont2/";
private static final String ONT3 = "http://ont3/";
private static final String OP1 = ONT1 + "first";
private static final String OP2 = ONT2 + "second";
private static final String OP3 = ONT1 + "third";
private static final String OP4 = ONT1 + "fourth";
private static final String OP2_PICK_NAME = "The second one";
private static final String OP3_PICK_NAME = "The third one";
private static final String OP4_PICK_NAME = "The fourth one";
private static final String OP3_LOCALNAME_W_PREFIX = "ontology1:third";
private static final String OP4_LOCALNAME_W_PREFIX = "ontology1:fourth";
private static final String DOMAIN_NONE = "http://domain/noSuchDomain";
private static final String DOMAIN_NO_NAME = "http://domain/domainWithNoName";
private static final String DOMAIN_W_NAME = "http://domain/namedDomain";
private static final String NAME_DOMAIN = "An excellent domain";
private static final String RANGE_NONE = "http://domain/noSuchRange";
private static final String RANGE_NO_NAME = "http://domain/rangeWithNoName";
private static final String RANGE_W_NAME = "http://domain/namedRange";
private static final String NAME_RANGE = "Home on the range";
private static final String GROUP_NONE = "http://domain/noSuchGroup";
private static final String GROUP_NO_NAME = "http://domain/groupWithNoName";
private static final String GROUP_W_NAME = "http://domain/namedGroup";
private static final String NAME_GROUP = "The Groupsters";
private static final JsonNode NO_DATA_RESPONSE = arrayOf(mapper
.createObjectNode().put("name", "No object properties found"));
private static final JsonNode RESPONSE_UNFILTERED = arrayOf(
propertyListNode(PATH, OP1, "first", "first", "", "",
"unspecified"),
propertyListNode(PATH, OP4, OP4_PICK_NAME, OP4_LOCALNAME_W_PREFIX,
NAME_DOMAIN, NAME_RANGE, NAME_GROUP),
propertyListNode(PATH, OP2, OP2_PICK_NAME, "second", "", "",
"unknown group"),
propertyListNode(PATH, OP3, OP3_PICK_NAME, OP3_LOCALNAME_W_PREFIX,
"domainWithNoName", "rangeWithNoName", ""));
private static final JsonNode RESPONSE_FILTERED_BY_ONT1 = arrayOf(
propertyListNode(PATH, OP1, "first", "first", "", "",
"unspecified"),
propertyListNode(PATH, OP4, OP4_PICK_NAME, OP4_LOCALNAME_W_PREFIX,
NAME_DOMAIN, NAME_RANGE, NAME_GROUP),
propertyListNode(PATH, OP3, OP3_PICK_NAME, OP3_LOCALNAME_W_PREFIX,
"domainWithNoName", "rangeWithNoName", ""));
private static final JsonNode RESPONSE_FILTERED_BY_ONT2 = arrayOf(
propertyListNode(PATH, OP2, OP2_PICK_NAME, "second", "", "",
"unknown group"));
private static final JsonNode RESPONSE_FILTERED_BY_ONT3 = arrayOf(mapper
.createObjectNode().put("name", "No object properties found"));
private ListPropertyWebappsController controller;
private HttpServletRequestStub req;
private ModelAccessFactoryStub modelsFactory;
private WebappDaoFactoryStub wadf;
private ObjectPropertyDaoStub opdao;
private OntologyDaoStub odao;
private PropertyGroupDaoStub pgdao;
private VClassDaoStub vcdao;
@Before
public void setup() {
controller = new ListPropertyWebappsController();
req = new HttpServletRequestStub();
new VitroRequest(req).setCollator(Collator.getInstance());
opdao = new ObjectPropertyDaoStub();
odao = new OntologyDaoStub();
pgdao = new PropertyGroupDaoStub();
vcdao = new VClassDaoStub();
wadf = new WebappDaoFactoryStub();
wadf.setObjectPropertyDao(opdao);
wadf.setOntologyDao(odao);
wadf.setPropertyGroupDao(pgdao);
wadf.setVClassDao(vcdao);
modelsFactory = new ModelAccessFactoryStub();
modelsFactory.get(req).setWebappDaoFactory(wadf, POLICY_NEUTRAL);
modelsFactory.get(req).setWebappDaoFactory(wadf, POLICY_NEUTRAL,
LANGUAGE_NEUTRAL);
}
// ----------------------------------------------------------------------
// The tests
// ----------------------------------------------------------------------
@Test
public void noDataProperties() throws Exception {
assertMatchingJson(controller, req, NO_DATA_RESPONSE);
}
@Test
public void unfiltered() throws Exception {
populate();
assertMatchingJson(controller, req, RESPONSE_UNFILTERED);
}
@Test
public void filteredByOnt1() throws Exception {
populate();
req.addParameter("ontologyUri", ONT1);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT1);
}
@Test
public void filteredByOnt2() throws Exception {
populate();
req.addParameter("ontologyUri", ONT2);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT2);
}
@Test
public void filteredByOnt3() throws Exception {
populate();
req.addParameter("ontologyUri", ONT3);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT3);
}
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
private void populate() {
vcdao.setVClass(vclass(DOMAIN_NO_NAME, null));
vcdao.setVClass(vclass(DOMAIN_W_NAME, NAME_DOMAIN));
vcdao.setVClass(vclass(RANGE_NO_NAME, null));
vcdao.setVClass(vclass(RANGE_W_NAME, NAME_RANGE));
pgdao.addPropertyGroup(propertyGroup(GROUP_NO_NAME, null, 5));
pgdao.addPropertyGroup(propertyGroup(GROUP_W_NAME, NAME_GROUP, 3));
opdao.addObjectProperty(
objectProperty(OP1, null, null, null, null, null));
opdao.addObjectProperty(objectProperty(OP2, OP2_PICK_NAME, null,
DOMAIN_NONE, RANGE_NONE, GROUP_NONE));
opdao.addObjectProperty(
objectProperty(OP3, OP3_PICK_NAME, OP3_LOCALNAME_W_PREFIX,
DOMAIN_NO_NAME, RANGE_NO_NAME, GROUP_NO_NAME));
opdao.addObjectProperty(
objectProperty(OP4, OP4_PICK_NAME, OP4_LOCALNAME_W_PREFIX,
DOMAIN_W_NAME, RANGE_W_NAME, GROUP_W_NAME));
}
private PropertyGroup propertyGroup(String uri, String name,
int displayRank, Property... properties) {
PropertyGroup pg = new PropertyGroup();
pg.setURI(uri);
pg.setName(name);
pg.setDisplayRank(displayRank);
pg.setPropertyList(new ArrayList<>(Arrays.asList(properties)));
return pg;
}
private ObjectProperty objectProperty(String uri, String name,
String localNameWithPrefix, String domainVClass, String rangeVClass,
String propertyGroup) {
ObjectProperty op = new ObjectProperty();
op.setURI(uri);
op.setPickListName(name);
op.setLocalNameWithPrefix(localNameWithPrefix);
op.setRangeVClassURI(rangeVClass);
op.setDomainVClassURI(domainVClass);
op.setGroupURI(propertyGroup);
return op;
}
private VClass vclass(String uri, String name) {
VClass vc = new VClass();
vc.setURI(uri);
vc.setPickListName(name);
return vc;
}
}

View file

@ -0,0 +1,233 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.PolicyOption.POLICY_NEUTRAL;
import java.text.Collator;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.OntologyDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.VClassDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
import stubs.javax.servlet.http.HttpServletRequestStub;
/**
* Not a well-formed set of unit tests. But it's a pretty good exercise of the
* different possibilities in the output stage.
*
* Test plan:
*
* <pre>
*
* Ontology is not specified
* Ontology is specified and matches
* Ontology is specified and does not match
*
* classes = empty
* classes = null -- UNREALISTIC
*
* no pickListName
* pickListName
*
* shortDef
* no shortDef
*
* no group uri
* no group for uri
* no name for group
* group with name
*
* ontology not found
* ontology no name
* ontology with name
*
* VC1 - Ont1, no pickListName, no shortDef, no GroupURI, no matching Ontology
* VC2 - Ont2, pickListName, shortDef, no group for GroupURI, ontology has no name
* VC3 - Ont2, pickListName, shortDef, group has no name, ontology with name
* VC4 - Ont1, pickListName, shortDef, group with name, no matching Ontology
*
* Try once with no data
* Try with all data and no ontology specified
* Try with all data and Ont1, Ont2, Ont3
* Sorted by picklist
* </pre>
*/
public class ListVClassWebappsControllerTest extends ListControllerTestBase {
private static final String PATH = "./vclassEdit";
private static final String ONT1 = "http://ont1/";
private static final String ONT2 = "http://ont2/";
private static final String ONT3 = "http://ont3/";
private static final String ONT2_NAME = "Fabulous Ontology";
private static final String VC1 = ONT1 + "vc1";
private static final String VC2 = ONT2 + "vc2";
private static final String VC3 = ONT2 + "vc3";
private static final String VC4 = ONT1 + "vc4";
private static final String VC2_NAME = "Carol";
private static final String VC3_NAME = "Ted";
private static final String VC4_NAME = "ALice";
private static final String VC2_SHORT_DEF = "Short Carol";
private static final String VC3_SHORT_DEF = "Tiny Ted";
private static final String VC4_SHORT_DEF = "Wee ALice";
private static final String GROUP_NONE = "http://domain/noSuchGroup";
private static final String GROUP_NO_NAME = "http://domain/groupWithNoName";
private static final String GROUP_W_NAME = "http://domain/namedGroup";
private static final String NAME_GROUP = "The Groupsters";
private static final JsonNode JSON_EMPTY_RESPONSE = arrayOf();
private static final JsonNode RESPONSE_UNFILTERED = arrayOf(
vclassListNode(PATH, VC4, VC4_NAME, VC4_SHORT_DEF, NAME_GROUP,
ONT1),
vclassListNode(PATH, VC2, VC2_NAME, VC2_SHORT_DEF, "", ONT2_NAME),
vclassListNode(PATH, VC3, VC3_NAME, VC3_SHORT_DEF, "", ONT2_NAME),
degenerateVclassListNode("", "", "", ONT1) // VC1
);
private static final JsonNode RESPONSE_FILTERED_BY_ONT1 = arrayOf(
vclassListNode(PATH, VC4, VC4_NAME, VC4_SHORT_DEF, NAME_GROUP,
ONT1),
degenerateVclassListNode("", "", "", ONT1) // VC1
);
private static final JsonNode RESPONSE_FILTERED_BY_ONT2 = arrayOf(
vclassListNode(PATH, VC2, VC2_NAME, VC2_SHORT_DEF, "", ONT2_NAME),
vclassListNode(PATH, VC3, VC3_NAME, VC3_SHORT_DEF, "", ONT2_NAME));
private static final JsonNode RESPONSE_FILTERED_BY_ONT3 = arrayOf();
private ListVClassWebappsController controller;
private HttpServletRequestStub req;
private ModelAccessFactoryStub modelsFactory;
private WebappDaoFactoryStub wadf;
private OntologyDaoStub odao;
private VClassDaoStub vcdao;
private VClassGroupDaoStub vcgdao;
@Before
public void setup() {
controller = new ListVClassWebappsController();
req = new HttpServletRequestStub();
new VitroRequest(req).setCollator(Collator.getInstance());
odao = new OntologyDaoStub();
vcdao = new VClassDaoStub();
vcgdao = new VClassGroupDaoStub();
wadf = new WebappDaoFactoryStub();
wadf.setOntologyDao(odao);
wadf.setVClassDao(vcdao);
wadf.setVClassGroupDao(vcgdao);
modelsFactory = new ModelAccessFactoryStub();
modelsFactory.get(req).setWebappDaoFactory(wadf, POLICY_NEUTRAL);
// modelsFactory.get(req).setWebappDaoFactory(wadf, LANGUAGE_NEUTRAL,
// POLICY_NEUTRAL);
}
// ----------------------------------------------------------------------
// The tests
// ----------------------------------------------------------------------
@Test
public void noData() throws Exception {
assertMatchingJson(controller, req, JSON_EMPTY_RESPONSE);
}
@Test
public void unfiltered() throws Exception {
populate();
// No name produces invalid JSON so we kluge it for easy comparison
String rawResponse = getJsonFromController(controller, req);
String kluged = rawResponse.replace("\"\"\"", "\"\",\"");
assertKlugedJson(RESPONSE_UNFILTERED, kluged);
}
@Test
public void filteredByOnt1() throws Exception {
populate();
req.addParameter("ontologyUri", ONT1);
// No name produces invalid JSON so we kluge it for easy comparison
// Filtered out classes leave their commas behind, so remove them
String rawResponse = getJsonFromController(controller, req);
String kluged = rawResponse.replace("\"\"\"", "\"\",\"")
.replace(", , ,", ",");
assertKlugedJson(RESPONSE_FILTERED_BY_ONT1, kluged);
}
@Test
public void filteredByOnt2() throws Exception {
populate();
req.addParameter("ontologyUri", ONT2);
// Filtered out classes leave their commas behind, so remove them
String rawResponse = getJsonFromController(controller, req);
String kluged = rawResponse.replaceAll(", $", " ");
assertKlugedJson(RESPONSE_FILTERED_BY_ONT2, kluged);
}
@Test
public void filteredByOnt3() throws Exception {
populate();
req.addParameter("ontologyUri", ONT3);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT3);
}
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
private void populate() {
odao.insertNewOntology(ontology(ONT2, ONT2_NAME));
odao.insertNewOntology(ontology(ONT3, null));
vcgdao.setGroups(vclassGroup(GROUP_NO_NAME, null));
vcgdao.setGroups(vclassGroup(GROUP_W_NAME, NAME_GROUP));
vcdao.setVClass(vclass(VC1, null, null, null));
vcdao.setVClass(vclass(VC2, VC2_NAME, VC2_SHORT_DEF, GROUP_NONE));
vcdao.setVClass(vclass(VC3, VC3_NAME, VC3_SHORT_DEF, GROUP_NO_NAME));
vcdao.setVClass(vclass(VC4, VC4_NAME, VC4_SHORT_DEF, GROUP_W_NAME));
}
private VClass vclass(String uri, String name, String shortDef,
String groupURI) {
VClass vc = new VClass();
vc.setURI(uri);
if (name != null) {
vc.setName(name);
vc.setPickListName(name);
}
if (shortDef != null) {
vc.setShortDef(shortDef);
}
if (groupURI != null) {
vc.setGroupURI(groupURI);
}
return vc;
}
private VClassGroup vclassGroup(String uri, String name) {
VClassGroup vcg = new VClassGroup();
vcg.setURI(uri);
vcg.setPublicName(name);
return vcg;
}
private Ontology ontology(String uri, String name) {
Ontology o = new Ontology();
o.setURI(uri);
o.setName(name);
return o;
}
}

View file

@ -0,0 +1,229 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.ASSERTIONS_ONLY;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.POLICY_NEUTRAL;
import java.text.Collator;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.OntologyDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.VClassDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
import stubs.javax.servlet.http.HttpServletRequestStub;
/**
* Not a well-formed set of unit tests. But it's a pretty good exercise of the
* different possibilities in the output stage.
*
* Test plan:
*
* <pre>
* No data - roots is null -- NONSENSICAL
* No data - roots is empty
*
* Ontology is not specified
* Ontology is specified and matches
* Ontology is specified and does not match
* VClass does not match Ontology, but has child properties that do.
*
* pickListName
* no pickListName
*
* shortDef
* no shortDef
*
* Group no group URI
* Group no group for URI
* Group no name
* Group has a name
*
* No ontology for namespace
* Ontology but no name
* Ontology with name
*
* DP_1A Ont1, no pickListName, no shortDef, no GroupURI, no matching Ontology
* DP_1B Ont2, pickListName, shortDef, no group for GroupURI, ontology has no name
* DP_1B2A Ont3, pickListName, shortDef, group has no name, ontology with name
* DP_1B2B Ont1, pickListName, shortDef, group with name, no matching Ontology
*
* Try once with no data
* Try with all data and no ontology specified
* Try with all data and Ont1, Ont2, Ont3
* </pre>
*/
public class ShowClassHierarchyControllerTest extends ListControllerTestBase {
private static final String PATH = "vclassEdit";
private static final String ONT1 = "http://ont1/";
private static final String ONT2 = "http://ont2/";
private static final String ONT3 = "http://ont3/";
private static final String ONT3_NAME = "Fabulous Ontology";
private static final String URI_GREATAUNT = ONT1 + "greatAunt";
private static final String URI_GRANDMOTHER = ONT2 + "grandmother";
private static final String URI_AUNT = ONT3 + "aunt";
private static final String URI_MOTHER = ONT1 + "mother";
private static final String NAME_GRANDMOTHER = "GrandMother";
private static final String NAME_AUNT = "Aunt";
private static final String NAME_MOTHER = "Mother";
private static final String SHORT_DEF_GRANDMOTHER = "My GrandMother";
private static final String SHORT_DEF_AUNT = "My Aunt";
private static final String SHORT_DEF_MOTHER = "My Mother";
private static final String GROUP_NONE = "http://domain/noSuchGroup";
private static final String GROUP_NO_NAME = "http://domain/groupWithNoName";
private static final String GROUP_W_NAME = "http://domain/namedGroup";
private static final String NAME_GROUP = "The Groupsters";
private static final ArrayNode JSON_EMPTY_RESPONSE = arrayOf(
vclassHierarchyNode(PATH,
"http://www.w3.org/1999/02/22-rdf-syntax-ns#Resource",
"Resource", "", "",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#"));
private static final JsonNode RESPONSE_UNFILTERED = arrayOf(
vclassHierarchyNode(PATH,URI_GRANDMOTHER, NAME_GRANDMOTHER,
SHORT_DEF_GRANDMOTHER, "", ONT2,
vclassHierarchyNode(PATH,URI_AUNT, NAME_AUNT, SHORT_DEF_AUNT, "",
ONT3_NAME),
vclassHierarchyNode(PATH,URI_MOTHER, NAME_MOTHER,
SHORT_DEF_MOTHER, NAME_GROUP, ONT1)),
vclassHierarchyNode(PATH,URI_GREATAUNT, "greatAunt", "", "", ONT1));
private static final JsonNode RESPONSE_FILTERED_BY_ONT1 = arrayOf(
vclassHierarchyNode(PATH,URI_GREATAUNT, "greatAunt", "", "", ONT1));
private static final JsonNode RESPONSE_FILTERED_BY_ONT2 = arrayOf(
vclassHierarchyNode(PATH,URI_GRANDMOTHER, NAME_GRANDMOTHER,
SHORT_DEF_GRANDMOTHER, "", ONT2));
private static final JsonNode RESPONSE_FILTERED_BY_ONT3 = arrayOf();
private ShowClassHierarchyController controller;
private HttpServletRequestStub req;
private ModelAccessFactoryStub modelsFactory;
private OntologyDaoStub ontdao;
private VClassDaoStub vcdao;
private VClassGroupDaoStub vcgdao;
private WebappDaoFactoryStub wadf;
@Before
public void setup() {
controller = new ShowClassHierarchyController();
req = new HttpServletRequestStub();
new VitroRequest(req).setCollator(Collator.getInstance());
ontdao = new OntologyDaoStub();
vcdao = new VClassDaoStub();
vcgdao = new VClassGroupDaoStub();
wadf = new WebappDaoFactoryStub();
wadf.setOntologyDao(ontdao);
wadf.setVClassDao(vcdao);
wadf.setVClassGroupDao(vcgdao);
modelsFactory = new ModelAccessFactoryStub();
modelsFactory.get(req).setWebappDaoFactory(wadf, POLICY_NEUTRAL);
modelsFactory.get(req).setWebappDaoFactory(wadf, POLICY_NEUTRAL,
ASSERTIONS_ONLY);
}
// ----------------------------------------------------------------------
// The tests
// ----------------------------------------------------------------------
@Test
public void noData() throws Exception {
assertMatchingJson(controller, req, JSON_EMPTY_RESPONSE);
}
@Test
public void unfiltered() throws Exception {
populate();
assertMatchingJson(controller, req, RESPONSE_UNFILTERED);
}
@Test
public void filteredByOnt1() throws Exception {
populate();
req.addParameter("ontologyUri", ONT1);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT1);
}
@Test
public void filteredByOnt2() throws Exception {
populate();
req.addParameter("ontologyUri", ONT2);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT2);
}
@Test
public void filteredByOnt3() throws Exception {
populate();
req.addParameter("ontologyUri", ONT3);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT3);
}
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
private void populate() {
ontdao.insertNewOntology(ontology(ONT2, null));
ontdao.insertNewOntology(ontology(ONT3, ONT3_NAME));
vcgdao.setGroups(vclassGroup(GROUP_NO_NAME, null));
vcgdao.setGroups(vclassGroup(GROUP_W_NAME, NAME_GROUP));
vcdao.setVClass(vclass(URI_GREATAUNT, null, null, null));
vcdao.setVClass(vclass(URI_GRANDMOTHER, NAME_GRANDMOTHER, GROUP_NONE,
SHORT_DEF_GRANDMOTHER));
vcdao.setVClass(
vclass(URI_AUNT, NAME_AUNT, GROUP_NO_NAME, SHORT_DEF_AUNT),
URI_GRANDMOTHER);
vcdao.setVClass(
vclass(URI_MOTHER, NAME_MOTHER, GROUP_W_NAME, SHORT_DEF_MOTHER),
URI_GRANDMOTHER);
}
private VClass vclass(String uri, String name, String groupUri,
String shortDef) {
VClass vc = new VClass();
vc.setURI(uri);
vc.setPickListName(name);
vc.setShortDef(shortDef);
vc.setGroupURI(groupUri);
VClassGroup group = vcgdao.getGroupByURI(groupUri);
if (group != null) {
group.add(vc);
}
return vc;
}
private Ontology ontology(String uri, String name) {
Ontology o = new Ontology();
o.setURI(uri);
o.setName(name);
return o;
}
private VClassGroup vclassGroup(String uri, String name) {
VClassGroup vcg = new VClassGroup();
vcg.setURI(uri);
vcg.setPublicName(name);
return vcg;
}
}

View file

@ -0,0 +1,286 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.ASSERTIONS_ONLY;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.LANGUAGE_NEUTRAL;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.POLICY_NEUTRAL;
import java.text.Collator;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.databind.node.ArrayNode;
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.VitroRequest;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.DatatypeDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.VClassDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
import stubs.javax.servlet.http.HttpServletRequestStub;
/**
* Not a well-formed set of unit tests. But it's a pretty good exercise of the
* different possibilities in the output stage.
*
* Test plan:
*
* <pre>
* No data - roots is null -- NONSENSICAL
* No data - roots is empty
*
* Ontology is not specified
* Ontology is specified and matches
* Ontology is specified and does not match
* DataProperty does not match Ontology, but has child properties that do.
*
* Name from picklistName
* Name from getName
* Name from getUri
* Name no URL? -- NONSENSICAL
*
* InternalName from picklistName
* InternalName missing.
*
* Domain class no class URI
* Domain class no class for URI
* Domain class get picklistName from Language Aware DAO
* Domain class use picklistName from Language Neutral DAO
*
* Range no range URI
* Range no datatype for URI
* Range datatype has no name
* Range has a name
*
* Group no group URI
* Group no group for URI
* Group no name
* Group has a name
*
* Children no children
* Children sorted by picklist
*
* DP_1A Ont1, no name, no picklistName, no domainClass, no RangeClass, no GroupURI
* DP_1B Ont2, name, no picklistName, no domain class for URI, no range datatype for URI, no group for GroupURI
* DP_1B2A Ont1, picklistname, domainclass no picklistname, range datatype with no name, group has no name
* DP_1B2B Ont1, picklistname(less than 1B2A), domainclass w/picklistname, range datatype with name, group with name
*
* Try once with no data
* Try with all data and no ontology specified
* Try with all data and Ont1, Ont2, Ont3
* </pre>
*/
public class ShowDataPropertyHierarchyControllerTest
extends ListControllerTestBase {
private static final String PATH = "datapropEdit";
private static final String ONT1 = "http://ont1/";
private static final String ONT2 = "http://ont2/";
private static final String ONT3 = "http://ont3/";
private static final String URI_GREATAUNT = ONT1 + "greatAunt";
private static final String URI_GRANDMOTHER = ONT2 + "grandmother";
private static final String URI_AUNT = ONT1 + "aunt";
private static final String URI_MOTHER = ONT1 + "mother";
private static final String URI_DAUGHTER = ONT2 + "daughter";
private static final String NAME_GRANDMOTHER = "GrandMother";
private static final String NAME_AUNT = "Aunt";
private static final String NAME_MOTHER = "Mother";
private static final String NAME_DAUGHTER = "Me";
private static final String PICK_NAME_AUNT = "Old Aunt Agnes";
private static final String PICK_NAME_MOTHER = "My Mother";
private static final String DOMAIN_NONE = "http://domain/noSuchDomain";
private static final String DOMAIN_NO_NAME = "http://domain/domainWithNoName";
private static final String DOMAIN_W_NAME = "http://domain/namedDomain";
private static final String NAME_DOMAIN = "An excellent domain";
private static final String RANGE_NONE = "http://domain/noSuchRange";
private static final String RANGE_NO_NAME = "http://domain/rangeWithNoName";
private static final String RANGE_W_NAME = "http://domain/namedRange";
private static final String NAME_RANGE = "Home on the range";
private static final String GROUP_NONE = "http://domain/noSuchGroup";
private static final String GROUP_NO_NAME = "http://domain/groupWithNoName";
private static final String GROUP_W_NAME = "http://domain/namedGroup";
private static final String NAME_GROUP = "The Groupsters";
private static final ArrayNode NO_DATA_RESPONSE = arrayOf( //
propertyHierarchyNode(PATH, "nullfake", "ullfake", "ullfake", "",
"", "unspecified"));
private static final ArrayNode RESPONSE_UNFILTERED = arrayOf(
propertyHierarchyNode(PATH, URI_GRANDMOTHER, "grandmother",
"grandmother", "", "http://domain/noSuchRange",
"unknown group",
propertyHierarchyNode(PATH, URI_MOTHER, PICK_NAME_MOTHER,
"My Mother", "namedDomain", "Home on the range",
"The Groupsters",
propertyHierarchyNode(PATH, URI_DAUGHTER,
"daughter", "daughter", "", "",
"unspecified")),
propertyHierarchyNode(PATH, URI_AUNT, PICK_NAME_AUNT,
"Old Aunt Agnes", "domainWithNoName", "", "")),
propertyHierarchyNode(PATH, URI_GREATAUNT, "greatAunt", "greatAunt",
"", "", "unspecified"));
private static final ArrayNode RESPONSE_FILTERED_BY_ONT1 = arrayOf(
propertyHierarchyNode(PATH, URI_GREATAUNT, "greatAunt", "greatAunt",
"", "", "unspecified"));
private static final ArrayNode RESPONSE_FILTERED_BY_ONT2 = arrayOf(
propertyHierarchyNode(PATH, URI_GRANDMOTHER, "grandmother",
"grandmother", "", "http://domain/noSuchRange",
"unknown group", propertyHierarchyNode(PATH, URI_DAUGHTER,
"daughter", "daughter", "", "", "unspecified")));
private static final ArrayNode RESPONSE_FILTERED_BY_ONT3 = arrayOf();
private ShowDataPropertyHierarchyController controller;
private HttpServletRequestStub req;
private ModelAccessFactoryStub modelsFactory;
private WebappDaoFactoryStub wadf;
private DatatypeDaoStub ddao;
private DataPropertyDaoStub dpdao;
private PropertyGroupDaoStub pgdao;
private VClassDaoStub vcdao;
@Before
public void setup() {
controller = new ShowDataPropertyHierarchyController();
req = new HttpServletRequestStub();
new VitroRequest(req).setCollator(Collator.getInstance());
ddao = new DatatypeDaoStub();
dpdao = new DataPropertyDaoStub();
pgdao = new PropertyGroupDaoStub();
vcdao = new VClassDaoStub();
wadf = new WebappDaoFactoryStub();
wadf.setDatatypeDao(ddao);
wadf.setDataPropertyDao(dpdao);
wadf.setPropertyGroupDao(pgdao);
wadf.setVClassDao(vcdao);
modelsFactory = new ModelAccessFactoryStub();
modelsFactory.get(req).setWebappDaoFactory(wadf, POLICY_NEUTRAL);
modelsFactory.get(req).setWebappDaoFactory(wadf, POLICY_NEUTRAL,
ASSERTIONS_ONLY);
modelsFactory.get(req).setWebappDaoFactory(wadf, POLICY_NEUTRAL,
LANGUAGE_NEUTRAL);
}
// ----------------------------------------------------------------------
// The tests
// ----------------------------------------------------------------------
@Test
public void noDataTest() throws Exception {
// The NO DATA response is not valid JSON unless we kluge it.
String rawResponse = getJsonFromController(controller, req);
String kluged = rawResponse + "]}";
assertKlugedJson(NO_DATA_RESPONSE, kluged);
// assertMatchingJson(controller, req, NO_DATA_RESPONSE);
}
@Test
public void unfiltered() throws Exception {
populate();
assertMatchingJson(controller, req, RESPONSE_UNFILTERED);
}
@Test
public void filteredByOnt1() throws Exception {
populate();
req.addParameter("ontologyUri", ONT1);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT1);
}
@Test
public void filteredByOnt2() throws Exception {
populate();
req.addParameter("ontologyUri", ONT2);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT2);
}
@Test
public void filteredByOnt3() throws Exception {
populate();
req.addParameter("ontologyUri", ONT3);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT3);
}
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
private void populate() {
vcdao.setVClass(vclass(DOMAIN_NO_NAME, null));
vcdao.setVClass(vclass(DOMAIN_W_NAME, NAME_DOMAIN));
ddao.addDatatype(datatype(RANGE_NO_NAME, null));
ddao.addDatatype(datatype(RANGE_W_NAME, NAME_RANGE));
pgdao.addPropertyGroup(propertyGroup(GROUP_NO_NAME, null));
pgdao.addPropertyGroup(propertyGroup(GROUP_W_NAME, NAME_GROUP));
dpdao.addDataProperty(
dataProperty(URI_GREATAUNT, null, null, null, null, null));
dpdao.addDataProperty(dataProperty(URI_GRANDMOTHER, NAME_GRANDMOTHER,
null, DOMAIN_NONE, RANGE_NONE, GROUP_NONE));
dpdao.addDataProperty(
dataProperty(URI_AUNT, NAME_AUNT, PICK_NAME_AUNT,
DOMAIN_NO_NAME, RANGE_NO_NAME, GROUP_NO_NAME),
URI_GRANDMOTHER);
dpdao.addDataProperty(
dataProperty(URI_MOTHER, NAME_MOTHER, PICK_NAME_MOTHER,
DOMAIN_W_NAME, RANGE_W_NAME, GROUP_W_NAME),
URI_GRANDMOTHER);
dpdao.addDataProperty(dataProperty(URI_DAUGHTER, NAME_DAUGHTER, null,
null, null, null), URI_MOTHER);
}
private DataProperty dataProperty(String uri, String name,
String pickListName, String domainClassUri, String rangeDatatypeUri,
String groupUri) {
DataProperty dp = new DataProperty();
dp.setURI(uri);
dp.setName(name);
dp.setPickListName(pickListName);
dp.setDomainClassURI(domainClassUri);
dp.setRangeDatatypeURI(rangeDatatypeUri);
dp.setGroupURI(groupUri);
return dp;
}
private Datatype datatype(String uri, String name) {
Datatype d = new Datatype();
d.setUri(uri);
d.setName(name);
return d;
}
private PropertyGroup propertyGroup(String uri, String name) {
PropertyGroup pg = new PropertyGroup();
pg.setURI(uri);
pg.setName(name);
return pg;
}
private VClass vclass(String uri) {
VClass vc = new VClass();
vc.setURI(uri);
return vc;
}
private VClass vclass(String uri, String name) {
VClass vc = vclass(uri);
vc.setName(name);
return vc;
}
}

View file

@ -0,0 +1,292 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.ASSERTIONS_ONLY;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.LANGUAGE_NEUTRAL;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.POLICY_NEUTRAL;
import java.text.Collator;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.databind.node.ArrayNode;
import edu.cornell.mannlib.vitro.webapp.beans.Datatype;
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.VitroRequest;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.DatatypeDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.VClassDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
import stubs.javax.servlet.http.HttpServletRequestStub;
/**
* Not a well-formed set of unit tests. But it's a pretty good exercise of the
* different possibilities in the output stage.
*
* Test plan:
*
* <pre>
* No data - roots is null -- NONSENSICAL
* No data - roots is empty
*
* Ontology is not specified
* Ontology is specified and matches
* Ontology is specified and does not match
* ObjectProperty does not match Ontology, but has child properties that do.
*
* Name from picklistName
* Name from getLocalName
* Name no URL? -- NONSENSICAL
*
* InternalName from localNameWithPrefix
* InternalName from localName
*
* Domain class no class URI
* Domain class no class for URI
* Domain class get picklistName from Language Aware DAO
* Domain class use picklistName from Language Neutral DAO
*
* Range class no class URI
* Range class no class for URI
* Range class get picklistName from Language Aware DAO
* Range class use picklistName from Language Neutral DAO
*
* Group no group URI
* Group no group for URI
* Group no name
* Group has a name
*
* Children no children
* Children sorted by picklist
*
* DP_1A Ont1, no name, no localnamewithprefix, no picklistName, no domainClass, no RangeClass, no GroupURI
* DP_1B Ont2, name, no localnamewithprefix, no picklistName, no domain class for URI, no range clqss for URI, no group for GroupURI
* DP_1B2A Ont1, name, localnamewithprefix, picklistname, domainclass no picklistname, range class with no picklistname, group has no name
* DP_1B2B Ont1, name, localnamewithprefix, picklistname(less than 1B2A), domain class w/picklistname, range class w/picklistname, group with name
*
* Try once with no data
* Try with all data and no ontology specified
* Try with all data and Ont1, Ont2, Ont3
* </pre>
*/
public class ShowObjectPropertyHierarchyControllerTest
extends ListControllerTestBase {
private static final String PATH = "propertyEdit";
private static final String ONT1 = "http://ont1/";
private static final String ONT2 = "http://ont2/";
private static final String ONT3 = "http://ont3/";
private static final String URI_GREATAUNT = ONT1 + "greatAunt";
private static final String URI_GRANDMOTHER = ONT2 + "grandmother";
private static final String URI_AUNT = ONT1 + "aunt";
private static final String URI_MOTHER = ONT1 + "mother";
private static final String URI_DAUGHTER = ONT2 + "daughter";
private static final String NAME_GRANDMOTHER = "GrandMother";
private static final String NAME_AUNT = "Aunt";
private static final String NAME_MOTHER = "Mother";
private static final String NAME_DAUGHTER = "Me";
private static final String LOCAL_NAME_WITH_PREFIX_AUNT = "family:aunt";
private static final String LOCAL_NAME_WITH_PREFIX_MOTHER = "family:mother";
private static final String DOMAIN_NONE = "http://domain/noSuchDomain";
private static final String DOMAIN_NO_NAME = "http://domain/domainWithNoName";
private static final String DOMAIN_W_NAME = "http://domain/namedDomain";
private static final String NAME_DOMAIN = "An excellent domain";
private static final String RANGE_NONE = "http://domain/noSuchRange";
private static final String RANGE_NO_NAME = "http://domain/rangeWithNoName";
private static final String RANGE_W_NAME = "http://domain/namedRange";
private static final String NAME_RANGE = "Home on the range";
private static final String GROUP_NONE = "http://domain/noSuchGroup";
private static final String GROUP_NO_NAME = "http://domain/groupWithNoName";
private static final String GROUP_W_NAME = "http://domain/namedGroup";
private static final String NAME_GROUP = "The Groupsters";
private static final ArrayNode NO_DATA_RESPONSE = arrayOf( //
propertyHierarchyNode(PATH, "nullfake", "ullfake", "ullfake", "",
"", "unspecified"));
private static final ArrayNode RESPONSE_UNFILTERED = arrayOf(
propertyHierarchyNode(PATH, URI_GRANDMOTHER, NAME_GRANDMOTHER,
"grandmother", "", "", "unknown group",
propertyHierarchyNode(PATH, URI_AUNT, NAME_AUNT,
"family:aunt", "domainWithNoName", "", ""),
propertyHierarchyNode(PATH, URI_MOTHER, NAME_MOTHER,
"family:mother", "namedDomain", "",
"The Groupsters",
propertyHierarchyNode(PATH, URI_DAUGHTER,
NAME_DAUGHTER, "daughter", "", "",
"unspecified"))),
propertyHierarchyNode(PATH, URI_GREATAUNT, "greatAunt", "greatAunt",
"", "", "unspecified"));
private static final ArrayNode RESPONSE_FILTERED_BY_ONT1 = arrayOf(
propertyHierarchyNode(PATH, URI_GREATAUNT, "greatAunt", "greatAunt",
"", "", "unspecified"));
private static final ArrayNode RESPONSE_FILTERED_BY_ONT2 = arrayOf(
propertyHierarchyNode(PATH, URI_GRANDMOTHER, NAME_GRANDMOTHER,
"grandmother", "", "", "unknown group",
propertyHierarchyNode(PATH, URI_DAUGHTER, NAME_DAUGHTER,
"daughter", "", "", "unspecified")));
private static final ArrayNode RESPONSE_FILTERED_BY_ONT3 = arrayOf();
private ShowObjectPropertyHierarchyController controller;
private HttpServletRequestStub req;
private ModelAccessFactoryStub modelsFactory;
private WebappDaoFactoryStub wadf;
private DatatypeDaoStub ddao;
private ObjectPropertyDaoStub opdao;
private PropertyGroupDaoStub pgdao;
private VClassDaoStub vcdao;
@Before
public void setup() {
controller = new ShowObjectPropertyHierarchyController();
req = new HttpServletRequestStub();
new VitroRequest(req).setCollator(Collator.getInstance());
ddao = new DatatypeDaoStub();
opdao = new ObjectPropertyDaoStub();
pgdao = new PropertyGroupDaoStub();
vcdao = new VClassDaoStub();
wadf = new WebappDaoFactoryStub();
wadf.setDatatypeDao(ddao);
wadf.setObjectPropertyDao(opdao);
wadf.setPropertyGroupDao(pgdao);
wadf.setVClassDao(vcdao);
modelsFactory = new ModelAccessFactoryStub();
modelsFactory.get(req).setWebappDaoFactory(wadf, POLICY_NEUTRAL);
modelsFactory.get(req).setWebappDaoFactory(wadf, POLICY_NEUTRAL,
ASSERTIONS_ONLY);
modelsFactory.get(req).setWebappDaoFactory(wadf, POLICY_NEUTRAL,
LANGUAGE_NEUTRAL);
}
// ----------------------------------------------------------------------
// The tests
// ----------------------------------------------------------------------
@Test
public void noDataTest() throws Exception {
// The NO DATA response is not valid JSON unless we kluge it.
String rawResponse = getJsonFromController(controller, req);
String kluged = rawResponse + "]}";
assertKlugedJson(NO_DATA_RESPONSE, kluged);
// assertMatchingJson(controller, req, NO_DATA_RESPONSE);
}
@Test
public void unfiltered() throws Exception {
populate();
assertMatchingJson(controller, req, RESPONSE_UNFILTERED);
}
@Test
public void filteredByOnt1() throws Exception {
populate();
req.addParameter("ontologyUri", ONT1);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT1);
}
@Test
public void filteredByOnt2() throws Exception {
populate();
req.addParameter("ontologyUri", ONT2);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT2);
}
@Test
public void filteredByOnt3() throws Exception {
populate();
req.addParameter("ontologyUri", ONT3);
assertMatchingJson(controller, req, RESPONSE_FILTERED_BY_ONT3);
}
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
private void populate() {
vcdao.setVClass(vclass(DOMAIN_NO_NAME, null));
vcdao.setVClass(vclass(DOMAIN_W_NAME, NAME_DOMAIN));
ddao.addDatatype(datatype(RANGE_NO_NAME, null));
ddao.addDatatype(datatype(RANGE_W_NAME, NAME_RANGE));
pgdao.addPropertyGroup(propertyGroup(GROUP_NO_NAME, null));
pgdao.addPropertyGroup(propertyGroup(GROUP_W_NAME, NAME_GROUP));
opdao.addObjectProperty(
objectProperty(URI_GREATAUNT, null, null, null, null, null));
opdao.addObjectProperty(objectProperty(URI_GRANDMOTHER,
NAME_GRANDMOTHER, null, DOMAIN_NONE, RANGE_NONE, GROUP_NONE));
opdao.addObjectProperty(
objectProperty(URI_AUNT, NAME_AUNT, LOCAL_NAME_WITH_PREFIX_AUNT,
DOMAIN_NO_NAME, RANGE_NO_NAME, GROUP_NO_NAME),
URI_GRANDMOTHER);
opdao.addObjectProperty(objectProperty(URI_MOTHER, NAME_MOTHER,
LOCAL_NAME_WITH_PREFIX_MOTHER, DOMAIN_W_NAME, RANGE_W_NAME,
GROUP_W_NAME), URI_GRANDMOTHER);
opdao.addObjectProperty(objectProperty(URI_DAUGHTER, NAME_DAUGHTER,
null, null, null, null), URI_MOTHER);
}
private ObjectProperty objectProperty(String uri, String name,
String localNameWithPrefix, String domainClassUri,
String rangeDatatypeUri, String groupUri) {
ObjectProperty op = new ObjectProperty();
op.setURI(uri);
op.setPickListName(name);
op.setLocalNameWithPrefix(localNameWithPrefix);
op.setDomainVClassURI(domainClassUri);
op.setDomainPublic(getLocalName(domainClassUri));
op.setRangeVClassURI(rangeDatatypeUri);
op.setGroupURI(groupUri);
return op;
}
private Datatype datatype(String uri, String name) {
Datatype d = new Datatype();
d.setUri(uri);
d.setName(name);
return d;
}
private PropertyGroup propertyGroup(String uri, String name) {
PropertyGroup pg = new PropertyGroup();
pg.setURI(uri);
pg.setName(name);
return pg;
}
private VClass vclass(String uri) {
VClass vc = new VClass();
vc.setURI(uri);
return vc;
}
private VClass vclass(String uri, String name) {
VClass vc = vclass(uri);
vc.setName(name);
return vc;
}
private String getLocalName(String uri) {
if (uri == null) {
return null;
}
int delimiter = Math.max(uri.lastIndexOf('#'), uri.lastIndexOf('/'));
return uri.substring(delimiter + 1);
}
}

View file

@ -196,7 +196,7 @@ public class JsonServletTest extends AbstractTestClass {
setLoggerLevel(JsonServlet.class, Level.FATAL); setLoggerLevel(JsonServlet.class, Level.FATAL);
setLoggerLevel(ModelAccess.class, Level.ERROR); setLoggerLevel(ModelAccess.class, Level.ERROR);
String vclassId = "http://myVclass"; String vclassId = "http://myVclass";
vcDao.setVClass(vclassId, new VClass(vclassId)); vcDao.setVClass(new VClass(vclassId));
req.addParameter(GET_SEARCH_INDIVIDUALS_BY_VCLASS, "true"); req.addParameter(GET_SEARCH_INDIVIDUALS_BY_VCLASS, "true");
req.addParameter(VCLASS_ID, vclassId); req.addParameter(VCLASS_ID, vclassId);

View file

@ -0,0 +1,73 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.utils.json;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
/**
* quotes,\, \r, \n, \b, \f, \t and other control characters.
*
*
*/
public class JacksonUtilsTest extends AbstractTestClass {
// ----------------------------------------------------------------------
// Tests for quote()
// quotes,\, \r, \n, \b, \f, \t and other control characters.
// Originally written as direct comparisons to the net.sf.json version.
// ----------------------------------------------------------------------
@Test
public void quoteNull() {
assertJacksonQuoted(null, "");
// assertNetSfJsonQuoted(null, "");
}
@Test
public void quoteQuote() {
assertJacksonQuoted("\"", "\\\"");
// assertNetSfJsonQuoted("\"", "\\\"");
}
@Test
public void quoteBackslash() {
assertJacksonQuoted("\\", "\\\\");
// assertNetSfJsonQuoted("\\", "\\\\");
}
@Test
public void quoteReturn() {
assertJacksonQuoted("\r", "\\r");
// assertNetSfJsonQuoted("\r", "\\r");
}
@Test
public void quoteUnicode() {
assertJacksonQuoted("\u0007", "\\u0007");
// assertNetSfJsonQuoted("\u0007", "\\u0007");
}
@Test
public void quoteAssorted() {
assertJacksonQuoted("\n\b\f\t", "\\n\\b\\f\\t");
// assertNetSfJsonQuoted("\n\b\f\t", "\\n\\b\\f\\t");
}
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
private void assertJacksonQuoted(String raw, String expected) {
String actual = JacksonUtils.quote(raw);
assertEquals("\"" + expected + "\"", actual);
}
// private void assertNetSfJsonQuoted(String raw, String expected) {
// String actual = net.sf.json.util.JSONUtils.quote(raw);
// assertEquals("\"" + expected + "\"", actual);
// }
}

View file

@ -2,12 +2,15 @@
package stubs.edu.cornell.mannlib.vitro.webapp.dao; package stubs.edu.cornell.mannlib.vitro.webapp.dao;
import java.util.ArrayList; import static java.util.stream.Collectors.toList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.google.common.base.Objects;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty; import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.Property; import edu.cornell.mannlib.vitro.webapp.beans.Property;
@ -26,10 +29,41 @@ public class DataPropertyDaoStub implements DataPropertyDao {
// Stub infrastructure // Stub infrastructure
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
private final Map<String, DataProperty> dpMap = new HashMap<String, DataProperty>(); private static class DataPropertyHolder {
final DataProperty dprop;
final String parentUri;
DataPropertyHolder(DataProperty dprop, String parentUri) {
this.dprop = dprop;
this.parentUri = parentUri;
}
public DataProperty getDataProperty() {
return dprop;
}
public String getParentUri() {
return parentUri;
}
boolean isRoot() {
return parentUri == null;
}
boolean inOntology(String ontologyUri) {
return Objects.equal(ontologyUri, dprop.getNamespace());
}
}
private final Map<String, DataPropertyHolder> dataPropertyMap = new HashMap<>();
private final Map<String, String> configFilesMap = new HashMap<String, String>(); private final Map<String, String> configFilesMap = new HashMap<String, String>();
public void addDataProperty(DataProperty dataProperty) { public void addDataProperty(DataProperty dataProperty) {
addDataProperty(dataProperty, null);
}
public void addDataProperty(DataProperty dataProperty, String parentUri) {
if (dataProperty == null) { if (dataProperty == null) {
throw new NullPointerException("dataProperty may not be null."); throw new NullPointerException("dataProperty may not be null.");
} }
@ -39,10 +73,12 @@ public class DataPropertyDaoStub implements DataPropertyDao {
throw new NullPointerException("uri may not be null."); throw new NullPointerException("uri may not be null.");
} }
dpMap.put(uri, dataProperty); dataPropertyMap.put(uri,
new DataPropertyHolder(dataProperty, parentUri));
} }
public void setCustomListViewConfigFileName(DataProperty property, String filename) { public void setCustomListViewConfigFileName(DataProperty property,
String filename) {
if (property == null) { if (property == null) {
throw new NullPointerException("property may not be null."); throw new NullPointerException("property may not be null.");
} }
@ -54,18 +90,24 @@ public class DataPropertyDaoStub implements DataPropertyDao {
configFilesMap.put(uri, filename); configFilesMap.put(uri, filename);
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Stub methods // Stub methods
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@Override @Override
public List<DataProperty> getAllDataProperties() { public List<DataProperty> getAllDataProperties() {
return new ArrayList<>(dpMap.values()); return dataPropertyMap.values().stream()
.map(DataPropertyHolder::getDataProperty).collect(toList());
} }
@Override @Override
public DataProperty getDataPropertyByURI(String dataPropertyURI) { public DataProperty getDataPropertyByURI(String dataPropertyURI) {
return dpMap.get(dataPropertyURI); if (dataPropertyMap.containsKey(dataPropertyURI)) {
return dataPropertyMap.get(dataPropertyURI).getDataProperty();
} else {
return null;
}
} }
@Override @Override
@ -79,6 +121,20 @@ public class DataPropertyDaoStub implements DataPropertyDao {
} }
return configFilesMap.get(uri); return configFilesMap.get(uri);
} }
@Override
public List<DataProperty> getRootDataProperties() {
return dataPropertyMap.values().stream().filter(DataPropertyHolder::isRoot)
.map(DataPropertyHolder::getDataProperty).collect(toList());
}
@Override
public List<String> getSubPropertyURIs(String propertyURI) {
return dataPropertyMap.values().stream()
.filter(dph -> propertyURI.equals(dph.getParentUri()))
.map(dph -> dph.getDataProperty().getURI()).collect(toList());
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Un-implemented methods // Un-implemented methods
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -102,7 +158,8 @@ public class DataPropertyDaoStub implements DataPropertyDao {
} }
@Override @Override
public void removeSuperproperty(String propertyURI, String superpropertyURI) { public void removeSuperproperty(String propertyURI,
String superpropertyURI) {
throw new RuntimeException( throw new RuntimeException(
"PropertyDao.removeSuperproperty() not implemented."); "PropertyDao.removeSuperproperty() not implemented.");
} }
@ -159,12 +216,6 @@ public class DataPropertyDaoStub implements DataPropertyDao {
"PropertyDao.removeEquivalentProperty() not implemented."); "PropertyDao.removeEquivalentProperty() not implemented.");
} }
@Override
public List<String> getSubPropertyURIs(String propertyURI) {
throw new RuntimeException(
"PropertyDao.getSubPropertyURIs() not implemented.");
}
@Override @Override
public List<String> getAllSubPropertyURIs(String propertyURI) { public List<String> getAllSubPropertyURIs(String propertyURI) {
throw new RuntimeException( throw new RuntimeException(
@ -172,7 +223,8 @@ public class DataPropertyDaoStub implements DataPropertyDao {
} }
@Override @Override
public List<String> getSuperPropertyURIs(String propertyURI, boolean direct) { public List<String> getSuperPropertyURIs(String propertyURI,
boolean direct) {
throw new RuntimeException( throw new RuntimeException(
"PropertyDao.getSuperPropertyURIs() not implemented."); "PropertyDao.getSuperPropertyURIs() not implemented.");
} }
@ -190,7 +242,8 @@ public class DataPropertyDaoStub implements DataPropertyDao {
} }
@Override @Override
public List<VClass> getClassesWithRestrictionOnProperty(String propertyURI) { public List<VClass> getClassesWithRestrictionOnProperty(
String propertyURI) {
throw new RuntimeException( throw new RuntimeException(
"PropertyDao.getClassesWithRestrictionOnProperty() not implemented."); "PropertyDao.getClassesWithRestrictionOnProperty() not implemented.");
} }
@ -252,12 +305,6 @@ public class DataPropertyDaoStub implements DataPropertyDao {
"DataPropertyDao.deleteDataProperty() not implemented."); "DataPropertyDao.deleteDataProperty() not implemented.");
} }
@Override
public List<DataProperty> getRootDataProperties() {
throw new RuntimeException(
"DataPropertyDao.getRootDataProperties() not implemented.");
}
@Override @Override
public boolean annotateDataPropertyAsExternalIdentifier( public boolean annotateDataPropertyAsExternalIdentifier(
String dataPropertyURI) { String dataPropertyURI) {

View file

@ -0,0 +1,77 @@
package stubs.edu.cornell.mannlib.vitro.webapp.dao;
import java.util.ArrayList;
import java.util.List;
import com.google.common.base.Objects;
import edu.cornell.mannlib.vitro.webapp.beans.Datatype;
import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao;
public class DatatypeDaoStub implements DatatypeDao {
private final List<Datatype> dtList = new ArrayList<>();
// ----------------------------------------------------------------------
// Stub infrastructure
// ----------------------------------------------------------------------
public void addDatatype(Datatype dt) {
dtList.add(dt);
}
// ----------------------------------------------------------------------
// Stub methods
// ----------------------------------------------------------------------
@Override
public Datatype getDatatypeByURI(String uri) {
for (Datatype dt : dtList) {
if (Objects.equal(dt.getUri(), uri)) {
return dt;
}
}
return null;
}
// ----------------------------------------------------------------------
// Un-implemented methods
// ----------------------------------------------------------------------
@Override
public void updateDatatype(Datatype dtp) {
throw new RuntimeException(
"DatatypeDaoStub.updateDatatype() not implemented.");
}
@Override
public void deleteDatatype(Datatype dtp) {
throw new RuntimeException(
"DatatypeDaoStub.deleteDatatype() not implemented.");
}
@Override
public void deleteDatatype(int id) {
throw new RuntimeException(
"DatatypeDaoStub.deleteDatatype() not implemented.");
}
@Override
public Datatype getDatatypeById(int id) {
throw new RuntimeException(
"DatatypeDaoStub.getDatatypeById() not implemented.");
}
@Override
public int getDatatypeIdByURI(String uri) {
throw new RuntimeException(
"DatatypeDaoStub.getDatatypeIdByURI() not implemented.");
}
@Override
public List<Datatype> getAllDatatypes() {
throw new RuntimeException(
"DatatypeDaoStub.getAllDatatypes() not implemented.");
}
}

View file

@ -2,14 +2,16 @@
package stubs.edu.cornell.mannlib.vitro.webapp.dao; package stubs.edu.cornell.mannlib.vitro.webapp.dao;
import java.util.ArrayList; import static java.util.stream.Collectors.toList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.google.common.base.Objects;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Property; import edu.cornell.mannlib.vitro.webapp.beans.Property;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.InsertException; import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
@ -26,12 +28,42 @@ public class ObjectPropertyDaoStub implements ObjectPropertyDao {
// Stub infrastructure // Stub infrastructure
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
private final Map<String, ObjectProperty> opMap = new HashMap<String, ObjectProperty>(); private static class ObjectPropertyHolder {
private final Map<String, String> configFilesMap = new HashMap<String, String>(); final ObjectProperty oprop;
final String parentUri;
ObjectPropertyHolder(ObjectProperty oprop, String parentUri) {
this.oprop = oprop;
this.parentUri = parentUri;
}
public ObjectProperty getObjectProperty() {
return oprop;
}
public String getParentUri() {
return parentUri;
}
boolean isRoot() {
return parentUri == null;
}
boolean inOntology(String ontologyUri) {
return Objects.equal(ontologyUri, oprop.getNamespace());
}
}
private final Map<String, ObjectPropertyHolder> objectPropertyMap = new HashMap<>();
private final Map<String, String> configFilesMap = new HashMap<>();
public void addObjectProperty(ObjectProperty property) { public void addObjectProperty(ObjectProperty property) {
addObjectProperty(property, null);
}
public void addObjectProperty(ObjectProperty property, String parentUri) {
if (property == null) { if (property == null) {
throw new NullPointerException("predicate may not be null."); throw new NullPointerException("property may not be null.");
} }
String uri = property.getURI(); String uri = property.getURI();
@ -39,7 +71,8 @@ public class ObjectPropertyDaoStub implements ObjectPropertyDao {
throw new NullPointerException("uri may not be null."); throw new NullPointerException("uri may not be null.");
} }
opMap.put(uri, property); objectPropertyMap.put(uri,
new ObjectPropertyHolder(property, parentUri));
} }
public void setCustomListViewConfigFileName(ObjectProperty property, public void setCustomListViewConfigFileName(ObjectProperty property,
@ -62,7 +95,8 @@ public class ObjectPropertyDaoStub implements ObjectPropertyDao {
@Override @Override
public List<ObjectProperty> getAllObjectProperties() { public List<ObjectProperty> getAllObjectProperties() {
return new ArrayList<>(opMap.values()); return objectPropertyMap.values().stream()
.map(ObjectPropertyHolder::getObjectProperty).collect(toList());
} }
@Override @Override
@ -70,7 +104,11 @@ public class ObjectPropertyDaoStub implements ObjectPropertyDao {
if (objectPropertyURI == null) { if (objectPropertyURI == null) {
return null; return null;
} }
return opMap.get(objectPropertyURI); if (objectPropertyMap.containsKey(objectPropertyURI)) {
return objectPropertyMap.get(objectPropertyURI).getObjectProperty();
} else {
return null;
}
} }
@Override @Override
@ -86,7 +124,21 @@ public class ObjectPropertyDaoStub implements ObjectPropertyDao {
} }
@Override @Override
public String getCustomListViewConfigFileName(ObjectProperty objectProperty) { public List<ObjectProperty> getRootObjectProperties() {
return objectPropertyMap.values().stream().filter(ObjectPropertyHolder::isRoot)
.map(ObjectPropertyHolder::getObjectProperty).collect(toList());
}
@Override
public List<String> getSubPropertyURIs(String objectPropertyURI) {
return objectPropertyMap.values().stream()
.filter(oph -> objectPropertyURI.equals(oph.getParentUri()))
.map(oph -> oph.getObjectProperty().getURI()).collect(toList());
}
@Override
public String getCustomListViewConfigFileName(
ObjectProperty objectProperty) {
if (objectProperty == null) { if (objectProperty == null) {
return null; return null;
} }
@ -120,7 +172,8 @@ public class ObjectPropertyDaoStub implements ObjectPropertyDao {
} }
@Override @Override
public void removeSuperproperty(String propertyURI, String superpropertyURI) { public void removeSuperproperty(String propertyURI,
String superpropertyURI) {
throw new RuntimeException( throw new RuntimeException(
"ObjectPropertyDaoStub.removeSuperproperty() not implemented."); "ObjectPropertyDaoStub.removeSuperproperty() not implemented.");
} }
@ -196,7 +249,8 @@ public class ObjectPropertyDaoStub implements ObjectPropertyDao {
} }
@Override @Override
public List<VClass> getClassesWithRestrictionOnProperty(String propertyURI) { public List<VClass> getClassesWithRestrictionOnProperty(
String propertyURI) {
throw new RuntimeException( throw new RuntimeException(
"ObjectPropertyDaoStub.getClassesWithRestrictionOnProperty() not implemented."); "ObjectPropertyDaoStub.getClassesWithRestrictionOnProperty() not implemented.");
} }
@ -215,12 +269,6 @@ public class ObjectPropertyDaoStub implements ObjectPropertyDao {
"ObjectPropertyDaoStub.getSuperPropertyURIs() not implemented."); "ObjectPropertyDaoStub.getSuperPropertyURIs() not implemented.");
} }
@Override
public List<String> getSubPropertyURIs(String objectPropertyURI) {
throw new RuntimeException(
"ObjectPropertyDaoStub.getSubPropertyURIs() not implemented.");
}
@Override @Override
public void fillObjectPropertiesForIndividual(Individual individual) { public void fillObjectPropertiesForIndividual(Individual individual) {
throw new RuntimeException( throw new RuntimeException(
@ -258,12 +306,6 @@ public class ObjectPropertyDaoStub implements ObjectPropertyDao {
"ObjectPropertyDaoStub.skipEditForm() not implemented."); "ObjectPropertyDaoStub.skipEditForm() not implemented.");
} }
@Override
public List<ObjectProperty> getRootObjectProperties() {
throw new RuntimeException(
"ObjectPropertyDaoStub.getRootObjectProperties() not implemented.");
}
@Override @Override
public List<ObjectProperty> getObjectPropertyList(Individual subject) { public List<ObjectProperty> getObjectPropertyList(Individual subject) {
throw new RuntimeException( throw new RuntimeException(

View file

@ -38,16 +38,15 @@ public class OntologyDaoStub implements OntologyDao {
return new ArrayList<Ontology>(ontologies.values()); return new ArrayList<Ontology>(ontologies.values());
} }
@Override
public Ontology getOntologyByURI(String ontologyURI) {
return ontologies.get(ontologyURI);
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Un-implemented methods // Un-implemented methods
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@Override
public Ontology getOntologyByURI(String ontologyURI) {
throw new RuntimeException(
"OntologyDaoStub.getOntologyByURI() not implemented.");
}
@Override @Override
public void updateOntology(Ontology ontology) { public void updateOntology(Ontology ontology) {
throw new RuntimeException( throw new RuntimeException(

View file

@ -0,0 +1,96 @@
package stubs.edu.cornell.mannlib.vitro.webapp.dao;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
public class PropertyGroupDaoStub implements PropertyGroupDao {
// ----------------------------------------------------------------------
// Stub infrastructure
// ----------------------------------------------------------------------
private final Map<String, PropertyGroup> map = new HashMap<>();
public void addPropertyGroup(PropertyGroup group) {
map.put(group.getURI(), group);
}
// ----------------------------------------------------------------------
// Stub methods
// ----------------------------------------------------------------------
@Override
public PropertyGroup getGroupByURI(String uri) {
return (uri == null) ? null : copyGroup(map.get(uri), false);
}
@Override
public List<PropertyGroup> getPublicGroups(boolean withProperties) {
List<PropertyGroup> list = new ArrayList<>();
for (PropertyGroup group: map.values()) {
list.add(copyGroup(group, withProperties));
}
return list;
}
private PropertyGroup copyGroup(PropertyGroup source, boolean withProperties) {
if (source == null) {
return null;
}
PropertyGroup target = new PropertyGroup();
target.setURI(source.getURI());
target.setPickListName(source.getPickListName());
target.setDisplayRank(source.getDisplayRank());
target.setName(source.getName());
target.setStatementCount(source.getStatementCount());
target.setPublicDescription(source.getPublicDescription());
if (withProperties) {
target.setPropertyList(source.getPropertyList());
}
return target;
}
// ----------------------------------------------------------------------
// Un-implemented methods
// ----------------------------------------------------------------------
@Override
public int removeUnpopulatedGroups(List<PropertyGroup> groups) {
throw new RuntimeException(
"PropertyGroupDaoStub.removeUnpopulatedGroups() not implemented.");
}
@Override
public PropertyGroup createDummyPropertyGroup(String name, int rank) {
throw new RuntimeException(
"PropertyGroupDaoStub.createDummyPropertyGroup() not implemented.");
}
@Override
public String insertNewPropertyGroup(PropertyGroup group) {
throw new RuntimeException(
"PropertyGroupDaoStub.insertNewPropertyGroup() not implemented.");
}
@Override
public void updatePropertyGroup(PropertyGroup group) {
throw new RuntimeException(
"PropertyGroupDaoStub.updatePropertyGroup() not implemented.");
}
@Override
public void deletePropertyGroup(PropertyGroup group) {
throw new RuntimeException(
"PropertyGroupDaoStub.deletePropertyGroup() not implemented.");
}
}

View file

@ -0,0 +1,80 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package stubs.edu.cornell.mannlib.vitro.webapp.dao;
import java.util.Collection;
import edu.cornell.mannlib.vitro.webapp.beans.PropertyInstance;
import edu.cornell.mannlib.vitro.webapp.beans.PropertyInstanceIface;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao;
/**
* TODO
*/
public class PropertyInstanceDaoStub implements PropertyInstanceDao {
// ----------------------------------------------------------------------
// Stub infrastructure
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Stub methods
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Un-implemented methods
// ----------------------------------------------------------------------
@Override
public void deleteObjectPropertyStatement(String subjectURI,
String propertyURI, String objectURI) {
throw new RuntimeException(
"PropertyInstanceDaoStub.deleteObjectPropertyStatement() not implemented.");
}
@Override
public Collection<PropertyInstance> getAllPossiblePropInstForIndividual(
String individualURI) {
throw new RuntimeException(
"PropertyInstanceDaoStub.getAllPossiblePropInstForIndividual() not implemented.");
}
@Override
public Collection<PropertyInstance> getAllPropInstByVClass(
String classURI) {
throw new RuntimeException(
"PropertyInstanceDaoStub.getAllPropInstByVClass() not implemented.");
}
@Override
public Collection<PropertyInstance> getExistingProperties(String entityURI,
String propertyURI) {
throw new RuntimeException(
"PropertyInstanceDaoStub.getExistingProperties() not implemented.");
}
@Override
public PropertyInstance getProperty(String subjectURI, String predicateURI,
String objectURI) {
throw new RuntimeException(
"PropertyInstanceDaoStub.getProperty() not implemented.");
}
@Override
public int insertProp(PropertyInstanceIface prop) {
throw new RuntimeException(
"PropertyInstanceDaoStub.insertProp() not implemented.");
}
@Override
public void insertPropertyInstance(PropertyInstance prop) {
throw new RuntimeException(
"PropertyInstanceDaoStub.insertPropertyInstance() not implemented.");
}
@Override
public void deletePropertyInstance(PropertyInstance prop) {
throw new RuntimeException(
"PropertyInstanceDaoStub.deletePropertyInstance() not implemented.");
}
}

View file

@ -2,10 +2,16 @@
package stubs.edu.cornell.mannlib.vitro.webapp.dao; package stubs.edu.cornell.mannlib.vitro.webapp.dao;
import static java.util.stream.Collectors.toList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.jena.vocabulary.RDF;
import com.google.common.base.Objects;
import edu.cornell.mannlib.vitro.webapp.beans.Classes2Classes; import edu.cornell.mannlib.vitro.webapp.beans.Classes2Classes;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
@ -17,44 +23,91 @@ public class VClassDaoStub implements VClassDao {
// Stub infrastructure // Stub infrastructure
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
private final Map<String, VClass> vclassesByUri = new HashMap<String, VClass>(); private static class VClassHolder {
final VClass vclass;
final String parentUri;
public void setVClass(String uri, VClass vclass) { VClassHolder(VClass vclass, String parentUri) {
vclassesByUri.put(uri, vclass); this.vclass = vclass;
this.parentUri = parentUri;
}
public VClass getVclass() {
return vclass;
}
public String getParentUri() {
return parentUri;
}
boolean isRoot() {
return parentUri == null;
}
boolean inOntology(String ontologyUri) {
return Objects.equal(ontologyUri, vclass.getNamespace());
}
}
private final Map<String, VClassHolder> vclassMap = new HashMap<>();
public void setVClass(VClass vclass) {
setVClass(vclass, null);
}
public void setVClass(VClass vclass, String parentUri) {
vclassMap.put(vclass.getURI(), new VClassHolder(vclass, parentUri));
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Stub methods // Stub methods
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@Override
public List<VClass> getAllVclasses() {
return vclassMap.values().stream().map(VClassHolder::getVclass)
.collect(toList());
}
// Only direct (one-hop) sub-classes.
@Override
public List<String> getSubClassURIs(String classURI) {
return vclassMap.values().stream()
.filter(vch -> vch.parentUri == classURI)
.map(vch -> vch.getVclass().getURI()).collect(toList());
}
@Override @Override
public VClass getVClassByURI(String URI) { public VClass getVClassByURI(String URI) {
return vclassesByUri.get(URI); VClassHolder vch = vclassMap.get(URI);
return vch == null ? null : vch.getVclass();
}
@Override
public List<VClass> getRootClasses() {
return vclassMap.values().stream().filter(VClassHolder::isRoot)
.map(VClassHolder::getVclass).collect(toList());
}
@Override
public List<VClass> getOntologyRootClasses(String ontologyURI) {
return getRootClasses().stream()
.filter(vc -> Objects.equal(ontologyURI, vc.getNamespace()))
.collect(toList());
}
@Override
public VClass getTopConcept() {
VClass top = new VClass();
top.setURI(RDF.getURI() + "Resource");
top.setName(top.getLocalName());
return top;
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Un-implemented methods // Un-implemented methods
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@Override
public List<VClass> getRootClasses() {
throw new RuntimeException(
"VClassDaoStub.getRootClasses() not implemented.");
}
@Override
public List<VClass> getOntologyRootClasses(String ontologyURI) {
throw new RuntimeException(
"VClassDaoStub.getOntologyRootClasses() not implemented.");
}
@Override
public List<VClass> getAllVclasses() {
throw new RuntimeException(
"VClassDaoStub.getAllVclasses() not implemented.");
}
@Override @Override
public List<String> getDisjointWithClassURIs(String vclassURI) { public List<String> getDisjointWithClassURIs(String vclassURI) {
throw new RuntimeException( throw new RuntimeException(
@ -116,7 +169,8 @@ public class VClassDaoStub implements VClassDao {
} }
@Override @Override
public void removeDisjointWithClass(String classURI, String disjointClassURI) { public void removeDisjointWithClass(String classURI,
String disjointClassURI) {
throw new RuntimeException( throw new RuntimeException(
"VClassDaoStub.removeDisjointWithClass() not implemented."); "VClassDaoStub.removeDisjointWithClass() not implemented.");
} }
@ -134,17 +188,12 @@ public class VClassDaoStub implements VClassDao {
} }
@Override @Override
public void removeEquivalentClass(String classURI, String equivalentClassURI) { public void removeEquivalentClass(String classURI,
String equivalentClassURI) {
throw new RuntimeException( throw new RuntimeException(
"VClassDaoStub.removeEquivalentClass() not implemented."); "VClassDaoStub.removeEquivalentClass() not implemented.");
} }
@Override
public List<String> getSubClassURIs(String classURI) {
throw new RuntimeException(
"VClassDaoStub.getSubClassURIs() not implemented.");
}
@Override @Override
public List<String> getAllSubClassURIs(String classURI) { public List<String> getAllSubClassURIs(String classURI) {
throw new RuntimeException( throw new RuntimeException(
@ -251,12 +300,6 @@ public class VClassDaoStub implements VClassDao {
"VClassDaoStub.isSubClassOf() not implemented."); "VClassDaoStub.isSubClassOf() not implemented.");
} }
@Override
public VClass getTopConcept() {
throw new RuntimeException(
"VClassDaoStub.getTopConcept() not implemented.");
}
@Override @Override
public VClass getBottomConcept() { public VClass getBottomConcept() {
throw new RuntimeException( throw new RuntimeException(

View file

@ -0,0 +1,115 @@
package stubs.edu.cornell.mannlib.vitro.webapp.dao;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import org.apache.jena.ext.com.google.common.base.Objects;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
public class VClassGroupDaoStub implements VClassGroupDao {
// ----------------------------------------------------------------------
// Stub infrastructure
// ----------------------------------------------------------------------
private List<VClassGroup> groups = new ArrayList<>();
public void setGroups(VClassGroup... groups) {
this.groups = new ArrayList<>(Arrays.asList(groups));
}
// ----------------------------------------------------------------------
// Stub methods
// ----------------------------------------------------------------------
@Override
public VClassGroup getGroupByURI(String uri) {
for (VClassGroup group: groups) {
if (Objects.equal(group.getURI(), uri)) {
return group;
}
}
return null;
}
@Override
public List<VClassGroup> getPublicGroupsWithVClasses() {
List<VClassGroup> list = new ArrayList<>();
for (VClassGroup group: groups) {
if (!group.isEmpty()) {
list.add(group);
}
}
return groups;
}
// ----------------------------------------------------------------------
// Un-implemented methods
// ----------------------------------------------------------------------
@Override
public LinkedHashMap<String, VClassGroup> getClassGroupMap() {
throw new RuntimeException(
"VClassGroupDaoStub.getClassGroupMap() not implemented.");
}
@Override
public List<VClassGroup> getPublicGroupsWithVClasses(boolean displayOrder) {
throw new RuntimeException(
"VClassGroupDaoStub.getPublicGroupsWithVClasses() not implemented.");
}
@Override
public List<VClassGroup> getPublicGroupsWithVClasses(boolean displayOrder,
boolean includeUninstantiatedClasses) {
throw new RuntimeException(
"VClassGroupDaoStub.getPublicGroupsWithVClasses() not implemented.");
}
@Override
public List<VClassGroup> getPublicGroupsWithVClasses(boolean displayOrder,
boolean includeUninstantiatedClasses, boolean getIndividualCount) {
throw new RuntimeException(
"VClassGroupDaoStub.getPublicGroupsWithVClasses() not implemented.");
}
@Override
public void sortGroupList(List<VClassGroup> groupList) {
throw new RuntimeException(
"VClassGroupDaoStub.sortGroupList() not implemented.");
}
@Override
public int removeUnpopulatedGroups(List<VClassGroup> groups) {
throw new RuntimeException(
"VClassGroupDaoStub.removeUnpopulatedGroups() not implemented.");
}
@Override
public int insertNewVClassGroup(VClassGroup vcg) {
throw new RuntimeException(
"VClassGroupDaoStub.insertNewVClassGroup() not implemented.");
}
@Override
public void updateVClassGroup(VClassGroup vcg) {
throw new RuntimeException(
"VClassGroupDaoStub.updateVClassGroup() not implemented.");
}
@Override
public void deleteVClassGroup(VClassGroup vcg) {
throw new RuntimeException(
"VClassGroupDaoStub.deleteVClassGroup() not implemented.");
}
@Override
public VClassGroup getGroupByName(String vcgName) {
throw new RuntimeException(
"VClassGroupDaoStub.getGroupByName() not implemented.");
}
}

View file

@ -38,14 +38,18 @@ public class WebappDaoFactoryStub implements WebappDaoFactory {
private String defaultNamespace; private String defaultNamespace;
private ApplicationDao applicationDao; private ApplicationDao applicationDao;
private DataPropertyDao dataPropertyDao; private DataPropertyDao dataPropertyDao;
private DatatypeDao datatypeDao;
private FauxPropertyDao fauxPropertyDao;
private IndividualDao individualDao; private IndividualDao individualDao;
private MenuDao menuDao; private MenuDao menuDao;
private ObjectPropertyDao objectPropertyDao; private ObjectPropertyDao objectPropertyDao;
private ObjectPropertyStatementDao objectPropertyStatementDao; private ObjectPropertyStatementDao objectPropertyStatementDao;
private FauxPropertyDao fauxPropertyDao;
private OntologyDao ontologyDao; private OntologyDao ontologyDao;
private PropertyGroupDao propertyGroupDao;
private PropertyInstanceDao propertyInstanceDao;
private UserAccountsDao userAccountsDao; private UserAccountsDao userAccountsDao;
private VClassDao vClassDao; private VClassDao vClassDao;
private VClassGroupDao vClassGroupDao;
public void setDefaultNamespace(String defaultNamespace) { public void setDefaultNamespace(String defaultNamespace) {
this.defaultNamespace = defaultNamespace; this.defaultNamespace = defaultNamespace;
@ -59,6 +63,14 @@ public class WebappDaoFactoryStub implements WebappDaoFactory {
this.dataPropertyDao = dataPropertyDao; this.dataPropertyDao = dataPropertyDao;
} }
public void setDatatypeDao(DatatypeDao datatypeDao) {
this.datatypeDao = datatypeDao;
}
public void setFauxPropertyDao(FauxPropertyDao fauxPropertyDao) {
this.fauxPropertyDao = fauxPropertyDao;
}
public void setIndividualDao(IndividualDao individualDao) { public void setIndividualDao(IndividualDao individualDao) {
this.individualDao = individualDao; this.individualDao = individualDao;
} }
@ -76,14 +88,19 @@ public class WebappDaoFactoryStub implements WebappDaoFactory {
this.objectPropertyStatementDao = objectPropertyStatementDao; this.objectPropertyStatementDao = objectPropertyStatementDao;
} }
public void setFauxPropertyDao(FauxPropertyDao fauxPropertyDao) {
this.fauxPropertyDao = fauxPropertyDao;
}
public void setOntologyDao(OntologyDao ontologyDao) { public void setOntologyDao(OntologyDao ontologyDao) {
this.ontologyDao = ontologyDao; this.ontologyDao = ontologyDao;
} }
public void setPropertyGroupDao(PropertyGroupDao propertyGroupDao) {
this.propertyGroupDao = propertyGroupDao;
}
public void setPropertyInstanceDao(
PropertyInstanceDao propertyInstanceDao) {
this.propertyInstanceDao = propertyInstanceDao;
}
public void setUserAccountsDao(UserAccountsDao userAccountsDao) { public void setUserAccountsDao(UserAccountsDao userAccountsDao) {
this.userAccountsDao = userAccountsDao; this.userAccountsDao = userAccountsDao;
} }
@ -92,6 +109,10 @@ public class WebappDaoFactoryStub implements WebappDaoFactory {
this.vClassDao = vClassDao; this.vClassDao = vClassDao;
} }
public void setVClassGroupDao(VClassGroupDao vClassGroupDao) {
this.vClassGroupDao = vClassGroupDao;
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Stub methods // Stub methods
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -111,6 +132,11 @@ public class WebappDaoFactoryStub implements WebappDaoFactory {
return this.dataPropertyDao; return this.dataPropertyDao;
} }
@Override
public DatatypeDao getDatatypeDao() {
return this.datatypeDao;
}
@Override @Override
public IndividualDao getIndividualDao() { public IndividualDao getIndividualDao() {
return this.individualDao; return this.individualDao;
@ -141,6 +167,16 @@ public class WebappDaoFactoryStub implements WebappDaoFactory {
return this.ontologyDao; return this.ontologyDao;
} }
@Override
public PropertyGroupDao getPropertyGroupDao() {
return this.propertyGroupDao;
}
@Override
public PropertyInstanceDao getPropertyInstanceDao() {
return this.propertyInstanceDao;
}
@Override @Override
public UserAccountsDao getUserAccountsDao() { public UserAccountsDao getUserAccountsDao() {
return this.userAccountsDao; return this.userAccountsDao;
@ -151,6 +187,11 @@ public class WebappDaoFactoryStub implements WebappDaoFactory {
return this.vClassDao; return this.vClassDao;
} }
@Override
public VClassGroupDao getVClassGroupDao() {
return this.vClassGroupDao;
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Un-implemented methods // Un-implemented methods
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -203,12 +244,6 @@ public class WebappDaoFactoryStub implements WebappDaoFactory {
"WebappDaoFactory.getUserURI() not implemented."); "WebappDaoFactory.getUserURI() not implemented.");
} }
@Override
public DatatypeDao getDatatypeDao() {
throw new RuntimeException(
"WebappDaoFactory.getDatatypeDao() not implemented.");
}
@Override @Override
public DataPropertyStatementDao getDataPropertyStatementDao() { public DataPropertyStatementDao getDataPropertyStatementDao() {
throw new RuntimeException( throw new RuntimeException(
@ -221,24 +256,6 @@ public class WebappDaoFactoryStub implements WebappDaoFactory {
"WebappDaoFactory.getDisplayModelDao() not implemented."); "WebappDaoFactory.getDisplayModelDao() not implemented.");
} }
@Override
public VClassGroupDao getVClassGroupDao() {
throw new RuntimeException(
"WebappDaoFactory.getVClassGroupDao() not implemented.");
}
@Override
public PropertyGroupDao getPropertyGroupDao() {
throw new RuntimeException(
"WebappDaoFactory.getPropertyGroupDao() not implemented.");
}
@Override
public PropertyInstanceDao getPropertyInstanceDao() {
throw new RuntimeException(
"WebappDaoFactory.getPropertyInstanceDao() not implemented.");
}
@Override @Override
public PageDao getPageDao() { public PageDao getPageDao() {
throw new RuntimeException( throw new RuntimeException(

14
dependencies/pom.xml vendored
View file

@ -147,12 +147,6 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.2.2</version>
<classifier>jdk15</classifier>
</dependency>
<dependency> <dependency>
<groupId>net.sf.saxon</groupId> <groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId> <artifactId>Saxon-HE</artifactId>
@ -228,22 +222,22 @@
<dependency> <dependency>
<groupId>org.apache.jena</groupId> <groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId> <artifactId>jena-arq</artifactId>
<version>3.1.1</version> <version>3.3.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.jena</groupId> <groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId> <artifactId>jena-core</artifactId>
<version>3.1.1</version> <version>3.3.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.jena</groupId> <groupId>org.apache.jena</groupId>
<artifactId>jena-sdb</artifactId> <artifactId>jena-sdb</artifactId>
<version>3.1.1</version> <version>3.3.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.jena</groupId> <groupId>org.apache.jena</groupId>
<artifactId>jena-tdb</artifactId> <artifactId>jena-tdb</artifactId>
<version>3.1.1</version> <version>3.3.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.solr</groupId> <groupId>org.apache.solr</groupId>

View file

@ -8,7 +8,9 @@
<div id="wrap" class="container"> <div id="wrap" class="container">
<div id="header"> <div id="header">
<header id="branding" role="banner">
<#include "identity.ftl"> <#include "identity.ftl">
</header>
<#-- Note to UI team: do not change this div without also making the corresponding change in menu.jsp --> <#-- Note to UI team: do not change this div without also making the corresponding change in menu.jsp -->
<div id="navAndSearch" class="block"> <div id="navAndSearch" class="block">
@ -22,11 +24,7 @@
<hr class="hidden" /> <hr class="hidden" />
<div id="contentwrap"> <div id="contentwrap">
<#if flash?has_content> <#include "flash.html">
<div id="flash-message">
${flash}
</div>
</#if>
<div id="content"> <div id="content">
${body} ${body}
@ -34,7 +32,6 @@
</div> <!-- contentwrap --> </div> <!-- contentwrap -->
<#include "footer.ftl"> <#include "footer.ftl">
</div> <!-- wrap --> </div> <!-- wrap -->
<#include "scripts.ftl"> <#include "scripts.ftl">

View file

@ -1,12 +1,17 @@
<#-- $This file is distributed under the terms of the license in LICENSE$ --> <#-- $This file is distributed under the terms of the license in LICENSE$ -->
<p class="copyright">
<#if copyright??> <#if copyright??>
<div class="copyright"> <small>&copy;${copyright.year?c}
&copy;${copyright.year?c}
<#if copyright.url??> <#if copyright.url??>
<a href="${copyright.url}" title="${i18n().copyright}">${copyright.text}</a> <a href="${copyright.url}" title="${i18n().copyright}">${copyright.text}</a>
<#else> <#else>
${copyright.text} ${copyright.text}
</#if> </#if>
</div> | <a class="terms" href="${urls.termsOfUse}" title="${i18n().terms_of_use}">${i18n().terms_of_use}</a></small> |
</#if> </#if>
${i18n().powered_by} <a class="powered-by-vitro" href="http://vitro.sourceforge.net"><strong>Vitro</strong></a>
<#if user.hasRevisionInfoAccess>
| ${i18n().version} <a href="${version.moreInfoUrl}" title="${i18n().version}">${version.label}</a>
</#if>
</p>

View file

@ -0,0 +1,8 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#if flash?has_content>
<div id="flash-message">
${flash}
</div>
</#if>

View file

@ -2,23 +2,18 @@
<#import "lib-list.ftl" as l> <#import "lib-list.ftl" as l>
<div id="footer"> <footer role="contentinfo">
<#if urls.bannerImage??>
<img class="footerLogo" src="${urls.bannerImage}" alt="${siteTagline!}" />
</#if>
<div class="footerLinks">
<ul class="otherNav">
<@l.firstLastList>
<#include "subMenuLinks.ftl">
</@l.firstLastList>
</ul>
</div>
<#include "copyright.ftl"> <#include "copyright.ftl">
${i18n().all_rights_reserved} <a href="${urls.termsOfUse}" title="${i18n().terms_of_use}">${i18n().terms_of_use}</a> <nav role="navigation">
<ul id="footer-nav" role="list">
<li role="listitem"><a href="${urls.about}" title="${i18n().about}">${i18n().about}</a></li>
<#if urls.contact??>
<li role="listitem"><a href="${urls.contact}" title="${i18n().contact_us}">${i18n().contact_us}</a></li>
</#if>
<li role="listitem"><a href="http://www.vivoweb.org/support" target="blank" title="${i18n().support}">${i18n().support}</a></li>
</ul>
</nav>
</footer>
<#include "version.ftl"> <#include "scripts.ftl">
</div>

View file

@ -1,19 +1,26 @@
<#-- NOTICE: This is SAMPLE Google Analytics code. You must replace it with your institution's code. --> <#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#-- <#if gatracker??>
<script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); <script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
try { try {
var pageTracker = _gat._getTracker("UA-5164622-5"); var pageTracker = _gat._getTracker("${gatracker}");
pageTracker._setDomainName("vivo.cornell.edu"); <#if gadomain??>
pageTracker._setDomainName("${gadomain});
</#if>
pageTracker._setAllowLinker(true); pageTracker._setAllowLinker(true);
pageTracker._trackPageview(); pageTracker._trackPageview();
var rollupTracker = _gat._getTracker("UA-12531954-1");
<#if gatrackerrollup??>
var rollupTracker = _gat._getTracker("${gatrackerrollup}");
rollupTracker._setDomainName("none"); rollupTracker._setDomainName("none");
rollupTracker._setAllowLinker(true); rollupTracker._setAllowLinker(true);
rollupTracker._trackPageview(location.host+location.pathname); rollupTracker._trackPageview(location.host+location.pathname);
</#if>
} }
catch(err) {} catch(err) {}
</script> </script>
--> </#if>

View file

@ -8,8 +8,14 @@
<#include "stylesheets.ftl"> <#include "stylesheets.ftl">
<#include "themeStylesheets.ftl">
<#include "headScripts.ftl"> <#include "headScripts.ftl">
<!--[if (gte IE 6)&(lte IE 8)]>
<script type="text/javascript" src="${urls.base}/js/selectivizr.js"></script>
<![endif]-->
<#if metaTags??> <#if metaTags??>
${metaTags.list()} ${metaTags.list()}
</#if> </#if>
@ -17,3 +23,5 @@
<#-- Inject head content specified in the controller. Currently this is used only to generate an rdf link on <#-- Inject head content specified in the controller. Currently this is used only to generate an rdf link on
an individual profile page. --> an individual profile page. -->
${headContent!} ${headContent!}
<link rel="shortcut icon" type="image/x-icon" href="${urls.base}/favicon.ico">

View file

@ -1,7 +1,6 @@
<#-- $This file is distributed under the terms of the license in LICENSE$ --> <#-- $This file is distributed under the terms of the license in LICENSE$ -->
<header id="branding" role="banner"> <h1 class="vitro-logo"><a href="${urls.home}" title="${siteName}"><span class="displace">${siteName}</span></a></h1>
<h1 class="vivo-logo"><a href="${urls.home}" title="${siteName}"><span class="displace">${siteName}</span></a></h1>
<#if siteTagline?has_content> <#if siteTagline?has_content>
<em>${siteTagline}</em> <em>${siteTagline}</em>
</#if> </#if>
@ -40,4 +39,3 @@
</form> </form>
</fieldset> </fieldset>
</section> </section>
</header>

View file

@ -9,10 +9,3 @@
</#list> </#list>
</ul> </ul>
</nav> </nav>
<div id="wrapper-content" role="main">
<#if flash?has_content>
<section id="flash-message" role="alert">
${flash}
</section>
</#if>

View file

@ -0,0 +1 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->

View file

@ -1,3 +1,3 @@
<#-- $This file is distributed under the terms of the license in LICENSE$ --> <#-- $This file is distributed under the terms of the license in LICENSE$ -->
<title>${siteName!}</title> <title>${(title?html)!siteName!}</title>

View file

@ -0,0 +1,19 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#if flash?has_content>
<#if flash?starts_with("Welcome") >
<section id="welcome-msg-container" role="container">
<section id="welcome-message" role="alert">${flash}</section>
</section>
<#else>
<section id="flash-message" role="alert">
${flash}
</section>
</#if>
</#if>
<!--[if lte IE 8]>
<noscript>
<p class="ie-alert">${i18n().javascript_ie_alert_text} Here are the <a href="http://www.enable-javascript.com" title="javascript instructions">${i18n().to_enable_javascript}</a>.</p>
</noscript>
<![endif]-->

View file

@ -1,33 +0,0 @@
<#-- $This file is distributed under the terms of the license in LICENSE$ -->
</div> <!-- #wrapper-content -->
<footer role="contentinfo">
<p class="copyright">
<#if copyright??>
<small>&copy;${copyright.year?c}
<#if copyright.url??>
<a href="${copyright.url}" title="${i18n().copyright}">${copyright.text}</a>
<#else>
${copyright.text}
</#if>
| <a class="terms" href="${urls.termsOfUse}" title="${i18n().terms_of_use}">${i18n().terms_of_use}</a></small> |
</#if>
${i18n().powered_by} <a class="powered-by-vitro" href="http://vitro.sourceforge.net"><strong>Vitro</strong></a>
<#if user.hasRevisionInfoAccess>
| ${i18n().version} <a href="${version.moreInfoUrl}" title="${i18n().version}">${version.label}</a>
</#if>
</p>
<nav role="navigation">
<ul id="footer-nav" role="list">
<li role="listitem"><a href="${urls.about}" title="${i18n().about}">${i18n().about}</a></li>
<#if urls.contact??>
<li role="listitem"><a href="${urls.contact}" title="${i18n().contact_us}">${i18n().contact_us}</a></li>
</#if>
<li role="listitem"><a href="http://www.vivoweb.org/support" target="blank" title="${i18n().support}">${i18n().support}</a></li>
</ul>
</nav>
</footer>
<#include "scripts.ftl">

View file

@ -1,26 +0,0 @@
<#-- $This file is distributed under the terms of the license in LICENSE$ -->
<#-- NOTICE: This is SAMPLE Google Analytics code. You must replace it with your institution's code.
Please see documentation at https://confluence.cornell.edu/display/ennsrd/Google+Analytics+for+UI. -->
<#--
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-5164622-5");
pageTracker._setDomainName("vivo.cornell.edu");
pageTracker._setAllowLinker(true);
pageTracker._trackPageview();
var rollupTracker = _gat._getTracker("UA-12531954-1");
rollupTracker._setDomainName("none");
rollupTracker._setAllowLinker(true);
rollupTracker._trackPageview(location.host+location.pathname);
}
catch(err) {}
</script>
-->

View file

@ -1,26 +0,0 @@
<#-- $This file is distributed under the terms of the license in LICENSE$ -->
<meta charset="utf-8" />
<!-- Google Chrome Frame open source plug-in brings Google Chrome's open web technologies and speedy JavaScript engine to Internet Explorer-->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>${(title?html)!siteName!}</title>
<#include "stylesheets.ftl">
<link rel="stylesheet" href="${urls.theme}/css/screen.css" />
<#include "headScripts.ftl">
<!--[if (gte IE 6)&(lte IE 8)]>
<script type="text/javascript" src="${urls.base}/js/selectivizr.js"></script>
<![endif]-->
<#if metaTags??>
${metaTags.list()}
</#if>
<#-- Inject head content specified in the controller. Currently this is used only to generate an rdf link on
an individual profile page. -->
${headContent!}
<link rel="shortcut icon" type="image/x-icon" href="${urls.base}/favicon.ico">

View file

@ -1,6 +1,5 @@
<#-- $This file is distributed under the terms of the license in LICENSE$ --> <#-- $This file is distributed under the terms of the license in LICENSE$ -->
<header id="branding" role="banner">
<h1 class="vitro-logo"><a title="${siteName}" href="${urls.home}"><span class="displace">${siteName}</span></a></h1> <h1 class="vitro-logo"><a title="${siteName}" href="${urls.home}"><span class="displace">${siteName}</span></a></h1>
<#-- Since we are using a graphic text for the tagline, we won't render ${siteTagline} <#-- Since we are using a graphic text for the tagline, we won't render ${siteTagline}
<#if siteTagline?has_content> <#if siteTagline?has_content>

View file

@ -1,7 +1,5 @@
<#-- $This file is distributed under the terms of the license in LICENSE$ --> <#-- $This file is distributed under the terms of the license in LICENSE$ -->
</header>
<#include "developer.ftl"> <#include "developer.ftl">
<nav role="navigation"> <nav role="navigation">
@ -11,22 +9,3 @@
</#list> </#list>
</ul> </ul>
</nav> </nav>
<div id="wrapper-content" role="main">
<#if flash?has_content>
<#if flash?starts_with("Welcome") >
<section id="welcome-msg-container" role="container">
<section id="welcome-message" role="alert">${flash}</section>
</section>
<#else>
<section id="flash-message" role="alert">
${flash}
</section>
</#if>
</#if>
<!--[if lte IE 8]>
<noscript>
<p class="ie-alert">${i18n().javascript_ie_alert_text} Here are the <a href="http://www.enable-javascript.com" title="javascript instructions">${i18n().to_enable_javascript}</a>.</p>
</noscript>
<![endif]-->

View file

@ -10,10 +10,12 @@
</head> </head>
<body class="${bodyClasses!}"> <body class="${bodyClasses!}">
<header id="branding" role="banner">
<#include "identity.ftl"> <#include "identity.ftl">
</header>
<#include "menu.ftl"> <#include "menu.ftl">
<div id="wrapper-content" role="main">
<section id="intro" role="region"> <section id="intro" role="region">
<h2>${i18n().what_is_vitro}</h2> <h2>${i18n().what_is_vitro}</h2>
@ -51,12 +53,11 @@
</section> <!-- #intro --> </section> <!-- #intro -->
<@widget name="login" /> <@widget name="login" />
<!-- Statistical information relating to property groups and their classes; displayed horizontally, not vertically--> <!-- Statistical information relating to property groups and their classes; displayed horizontally, not vertically-->
<@lh.allClassGroups vClassGroups! /> <@lh.allClassGroups vClassGroups! />
</div>
<#include "footer.ftl"> <#include "footer.ftl">
<script> <script>

View file

@ -9,12 +9,15 @@
</head> </head>
<body class="${bodyClasses!}"> <body class="${bodyClasses!}">
<header id="branding" role="banner">
<#include "identity.ftl"> <#include "identity.ftl">
<#include "search.ftl"> <#include "search.ftl">
</header>
<#include "menu.ftl"> <#include "menu.ftl">
<div id="wrapper-content" role="main">
${body} ${body}
</div>
<#include "footer.ftl"> <#include "footer.ftl">
</body> </body>
</html> </html>

View file

@ -0,0 +1,3 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<link rel="stylesheet" href="${urls.theme}/css/screen.css" />