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 eu.clarin.cmdi.vlo.service.impl.ExclusiveFieldFilter; |
---|
20 | import eu.clarin.cmdi.vlo.service.impl.InclusiveFieldFilter; |
---|
21 | import com.google.common.collect.Sets; |
---|
22 | import eu.clarin.cmdi.vlo.VloWicketApplication; |
---|
23 | import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; |
---|
24 | import eu.clarin.cmdi.vlo.service.FacetFieldsService; |
---|
25 | import eu.clarin.cmdi.vlo.service.FieldFilter; |
---|
26 | import eu.clarin.cmdi.vlo.service.PageParametersConverter; |
---|
27 | import eu.clarin.cmdi.vlo.service.ResourceStringConverter; |
---|
28 | import eu.clarin.cmdi.vlo.service.ResourceTypeCountingService; |
---|
29 | import eu.clarin.cmdi.vlo.service.SearchResultsDao; |
---|
30 | import eu.clarin.cmdi.vlo.service.SolrDocumentService; |
---|
31 | import eu.clarin.cmdi.vlo.service.SolrFacetQueryFactory; |
---|
32 | import eu.clarin.cmdi.vlo.service.impl.QueryFacetsSelectionParametersConverter; |
---|
33 | import eu.clarin.cmdi.vlo.service.impl.ResourceStringConverterImpl; |
---|
34 | import eu.clarin.cmdi.vlo.service.impl.ResourceTypeCountingServiceImpl; |
---|
35 | import eu.clarin.cmdi.vlo.service.impl.SearchResultsDaoImpl; |
---|
36 | import eu.clarin.cmdi.vlo.service.impl.SolrDocumentQueryFactoryImpl; |
---|
37 | import eu.clarin.cmdi.vlo.service.impl.SolrDocumentServiceImpl; |
---|
38 | import eu.clarin.cmdi.vlo.service.impl.SolrFacetFieldsService; |
---|
39 | import eu.clarin.cmdi.vlo.service.impl.SolrFacetQueryFactoryImpl; |
---|
40 | import java.io.IOException; |
---|
41 | import org.apache.solr.client.solrj.SolrServer; |
---|
42 | import org.apache.solr.client.solrj.impl.HttpSolrServer; |
---|
43 | import org.springframework.context.annotation.Bean; |
---|
44 | import org.springframework.context.annotation.Configuration; |
---|
45 | |
---|
46 | /** |
---|
47 | * Annotation based Spring configuration for the VLO web application. |
---|
48 | * |
---|
49 | * Note: this works because |
---|
50 | * {@link org.apache.wicket.spring.SpringWebApplicationFactory} is used in place |
---|
51 | * of the standard Wicket application factory and annotation driven |
---|
52 | * configuration is enabled in WEB-INF/applicationContext.xml |
---|
53 | * |
---|
54 | * @author twagoo |
---|
55 | */ |
---|
56 | @Configuration |
---|
57 | public class VloSpringConfig { |
---|
58 | |
---|
59 | /** |
---|
60 | * |
---|
61 | * @return the web application object that represents the Wicket application |
---|
62 | */ |
---|
63 | @Bean |
---|
64 | public VloWicketApplication webApplication() { |
---|
65 | return new VloWicketApplication(); |
---|
66 | } |
---|
67 | |
---|
68 | @Bean |
---|
69 | public VloConfig vloConfig() { |
---|
70 | try { |
---|
71 | return vloConfigFactory().newConfig(); |
---|
72 | } catch (IOException ex) { |
---|
73 | throw new RuntimeException("Could not read VLO configuration", ex); |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | @Bean |
---|
78 | public VloConfigFactory vloConfigFactory() { |
---|
79 | return new ServletVloConfigFactory(); |
---|
80 | } |
---|
81 | |
---|
82 | @Bean |
---|
83 | public FacetFieldsService facetFieldsService() { |
---|
84 | return new SolrFacetFieldsService(searchResultsDao(), facetQueryFactory()); |
---|
85 | } |
---|
86 | |
---|
87 | @Bean |
---|
88 | public SolrFacetQueryFactory facetQueryFactory() { |
---|
89 | return new SolrFacetQueryFactoryImpl(vloConfig().getAllFacetFields()); |
---|
90 | } |
---|
91 | |
---|
92 | @Bean |
---|
93 | public SolrDocumentService documentService() { |
---|
94 | return new SolrDocumentServiceImpl(searchResultsDao(), documentQueryFactory()); |
---|
95 | } |
---|
96 | |
---|
97 | @Bean |
---|
98 | public SearchResultsDao searchResultsDao() { |
---|
99 | return new SearchResultsDaoImpl(solrServer(), vloConfig()); |
---|
100 | } |
---|
101 | |
---|
102 | @Bean |
---|
103 | public SolrDocumentQueryFactoryImpl documentQueryFactory() { |
---|
104 | return new SolrDocumentQueryFactoryImpl(); |
---|
105 | } |
---|
106 | |
---|
107 | @Bean |
---|
108 | public ResourceTypeCountingService resourceTypeCountingService() { |
---|
109 | return new ResourceTypeCountingServiceImpl(resourceStringConverter()); |
---|
110 | } |
---|
111 | |
---|
112 | @Bean |
---|
113 | public ResourceStringConverter resourceStringConverter() { |
---|
114 | return new ResourceStringConverterImpl(); |
---|
115 | } |
---|
116 | |
---|
117 | @Bean |
---|
118 | public PageParametersConverter<QueryFacetsSelection> queryParametersConverter() { |
---|
119 | return new QueryFacetsSelectionParametersConverter(); |
---|
120 | } |
---|
121 | |
---|
122 | @Bean |
---|
123 | public SolrServer solrServer() { |
---|
124 | return new HttpSolrServer(vloConfig().getSolrUrl()); |
---|
125 | } |
---|
126 | |
---|
127 | @Bean(name = "basicPropertiesFilter") |
---|
128 | public FieldFilter basicPropertiesFieldFilter() { |
---|
129 | return new ExclusiveFieldFilter(Sets.union( |
---|
130 | vloConfig().getIgnoredFields(), |
---|
131 | vloConfig().getTechnicalFields())); |
---|
132 | } |
---|
133 | |
---|
134 | @Bean(name = "technicalPropertiesFilter") |
---|
135 | public FieldFilter technicalPropertiesFieldFilter() { |
---|
136 | return new InclusiveFieldFilter( |
---|
137 | vloConfig().getTechnicalFields()); |
---|
138 | } |
---|
139 | } |
---|