Changing individualSDB.getMoniker() in SDB so that it doesn't return a VClass name when the moniker is not in the model

This commit is contained in:
bdc34 2011-02-02 19:52:10 +00:00
parent ddc58f5259
commit bfa9979266

View file

@ -342,121 +342,132 @@ public class IndividualSDB extends IndividualImpl implements Individual {
} }
private void doFlag1() { private void doFlag1() {
String getObjects = null; if( webappDaoFactory.getPortalDao().isSinglePortal() ){
Model tempModel = ModelFactory.createDefaultModel(); flag1Set = "0";
OntModel ontModel = ModelFactory.createOntologyModel( flag1Numeric = 1;
OntModelSpec.OWL_MEM); }else{
DatasetWrapper w = getDatasetWrapper(); String getObjects = null;
Dataset dataset = w.getDataset(); Model tempModel = ModelFactory.createDefaultModel();
dataset.getLock().enterCriticalSection(Lock.READ); OntModel ontModel = ModelFactory.createOntologyModel(
try { OntModelSpec.OWL_MEM);
ClosableIterator typeIt = null; DatasetWrapper w = getDatasetWrapper();
int portalNumeric = 0; Dataset dataset = w.getDataset();
String portalSet = ""; dataset.getLock().enterCriticalSection(Lock.READ);
try{ try {
getObjects = ClosableIterator typeIt = null;
"CONSTRUCT{<" + this.individualURI + "> <" + int portalNumeric = 0;
RDF.type + "> ?object}" + String portalSet = "";
"WHERE{ <" + this.individualURI + "> <" + try{
RDF.type + "> ?object }"; getObjects =
tempModel = QueryExecutionFactory.create( "CONSTRUCT{<" + this.individualURI + "> <" +
QueryFactory.create( RDF.type + "> ?object}" +
getObjects), dataset).execConstruct(); "WHERE{ <" + this.individualURI + "> <" +
ontModel.add(tempModel.listStatements()); RDF.type + "> ?object }";
OntResource ontRes = ontModel.createOntResource( tempModel = QueryExecutionFactory.create(
this.individualURI); QueryFactory.create(
typeIt = ontRes.getOntModel().listStatements( getObjects), dataset).execConstruct();
ontRes, RDF.type ,(String) null); ontModel.add(tempModel.listStatements());
while (typeIt.hasNext()) { OntResource ontRes = ontModel.createOntResource(
Statement stmt = (Statement) typeIt.next(); this.individualURI);
Resource type = (Resource)stmt.getObject(); typeIt = ontRes.getOntModel().listStatements(
String typeName = type.getLocalName(); ontRes, RDF.type ,(String) null);
if(type.getNameSpace() != null while (typeIt.hasNext()) {
&& type.getNameSpace().equals( Statement stmt = (Statement) typeIt.next();
VitroVocabulary.vitroURI) Resource type = (Resource)stmt.getObject();
&& typeName.indexOf("Flag1Value")==0) { String typeName = type.getLocalName();
try { if(type.getNameSpace() != null
int portalNumber = Integer.decode( && type.getNameSpace().equals(
typeName.substring(10,typeName.length()-5)); VitroVocabulary.vitroURI)
portalNumeric = portalNumeric | (1 << portalNumber); && typeName.indexOf("Flag1Value")==0) {
if (portalSet.length() > 0) { try {
portalSet+=","; int portalNumber = Integer.decode(
typeName.substring(10,typeName.length()-5));
portalNumeric = portalNumeric | (1 << portalNumber);
if (portalSet.length() > 0) {
portalSet+=",";
}
portalSet+=Integer.toString(portalNumber);
} catch (Exception e) {
log.warn("could not convert into a " +
"portal id:'" + typeName + "' " + e.getMessage());
} }
portalSet+=Integer.toString(portalNumber);
} catch (Exception e) {
log.error(e,e);
} }
} }
}finally{
if( typeIt != null ) typeIt.close() ;
} }
}finally{ flag1Set = portalSet;
if( typeIt != null ) typeIt.close() ; flag1Numeric = portalNumeric;
} finally {
tempModel.close();
ontModel.close();
dataset.getLock().leaveCriticalSection();
w.close();
} }
flag1Set = portalSet;
flag1Numeric = portalNumeric;
} finally {
tempModel.close();
ontModel.close();
dataset.getLock().leaveCriticalSection();
w.close();
} }
} }
private void doFlag2() { private void doFlag2() {
String getObjects = null; if( webappDaoFactory.getPortalDao().isSinglePortal() ){
Model tempModel = ModelFactory.createDefaultModel(); flag2Set = "";
OntModel ontModel = ModelFactory.createOntologyModel( flag2Numeric = 0 ;
OntModelSpec.OWL_MEM); }else{
DatasetWrapper w = getDatasetWrapper(); String getObjects = null;
Dataset dataset = w.getDataset(); Model tempModel = ModelFactory.createDefaultModel();
dataset.getLock().enterCriticalSection(Lock.READ); OntModel ontModel = ModelFactory.createOntologyModel(
try { OntModelSpec.OWL_MEM);
ClosableIterator typeIt=null; DatasetWrapper w = getDatasetWrapper();
String flagSet = ""; Dataset dataset = w.getDataset();
try{ dataset.getLock().enterCriticalSection(Lock.READ);
getObjects = try {
"CONSTRUCT{<" + this.individualURI + "> <" + ClosableIterator typeIt=null;
RDF.type + "> ?object}" + String flagSet = "";
"WHERE{ <" + this.individualURI + "> <" + try{
RDF.type + "> ?object }"; getObjects =
tempModel = QueryExecutionFactory.create( "CONSTRUCT{<" + this.individualURI + "> <" +
QueryFactory.create( RDF.type + "> ?object}" +
getObjects), dataset).execConstruct(); "WHERE{ <" + this.individualURI + "> <" +
ontModel.add(tempModel.listStatements()); RDF.type + "> ?object }";
OntResource ontRes = ontModel.createOntResource( tempModel = QueryExecutionFactory.create(
this.individualURI); QueryFactory.create(
typeIt = ontRes.getOntModel().listStatements( getObjects), dataset).execConstruct();
ontRes, RDF.type ,(String) null); ontModel.add(tempModel.listStatements());
while (typeIt.hasNext()) { OntResource ontRes = ontModel.createOntResource(
Statement stmt = (Statement) typeIt.next(); this.individualURI);
Resource type = (Resource)stmt.getObject(); typeIt = ontRes.getOntModel().listStatements(
String typeName = type.getLocalName(); ontRes, RDF.type ,(String) null);
if(type.getNameSpace() != null while (typeIt.hasNext()) {
&& type.getNameSpace().equals( Statement stmt = (Statement) typeIt.next();
VitroVocabulary.vitroURI) Resource type = (Resource)stmt.getObject();
&& typeName.indexOf("Flag2Value")==0) { String typeName = type.getLocalName();
try { if(type.getNameSpace() != null
String flagValue = && type.getNameSpace().equals(
((WebappDaoFactoryJena) webappDaoFactory) VitroVocabulary.vitroURI)
.getFlag2ClassLabelMap().get(type); && typeName.indexOf("Flag2Value")==0) {
if (flagSet.length() > 0) { try {
flagSet+=","; String flagValue =
((WebappDaoFactoryJena) webappDaoFactory)
.getFlag2ClassLabelMap().get(type);
if (flagSet.length() > 0) {
flagSet+=",";
}
flagSet+=flagValue;
} catch (Exception e) {
log.error(e,e);
} }
flagSet+=flagValue;
} catch (Exception e) {
log.error(e,e);
} }
} }
}finally{
if( typeIt != null ) typeIt.close() ;
} }
}finally{ flag2Set = flagSet;
if( typeIt != null ) typeIt.close() ; } finally {
tempModel.close();
ontModel.close();
dataset.getLock().leaveCriticalSection();
w.close();
} }
flag2Set = flagSet;
} finally {
tempModel.close();
ontModel.close();
dataset.getLock().leaveCriticalSection();
w.close();
} }
} }
@ -576,45 +587,48 @@ public class IndividualSDB extends IndividualImpl implements Individual {
moniker = webappDaoFactory.getJenaBaseDao() moniker = webappDaoFactory.getJenaBaseDao()
.getPropertyStringValue( .getPropertyStringValue(
ind,webappDaoFactory.getJenaBaseDao().MONIKER); ind,webappDaoFactory.getJenaBaseDao().MONIKER);
if (moniker == null) { //Changing behavior to moniker because it is taking extra time to get the vclass
try { //alternative if the moniker isn't filled out. That time is wasted if the vclass alternative isn't desired.
// trying to deal with the fact that an entity //see NIHVIVO-2001
// may have more than 1 VClass // if (moniker == null) {
List<VClass> clasList = this.getVClasses(true); // try {
if (clasList == null || clasList.size() < 2) { // // trying to deal with the fact that an entity
if( getVClass() != null ) // // may have more than 1 VClass
moniker = getVClass().getName(); // List<VClass> clasList = this.getVClasses(true);
} else { // if (clasList == null || clasList.size() < 2) {
VClass preferredClass = null; // if( getVClass() != null )
for (VClass clas : clasList) { // moniker = getVClass().getName();
if (clas.getCustomDisplayView() != null // } else {
&& clas.getCustomDisplayView() // VClass preferredClass = null;
.length()>0) { // for (VClass clas : clasList) {
// arbitrarily deciding that the // if (clas.getCustomDisplayView() != null
// preferred class (could be >1) // && clas.getCustomDisplayView()
// is one with a custom view // .length()>0) {
preferredClass = clas; // // arbitrarily deciding that the
log.debug("Found direct class [" + // // preferred class (could be >1)
clas.getName() + // // is one with a custom view
"] with custom view " + // preferredClass = clas;
clas.getCustomDisplayView() + // log.debug("Found direct class [" +
"; resetting entity vClass " + // clas.getName() +
"to this class"); // "] with custom view " +
} // clas.getCustomDisplayView() +
} // "; resetting entity vClass " +
if (preferredClass == null) { // "to this class");
// no basis for selecting a preferred // }
// class name to use // }
moniker = null; // if (preferredClass == null) {
// was this.getVClass().getName(); // // no basis for selecting a preferred
} else { // // class name to use
preferredClass.getName(); // moniker = null;
} // // was this.getVClass().getName();
} // } else {
} catch (Exception e) { // preferredClass.getName();
log.error(e,e); // }
} // }
} // } catch (Exception e) {
// log.error(e,e);
// }
// }
return moniker; return moniker;
} finally { } finally {
ind.getOntModel().leaveCriticalSection(); ind.getOntModel().leaveCriticalSection();