2 * This document is a part of the source code and related artifacts
\r
3 * for CollectionSpace, an open source collections management system
\r
4 * for museums and related institutions:
\r
6 * http://www.collectionspace.org
\r
7 * http://wiki.collectionspace.org
\r
9 * Copyright 2009 University of California at Berkeley
\r
11 * Licensed under the Educational Community License (ECL), Version 2.0.
\r
12 * You may not use this file except in compliance with this License.
\r
14 * You may obtain a copy of the ECL 2.0 License at
\r
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
\r
18 * Unless required by applicable law or agreed to in writing, software
\r
19 * distributed under the License is distributed on an "AS IS" BASIS,
\r
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
21 * See the License for the specific language governing permissions and
\r
22 * limitations under the License.
\r
24 package org.collectionspace.services.vocabulary;
\r
26 import javax.ws.rs.Consumes;
\r
27 import javax.ws.rs.GET;
\r
28 import javax.ws.rs.Path;
\r
29 import javax.ws.rs.Produces;
\r
30 import javax.ws.rs.DELETE;
\r
31 import javax.ws.rs.POST;
\r
32 import javax.ws.rs.PUT;
\r
33 import javax.ws.rs.PathParam;
\r
34 import javax.ws.rs.WebApplicationException;
\r
35 import javax.ws.rs.core.Context;
\r
36 import javax.ws.rs.core.Response;
\r
37 import javax.ws.rs.core.UriBuilder;
\r
38 import javax.ws.rs.core.UriInfo;
\r
39 import javax.xml.bind.JAXBContext;
\r
40 import javax.xml.bind.Marshaller;
\r
42 import org.collectionspace.services.common.vocabulary.VocabManager;
\r
43 import org.slf4j.Logger;
\r
44 import org.slf4j.LoggerFactory;
\r
47 @Consumes("application/xml")
\r
48 @Produces("application/xml")
\r
49 public class VocabResource {
\r
51 public final static String SERVICE_NAME = "vocab";
\r
52 final Logger logger = LoggerFactory.getLogger(VocabResource.class);
\r
54 public VocabResource() {
\r
60 public void getVocab(
\r
61 @PathParam("csid") String csid) {
\r
62 if(logger.isDebugEnabled()){
\r
63 verbose("getVocab with csid=" + csid);
\r
65 if(csid == null || "".equals(csid)){
\r
66 logger.error("getVocab: missing csid!");
\r
67 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
\r
68 "get failed on getVocab csid=" + csid).type(
\r
69 "text/plain").build();
\r
70 throw new WebApplicationException(response);
\r
75 // An example call to the Vocabulary manager
\r
77 VocabManager.exampleMethod("someParam");
\r
78 } catch(Exception e){
\r
79 if(logger.isDebugEnabled()){
\r
80 logger.debug("getVocab", e);
\r
82 Response response = Response.status(Response.Status.NOT_FOUND).entity(
\r
83 "Get failed on vocab csid=" + csid).type(
\r
84 "text/plain").build();
\r
85 throw new WebApplicationException(response);
\r
88 // an example of how to send a failed message
\r
90 Response response = Response.status(Response.Status.NOT_FOUND).entity(
\r
91 "Get failed, the requested CSID:" + csid + ": was not found.").type(
\r
92 "text/plain").build();
\r
93 throw new WebApplicationException(response);
\r
97 private void verbose(String msg) {
\r
98 System.out.println("VocabResource. " + msg);
\r