ongoing work on VIVO-60 application ontology support for property/class combinations
This commit is contained in:
parent
4ee600a0d4
commit
54f43f56d3
6 changed files with 74 additions and 12 deletions
|
@ -21,6 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||||
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.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.FreemarkerConfigurationLoader;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfigurationLoader;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||||
|
@ -57,6 +58,10 @@ public class EditConfigurationUtils {
|
||||||
return vreq.getParameter("rangeUri");
|
return vreq.getParameter("rangeUri");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static VClass getRangeVClass(VitroRequest vreq) {
|
||||||
|
return vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(getRangeUri(vreq));
|
||||||
|
}
|
||||||
|
|
||||||
//get individual
|
//get individual
|
||||||
|
|
||||||
public static Individual getSubjectIndividual(VitroRequest vreq) {
|
public static Individual getSubjectIndividual(VitroRequest vreq) {
|
||||||
|
@ -93,7 +98,8 @@ public class EditConfigurationUtils {
|
||||||
public static ObjectProperty getObjectProperty(VitroRequest vreq) {
|
public static ObjectProperty getObjectProperty(VitroRequest vreq) {
|
||||||
//gets the predicate uri from the request
|
//gets the predicate uri from the request
|
||||||
String predicateUri = getPredicateUri(vreq);
|
String predicateUri = getPredicateUri(vreq);
|
||||||
return getObjectPropertyForPredicate(vreq, predicateUri);
|
String rangeUri = getRangeUri(vreq);
|
||||||
|
return getObjectPropertyForPredicate(vreq, predicateUri, rangeUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataProperty getDataProperty(VitroRequest vreq) {
|
public static DataProperty getDataProperty(VitroRequest vreq) {
|
||||||
|
@ -102,8 +108,16 @@ public class EditConfigurationUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ObjectProperty getObjectPropertyForPredicate(VitroRequest vreq, String predicateUri) {
|
public static ObjectProperty getObjectPropertyForPredicate(VitroRequest vreq, String predicateUri) {
|
||||||
|
return getObjectPropertyForPredicate(vreq, predicateUri, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ObjectProperty getObjectPropertyForPredicate(VitroRequest vreq, String predicateUri, String rangeUri) {
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||||
ObjectProperty objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
ObjectProperty objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
||||||
|
if (rangeUri != null) {
|
||||||
|
objectProp.setRangeVClassURI(rangeUri);
|
||||||
|
// TODO implement this in the DAO?
|
||||||
|
}
|
||||||
return objectProp;
|
return objectProp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
|
||||||
public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
||||||
|
@ -77,6 +78,10 @@ public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
||||||
//get all vclasses applicable to the individual subject
|
//get all vclasses applicable to the individual subject
|
||||||
HashSet<String> vclassesURIs = getApplicableVClassURIs(subject, wDaoFact);
|
HashSet<String> vclassesURIs = getApplicableVClassURIs(subject, wDaoFact);
|
||||||
|
|
||||||
|
if (rangeUri != null) {
|
||||||
|
vclassesURIs = filterToSubclassesOfRange(vclassesURIs, rangeUri, wDaoFact);
|
||||||
|
}
|
||||||
|
|
||||||
if (vclassesURIs.size() == 0) {
|
if (vclassesURIs.size() == 0) {
|
||||||
return optionsMap;
|
return optionsMap;
|
||||||
}
|
}
|
||||||
|
@ -138,6 +143,19 @@ public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
||||||
return vclassesURIs;
|
return vclassesURIs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HashSet<String> filterToSubclassesOfRange(HashSet<String> vclassesURIs,
|
||||||
|
String rangeUri,
|
||||||
|
WebappDaoFactory wDaoFact) {
|
||||||
|
HashSet<String> filteredVClassesURIs = new HashSet<String>();
|
||||||
|
VClassDao vcDao = wDaoFact.getVClassDao();
|
||||||
|
for (String vclass : vclassesURIs) {
|
||||||
|
if (vclass.equals(rangeUri) || vcDao.isSubClassOf(vclass, rangeUri)) {
|
||||||
|
filteredVClassesURIs.add(vclass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filteredVClassesURIs;
|
||||||
|
}
|
||||||
|
|
||||||
// copied from OptionsForPropertyTag.java in the thought that class may be deprecated
|
// copied from OptionsForPropertyTag.java in the thought that class may be deprecated
|
||||||
private static List<Individual> removeIndividualsAlreadyInRange(List<Individual> individuals,
|
private static List<Individual> removeIndividualsAlreadyInRange(List<Individual> individuals,
|
||||||
List<ObjectPropertyStatement> stmts, String predicateUri, String objectUriBeingEdited){
|
List<ObjectPropertyStatement> stmts, String predicateUri, String objectUriBeingEdited){
|
||||||
|
|
|
@ -145,7 +145,6 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
query.setQuery( VitroSearchTermNames.RDFTYPE + ":" + type);
|
query.setQuery( VitroSearchTermNames.RDFTYPE + ":" + type);
|
||||||
}
|
}
|
||||||
query.setRows(0);
|
query.setRows(0);
|
||||||
|
|
||||||
QueryResponse rsp = solrServer.query(query);
|
QueryResponse rsp = solrServer.query(query);
|
||||||
SolrDocumentList docs = rsp.getResults();
|
SolrDocumentList docs = rsp.getResults();
|
||||||
long found = docs.getNumFound();
|
long found = docs.getNumFound();
|
||||||
|
@ -472,6 +471,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
for( String type:types){
|
for( String type:types){
|
||||||
//solr for type count.
|
//solr for type count.
|
||||||
SolrQuery query = new SolrQuery();
|
SolrQuery query = new SolrQuery();
|
||||||
|
|
||||||
query.setQuery( VitroSearchTermNames.RDFTYPE + ":" + type);
|
query.setQuery( VitroSearchTermNames.RDFTYPE + ":" + type);
|
||||||
query.setRows(0);
|
query.setRows(0);
|
||||||
|
|
||||||
|
|
|
@ -217,7 +217,7 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
}else if( predicateUri != null && !predicateUri.isEmpty() ){
|
}else if( predicateUri != null && !predicateUri.isEmpty() ){
|
||||||
Property prop = getProperty( predicateUri, vreq);
|
Property prop = getProperty( predicateUri, vreq);
|
||||||
if (prop != null && rangeUri != null) {
|
if (prop != null && rangeUri != null) {
|
||||||
// get the custom form out of the application ontology data
|
editConfGeneratorName = getCustomEntryFormForPropertyAndRange(prop, rangeUri);
|
||||||
} else if( prop != null && prop.getCustomEntryForm() != null ){
|
} else if( prop != null && prop.getCustomEntryForm() != null ){
|
||||||
//there is a custom form, great! let's use it.
|
//there is a custom form, great! let's use it.
|
||||||
editConfGeneratorName = prop.getCustomEntryForm();
|
editConfGeneratorName = prop.getCustomEntryForm();
|
||||||
|
@ -247,6 +247,21 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
return editConfGeneratorName;
|
return editConfGeneratorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getCustomEntryFormForPropertyAndRange(Property prop, String rangeUri){
|
||||||
|
String entryFormName = null;
|
||||||
|
// = ApplicationConfigurationOntologyUtils.getEntryForm(prop.getURI(), rangeUri);
|
||||||
|
if (entryFormName == null) {
|
||||||
|
if (prop.getCustomEntryForm() != null) {
|
||||||
|
return prop.getCustomEntryForm();
|
||||||
|
} else {
|
||||||
|
return DEFAULT_OBJ_FORM;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
prop.setCustomEntryForm(entryFormName);
|
||||||
|
return entryFormName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Property getProperty(String predicateUri, VitroRequest vreq) {
|
private Property getProperty(String predicateUri, VitroRequest vreq) {
|
||||||
Property p = null;
|
Property p = null;
|
||||||
try{
|
try{
|
||||||
|
|
|
@ -37,6 +37,8 @@ public class ApplicationConfigurationOntologyUtils {
|
||||||
return getAdditionalFauxSubpropertiesForList(propList, displayModel, tboxModel);
|
return getAdditionalFauxSubpropertiesForList(propList, displayModel, tboxModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static List<ObjectProperty> getAdditionalFauxSubpropertiesForList(List<ObjectProperty> propList,
|
public static List<ObjectProperty> getAdditionalFauxSubpropertiesForList(List<ObjectProperty> propList,
|
||||||
Model displayModel,
|
Model displayModel,
|
||||||
Model tboxModel) {
|
Model tboxModel) {
|
||||||
|
|
|
@ -180,6 +180,7 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
||||||
Individual objectIndividual = EditConfigurationUtils.getObjectIndividual(vreq);
|
Individual objectIndividual = EditConfigurationUtils.getObjectIndividual(vreq);
|
||||||
ObjectProperty prop = EditConfigurationUtils.getObjectProperty(vreq);
|
ObjectProperty prop = EditConfigurationUtils.getObjectProperty(vreq);
|
||||||
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
|
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
|
||||||
|
VClass rangeClass = EditConfigurationUtils.getRangeVClass(vreq);
|
||||||
if(objectIndividual != null) {
|
if(objectIndividual != null) {
|
||||||
propertyTitle = prop.getDomainPublic();
|
propertyTitle = prop.getDomainPublic();
|
||||||
} else {
|
} else {
|
||||||
|
@ -187,8 +188,9 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
||||||
if ( prop.getOfferCreateNewOption() ) {
|
if ( prop.getOfferCreateNewOption() ) {
|
||||||
//Try to get the name of the class to select from
|
//Try to get the name of the class to select from
|
||||||
VClass classOfObjectFillers = null;
|
VClass classOfObjectFillers = null;
|
||||||
|
if (rangeClass != null) {
|
||||||
if( prop.getRangeVClassURI() == null ) {
|
classOfObjectFillers = rangeClass;
|
||||||
|
} else if( prop.getRangeVClassURI() == null ) {
|
||||||
// If property has no explicit range, try to get classes
|
// If property has no explicit range, try to get classes
|
||||||
List<VClass> classes = wdf.getVClassDao().getVClassesForProperty(subject.getVClassURI(), prop.getURI());
|
List<VClass> classes = wdf.getVClassDao().getVClassesForProperty(subject.getVClassURI(), prop.getURI());
|
||||||
if( classes == null || classes.size() == 0 || classes.get(0) == null ){
|
if( classes == null || classes.size() == 0 || classes.get(0) == null ){
|
||||||
|
@ -515,12 +517,23 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
||||||
Individual sub =
|
Individual sub =
|
||||||
wdf.getIndividualDao().getIndividualByURI(editConfig.getSubjectUri());
|
wdf.getIndividualDao().getIndividualByURI(editConfig.getSubjectUri());
|
||||||
|
|
||||||
|
VClass rangeClass = EditConfigurationUtils.getRangeVClass(vreq);
|
||||||
|
|
||||||
List<VClass> vclasses = null;
|
List<VClass> vclasses = null;
|
||||||
List<VClass> subjectVClasses = sub.getVClasses();
|
List<VClass> subjectVClasses = sub.getVClasses();
|
||||||
if( subjectVClasses == null ) {
|
if( subjectVClasses == null ) {
|
||||||
vclasses = wdf.getVClassDao().getAllVclasses();
|
vclasses = wdf.getVClassDao().getAllVclasses();
|
||||||
|
} else if (rangeClass != null) {
|
||||||
|
vclasses = new ArrayList<VClass>();
|
||||||
|
vclasses.add(rangeClass);
|
||||||
|
List<String> subURIs = wdf.getVClassDao().getSubClassURIs(rangeClass.getURI());
|
||||||
|
for (String subClassURI : subURIs) {
|
||||||
|
VClass subClass = wdf.getVClassDao().getVClassByURI(subClassURI);
|
||||||
|
if (subClass != null) {
|
||||||
|
vclasses.add(subClass);
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
|
} else {
|
||||||
//this hash is used to make sure there are no duplicates in the vclasses
|
//this hash is used to make sure there are no duplicates in the vclasses
|
||||||
//a more elegant method may look at overriding equals/hashcode to enable a single hashset of VClass objects
|
//a more elegant method may look at overriding equals/hashcode to enable a single hashset of VClass objects
|
||||||
HashSet<String> vclassesURIs = new HashSet<String>();
|
HashSet<String> vclassesURIs = new HashSet<String>();
|
||||||
|
|
Loading…
Add table
Reference in a new issue