union domains on data property pages

This commit is contained in:
brianjlowe 2013-12-05 16:06:42 -05:00
parent 8ab6d229a6
commit 89d4fc9228
6 changed files with 81 additions and 19 deletions

View file

@ -70,6 +70,11 @@ public class DataProperty extends Property implements Comparable<DataProperty>,
public String getDomainClassURI() {
return domainClassURI;
}
@Override
public String getDomainVClassURI() {
return domainClassURI;
}
public void setDomainClassURI(String domainClassURI) {
this.domainClassURI = domainClassURI;

View file

@ -28,6 +28,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
public class DatapropEditController extends BaseEditController {
@ -45,7 +46,13 @@ public class DatapropEditController extends BaseEditController {
String datapropURI = request.getParameter("uri");
DataPropertyDao dpDao = vreq.getUnfilteredWebappDaoFactory().getDataPropertyDao();
DataPropertyDao dpDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getDataPropertyDao();
VClassDao vcDao = vreq.getLanguageNeutralWebappDaoFactory().getVClassDao();
VClassDao vcDaoWLang = vreq.getUnfilteredWebappDaoFactory().getVClassDao();
DataProperty dp = dpDao.getDataPropertyByURI(datapropURI);
DataProperty pLangNeut = dpDaoLangNeut.getDataPropertyByURI(request.getParameter("uri"));
PropertyGroupDao pgDao = vreq.getUnfilteredWebappDaoFactory().getPropertyGroupDao();
ArrayList results = new ArrayList();
@ -98,14 +105,21 @@ public class DatapropEditController extends BaseEditController {
//String parentPropertyStr = "<i>(datatype properties are not yet modeled in a property hierarchy)</i>"; // TODO - need multiple inheritance
//results.add(parentPropertyStr);
// TODO - need unionOf/intersectionOf-style domains for domain class
String domainStr="";
try {
VClass domainClass = getWebappDaoFactory().getVClassDao().getVClassByURI(dp.getDomainClassURI());
String domainLinkAnchor = (domainClass != null) ? domainClass.getPickListName() : dp.getDomainClassURI();
domainStr = (dp.getDomainClassURI() == null) ? "" : "<a href=\"vclassEdit?uri="+URLEncoder.encode(dp.getDomainClassURI(),"UTF-8")+"\">"+domainLinkAnchor+"</a>";
} catch (UnsupportedEncodingException e) {
log.error(e, e);
String domainStr = "";
if (pLangNeut.getDomainVClassURI() != null) {
VClass domainClass = vcDao.getVClassByURI(pLangNeut.getDomainVClassURI());
VClass domainWLang = vcDaoWLang.getVClassByURI(pLangNeut.getDomainVClassURI());
if (domainClass != null && domainClass.getURI() != null && domainClass.getPickListName() != null) {
try {
if (domainClass.isAnonymous()) {
domainStr = domainClass.getPickListName();
} else {
domainStr = "<a href=\"vclassEdit?uri="+URLEncoder.encode(domainClass.getURI(),"UTF-8")+"\">"+domainWLang.getPickListName()+"</a>";
}
} catch (UnsupportedEncodingException e) {
log.error(e, e);
}
}
}
results.add(domainStr); // column 6

View file

@ -20,6 +20,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.Datatype;
import edu.cornell.mannlib.vitro.webapp.beans.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;
@ -57,7 +58,9 @@ public class ListDatatypePropertiesController extends FreemarkerHttpServlet {
String ontologyUri = vreq.getParameter("ontologyUri");
DataPropertyDao dao = vreq.getUnfilteredWebappDaoFactory().getDataPropertyDao();
DataPropertyDao dpDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getDataPropertyDao();
VClassDao vcDao = vreq.getUnfilteredWebappDaoFactory().getVClassDao();
VClassDao vcDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getVClassDao();
DatatypeDao dDao = vreq.getUnfilteredWebappDaoFactory().getDatatypeDao();
PropertyGroupDao pgDao = vreq.getUnfilteredWebappDaoFactory().getPropertyGroupDao();
@ -132,8 +135,11 @@ public class ListDatatypePropertiesController extends FreemarkerHttpServlet {
}
}
*/
VClass vc = (prop.getDomainClassURI() != null) ? vcDao.getVClassByURI(prop.getDomainClassURI()) : null;
String domainStr = (vc != null) ? vc.getPickListName() : "";
DataProperty dpLangNeut = dpDaoLangNeut.getDataPropertyByURI(prop.getURI());
if(dpLangNeut == null) {
dpLangNeut = prop;
}
String domainStr = getVClassNameFromURI(dpLangNeut.getDomainVClassURI(), vcDao, vcDaoLangNeut);
json += "\"domainVClass\": " + JSONUtils.quote(domainStr) + ", " ;
Datatype rangeDatatype = dDao.getDatatypeByURI(prop.getRangeDatatypeURI());
@ -156,4 +162,20 @@ public class ListDatatypePropertiesController extends FreemarkerHttpServlet {
}
return new TemplateResponseValues(TEMPLATE_NAME, body);
}
private String getVClassNameFromURI(String vclassURI, VClassDao vcDao, VClassDao vcDaoLangNeut) {
if(vclassURI == null) {
return "";
}
VClass vclass = vcDaoLangNeut.getVClassByURI(vclassURI);
if(vclass == null) {
return "";
}
if(vclass.isAnonymous()) {
return vclass.getPickListName();
} else {
VClass vclassWLang = vcDao.getVClassByURI(vclassURI);
return (vclassWLang != null) ? vclassWLang.getPickListName() : vclass.getPickListName();
}
}
}

View file

@ -21,6 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.Datatype;
import edu.cornell.mannlib.vitro.webapp.beans.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;
@ -40,7 +41,9 @@ public class ShowDataPropertyHierarchyController extends FreemarkerHttpServlet {
private int MAXDEPTH = 5;
private DataPropertyDao dpDao = null;
private DataPropertyDao dpDaoLangNeut = null;
private VClassDao vcDao = null;
private VClassDao vcDaoLangNeut = null;
private PropertyGroupDao pgDao = null;
private DatatypeDao dDao = null;
@ -77,7 +80,9 @@ public class ShowDataPropertyHierarchyController extends FreemarkerHttpServlet {
body.put("propertyType", "data");
dpDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getDataPropertyDao();
dpDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getDataPropertyDao();
vcDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getVClassDao();
vcDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getVClassDao();
pgDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getPropertyGroupDao();
dDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getDatatypeDao();
@ -217,15 +222,14 @@ public class ShowDataPropertyHierarchyController extends FreemarkerHttpServlet {
tempString += "\"data\": { \"internalName\": " + JSONUtils.quote(
dp.getPickListName()) + ", ";
VClass tmp = null;
DataProperty dpLangNeut = dpDaoLangNeut.getDataPropertyByURI(dp.getURI());
if(dpLangNeut == null) {
dpLangNeut = dp;
}
String domainStr = getVClassNameFromURI(dpLangNeut.getDomainVClassURI(), vcDao, vcDaoLangNeut);
try {
tempString += "\"domainVClass\": " + JSONUtils.quote(
((tmp = vcDao.getVClassByURI(dp.getDomainClassURI())) != null
&& (tmp.getPickListName() == null))
? ""
: vcDao.getVClassByURI(
dp.getDomainClassURI())
.getPickListName()) + ", " ;
tempString += "\"domainVClass\": " + JSONUtils.quote(domainStr) + ", " ;
} catch (NullPointerException e) {
tempString += "\"domainVClass\": \"\",";
}
@ -249,4 +253,20 @@ public class ShowDataPropertyHierarchyController extends FreemarkerHttpServlet {
return tempString;
}
private String getVClassNameFromURI(String vclassURI, VClassDao vcDao, VClassDao vcDaoLangNeut) {
if(vclassURI == null) {
return "";
}
VClass vclass = vcDaoLangNeut.getVClassByURI(vclassURI);
if(vclass == null) {
return "";
}
if(vclass.isAnonymous()) {
return vclass.getPickListName();
} else {
VClass vclassWLang = vcDao.getVClassByURI(vclassURI);
return (vclassWLang != null) ? vclassWLang.getPickListName() : vclass.getPickListName();
}
}
}

View file

@ -183,7 +183,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
dp.setPickListName(getWebappDaoFactory().makePickListName(dp));
Resource dRes = op.getDomain();
if (dRes != null) {
dp.setDomainClassURI(dRes.getURI());
dp.setDomainClassURI(dRes.isAnon()? PSEUDO_BNODE_NS + dRes.getId().toString() : dRes.getURI());
}
Resource rRes = op.getRange();
if (rRes != null) {

View file

@ -192,6 +192,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
return getLabelOrId(cls);
}
} catch (Exception e) {
log.error(e, e);
return "???";
} finally {
cls.getModel().leaveCriticalSection();