VIVO-742 Setup the Application properly, and guard against NPEs
This commit is contained in:
parent
90886c564e
commit
1bb5153857
5 changed files with 63 additions and 11 deletions
|
@ -3,22 +3,28 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.application;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.modules.Application;
|
||||
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
|
||||
import edu.cornell.mannlib.vitro.webapp.searchengine.SearchEngineWrapper;
|
||||
import edu.cornell.mannlib.vitro.webapp.searchengine.solr.SolrSearchEngine;
|
||||
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||
|
||||
/**
|
||||
* The basic implementation of the Application interface.
|
||||
*/
|
||||
public class ApplicationImpl implements Application {
|
||||
// ----------------------------------------------------------------------
|
||||
// The instance
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private final ServletContext ctx;
|
||||
private SearchEngine searchEngine;
|
||||
|
||||
public ApplicationImpl(ServletContext ctx) {
|
||||
this.ctx = ctx;
|
||||
setSearchEngine(new SolrSearchEngine());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,10 +38,37 @@ public class ApplicationImpl implements Application {
|
|||
}
|
||||
|
||||
public void setSearchEngine(SearchEngine searchEngine) {
|
||||
if (searchEngine instanceof SearchEngineWrapper) {
|
||||
this.searchEngine = searchEngine;
|
||||
} else {
|
||||
this.searchEngine = new SearchEngineWrapper(searchEngine);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// The Setup class.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public static class Setup implements ServletContextListener {
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
ServletContext ctx = sce.getServletContext();
|
||||
StartupStatus ss = StartupStatus.getBean(ctx);
|
||||
|
||||
try {
|
||||
SearchEngine searchEngine = new SearchEngineWrapper(
|
||||
new SolrSearchEngine());
|
||||
|
||||
ApplicationImpl application = new ApplicationImpl(ctx);
|
||||
application.setSearchEngine(searchEngine);
|
||||
ApplicationUtils.setInstance(application);
|
||||
ss.info(this, "Appliation is configured.");
|
||||
} catch (Exception e) {
|
||||
ss.fatal(this, "Failed to initialize the Application.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
// Nothing to tear down.
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,4 +26,8 @@ public class ApplicationUtils {
|
|||
}
|
||||
}
|
||||
|
||||
static void setInstance(Application application) {
|
||||
instance = application;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -148,8 +148,11 @@ public class SolrConversionUtils {
|
|||
private static Map<String, SearchFacetField> convertToSearchFacetFieldMap(
|
||||
List<FacetField> facetFields) {
|
||||
Map<String, SearchFacetField> map = new HashMap<>();
|
||||
if (facetFields != null) {
|
||||
for (FacetField facetField : facetFields) {
|
||||
map.put(facetField.getName(), convertToSearchFacetField(facetField));
|
||||
map.put(facetField.getName(),
|
||||
convertToSearchFacetField(facetField));
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
@ -163,10 +166,12 @@ public class SolrConversionUtils {
|
|||
private static List<BaseCount> convertToSearchFacetFieldCounts(
|
||||
List<FacetField.Count> solrCounts) {
|
||||
List<BaseCount> searchCounts = new ArrayList<>();
|
||||
if (solrCounts != null) {
|
||||
for (FacetField.Count solrCount : solrCounts) {
|
||||
searchCounts.add(new BaseCount(solrCount.getName(), solrCount
|
||||
.getCount()));
|
||||
}
|
||||
}
|
||||
return searchCounts;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,16 @@ public class SolrSearchResultDocumentList implements SearchResultDocumentList {
|
|||
private SolrDocumentList solrDocs;
|
||||
|
||||
public SolrSearchResultDocumentList(SolrDocumentList solrDocs) {
|
||||
if (solrDocs == null) {
|
||||
SolrDocumentList list = new SolrDocumentList();
|
||||
list.setStart(0L);
|
||||
list.setNumFound(0L);
|
||||
list.setMaxScore(0.0F);
|
||||
this.solrDocs = list;
|
||||
} else {
|
||||
this.solrDocs = solrDocs;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<SearchResultDocument> iterator() {
|
||||
|
|
|
@ -13,6 +13,8 @@ edu.cornell.mannlib.vitro.webapp.config.ConfigurationPropertiesSmokeTests
|
|||
|
||||
edu.cornell.mannlib.vitro.webapp.utils.developer.DeveloperSettings$Setup
|
||||
|
||||
edu.cornell.mannlib.vitro.webapp.application.ApplicationImpl$Setup
|
||||
|
||||
edu.cornell.mannlib.vitro.webapp.config.RevisionInfoSetup
|
||||
|
||||
edu.cornell.mannlib.vitro.webapp.email.FreemarkerEmailFactory$Setup
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue