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.person;
27 import javax.ws.rs.Consumes;
28 import javax.ws.rs.DELETE;
29 import javax.ws.rs.GET;
30 import javax.ws.rs.POST;
31 import javax.ws.rs.PUT;
32 import javax.ws.rs.Path;
33 import javax.ws.rs.PathParam;
34 import javax.ws.rs.Produces;
35 import javax.ws.rs.QueryParam;
36 import javax.ws.rs.WebApplicationException;
37 import javax.ws.rs.core.Context;
38 import javax.ws.rs.core.HttpHeaders;
39 import javax.ws.rs.core.MultivaluedMap;
40 import javax.ws.rs.core.Response;
41 import javax.ws.rs.core.UriBuilder;
42 import javax.ws.rs.core.UriInfo;
44 import org.collectionspace.services.PersonJAXBSchema;
45 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
46 import org.collectionspace.services.common.ClientType;
47 import org.collectionspace.services.common.ServiceMain;
48 import org.collectionspace.services.common.context.MultipartServiceContext;
49 import org.collectionspace.services.common.context.MultipartServiceContextFactory;
50 import org.collectionspace.services.common.context.ServiceContext;
51 import org.collectionspace.services.common.document.BadRequestException;
52 import org.collectionspace.services.common.document.DocumentFilter;
53 import org.collectionspace.services.common.document.DocumentHandler;
54 import org.collectionspace.services.common.document.DocumentNotFoundException;
55 import org.collectionspace.services.common.security.UnauthorizedException;
56 import org.collectionspace.services.common.query.IQueryManager;
57 import org.collectionspace.services.contact.ContactResource;
58 import org.collectionspace.services.contact.ContactsCommon;
59 import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler;
60 import org.collectionspace.services.person.nuxeo.PersonDocumentModelHandler;
61 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
62 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
63 import org.jboss.resteasy.util.HttpResponseCodes;
64 import org.slf4j.Logger;
65 import org.slf4j.LoggerFactory;
67 @Path("/personauthorities")
68 @Consumes("multipart/mixed")
69 @Produces("multipart/mixed")
70 public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl {
72 private final static String personAuthorityServiceName = "personauthorities";
73 private final static String personServiceName = "persons";
74 final Logger logger = LoggerFactory.getLogger(PersonAuthorityResource.class);
75 //FIXME retrieve client type from configuration
76 final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType();
77 private ContactResource contactResource = new ContactResource();
79 public PersonAuthorityResource() {
84 protected String getVersionString() {
85 /** The last change revision. */
86 final String lastChangeRevision = "$LastChangedRevision$";
87 return lastChangeRevision;
91 public String getServiceName() {
92 return personAuthorityServiceName;
95 public String getItemServiceName() {
96 return personServiceName;
99 public String getContactServiceName() {
100 return contactResource.getServiceName();
104 public RemoteServiceContext createItemServiceContext(MultipartInput input) throws Exception {
105 RemoteServiceContext ctx = new RemoteServiceContextImpl(getItemServiceName());
111 public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
112 DocumentHandler docHandler = ctx.getDocumentHandler();
113 if (ctx.getInput() != null) {
114 Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), PersonauthoritiesCommon.class);
116 docHandler.setCommonPart((PersonauthoritiesCommon) obj);
122 private DocumentHandler createItemDocumentHandler(
124 String inAuthority) throws Exception {
125 DocumentHandler docHandler = ctx.getDocumentHandler();
126 ((PersonDocumentModelHandler) docHandler).setInAuthority(inAuthority);
127 if (ctx.getInput() != null) {
128 Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(getItemServiceName()),
129 PersonsCommon.class);
131 docHandler.setCommonPart((PersonsCommon) obj);
137 private DocumentHandler createContactDocumentHandler(
138 ServiceContext ctx, String inAuthority,
139 String inItem) throws Exception {
140 DocumentHandler docHandler = ctx.getDocumentHandler();
141 // Set the inAuthority and inItem values, specifying the
142 // grandparent authority (e.g. PersonAuthority, OrgAuthority) and
143 // the parent item (e.g. Person, Organization) of the Contact
144 ((ContactDocumentModelHandler) docHandler).setInAuthority(inAuthority);
145 ((ContactDocumentModelHandler) docHandler).setInItem(inItem);
146 if (ctx.getInput() != null) {
147 Object obj = ((MultipartServiceContext) ctx)
148 .getInputPart(ctx.getCommonPartLabel(getContactServiceName()),
149 ContactsCommon.class);
151 docHandler.setCommonPart((ContactsCommon) obj);
159 public Response createPersonAuthority(MultipartInput input) {
161 ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
162 DocumentHandler handler = createDocumentHandler(ctx);
163 String csid = getRepositoryClient(ctx).create(ctx, handler);
164 //personAuthorityObject.setCsid(csid);
165 UriBuilder path = UriBuilder.fromResource(PersonAuthorityResource.class);
166 path.path("" + csid);
167 Response response = Response.created(path.build()).build();
169 } catch (UnauthorizedException ue) {
170 Response response = Response.status(
171 Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build();
172 throw new WebApplicationException(response);
173 } catch (Exception e) {
174 if (logger.isDebugEnabled()) {
175 logger.debug("Caught exception in createPersonAuthority", e);
177 Response response = Response.status(
178 Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
179 throw new WebApplicationException(response);
185 public MultipartOutput getPersonAuthority(@PathParam("csid") String csid) {
186 String idValue = null;
188 logger.error("getPersonAuthority: missing csid!");
189 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
190 "get failed on PersonAuthority csid=" + csid).type(
191 "text/plain").build();
192 throw new WebApplicationException(response);
194 if (logger.isDebugEnabled()) {
195 logger.debug("getPersonAuthority with path(id)=" + csid);
197 MultipartOutput result = null;
199 ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
200 DocumentHandler handler = createDocumentHandler(ctx);
201 getRepositoryClient(ctx).get(ctx, csid, handler);
202 result = (MultipartOutput) ctx.getOutput();
203 } catch (UnauthorizedException ue) {
204 Response response = Response.status(
205 Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
206 throw new WebApplicationException(response);
207 } catch (DocumentNotFoundException dnfe) {
208 if (logger.isDebugEnabled()) {
209 logger.debug("getPersonAuthority", dnfe);
211 Response response = Response.status(Response.Status.NOT_FOUND).entity(
212 "Get failed on PersonAuthority csid=" + csid).type(
213 "text/plain").build();
214 throw new WebApplicationException(response);
215 } catch (Exception e) {
216 if (logger.isDebugEnabled()) {
217 logger.debug("getPersonAuthority", e);
219 Response response = Response.status(
220 Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
221 throw new WebApplicationException(response);
223 if (result == null) {
224 Response response = Response.status(Response.Status.NOT_FOUND).entity(
225 "Get failed, the requested PersonAuthority CSID:" + csid + ": was not found.").type(
226 "text/plain").build();
227 throw new WebApplicationException(response);
233 @Produces("application/xml")
234 public PersonauthoritiesCommonList getPersonAuthorityList(@Context UriInfo ui) {
235 PersonauthoritiesCommonList personAuthorityObjectList = new PersonauthoritiesCommonList();
237 ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
238 MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
239 DocumentHandler handler = createDocumentHandler(ctx);
240 DocumentFilter myFilter = new DocumentFilter();
241 myFilter.setPagination(queryParams);
242 String nameQ = queryParams.getFirst("refName");
244 myFilter.setWhereClause("personauthorities_common:refName='" + nameQ + "'");
246 handler.setDocumentFilter(myFilter);
247 getRepositoryClient(ctx).getFiltered(ctx, handler);
248 personAuthorityObjectList = (PersonauthoritiesCommonList) handler.getCommonPartList();
249 } catch (UnauthorizedException ue) {
250 Response response = Response.status(
251 Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
252 throw new WebApplicationException(response);
253 } catch (Exception e) {
254 if (logger.isDebugEnabled()) {
255 logger.debug("Caught exception in getPersonAuthorityList", e);
257 Response response = Response.status(
258 Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
259 throw new WebApplicationException(response);
261 return personAuthorityObjectList;
266 public MultipartOutput updatePersonAuthority(
267 @PathParam("csid") String csid,
268 MultipartInput theUpdate) {
269 if (logger.isDebugEnabled()) {
270 logger.debug("updatePersonAuthority with csid=" + csid);
272 if (csid == null || "".equals(csid)) {
273 logger.error("updatePersonAuthority: missing csid!");
274 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
275 "update failed on PersonAuthority csid=" + csid).type(
276 "text/plain").build();
277 throw new WebApplicationException(response);
279 MultipartOutput result = null;
281 ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
282 DocumentHandler handler = createDocumentHandler(ctx);
283 getRepositoryClient(ctx).update(ctx, csid, handler);
284 result = (MultipartOutput) ctx.getOutput();
285 } catch (UnauthorizedException ue) {
286 Response response = Response.status(
287 Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build();
288 throw new WebApplicationException(response);
289 } catch (DocumentNotFoundException dnfe) {
290 if (logger.isDebugEnabled()) {
291 logger.debug("caugth exception in updatePersonAuthority", dnfe);
293 Response response = Response.status(Response.Status.NOT_FOUND).entity(
294 "Update failed on PersonAuthority csid=" + csid).type(
295 "text/plain").build();
296 throw new WebApplicationException(response);
297 } catch (Exception e) {
298 Response response = Response.status(
299 Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
300 throw new WebApplicationException(response);
307 public Response deletePersonAuthority(@PathParam("csid") String csid) {
309 if (logger.isDebugEnabled()) {
310 logger.debug("deletePersonAuthority with csid=" + csid);
312 if (csid == null || "".equals(csid)) {
313 logger.error("deletePersonAuthority: missing csid!");
314 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
315 "delete failed on PersonAuthority csid=" + csid).type(
316 "text/plain").build();
317 throw new WebApplicationException(response);
320 ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
321 getRepositoryClient(ctx).delete(ctx, csid);
322 return Response.status(HttpResponseCodes.SC_OK).build();
323 } catch (UnauthorizedException ue) {
324 Response response = Response.status(
325 Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build();
326 throw new WebApplicationException(response);
327 } catch (DocumentNotFoundException dnfe) {
328 if (logger.isDebugEnabled()) {
329 logger.debug("caught exception in deletePersonAuthority", dnfe);
331 Response response = Response.status(Response.Status.NOT_FOUND).entity(
332 "Delete failed on PersonAuthority csid=" + csid).type(
333 "text/plain").build();
334 throw new WebApplicationException(response);
335 } catch (Exception e) {
336 Response response = Response.status(
337 Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
338 throw new WebApplicationException(response);
343 /*************************************************************************
344 * Person parts - this is a sub-resource of PersonAuthority
345 *************************************************************************/
347 @Path("{csid}/items")
348 public Response createPerson(@PathParam("csid") String parentcsid, MultipartInput input) {
350 ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getItemServiceName());
351 DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
352 String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
353 UriBuilder path = UriBuilder.fromResource(PersonAuthorityResource.class);
354 path.path(parentcsid + "/items/" + itemcsid);
355 Response response = Response.created(path.build()).build();
357 } catch (BadRequestException bre) {
358 Response response = Response.status(
359 Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
360 throw new WebApplicationException(response);
361 } catch (UnauthorizedException ue) {
362 Response response = Response.status(
363 Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build();
364 throw new WebApplicationException(response);
365 } catch (Exception e) {
366 if (logger.isDebugEnabled()) {
367 logger.debug("Caught exception in createPerson", e);
369 Response response = Response.status(
370 Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
371 throw new WebApplicationException(response);
376 @Path("{csid}/items/{itemcsid}")
377 public MultipartOutput getPerson(
378 @PathParam("csid") String parentcsid,
379 @PathParam("itemcsid") String itemcsid) {
380 if (logger.isDebugEnabled()) {
381 logger.debug("getPerson with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
383 if (parentcsid == null || "".equals(parentcsid)) {
384 logger.error("getPerson: missing csid!");
385 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
386 "get failed on Person csid=" + parentcsid).type(
387 "text/plain").build();
388 throw new WebApplicationException(response);
390 if (itemcsid == null || "".equals(itemcsid)) {
391 logger.error("getPerson: missing itemcsid!");
392 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
393 "get failed on Person itemcsid=" + itemcsid).type(
394 "text/plain").build();
395 throw new WebApplicationException(response);
397 MultipartOutput result = null;
399 // Note that we have to create the service context for the Items, not the main service
400 ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
401 DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
402 getRepositoryClient(ctx).get(ctx, itemcsid, handler);
403 // TODO should we assert that the item is in the passed personAuthority?
404 result = (MultipartOutput) ctx.getOutput();
405 } catch (UnauthorizedException ue) {
406 Response response = Response.status(
407 Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
408 throw new WebApplicationException(response);
409 } catch (DocumentNotFoundException dnfe) {
410 if (logger.isDebugEnabled()) {
411 logger.debug("getPerson", dnfe);
413 Response response = Response.status(Response.Status.NOT_FOUND).entity(
414 "Get failed on Person csid=" + itemcsid).type(
415 "text/plain").build();
416 throw new WebApplicationException(response);
417 } catch (Exception e) {
418 if (logger.isDebugEnabled()) {
419 logger.debug("getPerson", e);
421 Response response = Response.status(
422 Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
423 throw new WebApplicationException(response);
425 if (result == null) {
426 Response response = Response.status(Response.Status.NOT_FOUND).entity(
427 "Get failed, the requested Person CSID:" + itemcsid + ": was not found.").type(
428 "text/plain").build();
429 throw new WebApplicationException(response);
435 @Path("{csid}/items")
436 @Produces("application/xml")
437 public PersonsCommonList getPersonList(
438 @PathParam("csid") String parentcsid,
439 @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
440 @Context UriInfo ui) {
441 PersonsCommonList personObjectList = new PersonsCommonList();
443 // Note that docType defaults to the ServiceName, so we're fine with that.
444 ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
445 DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
446 MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
447 DocumentFilter myFilter = new DocumentFilter();
448 myFilter.setPagination(queryParams);
450 // Add the where clause "persons_common:inAuthority='" + parentcsid + "'"
451 myFilter.setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" +
452 PersonJAXBSchema.IN_AUTHORITY +
453 "='" + parentcsid + "'" + "AND ecm:isProxy = 0");
455 // AND persons_common:displayName LIKE '%partialTerm%'
456 if (partialTerm != null && !partialTerm.isEmpty()) {
457 String ptClause = "AND " +
458 PersonJAXBSchema.PERSONS_COMMON + ":" +
459 PersonJAXBSchema.DISPLAY_NAME +
461 "'%" + partialTerm + "%'";
462 myFilter.appendWhereClause(ptClause);
465 handler.setDocumentFilter(myFilter);
466 getRepositoryClient(ctx).getFiltered(ctx, handler);
467 personObjectList = (PersonsCommonList) handler.getCommonPartList();
468 } catch (UnauthorizedException ue) {
469 Response response = Response.status(
470 Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
471 throw new WebApplicationException(response);
472 } catch (Exception e) {
473 if (logger.isDebugEnabled()) {
474 logger.debug("Caught exception in getPersonList", e);
476 Response response = Response.status(
477 Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
478 throw new WebApplicationException(response);
480 return personObjectList;
484 @Path("{csid}/items/{itemcsid}")
485 public MultipartOutput updatePerson(
486 @PathParam("csid") String parentcsid,
487 @PathParam("itemcsid") String itemcsid,
488 MultipartInput theUpdate) {
489 if (logger.isDebugEnabled()) {
490 logger.debug("updatePerson with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
492 if (parentcsid == null || "".equals(parentcsid)) {
493 logger.error("updatePerson: missing csid!");
494 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
495 "update failed on Person parentcsid=" + parentcsid).type(
496 "text/plain").build();
497 throw new WebApplicationException(response);
499 if (itemcsid == null || "".equals(itemcsid)) {
500 logger.error("updatePerson: missing itemcsid!");
501 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
502 "update failed on Person=" + itemcsid).type(
503 "text/plain").build();
504 throw new WebApplicationException(response);
506 MultipartOutput result = null;
508 // Note that we have to create the service context for the Items, not the main service
509 ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getItemServiceName());
510 DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
511 getRepositoryClient(ctx).update(ctx, itemcsid, handler);
512 result = (MultipartOutput) ctx.getOutput();
513 } catch (BadRequestException bre) {
514 Response response = Response.status(
515 Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
516 throw new WebApplicationException(response);
517 } catch (UnauthorizedException ue) {
518 Response response = Response.status(
519 Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build();
520 throw new WebApplicationException(response);
521 } catch (DocumentNotFoundException dnfe) {
522 if (logger.isDebugEnabled()) {
523 logger.debug("caught exception in updatePerson", dnfe);
525 Response response = Response.status(Response.Status.NOT_FOUND).entity(
526 "Update failed on Person csid=" + itemcsid).type(
527 "text/plain").build();
528 throw new WebApplicationException(response);
529 } catch (Exception e) {
530 Response response = Response.status(
531 Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
532 throw new WebApplicationException(response);
538 @Path("{csid}/items/{itemcsid}")
539 public Response deletePerson(
540 @PathParam("csid") String parentcsid,
541 @PathParam("itemcsid") String itemcsid) {
542 if (logger.isDebugEnabled()) {
543 logger.debug("deletePerson with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
545 if (parentcsid == null || "".equals(parentcsid)) {
546 logger.error("deletePerson: missing csid!");
547 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
548 "delete failed on Person parentcsid=" + parentcsid).type(
549 "text/plain").build();
550 throw new WebApplicationException(response);
552 if (itemcsid == null || "".equals(itemcsid)) {
553 logger.error("deletePerson: missing itemcsid!");
554 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
555 "delete failed on Person=" + itemcsid).type(
556 "text/plain").build();
557 throw new WebApplicationException(response);
560 // Note that we have to create the service context for the Items, not the main service
561 ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
562 getRepositoryClient(ctx).delete(ctx, itemcsid);
563 return Response.status(HttpResponseCodes.SC_OK).build();
564 } catch (UnauthorizedException ue) {
565 Response response = Response.status(
566 Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build();
567 throw new WebApplicationException(response);
568 } catch (DocumentNotFoundException dnfe) {
569 if (logger.isDebugEnabled()) {
570 logger.debug("caught exception in deletePerson", dnfe);
572 Response response = Response.status(Response.Status.NOT_FOUND).entity(
573 "Delete failed on Person itemcsid=" + itemcsid).type(
574 "text/plain").build();
575 throw new WebApplicationException(response);
576 } catch (Exception e) {
577 Response response = Response.status(
578 Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
579 throw new WebApplicationException(response);
584 /*************************************************************************
585 * Contact parts - this is a sub-resource of Person (or "item")
586 *************************************************************************/
588 @Path("{authorityCsid}/items/{itemCsid}/contacts")
589 public Response createContact(
590 @PathParam("authorityCsid") String authorityCsid,
591 @PathParam("itemCsid") String itemCsid,
592 MultipartInput input) {
595 ContactResource contactResource = new ContactResource();
597 contactResource.createContact(authorityCsid, itemCsid, input);
598 UriBuilder path = UriBuilder.fromResource(PersonAuthorityResource.class);
599 path.path("" + authorityCsid + "/items/" + itemCsid + "/contacts/" + csid);
600 Response response = Response.created(path.build()).build();
603 } catch (UnauthorizedException ue) {
604 Response response = Response.status(Response.Status.UNAUTHORIZED).entity(
605 "Create failed reason " + ue.getErrorReason()).type("text/plain").build();
606 throw new WebApplicationException(response);
608 } catch (Exception e) {
609 if (logger.isDebugEnabled()) {
610 logger.debug("Caught exception in createContact", e);
612 Response response = Response.status(
613 Response.Status.INTERNAL_SERVER_ERROR)
614 .entity("Attempt to create Contact failed.")
615 .type("text/plain").build();
616 throw new WebApplicationException(response);
622 @Produces({"application/xml"})
623 @Path("/{authorityCsid}/items/{itemCsid}/contacts/")
624 public Response getContactList(
625 @PathParam("authorityCsid") String authorityCsid,
626 @PathParam("itemCsid") String itemCsid) {
628 // FIXME Placeholder while call is being implemented.
629 String msg = "Reading lists of contacts is not yet implemented.";
631 Response response = Response.status(
632 Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type("text/plain").build();
638 @Path("/{authorityCsid}/items/{itemCsid}/contacts/{csid}")
639 public MultipartOutput getContact(
640 @PathParam("authorityCsid") String authorityCsid,
641 @PathParam("itemCsid") String itemCsid,
642 @PathParam("csid") String csid) {
643 MultipartOutput result = null;
645 ContactResource resource = new ContactResource();
646 result = resource.getContact(authorityCsid, itemCsid, csid);
648 } catch (UnauthorizedException ue) {
649 Response response = Response.status(Response.Status.UNAUTHORIZED)
650 .entity("Get failed reason " + ue.getErrorReason())
651 .type("text/plain").build();
652 throw new WebApplicationException(response);
654 } catch (DocumentNotFoundException dnfe) {
655 if (logger.isDebugEnabled()) {
656 logger.debug("getContact", dnfe);
658 Response response = Response.status(Response.Status.NOT_FOUND)
659 .entity("Get failed, the requested Contact CSID:" + csid + ": was not found.")
660 .type("text/plain").build();
661 throw new WebApplicationException(response);
662 } catch (Exception e) {
663 if (logger.isDebugEnabled()) {
664 logger.debug("getContact", e);
666 Response response = Response.status(Response.Status.INTERNAL_SERVER_ERROR)
667 .entity("Get failed")
668 .type("text/plain").build();
669 throw new WebApplicationException(response);
671 if (result == null) {
672 Response response = Response.status(Response.Status.NOT_FOUND)
673 .entity("Get failed, the requested Contact CSID:" + csid + ": was not found.")
674 .type("text/plain").build();
675 throw new WebApplicationException(response);
682 @Path("/{authorityCsid}/items/{itemCsid}/contacts/{csid}")
683 MultipartOutput updateContact(
684 @PathParam("authorityCsid") String authorityCsid,
685 @PathParam("itemCsid") String itemCsid,
686 @PathParam("csid") String csid,
687 MultipartInput input) {
689 // FIXME Placeholder while call is being implemented.
690 MultipartOutput result = null;
695 @Path("/{authorityCsid}/items/{itemCsid}/contacts/{csid}")
696 Response deleteContact(
697 @PathParam("authorityCsid") String authorityCsid,
698 @PathParam("itemCsid") String itemCsid,
699 @PathParam("csid") String csid) {
701 // FIXME Placeholder while call is being implemented.
702 String msg = "Deleting contacts is not yet implemented.";
704 Response response = Response.status(
705 Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type("text/plain").build();