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.wicket.components.FieldsTablePanel; |
---|
23 | import eu.clarin.cmdi.vlo.wicket.components.SolrFieldLabel; |
---|
24 | import eu.clarin.cmdi.vlo.wicket.model.SolrFieldStringModel; |
---|
25 | import eu.clarin.cmdi.vlo.wicket.provider.DocumentFieldsProvider; |
---|
26 | import java.io.Serializable; |
---|
27 | import org.apache.solr.common.SolrDocument; |
---|
28 | import org.apache.wicket.markup.html.WebPage; |
---|
29 | import org.apache.wicket.markup.html.link.ExternalLink; |
---|
30 | import org.apache.wicket.model.IModel; |
---|
31 | |
---|
32 | /** |
---|
33 | * |
---|
34 | * @author twagoo |
---|
35 | */ |
---|
36 | public class RecordPage extends WebPage { |
---|
37 | |
---|
38 | private final IModel<QueryFacetsSelection> contextModel; |
---|
39 | |
---|
40 | public RecordPage(IModel<SolrDocument> documentModel, IModel<QueryFacetsSelection> contextModel) { |
---|
41 | super(documentModel); |
---|
42 | this.contextModel = contextModel; |
---|
43 | |
---|
44 | add(new SolrFieldLabel("name", documentModel, FacetConstants.FIELD_NAME, "Unnamed record")); |
---|
45 | add(createLandingPageLink("landingPageLink", documentModel)); |
---|
46 | add(new FieldsTablePanel("documentProperties", new DocumentFieldsProvider(documentModel, new BasicPropertiesFieldFilter()))); |
---|
47 | } |
---|
48 | |
---|
49 | private ExternalLink createLandingPageLink(String id, IModel<SolrDocument> documentModel) { |
---|
50 | final SolrFieldStringModel landingPageHrefModel = new SolrFieldStringModel(documentModel, FacetConstants.FIELD_LANDINGPAGE); |
---|
51 | // add landing page link |
---|
52 | final ExternalLink landingPageLink = new ExternalLink(id, landingPageHrefModel) { |
---|
53 | |
---|
54 | @Override |
---|
55 | protected void onConfigure() { |
---|
56 | super.onConfigure(); |
---|
57 | setVisible(landingPageHrefModel.getObject() != null); |
---|
58 | } |
---|
59 | |
---|
60 | }; |
---|
61 | return landingPageLink; |
---|
62 | } |
---|
63 | |
---|
64 | @Override |
---|
65 | public void detachModels() { |
---|
66 | super.detachModels(); |
---|
67 | // not passed to parent |
---|
68 | contextModel.detach(); |
---|
69 | } |
---|
70 | |
---|
71 | private class BasicPropertiesFieldFilter implements FieldFilter, Serializable { |
---|
72 | |
---|
73 | @Override |
---|
74 | public boolean allowField(String fieldName) { |
---|
75 | return !fieldName.startsWith("_"); |
---|
76 | //TODO: Exclude excluded fields and technical fields |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | } |
---|