VIVO-906 Explicitly configure the SearchIndexExcluders and DocumentModifiers.

This commit is contained in:
j2blake 2014-11-13 17:18:13 -05:00
parent 78241be685
commit 68b06322fb
15 changed files with 106 additions and 154 deletions

View file

@ -63,9 +63,6 @@ edu.ucsf.vitro.opensocial.OpenSocialSmokeTests
# For multiple language support # For multiple language support
edu.cornell.mannlib.vitro.webapp.i18n.selection.LocaleSelectionSetup edu.cornell.mannlib.vitro.webapp.i18n.selection.LocaleSelectionSetup
# Add VIVO specific DocumentModifers, this must come before SearchIndexerSetup
edu.cornell.mannlib.vitro.webapp.search.documentBuilding.VivoDocumentModifiers
# The search indexer uses a "public" permission, so the PropertyRestrictionPolicyHelper # The search indexer uses a "public" permission, so the PropertyRestrictionPolicyHelper
# and the PermissionRegistry must already be set up. # and the PermissionRegistry must already be set up.
edu.cornell.mannlib.vitro.webapp.searchindex.SearchIndexerSetup edu.cornell.mannlib.vitro.webapp.searchindex.SearchIndexerSetup

View file

@ -0,0 +1,46 @@
@prefix : <http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#> .
#
# Specify the SearchIndexExcluders and DocumentModifiers for VIVO.
# These are in addition to the ones specified for VIVO.
#
:vivoSearchExcluder_namespaceExcluder
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ExcludeBasedOnNamespace> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.SearchIndexExcluder> ;
:excludes
"http://purl.obolibrary.org/obo/" .
# ------------------------------------
:vivodocumentModifier_calculateParameters
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.CalculateParameters> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier> .
:vivodocumentModifier_valuesFromVcards
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.VIVOValuesFromVcards> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier> .
:vivodocumentModifier_ISFBasicFields
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.VivoISFBasicFields> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier> .
:vivodocumentModifier_ISFAdvisingFields
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.VivoISFAdvisingFields> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier> .
:vivodocumentModifier_ISFEducationFields
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.VivoISFEducationFields> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier> .
:vivodocumentModifier_ISFGrantFields
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.VivoISFGrantFields> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier> .
:vivodocumentModifier_ISFMemberFields
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.VivoISFMemberFields> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier> .
:vivodocumentModifier_informationResourceContextNodeFields
a <java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.VivoInformationResourceContextNodeFields> ,
<java:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier> .

View file

