VIVO-935 Clean up code for search exclusion.
Take out the attribute key in SearchIndexerSetup. Nobody ever sets that attribute. Take out the VClassGroupCache.removeClassesHiddenFromSearch() method. If nobody sets that attribute, this method does nothing. Take out VClassGroupDao.removeClassesHiddenFromSearch() and VClassGroupDaoJena.removeClassesHiddenFromSearch(). They are never called. Take out ClassProhibitedFromSearch interface. It is implemented but never referenced. Take out FileBasedProhibitedFromSearch. It is never used. Move ProhibitedFromSearch and ProhibitedFromSearchTest from edu.cornell.mannlib.vitro.webapp.search.beans to edu.cornell.mannlib.vitro.webapp.dao.vclassgroup
This commit is contained in:
parent
f4f51a096f
commit
ac39b0799e
12 changed files with 16 additions and 115 deletions
|
@ -2,25 +2,20 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.beans;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.filestorage.model.ImageInfo;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||
|
||||
/**
|
||||
* Represents a single entity record.
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||
|
||||
public interface VClassGroupDao {
|
||||
|
||||
public abstract VClassGroup getGroupByURI(String uri);
|
||||
|
@ -54,8 +54,6 @@ public interface VClassGroupDao {
|
|||
|
||||
public abstract int removeUnpopulatedGroups(List<VClassGroup> groups);
|
||||
|
||||
public void removeClassesHiddenFromSearch(List<VClassGroup> groups);
|
||||
|
||||
int insertNewVClassGroup(VClassGroup vcg);
|
||||
|
||||
void updateVClassGroup(VClassGroup vcg);
|
||||
|
|
|
@ -106,12 +106,6 @@ public class VClassGroupDaoFiltering extends BaseFiltering implements VClassGrou
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removeClassesHiddenFromSearch(List<VClassGroup> groups) {
|
||||
innerDao.removeClassesHiddenFromSearch(groups);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VClassGroup getGroupByName(String vcgName) {
|
||||
return innerDao.getGroupByName(vcgName);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -42,10 +41,8 @@ import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchFacetField.Co
|
|||
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery;
|
||||
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexingEventListener;
|
||||
import edu.cornell.mannlib.vitro.webapp.searchindex.SearchIndexerSetup;
|
||||
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
|
||||
|
||||
|
@ -243,10 +240,7 @@ public class VClassGroupCache implements IndexingEventListener {
|
|||
}
|
||||
|
||||
/**
|
||||
* Method that rebuilds the cache. This will use a WebappDaoFactory,
|
||||
* a SearchEngine and maybe a ProhibitedFromSearch from the cache.context.
|
||||
*
|
||||
* If ProhibitedFromSearch is not found in the context, that will be skipped.
|
||||
* Method that rebuilds the cache. This will use a WebappDaoFactory and a SearchEngine.
|
||||
*/
|
||||
protected static void rebuildCacheUsingSearch( VClassGroupCache cache ) throws SearchEngineException{
|
||||
long start = System.currentTimeMillis();
|
||||
|
@ -260,7 +254,6 @@ public class VClassGroupCache implements IndexingEventListener {
|
|||
List<VClassGroup> groups = vcgDao.getPublicGroupsWithVClasses(ORDER_BY_DISPLAYRANK,
|
||||
INCLUDE_UNINSTANTIATED, DONT_INCLUDE_INDIVIDUAL_COUNT);
|
||||
|
||||
removeClassesHiddenFromSearch(groups, cache.context);
|
||||
addCountsUsingSearch(groups, searchEngine);
|
||||
cache.setCache(groups, classMapForGroups(groups));
|
||||
|
||||
|
@ -281,28 +274,6 @@ public class VClassGroupCache implements IndexingEventListener {
|
|||
return newClassMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes classes from groups that are prohibited from search.
|
||||
*/
|
||||
protected static void removeClassesHiddenFromSearch(List<VClassGroup> groups, ServletContext context2) {
|
||||
ProhibitedFromSearch pfs = (ProhibitedFromSearch)context2.getAttribute(SearchIndexerSetup.PROHIBITED_FROM_SEARCH);
|
||||
if(pfs==null){
|
||||
log.debug("Could not get ProhibitedFromSearch from ServletContext");
|
||||
return;
|
||||
}
|
||||
|
||||
for (VClassGroup group : groups) {
|
||||
List<VClass> classList = new ArrayList<VClass>();
|
||||
for (VClass vclass : group.getVitroClassList()) {
|
||||
if (!pfs.isClassProhibitedFromSearch(vclass.getURI())) {
|
||||
classList.add(vclass);
|
||||
}
|
||||
}
|
||||
group.setVitroClassList(classList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add the Individual count to classes in groups.
|
||||
|
|
|
@ -26,12 +26,10 @@ import com.hp.hpl.jena.util.iterator.ClosableIterator;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||
|
||||
public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
|
||||
|
||||
|
@ -295,22 +293,6 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeClassesHiddenFromSearch(List<VClassGroup> groups) {
|
||||
OntModel displayOntModel = getOntModelSelector().getDisplayModel();
|
||||
ProhibitedFromSearch pfs = new ProhibitedFromSearch(
|
||||
DisplayVocabulary.SEARCH_INDEX_URI, displayOntModel);
|
||||
for (VClassGroup group : groups) {
|
||||
List<VClass> classList = new ArrayList<VClass>();
|
||||
for (VClass vclass : group.getVitroClassList()) {
|
||||
if (!pfs.isClassProhibitedFromSearch(vclass.getURI())) {
|
||||
classList.add(vclass);
|
||||
}
|
||||
}
|
||||
group.setVitroClassList(classList);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VClassGroup getGroupByName(String vcgName) {
|
||||
if( vcgName == null )
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.search.beans;
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.vclassgroup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -25,7 +25,7 @@ import com.hp.hpl.jena.shared.Lock;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||
|
||||
public class ProhibitedFromSearch implements ClassProhibitedFromSearch{
|
||||
public class ProhibitedFromSearch {
|
||||
List<String> prohibitedClasses;
|
||||
String ProhibitedFromSearchURI;
|
||||
|
||||
|
@ -94,7 +94,7 @@ public class ProhibitedFromSearch implements ClassProhibitedFromSearch{
|
|||
return newProhibitedClasses;
|
||||
}
|
||||
|
||||
private static enum ChangeType { ADD, REMOVE } ;
|
||||
private static enum ChangeType { ADD, REMOVE }
|
||||
|
||||
class ProhibitedFromSearchChangeListener extends StatementListener {
|
||||
ProhibitedFromSearch pfs;
|
||||
|
@ -117,10 +117,10 @@ public class ProhibitedFromSearch implements ClassProhibitedFromSearch{
|
|||
|
||||
//is it about this ProhibitedFromSearch?
|
||||
if( s.getSubject() != null ){
|
||||
String subURI = ((Resource) s.getSubject()).getURI() ;
|
||||
String subURI = 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();
|
||||
String classURI = s.getObject().as(Resource.class).getURI();
|
||||
if( add == ChangeType.ADD )
|
||||
pfs.addProhibitedClass(classURI);
|
||||
else
|
|
@ -5,7 +5,6 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -30,6 +29,7 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.vclassgroup.ProhibitedFromSearch;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.ModelSelector;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardModelSelector;
|
||||
|
@ -37,7 +37,6 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardWDF
|
|||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.WDFSelector;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDataPropertyFormGenerator;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ModelChangePreprocessor;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,6 +26,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.vclassgroup.ProhibitedFromSearch;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||
|
@ -39,7 +40,6 @@ import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery;
|
|||
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse;
|
||||
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResultDocumentList;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
|
||||
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.search.beans;
|
||||
|
||||
public interface ClassProhibitedFromSearch {
|
||||
public boolean isClassProhibitedFromSearch(String classUri);
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.search.beans;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.RDFFilesLoader;
|
||||
|
||||
public class FileBasedProhibitedFromSearch extends ProhibitedFromSearch {
|
||||
|
||||
/**
|
||||
* Load all the .n3 files in dir, add them to a model and create
|
||||
* a ProhibitedFromSearch based on that model
|
||||
* @param URI of the search individual.
|
||||
* @param dir to find N3 files in.
|
||||
*/
|
||||
public FileBasedProhibitedFromSearch(String uri, File dir){
|
||||
super( uri, RDFFilesLoader.getModelFromDir(dir));
|
||||
}
|
||||
|
||||
public FileBasedProhibitedFromSearch(String URI, OntModel model) {
|
||||
super(URI, model);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -47,8 +47,6 @@ import edu.cornell.mannlib.vitro.webapp.utils.developer.listeners.DeveloperDisab
|
|||
public class SearchIndexerSetup implements ServletContextListener {
|
||||
private static final Log log = LogFactory.getLog(SearchIndexerSetup.class);
|
||||
|
||||
public static final String PROHIBITED_FROM_SEARCH = "edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch";
|
||||
|
||||
private ServletContext ctx;
|
||||
private OntModel displayModel;
|
||||
private ConfigurationBeanLoader beanLoader;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.search.beans;
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.vclassgroup;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class ProhibitedFromSearchTest {
|
|||
@Test
|
||||
public void testBuildingProhibited(){
|
||||
Model r = ModelFactory.createDefaultModel().read(new StringReader(n3), null, "N3");
|
||||
OntModel m = (OntModel) ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
m.add( r.listStatements() );
|
||||
|
||||
Assert.assertTrue(m.size() > 4);
|
||||
|
@ -48,7 +48,7 @@ public class ProhibitedFromSearchTest {
|
|||
@Test
|
||||
public void testNotFound(){
|
||||
Model r = ModelFactory.createDefaultModel().read(new StringReader(n3), null, "N3");
|
||||
OntModel m = (OntModel) ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
m.add( r.listStatements() );
|
||||
|
||||
Assert.assertTrue(m.size() > 4);
|
||||
|
@ -63,7 +63,7 @@ public class ProhibitedFromSearchTest {
|
|||
@Test
|
||||
public void testListener(){
|
||||
Model r = ModelFactory.createDefaultModel().read(new StringReader(n3), null, "N3");
|
||||
OntModel m = (OntModel) ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
m.add( r.listStatements() );
|
||||
Assert.assertTrue(m.size() > 4);
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class ProhibitedFromSearchTest {
|
|||
@Test
|
||||
public void testListenerAbnormal(){
|
||||
Model r = ModelFactory.createDefaultModel().read(new StringReader(n3), null, "N3");
|
||||
OntModel m = (OntModel) ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
m.add( r.listStatements() );
|
||||
Assert.assertTrue(m.size() > 4);
|
||||
|
||||
|
@ -115,7 +115,7 @@ public class ProhibitedFromSearchTest {
|
|||
"<http://vivoweb.org/ontology/core#NonAcademic> . ";
|
||||
|
||||
Model r = ModelFactory.createDefaultModel().read(new StringReader(primaryIndexN3), null, "N3");
|
||||
OntModel m = (OntModel) ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
m.add( r.listStatements() );
|
||||
|
||||
Assert.assertTrue(m.size() == 1);
|
Loading…
Add table
Reference in a new issue