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

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

Added CMDI view (obtained through XSLT transform) to record page

File size: 4.6 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 eu.clarin.cmdi.vlo.FacetConstants;
20import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
21import eu.clarin.cmdi.vlo.service.FieldFilter;
22import eu.clarin.cmdi.vlo.service.PageParametersConverter;
23import eu.clarin.cmdi.vlo.wicket.panels.FieldsTablePanel;
24import eu.clarin.cmdi.vlo.wicket.panels.ResourceLinksPanel;
25import eu.clarin.cmdi.vlo.wicket.components.SolrFieldLabel;
26import eu.clarin.cmdi.vlo.wicket.model.SolrDocumentModel;
27import eu.clarin.cmdi.vlo.wicket.model.SolrFieldModel;
28import eu.clarin.cmdi.vlo.wicket.model.SolrFieldStringModel;
29import eu.clarin.cmdi.vlo.wicket.model.UrlFromStringModel;
30import eu.clarin.cmdi.vlo.wicket.model.XsltModel;
31import eu.clarin.cmdi.vlo.wicket.provider.DocumentFieldsProvider;
32import org.apache.solr.common.SolrDocument;
33import org.apache.wicket.markup.html.basic.Label;
34import org.apache.wicket.markup.html.link.ExternalLink;
35import org.apache.wicket.model.IModel;
36import org.apache.wicket.model.Model;
37import org.apache.wicket.request.mapper.parameter.PageParameters;
38import org.apache.wicket.spring.injection.annot.SpringBean;
39
40/**
41 *
42 * @author twagoo
43 */
44public class RecordPage extends VloBasePage<SolrDocument> {
45
46    @SpringBean
47    private PageParametersConverter<QueryFacetsSelection> selectionParametersConverter;
48    @SpringBean(name = "basicPropertiesFilter")
49    private FieldFilter basicPropertiesFilter;
50    @SpringBean(name = "technicalPropertiesFilter")
51    private FieldFilter technicalPropertiesFilter;
52
53    private final IModel<QueryFacetsSelection> contextModel;
54
55    public RecordPage(PageParameters params) {
56        super(params);
57
58        final SolrDocumentModel documentModel = new SolrDocumentModel(params.get("docId").toString());
59        setModel(documentModel);
60
61        final QueryFacetsSelection selection = selectionParametersConverter.fromParameters(params);
62        this.contextModel = Model.of(selection);
63
64        addComponents();
65    }
66
67    public RecordPage(IModel<SolrDocument> documentModel, IModel<QueryFacetsSelection> contextModel) {
68        super(documentModel);
69        this.contextModel = contextModel;
70        addComponents();
71    }
72
73    private void addComponents() {
74        // General information section
75        add(new SolrFieldLabel("name", getModel(), FacetConstants.FIELD_NAME, "Unnamed record"));
76        add(createLandingPageLink("landingPageLink"));
77        add(new FieldsTablePanel("documentProperties", new DocumentFieldsProvider(getModel(), basicPropertiesFilter)));
78       
79        // Resources section
80        add(new ResourceLinksPanel("resources", new SolrFieldModel<String>(getModel(), FacetConstants.FIELD_RESOURCE)));
81       
82        // Technical section
83        add(createCmdiContent("cmdi"));
84        add(new FieldsTablePanel("technicalProperties", new DocumentFieldsProvider(getModel(), technicalPropertiesFilter)));
85    }
86
87    private ExternalLink createLandingPageLink(String id) {
88        final SolrFieldStringModel landingPageHrefModel = new SolrFieldStringModel(getModel(), FacetConstants.FIELD_LANDINGPAGE);
89        // add landing page link
90        final ExternalLink landingPageLink = new ExternalLink(id, landingPageHrefModel) {
91
92            @Override
93            protected void onConfigure() {
94                super.onConfigure();
95                setVisible(landingPageHrefModel.getObject() != null);
96            }
97
98        };
99        return landingPageLink;
100    }
101
102    private Label createCmdiContent(String id) {
103        final IModel<String> locationModel = new SolrFieldStringModel(getModel(), FacetConstants.FIELD_FILENAME);
104        final UrlFromStringModel locationUrlModel = new UrlFromStringModel(locationModel);
105        final Label cmdiContentLabel = new Label(id, new XsltModel(locationUrlModel));
106        cmdiContentLabel.setEscapeModelStrings(false);
107        return cmdiContentLabel;
108    }
109
110    @Override
111    public void detachModels() {
112        super.detachModels();
113        // not passed to parent
114        contextModel.detach();
115    }
116
117}
Note: See TracBrowser for help on using the repository browser.