From ec7a7c23a86bef5baf41d46131a43ce7fd49b8f2 Mon Sep 17 00:00:00 2001 From: bdc34 Date: Fri, 2 Jul 2010 00:24:15 +0000 Subject: [PATCH] Adding ability to hide classes in search. NIHVIVO-643. Adding ability to have n3 files in ontology directories. --- .../search/beans/ProhibitedFromSearch.java | 135 ++++++++++++++++++ .../webapp/search/indexing/IndexBuilder.java | 28 +++- .../webapp/search/lucene/LuceneSetup.java | 7 + .../setup/JenaDataSourceSetupBase.java | 18 ++- .../vitro/webapp/web/DisplayVocabulary.java | 51 ++++--- .../beans/ProhibitedFromSearchTest.java | 126 ++++++++++++++++ webapp/web/templates/freemarker/body/home.ftl | 2 +- 7 files changed, 338 insertions(+), 29 deletions(-) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/ProhibitedFromSearch.java create mode 100644 webapp/test/edu/cornell/mannlib/vitro/webapp/search/beans/ProhibitedFromSearchTest.java diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/ProhibitedFromSearch.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/ProhibitedFromSearch.java new file mode 100644 index 000000000..ed40f48e3 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/ProhibitedFromSearch.java @@ -0,0 +1,135 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.search.beans; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryExecution; +import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.QuerySolutionMap; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.listeners.StatementListener; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelChangedListener; +import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.rdf.model.ResourceFactory; +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.web.DisplayVocabulary; + +public class ProhibitedFromSearch { + List prohibitedClasses; + String ProhibitedFromSearchURI; + + private static final String queryForProhibitedClasses = "SELECT ?prohibited WHERE{" + + "?searchConfig <" + DisplayVocabulary.EXCLUDE_CLASS + "> ?prohibited . }"; + + private static final Log log = LogFactory.getLog(ProhibitedFromSearch.class.getName()); + + public ProhibitedFromSearch(String URI, OntModel model){ + this.ProhibitedFromSearchURI = URI; + this.prohibitedClasses = new ArrayList(); + addAllProhibitedClasses( buildProhibitedClassesList(URI,model) ); + model.register(new ProhibitedFromSearchChangeListener( this )); + } + + public synchronized boolean isClassProhibited(String classURI){ + if( classURI != null ){ + return prohibitedClasses.contains(classURI); + }else{ + return false; + } + } + + private synchronized void removeProhibitedClass(String classURI){ + prohibitedClasses.remove(classURI); + } + + private synchronized void addProhibitedClass(String classURI){ + prohibitedClasses.add(classURI); + } + + private synchronized void addAllProhibitedClasses(List classURIs){ + prohibitedClasses.addAll(classURIs); + } + + private List buildProhibitedClassesList( String URI, OntModel model){ + List newProhibitedClasses = new ArrayList(); + + QuerySolutionMap initialBinding = new QuerySolutionMap(); + Resource searchConfig = ResourceFactory.createResource(URI); + initialBinding.add("searchConfig", searchConfig); + + Query query = QueryFactory.create(queryForProhibitedClasses); + model.enterCriticalSection(Lock.READ); + try{ + QueryExecution qExec = QueryExecutionFactory.create(query,model,initialBinding); + try{ + ResultSet results = qExec.execSelect(); + for(;results.hasNext();){ + QuerySolution soln = results.nextSolution(); + RDFNode n = soln.get("prohibited"); + if( n.isResource() && !n.isAnon()){ + newProhibitedClasses.add(((Resource) n).getURI()); + }else{ + log.warn("unexpected node in object position for prohibited classes: " + n.toString()); + } + } + }catch(Throwable t){ + log.error(t,t); + }finally{ qExec.close(); } + }finally{ model.leaveCriticalSection(); } + + return newProhibitedClasses; + } + + private static enum ChangeType { ADD, REMOVE } ; + + class ProhibitedFromSearchChangeListener extends StatementListener { + ProhibitedFromSearch pfs; + + ProhibitedFromSearchChangeListener(ProhibitedFromSearch pfs){ + this.pfs = pfs; + } + + @Override + public void addedStatement(Statement s) { processChange(s,ChangeType.ADD);} + + @Override + public void removedStatement(Statement s) { processChange(s,ChangeType.REMOVE); } + + private void processChange( Statement s, ChangeType add){ + //is it a change to an exclude class property? + if( s != null && s.getPredicate() != null + && s.getPredicate().getURI() != null + && s.getPredicate().getURI().equals(DisplayVocabulary.EXCLUDE_CLASS.getURI())){ + + //is it about this ProhibitedFromSearch? + if( s.getSubject() != null ){ + String subURI = ((Resource) s.getSubject()).getURI() ; + if( subURI != null && subURI.equals( ProhibitedFromSearchURI )){ + if( s.getObject() != null && s.getObject().canAs(Resource.class)){ + String classURI = ((Resource)s.getObject().as(Resource.class)).getURI(); + if( add == ChangeType.ADD ) + pfs.addProhibitedClass(classURI); + else + pfs.removeProhibitedClass(classURI); + } + } + } + } + } + + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java index d8b28f2fc..a1bb928c3 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java @@ -20,11 +20,12 @@ import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.search.IndexingException; import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface; +import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; /** * The IndexBuilder is used to rebuild or update a search index. - * It uses an implementation of a backend through an object that - * implements IndexerIface. An example of a backend is LuceneIndexer. + * It uses an implementation of a back-end through an object that + * implements IndexerIface. An example of a back-end is LuceneIndexer. * * The IndexBuilder implements the EntityChangeListener so it can * be registered for Entity changes from the GenericDB classes. @@ -42,6 +43,7 @@ public class IndexBuilder implements Runnable { List sourceList = new LinkedList(); IndexerIface indexer = null; ServletContext context = null; + ProhibitedFromSearch classesProhibitedFromSearch = null; long lastRun = 0; List changedUris = null; @@ -256,8 +258,17 @@ public class IndexBuilder implements Runnable { return; if( ind.getVClasses() == null || ind.getVClasses().size() < 1 ) return; - - indexer.index(ind, newDoc); + boolean prohibitedClass = false; + if( classesProhibitedFromSearch != null ){ + for( VClass vclass : ind.getVClasses() ){ + if( classesProhibitedFromSearch.isClassProhibited(vclass.getURI()) ){ + prohibitedClass = true; + break; + } + } + } + if( !prohibitedClass ) + indexer.index(ind, newDoc); }catch(Throwable ex){ log.debug("IndexBuilder.indexItem() Error indexing " + ind + "\n" +ex); @@ -317,4 +328,13 @@ public class IndexBuilder implements Runnable { return getAllOfThisTypeIterator(); } } + + public ProhibitedFromSearch getClassesProhibitedFromSearch() { + return classesProhibitedFromSearch; + } + + public void setClassesProhibitedFromSearch( + ProhibitedFromSearch classesProhibitedFromSearch) { + this.classesProhibitedFromSearch = classesProhibitedFromSearch; + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneSetup.java index 918451fc7..182545211 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneSetup.java @@ -30,8 +30,10 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener; +import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.Searcher; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; +import edu.cornell.mannlib.vitro.webapp.web.DisplayVocabulary; /** * Setup objects for lucene searching and indexing. @@ -122,6 +124,11 @@ public class LuceneSetup implements javax.servlet.ServletContextListener { SearchReindexingListener srl = new SearchReindexingListener(baseOntModel, sce.getServletContext()); baseOntModel.getBaseModel().register(srl); jenaOntModel.getBaseModel().register(srl); + + //set the classes that the indexBuilder ignores + OntModel displayOntModel = (OntModel)sce.getServletContext().getAttribute("displayOntModel"); + builder.setClassesProhibitedFromSearch( + new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel)); log.debug("**** End of "+this.getClass().getName()+".contextInitialized()"); } catch (Throwable t) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupBase.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupBase.java index 7c8597bd2..79f501482 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupBase.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupBase.java @@ -136,18 +136,30 @@ public class JenaDataSourceSetupBase { Set paths = ctx.getResourcePaths(path); if (paths != null) { for (String p : paths) { - log.info("Loading ontology file at " + p); + String format = getRdfFormat(p); + log.info("Loading ontology file at " + p + " as format " + format); InputStream ontologyInputStream = ctx.getResourceAsStream(p); try { - model.read(ontologyInputStream, null); + model.read(ontologyInputStream, null, format); log.debug("...successful"); } catch (Throwable t) { - log.error("Failed to load ontology file at '" + p + "'", t); + log.error("Failed to load ontology file at '" + p + "' as format " + format, t); } } } } + private static String getRdfFormat(String filename){ + String defaultformat = "RDF/XML"; + if( filename == null ) + return defaultformat; + else if( filename.endsWith("n3") ) + return "N3"; + else if( filename.endsWith("ttl") ) + return "TURTLE"; + else + return defaultformat; + } /** * If the {@link ConfigurationProperties} has a name for the initial admin * user, create the user and add it to the model. diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/DisplayVocabulary.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/DisplayVocabulary.java index e0343bf58..d53fbd1c2 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/DisplayVocabulary.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/DisplayVocabulary.java @@ -3,7 +3,6 @@ package edu.cornell.mannlib.vitro.webapp.web; import com.hp.hpl.jena.ontology.DatatypeProperty; -import com.hp.hpl.jena.ontology.Individual; import com.hp.hpl.jena.ontology.ObjectProperty; import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntModel; @@ -29,48 +28,58 @@ public class DisplayVocabulary { /**

The namespace of the vocabulary as a resource

*/ public static final Resource NAMESPACE = m_model.createResource( NS ); - public static final ObjectProperty REQUIRES_VALUES = m_model.createObjectProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#requiresValues" ); + public static final ObjectProperty REQUIRES_VALUES = m_model.createObjectProperty( NS + "requiresValues" ); - public static final ObjectProperty TO_PAGE = m_model.createObjectProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#toPage" ); + public static final ObjectProperty TO_PAGE = m_model.createObjectProperty( NS + "toPage" ); + + public static final ObjectProperty EXCLUDE_CLASS = m_model.createObjectProperty( NS + "excludeClass" ); + + public static final ObjectProperty INCLUDE_CLASS = m_model.createObjectProperty( NS + "includeClass" ); /**

Java package and class name. ex edu.cornell.mannlib.vitro.webapps.functions.ExampleFunction

*/ - public static final DatatypeProperty JAVA_CLASS_NAME = m_model.createDatatypeProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#javaClassName" ); + public static final DatatypeProperty JAVA_CLASS_NAME = m_model.createDatatypeProperty( NS + "javaClassName" ); - public static final DatatypeProperty MENU_POSITION = m_model.createDatatypeProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#menuPosition" ); + public static final DatatypeProperty MENU_POSITION = m_model.createDatatypeProperty( NS + "menuPosition" ); - public static final DatatypeProperty PARAMETER_NAME = m_model.createDatatypeProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#parameterName" ); + public static final DatatypeProperty PARAMETER_NAME = m_model.createDatatypeProperty( NS + "parameterName" ); - public static final DatatypeProperty PARAMETER_VALUE = m_model.createDatatypeProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#parameterValue" ); + public static final DatatypeProperty PARAMETER_VALUE = m_model.createDatatypeProperty( NS + "parameterValue" ); - public static final DatatypeProperty REQUIRES_BODY_TEMPLATE = m_model.createDatatypeProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#requiresBodyTemplate" ); + public static final DatatypeProperty REQUIRES_BODY_TEMPLATE = m_model.createDatatypeProperty( NS + "requiresBodyTemplate" ); /**

Values from HttpRequest.getPathInfo() will be mapped to values from urlMapping.

*/ - public static final DatatypeProperty URL_MAPPING = m_model.createDatatypeProperty( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#urlMapping" ); + public static final DatatypeProperty URL_MAPPING = m_model.createDatatypeProperty( NS + "urlMapping" ); + + /**

This represents a menu item or other general navigation item.

*/ - public static final OntClass NAVIGATION_ELEMENT = m_model.createClass( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#NavigationElement" ); + public static final OntClass NAVIGATION_ELEMENT = m_model.createClass( NS + "NavigationElement" ); /**

Class of pages.

*/ - public static final OntClass PAGE = m_model.createClass( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#Page" ); + public static final OntClass PAGE = m_model.createClass( NS + "Page" ); - //public static final Individual EVENTS = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#Events", PAGE ); + /* URIs for some individuals in the dispaly ontology */ + public static final String PRIMARY_LUCENE_INDEX_URI = NS + "PrimaryLuceneIndex"; - //public static final Individual EVENTS_MENU_ITEM = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#EventsMenuItem", NAVIGATION_ELEMENT ); + //public static final Individual EVENTS = m_model.createIndividual( NS + "Events", PAGE ); - //public static final Individual HOME = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#Home", PAGE ); + //public static final Individual EVENTS_MENU_ITEM = m_model.createIndividual( NS + "EventsMenuItem", NAVIGATION_ELEMENT ); - //public static final Individual HOME_MENU_ITEM = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#HomeMenuItem", NAVIGATION_ELEMENT ); + //public static final Individual HOME = m_model.createIndividual( NS + "Home", PAGE ); - //public static final Individual ORGANIZATIONS = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#Organizations", PAGE ); + //public static final Individual HOME_MENU_ITEM = m_model.createIndividual( NS + "HomeMenuItem", NAVIGATION_ELEMENT ); - //public static final Individual ORGANIZATIONS_MENU_ITEM = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#OrganizationsMenuItem", NAVIGATION_ELEMENT ); + //public static final Individual ORGANIZATIONS = m_model.createIndividual( NS + "Organizations", PAGE ); - //public static final Individual PEOPLE = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#People", PAGE ); + //public static final Individual ORGANIZATIONS_MENU_ITEM = m_model.createIndividual( NS + "OrganizationsMenuItem", NAVIGATION_ELEMENT ); - //public static final Individual PEOPLE_MENU_ITEM = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#PeopleMenuItem", NAVIGATION_ELEMENT ); + //public static final Individual PEOPLE = m_model.createIndividual( NS + "People", PAGE ); - //public static final Individual PUBLICATIONS = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#Publications", PAGE ); + //public static final Individual PEOPLE_MENU_ITEM = m_model.createIndividual( NS + "PeopleMenuItem", NAVIGATION_ELEMENT ); + + //public static final Individual PUBLICATIONS = m_model.createIndividual( NS + "Publications", PAGE ); + + //public static final Individual PUBLICATIONS_MENU_ITEM = m_model.createIndividual( NS + "PublicationsMenuItem", NAVIGATION_ELEMENT ); - //public static final Individual PUBLICATIONS_MENU_ITEM = m_model.createIndividual( "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#PublicationsMenuItem", NAVIGATION_ELEMENT ); } diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/beans/ProhibitedFromSearchTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/beans/ProhibitedFromSearchTest.java new file mode 100644 index 000000000..865af4c2d --- /dev/null +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/beans/ProhibitedFromSearchTest.java @@ -0,0 +1,126 @@ +package edu.cornell.mannlib.vitro.webapp.search.beans; + +import java.io.StringReader; + +import org.junit.Assert; +import org.junit.Test; + +import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.ontology.OntModelSpec; +import com.hp.hpl.jena.rdf.model.Literal; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.rdf.model.ResourceFactory; + +import edu.cornell.mannlib.vitro.webapp.web.DisplayVocabulary; + + +public class ProhibitedFromSearchTest { + String SEARCH_CONFIG_URI = "http://example.com/TestSearchConfig"; + String TEST_CLASS = "http://vivoweb.org/ontology/test/bogus#Class5"; + + String n3 = + "@prefix : . \n" + + "@prefix vivo: . \n" + + "@prefix rdf: . \n"+ + "<"+SEARCH_CONFIG_URI+"> rdf:type :ProhibitedFromSearch ;\n" + + " <" + DisplayVocabulary.EXCLUDE_CLASS.getURI() + "> vivo:Class2, vivo:Class3, vivo:Class4, <"+TEST_CLASS+"> .\n" ; + + + + @Test + public void testBuildingProhibited(){ + Model r = ModelFactory.createDefaultModel().read(new StringReader(n3), null, "N3"); + OntModel m = (OntModel) ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); + m.add( r.listStatements() ); + + Assert.assertTrue(m.size() > 4); + ProhibitedFromSearch pfs = new ProhibitedFromSearch( SEARCH_CONFIG_URI , m); + Assert.assertNotNull(pfs.prohibitedClasses); + Assert.assertTrue(pfs.prohibitedClasses.size() == 4); + Assert.assertTrue(pfs.isClassProhibited(TEST_CLASS)); + Assert.assertTrue(!pfs.isClassProhibited("http://someOtherClass.com/test")); + } + + @Test + public void testNotFound(){ + Model r = ModelFactory.createDefaultModel().read(new StringReader(n3), null, "N3"); + OntModel m = (OntModel) ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); + m.add( r.listStatements() ); + + Assert.assertTrue(m.size() > 4); + ProhibitedFromSearch pfs = new ProhibitedFromSearch( "http://NotFound.com/inModel", m); + Assert.assertNotNull(pfs.prohibitedClasses); + Assert.assertTrue(pfs.prohibitedClasses.size() == 0); + Assert.assertTrue(!pfs.isClassProhibited(TEST_CLASS)); + Assert.assertTrue(!pfs.isClassProhibited("http://someOtherClass.com/test")); + } + + + @Test + public void testListener(){ + Model r = ModelFactory.createDefaultModel().read(new StringReader(n3), null, "N3"); + OntModel m = (OntModel) ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); + m.add( r.listStatements() ); + Assert.assertTrue(m.size() > 4); + + ProhibitedFromSearch pfs = new ProhibitedFromSearch( SEARCH_CONFIG_URI , m); + Assert.assertTrue(pfs.prohibitedClasses.size() == 4); + + Resource bougsClass3 = ResourceFactory.createResource("http://example.com/bougsClass3"); + Resource searchConfig = ResourceFactory.createResource(SEARCH_CONFIG_URI); + m.add(searchConfig, DisplayVocabulary.EXCLUDE_CLASS, bougsClass3); + Assert.assertEquals(5, pfs.prohibitedClasses.size()); + + m.remove(searchConfig, DisplayVocabulary.EXCLUDE_CLASS, bougsClass3); + Assert.assertEquals(4, pfs.prohibitedClasses.size()); + + Resource bougsClass4 = ResourceFactory.createResource("http://vivoweb.org/ontology/test/bogus#Class4"); + m.remove(searchConfig, DisplayVocabulary.EXCLUDE_CLASS, bougsClass4); + Assert.assertEquals(3, pfs.prohibitedClasses.size()); + } + + + @Test + public void testListenerAbnormal(){ + Model r = ModelFactory.createDefaultModel().read(new StringReader(n3), null, "N3"); + OntModel m = (OntModel) ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); + m.add( r.listStatements() ); + Assert.assertTrue(m.size() > 4); + + ProhibitedFromSearch pfs = new ProhibitedFromSearch( SEARCH_CONFIG_URI , m); + Assert.assertTrue(pfs.prohibitedClasses.size() == 4); + int originalSize = pfs.prohibitedClasses.size(); + + Literal bogusLiteral = ResourceFactory.createPlainLiteral("some bogus literal"); + Resource searchConfig = ResourceFactory.createResource(SEARCH_CONFIG_URI); + m.add(searchConfig, DisplayVocabulary.EXCLUDE_CLASS, bogusLiteral); + Assert.assertEquals(originalSize, pfs.prohibitedClasses.size()); + m.remove(searchConfig, DisplayVocabulary.EXCLUDE_CLASS, bogusLiteral); + Assert.assertEquals(originalSize, pfs.prohibitedClasses.size()); + + Resource anonRes = ResourceFactory.createResource(); + m.remove(searchConfig, DisplayVocabulary.EXCLUDE_CLASS, anonRes); + Assert.assertEquals(originalSize, pfs.prohibitedClasses.size()); + } + + @Test + public void testPrimaryIndex(){ + String primaryIndexN3 = + "" + + "" + + " . "; + + Model r = ModelFactory.createDefaultModel().read(new StringReader(primaryIndexN3), null, "N3"); + OntModel m = (OntModel) ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); + m.add( r.listStatements() ); + + Assert.assertTrue(m.size() == 1); + ProhibitedFromSearch pfs = new ProhibitedFromSearch( DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, m); + Assert.assertNotNull(pfs.prohibitedClasses); + Assert.assertEquals(1, pfs.prohibitedClasses.size() ); + Assert.assertTrue(pfs.isClassProhibited("http://vivoweb.org/ontology/core#NonAcademic")); + Assert.assertTrue(!pfs.isClassProhibited("http://someOtherClass.com/test")); + } +} diff --git a/webapp/web/templates/freemarker/body/home.ftl b/webapp/web/templates/freemarker/body/home.ftl index 2dc2766a8..d6bd89b13 100644 --- a/webapp/web/templates/freemarker/body/home.ftl +++ b/webapp/web/templates/freemarker/body/home.ftl @@ -1,3 +1,3 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ +<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->

Welcome to VIVO

\ No newline at end of file