source: FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/ResourceInfo.java @ 5477

Last change on this file since 5477 was 5477, checked in by margaretha@ids-mannheim.de, 10 years ago

Added endpoint description,
updated SimpleResourceInfoInventory? according to the new format.

  • Property svn:eol-style set to native
File size: 6.5 KB
Line 
1package eu.clarin.sru.server.fcs;
2
3import java.util.Collections;
4import java.util.List;
5import java.util.Map;
6
7
8/**
9 * This class implements a resource info record, which provides supplementary
10 * information about a resource that is available at the endpoint.
11 *
12 * @see ResourceInfoInventory
13 */
14public class ResourceInfo {
15    private final String pid;
16    @Deprecated
17    private final int resourceCount;
18    private final Map<String, String> title;
19    private final Map<String, String> description;
20    private final String landingPageURI;
21    private final List<String> languages;
22    private final List<String> availableDataViews;
23    private List<ResourceInfo> subResources;
24   
25
26    /**
27     * Constructor.
28     *
29     * @param pid
30     *            the persistent identifier of the resource
31     * @param resourceCount
32     *            the number of items within the resource or <code>-1</code> if
33     *            not applicable
34     * @param title
35     *            the title of the resource represented as a map with pairs of
36     *            language code and title
37     * @param description
38     *            the description of the resource represented as a map with
39     *            pairs of language code and description or <code>null</code> if
40     *            not applicable
41     * @param landingPageURI
42     *            a URI to the landing page of the resource or <code>null</code>
43     *            if not applicable
44     * @param languages
45     *            the languages represented within this resource represented as
46     *            a list of ISO-632-3 three letter language codes
47     * @param subResources
48     *            a list of resource sub-ordinate to this resource or
49     *            <code>null</code> if not applicable
50     */
51    public ResourceInfo(String pid, int resourceCount,
52            Map<String, String> title, Map<String, String> description,
53            String landingPageURI, List<String> languages,
54            List<String> availableDataViews,
55            List<ResourceInfo> subResources) {
56        if (pid == null) {
57            throw new NullPointerException("id == null");
58        }
59        this.pid = pid;
60        this.resourceCount = (resourceCount > 0) ? resourceCount : -1;
61        if (title == null) {
62            throw new NullPointerException("title == null");
63        }
64        if (title.isEmpty()) {
65            throw new IllegalArgumentException("title is empty");
66        }
67        this.title = Collections.unmodifiableMap(title);
68        if ((description != null) && !description.isEmpty()) {
69            this.description = Collections.unmodifiableMap(description);
70        } else {
71            this.description = null;
72        }
73        this.landingPageURI = landingPageURI;
74        if (languages == null) {
75            throw new NullPointerException("languages == null");
76        }
77        if (languages.isEmpty()) {
78            throw new IllegalArgumentException("languages is empty");
79        }
80        this.languages = languages;
81        if (availableDataViews == null){
82                throw new IllegalArgumentException("available data views == null");
83        }
84        if (availableDataViews.isEmpty()){
85                throw new IllegalArgumentException("available data views are empty");
86        }
87        this.availableDataViews = availableDataViews;
88        if ((subResources != null) && !subResources.isEmpty()) {
89            this.subResources = Collections.unmodifiableList(subResources);
90        } else {
91            this.subResources = null;
92        }       
93    }
94
95
96    /**
97     * Get the persistent identifier of this resource.
98     *
99     * @return a string representing the persistent identifier of this resource
100     */
101    public String getPid() {
102        return pid;
103    }
104
105
106    /**
107     * Get the number of resources within this resource. If this resource has
108     * sub-ordinate resources, this number should be the sum of all items within
109     * the sub-ordinate resources plus the number of items within this resource.
110     *
111     * @return a number of items or <code>-1</code> if not applicable
112     */
113    @Deprecated
114    public int getResourceCount() {
115        return resourceCount;
116    }
117
118
119    /**
120     * Determine, if this resource has sub-resources.
121     *
122     * @return <code>true</code> if the resource has sub-resources,
123     *         <code>false</code> otherwise
124     */
125    public boolean hasSubResources() {
126        return subResources != null;
127    }
128
129
130    /**
131     * Get the title of this resource.
132     *
133     * @return a Map of titles keyed by language code
134     */
135    public Map<String, String> getTitle() {
136        return title;
137    }
138
139
140    /**
141     * Get the title of the resource for a specific language code.
142     *
143     * @param language
144     *            the language code
145     * @return the title for the language code or <code>null</code> if no title
146     *         for this language code exists
147     */
148    public String getTitle(String language) {
149        return title.get(language);
150    }
151
152
153    /**
154     * Get the description of this resource.
155     *
156     * @return a Map of descriptions keyed by language code
157     */
158    public Map<String, String> getDescription() {
159        return description;
160    }
161
162
163    /**
164     * Get the description of the resource for a specific language code.
165     *
166     * @param language
167     *            the language code
168     * @return the description for the language code or <code>null</code> if no
169     *         title for this language code exists
170     */
171    public String getDescription(String language) {
172        return (description != null) ? description.get(language) : null;
173    }
174
175
176    /**
177     * Get the landing page of this resource.
178     *
179     * @return the landing page of this resource or <code>null</code> if not
180     *         applicable
181     */
182    public String getLandingPageURI() {
183        return landingPageURI;
184    }
185
186
187    /**
188     * Get the list of languages in this resource represented as ISO-632-3 three
189     * letter language code.
190     *
191     * @return the list of languages in this resource as a list of ISO-632-3
192     *         three letter language codes.
193     */
194    public List<String> getLanguages() {
195        return languages;
196    }
197
198
199    /**
200     * Get the direct sub-ordinate resources of this resource.
201     *
202     * @return a list of resources or <code>null</code> if this resource has no
203     *         sub-ordinate resources
204     */
205    public List<ResourceInfo> getSubResources() {
206        return subResources;
207    }
208
209
210        public List<String> getAvailableDataViews() {
211                return availableDataViews;
212        }
213
214
215} // class ResourceInfo
Note: See TracBrowser for help on using the repository browser.