VIVO-623 unión domains and ranges on object property displays

This commit is contained in:
brianjlowe 2013-12-05 14:57:31 -05:00
parent d2792db057
commit 8ab6d229a6
3 changed files with 67 additions and 31 deletions

View file

@ -27,6 +27,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
@ -47,10 +48,12 @@ public class PropertyEditController extends BaseEditController {
VitroRequest vreq = new VitroRequest(request);
ObjectPropertyDao propDao = vreq.getUnfilteredWebappDaoFactory().getObjectPropertyDao();
VClassDao vcDao = vreq.getUnfilteredWebappDaoFactory().getVClassDao();
ObjectPropertyDao propDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getObjectPropertyDao();
VClassDao vcDao = vreq.getLanguageNeutralWebappDaoFactory().getVClassDao();
VClassDao vcDaoWLang = vreq.getUnfilteredWebappDaoFactory().getVClassDao();
PropertyGroupDao pgDao = vreq.getUnfilteredWebappDaoFactory().getPropertyGroupDao();
DataPropertyDao dpDao = vreq.getUnfilteredWebappDaoFactory().getDataPropertyDao();
ObjectProperty p = (ObjectProperty)propDao.getObjectPropertyByURI(request.getParameter("uri"));
ObjectProperty p = propDao.getObjectPropertyByURI(request.getParameter("uri"));
ObjectProperty pLangNeut = propDaoLangNeut.getObjectPropertyByURI(request.getParameter("uri"));
request.setAttribute("property",p);
ArrayList<String> results = new ArrayList<String>();
@ -119,14 +122,15 @@ public class PropertyEditController extends BaseEditController {
results.add(p.getDomainPublic() == null ? "(no public label)" : p.getDomainPublic()); // column 6
String domainStr = "";
if (p.getDomainVClassURI() != null) {
VClass domainClass = vcDao.getVClassByURI(p.getDomainVClassURI());
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")+"\">"+domainClass.getPickListName()+"</a>";
domainStr = "<a href=\"vclassEdit?uri="+URLEncoder.encode(domainClass.getURI(),"UTF-8")+"\">"+domainWLang.getPickListName()+"</a>";
}
} catch (UnsupportedEncodingException e) {
log.error(e, e);
@ -136,14 +140,15 @@ public class PropertyEditController extends BaseEditController {
results.add(domainStr); // column 7
String rangeStr = "";
if (p.getRangeVClassURI() != null) {
VClass rangeClass = vcDao.getVClassByURI(p.getRangeVClassURI());
if (pLangNeut.getRangeVClassURI() != null) {
VClass rangeClass = vcDao.getVClassByURI(pLangNeut.getRangeVClassURI());
VClass rangeWLang = vcDaoWLang.getVClassByURI(pLangNeut.getRangeVClassURI());
if (rangeClass != null && rangeClass.getURI() != null && rangeClass.getPickListName() != null) {
try {
if (rangeClass.isAnonymous()) {
rangeStr = rangeClass.getPickListName();
} else {
rangeStr = "<a href=\"vclassEdit?uri="+URLEncoder.encode(rangeClass.getURI(),"UTF-8")+"\">"+rangeClass.getPickListName()+"</a>";
rangeStr = "<a href=\"vclassEdit?uri="+URLEncoder.encode(rangeClass.getURI(),"UTF-8")+"\">"+rangeWLang.getPickListName()+"</a>";
}
} catch (UnsupportedEncodingException e) {
log.error(e, e);

View file

@ -59,8 +59,10 @@ public class ListPropertyWebappsController extends FreemarkerHttpServlet {
String ontologyUri = vreq.getParameter("ontologyUri");
ObjectPropertyDao dao = vreq.getUnfilteredWebappDaoFactory().getObjectPropertyDao();
ObjectPropertyDao opDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getObjectPropertyDao();
PropertyInstanceDao piDao = vreq.getLanguageNeutralWebappDaoFactory().getPropertyInstanceDao();
VClassDao vcDao = vreq.getUnfilteredWebappDaoFactory().getVClassDao();
VClassDao vcDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getVClassDao();
PropertyGroupDao pgDao = vreq.getUnfilteredWebappDaoFactory().getPropertyGroupDao();
String vclassURI = vreq.getParameter("vclassUri");
@ -160,12 +162,14 @@ public class ListPropertyWebappsController extends FreemarkerHttpServlet {
json += "\"data\": { \"internalName\": " + JSONUtils.quote(prop.getLocalNameWithPrefix()) + ", ";
VClass vc = (prop.getDomainVClassURI() != null) ? vcDao.getVClassByURI(prop.getDomainVClassURI()) : null;
String domainStr = (vc != null) ? vc.getPickListName() : "";
ObjectProperty opLangNeut = opDaoLangNeut.getObjectPropertyByURI(prop.getURI());
if(opLangNeut == null) {
opLangNeut = prop;
}
String domainStr = getVClassNameFromURI(opLangNeut.getDomainVClassURI(), vcDao, vcDaoLangNeut);
json += "\"domainVClass\": " + JSONUtils.quote(domainStr) + ", " ;
vc = (prop.getRangeVClassURI() != null) ? vcDao.getVClassByURI(prop.getRangeVClassURI()) : null;
String rangeStr = (vc != null) ? vc.getPickListName() : "";
String rangeStr = getVClassNameFromURI(opLangNeut.getRangeVClassURI(), vcDao, vcDaoLangNeut);
json += "\"rangeVClass\": " + JSONUtils.quote(rangeStr) + ", " ;
if (prop.getGroupURI() != null) {
@ -186,4 +190,20 @@ public class ListPropertyWebappsController 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

@ -39,7 +39,9 @@ public class ShowObjectPropertyHierarchyController extends FreemarkerHttpServlet
private int MAXDEPTH = 5;
private ObjectPropertyDao opDao = null;
private ObjectPropertyDao opDaoLangNeut = null;
private VClassDao vcDao = null;
private VClassDao vcDaoLangNeut = null;
private PropertyGroupDao pgDao = null;
private int previous_posn = 0;
@ -75,7 +77,9 @@ public class ShowObjectPropertyHierarchyController extends FreemarkerHttpServlet
body.put("propertyType", "object");
opDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getObjectPropertyDao();
opDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getObjectPropertyDao();
vcDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getVClassDao();
vcDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getVClassDao();
pgDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getPropertyGroupDao();
String json = new String();
@ -213,29 +217,20 @@ public class ShowObjectPropertyHierarchyController extends FreemarkerHttpServlet
tempString += "\"data\": { \"internalName\": " + JSONUtils.quote(
op.getLocalNameWithPrefix()) + ", ";
VClass tmp = null;
ObjectProperty opLangNeut = opDaoLangNeut.getObjectPropertyByURI(op.getURI());
if(opLangNeut == null) {
opLangNeut = op;
}
String domainStr = getVClassNameFromURI(opLangNeut.getDomainVClassURI(), vcDao, vcDaoLangNeut);
String rangeStr = getVClassNameFromURI(opLangNeut.getRangeVClassURI(), vcDao, vcDaoLangNeut);
try {
tempString += "\"domainVClass\": " + JSONUtils.quote(
((tmp = vcDao.getVClassByURI(
op.getDomainVClassURI())) != null
&& (tmp.getPickListName() == null))
? ""
: vcDao.getVClassByURI(
op.getDomainVClassURI())
.getPickListName()) + ", " ;
tempString += "\"domainVClass\": " + JSONUtils.quote(domainStr) + ", " ;
} catch (NullPointerException e) {
tempString += "\"domainVClass\": \"\",";
}
try {
tempString += "\"rangeVClass\": " + JSONUtils.quote(
((tmp = vcDao.getVClassByURI(
op.getRangeVClassURI())) != null
&& (tmp.getPickListName() == null))
? ""
: vcDao.getVClassByURI(
op.getRangeVClassURI())
.getPickListName()) + ", " ;
tempString += "\"rangeVClass\": " + JSONUtils.quote(rangeStr) + ", " ;
} catch (NullPointerException e) {
tempString += "\"rangeVClass\": \"\",";
}
@ -253,6 +248,22 @@ public class ShowObjectPropertyHierarchyController 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();
}
}
public static class ObjectPropertyAlphaComparator implements Comparator<ObjectProperty> {
Collator collator;