source: vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/pages/RecordPage.java @ 4640

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

added resources overview to the record page

File size: 4.4 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.pages;
18
19import com.google.common.collect.Sets;
20import eu.clarin.cmdi.vlo.FacetConstants;
21import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
22import eu.clarin.cmdi.vlo.service.FieldFilter;
23import eu.clarin.cmdi.vlo.wicket.components.FieldsTablePanel;
24import eu.clarin.cmdi.vlo.wicket.components.ResourceLinksPanel;
25import eu.clarin.cmdi.vlo.wicket.components.SolrFieldLabel;
26import eu.clarin.cmdi.vlo.wicket.model.SolrFieldModel;
27import eu.clarin.cmdi.vlo.wicket.model.SolrFieldStringModel;
28import eu.clarin.cmdi.vlo.wicket.provider.DocumentFieldsProvider;
29import java.io.Serializable;
30import java.util.Collection;
31import org.apache.solr.common.SolrDocument;
32import org.apache.wicket.markup.html.WebPage;
33import org.apache.wicket.markup.html.link.ExternalLink;
34import org.apache.wicket.model.IModel;
35
36/**
37 *
38 * @author twagoo
39 */
40public class RecordPage extends WebPage {
41
42    /**
43     * Fields to be ignored. TODO: read this from config
44     */
45    private static final Collection<String> IGNORE_FIELDS
46            = Sets.newHashSet(
47                    FacetConstants.FIELD_FORMAT);
48    /**
49     * Fields to be included in technical details. TODO: read this from config
50     */
51    private static final Collection<String> TECHNICAL_FIELDS
52            = Sets.newHashSet(
53                    FacetConstants.FIELD_ID,
54                    FacetConstants.FIELD_DATA_PROVIDER,
55                    FacetConstants.FIELD_FORMAT,
56                    FacetConstants.FIELD_LANDINGPAGE,
57                    FacetConstants.FIELD_SEARCHPAGE,
58                    FacetConstants.FIELD_SEARCH_SERVICE,
59                    FacetConstants.FIELD_LAST_SEEN);
60    private final IModel<QueryFacetsSelection> contextModel;
61
62    public RecordPage(IModel<SolrDocument> documentModel, IModel<QueryFacetsSelection> contextModel) {
63        super(documentModel);
64        this.contextModel = contextModel;
65
66        add(new SolrFieldLabel("name", documentModel, FacetConstants.FIELD_NAME, "Unnamed record"));
67        add(createLandingPageLink("landingPageLink", documentModel));
68        add(new FieldsTablePanel("documentProperties", new DocumentFieldsProvider(documentModel, new BasicPropertiesFieldFilter())));
69        add(new ResourceLinksPanel("resources", new SolrFieldModel<String>(documentModel, FacetConstants.FIELD_RESOURCE)));
70        add(new FieldsTablePanel("technicalProperties", new DocumentFieldsProvider(documentModel, new TechnicalPropertiesFieldFilter())));
71    }
72
73    private ExternalLink createLandingPageLink(String id, IModel<SolrDocument> documentModel) {
74        final SolrFieldStringModel landingPageHrefModel = new SolrFieldStringModel(documentModel, FacetConstants.FIELD_LANDINGPAGE);
75        // add landing page link
76        final ExternalLink landingPageLink = new ExternalLink(id, landingPageHrefModel) {
77
78            @Override
79            protected void onConfigure() {
80                super.onConfigure();
81                setVisible(landingPageHrefModel.getObject() != null);
82            }
83
84        };
85        return landingPageLink;
86    }
87
88    @Override
89    public void detachModels() {
90        super.detachModels();
91        // not passed to parent
92        contextModel.detach();
93    }
94
95    private class BasicPropertiesFieldFilter implements FieldFilter, Serializable {
96
97        @Override
98        public boolean allowField(String fieldName) {
99            return !(fieldName.startsWith("_")
100                    || IGNORE_FIELDS.contains(fieldName)
101                    || TECHNICAL_FIELDS.contains(fieldName));
102        }
103    }
104
105    private class TechnicalPropertiesFieldFilter implements FieldFilter, Serializable {
106
107        @Override
108        public boolean allowField(String fieldName) {
109            return TECHNICAL_FIELDS.contains(fieldName);
110        }
111    }
112
113}
Note: See TracBrowser for help on using the repository browser.