diff --git a/src/org/vivoweb/webapp/util/ModelUtils.java b/src/org/vivoweb/webapp/util/ModelUtils.java new file mode 100644 index 00000000..3215d07c --- /dev/null +++ b/src/org/vivoweb/webapp/util/ModelUtils.java @@ -0,0 +1,71 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package org.vivoweb.webapp.util; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; +import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; + + +public class ModelUtils { + + private static final Log log = LogFactory.getLog(ModelUtils.class.getName()); + + private static final String processPropertyURI = "http://vivoweb.org/ontology/core#roleRealizedIn"; + private static final String processPropertyInverseURI = "http://vivoweb.org/ontology/core#realizedRole"; + private static final String nonProcessPropertyURI = "http://vivoweb.org/ontology/core#roleContributesTo"; + private static final String nonProcessPropertyInverseURI = "http://vivoweb.org/ontology/core#ContributingRole"; + + private static Set processClass = new HashSet(); + static { + processClass.add("http://vivoweb.org/ontology/core#Process"); + processClass.add("http://purl.org/NET/c4dm/event.owl#Event"); + processClass.add("http://xmlns.com/foaf/0.1/Agent"); + } + + /* + * Given a class URI that represents the type of entity that a Role + * is in (in, in any of its senses) this method returns the URIs of + * the properties that should use used to relate the Role to the entity. + * + * Note: we may want to change the implementation of this method + * to check whether the target class has both a parent that is a + * BFO Process and a parent that is not a BFO Process and issue + * a warning if so. + */ + public static PropertyURIPair getPropertyForRoleInClass(String classURI, WebappDaoFactory wadf) { + + PropertyURIPair propertyURIPair= null; + + if (classURI == null) { + log.error("input classURI is null"); + return propertyURIPair; + } + + if (wadf == null) { + log.error("input WebappDaoFactory is null"); + return propertyURIPair; + } + + VClassDao vcd = wadf.getVClassDao(); + List superClassURIs = vcd.getSuperClassURIs(classURI, false); + Iterator iter = superClassURIs.iterator(); + + while (iter.hasNext()) { + String superClassURI = iter.next(); + + if (processClass.contains(superClassURI)) { + return new PropertyURIPair(processPropertyURI, processPropertyInverseURI); + } + } + + return new PropertyURIPair(nonProcessPropertyURI, nonProcessPropertyInverseURI); + } +} diff --git a/src/org/vivoweb/webapp/util/PropertyURIPair.java b/src/org/vivoweb/webapp/util/PropertyURIPair.java new file mode 100644 index 00000000..d27782bf --- /dev/null +++ b/src/org/vivoweb/webapp/util/PropertyURIPair.java @@ -0,0 +1,32 @@ + +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package org.vivoweb.webapp.util; + +public class PropertyURIPair { + private String propURI = null; + private String inversePropURI = null; + + public PropertyURIPair(){}; + + public PropertyURIPair(String propURI, String inversePropURI) { + this.propURI = propURI; + this.inversePropURI = inversePropURI; + } + + public String getPropURI() { + return propURI; + } + + public void setPropURI(String propURI) { + this.propURI = propURI; + } + + public String getInversePropURI() { + return inversePropURI; + } + + public void setInversePropURI(String inversePropURI) { + this.inversePropURI = inversePropURI; + } +}