1 | /* |
---|
2 | * Copyright (C) 2014 CLARIN |
---|
3 | * |
---|
4 | * This program is free software: you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation, either version 3 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | */ |
---|
17 | package eu.clarin.cmdi.vlo.config; |
---|
18 | |
---|
19 | import com.google.common.collect.Lists; |
---|
20 | import eu.clarin.cmdi.vlo.VloWicketApplication; |
---|
21 | import eu.clarin.cmdi.vlo.service.FacetFieldsService; |
---|
22 | import eu.clarin.cmdi.vlo.service.SearchResultsDao; |
---|
23 | import eu.clarin.cmdi.vlo.service.SolrDocumentService; |
---|
24 | import eu.clarin.cmdi.vlo.service.SolrFacetQueryFactory; |
---|
25 | import eu.clarin.cmdi.vlo.service.impl.SearchResultsDaoImpl; |
---|
26 | import eu.clarin.cmdi.vlo.service.impl.SolrDocumentQueryFactoryImpl; |
---|
27 | import eu.clarin.cmdi.vlo.service.impl.SolrDocumentServiceImpl; |
---|
28 | import eu.clarin.cmdi.vlo.service.impl.SolrFacetFieldsService; |
---|
29 | import eu.clarin.cmdi.vlo.service.impl.SolrFacetQueryFactoryImpl; |
---|
30 | import java.io.IOException; |
---|
31 | import java.util.ArrayList; |
---|
32 | import org.apache.solr.client.solrj.SolrServer; |
---|
33 | import org.apache.solr.client.solrj.impl.HttpSolrServer; |
---|
34 | import org.springframework.context.annotation.Bean; |
---|
35 | import org.springframework.context.annotation.Configuration; |
---|
36 | |
---|
37 | /** |
---|
38 | * Annotation based Spring configuration for the VLO web application. |
---|
39 | * |
---|
40 | * Note: this works because |
---|
41 | * {@link org.apache.wicket.spring.SpringWebApplicationFactory} is used in place |
---|
42 | * of the standard Wicket application factory and annotation driven |
---|
43 | * configuration is enabled in WEB-INF/applicationContext.xml |
---|
44 | * |
---|
45 | * @author twagoo |
---|
46 | */ |
---|
47 | @Configuration |
---|
48 | public class VloSpringConfig { |
---|
49 | |
---|
50 | /** |
---|
51 | * |
---|
52 | * @return the web application object that represents the Wicket application |
---|
53 | */ |
---|
54 | @Bean |
---|
55 | public VloWicketApplication webApplication() { |
---|
56 | return new VloWicketApplication(); |
---|
57 | } |
---|
58 | |
---|
59 | @Bean |
---|
60 | public VloConfig vloConfig() { |
---|
61 | try { |
---|
62 | return vloConfigFactory().newConfig(); |
---|
63 | } catch (IOException ex) { |
---|
64 | throw new RuntimeException("Could not read VLO configuration", ex); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | @Bean |
---|
69 | public VloConfigFactory vloConfigFactory() { |
---|
70 | return new ServletVloConfigFactory(); |
---|
71 | } |
---|
72 | |
---|
73 | @Bean |
---|
74 | public FacetFieldsService facetFieldsService() { |
---|
75 | return new SolrFacetFieldsService(searchResultsDao(), facetQueryFactory()); |
---|
76 | } |
---|
77 | |
---|
78 | @Bean |
---|
79 | public SolrFacetQueryFactory facetQueryFactory() { |
---|
80 | final ArrayList<String> facets = Lists.newArrayList(vloConfig().getFacetFields()); |
---|
81 | //TODO: get collections facet from config |
---|
82 | facets.add(vloConfig().getCollectionFacet()); |
---|
83 | |
---|
84 | return new SolrFacetQueryFactoryImpl(facets); |
---|
85 | } |
---|
86 | |
---|
87 | @Bean |
---|
88 | public SolrDocumentService documentService() { |
---|
89 | return new SolrDocumentServiceImpl(searchResultsDao(), documentQueryFactory()); |
---|
90 | } |
---|
91 | |
---|
92 | @Bean |
---|
93 | public SearchResultsDao searchResultsDao() { |
---|
94 | return new SearchResultsDaoImpl(solrServer(), vloConfig()); |
---|
95 | } |
---|
96 | |
---|
97 | @Bean |
---|
98 | public SolrDocumentQueryFactoryImpl documentQueryFactory() { |
---|
99 | return new SolrDocumentQueryFactoryImpl(); |
---|
100 | } |
---|
101 | |
---|
102 | @Bean |
---|
103 | public SolrServer solrServer() { |
---|
104 | return new HttpSolrServer(vloConfig().getSolrUrl()); |
---|
105 | } |
---|
106 | } |
---|