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: * Register a listener to the models needed to get changes to:
* class membership * Basic abox statemetns:
* inferred class membership * abox object property statements
* class group membership, * abox data property statements
* object properties, * abox rdf:type statements
* data properties, * inferred types of individuals in abox
* inferred object properties, * class group membership of individuals in abox
* rdfs:label annotations * rdfs:labe annotations of things in abox.
* This listener does not need: *
* other annotations * Basic application annotations:
* change to TBox * 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){ public static void registerListenerForChanges(ServletContext ctx, ModelChangedListener ml){
ModelContext.getJenaOntModel(ctx).register(ml); ModelContext.getJenaOntModel(ctx).register(ml);
@ -97,6 +101,9 @@ public class ModelContext {
ModelContext.getBaseOntModelSelector(ctx).getABoxModel().register(ml); ModelContext.getBaseOntModelSelector(ctx).getABoxModel().register(ml);
ModelContext.getBaseOntModelSelector(ctx).getApplicationMetadataModel().register(ml); ModelContext.getBaseOntModelSelector(ctx).getApplicationMetadataModel().register(ml);
ModelContext.getInferenceOntModelSelector(ctx).getABoxModel().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.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
@ -17,9 +16,13 @@ import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.listeners.StatementListener;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.Statement; 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.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
@ -316,7 +319,7 @@ public class VClassGroupCache {
checkAndDoUpdate(stmt); checkAndDoUpdate(stmt);
} }
private void checkAndDoUpdate(Statement stmt) { protected void checkAndDoUpdate(Statement stmt) {
if (stmt == null) if (stmt == null)
return; return;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -325,11 +328,28 @@ public class VClassGroupCache {
} }
if (RDF.type.getURI().equals(stmt.getPredicate().getURI())) { if (RDF.type.getURI().equals(stmt.getPredicate().getURI())) {
requestCacheUpdate(); requestCacheUpdate();
} else if (VitroVocabulary.IN_CLASSGROUP.equals(stmt.getPredicate() } else if (VitroVocabulary.IN_CLASSGROUP.equals(stmt.getPredicate().getURI())) {
.getURI())) {
requestCacheUpdate(); requestCacheUpdate();
} else if(VitroVocabulary.DISPLAY_RANK.equals(stmt.getPredicate().getURI())){ } else if(VitroVocabulary.DISPLAY_RANK.equals(stmt.getPredicate().getURI())){
requestCacheUpdate(); 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;
} }
} }
} }