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.pages; |
---|
18 | |
---|
19 | import eu.clarin.cmdi.vlo.FacetConstants; |
---|
20 | import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; |
---|
21 | import eu.clarin.cmdi.vlo.service.FieldFilter; |
---|
22 | import eu.clarin.cmdi.vlo.service.PageParametersConverter; |
---|
23 | import eu.clarin.cmdi.vlo.wicket.panels.FieldsTablePanel; |
---|
24 | import eu.clarin.cmdi.vlo.wicket.panels.ResourceLinksPanel; |
---|
25 | import eu.clarin.cmdi.vlo.wicket.components.SolrFieldLabel; |
---|
26 | import eu.clarin.cmdi.vlo.wicket.model.SolrDocumentModel; |
---|
27 | import eu.clarin.cmdi.vlo.wicket.model.SolrFieldModel; |
---|
28 | import eu.clarin.cmdi.vlo.wicket.model.SolrFieldStringModel; |
---|
29 | import eu.clarin.cmdi.vlo.wicket.model.UrlFromStringModel; |
---|
30 | import eu.clarin.cmdi.vlo.wicket.model.XsltModel; |
---|
31 | import eu.clarin.cmdi.vlo.wicket.provider.DocumentFieldsProvider; |
---|
32 | import org.apache.solr.common.SolrDocument; |
---|
33 | import org.apache.wicket.markup.html.basic.Label; |
---|
34 | import org.apache.wicket.markup.html.link.ExternalLink; |
---|
35 | import org.apache.wicket.model.IModel; |
---|
36 | import org.apache.wicket.model.Model; |
---|
37 | import org.apache.wicket.request.mapper.parameter.PageParameters; |
---|
38 | import org.apache.wicket.spring.injection.annot.SpringBean; |
---|
39 | |
---|
40 | /** |
---|
41 | * |
---|
42 | * @author twagoo |
---|
43 | */ |
---|
44 | public 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 | } |
---|