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 javax.ws.rs.Consumes;
27 import javax.ws.rs.DELETE;
28 import javax.ws.rs.GET;
29 import javax.ws.rs.POST;
30 import javax.ws.rs.PUT;
31 import javax.ws.rs.Path;
32 import javax.ws.rs.PathParam;
33 import javax.ws.rs.Produces;
34 import javax.ws.rs.QueryParam;
35 import javax.ws.rs.WebApplicationException;
36 import javax.ws.rs.core.Context;
37 import javax.ws.rs.core.MultivaluedMap;
38 import javax.ws.rs.core.Response;
39 import javax.ws.rs.core.UriBuilder;
40 import javax.ws.rs.core.UriInfo;
42 import org.collectionspace.services.VocabularyItemJAXBSchema;
43 import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
44 import org.collectionspace.services.common.ClientType;
45 import org.collectionspace.services.common.ServiceMain;
46 import org.collectionspace.services.common.context.MultipartServiceContext;
47 import org.collectionspace.services.common.context.MultipartServiceContextFactory;
48 import org.collectionspace.services.common.context.ServiceContext;
49 import org.collectionspace.services.common.document.BadRequestException;
50 import org.collectionspace.services.common.document.DocumentFilter;
51 import org.collectionspace.services.common.document.DocumentHandler;
52 import org.collectionspace.services.common.document.DocumentNotFoundException;
53 import org.collectionspace.services.common.security.UnauthorizedException;
54 import org.collectionspace.services.common.query.IQueryManager;
55 import org.collectionspace.services.vocabulary.nuxeo.VocabularyItemDocumentModelHandler;
56 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
57 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
58 import org.jboss.resteasy.util.HttpResponseCodes;
59 import org.slf4j.Logger;
60 import org.slf4j.LoggerFactory;
63 * The Class VocabularyResource.
65 @Path("/vocabularies")
66 @Consumes("multipart/mixed")
67 @Produces("multipart/mixed")
68 public class VocabularyResource extends
69 AbstractMultiPartCollectionSpaceResourceImpl {
71 /** The Constant vocabularyServiceName. */
72 private final static String vocabularyServiceName = "vocabularies";
74 /** The Constant vocabularyItemServiceName. */
75 private final static String vocabularyItemServiceName = "vocabularyitems";
78 final Logger logger = LoggerFactory.getLogger(VocabularyResource.class);
79 //FIXME retrieve client type from configuration
80 /** The Constant CLIENT_TYPE. */
81 final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType();
84 * Instantiates a new vocabulary resource.
86 public VocabularyResource() {
91 * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
94 protected String getVersionString() {
95 /** The last change revision. */
96 final String lastChangeRevision = "$LastChangedRevision$";
97 return lastChangeRevision;
101 * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
104 public String getServiceName() {
105 return vocabularyServiceName;
109 * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
112 public Class<VocabulariesCommon> getCommonPartClass() {
113 return VocabulariesCommon.class;
117 * Gets the item service name.
119 * @return the item service name
121 public String getItemServiceName() {
122 return vocabularyItemServiceName;
126 public RemoteServiceContext createItemServiceContext(MultipartInput input) throws Exception {
127 RemoteServiceContext ctx = new RemoteServiceContextImpl(getItemServiceName());
133 // public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
134 // DocumentHandler docHandler = ctx.getDocumentHandler();
135 // if (ctx.getInput() != null) {
136 // Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), VocabulariesCommon.class);
137 // if (obj != null) {
138 // docHandler.setCommonPart((VocabulariesCommon) obj);
141 // return docHandler;
145 // public DocumentHandler createDocumentHandler(ServiceContext ctx)
146 // throws Exception {
147 // DocumentHandler docHandler = createDocumentHandler(ctx, VocabulariesCommon.class);
148 // return docHandler;
152 * Creates the item document handler.
155 * @param inVocabulary the in vocabulary
157 * @return the document handler
159 * @throws Exception the exception
161 private DocumentHandler createItemDocumentHandler(
162 ServiceContext<MultipartInput, MultipartOutput> ctx,
165 VocabularyItemDocumentModelHandler docHandler;
167 docHandler = (VocabularyItemDocumentModelHandler)createDocumentHandler(ctx,
168 ctx.getCommonPartLabel(getItemServiceName()),
169 VocabularyitemsCommon.class);
170 docHandler.setInVocabulary(inVocabulary);
176 * Creates the vocabulary.
178 * @param input the input
180 * @return the response
183 public Response createVocabulary(MultipartInput input) {
185 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(input);
186 DocumentHandler handler = createDocumentHandler(ctx);
187 String csid = getRepositoryClient(ctx).create(ctx, handler);
188 //vocabularyObject.setCsid(csid);
189 UriBuilder path = UriBuilder.fromResource(VocabularyResource.class);
190 path.path("" + csid);
191 Response response = Response.created(path.build()).build();
193 } catch (UnauthorizedException ue) {
194 Response response = Response.status(
195 Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build();
196 throw new WebApplicationException(response);
197 } catch (Exception e) {
198 if (logger.isDebugEnabled()) {
199 logger.debug("Caught exception in createVocabulary", e);
201 Response response = Response.status(
202 Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
203 throw new WebApplicationException(response);
208 * Gets the vocabulary.
210 * @param csid the csid
212 * @return the vocabulary
216 public MultipartOutput getVocabulary(@PathParam("csid") String csid) {
217 String idValue = null;
219 logger.error("getVocabulary: missing csid!");
220 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
221 "get failed on Vocabulary csid=" + csid).type(
222 "text/plain").build();
223 throw new WebApplicationException(response);
225 if (logger.isDebugEnabled()) {
226 logger.debug("getVocabulary with path(id)=" + csid);
228 MultipartOutput result = null;
230 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
231 DocumentHandler handler = createDocumentHandler(ctx);
232 getRepositoryClient(ctx).get(ctx, csid, handler);
233 result = (MultipartOutput) ctx.getOutput();
234 } catch (UnauthorizedException ue) {
235 Response response = Response.status(
236 Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
237 throw new WebApplicationException(response);
238 } catch (DocumentNotFoundException dnfe) {
239 if (logger.isDebugEnabled()) {
240 logger.debug("getVocabulary", dnfe);
242 Response response = Response.status(Response.Status.NOT_FOUND).entity(
243 "Get failed on Vocabulary csid=" + csid).type(
244 "text/plain").build();
245 throw new WebApplicationException(response);
246 } catch (Exception e) {
247 if (logger.isDebugEnabled()) {
248 logger.debug("getVocabulary", e);
250 Response response = Response.status(
251 Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
252 throw new WebApplicationException(response);
255 if (result == null) {
256 Response response = Response.status(Response.Status.NOT_FOUND).entity(
257 "Get failed, the requested Vocabulary CSID:" + csid + ": was not found.").type(
258 "text/plain").build();
259 throw new WebApplicationException(response);
266 * Gets the vocabulary list.
270 * @return the vocabulary list
273 @Produces("application/xml")
274 public VocabulariesCommonList getVocabularyList(@Context UriInfo ui) {
275 VocabulariesCommonList vocabularyObjectList = new VocabulariesCommonList();
277 MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
278 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
279 DocumentHandler handler = createDocumentHandler(ctx);
280 // DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
281 DocumentFilter myFilter = handler.getDocumentFilter();
282 // myFilter.setPagination(queryParams);
283 String nameQ = queryParams.getFirst("refName");
285 myFilter.setWhereClause("vocabularies_common:refName='" + nameQ + "'");
287 // handler.setDocumentFilter(myFilter);
288 getRepositoryClient(ctx).getFiltered(ctx, handler);
289 vocabularyObjectList = (VocabulariesCommonList) handler.getCommonPartList();
290 } catch (UnauthorizedException ue) {
291 Response response = Response.status(
292 Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
293 throw new WebApplicationException(response);
294 } catch (Exception e) {
295 if (logger.isDebugEnabled()) {
296 logger.debug("Caught exception in getVocabularyList", e);
298 Response response = Response.status(
299 Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
300 throw new WebApplicationException(response);
302 return vocabularyObjectList;
308 * @param csid the csid
309 * @param theUpdate the the update
311 * @return the multipart output
315 public MultipartOutput updateVocabulary(
316 @PathParam("csid") String csid,
317 MultipartInput theUpdate) {
318 if (logger.isDebugEnabled()) {
319 logger.debug("updateVocabulary with csid=" + csid);
321 if (csid == null || "".equals(csid)) {
322 logger.error("updateVocabulary: missing csid!");
323 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
324 "update failed on Vocabulary csid=" + csid).type(
325 "text/plain").build();
326 throw new WebApplicationException(response);
328 MultipartOutput result = null;
330 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(theUpdate);
331 DocumentHandler handler = createDocumentHandler(ctx);
332 getRepositoryClient(ctx).update(ctx, csid, handler);
333 result = (MultipartOutput) ctx.getOutput();
334 } catch (UnauthorizedException ue) {
335 Response response = Response.status(
336 Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build();
337 throw new WebApplicationException(response);
338 } catch (DocumentNotFoundException dnfe) {
339 if (logger.isDebugEnabled()) {
340 logger.debug("caugth exception in updateVocabulary", dnfe);
342 Response response = Response.status(Response.Status.NOT_FOUND).entity(
343 "Update failed on Vocabulary csid=" + csid).type(
344 "text/plain").build();
345 throw new WebApplicationException(response);
346 } catch (Exception e) {
347 Response response = Response.status(
348 Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
349 throw new WebApplicationException(response);
357 * @param csid the csid
359 * @return the response
363 public Response deleteVocabulary(@PathParam("csid") String csid) {
365 if (logger.isDebugEnabled()) {
366 logger.debug("deleteVocabulary with csid=" + csid);
368 if (csid == null || "".equals(csid)) {
369 logger.error("deleteVocabulary: missing csid!");
370 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
371 "delete failed on Vocabulary csid=" + csid).type(
372 "text/plain").build();
373 throw new WebApplicationException(response);
376 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
377 getRepositoryClient(ctx).delete(ctx, csid);
378 return Response.status(HttpResponseCodes.SC_OK).build();
379 } catch (UnauthorizedException ue) {
380 Response response = Response.status(
381 Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build();
382 throw new WebApplicationException(response);
383 } catch (DocumentNotFoundException dnfe) {
384 if (logger.isDebugEnabled()) {
385 logger.debug("caught exception in deleteVocabulary", dnfe);
387 Response response = Response.status(Response.Status.NOT_FOUND).entity(
388 "Delete failed on Vocabulary csid=" + csid).type(
389 "text/plain").build();
390 throw new WebApplicationException(response);
391 } catch (Exception e) {
392 Response response = Response.status(
393 Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
394 throw new WebApplicationException(response);
399 /*************************************************************************
400 * VocabularyItem parts - this is a sub-resource of Vocabulary
401 *************************************************************************/
403 @Path("{csid}/items")
404 public Response createVocabularyItem(@PathParam("csid") String parentcsid, MultipartInput input) {
406 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
408 DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
409 String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
410 UriBuilder path = UriBuilder.fromResource(VocabularyResource.class);
411 path.path(parentcsid + "/items/" + itemcsid);
412 Response response = Response.created(path.build()).build();
414 } catch (BadRequestException bre) {
415 Response response = Response.status(
416 Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
417 throw new WebApplicationException(response);
418 } catch (UnauthorizedException ue) {
419 Response response = Response.status(
420 Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build();
421 throw new WebApplicationException(response);
422 } catch (Exception e) {
423 if (logger.isDebugEnabled()) {
424 logger.debug("Caught exception in createVocabularyItem", e);
426 Response response = Response.status(
427 Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
428 throw new WebApplicationException(response);
433 * Gets the vocabulary item.
435 * @param parentcsid the parentcsid
436 * @param itemcsid the itemcsid
438 * @return the vocabulary item
441 @Path("{csid}/items/{itemcsid}")
442 public MultipartOutput getVocabularyItem(
443 @PathParam("csid") String parentcsid,
444 @PathParam("itemcsid") String itemcsid) {
445 if (logger.isDebugEnabled()) {
446 logger.debug("getVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
448 if (parentcsid == null || "".equals(parentcsid)) {
449 logger.error("getVocabularyItem: missing csid!");
450 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
451 "get failed on VocabularyItem csid=" + parentcsid).type(
452 "text/plain").build();
453 throw new WebApplicationException(response);
455 if (itemcsid == null || "".equals(itemcsid)) {
456 logger.error("getVocabularyItem: missing itemcsid!");
457 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
458 "get failed on VocabularyItem itemcsid=" + itemcsid).type(
459 "text/plain").build();
460 throw new WebApplicationException(response);
462 MultipartOutput result = null;
464 // Note that we have to create the service context for the Items, not the main service
465 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
466 DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
467 getRepositoryClient(ctx).get(ctx, itemcsid, handler);
468 // TODO should we assert that the item is in the passed vocab?
469 result = (MultipartOutput) ctx.getOutput();
470 } catch (UnauthorizedException ue) {
471 Response response = Response.status(
472 Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
473 throw new WebApplicationException(response);
474 } catch (DocumentNotFoundException dnfe) {
475 if (logger.isDebugEnabled()) {
476 logger.debug("getVocabularyItem", dnfe);
478 Response response = Response.status(Response.Status.NOT_FOUND).entity(
479 "Get failed on VocabularyItem csid=" + itemcsid).type(
480 "text/plain").build();
481 throw new WebApplicationException(response);
482 } catch (Exception e) {
483 if (logger.isDebugEnabled()) {
484 logger.debug("getVocabularyItem", e);
486 Response response = Response.status(
487 Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
488 throw new WebApplicationException(response);
490 if (result == null) {
491 Response response = Response.status(Response.Status.NOT_FOUND).entity(
492 "Get failed, the requested VocabularyItem CSID:" + itemcsid + ": was not found.").type(
493 "text/plain").build();
494 throw new WebApplicationException(response);
500 * Gets the vocabulary item list.
502 * @param parentcsid the parentcsid
503 * @param partialTerm the partial term
506 * @return the vocabulary item list
509 @Path("{csid}/items")
510 @Produces("application/xml")
511 public VocabularyitemsCommonList getVocabularyItemList(
512 @PathParam("csid") String parentcsid,
513 @QueryParam(IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
514 @Context UriInfo ui) {
515 VocabularyitemsCommonList vocabularyItemObjectList = new VocabularyitemsCommonList();
517 MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
518 // Note that docType defaults to the ServiceName, so we're fine with that.
519 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
521 DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
522 // DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
523 DocumentFilter myFilter = handler.getDocumentFilter(); //new DocumentFilter();
524 // myFilter.setPagination(queryParams);
525 // "vocabularyitems_common:inVocabulary='" + parentcsid + "'");
526 myFilter.setWhereClause(
527 VocabularyItemJAXBSchema.VOCABULARYITEMS_COMMON + ":"
528 + VocabularyItemJAXBSchema.IN_VOCABULARY + "="
529 + "'" + parentcsid + "'");
531 // AND vocabularyitems_common:displayName LIKE '%partialTerm%'
532 if (partialTerm != null && !partialTerm.isEmpty()) {
533 String ptClause = "AND "
534 + VocabularyItemJAXBSchema.VOCABULARYITEMS_COMMON + ":"
535 + VocabularyItemJAXBSchema.DISPLAY_NAME
537 + "'%" + partialTerm + "%'";
538 myFilter.appendWhereClause(ptClause);
541 if (logger.isDebugEnabled()) {
542 logger.debug("getVocabularyItemList filtered WHERE clause: "
543 + myFilter.getWhereClause());
546 handler.setDocumentFilter(myFilter);
547 getRepositoryClient(ctx).getFiltered(ctx, handler);
549 vocabularyItemObjectList = (VocabularyitemsCommonList) handler.getCommonPartList();
550 } catch (UnauthorizedException ue) {
551 Response response = Response.status(
552 Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
553 throw new WebApplicationException(response);
554 } catch (Exception e) {
555 if (logger.isDebugEnabled()) {
556 logger.debug("Caught exception in getVocabularyItemList", e);
558 Response response = Response.status(
559 Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
560 throw new WebApplicationException(response);
562 return vocabularyItemObjectList;
566 * Update vocabulary item.
568 * @param parentcsid the parentcsid
569 * @param itemcsid the itemcsid
570 * @param theUpdate the the update
572 * @return the multipart output
575 @Path("{csid}/items/{itemcsid}")
576 public MultipartOutput updateVocabularyItem(
577 @PathParam("csid") String parentcsid,
578 @PathParam("itemcsid") String itemcsid,
579 MultipartInput theUpdate) {
580 if (logger.isDebugEnabled()) {
581 logger.debug("updateVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
583 if (parentcsid == null || "".equals(parentcsid)) {
584 logger.error("updateVocabularyItem: missing csid!");
585 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
586 "update failed on VocabularyItem parentcsid=" + parentcsid).type(
587 "text/plain").build();
588 throw new WebApplicationException(response);
590 if (itemcsid == null || "".equals(itemcsid)) {
591 logger.error("updateVocabularyItem: missing itemcsid!");
592 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
593 "update failed on VocabularyItem=" + itemcsid).type(
594 "text/plain").build();
595 throw new WebApplicationException(response);
597 MultipartOutput result = null;
599 // Note that we have to create the service context for the Items, not the main service
600 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
602 DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
603 getRepositoryClient(ctx).update(ctx, itemcsid, handler);
604 result = (MultipartOutput) ctx.getOutput();
605 } catch (BadRequestException bre) {
606 Response response = Response.status(
607 Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
608 throw new WebApplicationException(response);
609 } catch (UnauthorizedException ue) {
610 Response response = Response.status(
611 Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build();
612 throw new WebApplicationException(response);
613 } catch (DocumentNotFoundException dnfe) {
614 if (logger.isDebugEnabled()) {
615 logger.debug("caught DNF exception in updateVocabularyItem", dnfe);
617 Response response = Response.status(Response.Status.NOT_FOUND).entity(
618 "Update failed on VocabularyItem csid=" + itemcsid).type(
619 "text/plain").build();
620 throw new WebApplicationException(response);
621 } catch (Exception e) {
622 Response response = Response.status(
623 Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
624 throw new WebApplicationException(response);
630 * Delete vocabulary item.
632 * @param parentcsid the parentcsid
633 * @param itemcsid the itemcsid
635 * @return the response
638 @Path("{csid}/items/{itemcsid}")
639 public Response deleteVocabularyItem(
640 @PathParam("csid") String parentcsid,
641 @PathParam("itemcsid") String itemcsid) {
642 if (logger.isDebugEnabled()) {
643 logger.debug("deleteVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
645 if (parentcsid == null || "".equals(parentcsid)) {
646 logger.error("deleteVocabularyItem: missing csid!");
647 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
648 "delete failed on VocabularyItem parentcsid=" + parentcsid).type(
649 "text/plain").build();
650 throw new WebApplicationException(response);
652 if (itemcsid == null || "".equals(itemcsid)) {
653 logger.error("deleteVocabularyItem: missing itemcsid!");
654 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
655 "delete failed on VocabularyItem=" + itemcsid).type(
656 "text/plain").build();
657 throw new WebApplicationException(response);
660 // Note that we have to create the service context for the Items, not the main service
661 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
662 getRepositoryClient(ctx).delete(ctx, itemcsid);
663 return Response.status(HttpResponseCodes.SC_OK).build();
664 } catch (UnauthorizedException ue) {
665 Response response = Response.status(
666 Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build();
667 throw new WebApplicationException(response);
668 } catch (DocumentNotFoundException dnfe) {
669 if (logger.isDebugEnabled()) {
670 logger.debug("caught exception in deleteVocabulary", dnfe);
672 Response response = Response.status(Response.Status.NOT_FOUND).entity(
673 "Delete failed on VocabularyItem itemcsid=" + itemcsid).type(
674 "text/plain").build();
675 throw new WebApplicationException(response);
676 } catch (Exception e) {
677 Response response = Response.status(
678 Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
679 throw new WebApplicationException(response);