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

Last change on this file since 4588 was 4588, checked in by Twan Goosen, 10 years ago

Javadoc for recently added classes

File size: 2.2 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 eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
20import eu.clarin.cmdi.vlo.service.FacetFieldsService;
21import java.util.Collections;
22import java.util.List;
23import org.apache.solr.client.solrj.response.FacetField;
24import org.apache.wicket.model.AbstractReadOnlyModel;
25import org.apache.wicket.model.IModel;
26
27/**
28 * Decorator for {@link FacetFieldsModel} for a selection of a single facet.
29 *
30 * Notice that the actual retrieval is carried out by the provided
31 * {@link FacetFieldsService}, which therefore should be configured to actually
32 * retrieve the specified facet (through the constructor), otherwise it may not
33 * be presented.
34 *
35 * @author twagoo
36 */
37public class FacetFieldModel extends AbstractReadOnlyModel<FacetField> {
38
39    //todo: can be made more efficient/elegant than wrapping fields model
40    private final FacetFieldsModel fieldsModel;
41
42    /**
43     *
44     * @param service service to use for facet field retrieval
45     * @param facet facet to provide
46     * @param selectionModel model that provides current query/selection
47     */
48    public FacetFieldModel(FacetFieldsService service, String facet, IModel<QueryFacetsSelection> selectionModel) {
49        fieldsModel = new FacetFieldsModel(service, Collections.singletonList(facet), selectionModel);
50    }
51
52    @Override
53    public FacetField getObject() {
54        final List<FacetField> fieldsList = fieldsModel.getObject();
55        if (fieldsList == null || fieldsList.isEmpty()) {
56            return null;
57        } else {
58            return fieldsList.get(0);
59        }
60    }
61
62}
Note: See TracBrowser for help on using the repository browser.