source: vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/model/FacetFieldsModel.java @ 4582

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

refactored construction of facet panels, both in facets panel and single collections facet panel

File size: 2.1 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.wicket.model;
18
19import com.google.common.base.Predicate;
20import com.google.common.collect.Collections2;
21import com.google.common.collect.ImmutableList;
22import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
23import eu.clarin.cmdi.vlo.service.FacetFieldsService;
24import java.util.Collection;
25import java.util.List;
26import org.apache.solr.client.solrj.response.FacetField;
27import org.apache.wicket.model.IModel;
28import org.apache.wicket.model.LoadableDetachableModel;
29
30/**
31 *
32 * @author twagoo
33 */
34public class FacetFieldsModel extends LoadableDetachableModel<List<FacetField>> {
35
36    private final FacetFieldsService service;
37    private final List<String> facets;
38    private final IModel<QueryFacetsSelection> selectionModel;
39
40    public FacetFieldsModel(FacetFieldsService service, List<String> facets, IModel<QueryFacetsSelection> selectionModel) {
41        this.service = service;
42        this.facets = facets;
43        this.selectionModel = selectionModel;
44    }
45
46    @Override
47    protected List<FacetField> load() {
48        final List<FacetField> allFacetFields = service.getFacetFields(selectionModel.getObject());
49        final Collection<FacetField> filtered = Collections2.filter(allFacetFields, new Predicate<FacetField>() {
50
51            @Override
52            public boolean apply(FacetField t) {
53                return facets.contains(t.getName());
54            }
55        });
56        return ImmutableList.copyOf(filtered);
57    }
58
59}
Note: See TracBrowser for help on using the repository browser.