]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
db1a002c005c6e4426bc2807b4e0f87b3cdb7ddd
[tmp/jakarta-migration.git] /
1 /**
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:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
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.
23  */
24 package org.collectionspace.services.vocabulary;
25
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;
38
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
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;
50
51 @Path("/" + VocabularyClient.SERVICE_PATH_COMPONENT)
52 public class VocabularyResource extends 
53         AuthorityResource<VocabulariesCommon, VocabularyItemDocumentModelHandler> {
54
55     private final static String vocabularyServiceName = VocabularyClient.SERVICE_PATH_COMPONENT;
56
57         private final static String VOCABULARIES_COMMON = "vocabularies_common";
58     
59     private final static String vocabularyItemServiceName = "vocabularyitems";
60         private final static String VOCABULARYITEMS_COMMON = "vocabularyitems_common";
61     
62     final Logger logger = LoggerFactory.getLogger(VocabularyResource.class);
63
64         public VocabularyResource() {
65                 super(VocabulariesCommon.class, VocabularyResource.class,
66                                 VOCABULARIES_COMMON, VOCABULARYITEMS_COMMON);
67         }
68
69     @GET
70     @Path("{csid}")
71     @Override
72     public Response get(
73             @Context Request request,
74             @Context UriInfo uriInfo,
75             @PathParam("csid") String specifier) {
76         Response result = null;
77         uriInfo = new UriInfoWrapper(uriInfo);
78         
79         try {
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) {
84                 //
85                 // We'll honor paging params if we find any; otherwise we'll set the page size to 0 to get ALL the items
86                 //
87                 if (queryParams.containsKey(IClientQueryParams.PAGE_SIZE_PARAM) == false) {
88                         queryParams.add(IClientQueryParams.PAGE_SIZE_PARAM, "0");
89                 }
90             }
91
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);
97         }
98
99         if (result == null) {
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);
104         }
105
106         return result;
107     }
108     
109     @Override
110     public String getServiceName() {
111         return vocabularyServiceName;
112     }
113
114     @Override
115     public String getItemServiceName() {
116         return vocabularyItemServiceName;
117     }
118     
119         @Override
120         public Class<VocabulariesCommon> getCommonPartClass() {
121                 return VocabulariesCommon.class;
122         }
123
124     /**
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.
128      */
129         @Override
130     protected String getRefPropName() {
131         return ServiceBindingUtils.TERM_REF_PROP;
132     }
133         
134         @Override
135         protected String getOrderByField(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx) {
136                 String result = null;
137
138                 result = authorityItemCommonSchemaName + ":" + VocabularyItemJAXBSchema.DISPLAY_NAME;
139
140                 return result;
141         }
142         
143         @Override
144         protected String getPartialTermMatchField(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx) {
145                 return getOrderByField(ctx);
146         }
147
148         /*
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.
151          */
152         @Override
153         public String getItemTermInfoGroupXPathBase() {
154                 return null;
155         }
156 }