2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 package org.collectionspace.services.vocabulary;
26 import org.collectionspace.services.client.IClientQueryParams;
27 import org.collectionspace.services.client.PoxPayloadIn;
28 import org.collectionspace.services.client.PoxPayloadOut;
29 import org.collectionspace.services.client.VocabularyClient;
30 import org.collectionspace.services.common.CSWebApplicationException;
31 import org.collectionspace.services.common.ServiceMessages;
32 import org.collectionspace.services.common.UriInfoWrapper;
33 import org.collectionspace.services.common.api.Tools;
34 import org.collectionspace.services.common.context.ServiceBindingUtils;
35 import org.collectionspace.services.common.context.ServiceContext;
36 import org.collectionspace.services.common.vocabulary.AuthorityResource;
37 import org.collectionspace.services.vocabulary.nuxeo.VocabularyItemDocumentModelHandler;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 import javax.ws.rs.GET;
43 import javax.ws.rs.Path;
44 import javax.ws.rs.PathParam;
45 import javax.ws.rs.core.Context;
46 import javax.ws.rs.core.MultivaluedMap;
47 import javax.ws.rs.core.Request;
48 import javax.ws.rs.core.Response;
49 import javax.ws.rs.core.UriInfo;
51 @Path("/" + VocabularyClient.SERVICE_PATH_COMPONENT)
52 public class VocabularyResource extends
53 AuthorityResource<VocabulariesCommon, VocabularyItemDocumentModelHandler> {
55 private final static String vocabularyServiceName = VocabularyClient.SERVICE_PATH_COMPONENT;
57 private final static String VOCABULARIES_COMMON = "vocabularies_common";
59 private final static String vocabularyItemServiceName = "vocabularyitems";
60 private final static String VOCABULARYITEMS_COMMON = "vocabularyitems_common";
62 final Logger logger = LoggerFactory.getLogger(VocabularyResource.class);
64 public VocabularyResource() {
65 super(VocabulariesCommon.class, VocabularyResource.class,
66 VOCABULARIES_COMMON, VOCABULARYITEMS_COMMON);
73 @Context Request request,
74 @Context UriInfo uriInfo,
75 @PathParam("csid") String specifier) {
76 Response result = null;
77 uriInfo = new UriInfoWrapper(uriInfo);
80 MultivaluedMap<String,String> queryParams = uriInfo.getQueryParameters();
81 String showItemsValue = (String)queryParams.getFirst(VocabularyClient.SHOW_ITEMS_QP);
82 boolean showItems = Tools.isTrue(showItemsValue);
83 if (showItems == true) {
85 // We'll honor paging params if we find any; otherwise we'll set the page size to 0 to get ALL the items
87 if (queryParams.containsKey(IClientQueryParams.PAGE_SIZE_PARAM) == false) {
88 queryParams.add(IClientQueryParams.PAGE_SIZE_PARAM, "0");
92 ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(request, uriInfo);
93 PoxPayloadOut payloadout = getAuthority(ctx, request, uriInfo, specifier, showItems);
94 result = buildResponse(ctx, payloadout);
95 } catch (Exception e) {
96 throw bigReThrow(e, ServiceMessages.GET_FAILED, specifier);
100 Response response = Response.status(Response.Status.NOT_FOUND).entity(
101 "GET request failed. The requested Authority specifier:" + specifier + ": was not found.").type(
102 "text/plain").build();
103 throw new CSWebApplicationException(response);
110 public String getServiceName() {
111 return vocabularyServiceName;
115 public String getItemServiceName() {
116 return vocabularyItemServiceName;
120 public Class<VocabulariesCommon> getCommonPartClass() {
121 return VocabulariesCommon.class;
125 * @return the name of the property used to specify references for items in this type of
126 * authority. For most authorities, it is ServiceBindingUtils.AUTH_REF_PROP ("authRef").
127 * Some types (like Vocabulary) use a separate property.
130 protected String getRefPropName() {
131 return ServiceBindingUtils.TERM_REF_PROP;
135 protected String getOrderByField(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx) {
136 String result = null;
138 result = authorityItemCommonSchemaName + ":" + VocabularyItemJAXBSchema.DISPLAY_NAME;
144 protected String getPartialTermMatchField(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx) {
145 return getOrderByField(ctx);
149 * The item schema for the Vocabulary service does not support a multi-valued term list. Only authorities that support
150 * term lists need to implement this method.
153 public String getItemTermInfoGroupXPathBase() {