VClassGroupCache will rebuild on change of class membership in vclassgroup. NIHVIVO-2925

This commit is contained in:
briancaruso 2011-07-15 18:23:45 +00:00
parent 7590dccf88
commit 414b84c2ad
2 changed files with 42 additions and 15 deletions

View file

@ -78,16 +78,20 @@ public class ModelContext {
/**
* Register a listener to the models needed to get changes to:
* class membership
* inferred class membership
* class group membership,
* object properties,
* data properties,
* inferred object properties,
* rdfs:label annotations
* This listener does not need:
* other annotations
* change to TBox
* Basic abox statemetns:
* abox object property statements
* abox data property statements
* abox rdf:type statements
* inferred types of individuals in abox
* class group membership of individuals in abox
* rdfs:labe annotations of things in abox.
*
* Basic application annotations:
* changes to annotations on classes
* changes to annotations on class gorups
* changes to annotations on properties
*
* Changes to application model
*/
public static void registerListenerForChanges(ServletContext ctx, ModelChangedListener ml){
ModelContext.getJenaOntModel(ctx).register(ml);
@ -97,6 +101,9 @@ public class ModelContext {
ModelContext.getBaseOntModelSelector(ctx).getABoxModel().register(ml);
ModelContext.getBaseOntModelSelector(ctx).getApplicationMetadataModel().register(ml);
ModelContext.getInferenceOntModelSelector(ctx).getABoxModel().register(ml);
ModelContext.getBaseOntModelSelector(ctx).getTBoxModel().register(ml);
}
}

View file

@ -8,7 +8,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
@ -17,9 +16,13 @@ import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.listeners.StatementListener;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
@ -307,7 +310,7 @@ public class VClassGroupCache {
}
/* ****************** Jena Model Change Listener***************************** */
private class VClassGroupCacheChangeListener extends StatementListener {
private class VClassGroupCacheChangeListener extends StatementListener {
public void addedStatement(Statement stmt) {
checkAndDoUpdate(stmt);
}
@ -316,7 +319,7 @@ public class VClassGroupCache {
checkAndDoUpdate(stmt);
}
private void checkAndDoUpdate(Statement stmt) {
protected void checkAndDoUpdate(Statement stmt) {
if (stmt == null)
return;
if (log.isDebugEnabled()) {
@ -325,11 +328,28 @@ public class VClassGroupCache {
}
if (RDF.type.getURI().equals(stmt.getPredicate().getURI())) {
requestCacheUpdate();
} else if (VitroVocabulary.IN_CLASSGROUP.equals(stmt.getPredicate()
.getURI())) {
} else if (VitroVocabulary.IN_CLASSGROUP.equals(stmt.getPredicate().getURI())) {
requestCacheUpdate();
} else if(VitroVocabulary.DISPLAY_RANK.equals(stmt.getPredicate().getURI())){
requestCacheUpdate();
} else if( isVClassGroupNameChange(stmt) ) {
requestCacheUpdate();
}
}
protected boolean isVClassGroupNameChange(Statement stmt) {
// Check if the stmt is a rdfs:label change and that the
// subject is a VClassGroup.
if( RDFS.label.equals( stmt.getPredicate() )) {
OntModel jenaOntModel = ModelContext.getJenaOntModel(context);
jenaOntModel.enterCriticalSection(Lock.READ);
try{
return jenaOntModel.contains(stmt.getSubject(), RDF.type, ResourceFactory.createResource(VitroVocabulary.CLASSGROUP));
}finally{
jenaOntModel.leaveCriticalSection();
}
}else{
return false;
}
}
}