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

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

Enabled x-cmd-resource-info

  • Property svn:eol-style set to native
File size: 6.8 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 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<ResourceInfo> subResources) {
55        if (pid == null) {
56            throw new NullPointerException("id == null");
57        }
58        this.pid = pid;
59        this.resourceCount = (resourceCount > 0) ? resourceCount : -1;
60        if (title == null) {
61            throw new NullPointerException("title == null");
62        }
63        if (title.isEmpty()) {
64            throw new IllegalArgumentException("title is empty");
65        }
66        this.title = Collections.unmodifiableMap(title);
67        if ((description != null) && !description.isEmpty()) {
68            this.description = Collections.unmodifiableMap(description);
69        } else {
70            this.description = null;
71        }
72        this.landingPageURI = landingPageURI;
73        if (languages == null) {
74            throw new NullPointerException("languages == null");
75        }
76        if (languages.isEmpty()) {
77            throw new IllegalArgumentException("languages is empty");
78        }
79        this.languages = languages;
80       
81        if ((subResources != null) && !subResources.isEmpty()) {
82            this.subResources = Collections.unmodifiableList(subResources);
83        } else {
84            this.subResources = null;
85        }       
86    }
87
88    public ResourceInfo(String pid, int resourceCount,
89            Map<String, String> title, Map<String, String> description,
90            String landingPageURI, List<String> languages,
91            List<String> availableDataViews,
92            List<ResourceInfo> subResources) {
93        this(pid,resourceCount, title, description, landingPageURI, languages, subResources);
94       
95        if (availableDataViews == null){
96                throw new IllegalArgumentException("available data views == null");
97        }
98        if (availableDataViews.isEmpty()){
99                throw new IllegalArgumentException("available data views are empty");
100        }
101        this.availableDataViews = availableDataViews;       
102    }
103   
104
105    /**
106     * Get the persistent identifier of this resource.
107     *
108     * @return a string representing the persistent identifier of this resource
109     */
110    public String getPid() {
111        return pid;
112    }
113
114
115    /**
116     * Get the number of resources within this resource. If this resource has
117     * sub-ordinate resources, this number should be the sum of all items within
118     * the sub-ordinate resources plus the number of items within this resource.
119     *
120     * @return a number of items or <code>-1</code> if not applicable
121     */
122    @Deprecated
123    public int getResourceCount() {
124        return resourceCount;
125    }
126
127
128    /**
129     * Determine, if this resource has sub-resources.
130     *
131     * @return <code>true</code> if the resource has sub-resources,
132     *         <code>false</code> otherwise
133     */
134    public boolean hasSubResources() {
135        return subResources != null;
136    }
137
138
139    /**
140     * Get the title of this resource.
141     *
142     * @return a Map of titles keyed by language code
143     */
144    public Map<String, String> getTitle() {
145        return title;
146    }
147
148
149    /**
150     * Get the title of the resource for a specific language code.
151     *
152     * @param language
153     *            the language code
154     * @return the title for the language code or <code>null</code> if no title
155     *         for this language code exists
156     */
157    public String getTitle(String language) {
158        return title.get(language);
159    }
160
161
162    /**
163     * Get the description of this resource.
164     *
165     * @return a Map of descriptions keyed by language code
166     */
167    public Map<String, String> getDescription() {
168        return description;
169    }
170
171
172    /**
173     * Get the description of the resource for a specific language code.
174     *
175     * @param language
176     *            the language code
177     * @return the description for the language code or <code>null</code> if no
178     *         title for this language code exists
179     */
180    public String getDescription(String language) {
181        return (description != null) ? description.get(language) : null;
182    }
183
184
185    /**
186     * Get the landing page of this resource.
187     *
188     * @return the landing page of this resource or <code>null</code> if not
189     *         applicable
190     */
191    public String getLandingPageURI() {
192        return landingPageURI;
193    }
194
195
196    /**
197     * Get the list of languages in this resource represented as ISO-632-3 three
198     * letter language code.
199     *
200     * @return the list of languages in this resource as a list of ISO-632-3
201     *         three letter language codes.
202     */
203    public List<String> getLanguages() {
204        return languages;
205    }
206
207
208    /**
209     * Get the direct sub-ordinate resources of this resource.
210     *
211     * @return a list of resources or <code>null</code> if this resource has no
212     *         sub-ordinate resources
213     */
214    public List<ResourceInfo> getSubResources() {
215        return subResources;
216    }
217
218
219        public List<String> getAvailableDataViews() {
220                return availableDataViews;
221        }
222
223
224} // class ResourceInfo
Note: See TracBrowser for help on using the repository browser.