@ -12,6 +12,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.DatasetFactory;
import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryExecutionFactory;
@ -26,12 +27,13 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.shared.Lock;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccess;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument;
import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier; import edu.cornell.mannlib.vitro.webapp.utils.configuration.ContextModelsUser;
public class CalculateParameters implements DocumentModifier { public class CalculateParameters implements DocumentModifier, ContextModelsUser {
private boolean shutdown = false; private boolean shutdown = false;
private Dataset dataset; private Dataset dataset;
@ -60,13 +62,9 @@ public class CalculateParameters implements DocumentModifier {
private static Log log = LogFactory.getLog(CalculateParameters.class); private static Log log = LogFactory.getLog(CalculateParameters.class);
public CalculateParameters(Dataset dataset){ @Override
this.dataset =dataset; public void setContextModels(ContextModelAccess models) {
// new Thread(new TotalInd(this.dataset,totalCountQuery)).start(); this.dataset = DatasetFactory.create(models.getOntModel());
}
public CalculateParameters(){
super();
} }
public float calculateBeta(String uri){ public float calculateBeta(String uri){

View file

@ -15,11 +15,11 @@ import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccess;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier; import edu.cornell.mannlib.vitro.webapp.utils.configuration.ContextModelsUser;
/** /**
* If there are any VCards on this Individual with Title objects, store the text * If there are any VCards on this Individual with Title objects, store the text
@ -28,7 +28,7 @@ import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.DocumentModifier
* If there are any VCards on this Individual with EMail objects, store the text * If there are any VCards on this Individual with EMail objects, store the text
* in the ALL_TEXT field. * in the ALL_TEXT field.
*/ */
public class VIVOValuesFromVcards implements DocumentModifier { public class VIVOValuesFromVcards implements DocumentModifier, ContextModelsUser {
private static final Log log = LogFactory private static final Log log = LogFactory
.getLog(VIVOValuesFromVcards.class); .getLog(VIVOValuesFromVcards.class);
@ -77,11 +77,12 @@ public class VIVOValuesFromVcards implements DocumentModifier {
} }
}}; }};
private RDFServiceFactory rdfServiceFactory; private RDFService rdfService;
private boolean shutdown = false; private boolean shutdown = false;
public VIVOValuesFromVcards(RDFServiceFactory rdfServiceFactory) { @Override
this.rdfServiceFactory = rdfServiceFactory; public void setContextModels(ContextModelAccess models) {
this.rdfService = models.getRDFService();
} }
@Override @Override
@ -100,7 +101,6 @@ public class VIVOValuesFromVcards implements DocumentModifier {
String query = queryTemplate.replaceAll("\\?uri", uri); String query = queryTemplate.replaceAll("\\?uri", uri);
try { try {
RDFService rdfService = rdfServiceFactory.getRDFService();
ResultSet results = RDFServiceUtils.sparqlSelectQuery(query, ResultSet results = RDFServiceUtils.sparqlSelectQuery(query,
rdfService); rdfService);
if (results != null) { if (results != null) {

View file

@ -4,9 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.search.documentBuilding;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ContextNodeFields;
/** /**
* Class that adds text from context nodes to Search Documents for * Class that adds text from context nodes to Search Documents for
* foaf:Agent individuals. * foaf:Agent individuals.
@ -15,8 +12,8 @@ public class VivoAgentContextNodeFields extends ContextNodeFields{
static List<String> queriesForAgent = new ArrayList<String>(); static List<String> queriesForAgent = new ArrayList<String>();
public VivoAgentContextNodeFields(RDFServiceFactory rdfServiceFactory){ public VivoAgentContextNodeFields(){
super(queriesForAgent,rdfServiceFactory); super(queriesForAgent);
} }
protected static final String prefix = protected static final String prefix =

View file

@ -1,72 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.search.documentBuilding;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.DatasetFactory;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
public class VivoDocumentModifiers implements javax.servlet.ServletContextListener{
/**
* Exclude from the search index individuals who's URIs start with these namespaces.
*/
private static final String[] INDIVIDUAL_NS_EXCLUDES={
//bdc34: seems that there are a lot of odd OBO things in the search, exclude them
"http://purl.obolibrary.org/obo/"
};
@SuppressWarnings("unchecked")
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext context = sce.getServletContext();
RDFServiceFactory rdfServiceFactory = RDFServiceUtils.getRDFServiceFactory(context);
Dataset dataset = DatasetFactory.create(ModelAccess.on(context).getOntModel());
/* Put DocumentModifiers into servlet context for use later in startup by SearchSetup
* This adds the code for VIVO specific additions to the building
* of search input Documents. */
List<DocumentModifier> modifiers = (List<DocumentModifier>)context.getAttribute("DocumentModifiers");
if( modifiers == null ){
modifiers = new ArrayList<DocumentModifier>();
context.setAttribute("DocumentModifiers", modifiers);
}
modifiers.add(new CalculateParameters(dataset));
modifiers.add( new VIVOValuesFromVcards( rdfServiceFactory ));
modifiers.add( new VivoISFBasicFields( rdfServiceFactory ));
modifiers.add( new VivoISFAdvisingFields( rdfServiceFactory ));
modifiers.add( new VivoISFEducationFields( rdfServiceFactory ));
modifiers.add( new VivoISFGrantFields( rdfServiceFactory ));
modifiers.add( new VivoISFMemberFields( rdfServiceFactory ));
modifiers.add(new VivoInformationResourceContextNodeFields(rdfServiceFactory));
/*
* Add VIVO specific code that excludes Individuals from the search index.
*/
List<SearchIndexExcluder> excludes =
(List<SearchIndexExcluder>)context.getAttribute("SearchIndexExcludes");
if( excludes == null ){
excludes = new ArrayList<SearchIndexExcluder>();
context.setAttribute("SearchIndexExcludes", excludes);
}
excludes.add(new ExcludeBasedOnNamespace(INDIVIDUAL_NS_EXCLUDES ));
}
@Override
public void contextDestroyed(ServletContextEvent arg0) {
// do nothing.
}
}

View file

@ -5,9 +5,6 @@ package edu.cornell.mannlib.vitro.webapp.search.documentBuilding;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ContextNodeFields;
/** /**
* DocumentModifier for adding rdfs:labels of individuals related via * DocumentModifier for adding rdfs:labels of individuals related via
* a advising relationship. * a advising relationship.
@ -31,8 +28,8 @@ public class VivoISFAdvisingFields extends ContextNodeFields {
queries.add( makeQueryForPeople() ); queries.add( makeQueryForPeople() );
} }
public VivoISFAdvisingFields(RDFServiceFactory rdfServiceFactory){ public VivoISFAdvisingFields(){
super(queries,rdfServiceFactory); super(queries);
} }
/** /**

View file

@ -5,9 +5,6 @@ package edu.cornell.mannlib.vitro.webapp.search.documentBuilding;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ContextNodeFields;
/** /**
* DocumentModifier to populate Search index fields for the basic ISF relationships. * DocumentModifier to populate Search index fields for the basic ISF relationships.
* *
@ -32,8 +29,8 @@ public class VivoISFBasicFields extends ContextNodeFields {
static List<String> queries = new ArrayList<String>(); static List<String> queries = new ArrayList<String>();
public VivoISFBasicFields(RDFServiceFactory rdfServiceFactory){ public VivoISFBasicFields(){
super(queries,rdfServiceFactory); super(queries);
} }
protected static final String prefix = protected static final String prefix =

View file

@ -5,9 +5,6 @@ package edu.cornell.mannlib.vitro.webapp.search.documentBuilding;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ContextNodeFields;
public class VivoISFEducationFields extends ContextNodeFields { public class VivoISFEducationFields extends ContextNodeFields {
private static String VIVONS = "http://vivoweb.org/ontology/core#"; private static String VIVONS = "http://vivoweb.org/ontology/core#";
@ -18,8 +15,8 @@ public class VivoISFEducationFields extends ContextNodeFields {
+ " prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + " prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ " prefix obo: <http://purl.obolibrary.org/obo/> \n" ; + " prefix obo: <http://purl.obolibrary.org/obo/> \n" ;
public VivoISFEducationFields(RDFServiceFactory rdfServiceFactory){ public VivoISFEducationFields(){
super(queries,rdfServiceFactory); super(queries);
} }
/** /**

View file

@ -5,9 +5,6 @@ package edu.cornell.mannlib.vitro.webapp.search.documentBuilding;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ContextNodeFields;
/* /*
* This DocumentModifier is for the ISF style grants. * This DocumentModifier is for the ISF style grants.
* It will * It will
@ -30,8 +27,8 @@ public class VivoISFGrantFields extends ContextNodeFields {
+ " prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + " prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ " prefix obo: <http://purl.obolibrary.org/obo/> \n" ; + " prefix obo: <http://purl.obolibrary.org/obo/> \n" ;
public VivoISFGrantFields(RDFServiceFactory rdfServiceFactory){ public VivoISFGrantFields(){
super(queries,rdfServiceFactory); super(queries);
} }
/** /**

View file

@ -5,9 +5,6 @@ package edu.cornell.mannlib.vitro.webapp.search.documentBuilding;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ContextNodeFields;
/** /**
* This class will: * This class will:
* add people's names to organization's search Documents. * add people's names to organization's search Documents.
@ -26,8 +23,8 @@ public class VivoISFMemberFields extends ContextNodeFields {
+ " prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + " prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ " prefix obo: <http://purl.obolibrary.org/obo/> \n" ; + " prefix obo: <http://purl.obolibrary.org/obo/> \n" ;
public VivoISFMemberFields(RDFServiceFactory rdfServiceFactory){ public VivoISFMemberFields(){
super(queries,rdfServiceFactory); super(queries);
} }
/** /**

View file

@ -4,9 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.search.documentBuilding;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.search.documentBuilding.ContextNodeFields;
/** /**
* Class that adds text from context nodes to search index Documents for * Class that adds text from context nodes to search index Documents for
* obo:IAO_0000030 individuals. * obo:IAO_0000030 individuals.
@ -18,8 +15,8 @@ public class VivoInformationResourceContextNodeFields extends ContextNodeFields{
static List<String> queriesForInformationResource = new ArrayList<String>(); static List<String> queriesForInformationResource = new ArrayList<String>();
public VivoInformationResourceContextNodeFields(RDFServiceFactory rdfServiceFactory){ public VivoInformationResourceContextNodeFields(){
super(queriesForInformationResource, rdfServiceFactory); super(queriesForInformationResource);
} }
protected static final String prefix = protected static final String prefix =

View file

@ -9,6 +9,8 @@ import java.io.InputStream;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccessStub;
import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.Property;
@ -18,17 +20,14 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl; import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService;
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.rdfservice.impl.jena.model.RDFServiceModel;
public class VivoAgentContextNodeFieldsTest extends AbstractTestClass{ public class VivoAgentContextNodeFieldsTest extends AbstractTestClass{
static String SPCA = "http://vivo.mydomain.edu/individual/n8087"; static String SPCA = "http://vivo.mydomain.edu/individual/n8087";
static ContextModelAccessStub contextModels;
static RDFServiceFactory rdfServiceFactory;
@BeforeClass @BeforeClass
public static void setup(){ public static void setup(){
@ -44,8 +43,8 @@ public class VivoAgentContextNodeFieldsTest extends AbstractTestClass{
assertTrue("expect statements about SPCA", assertTrue("expect statements about SPCA",
m.contains(ResourceFactory.createResource(SPCA),(Property) null,(RDFNode) null)); m.contains(ResourceFactory.createResource(SPCA),(Property) null,(RDFNode) null));
RDFService rdfService = new RDFServiceModel(m); contextModels = new ContextModelAccessStub();
rdfServiceFactory = new RDFServiceFactorySingle(rdfService); contextModels.setRDFService(WhichService.CONTENT, new RDFServiceModel(m));
} }
@Test @Test
@ -53,7 +52,8 @@ public class VivoAgentContextNodeFieldsTest extends AbstractTestClass{
Individual ind = new IndividualImpl(); Individual ind = new IndividualImpl();
ind.setURI(SPCA); ind.setURI(SPCA);
VivoAgentContextNodeFields vacnf = new VivoAgentContextNodeFields(rdfServiceFactory); VivoAgentContextNodeFields vacnf = new VivoAgentContextNodeFields();
vacnf.setContextModels(contextModels);
StringBuffer sb = vacnf.getValues( ind ); StringBuffer sb = vacnf.getValues( ind );
assertNotNull( sb ); assertNotNull( sb );
@ -68,7 +68,8 @@ public class VivoAgentContextNodeFieldsTest extends AbstractTestClass{
Individual ind = new IndividualImpl(); Individual ind = new IndividualImpl();
ind.setURI(SPCA); ind.setURI(SPCA);
VivoAgentContextNodeFields vacnf = new VivoAgentContextNodeFields(rdfServiceFactory); VivoAgentContextNodeFields vacnf = new VivoAgentContextNodeFields();
vacnf.setContextModels(contextModels);
StringBuffer sb = vacnf.getValues( ind ); StringBuffer sb = vacnf.getValues( ind );
assertNotNull( sb ); assertNotNull( sb );
@ -83,7 +84,8 @@ public class VivoAgentContextNodeFieldsTest extends AbstractTestClass{
Individual ind = new IndividualImpl(); Individual ind = new IndividualImpl();
ind.setURI(SPCA); ind.setURI(SPCA);
VivoAgentContextNodeFields vacnf = new VivoAgentContextNodeFields(rdfServiceFactory); VivoAgentContextNodeFields vacnf = new VivoAgentContextNodeFields();
vacnf.setContextModels(contextModels);
StringBuffer sb = vacnf.getValues( ind ); StringBuffer sb = vacnf.getValues( ind );
assertNotNull( sb ); assertNotNull( sb );

View file

@ -10,6 +10,8 @@ import org.apache.commons.lang.StringUtils;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccessStub;
import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.Property;
@ -19,9 +21,7 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl; import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService;
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.rdfservice.impl.jena.model.RDFServiceModel;
/** /**
@ -32,8 +32,7 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceMod
public class VivoAgentContextNodeFieldsTest2 extends AbstractTestClass{ public class VivoAgentContextNodeFieldsTest2 extends AbstractTestClass{
static String HISTORY_DEPT = "http://vivo.colorado.edu/deptid_10238" ; static String HISTORY_DEPT = "http://vivo.colorado.edu/deptid_10238" ;
static ContextModelAccessStub contextModels;
static RDFServiceFactory rdfServiceFactory;
@BeforeClass @BeforeClass
public static void setup(){ public static void setup(){
@ -52,8 +51,8 @@ public class VivoAgentContextNodeFieldsTest2 extends AbstractTestClass{
assertTrue("expect statements about HISTORY_DEPT", assertTrue("expect statements about HISTORY_DEPT",
m.contains(ResourceFactory.createResource(HISTORY_DEPT),(Property) null,(RDFNode) null)); m.contains(ResourceFactory.createResource(HISTORY_DEPT),(Property) null,(RDFNode) null));
RDFService rdfService = new RDFServiceModel(m); contextModels = new ContextModelAccessStub();
rdfServiceFactory = new RDFServiceFactorySingle(rdfService); contextModels.setRDFService(WhichService.CONTENT, new RDFServiceModel(m));
} }
/** /**
@ -65,7 +64,8 @@ public class VivoAgentContextNodeFieldsTest2 extends AbstractTestClass{
Individual ind = new IndividualImpl(); Individual ind = new IndividualImpl();
ind.setURI(HISTORY_DEPT); ind.setURI(HISTORY_DEPT);
VivoAgentContextNodeFields vacnf = new VivoAgentContextNodeFields(rdfServiceFactory); VivoAgentContextNodeFields vacnf = new VivoAgentContextNodeFields();
vacnf.setContextModels(contextModels);
StringBuffer sb = vacnf.getValues( ind ); StringBuffer sb = vacnf.getValues( ind );
assertNotNull( sb ); assertNotNull( sb );

View file

@ -9,6 +9,7 @@ import java.util.Collection;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccessStub;
import stubs.edu.cornell.mannlib.vitro.webapp.modules.ApplicationStub; import stubs.edu.cornell.mannlib.vitro.webapp.modules.ApplicationStub;
import stubs.edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineStub; import stubs.edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineStub;
import stubs.javax.servlet.ServletContextStub; import stubs.javax.servlet.ServletContextStub;
@ -23,10 +24,8 @@ import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
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.rdfservice.impl.jena.model.RDFServiceModel;
public class VivoInformationResourceContextNodeFieldsTest extends AbstractTestClass { public class VivoInformationResourceContextNodeFieldsTest extends AbstractTestClass {
@ -55,12 +54,14 @@ public class VivoInformationResourceContextNodeFieldsTest extends AbstractTestCl
Individual ind = wadf.getIndividualDao().getIndividualByURI(DOCUMENT_URI); Individual ind = wadf.getIndividualDao().getIndividualByURI(DOCUMENT_URI);
Assert.assertNotNull(ind); Assert.assertNotNull(ind);
RDFService rdfService = new RDFServiceModel(ontModel); ContextModelAccessStub contextModels = new ContextModelAccessStub();
RDFServiceFactory rdfServiceFactory = new RDFServiceFactorySingle(rdfService); contextModels.setRDFService(WhichService.CONTENT, new RDFServiceModel(ontModel));
SearchInputDocument doc = ApplicationUtils.instance().getSearchEngine().createInputDocument(); SearchInputDocument doc = ApplicationUtils.instance().getSearchEngine().createInputDocument();
doc.addField("ALLTEXT", ""); doc.addField("ALLTEXT", "");
VivoInformationResourceContextNodeFields vircnf = new VivoInformationResourceContextNodeFields(rdfServiceFactory); VivoInformationResourceContextNodeFields vircnf = new VivoInformationResourceContextNodeFields();
vircnf.setContextModels(contextModels);
vircnf.modifyDocument(ind, doc); vircnf.modifyDocument(ind, doc);
Collection<Object> values = doc.getField("ALLTEXT").getValues(); Collection<Object> values = doc.getField("ALLTEXT").getValues();
@ -68,7 +69,8 @@ public class VivoInformationResourceContextNodeFieldsTest extends AbstractTestCl
Assert.assertFalse("rdf:label erroneously added by document modifier:", value.toString().contains(RDFS_LABEL_VALUE)); Assert.assertFalse("rdf:label erroneously added by document modifier:", value.toString().contains(RDFS_LABEL_VALUE));
} }
VivoAgentContextNodeFields vacnf = new VivoAgentContextNodeFields(rdfServiceFactory); VivoAgentContextNodeFields vacnf = new VivoAgentContextNodeFields();
vacnf.setContextModels(contextModels);
vacnf.modifyDocument(ind, doc); vacnf.modifyDocument(ind, doc);
} }