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.provider; |
---|
18 | |
---|
19 | import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; |
---|
20 | import eu.clarin.cmdi.vlo.service.SolrDocumentService; |
---|
21 | import java.math.BigDecimal; |
---|
22 | import java.util.Iterator; |
---|
23 | import java.util.List; |
---|
24 | import org.apache.solr.common.SolrDocument; |
---|
25 | import org.apache.wicket.markup.repeater.data.IDataProvider; |
---|
26 | import org.apache.wicket.model.IModel; |
---|
27 | import org.apache.wicket.model.Model; |
---|
28 | import org.apache.wicket.util.convert.converter.BigDecimalConverter; |
---|
29 | |
---|
30 | /** |
---|
31 | * |
---|
32 | * @author twagoo |
---|
33 | */ |
---|
34 | public class SolrDocumentProvider implements IDataProvider<SolrDocument> { |
---|
35 | |
---|
36 | private final SolrDocumentService documentService; |
---|
37 | private final IModel<QueryFacetsSelection> selection; |
---|
38 | |
---|
39 | public SolrDocumentProvider(SolrDocumentService documentService, IModel<QueryFacetsSelection> selection) { |
---|
40 | this.documentService = documentService; |
---|
41 | this.selection = selection; |
---|
42 | } |
---|
43 | |
---|
44 | @Override |
---|
45 | public Iterator<? extends SolrDocument> iterator(long first, long count) { |
---|
46 | final List<SolrDocument> documents = documentService.getDocuments(selection.getObject(), |
---|
47 | BigDecimal.valueOf(first).intValueExact(), // safe long->int conversion |
---|
48 | BigDecimal.valueOf(count).intValueExact()); // safe long->int conversion |
---|
49 | return documents.iterator(); |
---|
50 | } |
---|
51 | |
---|
52 | @Override |
---|
53 | public long size() { |
---|
54 | return documentService.getDocumentCount(selection.getObject()); |
---|
55 | } |
---|
56 | |
---|
57 | @Override |
---|
58 | public IModel<SolrDocument> model(SolrDocument object) { |
---|
59 | return new Model(object); |
---|
60 | } |
---|
61 | |
---|
62 | @Override |
---|
63 | public void detach() { |
---|
64 | } |
---|
65 | |
---|
66 | } |
---|