merging in updates for NIHVIVO-1157 from branch 1.1

This commit is contained in:
sjm222 2010-09-24 21:45:55 +00:00
parent 503652796c
commit bbde9a3eb5
3 changed files with 332 additions and 116 deletions

View file

@ -18,32 +18,32 @@ public class VClass extends BaseResourceBean implements Comparable<VClass>
/**
* What this VClass is called
*/
private String myName = null;
protected String myName = null;
public String getName() { return myName; }
public void setName( String name ) { myName = name; }
/**
* An example member of this VClass
*/
private String myExample = null;
protected String myExample = null;
public String getExample() { return myExample; }
public void setExample( String example ) { myExample = example; }
/**
* Information about the type of information expected of a member of this VClass
*/
private String myDescription = null;
protected String myDescription = null;
public String getDescription() { return myDescription; }
public void setDescription( String descr ) { myDescription = descr; }
private String myShortDefinition = null;
protected String myShortDefinition = null;
public String getShortDef() { return myShortDefinition; }
public void setShortDef( String sd ) { myShortDefinition = sd; }
// TODO: [kwg8-08/01/07] What is this for? It seems an entity count is the number of entities of
// this type in the database. Is this the case?
// [bjl23 2007-08-12] Yep. A count of individuals in the class.
private int myEntityCount = -1;
protected int myEntityCount = -1;
// rjy7 Removing deprecation since currently we have no other means to get this value.
// @Deprecated
@ -51,39 +51,39 @@ public class VClass extends BaseResourceBean implements Comparable<VClass>
public void setEntityCount( int ec ) { myEntityCount = ec; }
private int displayLimit = -1;
public int getDisplayLimit() { return displayLimit; }
protected Integer displayLimit = null;
public int getDisplayLimit() { return (displayLimit == null ? -1 : displayLimit); }
public void setDisplayLimit(int displayLimit) { this.displayLimit = displayLimit; }
private String quickEditJsp = null;
protected String quickEditJsp = null;
public String getQuickEditJsp() { return quickEditJsp; }
public void setQuickEditJsp(String quickEditJsp) { this.quickEditJsp = quickEditJsp; }
private int displayRank = -1;
public int getDisplayRank() { return displayRank; }
protected Integer displayRank = null;
public int getDisplayRank() { return (displayLimit == null ? -1 : displayLimit); }
public void setDisplayRank(int displayRank) { this.displayRank = displayRank; }
private String groupURI = null;
protected String groupURI = null;
public String getGroupURI() { return groupURI; }
public void setGroupURI(String groupURI) { this.groupURI = groupURI; }
private VClassGroup group=null;
protected VClassGroup group=null;
public VClassGroup getGroup() { return group; }
public void setGroup(VClassGroup vcg) { group = vcg; }
private String customEntryForm = null;
protected String customEntryForm = null;
public String getCustomEntryForm() { return customEntryForm; }
public void setCustomEntryForm(String s) { this.customEntryForm = s; }
private String customDisplayView = null;
protected String customDisplayView = null;
public String getCustomDisplayView() { return customDisplayView; }
public void setCustomDisplayView(String s) { this.customDisplayView = s; }
private String customShortView = null;
protected String customShortView = null;
public String getCustomShortView() { return customShortView; }
public void setCustomShortView(String s) { this.customShortView = s; }
private String customSearchView = null;
protected String customSearchView = null;
public String getCustomSearchView() { return customSearchView; }
public void setCustomSearchView(String s) { this.customSearchView = s; }

View file

