merging IndividualJena overrides into trunk
This commit is contained in:
parent
7b58a73c67
commit
7931113259
1 changed files with 77 additions and 0 deletions
|
@ -22,6 +22,8 @@ import org.joda.time.DateTime;
|
|||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntResource;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.rdf.model.NodeIterator;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
|
@ -39,6 +41,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Keyword;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.Link;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
|
@ -646,6 +649,80 @@ public class IndividualJena extends IndividualImpl implements Individual {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ObjectPropertyStatement> getObjectPropertyStatements(String propertyURI) {
|
||||
if (propertyURI == null) {
|
||||
return null;
|
||||
}
|
||||
List<ObjectPropertyStatement> objectPropertyStatements = new ArrayList<ObjectPropertyStatement>();
|
||||
ind.getOntModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
StmtIterator sit = ind.listProperties(ind.getModel().getProperty(propertyURI));
|
||||
while (sit.hasNext()) {
|
||||
Statement s = sit.nextStatement();
|
||||
if (!s.getSubject().canAs(OntResource.class) || !s.getObject().canAs(OntResource.class)) {
|
||||
continue;
|
||||
}
|
||||
Individual subj = new IndividualJena((OntResource) s.getSubject().as(OntResource.class), webappDaoFactory);
|
||||
Individual obj = new IndividualJena((OntResource) s.getObject().as(OntResource.class), webappDaoFactory);
|
||||
ObjectProperty op = webappDaoFactory.getObjectPropertyDao().getObjectPropertyByURI(s.getPredicate().getURI());
|
||||
if (subj != null && obj != null && op != null) {
|
||||
ObjectPropertyStatement ops = new ObjectPropertyStatementImpl();
|
||||
ops.setSubject(subj);
|
||||
ops.setSubjectURI(subj.getURI());
|
||||
ops.setObject(obj);
|
||||
ops.setObjectURI(obj.getURI());
|
||||
ops.setProperty(op);
|
||||
ops.setPropertyURI(op.getURI());
|
||||
objectPropertyStatements.add(ops);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
ind.getOntModel().leaveCriticalSection();
|
||||
}
|
||||
return objectPropertyStatements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Individual> getRelatedIndividuals(String propertyURI) {
|
||||
if (propertyURI == null) {
|
||||
return null;
|
||||
}
|
||||
List<Individual> relatedIndividuals = new ArrayList<Individual>();
|
||||
ind.getOntModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
NodeIterator values = ind.listPropertyValues(ind.getModel().getProperty(propertyURI));
|
||||
while (values.hasNext()) {
|
||||
RDFNode value = values.nextNode();
|
||||
if (value.canAs(OntResource.class)) {
|
||||
relatedIndividuals.add(
|
||||
new IndividualJena((OntResource) value.as(OntResource.class), webappDaoFactory) );
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
ind.getOntModel().leaveCriticalSection();
|
||||
}
|
||||
return relatedIndividuals;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Individual getRelatedIndividual(String propertyURI) {
|
||||
if (propertyURI == null) {
|
||||
return null;
|
||||
}
|
||||
ind.getOntModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
RDFNode value = ind.getPropertyValue(ind.getModel().getProperty(propertyURI));
|
||||
if (value != null && value.canAs(OntResource.class)) {
|
||||
return new IndividualJena((OntResource) value.as(OntResource.class), webappDaoFactory);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} finally {
|
||||
ind.getOntModel().leaveCriticalSection();
|
||||
}
|
||||
}
|
||||
|
||||
public List<ObjectProperty> getObjectPropertyList() {
|
||||
if (this.propertyList != null) {
|
||||
return this.propertyList;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue