VIVO-946 VIVO-984 Hack out a way of properly filtering faux properties.
This commit is contained in:
parent
ecbda5be7b
commit
89c6627340
10 changed files with 180 additions and 13 deletions
|
@ -104,4 +104,11 @@ public interface Individual extends ResourceBean, Comparable<Individual> {
|
||||||
|
|
||||||
String getSearchSnippet();
|
String getSearchSnippet();
|
||||||
void setSearchSnippet( String snippet );
|
void setSearchSnippet( String snippet );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is crap. It was put in so IndividualFiltering could filter object properties properly,
|
||||||
|
* but what we really need is either: filters have a reference to a webappDaoFactory, or
|
||||||
|
* all ObjectPropertyStatements are resolved when they are created. See VIVO-946 and VIVO-984.
|
||||||
|
*/
|
||||||
|
void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,4 +345,10 @@ public class IndividualImpl extends BaseResourceBean implements Individual, Comp
|
||||||
public boolean hasThumb() {
|
public boolean hasThumb() {
|
||||||
return getThumbUrl() != null && ! getThumbUrl().isEmpty();
|
return getThumbUrl() != null && ! getThumbUrl().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||||
|
// No webappDaoFactory, so nothing to do.
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,23 @@ public interface ObjectPropertyStatementDao {
|
||||||
String rangeUri, String queryString, Set<String> constructQueryStrings,
|
String rangeUri, String queryString, Set<String> constructQueryStrings,
|
||||||
String sortDirection);
|
String sortDirection);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inspect the elements of the statement to see whether it qualifies as a
|
||||||
|
* faux property.
|
||||||
|
*
|
||||||
|
* That is, is there a faux property definition, such that
|
||||||
|
* <ul>
|
||||||
|
* <li>The property URI of this statement is the base URI of the faux
|
||||||
|
* property</li>
|
||||||
|
* <li>One of the VClasses of the subject of this statement is the domain of
|
||||||
|
* the faux property</li>
|
||||||
|
* <li>One of the VClasses of the object of this statement is the range of
|
||||||
|
* the faux property</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* If that is so, then set the domain and range (and the domainURI and
|
||||||
|
* rangeURI) of the property of this statement to match the faux property.
|
||||||
|
*/
|
||||||
|
void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,6 +185,9 @@ public class IndividualFiltering implements Individual {
|
||||||
if (opStmts == null) {
|
if (opStmts == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
for(ObjectPropertyStatement opStmt: opStmts) {
|
||||||
|
_innerIndividual.resolveAsFauxPropertyStatement(opStmt);
|
||||||
|
}
|
||||||
ArrayList<ObjectPropertyStatement> filtered = new ArrayList<ObjectPropertyStatement>();
|
ArrayList<ObjectPropertyStatement> filtered = new ArrayList<ObjectPropertyStatement>();
|
||||||
Filter.filter(opStmts, _filters.getObjectPropertyStatementFilter(), filtered);
|
Filter.filter(opStmts, _filters.getObjectPropertyStatementFilter(), filtered);
|
||||||
return filtered;
|
return filtered;
|
||||||
|
@ -557,4 +560,11 @@ public class IndividualFiltering implements Individual {
|
||||||
public boolean hasThumb() {
|
public boolean hasThumb() {
|
||||||
return _innerIndividual.hasThumb();
|
return _innerIndividual.hasThumb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||||
|
_innerIndividual.resolveAsFauxPropertyStatement(stmt);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec
|
||||||
final ObjectPropertyStatementDao innerObjectPropertyStatementDao;
|
final ObjectPropertyStatementDao innerObjectPropertyStatementDao;
|
||||||
final VitroFilters filters;
|
final VitroFilters filters;
|
||||||
|
|
||||||
|
|
||||||
public ObjectPropertyStatementDaoFiltering(
|
public ObjectPropertyStatementDaoFiltering(
|
||||||
ObjectPropertyStatementDao objectPropertyStatementDao,
|
ObjectPropertyStatementDao objectPropertyStatementDao,
|
||||||
VitroFilters filters) {
|
VitroFilters filters) {
|
||||||
|
@ -36,8 +35,11 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static List<ObjectPropertyStatement> filterAndWrapList(List<ObjectPropertyStatement> list, VitroFilters filters){
|
private List<ObjectPropertyStatement> filterAndWrapList(List<ObjectPropertyStatement> list){
|
||||||
if( ( list ) != null ){
|
if( ( list ) != null ){
|
||||||
|
for (ObjectPropertyStatement stmt: list) {
|
||||||
|
innerObjectPropertyStatementDao.resolveAsFauxPropertyStatement(stmt);
|
||||||
|
}
|
||||||
|
|
||||||
ArrayList<ObjectPropertyStatement> ctemp = new ArrayList<ObjectPropertyStatement>();
|
ArrayList<ObjectPropertyStatement> ctemp = new ArrayList<ObjectPropertyStatement>();
|
||||||
Filter.filter(list,filters.getObjectPropertyStatementFilter(),ctemp);
|
Filter.filter(list,filters.getObjectPropertyStatementFilter(),ctemp);
|
||||||
|
@ -58,25 +60,25 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec
|
||||||
if( ind == null )
|
if( ind == null )
|
||||||
return null;
|
return null;
|
||||||
else{
|
else{
|
||||||
ind.setObjectPropertyStatements( filterAndWrapList( ind.getObjectPropertyStatements(), filters) );
|
ind.setObjectPropertyStatements( filterAndWrapList( ind.getObjectPropertyStatements()) );
|
||||||
return ind;
|
return ind;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ObjectPropertyStatement> getObjectPropertyStatements(ObjectProperty objectProperty) {
|
public List<ObjectPropertyStatement> getObjectPropertyStatements(ObjectProperty objectProperty) {
|
||||||
return filterAndWrapList( innerObjectPropertyStatementDao.getObjectPropertyStatements(objectProperty), filters );
|
return filterAndWrapList( innerObjectPropertyStatementDao.getObjectPropertyStatements(objectProperty) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ObjectPropertyStatement> getObjectPropertyStatements(ObjectProperty objectProperty, int startIndex, int endIndex) {
|
public List<ObjectPropertyStatement> getObjectPropertyStatements(ObjectProperty objectProperty, int startIndex, int endIndex) {
|
||||||
return filterAndWrapList( innerObjectPropertyStatementDao.getObjectPropertyStatements(objectProperty, startIndex, endIndex) ,filters);
|
return filterAndWrapList( innerObjectPropertyStatementDao.getObjectPropertyStatements(objectProperty, startIndex, endIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ObjectPropertyStatement> getObjectPropertyStatements(
|
public List<ObjectPropertyStatement> getObjectPropertyStatements(
|
||||||
ObjectPropertyStatement objPropertyStmt) {
|
ObjectPropertyStatement objPropertyStmt) {
|
||||||
return filterAndWrapList(innerObjectPropertyStatementDao.getObjectPropertyStatements(objPropertyStmt), filters);
|
return filterAndWrapList(innerObjectPropertyStatementDao.getObjectPropertyStatements(objPropertyStmt));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -117,7 +119,7 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec
|
||||||
List<ObjectPropertyStatement> stmtList = new ArrayList<ObjectPropertyStatement>(stmtsToData.keySet());
|
List<ObjectPropertyStatement> stmtList = new ArrayList<ObjectPropertyStatement>(stmtsToData.keySet());
|
||||||
|
|
||||||
// Apply the filters to the list of statements
|
// Apply the filters to the list of statements
|
||||||
List<ObjectPropertyStatement> filteredStatements = filterAndWrapList(stmtList, filters);
|
List<ObjectPropertyStatement> filteredStatements = filterAndWrapList(stmtList);
|
||||||
|
|
||||||
// Get the data associated with the filtered statements out of the map
|
// Get the data associated with the filtered statements out of the map
|
||||||
List<Map<String, String>> filteredData = new ArrayList<Map<String, String>>(filteredStatements.size());
|
List<Map<String, String>> filteredData = new ArrayList<Map<String, String>>(filteredStatements.size());
|
||||||
|
@ -139,6 +141,9 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||||
|
innerObjectPropertyStatementDao.resolveAsFauxPropertyStatement(stmt);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -616,6 +616,10 @@ public class IndividualJena extends IndividualImpl implements Individual {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||||
|
webappDaoFactory.getObjectPropertyStatementDao().resolveAsFauxPropertyStatement(stmt);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1087,5 +1087,9 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||||
|
webappDaoFactory.getObjectPropertyStatementDao().resolveAsFauxPropertyStatement(stmt);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
@ -39,10 +40,12 @@ import com.hp.hpl.jena.sparql.resultset.ResultSetMem;
|
||||||
import com.hp.hpl.jena.util.iterator.ClosableIterator;
|
import com.hp.hpl.jena.util.iterator.ClosableIterator;
|
||||||
import com.hp.hpl.jena.vocabulary.OWL;
|
import com.hp.hpl.jena.vocabulary.OWL;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.FauxProperty;
|
||||||
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.ObjectPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualUpdateEvent;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualUpdateEvent;
|
||||||
|
@ -551,4 +554,102 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this statement qualifies as a faux property, set the range and domain
|
||||||
|
* accordingly.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||||
|
if (stmt == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectProperty prop = obtainObjectPropertyFromStatement(stmt);
|
||||||
|
if (prop == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<FauxProperty> fauxProps = getWebappDaoFactory()
|
||||||
|
.getFauxPropertyDao()
|
||||||
|
.getFauxPropertiesForBaseUri(prop.getURI());
|
||||||
|
if (fauxProps.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Individual subject = obtainSubjectFromStatement(stmt);
|
||||||
|
if (subject == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Individual object = obtainObjectFromStatement(stmt);
|
||||||
|
if (object == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<VClass> subjectTypes = subject.getVClasses();
|
||||||
|
List<VClass> objectTypes = object.getVClasses();
|
||||||
|
for (FauxProperty fauxProp : fauxProps) {
|
||||||
|
VClass subjectType = selectType(subjectTypes,
|
||||||
|
fauxProp.getDomainURI());
|
||||||
|
VClass objectType = selectType(objectTypes, fauxProp.getRangeURI());
|
||||||
|
if (subjectType != null && objectType != null) {
|
||||||
|
prop.setDomainVClass(subjectType);
|
||||||
|
prop.setDomainVClassURI(subjectType.getURI());
|
||||||
|
prop.setRangeVClass(objectType);
|
||||||
|
prop.setRangeVClassURI(objectType.getURI());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ObjectProperty obtainObjectPropertyFromStatement(
|
||||||
|
ObjectPropertyStatement stmt) {
|
||||||
|
ObjectProperty prop = stmt.getProperty();
|
||||||
|
if (prop != null) {
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
String propertyURI = stmt.getPropertyURI();
|
||||||
|
if (propertyURI == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return getWebappDaoFactory().getObjectPropertyDao()
|
||||||
|
.getObjectPropertyByURI(propertyURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Individual obtainSubjectFromStatement(ObjectPropertyStatement stmt) {
|
||||||
|
Individual subject = stmt.getSubject();
|
||||||
|
if (subject != null) {
|
||||||
|
return subject;
|
||||||
|
}
|
||||||
|
String subjectURI = stmt.getSubjectURI();
|
||||||
|
if (subjectURI == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return getWebappDaoFactory().getIndividualDao().getIndividualByURI(
|
||||||
|
subjectURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Individual obtainObjectFromStatement(ObjectPropertyStatement stmt) {
|
||||||
|
Individual object = stmt.getObject();
|
||||||
|
if (object != null) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
String objectURI = stmt.getObjectURI();
|
||||||
|
if (objectURI == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return getWebappDaoFactory().getIndividualDao().getIndividualByURI(
|
||||||
|
objectURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
private VClass selectType(List<VClass> types, String uri) {
|
||||||
|
for (VClass type : types) {
|
||||||
|
if (Objects.equals(type.getURI(), uri)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,6 +208,11 @@ public class IndividualStub implements Individual {
|
||||||
return new ArrayList<VClass>(vClasses);
|
return new ArrayList<VClass>(vClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||||
|
// Nothing to do: no associated webappDaoFactory
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Un-implemented methods
|
// Un-implemented methods
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -501,4 +506,5 @@ public class IndividualStub implements Individual {
|
||||||
"IndividualStub.setRdfsLabel() not implemented.");
|
"IndividualStub.setRdfsLabel() not implemented.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -216,8 +216,9 @@ public class ObjectPropertyStatementDaoStub implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
|
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
|
||||||
String subjectUri, String propertyUri, String objectKey, String domainUri, String rangeUri,
|
String subjectUri, String propertyUri, String objectKey,
|
||||||
String query, Set<String> constructQueries, String sortDir) {
|
String domainUri, String rangeUri, String query,
|
||||||
|
Set<String> constructQueries, String sortDir) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"ObjectPropertyStatementDaoStub.getObjectPropertyStatementsForIndividualByProperty() not implemented.");
|
"ObjectPropertyStatementDaoStub.getObjectPropertyStatementsForIndividualByProperty() not implemented.");
|
||||||
}
|
}
|
||||||
|
@ -229,4 +230,10 @@ public class ObjectPropertyStatementDaoStub implements
|
||||||
"ObjectPropertyStatementDaoStub.getMostSpecificTypesInClassgroupsForIndividual() not implemented.");
|
"ObjectPropertyStatementDaoStub.getMostSpecificTypesInClassgroupsForIndividual() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"ObjectPropertyStatementDaoStub.resolveAsFauxPropertyStatement() not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue