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.VocabularyJAXBSchema;
43 import org.collectionspace.services.VocabularyItemJAXBSchema;
44 import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
45 import org.collectionspace.services.common.ClientType;
46 import org.collectionspace.services.common.ServiceMain;
47 import org.collectionspace.services.common.context.ServiceContext;
48 import org.collectionspace.services.common.document.BadRequestException;
49 import org.collectionspace.services.common.document.DocumentFilter;
50 import org.collectionspace.services.common.document.DocumentHandler;
51 import org.collectionspace.services.common.document.DocumentNotFoundException;
52 import org.collectionspace.services.common.security.UnauthorizedException;
53 import org.collectionspace.services.common.query.IQueryManager;
54 import org.collectionspace.services.vocabulary.nuxeo.VocabularyItemDocumentModelHandler;
55 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
56 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
57 import org.jboss.resteasy.util.HttpResponseCodes;
58 import org.slf4j.Logger;
59 import org.slf4j.LoggerFactory;
62 * The Class VocabularyResource.
64 @Path("/vocabularies")
65 @Consumes("multipart/mixed")
66 @Produces("multipart/mixed")
67 public class VocabularyResource extends
68 AbstractMultiPartCollectionSpaceResourceImpl {
70 /** The Constant vocabularyServiceName. */
71 private final static String vocabularyServiceName = "vocabularies";
73 /** The Constant vocabularyItemServiceName. */
74 private final static String vocabularyItemServiceName = "vocabularyitems";
77 final Logger logger = LoggerFactory.getLogger(VocabularyResource.class);
78 //FIXME retrieve client type from configuration
79 /** The Constant CLIENT_TYPE. */
80 final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType();
83 * Instantiates a new vocabulary resource.
85 public VocabularyResource() {
90 * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
93 protected String getVersionString() {
94 /** The last change revision. */
95 final String lastChangeRevision = "$LastChangedRevision$";
96 return lastChangeRevision;
100 * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
103 public String getServiceName() {
104 return vocabularyServiceName;
108 * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
111 public Class<VocabulariesCommon> getCommonPartClass() {
112 return VocabulariesCommon.class;
116 * Gets the item service name.
118 * @return the item service name
120 public String getItemServiceName() {
121 return vocabularyItemServiceName;
125 * Creates the item document handler.
128 * @param inVocabulary the in vocabulary
130 * @return the document handler
132 * @throws Exception the exception
134 private DocumentHandler createItemDocumentHandler(
135 ServiceContext<MultipartInput, MultipartOutput> ctx,
138 VocabularyItemDocumentModelHandler docHandler;
140 docHandler = (VocabularyItemDocumentModelHandler)createDocumentHandler(ctx,
141 ctx.getCommonPartLabel(getItemServiceName()),
142 VocabularyitemsCommon.class);
143 docHandler.setInVocabulary(inVocabulary);
149 * Creates the vocabulary.
151 * @param input the input
153 * @return the response
156 public Response createVocabulary(MultipartInput input) {
158 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(input);
159 DocumentHandler handler = createDocumentHandler(ctx);
160 String csid = getRepositoryClient(ctx).create(ctx, handler);
161 //vocabularyObject.setCsid(csid);
162 UriBuilder path = UriBuilder.fromResource(VocabularyResource.class);
163 path.path("" + csid);
164 Response response = Response.created(path.build()).build();
166 } catch (BadRequestException bre) {
167 Response response = Response.status(
168 Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
169 throw new WebApplicationException(response);
170 } catch (UnauthorizedException ue) {
171 Response response = Response.status(
172 Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build();
173 throw new WebApplicationException(response);
174 } catch (Exception e) {
175 if (logger.isDebugEnabled()) {
176 logger.debug("Caught exception in createVocabulary", e);
178 Response response = Response.status(
179 Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
180 throw new WebApplicationException(response);
185 * Gets the vocabulary.
187 * @param csid the csid
189 * @return the vocabulary
193 public MultipartOutput getVocabulary(@PathParam("csid") String csid) {
194 // String idValue = null;
196 logger.error("getVocabulary: missing csid!");
197 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
198 "get failed on Vocabulary csid=" + csid).type(
199 "text/plain").build();
200 throw new WebApplicationException(response);
202 if (logger.isDebugEnabled()) {
203 logger.debug("getVocabulary with path(id)=" + csid);
205 MultipartOutput result = null;
207 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
208 DocumentHandler handler = createDocumentHandler(ctx);
209 getRepositoryClient(ctx).get(ctx, csid, handler);
210 result = (MultipartOutput) ctx.getOutput();
211 } catch (UnauthorizedException ue) {
212 Response response = Response.status(
213 Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
214 throw new WebApplicationException(response);
215 } catch (DocumentNotFoundException dnfe) {
216 if (logger.isDebugEnabled()) {
217 logger.debug("getVocabulary", dnfe);
219 Response response = Response.status(Response.Status.NOT_FOUND).entity(
220 "Get failed on Vocabulary csid=" + csid).type(
221 "text/plain").build();
222 throw new WebApplicationException(response);
223 } catch (Exception e) {
224 if (logger.isDebugEnabled()) {
225 logger.debug("getVocabulary", e);
227 Response response = Response.status(
228 Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
229 throw new WebApplicationException(response);
232 if (result == null) {
233 Response response = Response.status(Response.Status.NOT_FOUND).entity(
234 "Get failed, the requested Vocabulary CSID:" + csid + ": was not found.").type(
235 "text/plain").build();
236 throw new WebApplicationException(response);
243 * Gets the vocabulary by name.
245 * @param specifier the specifier
247 * @return the vocabulary
250 @Path("urn:cspace:name({specifier})")
251 public MultipartOutput getVocabularyByName(@PathParam("specifier") String specifier) {
252 if (specifier == null) {
253 logger.error("getVocabularyByName: missing name!");
254 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
255 "get failed on Vocabulary (missing specifier)").type(
256 "text/plain").build();
257 throw new WebApplicationException(response);
260 VocabularyJAXBSchema.VOCABULARIES_COMMON+
261 ":"+VocabularyJAXBSchema.SHORT_IDENTIFIER+
263 // We only get a single doc - if there are multiple,
264 // it is an error in use.
266 if (logger.isDebugEnabled()) {
267 logger.debug("getVocabularyByName with name=" + specifier);
269 MultipartOutput result = null;
271 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
272 DocumentHandler handler = createDocumentHandler(ctx);
273 DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1);
274 handler.setDocumentFilter(myFilter);
275 getRepositoryClient(ctx).get(ctx, handler);
276 result = (MultipartOutput) ctx.getOutput();
277 } catch (UnauthorizedException ue) {
278 Response response = Response.status(
279 Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
280 throw new WebApplicationException(response);
281 } catch (DocumentNotFoundException dnfe) {
282 if (logger.isDebugEnabled()) {
283 logger.debug("getVocabularyByName", dnfe);
285 Response response = Response.status(Response.Status.NOT_FOUND).entity(
286 "Get failed on Vocabulary spec=" + specifier).type(
287 "text/plain").build();
288 throw new WebApplicationException(response);
289 } catch (Exception e) {
290 if (logger.isDebugEnabled()) {
291 logger.debug("getVocabularyByName", e);
293 Response response = Response.status(
294 Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
295 throw new WebApplicationException(response);
297 if (result == null) {
298 Response response = Response.status(Response.Status.NOT_FOUND).entity(
299 "Get failed, the requested Vocabulary spec:" + specifier + ": was not found.").type(
300 "text/plain").build();
301 throw new WebApplicationException(response);
307 * Gets the vocabulary list.
311 * @return the vocabulary list
314 @Produces("application/xml")
315 public VocabulariesCommonList getVocabularyList(@Context UriInfo ui) {
316 VocabulariesCommonList vocabularyObjectList = new VocabulariesCommonList();
318 MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
319 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
320 DocumentHandler handler = createDocumentHandler(ctx);
321 DocumentFilter myFilter = handler.getDocumentFilter();
322 String nameQ = queryParams.getFirst("refName");
324 myFilter.setWhereClause("vocabularies_common:refName='" + nameQ + "'");
326 getRepositoryClient(ctx).getFiltered(ctx, handler);
327 vocabularyObjectList = (VocabulariesCommonList) handler.getCommonPartList();
328 } catch (UnauthorizedException ue) {
329 Response response = Response.status(
330 Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
331 throw new WebApplicationException(response);
332 } catch (Exception e) {
333 if (logger.isDebugEnabled()) {
334 logger.debug("Caught exception in getVocabularyList", e);
336 Response response = Response.status(
337 Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
338 throw new WebApplicationException(response);
340 return vocabularyObjectList;
346 * @param csid the csid
347 * @param theUpdate the the update
349 * @return the multipart output
353 public MultipartOutput updateVocabulary(
354 @PathParam("csid") String csid,
355 MultipartInput theUpdate) {
356 if (logger.isDebugEnabled()) {
357 logger.debug("updateVocabulary with csid=" + csid);
359 if (csid == null || "".equals(csid)) {
360 logger.error("updateVocabulary: missing csid!");
361 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
362 "update failed on Vocabulary csid=" + csid).type(
363 "text/plain").build();
364 throw new WebApplicationException(response);
366 MultipartOutput result = null;
368 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(theUpdate);
369 DocumentHandler handler = createDocumentHandler(ctx);
370 getRepositoryClient(ctx).update(ctx, csid, handler);
371 result = (MultipartOutput) ctx.getOutput();
372 } catch (UnauthorizedException ue) {
373 Response response = Response.status(
374 Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build();
375 throw new WebApplicationException(response);
376 } catch (DocumentNotFoundException dnfe) {
377 if (logger.isDebugEnabled()) {
378 logger.debug("caugth exception in updateVocabulary", dnfe);
380 Response response = Response.status(Response.Status.NOT_FOUND).entity(
381 "Update failed on Vocabulary csid=" + csid).type(
382 "text/plain").build();
383 throw new WebApplicationException(response);
384 } catch (Exception e) {
385 Response response = Response.status(
386 Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
387 throw new WebApplicationException(response);
395 * @param csid the csid
397 * @return the response
401 public Response deleteVocabulary(@PathParam("csid") String csid) {
403 if (logger.isDebugEnabled()) {
404 logger.debug("deleteVocabulary with csid=" + csid);
406 if (csid == null || "".equals(csid)) {
407 logger.error("deleteVocabulary: missing csid!");
408 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
409 "delete failed on Vocabulary csid=" + csid).type(
410 "text/plain").build();
411 throw new WebApplicationException(response);
414 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
415 getRepositoryClient(ctx).delete(ctx, csid);
416 return Response.status(HttpResponseCodes.SC_OK).build();
417 } catch (UnauthorizedException ue) {
418 Response response = Response.status(
419 Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build();
420 throw new WebApplicationException(response);
421 } catch (DocumentNotFoundException dnfe) {
422 if (logger.isDebugEnabled()) {
423 logger.debug("caught exception in deleteVocabulary", dnfe);
425 Response response = Response.status(Response.Status.NOT_FOUND).entity(
426 "Delete failed on Vocabulary csid=" + csid).type(
427 "text/plain").build();
428 throw new WebApplicationException(response);
429 } catch (Exception e) {
430 Response response = Response.status(
431 Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
432 throw new WebApplicationException(response);
437 /*************************************************************************
438 * VocabularyItem parts - this is a sub-resource of Vocabulary
441 * @return vocab item response
442 *************************************************************************/
444 @Path("{csid}/items")
445 public Response createVocabularyItem(@PathParam("csid") String parentcsid, MultipartInput input) {
447 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
449 DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
450 String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
451 UriBuilder path = UriBuilder.fromResource(VocabularyResource.class);
452 path.path(parentcsid + "/items/" + itemcsid);
453 Response response = Response.created(path.build()).build();
455 } catch (BadRequestException bre) {
456 Response response = Response.status(
457 Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
458 throw new WebApplicationException(response);
459 } catch (UnauthorizedException ue) {
460 Response response = Response.status(
461 Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build();
462 throw new WebApplicationException(response);
463 } catch (Exception e) {
464 if (logger.isDebugEnabled()) {
465 logger.debug("Caught exception in createVocabularyItem", e);
467 Response response = Response.status(
468 Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
469 throw new WebApplicationException(response);
474 * Gets the vocabulary item.
476 * @param parentcsid the parentcsid
477 * @param itemcsid the itemcsid
479 * @return the vocabulary item
482 @Path("{csid}/items/{itemcsid}")
483 public MultipartOutput getVocabularyItem(
484 @PathParam("csid") String parentcsid,
485 @PathParam("itemcsid") String itemcsid) {
486 if (logger.isDebugEnabled()) {
487 logger.debug("getVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
489 if (parentcsid == null || "".equals(parentcsid)) {
490 logger.error("getVocabularyItem: missing csid!");
491 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
492 "get failed on VocabularyItem csid=" + parentcsid).type(
493 "text/plain").build();
494 throw new WebApplicationException(response);
496 if (itemcsid == null || "".equals(itemcsid)) {
497 logger.error("getVocabularyItem: missing itemcsid!");
498 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
499 "get failed on VocabularyItem itemcsid=" + itemcsid).type(
500 "text/plain").build();
501 throw new WebApplicationException(response);
503 MultipartOutput result = null;
505 // Note that we have to create the service context for the Items, not the main service
506 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
507 DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
508 getRepositoryClient(ctx).get(ctx, itemcsid, handler);
509 // TODO should we assert that the item is in the passed vocab?
510 result = (MultipartOutput) ctx.getOutput();
511 } catch (UnauthorizedException ue) {
512 Response response = Response.status(
513 Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
514 throw new WebApplicationException(response);
515 } catch (DocumentNotFoundException dnfe) {
516 if (logger.isDebugEnabled()) {
517 logger.debug("getVocabularyItem", dnfe);
519 Response response = Response.status(Response.Status.NOT_FOUND).entity(
520 "Get failed on VocabularyItem csid=" + itemcsid).type(
521 "text/plain").build();
522 throw new WebApplicationException(response);
523 } catch (Exception e) {
524 if (logger.isDebugEnabled()) {
525 logger.debug("getVocabularyItem", e);
527 Response response = Response.status(
528 Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
529 throw new WebApplicationException(response);
531 if (result == null) {
532 Response response = Response.status(Response.Status.NOT_FOUND).entity(
533 "Get failed, the requested VocabularyItem CSID:" + itemcsid + ": was not found.").type(
534 "text/plain").build();
535 throw new WebApplicationException(response);
541 * Gets the vocabulary item list.
543 * @param parentcsid the parentcsid
544 * @param partialTerm the partial term
547 * @return the vocabulary item list
550 @Path("{csid}/items")
551 @Produces("application/xml")
552 public VocabularyitemsCommonList getVocabularyItemList(
553 @PathParam("csid") String parentcsid,
554 @QueryParam(IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
555 @Context UriInfo ui) {
556 VocabularyitemsCommonList vocabularyItemObjectList = new VocabularyitemsCommonList();
558 MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
559 // Note that docType defaults to the ServiceName, so we're fine with that.
560 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
562 DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
563 DocumentFilter myFilter = handler.getDocumentFilter();
564 myFilter.setWhereClause(
565 VocabularyItemJAXBSchema.VOCABULARYITEMS_COMMON + ":"
566 + VocabularyItemJAXBSchema.IN_VOCABULARY + "="
567 + "'" + parentcsid + "'");
569 // AND vocabularyitems_common:displayName LIKE '%partialTerm%'
570 if (partialTerm != null && !partialTerm.isEmpty()) {
571 String ptClause = VocabularyItemJAXBSchema.VOCABULARYITEMS_COMMON + ":"
572 + VocabularyItemJAXBSchema.DISPLAY_NAME
573 + IQueryManager.SEARCH_LIKE
574 + "'%" + partialTerm + "%'";
575 myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
577 if (logger.isDebugEnabled()) {
578 logger.debug("getVocabularyItemList filtered WHERE clause: "
579 + myFilter.getWhereClause());
581 getRepositoryClient(ctx).getFiltered(ctx, handler);
582 vocabularyItemObjectList = (VocabularyitemsCommonList) handler.getCommonPartList();
583 } catch (UnauthorizedException ue) {
584 Response response = Response.status(
585 Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
586 throw new WebApplicationException(response);
587 } catch (Exception e) {
588 if (logger.isDebugEnabled()) {
589 logger.debug("Caught exception in getVocabularyItemList", e);
591 Response response = Response.status(
592 Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
593 throw new WebApplicationException(response);
595 return vocabularyItemObjectList;
600 * Gets the vocabulary item list.
602 * @param parentcsid the parentcsid
603 * @param partialTerm the partial term
606 * @return the vocabulary item list
609 @Path("urn:cspace:name({specifier})/items")
610 @Produces("application/xml")
611 public VocabularyitemsCommonList getVocabularyItemListByVocabName(
612 @PathParam("specifier") String specifier,
613 @QueryParam(IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
614 @Context UriInfo ui) {
616 MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
618 VocabularyJAXBSchema.VOCABULARIES_COMMON+
619 ":"+VocabularyJAXBSchema.SHORT_IDENTIFIER+
621 // Need to get an Authority by name
622 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
623 String parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
624 return getVocabularyItemList(parentcsid, partialTerm, ui);
625 } catch (UnauthorizedException ue) {
626 Response response = Response.status(
627 Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
628 throw new WebApplicationException(response);
629 } catch (Exception e) {
630 if (logger.isDebugEnabled()) {
631 logger.debug("Caught exception in getVocabularyItemListByVocabName", e);
633 Response response = Response.status(
634 Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
635 throw new WebApplicationException(response);
643 * Update vocabulary item.
645 * @param parentcsid the parentcsid
646 * @param itemcsid the itemcsid
647 * @param theUpdate the the update
649 * @return the multipart output
652 @Path("{csid}/items/{itemcsid}")
653 public MultipartOutput updateVocabularyItem(
654 @PathParam("csid") String parentcsid,
655 @PathParam("itemcsid") String itemcsid,
656 MultipartInput theUpdate) {
657 if (logger.isDebugEnabled()) {
658 logger.debug("updateVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
660 if (parentcsid == null || "".equals(parentcsid)) {
661 logger.error("updateVocabularyItem: missing csid!");
662 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
663 "update failed on VocabularyItem parentcsid=" + parentcsid).type(
664 "text/plain").build();
665 throw new WebApplicationException(response);
667 if (itemcsid == null || "".equals(itemcsid)) {
668 logger.error("updateVocabularyItem: missing itemcsid!");
669 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
670 "update failed on VocabularyItem=" + itemcsid).type(
671 "text/plain").build();
672 throw new WebApplicationException(response);
674 MultipartOutput result = null;
676 // Note that we have to create the service context for the Items, not the main service
677 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
679 DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
680 getRepositoryClient(ctx).update(ctx, itemcsid, handler);
681 result = (MultipartOutput) ctx.getOutput();
682 } catch (BadRequestException bre) {
683 Response response = Response.status(
684 Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
685 throw new WebApplicationException(response);
686 } catch (UnauthorizedException ue) {
687 Response response = Response.status(
688 Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build();
689 throw new WebApplicationException(response);
690 } catch (DocumentNotFoundException dnfe) {
691 if (logger.isDebugEnabled()) {
692 logger.debug("caught DNF exception in updateVocabularyItem", dnfe);
694 Response response = Response.status(Response.Status.NOT_FOUND).entity(
695 "Update failed on VocabularyItem csid=" + itemcsid).type(
696 "text/plain").build();
697 throw new WebApplicationException(response);
698 } catch (Exception e) {
699 Response response = Response.status(
700 Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
701 throw new WebApplicationException(response);
707 * Delete vocabulary item.
709 * @param parentcsid the parentcsid
710 * @param itemcsid the itemcsid
712 * @return the response
715 @Path("{csid}/items/{itemcsid}")
716 public Response deleteVocabularyItem(
717 @PathParam("csid") String parentcsid,
718 @PathParam("itemcsid") String itemcsid) {
719 if (logger.isDebugEnabled()) {
720 logger.debug("deleteVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
722 if (parentcsid == null || "".equals(parentcsid)) {
723 logger.error("deleteVocabularyItem: missing csid!");
724 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
725 "delete failed on VocabularyItem parentcsid=" + parentcsid).type(
726 "text/plain").build();
727 throw new WebApplicationException(response);
729 if (itemcsid == null || "".equals(itemcsid)) {
730 logger.error("deleteVocabularyItem: missing itemcsid!");
731 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
732 "delete failed on VocabularyItem=" + itemcsid).type(
733 "text/plain").build();
734 throw new WebApplicationException(response);
737 // Note that we have to create the service context for the Items, not the main service
738 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
739 getRepositoryClient(ctx).delete(ctx, itemcsid);
740 return Response.status(HttpResponseCodes.SC_OK).build();
741 } catch (UnauthorizedException ue) {
742 Response response = Response.status(
743 Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build();
744 throw new WebApplicationException(response);
745 } catch (DocumentNotFoundException dnfe) {
746 if (logger.isDebugEnabled()) {
747 logger.debug("caught exception in deleteVocabulary", dnfe);
749 Response response = Response.status(Response.Status.NOT_FOUND).entity(
750 "Delete failed on VocabularyItem itemcsid=" + itemcsid).type(
751 "text/plain").build();
752 throw new WebApplicationException(response);
753 } catch (Exception e) {
754 Response response = Response.status(
755 Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
756 throw new WebApplicationException(response);