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;
|
package edu.cornell.mannlib.vitro.webapp.application;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
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.Application;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
|
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
|
||||||
import edu.cornell.mannlib.vitro.webapp.searchengine.SearchEngineWrapper;
|
import edu.cornell.mannlib.vitro.webapp.searchengine.SearchEngineWrapper;
|
||||||
import edu.cornell.mannlib.vitro.webapp.searchengine.solr.SolrSearchEngine;
|
import edu.cornell.mannlib.vitro.webapp.searchengine.solr.SolrSearchEngine;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The basic implementation of the Application interface.
|
* The basic implementation of the Application interface.
|
||||||
*/
|
*/
|
||||||
public class ApplicationImpl implements Application {
|
public class ApplicationImpl implements Application {
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// The instance
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
private final ServletContext ctx;
|
private final ServletContext ctx;
|
||||||
private SearchEngine searchEngine;
|
private SearchEngine searchEngine;
|
||||||
|
|
||||||
public ApplicationImpl(ServletContext ctx) {
|
public ApplicationImpl(ServletContext ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
setSearchEngine(new SolrSearchEngine());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,10 +38,37 @@ public class ApplicationImpl implements Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSearchEngine(SearchEngine searchEngine) {
|
public void setSearchEngine(SearchEngine searchEngine) {
|
||||||
if (searchEngine instanceof SearchEngineWrapper) {
|
this.searchEngine = searchEngine;
|
||||||
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.
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,5 +25,9 @@ public class ApplicationUtils {
|
||||||
"Called for Application before it was available", e);
|
"Called for Application before it was available", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setInstance(Application application) {
|
||||||
|
instance = application;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,8 +148,11 @@ public class SolrConversionUtils {
|
||||||
private static Map<String, SearchFacetField> convertToSearchFacetFieldMap(
|
private static Map<String, SearchFacetField> convertToSearchFacetFieldMap(
|
||||||
List<FacetField> facetFields) {
|
List<FacetField> facetFields) {
|
||||||
Map<String, SearchFacetField> map = new HashMap<>();
|
Map<String, SearchFacetField> map = new HashMap<>();
|
||||||
for (FacetField facetField : facetFields) {
|
if (facetFields != null) {
|
||||||
map.put(facetField.getName(), convertToSearchFacetField(facetField));
|
for (FacetField facetField : facetFields) {
|
||||||
|
map.put(facetField.getName(),
|
||||||
|
convertToSearchFacetField(facetField));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
@ -163,9 +166,11 @@ public class SolrConversionUtils {
|
||||||
private static List<BaseCount> convertToSearchFacetFieldCounts(
|
private static List<BaseCount> convertToSearchFacetFieldCounts(
|
||||||
List<FacetField.Count> solrCounts) {
|
List<FacetField.Count> solrCounts) {
|
||||||
List<BaseCount> searchCounts = new ArrayList<>();
|
List<BaseCount> searchCounts = new ArrayList<>();
|
||||||
for (FacetField.Count solrCount : solrCounts) {
|
if (solrCounts != null) {
|
||||||
searchCounts.add(new BaseCount(solrCount.getName(), solrCount
|
for (FacetField.Count solrCount : solrCounts) {
|
||||||
.getCount()));
|
searchCounts.add(new BaseCount(solrCount.getName(), solrCount
|
||||||
|
.getCount()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return searchCounts;
|
return searchCounts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,15 @@ public class SolrSearchResultDocumentList implements SearchResultDocumentList {
|
||||||
private SolrDocumentList solrDocs;
|
private SolrDocumentList solrDocs;
|
||||||
|
|
||||||
public SolrSearchResultDocumentList(SolrDocumentList solrDocs) {
|
public SolrSearchResultDocumentList(SolrDocumentList solrDocs) {
|
||||||
this.solrDocs = 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
|
@Override
|
||||||
|
|
|
@ -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.utils.developer.DeveloperSettings$Setup
|
||||||
|
|
||||||
|
edu.cornell.mannlib.vitro.webapp.application.ApplicationImpl$Setup
|
||||||
|
|
||||||
edu.cornell.mannlib.vitro.webapp.config.RevisionInfoSetup
|
edu.cornell.mannlib.vitro.webapp.config.RevisionInfoSetup
|
||||||
|
|
||||||
edu.cornell.mannlib.vitro.webapp.email.FreemarkerEmailFactory$Setup
|
edu.cornell.mannlib.vitro.webapp.email.FreemarkerEmailFactory$Setup
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue