]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
30a48c913583717cd451763abc00fc5da535ede1
[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.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;
37
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
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;
49
50 @Path("/" + VocabularyClient.SERVICE_PATH_COMPONENT)
51 public class VocabularyResource extends 
52         AuthorityResource<VocabulariesCommon, VocabularyItemDocumentModelHandler> {
53
54     private final static String vocabularyServiceName = VocabularyClient.SERVICE_PATH_COMPONENT;
55
56         private final static String VOCABULARIES_COMMON = "vocabularies_common";
57     
58     private final static String vocabularyItemServiceName = "vocabularyitems";
59         private final static String VOCABULARYITEMS_COMMON = "vocabularyitems_common";
60     
61     final Logger logger = LoggerFactory.getLogger(VocabularyResource.class);
62
63         public VocabularyResource() {
64                 super(VocabulariesCommon.class, VocabularyResource.class,
65                                 VOCABULARIES_COMMON, VOCABULARYITEMS_COMMON);
66         }
67
68     @GET
69     @Path("{csid}")
70     @Override
71     public Response get(
72             @Context Request request,
73             @Context UriInfo uriInfo,
74             @PathParam("csid") String specifier) {
75         Response result = null;
76         uriInfo = new UriInfoWrapper(uriInfo);
77         
78         try {
79                 MultivaluedMap<String,String> queryParams = uriInfo.getQueryParameters();
80                 String showItemsValue = (String)queryParams.getFirst(VocabularyClient.SHOW_ITEMS_QP);
81             boolean showItems = Tools.isTrue(showItemsValue);
82
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);
88         }
89
90         if (result == null) {
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);
95         }
96
97         return result;
98     }
99     
100     @Override
101     public String getServiceName() {
102         return vocabularyServiceName;
103     }
104
105     @Override
106     public String getItemServiceName() {
107         return vocabularyItemServiceName;
108     }
109     
110         @Override
111         public Class<VocabulariesCommon> getCommonPartClass() {
112                 return VocabulariesCommon.class;
113         }
114
115     /**
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.
119      */
120         @Override
121     protected String getRefPropName() {
122         return ServiceBindingUtils.TERM_REF_PROP;
123     }
124         
125         @Override
126         protected String getOrderByField(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx) {
127                 String result = null;
128
129                 result = authorityItemCommonSchemaName + ":" + VocabularyItemJAXBSchema.DISPLAY_NAME;
130
131                 return result;
132         }
133         
134         @Override
135         protected String getPartialTermMatchField(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx) {
136                 return getOrderByField(ctx);
137         }
138
139         /*
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.
142          */
143         @Override
144         public String getItemTermInfoGroupXPathBase() {
145                 return null;
146         }
147 }