source: vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/provider/SolrDocumentProvider.java @ 4530

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

started implementation of search results. Created panel and added required service interfaces/implementations

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.provider;
18
19import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
20import eu.clarin.cmdi.vlo.service.SolrDocumentService;
21import java.math.BigDecimal;
22import java.util.Iterator;
23import java.util.List;
24import org.apache.solr.common.SolrDocument;
25import org.apache.wicket.markup.repeater.data.IDataProvider;
26import org.apache.wicket.model.IModel;
27import org.apache.wicket.model.Model;
28import org.apache.wicket.util.convert.converter.BigDecimalConverter;
29
30/**
31 *
32 * @author twagoo
33 */
34public 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}
Note: See TracBrowser for help on using the repository browser.