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.solr.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 | import org.apache.wicket.model.LoadableDetachableModel; |
---|
27 | |
---|
28 | /** |
---|
29 | * Decorator for {@link FacetFieldsModel} for a selection of a single facet. |
---|
30 | * |
---|
31 | * Notice that the actual retrieval is carried out by the provided |
---|
32 | * {@link FacetFieldsService}, which therefore should be configured to actually |
---|
33 | * retrieve the specified facet (through the constructor), otherwise it may not |
---|
34 | * be presented. |
---|
35 | * |
---|
36 | * TODO: Provide some kind of batch retrieval and look up to prevent a call for |
---|
37 | * each instance of this |
---|
38 | * |
---|
39 | * @author twagoo |
---|
40 | */ |
---|
41 | public class FacetFieldModel extends AbstractReadOnlyModel<FacetField> { |
---|
42 | |
---|
43 | private final FacetFieldsModel fieldsModel; |
---|
44 | private final String facetName; |
---|
45 | |
---|
46 | |
---|
47 | /** |
---|
48 | * |
---|
49 | * @param service service to use for facet field retrieval |
---|
50 | * @param facet facet to provide |
---|
51 | * @param selectionModel model that provides current query/selection |
---|
52 | */ |
---|
53 | public FacetFieldModel(String facet, FacetFieldsService service, IModel<QueryFacetsSelection> selectionModel) { |
---|
54 | this(facet, new FacetFieldsModel(service, Collections.singletonList(facet), selectionModel, -1)); |
---|
55 | } |
---|
56 | |
---|
57 | public FacetFieldModel(String facetName, FacetFieldsModel fieldsModel){ |
---|
58 | this.fieldsModel = fieldsModel; |
---|
59 | this.facetName = facetName; |
---|
60 | } |
---|
61 | |
---|
62 | @Override |
---|
63 | public FacetField getObject() { |
---|
64 | return fieldsModel.getFacetField(facetName); |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | public void detachFacetFieldsModel(){ |
---|
69 | fieldsModel.detach(); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | } |
---|