NIHVIVO-3014 properties included on property group listing page
This commit is contained in:
parent
349559f20e
commit
85d21c5c59
2 changed files with 129 additions and 134 deletions
|
@ -3,6 +3,7 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller.edit.listing;
|
package edu.cornell.mannlib.vitro.webapp.controller.edit.listing;
|
||||||
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.text.Collator;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -13,6 +14,10 @@ import javax.servlet.RequestDispatcher;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.EditOntology;
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.EditOntology;
|
||||||
|
@ -26,120 +31,87 @@ import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
|
||||||
|
|
||||||
public class PropertyGroupsListingController extends BaseEditController {
|
public class PropertyGroupsListingController extends BaseEditController {
|
||||||
|
|
||||||
@Override
|
private static final long serialVersionUID = 1L;
|
||||||
public void doGet(HttpServletRequest request, HttpServletResponse response) {
|
private static final Log log = LogFactory.getLog(PropertyGroupsListingController.class);
|
||||||
if (!isAuthorizedToDisplayPage(request, response, new Actions(new EditOntology()))) {
|
private static final boolean WITH_PROPERTIES = true;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
VitroRequest vrequest = new VitroRequest(request);
|
|
||||||
|
|
||||||
//need to figure out how to structure the results object to put the classes underneath
|
@Override
|
||||||
|
public void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
if (!isAuthorizedToDisplayPage(request, response, new Actions(new EditOntology()))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
|
|
||||||
PropertyGroupDao dao = vrequest.getFullWebappDaoFactory().getPropertyGroupDao();
|
PropertyGroupDao dao = vreq.getFullWebappDaoFactory().getPropertyGroupDao();
|
||||||
|
|
||||||
List<PropertyGroup> groups = dao.getPublicGroups(true);
|
List<PropertyGroup> groups = dao.getPublicGroups(WITH_PROPERTIES);
|
||||||
|
|
||||||
|
Comparator<Property> comparator = new PropertySorter();
|
||||||
|
|
||||||
ArrayList<String> results = new ArrayList<String>();
|
List<String> results = new ArrayList<String>();
|
||||||
results.add("XX");
|
results.add("XX");
|
||||||
results.add("Group");
|
results.add("group");
|
||||||
results.add("Public description");
|
|
||||||
results.add("display rank");
|
results.add("display rank");
|
||||||
|
results.add("");
|
||||||
results.add("XX");
|
results.add("XX");
|
||||||
|
|
||||||
if (groups != null) {
|
if (groups != null) {
|
||||||
Collections.sort(groups, new PropertyGroupDisplayComparator());
|
for(PropertyGroup pg: groups) {
|
||||||
Iterator<PropertyGroup> groupsIt = groups.iterator();
|
|
||||||
while (groupsIt.hasNext()) {
|
|
||||||
PropertyGroup pg = groupsIt.next();
|
|
||||||
results.add("XX");
|
results.add("XX");
|
||||||
if (pg.getName() != null) {
|
String publicName = pg.getName();
|
||||||
try {
|
if ( StringUtils.isBlank(publicName) ) {
|
||||||
results.add("<a href=\"./editForm?uri=" +
|
publicName = "(unnamed group)";
|
||||||
URLEncoder.encode(pg.getURI(),"UTF-8") +
|
}
|
||||||
"&controller=PropertyGroup\">" +
|
try {
|
||||||
pg.getName() + "</a>");
|
results.add("<a href=\"./editForm?uri="+URLEncoder.encode(pg.getURI(),"UTF-8")+"&controller=PropertyGroup\">"+publicName+"</a>");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
results.add(pg.getName());
|
results.add(publicName);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
results.add("");
|
|
||||||
}
|
}
|
||||||
results.add(
|
|
||||||
(pg.getPublicDescription() == null)
|
|
||||||
? "unspecified"
|
|
||||||
: pg.getPublicDescription());
|
|
||||||
Integer t;
|
Integer t;
|
||||||
results.add(
|
results.add(((t = Integer.valueOf(pg.getDisplayRank())) != -1) ? t.toString() : "");
|
||||||
((t = Integer.valueOf(pg.getDisplayRank())) != -1)
|
results.add("");
|
||||||
? t.toString()
|
|
||||||
: "");
|
|
||||||
results.add("XX");
|
results.add("XX");
|
||||||
List<Property> classList = pg.getPropertyList();
|
List<Property> propertyList = pg.getPropertyList();
|
||||||
if (classList != null && classList.size()>0) {
|
if (propertyList != null && propertyList.size() > 0) {
|
||||||
|
Collections.sort(propertyList, comparator);
|
||||||
results.add("+");
|
results.add("+");
|
||||||
results.add("XX");
|
results.add("XX");
|
||||||
results.add("Property");
|
results.add("property");
|
||||||
results.add("example");
|
results.add("");
|
||||||
results.add("description");
|
results.add("");
|
||||||
results.add("@@entities");
|
results.add("@@entities");
|
||||||
Iterator<Property> propIt = classList.iterator();
|
Iterator<Property> propIt = propertyList.iterator();
|
||||||
while (propIt.hasNext()) {
|
while (propIt.hasNext()) {
|
||||||
results.add("XX");
|
Property prop = propIt.next();
|
||||||
Property p = propIt.next();
|
results.add("XX");
|
||||||
if (p instanceof ObjectProperty) {
|
String controllerStr = "propertyEdit";
|
||||||
ObjectProperty op = (ObjectProperty) p;
|
String nameStr =
|
||||||
if (op.getLocalNameWithPrefix() != null
|
(prop.getLabel() == null)
|
||||||
&& op.getURI() != null) {
|
? ""
|
||||||
try {
|
: prop.getLabel();
|
||||||
results.add("<a href=\"propertyEdit?uri=" +
|
if (prop instanceof ObjectProperty) {
|
||||||
URLEncoder.encode(
|
nameStr = ((ObjectProperty) prop).getDomainPublic();
|
||||||
op.getURI(), "UTF-8") +
|
} else if (prop instanceof DataProperty) {
|
||||||
"\">" +
|
controllerStr = "datapropEdit";
|
||||||
op.getLocalNameWithPrefix()
|
nameStr = ((DataProperty) prop).getName();
|
||||||
+ "</a>");
|
|
||||||
} catch (Exception e) {
|
|
||||||
results.add(op.getLocalNameWithPrefix());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
results.add("");
|
|
||||||
}
|
|
||||||
String exampleStr =
|
|
||||||
(op.getExample() == null)
|
|
||||||
? ""
|
|
||||||
: op.getExample();
|
|
||||||
results.add(exampleStr);
|
|
||||||
String descriptionStr =
|
|
||||||
(op.getDescription() == null)
|
|
||||||
? ""
|
|
||||||
: op.getDescription();
|
|
||||||
results.add(descriptionStr);
|
|
||||||
} else {
|
|
||||||
DataProperty dp = (DataProperty) p;
|
|
||||||
if (dp.getName() != null && dp.getURI() != null) {
|
|
||||||
try {
|
|
||||||
results.add("<a href=\"datapropEdit?uri=" +
|
|
||||||
URLEncoder.encode(
|
|
||||||
dp.getURI(),"UTF-8") +
|
|
||||||
"\">" + dp.getName() +
|
|
||||||
"</a>");
|
|
||||||
} catch (Exception e) {
|
|
||||||
results.add(dp.getName());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
results.add("");
|
|
||||||
}
|
|
||||||
String exampleStr =
|
|
||||||
(dp.getExample() == null)
|
|
||||||
? ""
|
|
||||||
: dp.getExample();
|
|
||||||
results.add(exampleStr);
|
|
||||||
String descriptionStr =
|
|
||||||
(dp.getDescription() == null)
|
|
||||||
? ""
|
|
||||||
: dp.getDescription();
|
|
||||||
results.add(descriptionStr);
|
|
||||||
}
|
}
|
||||||
|
if (prop.getURI() != null) {
|
||||||
|
try {
|
||||||
|
results.add("<a href=\"" + controllerStr +
|
||||||
|
"?uri="+URLEncoder.encode(
|
||||||
|
prop.getURI(),"UTF-8") +
|
||||||
|
"\">" + nameStr +"</a>");
|
||||||
|
} catch (Exception e) {
|
||||||
|
results.add(nameStr);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
results.add(nameStr);
|
||||||
|
}
|
||||||
|
String exampleStr = "";
|
||||||
|
results.add(exampleStr);
|
||||||
|
String descriptionStr = "";
|
||||||
|
results.add(descriptionStr);
|
||||||
if (propIt.hasNext())
|
if (propIt.hasNext())
|
||||||
results.add("@@entities");
|
results.add("@@entities");
|
||||||
}
|
}
|
||||||
|
@ -163,20 +135,33 @@ public class PropertyGroupsListingController extends BaseEditController {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PropertyGroupDisplayComparator implements Comparator<PropertyGroup> {
|
private class PropertySorter implements Comparator<Property> {
|
||||||
@Override
|
|
||||||
public int compare (PropertyGroup o1, PropertyGroup o2) {
|
private Collator coll = Collator.getInstance();
|
||||||
try {
|
|
||||||
int diff = o1.getDisplayRank() - o2.getDisplayRank();
|
public int compare(Property p1, Property p2) {
|
||||||
if (diff==0) {
|
String name1 = getName(p1);
|
||||||
return o1.getName().compareToIgnoreCase(o2.getName());
|
String name2 = getName(p2);
|
||||||
}
|
if (name1 == null && name2 != null) {
|
||||||
return diff;
|
return 1;
|
||||||
} catch (Exception e) {
|
} else if (name2 == null && name1 != null) {
|
||||||
return 1;
|
return -1;
|
||||||
}
|
} else if (name1 == null && name2 == null) {
|
||||||
}
|
return 0;
|
||||||
|
}
|
||||||
|
return coll.compare(name1, name2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getName(Property prop) {
|
||||||
|
if (prop instanceof ObjectProperty) {
|
||||||
|
return ((ObjectProperty) prop).getDomainPublic();
|
||||||
|
} else if (prop instanceof DataProperty) {
|
||||||
|
return ((DataProperty) prop).getName();
|
||||||
|
} else {
|
||||||
|
return prop.getLabel();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import com.hp.hpl.jena.ontology.Individual;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||||
|
@ -87,44 +88,53 @@ public class PropertyGroupDaoJena extends JenaBaseDao implements PropertyGroupDa
|
||||||
public List<PropertyGroup> getPublicGroups(boolean withProperties) {
|
public List<PropertyGroup> getPublicGroups(boolean withProperties) {
|
||||||
ObjectPropertyDao opDao = getWebappDaoFactory().getObjectPropertyDao();
|
ObjectPropertyDao opDao = getWebappDaoFactory().getObjectPropertyDao();
|
||||||
DataPropertyDao dpDao = getWebappDaoFactory().getDataPropertyDao();
|
DataPropertyDao dpDao = getWebappDaoFactory().getDataPropertyDao();
|
||||||
|
List<PropertyGroup> groups = new ArrayList<PropertyGroup>();
|
||||||
getOntModel().enterCriticalSection(Lock.READ);
|
getOntModel().enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
List<PropertyGroup> groups = new ArrayList<PropertyGroup>();
|
|
||||||
ClosableIterator groupIt = getOntModel().listIndividuals(PROPERTYGROUP);
|
ClosableIterator groupIt = getOntModel().listIndividuals(PROPERTYGROUP);
|
||||||
try {
|
try {
|
||||||
while (groupIt.hasNext()) {
|
while (groupIt.hasNext()) {
|
||||||
Individual grp = (Individual) groupIt.next();
|
Individual grp = (Individual) groupIt.next();
|
||||||
PropertyGroup pgrp = groupFromGroupIndividual(grp);
|
PropertyGroup pgrp = groupFromGroupIndividual(grp);
|
||||||
List<Property> properties = new ArrayList<Property>();
|
if (pgrp != null) {
|
||||||
if (withProperties) {
|
groups.add(pgrp);
|
||||||
ClosableIterator closeIt = getOntModel().listStatements(null, PROPERTY_INPROPERTYGROUPANNOT, grp);
|
|
||||||
try {
|
|
||||||
for (Iterator stmtIt = closeIt; stmtIt.hasNext(); ) {
|
|
||||||
Statement stmt = (Statement) stmtIt.next();
|
|
||||||
Resource subjRes = stmt.getSubject();
|
|
||||||
if (subjRes.canAs(com.hp.hpl.jena.ontology.ObjectProperty.class)) {
|
|
||||||
properties.add(opDao.getObjectPropertyByURI(subjRes.getURI()));
|
|
||||||
} else if (subjRes.canAs(com.hp.hpl.jena.ontology.DatatypeProperty.class)) {
|
|
||||||
properties.add(dpDao.getDataPropertyByURI(subjRes.getURI()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
closeIt.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pgrp!=null) {
|
|
||||||
pgrp.setPropertyList(properties);
|
|
||||||
groups.add(pgrp);
|
|
||||||
Collections.sort(groups);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
groupIt.close();
|
groupIt.close();
|
||||||
}
|
}
|
||||||
return groups;
|
|
||||||
} finally {
|
} finally {
|
||||||
getOntModel().leaveCriticalSection();
|
getOntModel().leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
if (withProperties) {
|
||||||
|
Model tboxModel = getOntModelSelector().getTBoxModel();
|
||||||
|
tboxModel.enterCriticalSection(Lock.READ);
|
||||||
|
try {
|
||||||
|
for (PropertyGroup pgrp : groups) {
|
||||||
|
List<Property> properties = new ArrayList<Property>();
|
||||||
|
ClosableIterator closeIt = tboxModel.listStatements(
|
||||||
|
null, PROPERTY_INPROPERTYGROUPANNOT, tboxModel.getResource(pgrp.getURI()));
|
||||||
|
try {
|
||||||
|
for (Iterator stmtIt = closeIt; stmtIt.hasNext(); ) {
|
||||||
|
Statement stmt = (Statement) stmtIt.next();
|
||||||
|
Resource subjRes = stmt.getSubject();
|
||||||
|
if (subjRes.canAs(com.hp.hpl.jena.ontology.ObjectProperty.class)) {
|
||||||
|
properties.add(opDao.getObjectPropertyByURI(subjRes.getURI()));
|
||||||
|
} else if (subjRes.canAs(com.hp.hpl.jena.ontology.DatatypeProperty.class)) {
|
||||||
|
properties.add(dpDao.getDataPropertyByURI(subjRes.getURI()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
closeIt.close();
|
||||||
|
}
|
||||||
|
pgrp.setPropertyList(properties);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
tboxModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(groups);
|
||||||
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String insertNewPropertyGroup(PropertyGroup group) {
|
public String insertNewPropertyGroup(PropertyGroup group) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue