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

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

improved solr document model

File size: 1.9 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.FacetConstants;
20import eu.clarin.cmdi.vlo.VloWicketApplication;
21import eu.clarin.cmdi.vlo.service.SolrDocumentService;
22import org.apache.solr.common.SolrDocument;
23import org.apache.wicket.model.LoadableDetachableModel;
24
25/**
26 * Detachable model for Solr documents that uses the {@link SolrDocumentService}
27 * registered on the application to load a single document.
28 *
29 * @author twagoo
30 * @see VloWicketApplication#getDocumentService()
31 */
32public class SolrDocumentModel extends LoadableDetachableModel<SolrDocument> {
33
34    private final String docId;
35
36    public SolrDocumentModel(SolrDocument document) {
37        super(document);
38        this.docId = (String) document.getFieldValue(FacetConstants.FIELD_ID);
39    }
40
41    public SolrDocumentModel(String docId) {
42        this.docId = docId;
43    }
44
45    @Override
46    protected SolrDocument load() {
47        if (docId == null) {
48            return null;
49        } else {
50            return VloWicketApplication.get().getDocumentService().getDocument(docId);
51        }
52    }
53
54    @Override
55    public String toString() {
56        return String.format("%s docId=%s attached=%b", super.toString(), docId, isAttached());
57    }
58
59}
Note: See TracBrowser for help on using the repository browser.