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.wicket.model; |
---|
18 | |
---|
19 | import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; |
---|
20 | import eu.clarin.cmdi.vlo.service.FacetFieldsService; |
---|
21 | import java.util.Collections; |
---|
22 | import java.util.List; |
---|
23 | import org.apache.solr.client.solrj.response.FacetField; |
---|
24 | import org.apache.wicket.model.AbstractReadOnlyModel; |
---|
25 | import 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 | */ |
---|
37 | public 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 | } |
---|