source: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.3.0/src/main/java/eu/clarin/sru/server/fcs/ResourceInfo.java @ 6957

Last change on this file since 6957 was 6957, checked in by Oliver Schonefeld, 8 years ago
  • tag version 1.3.0
  • Property svn:eol-style set to native
File size: 7.5 KB
Line 
1/**
2 * This software is copyright (c) 2013-2016 by
3 *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
4 * This is free software. You can redistribute it
5 * and/or modify it under the terms described in
6 * the GNU General Public License v3 of which you
7 * should have received a copy. Otherwise you can download
8 * it from
9 *
10 *   http://www.gnu.org/licenses/gpl-3.0.txt
11 *
12 * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
13 *
14 * @license http://www.gnu.org/licenses/gpl-3.0.txt
15 *  GNU General Public License v3
16 */
17package eu.clarin.sru.server.fcs;
18
19import java.util.Collections;
20import java.util.List;
21import java.util.Map;
22
23
24/**
25 * This class implements a resource info record, which provides supplementary
26 * information about a resource that is available at the endpoint.
27 *
28 * @see EndpointDescription
29 */
30public class ResourceInfo {
31    private final String pid;
32    private final Map<String, String> title;
33    private final Map<String, String> description;
34    private final String landingPageURI;
35    private final List<String> languages;
36    private final List<DataView> availableDataViews;
37    private final List<Layer> availableLayers;
38    private final List<ResourceInfo> subResources;
39
40
41    /**
42     * Constructor.
43     *
44     * @param pid
45     *            the persistent identifier of the resource
46     * @param title
47     *            the title of the resource represented as a map with pairs of
48     *            language code and title
49     * @param description
50     *            the description of the resource represented as a map with
51     *            pairs of language code and description or <code>null</code> if
52     *            not applicable
53     * @param landingPageURI
54     *            a URI to the landing page of the resource or <code>null</code>
55     *            if not applicable
56     * @param languages
57     *            the languages represented within this resource represented as
58     *            a list of ISO-632-3 three letter language codes
59     * @param availableDataViews
60     *            the list of available data views for this resource
61     * @param availableLayers
62     *            the list if layers available for Advanced Search or
63     *            <code>null</code> if not applicable
64     * @param subResources
65     *            a list of resource sub-ordinate to this resource or
66     *            <code>null</code> if not applicable
67     */
68    public ResourceInfo(String pid, Map<String, String> title,
69            Map<String, String> description, String landingPageURI,
70            List<String> languages, List<DataView> availableDataViews,
71            List<Layer> availableLayers,
72            List<ResourceInfo> subResources) {
73        if (pid == null) {
74            throw new NullPointerException("pid == null");
75        }
76        this.pid = pid;
77
78        if (title == null) {
79            throw new NullPointerException("title == null");
80        }
81        if (title.isEmpty()) {
82            throw new IllegalArgumentException("title is empty");
83        }
84        this.title = Collections.unmodifiableMap(title);
85        if ((description != null) && !description.isEmpty()) {
86            this.description = Collections.unmodifiableMap(description);
87        } else {
88            this.description = null;
89        }
90
91        this.landingPageURI = landingPageURI;
92        if (languages == null) {
93            throw new NullPointerException("languages == null");
94        }
95        if (languages.isEmpty()) {
96            throw new IllegalArgumentException("languages is empty");
97        }
98        this.languages = languages;
99
100        if (availableDataViews == null) {
101            throw new IllegalArgumentException("availableDataViews == null");
102        }
103        this.availableDataViews =
104                Collections.unmodifiableList(availableDataViews);
105
106        if ((availableLayers != null) && !availableDataViews.isEmpty()) {
107            this.availableLayers =
108                    Collections.unmodifiableList(availableLayers);
109        } else {
110            this.availableLayers = null;
111        }
112
113        if ((subResources != null) && !subResources.isEmpty()) {
114            this.subResources = Collections.unmodifiableList(subResources);
115        } else {
116            this.subResources = null;
117        }
118    }
119
120
121    /**
122     * Get the persistent identifier of this resource.
123     *
124     * @return a string representing the persistent identifier of this resource
125     */
126    public String getPid() {
127        return pid;
128    }
129
130
131    /**
132     * Determine, if this resource has sub-resources.
133     *
134     * @return <code>true</code> if the resource has sub-resources,
135     *         <code>false</code> otherwise
136     */
137    public boolean hasSubResources() {
138        return subResources != null;
139    }
140
141
142    /**
143     * Get the title of this resource.
144     *
145     * @return a Map of titles keyed by language code
146     */
147    public Map<String, String> getTitle() {
148        return title;
149    }
150
151
152    /**
153     * Get the title of the resource for a specific language code.
154     *
155     * @param language
156     *            the language code
157     * @return the title for the language code or <code>null</code> if no title
158     *         for this language code exists
159     */
160    public String getTitle(String language) {
161        return title.get(language);
162    }
163
164
165    /**
166     * Get the description of this resource.
167     *
168     * @return a Map of descriptions keyed by language code
169     */
170    public Map<String, String> getDescription() {
171        return description;
172    }
173
174
175    /**
176     * Get the description of the resource for a specific language code.
177     *
178     * @param language
179     *            the language code
180     * @return the description for the language code or <code>null</code> if no
181     *         title for this language code exists
182     */
183    public String getDescription(String language) {
184        return (description != null) ? description.get(language) : null;
185    }
186
187
188    /**
189     * Get the landing page of this resource.
190     *
191     * @return the landing page of this resource or <code>null</code> if not
192     *         applicable
193     */
194    public String getLandingPageURI() {
195        return landingPageURI;
196    }
197
198
199    /**
200     * Get the list of languages in this resource represented as ISO-632-3 three
201     * letter language code.
202     *
203     * @return the list of languages in this resource as a list of ISO-632-3
204     *         three letter language codes.
205     */
206    public List<String> getLanguages() {
207        return languages;
208    }
209
210
211    /**
212     * Get the list of data views that are available for this resource.
213     *
214     * @return the list of data views
215     */
216    public List<DataView> getAvailableDataViews() {
217        return availableDataViews;
218    }
219
220
221    /**
222     * Get the list of layers that are available in Advanced Search for this
223     * resource.
224     *
225     * @return the list of layers or <code>null</code>
226     */
227    public List<Layer> getAvailableLayers() {
228        return availableLayers;
229    }
230
231
232    /**
233     * Check if any layers are available for Advanced Search
234     *
235     * @return <code>true</code> if any layer for Advanced Search is available,
236     *         <code>false</code> otherwise
237     */
238    public boolean hasAvailableLayers() {
239        return (availableLayers != null);
240    }
241
242
243    /**
244     * Get the direct sub-ordinate resources of this resource.
245     *
246     * @return a list of resources or <code>null</code> if this resource has no
247     *         sub-ordinate resources
248     */
249    public List<ResourceInfo> getSubResources() {
250        return subResources;
251    }
252
253} // class ResourceInfo
Note: See TracBrowser for help on using the repository browser.