diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java index 5f4e7493b..3c7fd9c06 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java @@ -15,6 +15,7 @@ import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; import org.apache.solr.client.solrj.impl.XMLResponseParser; import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.vocabulary.OWL; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; @@ -217,7 +218,7 @@ public class SolrSetup implements javax.servlet.ServletContextListener{ modifiers.add( new NameFields( rdfServiceFactory )); modifiers.add( new NameBoost( 1.2f )); - modifiers.add( new ThumbnailImageURL(jenaOntModel)); + modifiers.add( new ThumbnailImageURL( rdfServiceFactory )); /* try to get context attribute SearchIndexExcludes * and use that as the start of the list of exclude diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/SolrQueryTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/SolrQueryTest.java index f19b9ab4f..62572b4ae 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/SolrQueryTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/SolrQueryTest.java @@ -24,8 +24,8 @@ import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.core.CoreContainer; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.xml.sax.SAXException; @@ -37,10 +37,12 @@ import com.hp.hpl.jena.rdf.model.ResIterator; import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.util.FileManager; +import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceFactorySingle; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel; +import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualToSolrDocument; /** @@ -54,27 +56,37 @@ import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualT * * This code is based on a similar test from the CUL Discovery and Access * integration layer. + * + * All RDF/XML files in webapp/test/testontologies/SolrQueryTestRDF will be + * loaded into the model. */ -public class SolrQueryTest { +public class SolrQueryTest extends AbstractTestClass { /** Key of system property for build directory. */ - static final String buildDirSystemPropertyKey = "vitro.build.dir"; + final static String buildDirSystemPropertyKey = "vitro.build.dir"; /** Solr index to run test queries on. */ static SolrServer solr = null; + /** Container for solr */ + static CoreContainer coreContainer = null; + /** Folder to store the temporary Solr index. */ public static TemporaryFolder solrIndexFolder = null; - + /** * This test needs to load RDF data to use as a * source of individuals to to build documents. * This is relative to the build directory. */ - static final String testRDFDir = - "webapp/test/testontologies/SolrQueryTestData.n3"; + final static String testRDFDir = + "/webapp/test/testontologies/SolrQueryTestRDF"; - @BeforeClass - public static void setup() throws Exception{ + @Before + public void setup() throws Exception{ + //solr makes a lot of output + suppressSysout(); + suppressSyserr(); + File buildDir = findBuildDir(); solrIndexFolder = new TemporaryFolder(); @@ -84,9 +96,20 @@ public class SolrQueryTest { FileUtils.copyDirectory(getSolrTemplateDir(buildDir), tempSolrBase ); solr = setupSolr( tempSolrBase ); - indexRdf( loadTestRDF( buildDir ) ); + indexRdf( loadTestRDF( buildDir ) ); + } + + @After + public void takedown() throws Exception{ + if( coreContainer != null ) + coreContainer.shutdown(); + + restoreOutputStreams(); + + if( solrIndexFolder != null ) + solrIndexFolder.delete(); } - + /** * This will return the directory to use as the Solr * home template directory. @@ -94,7 +117,7 @@ public class SolrQueryTest { * Throws an exception if the directory is not found. * @param buildDir - must not be null, must be the base of the build. */ - private static File getSolrTemplateDir(File buildDir) throws Exception { + private File getSolrTemplateDir(File buildDir) throws Exception { if(buildDir == null || !buildDir.exists() ) throw new Exception("buildDir must not be null"); @@ -108,22 +131,22 @@ public class SolrQueryTest { return solrTemplateDir; } - protected static SolrServer setupSolr(File solrBase) + protected SolrServer setupSolr(File solrBase) throws ParserConfigurationException, IOException, SAXException{ System.setProperty("solr.solr.home", solrBase.getAbsolutePath()); CoreContainer.Initializer initializer = new CoreContainer.Initializer(); - CoreContainer coreContainer = initializer.initialize(); + coreContainer = initializer.initialize(); return new EmbeddedSolrServer(coreContainer, ""); } - private static OntModel loadTestRDF(File buildDir) throws Exception { - String dirname = buildDir.getAbsolutePath() + "/webapp/test/testontologies/solrTestRDF"; - File testRDFDir = new File( dirname ); - assertNotNull("could not find dir " + dirname , testRDFDir); - assertTrue(dirname + " must be a directory." ,testRDFDir.isDirectory()); + private OntModel loadTestRDF(File buildDir) throws Exception { + String dirname = buildDir.getAbsolutePath() + testRDFDir; + File rdfDir = new File( dirname ); + assertNotNull("could not find dir " + dirname , rdfDir); + assertTrue(dirname + " must be a directory." ,rdfDir.isDirectory()); //load all files in test dir. - File[] files = testRDFDir.listFiles(); + File[] files = rdfDir.listFiles(); assertNotNull("no test RDF files found",files); assertTrue("no test RDF files found", files.length > 0 ); @@ -132,9 +155,9 @@ public class SolrQueryTest { InputStream in = FileManager.get().open( file.getAbsolutePath() ); assertNotNull("Could not load file " + file.getAbsolutePath(), in ); try{ - model.read(in,null,"N-TRIPLE"); + model.read(in,null); }catch(Throwable th){ - throw new Exception( "Could not load N-TRIPLE file " + throw new Exception( "Could not load RDF/XML file " + file.getAbsolutePath() , th); } } @@ -147,7 +170,7 @@ public class SolrQueryTest { * or it will throw an exception if none can be found. * @throws Exception */ - private static File findBuildDir() throws Exception { + private File findBuildDir() throws Exception { //First try to find the base directory //of the build in the system properties. @@ -163,7 +186,7 @@ public class SolrQueryTest { //If there is no system property try to //guess the location based on the working directory File f = null; - String[] fallBackBases = {"./","../","../../"}; + String[] fallBackBases = {"","../","../../"}; List attempted = new ArrayList(); for( String base: fallBackBases){ String attemptedDir =base + "solr/homeDirectoryTemplate"; @@ -191,12 +214,15 @@ public class SolrQueryTest { /** Query the RDF, build Solr Documents from results, load them to Solr. */ - private static void indexRdf(OntModel model) throws Exception { + private void indexRdf(OntModel model) throws Exception { RDFServiceModel rdfService = new RDFServiceModel(model); - IndividualToSolrDocument r2d = SolrSetup.setupTransltion(model, - new RDFServiceFactorySingle(rdfService), - null, null); + IndividualToSolrDocument r2d = + SolrSetup.setupTransltion( + model, + model, + new RDFServiceFactorySingle(rdfService), + null, null); WebappDaoFactory wdf = new WebappDaoFactoryJena(model); @@ -210,16 +236,13 @@ public class SolrQueryTest { try { solr.add( doc ); } catch (Exception e) { - System.err.println("Failed adding doc to solr for uri:" + uri); -// System.err.println( IndexingUtilities.toString( doc ) + "\n\n" ); -// System.err.println( IndexingUtilities.prettyFormat( ClientUtils.toXML( doc ) ) ); - throw e; + throw new Exception("Failed adding doc to solr for uri:" + uri, e); } } solr.commit(); } - private static List getURISToIndex(Model model) { + private List getURISToIndex(Model model) { //just return all the URIs in the subject position List uris = new LinkedList(); ResIterator it = model.listSubjects(); @@ -239,58 +262,41 @@ public class SolrQueryTest { } @Test - public void testBronte() throws SolrServerException{ + public void testCorsonSearch() throws SolrServerException{ /* make sure that we have the document in the index before we do anything */ - SolrQuery query = - new SolrQuery().setQuery("id:4696").setParam("qt", "standard"); - - testQueryGetsDocs("Expect to find Bronte document by doc:id 4696", - query,new String[]{ "4696" } ) ; - - query = new SolrQuery().setQuery("bronte"); - testQueryGetsDocs("Expect to find doc:id 4696 when searching for 'bronte'", - query,new String[]{ "4696" } ) ; - - query = new SolrQuery().setQuery( "Selected Bronte\u0308 poems") ; - testQueryGetsDocs("Expect to find doc:id 4696 when searching for 'Selected Bronte\u0308 poems'", - query,new String[]{ "4696" } ) ; - - query = new SolrQuery().setQuery( "\"Selected Bronte\u0308 poems\"") ; - testQueryGetsDocs("Expect to find doc:id 4696 when searching for 'Selected Bronte\u0308 poems' all in quotes", - query,new String[]{ "4696" } ) ; - } - - @AfterClass - public static void down() throws Exception{ - if( solrIndexFolder != null ) - solrIndexFolder.delete(); + SolrQuery query = new SolrQuery().setQuery("corson"); + + testQueryGetsDocs("Expect to find a doc when searching for 'corson'", + query,new String[]{ "http://vivo.cornell.edu/individual/individual22972" } ) ; } + + /** - * Test that a document with the given IDs are in the results for the query. + * Test that a document with the given URIs are in the results for the query. * @throws SolrServerException */ - void testQueryGetsDocs(String errmsg, SolrQuery query, String[] docIds) throws SolrServerException{ + void testQueryGetsDocs(String errmsg, SolrQuery query, String[] expectedUris) throws SolrServerException{ assertNotNull(errmsg + " but query was null", query); - assertNotNull(errmsg + " but docIds was null", docIds ); + assertNotNull(errmsg + " but expected URIs was null", expectedUris ); QueryResponse resp = solr.query(query); if( resp == null ) fail( errmsg + " but Could not get a solr response"); - Set expecteIds = new HashSet(Arrays.asList( docIds )); + Set uris = new HashSet(Arrays.asList( expectedUris )); for( SolrDocument doc : resp.getResults()){ assertNotNull(errmsg + ": solr doc was null", doc); - String id = (String) doc.getFirstValue("id"); - assertNotNull(errmsg+": no id field in solr doc" , id); - expecteIds.remove( id ); + String uri = (String) doc.getFirstValue( VitroSearchTermNames.URI ); + assertNotNull(errmsg+": no URI field in solr doc" , uri); + uris.remove( uri ); } - if( expecteIds.size() > 0){ + if( uris.size() > 0){ String errorMsg = "\nThe query '"+ query + "' was expected " + - "to return the following ids but did not:"; - for( String id : expecteIds){ - errorMsg= errorMsg+"\n" + id; + "to return the following URIs but did not:"; + for( String uri : uris){ + errorMsg= errorMsg+"\n" + uri; } fail( errmsg + errorMsg); diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURLTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURLTest.java index 39fc0b418..178a6c1d4 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURLTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURLTest.java @@ -13,8 +13,6 @@ import org.junit.Assert; import org.junit.Before; 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.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler; @@ -22,21 +20,17 @@ import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler; import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory; +import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceFactorySingle; +import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.SkipIndividualException; import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ThumbnailImageURL; -/** - * @author bdc34 - * - */ public class ThumbnailImageURLTest extends AbstractTestClass{ - OntModel testModel; + RDFServiceFactory testRDF; String personsURI = "http://vivo.cornell.edu/individual/individual8803"; - - static VitroSearchTermNames term = new VitroSearchTermNames(); - String fieldForThumbnailURL = term.THUMBNAIL_URL; - + /** * @throws java.lang.Exception */ @@ -47,25 +41,32 @@ public class ThumbnailImageURLTest extends AbstractTestClass{ Model model = ModelFactory.createDefaultModel(); InputStream in = ThumbnailImageURLTest.class.getResourceAsStream("testPerson.n3"); model.read(in,"","N3"); - testModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM,model); + testRDF = new RDFServiceFactorySingle( new RDFServiceModel( model ) ); } /** + * Test to see if ThumbnailImageURL gets the date it is suppose to gete + * from a set of RDF. + * * Test method for {@link edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.ThumbnailImageURL#modifyDocument(edu.cornell.mannlib.vitro.webapp.beans.Individual, org.apache.solr.common.SolrInputDocument, java.lang.StringBuffer)}. */ @Test - public void testModifyDocument() { + public void testThumbnailFieldCreatedInSolrDoc() { SolrInputDocument doc = new SolrInputDocument(); - ThumbnailImageURL testMe = new ThumbnailImageURL( testModel ); + ThumbnailImageURL testMe = new ThumbnailImageURL( testRDF ); Individual ind = new IndividualImpl(); ind.setURI(personsURI); + + //make sure that the person is in the RDF try { testMe.modifyDocument(ind, doc, null); } catch (SkipIndividualException e) { - Assert.fail("person was skipped: " + e.getMessage()); + Assert.fail("Test individual was skipped by classes that build the search document: " + e.getMessage()); } - - SolrInputField thumbnailField = doc.getField(fieldForThumbnailURL); + + //make sure that a Solr document field got created for the thumbnail image + + SolrInputField thumbnailField = doc.getField( VitroSearchTermNames.THUMBNAIL_URL ); Assert.assertNotNull(thumbnailField); Assert.assertNotNull( thumbnailField.getValues() ); diff --git a/webapp/test/testontologies/SolrQueryTestRDF/jcr.rdf b/webapp/test/testontologies/SolrQueryTestRDF/jcr.rdf new file mode 100644 index 000000000..fc5c9818f --- /dev/null +++ b/webapp/test/testontologies/SolrQueryTestRDF/jcr.rdf @@ -0,0 +1,504 @@ + + + AgriVIVO: an Ontology-based Store of URIs and Relations between Entities in Agricultural Research + + + + + + + + 7 + + + ontology + + + Cornell's VIVO concept will expand to connect researchers nationwide + + + + + + 2011-01-01T05:00:00Z + + + + + + + + 4 + + + The Future of VIVO: Growing the Community + + + + + + 2011-01-01T00:00:00 + + + Polygon Overlay to Support Point Sample Mapping: the National Resources Inventory + + + DataStaR: Using the Semantic Web Approach for Data Curation + + + yearMonthDayPrecision + + + + + + 2011-01-01T00:00:00 + + + Albert R. Mann Library + Albert R. Mann Library + + + Digital Research Data Curation: Overview of Issues, Current Activities, and Opportunities for the Cornell University Library + + + Report of the Workshop on Rendering, Perception, and Measurement + + + + + + + + 3 + + + Searching Interoperability Between Linguistic Coding and Ontologies for Language Description + + + + + + + + 1 + + + + + + + + + co-Presenter + + + + + + + + 4 + + + + + + 2011-01-01T00:00:00 + + + semantic + + + AgriVIVO for enabling global networking for agriculture. Concept Note + + + + + + + + 3 + + + yearPrecision + + + + + + + + + + + + 2003-01-01T00:00:00 + + + VIVO: Connecting People, Creating a Virtual Life Sciences Community + + + + + + + + + + + + + + SUNY Chancellor's Award for Excellence in Professional Service (Corson-Rikert, Jonathan - 2012) + + + + + + 2012-01-01T00:00:00 + + + Extending VIVO + + + Act: An Easy-to-use and Dynamically Extensible 3D Graphics Library + + + + + + + + 1 + + + + + + + + + + VIVO Researcher Networking Update + + + geographic information system + + + + + + + + + member + + + + + + + + Ans van Tienhoven Award + + + VIVO: A Semantic Network of Researchers and Research Information as Linked Open Data + + + + + + + + + + + + + + 3 + + + CUL Discovery and Access Committee + + + + + + + + 1 + + + + + + 2010-05-18T00:00:00 + + + VIVO Development Roadmap: Enhancing an Ontology-Based University Research Portal with OWL and Rules + + + N.Y.'s climate change clearinghouse to offer info to all + + + informatics + + + DataStaR: Using the Semantic Web approach for Data Curation + + + repository + + + + + Info Tech Asst Dir II + Head of Information Technology Services, Mann Library, Cornell University + + + jc55 + + + + 0000-0002-2017-9998 + + + + + + + + 1012111 + Head of Information Technology Services + + jc55@cornell.edu + + <p>I am active in Semantic Web research for research information discovery and library projects.</p> + + <ul> +<li>Programmer Analyst, Mann Library 2001-2006</li> +<li>Lab Manager, Program of Computer Graphics, Cornell University, 1992-2001</li> +<li>Programmer, Harvard Lab for Computer Graphics, Cambridge, Massachusetts 1983-1992</li> +<li>Cartographer, Dane County Regional Planning Commission, Madison, Wisconsin, 1978-1982</li> +</ul> + + + + + + + + + + + 20336816000 + + Corson-Rikert + + + + + Jonathan + + + + + Corson-Rikert, Jonathan + + + + Info Tech Assistant Dir II + My research is focused on semantic web development for networked scholarship. + + + + 509729 + + + + B-3301-2009 + Corson-Rikert, Jon + + + + + + + + + + + + + + + Presenter + + + + + + + + 6 + + + SUNY Chancellor's Award for Excellence in Professional Service + + + VIVO: A Semantic Approach to Scholarly Networking and Discovery + + + + + + + + 2 + + + + + + 2011-01-01T05:00:00Z + + + + + + 2010-01-05T00:00:00 + + + + + + + + 2 + + + VIVO: Case Study of an Ontology-Based Web Site + + + VIVO: Enabling National Networking of Scientists + + + + + + + + 4 + + + + + + + + Web development intern + + + DataStaR: An Ontology-Based Approach to Representing Metadata for Research Datasets + + + The VIVO Ontology + + + + + + 0 + P + STA + + + Info Tech Assistant Dir II + + Info Tech Asst Dir II + + + + + + + + 1 + + + WYSIWYG Map Digitizing: Real Time Geometric Correction and Topological Encoding + + + + + + + + 3 + + + + + + + + 8 + + + + + + + + 4 + + + + + + + + + + + + + + 2 + +