source: vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/config/VloSpringConfig.java @ 4584

Last change on this file since 4584 was 4584, checked in by twagoo, 10 years ago

added collectionFacet property to VloConfig? (class+xml)

File size: 3.5 KB
Line 
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 */
17package eu.clarin.cmdi.vlo.config;
18
19import com.google.common.collect.Lists;
20import eu.clarin.cmdi.vlo.VloWicketApplication;
21import eu.clarin.cmdi.vlo.service.FacetFieldsService;
22import eu.clarin.cmdi.vlo.service.SearchResultsDao;
23import eu.clarin.cmdi.vlo.service.SolrDocumentService;
24import eu.clarin.cmdi.vlo.service.SolrFacetQueryFactory;
25import eu.clarin.cmdi.vlo.service.impl.SearchResultsDaoImpl;
26import eu.clarin.cmdi.vlo.service.impl.SolrDocumentQueryFactoryImpl;
27import eu.clarin.cmdi.vlo.service.impl.SolrDocumentServiceImpl;
28import eu.clarin.cmdi.vlo.service.impl.SolrFacetFieldsService;
29import eu.clarin.cmdi.vlo.service.impl.SolrFacetQueryFactoryImpl;
30import java.io.IOException;
31import java.util.ArrayList;
32import org.apache.solr.client.solrj.SolrServer;
33import org.apache.solr.client.solrj.impl.HttpSolrServer;
34import org.springframework.context.annotation.Bean;
35import 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
48public 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}
Note: See TracBrowser for help on using the repository browser.