ongoing work on VIVO-60 application ontology support for property/class combinations

This commit is contained in:
brianjlowe 2013-06-20 12:43:53 -04:00
parent 4ee600a0d4
commit 54f43f56d3
6 changed files with 74 additions and 12 deletions

View file

@ -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.Individual;
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.freemarker.FreemarkerConfigurationLoader;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
@ -57,6 +58,10 @@ public class EditConfigurationUtils {
return vreq.getParameter("rangeUri");
}
public static VClass getRangeVClass(VitroRequest vreq) {
return vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(getRangeUri(vreq));
}
//get individual
public static Individual getSubjectIndividual(VitroRequest vreq) {
@ -93,7 +98,8 @@ public class EditConfigurationUtils {
public static ObjectProperty getObjectProperty(VitroRequest vreq) {
//gets the predicate uri from the request
String predicateUri = getPredicateUri(vreq);
return getObjectPropertyForPredicate(vreq, predicateUri);
String rangeUri = getRangeUri(vreq);
return getObjectPropertyForPredicate(vreq, predicateUri, rangeUri);
}
public static DataProperty getDataProperty(VitroRequest vreq) {
@ -102,8 +108,16 @@ public class EditConfigurationUtils {
}
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();
ObjectProperty objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
if (rangeUri != null) {
objectProp.setRangeVClassURI(rangeUri);
// TODO implement this in the DAO?
}
return objectProp;
}

View file

@ -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.VClass;
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;
public class IndividualsViaObjectPropetyOptions implements FieldOptions {
@ -77,6 +78,10 @@ public class IndividualsViaObjectPropetyOptions implements FieldOptions {
//get all vclasses applicable to the individual subject
HashSet<String> vclassesURIs = getApplicableVClassURIs(subject, wDaoFact);
if (rangeUri != null) {
vclassesURIs = filterToSubclassesOfRange(vclassesURIs, rangeUri, wDaoFact);
}
if (vclassesURIs.size() == 0) {
return optionsMap;
}
@ -138,6 +143,19 @@ public class IndividualsViaObjectPropetyOptions implements FieldOptions {
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
private static List<Individual> removeIndividualsAlreadyInRange(List<Individual> individuals,
List<ObjectPropertyStatement> stmts, String predicateUri, String objectUriBeingEdited){

View file

@ -106,7 +106,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
String rangeUri = EditConfigurationUtils.getRangeUri(vreq);
if (rangeUri != null) {
types.add(rangeUri);
types.add(rangeUri);
return types;
}
//Get all vclasses applicable to subject
@ -145,7 +145,6 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
query.setQuery( VitroSearchTermNames.RDFTYPE + ":" + type);
}
query.setRows(0);
QueryResponse rsp = solrServer.query(query);
SolrDocumentList docs = rsp.getResults();
long found = docs.getNumFound();
@ -472,6 +471,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
for( String type:types){
//solr for type count.
SolrQuery query = new SolrQuery();
query.setQuery( VitroSearchTermNames.RDFTYPE + ":" + type);
query.setRows(0);

View file

@ -217,7 +217,7 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
}else if( predicateUri != null && !predicateUri.isEmpty() ){
Property prop = getProperty( predicateUri, vreq);
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 ){
//there is a custom form, great! let's use it.
editConfGeneratorName = prop.getCustomEntryForm();
@ -247,6 +247,21 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
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) {
Property p = null;
try{

View file

@ -37,6 +37,8 @@ public class ApplicationConfigurationOntologyUtils {
return getAdditionalFauxSubpropertiesForList(propList, displayModel, tboxModel);
}
public static List<ObjectProperty> getAdditionalFauxSubpropertiesForList(List<ObjectProperty> propList,
Model displayModel,
Model tboxModel) {

View file

@ -180,6 +180,7 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
Individual objectIndividual = EditConfigurationUtils.getObjectIndividual(vreq);
ObjectProperty prop = EditConfigurationUtils.getObjectProperty(vreq);
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
VClass rangeClass = EditConfigurationUtils.getRangeVClass(vreq);
if(objectIndividual != null) {
propertyTitle = prop.getDomainPublic();
} else {
@ -187,8 +188,9 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
if ( prop.getOfferCreateNewOption() ) {
//Try to get the name of the class to select from
VClass classOfObjectFillers = null;
if( prop.getRangeVClassURI() == null ) {
if (rangeClass != null) {
classOfObjectFillers = rangeClass;
} else if( prop.getRangeVClassURI() == null ) {
// If property has no explicit range, try to get classes
List<VClass> classes = wdf.getVClassDao().getVClassesForProperty(subject.getVClassURI(), prop.getURI());
if( classes == null || classes.size() == 0 || classes.get(0) == null ){
@ -515,12 +517,23 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
Individual sub =
wdf.getIndividualDao().getIndividualByURI(editConfig.getSubjectUri());
VClass rangeClass = EditConfigurationUtils.getRangeVClass(vreq);
List<VClass> vclasses = null;
List<VClass> subjectVClasses = sub.getVClasses();
if( subjectVClasses == null ) {
vclasses = wdf.getVClassDao().getAllVclasses();
}
else {
} 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 {
//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
HashSet<String> vclassesURIs = new HashSet<String>();