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.PoxPayloadIn;
27 import org.collectionspace.services.client.PoxPayloadOut;
28 import org.collectionspace.services.client.VocabularyClient;
29 import org.collectionspace.services.common.CSWebApplicationException;
30 import org.collectionspace.services.common.ServiceMessages;
31 import org.collectionspace.services.common.UriInfoWrapper;
32 import org.collectionspace.services.common.api.Tools;
33 import org.collectionspace.services.common.context.ServiceBindingUtils;
34 import org.collectionspace.services.common.context.ServiceContext;
35 import org.collectionspace.services.common.vocabulary.AuthorityResource;
36 import org.collectionspace.services.vocabulary.nuxeo.VocabularyItemDocumentModelHandler;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 import javax.ws.rs.GET;
42 import javax.ws.rs.Path;
43 import javax.ws.rs.PathParam;
44 import javax.ws.rs.core.Context;
45 import javax.ws.rs.core.MultivaluedMap;
46 import javax.ws.rs.core.Request;
47 import javax.ws.rs.core.Response;
48 import javax.ws.rs.core.UriInfo;
50 @Path("/" + VocabularyClient.SERVICE_PATH_COMPONENT)
51 public class VocabularyResource extends
52 AuthorityResource<VocabulariesCommon, VocabularyItemDocumentModelHandler> {
54 private final static String vocabularyServiceName = VocabularyClient.SERVICE_PATH_COMPONENT;
56 private final static String VOCABULARIES_COMMON = "vocabularies_common";
58 private final static String vocabularyItemServiceName = "vocabularyitems";
59 private final static String VOCABULARYITEMS_COMMON = "vocabularyitems_common";
61 final Logger logger = LoggerFactory.getLogger(VocabularyResource.class);
63 public VocabularyResource() {
64 super(VocabulariesCommon.class, VocabularyResource.class,
65 VOCABULARIES_COMMON, VOCABULARYITEMS_COMMON);
72 @Context Request request,
73 @Context UriInfo uriInfo,
74 @PathParam("csid") String specifier) {
75 Response result = null;
76 uriInfo = new UriInfoWrapper(uriInfo);
79 MultivaluedMap<String,String> queryParams = uriInfo.getQueryParameters();
80 String showItemsValue = (String)queryParams.getFirst(VocabularyClient.SHOW_ITEMS_QP);
81 boolean showItems = Tools.isTrue(showItemsValue);
83 ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(request, uriInfo);
84 PoxPayloadOut payloadout = getAuthority(ctx, request, uriInfo, specifier, showItems);
85 result = buildResponse(ctx, payloadout);
86 } catch (Exception e) {
87 throw bigReThrow(e, ServiceMessages.GET_FAILED, specifier);
91 Response response = Response.status(Response.Status.NOT_FOUND).entity(
92 "GET request failed. The requested Authority specifier:" + specifier + ": was not found.").type(
93 "text/plain").build();
94 throw new CSWebApplicationException(response);
101 public String getServiceName() {
102 return vocabularyServiceName;
106 public String getItemServiceName() {
107 return vocabularyItemServiceName;
111 public Class<VocabulariesCommon> getCommonPartClass() {
112 return VocabulariesCommon.class;
116 * @return the name of the property used to specify references for items in this type of
117 * authority. For most authorities, it is ServiceBindingUtils.AUTH_REF_PROP ("authRef").
118 * Some types (like Vocabulary) use a separate property.
121 protected String getRefPropName() {
122 return ServiceBindingUtils.TERM_REF_PROP;
126 protected String getOrderByField(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx) {
127 String result = null;
129 result = authorityItemCommonSchemaName + ":" + VocabularyItemJAXBSchema.DISPLAY_NAME;
135 protected String getPartialTermMatchField(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx) {
136 return getOrderByField(ctx);
140 * The item schema for the Vocabulary service does not support a multi-valued term list. Only authorities that support
141 * term lists need to implement this method.
144 public String getItemTermInfoGroupXPathBase() {