Cleanup of IndividualSDB: break long lines, remove commented code

This commit is contained in:
bjl23 2010-12-14 17:55:42 +00:00
parent fc1754db3c
commit 8e0fbcab09

View file

@ -65,7 +65,8 @@ import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
public class IndividualSDB extends IndividualImpl implements Individual { public class IndividualSDB extends IndividualImpl implements Individual {
private static final Log log = LogFactory.getLog(IndividualSDB.class.getName()); private static final Log log = LogFactory.getLog(
IndividualSDB.class.getName());
private OntResource ind = null; private OntResource ind = null;
private WebappDaoFactoryJena webappDaoFactory = null; private WebappDaoFactoryJena webappDaoFactory = null;
private Float _searchBoostJena = null; private Float _searchBoostJena = null;
@ -74,7 +75,9 @@ public class IndividualSDB extends IndividualImpl implements Individual {
private String individualURI = null; private String individualURI = null;
private Model model = null; private Model model = null;
public IndividualSDB(String individualURI, DatasetWrapperFactory datasetWrapperFactory, WebappDaoFactoryJena wadf, Model initModel) { public IndividualSDB(String individualURI,
DatasetWrapperFactory datasetWrapperFactory,
WebappDaoFactoryJena wadf, Model initModel) {
this.individualURI = individualURI; this.individualURI = individualURI;
this.dwf = datasetWrapperFactory; this.dwf = datasetWrapperFactory;
@ -82,21 +85,28 @@ public class IndividualSDB extends IndividualImpl implements Individual {
initModel.getLock().enterCriticalSection(Lock.READ); initModel.getLock().enterCriticalSection(Lock.READ);
String getStatements = String getStatements =
"CONSTRUCT \n" + "CONSTRUCT \n" +
"{ <"+individualURI+"> <" + RDFS.label.getURI() + "> ?ooo. \n" + "{ <"+individualURI+"> <" + RDFS.label.getURI() +
"> ?ooo. \n" +
"<"+individualURI+"> a ?type . \n" + "<"+individualURI+"> a ?type . \n" +
"<"+individualURI+"> <" + VitroVocabulary.MONIKER + "> ?moniker \n" + "<"+individualURI+"> <" + VitroVocabulary.MONIKER +
"> ?moniker \n" +
"} \n" + "} \n" +
"WHERE { \n" + "WHERE { \n" +
"{ <"+individualURI+"> <" + RDFS.label.getURI() + "> ?ooo } \n" + "{ <"+individualURI+"> <" + RDFS.label.getURI() +
"> ?ooo } \n" +
" UNION { <"+individualURI+"> a ?type } \n" + " UNION { <"+individualURI+"> a ?type } \n" +
" UNION { <"+individualURI+"> <" + VitroVocabulary.MONIKER + "> ?moniker } \n" + " UNION { <"+individualURI+"> <" + VitroVocabulary.MONIKER +
"> ?moniker } \n" +
"} "; "} ";
this.model = QueryExecutionFactory.create(QueryFactory.create(getStatements), initModel).execConstruct(); this.model = QueryExecutionFactory.create(
QueryFactory.create(getStatements), initModel)
.execConstruct();
} finally { } finally {
initModel.getLock().leaveCriticalSection(); initModel.getLock().leaveCriticalSection();
} }
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model); OntModel ontModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM, model);
this.ind = ontModel.createOntResource(individualURI); this.ind = ontModel.createOntResource(individualURI);
setUpURIParts(ind); setUpURIParts(ind);
this.webappDaoFactory = wadf; this.webappDaoFactory = wadf;
@ -120,23 +130,32 @@ public class IndividualSDB extends IndividualImpl implements Individual {
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
String getStatements = String getStatements =
"CONSTRUCT " + "CONSTRUCT " +
"{ <"+individualURI+"> <" + RDFS.label.getURI() + "> ?ooo. \n" + "{ <"+individualURI+"> <" + RDFS.label.getURI() +
"> ?ooo. \n" +
"<"+individualURI+"> a ?type . \n" + "<"+individualURI+"> a ?type . \n" +
"<"+individualURI+"> <" + VitroVocabulary.MONIKER + "> ?moniker \n" + "<"+individualURI+"> <" + VitroVocabulary.MONIKER +
"> ?moniker \n" +
"} WHERE {" + "} WHERE {" +
"{ GRAPH ?g { \n" + "{ GRAPH ?g { \n" +
"{ <"+individualURI+"> <" + RDFS.label.getURI() + "> ?ooo } \n" + "{ <"+individualURI+"> <" + RDFS.label.getURI() +
"UNION { <"+individualURI+"> <" + VitroVocabulary.MONIKER + "> ?moniker } \n" + "> ?ooo } \n" +
"UNION { <" +
individualURI+"> <" + VitroVocabulary.MONIKER +
"> ?moniker } \n" +
"} \n" + "} \n" +
"} UNION { GRAPH <http://vitro.mannlib.cornell.edu/default/vitro-kb-2> { <"+individualURI+"> a ?type } } \n" + "} UNION { GRAPH <http://vitro.mannlib.cornell.edu/default/vitro-kb-2> { <"
+ individualURI + "> a ?type } } \n" +
"}"; "}";
model = QueryExecutionFactory.create(QueryFactory.create(getStatements), dataset).execConstruct(); model = QueryExecutionFactory.create(
QueryFactory.create(getStatements), dataset)
.execConstruct();
} finally { } finally {
dataset.getLock().leaveCriticalSection(); dataset.getLock().leaveCriticalSection();
w.close(); w.close();
} }
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model); OntModel ontModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM, model);
this.ind = ontModel.createOntResource(individualURI); this.ind = ontModel.createOntResource(individualURI);
} }
@ -266,18 +285,21 @@ public class IndividualSDB extends IndividualImpl implements Individual {
*/ */
public boolean doesFlag1Match(int flagBitMask) { public boolean doesFlag1Match(int flagBitMask) {
Long [] numerics = FlagMathUtils.numeric2numerics(flagBitMask); Long [] numerics = FlagMathUtils.numeric2numerics(flagBitMask);
String Ask = null;
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try{ try{
for( Long numericPortal : numerics){ for( Long numericPortal : numerics){
int portalid = FlagMathUtils.numeric2Portalid(numericPortal); int portalid = FlagMathUtils.numeric2Portalid(numericPortal);
String portalTypeUri = VitroVocabulary.vitroURI + "Flag1Value" + portalid + "Thing"; String portalTypeUri = VitroVocabulary.vitroURI +
Ask = "ASK { GRAPH ?g { <" + this.individualURI + "> <" +RDF.type+ "> <" + portalTypeUri +">} }"; "Flag1Value" + portalid + "Thing";
if(!QueryExecutionFactory.create(QueryFactory.create(Ask), dataset).execAsk()) String Ask = "ASK { GRAPH ?g { <" + this.individualURI +
"> <" +RDF.type+ "> <" + portalTypeUri +">} }";
if(!QueryExecutionFactory.create(
QueryFactory.create(Ask), dataset).execAsk()) {
return false; return false;
} }
}
}finally{ }finally{
dataset.getLock().leaveCriticalSection(); dataset.getLock().leaveCriticalSection();
w.close(); w.close();
@ -288,7 +310,8 @@ public class IndividualSDB extends IndividualImpl implements Individual {
private void doFlag1() { private void doFlag1() {
String getObjects = null; String getObjects = null;
Model tempModel = ModelFactory.createDefaultModel(); Model tempModel = ModelFactory.createDefaultModel();
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel ontModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM);
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
@ -298,19 +321,29 @@ public class IndividualSDB extends IndividualImpl implements Individual {
String portalSet = ""; String portalSet = "";
try{ try{
getObjects = getObjects =
"CONSTRUCT{<" + this.individualURI + "> <" + RDF.type + "> ?object}" + "CONSTRUCT{<" + this.individualURI + "> <" +
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + RDF.type + "> ?object} }"; RDF.type + "> ?object}" +
tempModel = QueryExecutionFactory.create(QueryFactory.create(getObjects), dataset).execConstruct(); "WHERE{ GRAPH ?g { <" + this.individualURI + "> <" +
RDF.type + "> ?object} }";
tempModel = QueryExecutionFactory.create(
QueryFactory.create(
getObjects), dataset).execConstruct();
ontModel.add(tempModel.listStatements()); ontModel.add(tempModel.listStatements());
OntResource ontRes = ontModel.createOntResource(this.individualURI); OntResource ontRes = ontModel.createOntResource(
typeIt = ontRes.getOntModel().listStatements(ontRes, RDF.type ,(String) null); this.individualURI);
typeIt = ontRes.getOntModel().listStatements(
ontRes, RDF.type ,(String) null);
while (typeIt.hasNext()) { while (typeIt.hasNext()) {
Statement stmt = (Statement) typeIt.next(); Statement stmt = (Statement) typeIt.next();
Resource type = (Resource)stmt.getObject(); Resource type = (Resource)stmt.getObject();
String typeName = type.getLocalName(); String typeName = type.getLocalName();
if(type.getNameSpace() != null && type.getNameSpace().equals(VitroVocabulary.vitroURI) && typeName.indexOf("Flag1Value")==0) { if(type.getNameSpace() != null
&& type.getNameSpace().equals(
VitroVocabulary.vitroURI)
&& typeName.indexOf("Flag1Value")==0) {
try { try {
int portalNumber = Integer.decode(typeName.substring(10,typeName.length()-5)); int portalNumber = Integer.decode(
typeName.substring(10,typeName.length()-5));
portalNumeric = portalNumeric | (1 << portalNumber); portalNumeric = portalNumeric | (1 << portalNumber);
if (portalSet.length() > 0) { if (portalSet.length() > 0) {
portalSet+=","; portalSet+=",";
@ -336,7 +369,8 @@ public class IndividualSDB extends IndividualImpl implements Individual {
private void doFlag2() { private void doFlag2() {
String getObjects = null; String getObjects = null;
Model tempModel = ModelFactory.createDefaultModel(); Model tempModel = ModelFactory.createDefaultModel();
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel ontModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM);
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
@ -345,19 +379,30 @@ public class IndividualSDB extends IndividualImpl implements Individual {
String flagSet = ""; String flagSet = "";
try{ try{
getObjects = getObjects =
"CONSTRUCT{<" + this.individualURI + "> <" + RDF.type + "> ?object}" + "CONSTRUCT{<" + this.individualURI + "> <" +
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + RDF.type + "> ?object} }"; RDF.type + "> ?object}" +
tempModel = QueryExecutionFactory.create(QueryFactory.create(getObjects), dataset).execConstruct(); "WHERE{ GRAPH ?g { <" + this.individualURI + "> <" +
RDF.type + "> ?object} }";
tempModel = QueryExecutionFactory.create(
QueryFactory.create(
getObjects), dataset).execConstruct();
ontModel.add(tempModel.listStatements()); ontModel.add(tempModel.listStatements());
OntResource ontRes = ontModel.createOntResource(this.individualURI); OntResource ontRes = ontModel.createOntResource(
typeIt = ontRes.getOntModel().listStatements(ontRes, RDF.type ,(String) null); this.individualURI);
typeIt = ontRes.getOntModel().listStatements(
ontRes, RDF.type ,(String) null);
while (typeIt.hasNext()) { while (typeIt.hasNext()) {
Statement stmt = (Statement) typeIt.next(); Statement stmt = (Statement) typeIt.next();
Resource type = (Resource)stmt.getObject(); Resource type = (Resource)stmt.getObject();
String typeName = type.getLocalName(); String typeName = type.getLocalName();
if(type.getNameSpace() != null && type.getNameSpace().equals(VitroVocabulary.vitroURI) && typeName.indexOf("Flag2Value")==0) { if(type.getNameSpace() != null
&& type.getNameSpace().equals(
VitroVocabulary.vitroURI)
&& typeName.indexOf("Flag2Value")==0) {
try { try {
String flagValue = ((WebappDaoFactoryJena)webappDaoFactory).getFlag2ClassLabelMap().get(type); String flagValue =
((WebappDaoFactoryJena) webappDaoFactory)
.getFlag2ClassLabelMap().get(type);
if (flagSet.length() > 0) { if (flagSet.length() > 0) {
flagSet+=","; flagSet+=",";
} }
@ -385,7 +430,9 @@ public class IndividualSDB extends IndividualImpl implements Individual {
ind.getOntModel().enterCriticalSection(Lock.READ); ind.getOntModel().enterCriticalSection(Lock.READ);
try { try {
sunrise = webappDaoFactory.getJenaBaseDao().getPropertyDateTimeValue(ind,webappDaoFactory.getJenaBaseDao().SUNRISE); sunrise = webappDaoFactory.getJenaBaseDao()
.getPropertyDateTimeValue(
ind,webappDaoFactory.getJenaBaseDao().SUNRISE);
return sunrise; return sunrise;
} finally { } finally {
@ -401,7 +448,9 @@ public class IndividualSDB extends IndividualImpl implements Individual {
ind.getOntModel().enterCriticalSection(Lock.READ); ind.getOntModel().enterCriticalSection(Lock.READ);
try { try {
sunset = webappDaoFactory.getJenaBaseDao().getPropertyDateTimeValue(ind,webappDaoFactory.getJenaBaseDao().SUNSET); sunset = webappDaoFactory.getJenaBaseDao()
.getPropertyDateTimeValue(
ind,webappDaoFactory.getJenaBaseDao().SUNSET);
return sunset; return sunset;
} finally { } finally {
@ -417,7 +466,9 @@ public class IndividualSDB extends IndividualImpl implements Individual {
ind.getOntModel().enterCriticalSection(Lock.READ); ind.getOntModel().enterCriticalSection(Lock.READ);
try { try {
timekey = webappDaoFactory.getJenaBaseDao().getPropertyDateTimeValue(ind,webappDaoFactory.getJenaBaseDao().TIMEKEY); timekey = webappDaoFactory.getJenaBaseDao()
.getPropertyDateTimeValue(
ind,webappDaoFactory.getJenaBaseDao().TIMEKEY);
return timekey; return timekey;
} finally { } finally {
@ -433,7 +484,9 @@ public class IndividualSDB extends IndividualImpl implements Individual {
ind.getOntModel().enterCriticalSection(Lock.READ); ind.getOntModel().enterCriticalSection(Lock.READ);
try { try {
Date modDate = webappDaoFactory.getJenaBaseDao().getPropertyDateTimeValue(ind,webappDaoFactory.getJenaBaseDao().MODTIME); Date modDate = webappDaoFactory.getJenaBaseDao()
.getPropertyDateTimeValue(
ind,webappDaoFactory.getJenaBaseDao().MODTIME);
if (modDate != null) { if (modDate != null) {
modTime = new Timestamp(modDate.getTime()); modTime = new Timestamp(modDate.getTime());
} }
@ -451,25 +504,39 @@ public class IndividualSDB extends IndividualImpl implements Individual {
} else { } else {
ind.getOntModel().enterCriticalSection(Lock.READ); ind.getOntModel().enterCriticalSection(Lock.READ);
try { try {
moniker = webappDaoFactory.getJenaBaseDao().getPropertyStringValue(ind,webappDaoFactory.getJenaBaseDao().MONIKER); moniker = webappDaoFactory.getJenaBaseDao()
.getPropertyStringValue(
ind,webappDaoFactory.getJenaBaseDao().MONIKER);
if (moniker == null) { if (moniker == null) {
try { try {
// trying to deal with the fact that an entity may have more than 1 VClass // trying to deal with the fact that an entity
// may have more than 1 VClass
List<VClass> clasList = this.getVClasses(true); List<VClass> clasList = this.getVClasses(true);
if (clasList == null || clasList.size() < 2) { if (clasList == null || clasList.size() < 2) {
moniker = getVClass().getName(); moniker = getVClass().getName();
} else { } else {
VClass preferredClass = null; VClass preferredClass = null;
for (VClass clas : clasList) { for (VClass clas : clasList) {
if (clas.getCustomDisplayView() != null && clas.getCustomDisplayView().length()>0) { if (clas.getCustomDisplayView() != null
// arbitrarily deciding that the preferred class (could be >1) is one with a custom view && clas.getCustomDisplayView()
.length()>0) {
// arbitrarily deciding that the
// preferred class (could be >1)
// is one with a custom view
preferredClass = clas; preferredClass = clas;
log.debug("Found direct class ["+clas.getName()+"] with custom view "+clas.getCustomDisplayView()+"; resetting entity vClass to this class"); log.debug("Found direct class [" +
clas.getName() +
"] with custom view " +
clas.getCustomDisplayView() +
"; resetting entity vClass " +
"to this class");
} }
} }
if (preferredClass == null) { if (preferredClass == null) {
// no basis for selecting a preferred class name to use // no basis for selecting a preferred
moniker = null; // was this.getVClass().getName(); // class name to use
moniker = null;
// was this.getVClass().getName();
} else { } else {
preferredClass.getName(); preferredClass.getName();
} }
@ -478,75 +545,11 @@ public class IndividualSDB extends IndividualImpl implements Individual {
} }
return moniker; return moniker;
} finally { } finally {
ind.getOntModel().leaveCriticalSection(); ind.getOntModel().leaveCriticalSection();
} }
} }
} }
/* 2009-01-27 hold off on individual-level filtering for now
@Override
public RoleLevel getHiddenFromDisplayBelowRoleLevel(){
if( this.hiddenFromDisplayBelowRoleLevel != null )
return this.hiddenFromDisplayBelowRoleLevel;
OntModel model = ind.getOntModel();
model.enterCriticalSection(Lock.READ);
try {
NodeIterator it = model.listObjectsOfProperty(ind, model.getAnnotationProperty(VitroVocabulary.HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT));
if( it == null )
return BaseResourceBean.RoleLevel.values()[0];
BaseResourceBean.RoleLevel role = BaseResourceBean.RoleLevel.values()[0];
while( it.hasNext() ) {
RDFNode node = it.nextNode();
if( node != null && node.isURIResource() ) {
BaseResourceBean.RoleLevel foundRole = BaseResourceBean.RoleLevel.getRoleByUri( node.asNode().getURI() );
if( role.compareTo(foundRole ) < 0 ) { // find the lowest of all levels
role = foundRole;
}
}
}
return this.hiddenFromDisplayBelowRoleLevel = role;
} finally {
model.leaveCriticalSection();
}
}
/**
* this seems like a mismatch with the RDF storage model.
* We could have multiple statements in the model that associated
* the individual with multiple or redundant edit display levels.
*/
/*
@Override
public RoleLevel getProhibitedFromUpdateBelowRoleLevel() {
if( this.prohibitedFromUpdateBelowRoleLevel != null )
return this.prohibitedFromUpdateBelowRoleLevel;
OntModel model = ind.getOntModel();
model.enterCriticalSection(Lock.READ);
try {
NodeIterator it = model.listObjectsOfProperty(ind, model.getAnnotationProperty(VitroVocabulary.PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT));
if( it == null )
return BaseResourceBean.RoleLevel.values()[0];
BaseResourceBean.RoleLevel role = BaseResourceBean.RoleLevel.values()[0];
while( it.hasNext() ){
RDFNode node = it.nextNode();
if( node != null && node.isURIResource() ) {
BaseResourceBean.RoleLevel foundRole = BaseResourceBean.RoleLevel.getRoleByUri( node.asNode().getURI() );
if( role.compareTo(foundRole ) < 0 ) // find the lowest of all roles
role = foundRole;
}
}
return this.prohibitedFromUpdateBelowRoleLevel = role;
} finally {
model.leaveCriticalSection();
}
}
*/
public String getBlurb() { public String getBlurb() {
if (this.blurb != null) { if (this.blurb != null) {
return blurb; return blurb;
@ -570,7 +573,9 @@ public class IndividualSDB extends IndividualImpl implements Individual {
ind.getOntModel().enterCriticalSection(Lock.READ); ind.getOntModel().enterCriticalSection(Lock.READ);
try { try {
description = webappDaoFactory.getJenaBaseDao().getPropertyStringValue(ind,webappDaoFactory.getJenaBaseDao().DESCRIPTION); description = webappDaoFactory.getJenaBaseDao()
.getPropertyStringValue(
ind,webappDaoFactory.getJenaBaseDao().DESCRIPTION);
return description; return description;
} finally { } finally {
@ -586,14 +591,18 @@ public class IndividualSDB extends IndividualImpl implements Individual {
}else{ }else{
String getPropertyValue = String getPropertyValue =
"SELECT ?value" + "SELECT ?value" +
"WHERE { GRAPH ?g { <" + individualURI + ">" + webappDaoFactory.getJenaBaseDao().SEARCH_BOOST_ANNOT + "?value} }"; "WHERE { GRAPH ?g { <" + individualURI + ">" +
webappDaoFactory.getJenaBaseDao().SEARCH_BOOST_ANNOT +
"?value} }";
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try{ try{
try { try {
searchBoost = searchBoost =
((Literal)QueryExecutionFactory.create(QueryFactory.create(getPropertyValue), dataset).execSelect()).getFloat(); ((Literal)QueryExecutionFactory.create(
QueryFactory.create(getPropertyValue), dataset)
.execSelect()).getFloat();
} catch (Exception e) { } catch (Exception e) {
searchBoost = null; searchBoost = null;
} }
@ -624,7 +633,8 @@ public class IndividualSDB extends IndividualImpl implements Individual {
@Override @Override
public String getImageUrl() { public String getImageUrl() {
if (this.imageInfo == null) { if (this.imageInfo == null) {
this.imageInfo = ImageInfo.instanceFromEntityUri(webappDaoFactory, this); this.imageInfo = ImageInfo.instanceFromEntityUri(
webappDaoFactory, this);
log.trace("figured imageInfo for " + getURI() + ": '" log.trace("figured imageInfo for " + getURI() + ": '"
+ this.imageInfo + "'"); + this.imageInfo + "'");
} }
@ -638,7 +648,8 @@ public class IndividualSDB extends IndividualImpl implements Individual {
@Override @Override
public String getThumbUrl() { public String getThumbUrl() {
if (this.imageInfo == null) { if (this.imageInfo == null) {
this.imageInfo = ImageInfo.instanceFromEntityUri(webappDaoFactory, this); this.imageInfo = ImageInfo.instanceFromEntityUri(
webappDaoFactory, this);
log.trace("figured imageInfo for " + getURI() + ": '" log.trace("figured imageInfo for " + getURI() + ": '"
+ this.imageInfo + "'"); + this.imageInfo + "'");
} }
@ -715,7 +726,8 @@ public class IndividualSDB extends IndividualImpl implements Individual {
try { try {
webappDaoFactory.getLinksDao().addLinksToIndividual(this); webappDaoFactory.getLinksDao().addLinksToIndividual(this);
} catch (Exception e) { } catch (Exception e) {
log.debug(this.getClass().getName()+" could not addLinksToIndividual for "+this.getURI()); log.debug(this.getClass().getName() +
" could not addLinksToIndividual for " + this.getURI());
} }
return this.linksList; return this.linksList;
} }
@ -728,7 +740,9 @@ public class IndividualSDB extends IndividualImpl implements Individual {
try { try {
webappDaoFactory.getLinksDao().addPrimaryLinkToIndividual(this); webappDaoFactory.getLinksDao().addPrimaryLinkToIndividual(this);
} catch (Exception e) { } catch (Exception e) {
log.debug(this.getClass().getName()+" could not addPrimaryLinkToIndividual for "+this.getURI()); log.debug(this.getClass().getName() +
" could not addPrimaryLinkToIndividual for " +
this.getURI());
} }
return this.primaryLink; return this.primaryLink;
} }
@ -740,9 +754,11 @@ public class IndividualSDB extends IndividualImpl implements Individual {
return this.keywords; return this.keywords;
} else { } else {
try { try {
this.setKeywords(webappDaoFactory.getIndividualDao().getKeywordsForIndividual(this.getURI())); this.setKeywords(webappDaoFactory.getIndividualDao()
.getKeywordsForIndividual(this.getURI()));
} catch (Exception e) { } catch (Exception e) {
log.debug(this.getClass().getName()+" could not getKeywords for "+this.getURI()); log.debug(this.getClass().getName() +
" could not getKeywords for " + this.getURI());
} }
return this.keywords; return this.keywords;
} }
@ -753,9 +769,11 @@ public class IndividualSDB extends IndividualImpl implements Individual {
return this.keywordObjects; return this.keywordObjects;
} else { } else {
try { try {
this.setKeywordObjects(webappDaoFactory.getIndividualDao().getKeywordObjectsForIndividual(this.getURI())); this.setKeywordObjects(webappDaoFactory.getIndividualDao()
.getKeywordObjectsForIndividual(this.getURI()));
} catch (Exception e) { } catch (Exception e) {
log.error(this.getClass().getName()+" could not get Keyword Objects for "+this.getURI()); log.error(this.getClass().getName() +
" could not get Keyword Objects for " + this.getURI());
} }
} }
return this.keywordObjects; return this.keywordObjects;
@ -766,14 +784,12 @@ public class IndividualSDB extends IndividualImpl implements Individual {
return this.objectPropertyStatements; return this.objectPropertyStatements;
} else { } else {
try { try {
webappDaoFactory.getObjectPropertyStatementDao().fillExistingObjectPropertyStatements(this); webappDaoFactory.getObjectPropertyStatementDao()
//Iterator stmtIt = this.getObjectPropertyStatements().iterator(); .fillExistingObjectPropertyStatements(this);
//while (stmtIt.hasNext()) {
// ObjectPropertyStatement stmt = (ObjectPropertyStatement) stmtIt.next();
// stmt.setObject(webappDaoFactory.getIndividualDao().getIndividualByURI(stmt.getObject().getURI()));
//}
} catch (Exception e) { } catch (Exception e) {
log.error(this.getClass().getName()+" could not fill existing ObjectPropertyStatements for "+this.getURI(), e); log.error(this.getClass().getName() +
" could not fill existing ObjectPropertyStatements for "
+ this.getURI(), e);
} }
return this.objectPropertyStatements; return this.objectPropertyStatements;
} }
@ -784,10 +800,11 @@ public class IndividualSDB extends IndividualImpl implements Individual {
if (propertyURI == null) { if (propertyURI == null) {
return null; return null;
} }
List<ObjectPropertyStatement> objectPropertyStatements = new ArrayList<ObjectPropertyStatement>(); List<ObjectPropertyStatement> objectPropertyStatements = new ArrayList
<ObjectPropertyStatement>();
Model tempModel = ModelFactory.createDefaultModel(); Model tempModel = ModelFactory.createDefaultModel();
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel ontModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM);
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
@ -840,15 +857,21 @@ public class IndividualSDB extends IndividualImpl implements Individual {
try { try {
String valuesOfProperty = String valuesOfProperty =
"SELECT ?object" + "SELECT ?object" +
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + propertyURI + "> ?object} }"; "WHERE{ GRAPH ?g { <" + this.individualURI + "> <" +
ResultSet values = QueryExecutionFactory.create(QueryFactory.create(valuesOfProperty), dataset).execSelect(); propertyURI + "> ?object} }";
ResultSet values = QueryExecutionFactory.create(
QueryFactory.create(valuesOfProperty), dataset)
.execSelect();
QuerySolution result = null; QuerySolution result = null;
while (values.hasNext()) { while (values.hasNext()) {
result = values.next(); result = values.next();
RDFNode value = result.get("object"); RDFNode value = result.get("object");
if (value.canAs(OntResource.class)) { if (value.canAs(OntResource.class)) {
relatedIndividuals.add( relatedIndividuals.add(
new IndividualSDB(((OntResource) value.as(OntResource.class)).getURI(), this.dwf, webappDaoFactory) ); new IndividualSDB(
((OntResource) value.as(OntResource.class))
.getURI(),
this.dwf, webappDaoFactory) );
} }
} }
} finally { } finally {
@ -869,12 +892,16 @@ public class IndividualSDB extends IndividualImpl implements Individual {
try { try {
String valueOfProperty = String valueOfProperty =
"SELECT ?object" + "SELECT ?object" +
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + propertyURI + "> ?object} }"; "WHERE{ GRAPH ?g { <" + this.individualURI + "> <" +
ResultSet results = QueryExecutionFactory.create(QueryFactory.create(valueOfProperty), dataset).execSelect(); propertyURI + "> ?object} }";
ResultSet results = QueryExecutionFactory.create(
QueryFactory.create(valueOfProperty), dataset).execSelect();
QuerySolution result = results.next(); QuerySolution result = results.next();
RDFNode value = result.get("object"); RDFNode value = result.get("object");
if (value != null && value.canAs(OntResource.class)) { if (value != null && value.canAs(OntResource.class)) {
return new IndividualSDB(((OntResource) value.as(OntResource.class)).getURI(), dwf, webappDaoFactory); return new IndividualSDB(
((OntResource) value.as(OntResource.class)).getURI(),
dwf, webappDaoFactory);
} else { } else {
return null; return null;
} }
@ -889,9 +916,11 @@ public class IndividualSDB extends IndividualImpl implements Individual {
return this.propertyList; return this.propertyList;
} else { } else {
try { try {
webappDaoFactory.getObjectPropertyDao().fillObjectPropertiesForIndividual( this ); webappDaoFactory.getObjectPropertyDao()
.fillObjectPropertiesForIndividual( this );
} catch (Exception e) { } catch (Exception e) {
log.error(this.getClass().getName()+" could not fillEntityProperties for "+this.getURI()); log.error(this.getClass().getName() +
" could not fillEntityProperties for " + this.getURI());
} }
return this.propertyList; return this.propertyList;
} }
@ -900,7 +929,8 @@ public class IndividualSDB extends IndividualImpl implements Individual {
@Override @Override
public List<ObjectProperty> getPopulatedObjectPropertyList() { public List<ObjectProperty> getPopulatedObjectPropertyList() {
if (populatedObjectPropertyList == null) { if (populatedObjectPropertyList == null) {
populatedObjectPropertyList = webappDaoFactory.getObjectPropertyDao().getObjectPropertyList(this); populatedObjectPropertyList = webappDaoFactory
.getObjectPropertyDao().getObjectPropertyList(this);
} }
return populatedObjectPropertyList; return populatedObjectPropertyList;
} }
@ -930,9 +960,12 @@ public class IndividualSDB extends IndividualImpl implements Individual {
return this.dataPropertyStatements; return this.dataPropertyStatements;
} else { } else {
try { try {
webappDaoFactory.getDataPropertyStatementDao().fillExistingDataPropertyStatementsForIndividual(this/*,false*/); webappDaoFactory.getDataPropertyStatementDao()
.fillExistingDataPropertyStatementsForIndividual(this);
} catch (Exception e) { } catch (Exception e) {
log.error(this.getClass().getName()+" could not fill existing DataPropertyStatements for "+this.getURI()); log.error(this.getClass().getName() +
" could not fill existing DataPropertyStatements for "
+ this.getURI());
} }
return this.dataPropertyStatements; return this.dataPropertyStatements;
} }
@ -943,9 +976,11 @@ public class IndividualSDB extends IndividualImpl implements Individual {
return this.datatypePropertyList; return this.datatypePropertyList;
} else { } else {
try { try {
webappDaoFactory.getDataPropertyDao().fillDataPropertiesForIndividual( this ); webappDaoFactory.getDataPropertyDao()
.fillDataPropertiesForIndividual( this );
} catch (Exception e) { } catch (Exception e) {
log.error(this.getClass().getName()+" could not fill data properties for "+this.getURI()); log.error(this.getClass().getName() +
" could not fill data properties for " + this.getURI());
} }
return this.datatypePropertyList; return this.datatypePropertyList;
} }
@ -954,7 +989,8 @@ public class IndividualSDB extends IndividualImpl implements Individual {
@Override @Override
public List<DataProperty> getPopulatedDataPropertyList() { public List<DataProperty> getPopulatedDataPropertyList() {
if (populatedDataPropertyList == null) { if (populatedDataPropertyList == null) {
populatedDataPropertyList = webappDaoFactory.getDataPropertyDao().getDataPropertyList(this); populatedDataPropertyList = webappDaoFactory.getDataPropertyDao()
.getDataPropertyList(this);
} }
return populatedDataPropertyList; return populatedDataPropertyList;
} }
@ -980,16 +1016,18 @@ public class IndividualSDB extends IndividualImpl implements Individual {
} }
public List<DataPropertyStatement> getExternalIds() { public List<DataPropertyStatement> getExternalIds() {
// BJL 2007-11-11: need to decide whether we want to use Collections or Lists in our interfaces - we seem to be leaning toward Lists
if (this.externalIds != null) { if (this.externalIds != null) {
return this.externalIds; return this.externalIds;
} else { } else {
try { try {
List<DataPropertyStatement> dpsList = new ArrayList<DataPropertyStatement>(); List<DataPropertyStatement> dpsList =
dpsList.addAll(webappDaoFactory.getIndividualDao().getExternalIds(this.getURI(), null)); new ArrayList<DataPropertyStatement>();
dpsList.addAll(webappDaoFactory.getIndividualDao()
.getExternalIds(this.getURI(), null));
this.externalIds = dpsList; this.externalIds = dpsList;
} catch (Exception e) { } catch (Exception e) {
log.error(this.getClass().getName()+" could not fill external IDs for "+this.getURI()); log.error(this.getClass().getName() +
" could not fill external IDs for " + this.getURI());
} }
return this.externalIds; return this.externalIds;
} }
@ -1027,8 +1065,12 @@ public class IndividualSDB extends IndividualImpl implements Individual {
} }
else { else {
String getTypes = String getTypes =
"CONSTRUCT{ <" + this.individualURI + "> <" + RDF.type + "> ?types }\n" + "CONSTRUCT{ <" + this.individualURI + "> <" + RDF.type +
"WHERE{ GRAPH " + ((true) ? "<http://vitro.mannlib.cornell.edu/default/vitro-kb-2>" : "?g") "> ?types }\n" +
"WHERE{ GRAPH " +
((true)
? "<http://vitro.mannlib.cornell.edu/default/vitro-kb-2>"
: "?g")
+ " { <" + this.individualURI +"> <" +RDF.type+ "> ?types \n" + + " { <" + this.individualURI +"> <" +RDF.type+ "> ?types \n" +
"} } \n"; "} } \n";
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
@ -1137,7 +1179,8 @@ public class IndividualSDB extends IndividualImpl implements Individual {
VClassDao vclassDao = webappDaoFactory.getVClassDao(); VClassDao vclassDao = webappDaoFactory.getVClassDao();
for (VClass vClass : getVClasses(true)) { for (VClass vClass : getVClasses(true)) {
for (String superClassUri: vclassDao.getAllSuperClassURIs(vClass.getURI())) { for (String superClassUri: vclassDao.getAllSuperClassURIs(
vClass.getURI())) {
if (uri.equals(superClassUri)) { if (uri.equals(superClassUri)) {
return true; return true;
} }