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.panels; |
---|
18 | |
---|
19 | import eu.clarin.cmdi.vlo.FacetConstants; |
---|
20 | import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection; |
---|
21 | import eu.clarin.cmdi.vlo.wicket.model.SolrFieldStringModel; |
---|
22 | import eu.clarin.cmdi.vlo.wicket.provider.SolrDocumentProvider; |
---|
23 | import org.apache.solr.common.SolrDocument; |
---|
24 | import org.apache.wicket.AttributeModifier; |
---|
25 | import org.apache.wicket.markup.html.WebMarkupContainer; |
---|
26 | import org.apache.wicket.markup.html.panel.GenericPanel; |
---|
27 | import org.apache.wicket.markup.repeater.Item; |
---|
28 | import org.apache.wicket.markup.repeater.data.DataView; |
---|
29 | import org.apache.wicket.markup.repeater.data.IDataProvider; |
---|
30 | import org.apache.wicket.model.AbstractReadOnlyModel; |
---|
31 | import org.apache.wicket.model.IModel; |
---|
32 | import org.apache.wicket.model.Model; |
---|
33 | |
---|
34 | /** |
---|
35 | * Panel that renders an HTML form with hidden fields to submits the results of |
---|
36 | * a query selection to the Virtual Collection Registry in order to create a new |
---|
37 | * collection |
---|
38 | * |
---|
39 | * @author twagoo |
---|
40 | */ |
---|
41 | public class VirtualCollectionFormPanel extends GenericPanel<QueryFacetsSelection> { |
---|
42 | |
---|
43 | //TODO: make configurable |
---|
44 | private final String vcrSubmitEndpoint = "http://catalog-clarin.esc.rzg.mpg.de/vcr/service/submit"; |
---|
45 | |
---|
46 | /** |
---|
47 | * Construct the panel with a new document provider based on the provided |
---|
48 | * model |
---|
49 | * |
---|
50 | * @param id component id |
---|
51 | * @param model model to use for form content and document provider |
---|
52 | */ |
---|
53 | public VirtualCollectionFormPanel(String id, IModel<QueryFacetsSelection> model) { |
---|
54 | this(id, model, new SolrDocumentProvider(model)); |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * Constructs the panel with a shared document provider |
---|
59 | * |
---|
60 | * @param id component id |
---|
61 | * @param model model to use for form content (collection title) |
---|
62 | * @param documentProvider provider to use for gathering document ID's |
---|
63 | * (assumed to be based on the same model as the one provided to this |
---|
64 | * constructor) |
---|
65 | */ |
---|
66 | public VirtualCollectionFormPanel(String id, IModel<QueryFacetsSelection> model, IDataProvider<SolrDocument> documentProvider) { |
---|
67 | super(id, model); |
---|
68 | |
---|
69 | final WebMarkupContainer form = new WebMarkupContainer("vcrForm"); |
---|
70 | form.add(new AttributeModifier("action", Model.of(vcrSubmitEndpoint))); |
---|
71 | add(form); |
---|
72 | |
---|
73 | final IModel<String> nameModel = new AbstractReadOnlyModel<String>() { |
---|
74 | |
---|
75 | @Override |
---|
76 | public String getObject() { |
---|
77 | final String query = getModelObject().getQuery(); |
---|
78 | if (query != null) { |
---|
79 | return "VLO search results: " + query; |
---|
80 | } else { |
---|
81 | return "VLO search results"; |
---|
82 | } |
---|
83 | } |
---|
84 | }; |
---|
85 | |
---|
86 | final WebMarkupContainer collectionName = new WebMarkupContainer("collectionName"); |
---|
87 | collectionName.add(new AttributeModifier("value", nameModel)); |
---|
88 | form.add(collectionName); |
---|
89 | |
---|
90 | form.add(new DataView<SolrDocument>("metadataUris", documentProvider) { |
---|
91 | |
---|
92 | @Override |
---|
93 | protected void populateItem(Item<SolrDocument> item) { |
---|
94 | final WebMarkupContainer mdUri = new WebMarkupContainer("metadataUri"); |
---|
95 | final IModel<String> linkModel = new SolrFieldStringModel(item.getModel(), FacetConstants.FIELD_SELF_LINK); |
---|
96 | if (linkModel.getObject() == null) { |
---|
97 | mdUri.add(new AttributeModifier("value", new SolrFieldStringModel(item.getModel(), FacetConstants.FIELD_COMPLETE_METADATA))); |
---|
98 | } else { |
---|
99 | mdUri.add(new AttributeModifier("value", linkModel)); |
---|
100 | } |
---|
101 | item.add(mdUri); |
---|
102 | } |
---|
103 | }); |
---|
104 | } |
---|
105 | |
---|
106 | } |
---|