@ -438,7 +438,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
try {
OntClass cls = (OntClass) classIt.next();
if (!cls.isAnon() && !(NONUSER_NAMESPACES.contains(cls.getNameSpace()))) {
classes.add(vClassWebappFromOntClass(cls));
classes.add(new VClassJena(cls,getWebappDaoFactory()));
}
} catch (ClassCastException cce) {
cce.printStackTrace();
@ -536,7 +536,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
try {
OntClass cls = (OntClass) rootIt.next();
if (!cls.isAnon() && cls.getNameSpace() != null && !(NONUSER_NAMESPACES.contains(cls.getNameSpace()))) {
rootClasses.add(vClassWebappFromOntClass(cls));
rootClasses.add(new VClassJena(cls,getWebappDaoFactory()));
}
} catch (ClassCastException e) {}
}
@ -578,7 +578,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
superStmtIt.close();
}
if (root) {
ontologyRootClasses.add(this.vClassWebappFromOntClass(ontClass));
ontologyRootClasses.add(new VClassJena(ontClass,getWebappDaoFactory()));
}
}
}
@ -662,7 +662,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
try {
OntClass cls = getOntClass(getOntModel(),URIStr);
if (cls != null) {
return vClassWebappFromOntClass(cls);
return new VClassJena(cls,getWebappDaoFactory());
} else {
return null;
}
@ -940,102 +940,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
ontModel.leaveCriticalSection();
}
}
private VClass vClassWebappFromOntClass(OntClass cls) {
VClass vcw = new VClass();
getOntModel().enterCriticalSection(Lock.READ);
vcw.setName(getLabelForClass(cls,false,false));
vcw.setLocalNameWithPrefix(getLabelForClass(cls,true,false));
vcw.setPickListName(getLabelForClass(cls,false,true));
try {
if (cls.isAnon()) {
vcw.setNamespace(PSEUDO_BNODE_NS);
vcw.setLocalName(cls.getId().toString());
log.debug("setting local name with prefix to: " + vcw.getLocalNameWithPrefix());
} else {
if (vcw.getName() == null)
vcw.setName("[null]");
vcw.setURI(cls.getURI());
vcw.setNamespace(cls.getNameSpace());
vcw.setLocalName(cls.getLocalName());
}
try {
Resource groupRes = (Resource) cls.getPropertyValue(IN_CLASSGROUP);
if (groupRes != null) {
vcw.setGroupURI(groupRes.getURI());
}
} catch (Exception e) {
log.error("error retrieving vitro:inClassGroup property value for "+cls.getURI());
log.trace(e);
}
vcw.setShortDef(getPropertyStringValue(cls,SHORTDEF));
vcw.setExample(getPropertyStringValue(cls,EXAMPLE_ANNOT));
vcw.setDescription(getPropertyStringValue(cls,DESCRIPTION_ANNOT));
vcw.setDisplayLimit(getPropertyNonNegativeIntValue(cls,DISPLAY_LIMIT));
vcw.setDisplayRank(getPropertyNonNegativeIntValue(cls,DISPLAY_RANK_ANNOT));
vcw.setCustomEntryForm(getPropertyStringValue(cls,PROPERTY_CUSTOMENTRYFORMANNOT));
vcw.setCustomDisplayView(getPropertyStringValue(cls,PROPERTY_CUSTOMDISPLAYVIEWANNOT));
vcw.setCustomShortView(getPropertyStringValue(cls,PROPERTY_CUSTOMSHORTVIEWANNOT));
vcw.setCustomSearchView(getPropertyStringValue(cls,PROPERTY_CUSTOMSEARCHVIEWANNOT));
vcw.setSearchBoost(getPropertyFloatValue(cls,SEARCH_BOOST_ANNOT));
//There might be multiple HIDDEN_FROM_EDIT_DISPLAY_ANNOT properties, only use the highest
StmtIterator it = cls.listProperties(HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT);
BaseResourceBean.RoleLevel hiddenRoleLevel = null;
while( it.hasNext() ){
Statement stmt = it.nextStatement();
RDFNode obj;
if( stmt != null && (obj = stmt.getObject()) != null && obj.isURIResource() ){
Resource res = (Resource)obj.as(Resource.class);
if( res != null && res.getURI() != null ){
BaseResourceBean.RoleLevel roleFromModel = BaseResourceBean.RoleLevel.getRoleByUri(res.getURI());
if( roleFromModel != null &&
(hiddenRoleLevel == null || roleFromModel.compareTo(hiddenRoleLevel) > 0 )){
hiddenRoleLevel = roleFromModel;
}
}
}
}
vcw.setHiddenFromDisplayBelowRoleLevel(hiddenRoleLevel);//this might get set to null
//There might be multiple PROHIBITED_FROM_UPDATE_DISPLAY_ANNOT properties, only use the highest
it = cls.listProperties(PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT);
BaseResourceBean.RoleLevel prohibitedRoleLevel = null;
while( it.hasNext() ){
Statement stmt = it.nextStatement();
RDFNode obj;
if( stmt != null && (obj = stmt.getObject()) != null && obj.isURIResource() ){
Resource res = (Resource)obj.as(Resource.class);
if( res != null && res.getURI() != null ){
BaseResourceBean.RoleLevel roleFromModel = BaseResourceBean.RoleLevel.getRoleByUri(res.getURI());
if( roleFromModel != null &&
(prohibitedRoleLevel == null || roleFromModel.compareTo(prohibitedRoleLevel) > 0 )){
prohibitedRoleLevel = roleFromModel;
}
}
}
}
vcw.setProhibitedFromUpdateBelowRoleLevel(prohibitedRoleLevel);//this might get set to null
// We need a better way of caching the counts. For now I'm only setting 0 for the empty classes, to hide them from the DWR editing
/*
ClosableIterator typeIt = getOntModel().listStatements(null,RDF.type,cls);
try {
if (!typeIt.hasNext()) {
vcw.setEntityCount(0);
}
} finally {
typeIt.close();
}
*/
} finally {
getOntModel().leaveCriticalSection();
}
return vcw;
}
public boolean isSubClassOf(VClass vc1, VClass vc2) {
if (vc1 == null || vc2 == null) {
return false;

View file

@ -0,0 +1,311 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.dao.jena;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.shared.Lock;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
/**
* A Java class representing a lazy loading ontology ("VIVO") class
*
*/
public class VClassJena extends VClass {
private static final Log log = LogFactory.getLog(VClassJena.class.getName());
private OntClass cls = null;
private WebappDaoFactoryJena webappDaoFactory = null;
public VClassJena(OntClass cls, WebappDaoFactoryJena wadf) {
this.cls = cls;
if (cls.isAnon()) {
this.setNamespace(VitroVocabulary.PSEUDO_BNODE_NS);
this.setLocalName(cls.getId().toString());
} else {
this.URI = cls.getURI();
this.namespace = cls.getNameSpace();
this.localName = cls.getLocalName();
}
this.webappDaoFactory = wadf;
}
/**
* What this VClass is called
*/
public String getName() {
if (this.myName != null) {
return myName;
} else {
cls.getOntModel().enterCriticalSection(Lock.READ);
try {
this.myName = webappDaoFactory.getJenaBaseDao().getLabelOrId(cls);
if (this.myName == null) {
this.myName = "[null]";
}
return this.myName;
} finally {
cls.getOntModel().leaveCriticalSection();
}
}
}
/**
* An example member of this VClass
*/
public String getExample() {
if (this.myExample != null) {
return myName;
} else {
cls.getOntModel().enterCriticalSection(Lock.READ);
try {
setExample(webappDaoFactory.getJenaBaseDao().getPropertyStringValue(cls, webappDaoFactory.getJenaBaseDao().EXAMPLE_ANNOT));
return myExample;
} finally {
cls.getOntModel().leaveCriticalSection();
}
}
}
/**
* Information about the type of information expected of a member of this VClass
*/
public String getDescription() {
if (this.myDescription != null) {
return myDescription;
} else {
cls.getOntModel().enterCriticalSection(Lock.READ);
try {
setDescription(webappDaoFactory.getJenaBaseDao().getPropertyStringValue(cls, webappDaoFactory.getJenaBaseDao().DESCRIPTION_ANNOT));
return myDescription;
} finally {
cls.getOntModel().leaveCriticalSection();
}
}
}
public String getShortDef() {
if (this.myShortDefinition != null) {
return myShortDefinition;
} else {
cls.getOntModel().enterCriticalSection(Lock.READ);
try {
setShortDef(webappDaoFactory.getJenaBaseDao().getPropertyStringValue(cls, webappDaoFactory.getJenaBaseDao().SHORTDEF));
return myShortDefinition;
} finally {
cls.getOntModel().leaveCriticalSection();
}
}
}
public int getDisplayLimit() {
if (this.displayLimit != null) {
return displayLimit;
} else {
cls.getOntModel().enterCriticalSection(Lock.READ);
try {
setDisplayLimit(webappDaoFactory.getJenaBaseDao().getPropertyNonNegativeIntValue(cls, webappDaoFactory.getJenaBaseDao().DISPLAY_LIMIT));
return displayLimit;
} finally {
cls.getOntModel().leaveCriticalSection();
}
}
}
public int getDisplayRank() {
if (this.displayRank != null) {
return displayRank;
} else {
cls.getOntModel().enterCriticalSection(Lock.READ);
try {
setDisplayRank(webappDaoFactory.getJenaBaseDao().getPropertyNonNegativeIntValue(cls, webappDaoFactory.getJenaBaseDao().DISPLAY_RANK_ANNOT));
return displayRank;
} finally {
cls.getOntModel().leaveCriticalSection();
}
}
}
public String getGroupURI() {
if (this.groupURI != null) {
return this.groupURI;
} else {
cls.getOntModel().enterCriticalSection(Lock.READ);
try {
Resource groupRes = (Resource) cls.getPropertyValue(webappDaoFactory.getJenaBaseDao().IN_CLASSGROUP);
if (groupRes != null) {
setGroupURI(groupRes.getURI());
}
} catch (Exception e) {
log.error("error retrieving vitro:inClassGroup property value for " + cls.getURI());
log.trace(e);
} finally {
cls.getOntModel().leaveCriticalSection();
}
return this.groupURI;
}
}
public String getCustomEntryForm() {
if (this.customEntryForm != null) {
return this.customEntryForm;
} else {
cls.getOntModel().enterCriticalSection(Lock.READ);
try {
setCustomEntryForm(webappDaoFactory.getJenaBaseDao().getPropertyStringValue(cls, webappDaoFactory.getJenaBaseDao().PROPERTY_CUSTOMENTRYFORMANNOT));
return this.customEntryForm;
} finally {
cls.getOntModel().leaveCriticalSection();
}
}
}
public String getCustomDisplayView() {
if (this.customDisplayView != null) {
return this.customDisplayView;
} else {
cls.getOntModel().enterCriticalSection(Lock.READ);
try {
setCustomEntryForm(webappDaoFactory.getJenaBaseDao().getPropertyStringValue(cls, webappDaoFactory.getJenaBaseDao().PROPERTY_CUSTOMDISPLAYVIEWANNOT));
return this.customDisplayView;
} finally {
cls.getOntModel().leaveCriticalSection();
}
}
}
public String getCustomShortView() {
if (this.customShortView != null) {
return this.customShortView;
} else {
cls.getOntModel().enterCriticalSection(Lock.READ);
try {
setCustomShortView(webappDaoFactory.getJenaBaseDao().getPropertyStringValue(cls, webappDaoFactory.getJenaBaseDao().PROPERTY_CUSTOMSHORTVIEWANNOT));
return this.customShortView;
} finally {
cls.getOntModel().leaveCriticalSection();
}
}
}
public String getCustomSearchView() {
if (this.customSearchView != null) {
return this.customSearchView;
} else {
cls.getOntModel().enterCriticalSection(Lock.READ);
try {
setCustomSearchView(webappDaoFactory.getJenaBaseDao().getPropertyStringValue(cls, webappDaoFactory.getJenaBaseDao().PROPERTY_CUSTOMSEARCHVIEWANNOT));
return this.customSearchView;
} finally {
cls.getOntModel().leaveCriticalSection();
}
}
}
public Float getSearchBoost() {
if (this.searchBoost != null) {
return this.searchBoost;
} else {
cls.getOntModel().enterCriticalSection(Lock.READ);
try {
setSearchBoost(webappDaoFactory.getJenaBaseDao().getPropertyFloatValue(cls, webappDaoFactory.getJenaBaseDao().SEARCH_BOOST_ANNOT));
return this.searchBoost;
} finally {
cls.getOntModel().leaveCriticalSection();
}
}
}
public RoleLevel getHiddenFromDisplayBelowRoleLevel() {
if (this.hiddenFromDisplayBelowRoleLevel != null) {
return this.hiddenFromDisplayBelowRoleLevel;
} else {
cls.getOntModel().enterCriticalSection(Lock.READ);
try {
//There might be multiple HIDDEN_FROM_EDIT_DISPLAY_ANNOT properties, only use the highest
StmtIterator it = cls.listProperties(webappDaoFactory.getJenaBaseDao().HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT);
BaseResourceBean.RoleLevel hiddenRoleLevel = null;
while( it.hasNext() ){
Statement stmt = it.nextStatement();
RDFNode obj;
if( stmt != null && (obj = stmt.getObject()) != null && obj.isURIResource() ){
Resource res = (Resource)obj.as(Resource.class);
if( res != null && res.getURI() != null ){
BaseResourceBean.RoleLevel roleFromModel = BaseResourceBean.RoleLevel.getRoleByUri(res.getURI());
if( roleFromModel != null &&
(hiddenRoleLevel == null || roleFromModel.compareTo(hiddenRoleLevel) > 0 )){
hiddenRoleLevel = roleFromModel;
}
}
}
}
setHiddenFromDisplayBelowRoleLevel(hiddenRoleLevel); //this might get set to null
return this.hiddenFromDisplayBelowRoleLevel;
} finally {
cls.getOntModel().leaveCriticalSection();
}
}
}
public RoleLevel getProhibitedFromUpdateBelowRoleLevel() {
if (this.prohibitedFromUpdateBelowRoleLevel != null) {
return this.prohibitedFromUpdateBelowRoleLevel;
} else {
cls.getOntModel().enterCriticalSection(Lock.READ);
try {
//There might be multiple PROHIBITED_FROM_UPDATE_DISPLAY_ANNOT properties, only use the highest
StmtIterator it = cls.listProperties(webappDaoFactory.getJenaBaseDao().PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT);
BaseResourceBean.RoleLevel prohibitedRoleLevel = null;
while( it.hasNext() ){
Statement stmt = it.nextStatement();
RDFNode obj;
if( stmt != null && (obj = stmt.getObject()) != null && obj.isURIResource() ){
Resource res = (Resource)obj.as(Resource.class);
if( res != null && res.getURI() != null ){
BaseResourceBean.RoleLevel roleFromModel = BaseResourceBean.RoleLevel.getRoleByUri(res.getURI());
if( roleFromModel != null &&
(prohibitedRoleLevel == null || roleFromModel.compareTo(prohibitedRoleLevel) > 0 )){
prohibitedRoleLevel = roleFromModel;
}
}
}
}
setProhibitedFromUpdateBelowRoleLevel(prohibitedRoleLevel); //this might get set to null
return this.prohibitedFromUpdateBelowRoleLevel;
} finally {
cls.getOntModel().leaveCriticalSection();
}
}
}
}