]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
3b45ff4e6807dd27917d128de61ae7e32e4cb9a0
[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.organization;
25
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;
41
42 import org.collectionspace.services.OrgAuthorityJAXBSchema;
43 import org.collectionspace.services.OrganizationJAXBSchema;
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.MultipartServiceContext;
48 //import org.collectionspace.services.common.context.MultipartServiceContextFactory;
49 import org.collectionspace.services.common.context.ServiceContext;
50 import org.collectionspace.services.common.document.BadRequestException;
51 import org.collectionspace.services.common.document.DocumentFilter;
52 import org.collectionspace.services.common.document.DocumentHandler;
53 import org.collectionspace.services.common.document.DocumentNotFoundException;
54 import org.collectionspace.services.common.query.IQueryManager;
55 import org.collectionspace.services.contact.ContactResource;
56 import org.collectionspace.services.contact.ContactsCommon;
57 import org.collectionspace.services.contact.ContactsCommonList;
58 import org.collectionspace.services.contact.ContactJAXBSchema;
59 import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler;
60 import org.collectionspace.services.common.security.UnauthorizedException;
61 import org.collectionspace.services.organization.nuxeo.OrganizationDocumentModelHandler;
62 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
63 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
64 import org.jboss.resteasy.util.HttpResponseCodes;
65 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory;
67
68 /**
69  * The Class OrgAuthorityResource.
70  */
71 @Path("/orgauthorities")
72 @Consumes("multipart/mixed")
73 @Produces("multipart/mixed")
74 public class OrgAuthorityResource extends
75                 AbstractMultiPartCollectionSpaceResourceImpl {
76
77     /** The Constant orgAuthorityServiceName. */
78     private final static String orgAuthorityServiceName = "orgauthorities";
79     
80     /** The Constant organizationServiceName. */
81     private final static String organizationServiceName = "organizations";
82     
83     /** The logger. */
84     final Logger logger = LoggerFactory.getLogger(OrgAuthorityResource.class);
85     //FIXME retrieve client type from configuration
86     /** The Constant CLIENT_TYPE. */
87     final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType();
88     
89     /** The contact resource. */
90     private ContactResource contactResource = new ContactResource();
91
92     /**
93      * Instantiates a new org authority resource.
94      */
95     public OrgAuthorityResource() {
96         // do nothing
97     }
98
99     /* (non-Javadoc)
100      * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
101      */
102     @Override
103     protected String getVersionString() {
104         /** The last change revision. */
105         final String lastChangeRevision = "$LastChangedRevision$";
106         return lastChangeRevision;
107     }
108     
109     /* (non-Javadoc)
110      * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
111      */
112     @Override
113     public String getServiceName() {
114         return orgAuthorityServiceName;
115     }
116     
117     /* (non-Javadoc)
118      * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
119      */
120     @Override
121     public Class<OrgauthoritiesCommon> getCommonPartClass() {
122         return OrgauthoritiesCommon.class;
123     }    
124
125     /**
126      * Gets the item service name.
127      * 
128      * @return the item service name
129      */
130     public String getItemServiceName() {
131         return organizationServiceName;
132     }
133
134     /**
135      * Gets the contact service name.
136      * 
137      * @return the contact service name
138      */
139     public String getContactServiceName() {
140         return contactResource.getServiceName();
141     }
142
143     /*
144     public RemoteServiceContext createItemServiceContext(MultipartInput input) throws Exception {
145     RemoteServiceContext ctx = new RemoteServiceContextImpl(getItemServiceName());
146     ctx.setInput(input);
147     return ctx;
148     }
149      */
150     /* (non-Javadoc)
151      * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
152      */
153 //    @Override
154 //    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
155 //        DocumentHandler docHandler =ctx.getDocumentHandler();
156 //        if (ctx.getInput() != null) {
157 //            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), OrgauthoritiesCommon.class);
158 //            if (obj != null) {
159 //                docHandler.setCommonPart((OrgauthoritiesCommon) obj);
160 //            }
161 //        }
162 //        return docHandler;
163 //    }
164
165     /**
166      * Creates the item document handler.
167      * 
168      * @param ctx the ctx
169      * @param inAuthority the in authority
170      * 
171      * @return the document handler
172      * 
173      * @throws Exception the exception
174      */
175     private DocumentHandler createItemDocumentHandler(
176                 ServiceContext<MultipartInput, MultipartOutput> ctx,
177             String inAuthority) throws Exception {      
178         OrganizationDocumentModelHandler docHandler = (OrganizationDocumentModelHandler)createDocumentHandler(
179                         ctx,
180                         ctx.getCommonPartLabel(getItemServiceName()),
181                         OrganizationsCommon.class);             
182         docHandler.setInAuthority(inAuthority);
183         
184         
185 //        ((OrganizationDocumentModelHandler) docHandler).setInAuthority(inAuthority);
186 //        if (ctx.getInput() != null) {
187 //            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(getItemServiceName()),
188 //                    OrganizationsCommon.class);
189 //            if (obj != null) {
190 //                docHandler.setCommonPart((OrganizationsCommon) obj);
191 //            }
192 //        }
193
194         return docHandler;
195     }
196
197     /**
198      * Creates the contact document handler.
199      * 
200      * @param ctx the ctx
201      * @param inAuthority the in authority
202      * @param inItem the in item
203      * 
204      * @return the document handler
205      * 
206      * @throws Exception the exception
207      */
208     private DocumentHandler createContactDocumentHandler(
209                 ServiceContext<MultipartInput, MultipartOutput> ctx, String inAuthority,
210             String inItem) throws Exception {
211         
212         ContactDocumentModelHandler docHandler = (ContactDocumentModelHandler)createDocumentHandler(
213                         ctx,
214                         ctx.getCommonPartLabel(getContactServiceName()),
215                         ContactsCommon.class);          
216         docHandler.setInAuthority(inAuthority);
217         docHandler.setInItem(inItem);
218         
219 //        DocumentHandler docHandler = ctx.getDocumentHandler();
220 //        // Set the inAuthority and inItem values, which specify the
221 //        // parent authority (e.g. PersonAuthority, OrgAuthority) and the item
222 //        // (e.g. Person, Organization) with which the Contact is associated.
223 //        ((ContactDocumentModelHandler) docHandler).setInAuthority(inAuthority);
224 //        ((ContactDocumentModelHandler) docHandler).setInItem(inItem);
225 //        if (ctx.getInput() != null) {
226 //            Object obj = ((MultipartServiceContext) ctx)
227 //                .getInputPart(ctx.getCommonPartLabel(getContactServiceName()),
228 //                ContactsCommon.class);
229 //            if (obj != null) {
230 //                docHandler.setCommonPart((ContactsCommon) obj);
231 //            }
232 //        }
233         return docHandler;
234     }
235
236     /**
237      * Creates the org authority.
238      * 
239      * @param input the input
240      * 
241      * @return the response
242      */
243     @POST
244     public Response createOrgAuthority(MultipartInput input) {
245         try {
246                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(input);
247             DocumentHandler handler = createDocumentHandler(ctx);
248             String csid = getRepositoryClient(ctx).create(ctx, handler);
249             //orgAuthorityObject.setCsid(csid);
250             UriBuilder path = UriBuilder.fromResource(OrgAuthorityResource.class);
251             path.path("" + csid);
252             Response response = Response.created(path.build()).build();
253             return response;
254         } catch (BadRequestException bre) {
255             Response response = Response.status(
256                     Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
257             throw new WebApplicationException(response);
258         } catch (UnauthorizedException ue) {
259             Response response = Response.status(
260                     Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build();
261             throw new WebApplicationException(response);
262         } catch (Exception e) {
263             if (logger.isDebugEnabled()) {
264                 logger.debug("Caught exception in createOrgAuthority", e);
265             }
266             Response response = Response.status(
267                     Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
268             throw new WebApplicationException(response);
269         }
270     }
271
272     /**
273      * Gets the org authority by name.
274      * 
275      * @param specifier the specifier
276      * 
277      * @return the org authority by name
278      */
279     @GET
280     @Path("urn:cspace:name({specifier})")
281     public MultipartOutput getOrgAuthorityByName(@PathParam("specifier") String specifier) {
282         String idValue = null;
283         if (specifier == null) {
284             logger.error("getOrgAuthority: missing name!");
285             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
286                     "get failed on OrgAuthority (missing specifier)").type(
287                     "text/plain").build();
288             throw new WebApplicationException(response);
289         }
290         String whereClause =
291                 OrgAuthorityJAXBSchema.ORGAUTHORITIES_COMMON+
292                 ":"+OrgAuthorityJAXBSchema.DISPLAY_NAME+
293                 "='"+specifier+"'";
294         // We only get a single doc - if there are multiple,
295         // it is an error in use.
296
297         if (logger.isDebugEnabled()) {
298             logger.debug("getOrgAuthority with name=" + specifier);
299         } 
300         MultipartOutput result = null;
301         try {
302                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
303             DocumentHandler handler = createDocumentHandler(ctx);
304             DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1);
305             handler.setDocumentFilter(myFilter);
306             getRepositoryClient(ctx).get(ctx, handler);
307             result = (MultipartOutput) ctx.getOutput();
308         } catch (UnauthorizedException ue) {
309             Response response = Response.status(
310                     Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
311             throw new WebApplicationException(response);
312         } catch (DocumentNotFoundException dnfe) {
313             if (logger.isDebugEnabled()) {
314                 logger.debug("getOrgAuthority", dnfe);
315             }
316             Response response = Response.status(Response.Status.NOT_FOUND).entity(
317                     "Get failed on OrgAuthority spec=" + specifier).type(
318                     "text/plain").build();
319             throw new WebApplicationException(response);
320         } catch (Exception e) {
321             if (logger.isDebugEnabled()) {
322                 logger.debug("getOrgAuthority", e);
323             }
324             Response response = Response.status(
325                     Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
326             throw new WebApplicationException(response);
327         }
328         if (result == null) {
329             Response response = Response.status(Response.Status.NOT_FOUND).entity(
330                     "Get failed, the requested OrgAuthority spec:" + specifier + ": was not found.").type(
331                     "text/plain").build();
332             throw new WebApplicationException(response);
333         }
334         return result;
335     }
336
337     /**
338      * Gets the org authority.
339      * 
340      * @param csid the csid
341      * 
342      * @return the org authority
343      */
344     @GET
345     @Path("{csid}")
346     public MultipartOutput getOrgAuthority(@PathParam("csid") String csid) {
347         String idValue = null;
348         if (csid == null) {
349             logger.error("getOrgAuthority: missing csid!");
350             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
351                     "get failed on OrgAuthority csid=" + csid).type(
352                     "text/plain").build();
353             throw new WebApplicationException(response);
354         }
355         if (logger.isDebugEnabled()) {
356             logger.debug("getOrgAuthority with path(id)=" + csid);
357         }
358         MultipartOutput result = null;
359         try {
360                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
361             DocumentHandler handler = createDocumentHandler(ctx);
362             getRepositoryClient(ctx).get(ctx, csid, handler);
363             result = (MultipartOutput) ctx.getOutput();
364         } catch (UnauthorizedException ue) {
365             Response response = Response.status(
366                     Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
367             throw new WebApplicationException(response);
368         } catch (DocumentNotFoundException dnfe) {
369             if (logger.isDebugEnabled()) {
370                 logger.debug("getOrgAuthority", dnfe);
371             }
372             Response response = Response.status(Response.Status.NOT_FOUND).entity(
373                     "Get failed on OrgAuthority csid=" + csid).type(
374                     "text/plain").build();
375             throw new WebApplicationException(response);
376         } catch (Exception e) {
377             if (logger.isDebugEnabled()) {
378                 logger.debug("getOrgAuthority", e);
379             }
380             Response response = Response.status(
381                     Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
382             throw new WebApplicationException(response);
383         }
384         if (result == null) {
385             Response response = Response.status(Response.Status.NOT_FOUND).entity(
386                     "Get failed, the requested OrgAuthority CSID:" + csid + ": was not found.").type(
387                     "text/plain").build();
388             throw new WebApplicationException(response);
389         }
390         return result;
391     }
392
393     /**
394      * Gets the org authority list.
395      * 
396      * @param ui the ui
397      * 
398      * @return the org authority list
399      */
400     @GET
401     @Produces("application/xml")
402     public OrgauthoritiesCommonList getOrgAuthorityList(@Context UriInfo ui) {
403         OrgauthoritiesCommonList orgAuthorityObjectList = new OrgauthoritiesCommonList();
404         try {
405                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
406             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
407             DocumentHandler handler = createDocumentHandler(ctx);
408             DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
409             myFilter.setPagination(queryParams);
410             String nameQ = queryParams.getFirst("refName");
411             if (nameQ != null) {
412                 myFilter.setWhereClause("orgauthorities_common:refName='" + nameQ + "'");
413             }
414             handler.setDocumentFilter(myFilter);
415             getRepositoryClient(ctx).getFiltered(ctx, handler);
416             orgAuthorityObjectList = (OrgauthoritiesCommonList) handler.getCommonPartList();
417         } catch (UnauthorizedException ue) {
418             Response response = Response.status(
419                     Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
420             throw new WebApplicationException(response);
421         } catch (Exception e) {
422             if (logger.isDebugEnabled()) {
423                 logger.debug("Caught exception in getOrgAuthorityList", e);
424             }
425             Response response = Response.status(
426                     Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
427             throw new WebApplicationException(response);
428         }
429         return orgAuthorityObjectList;
430     }
431
432     /**
433      * Update org authority.
434      * 
435      * @param csid the csid
436      * @param theUpdate the the update
437      * 
438      * @return the multipart output
439      */
440     @PUT
441     @Path("{csid}")
442     public MultipartOutput updateOrgAuthority(
443             @PathParam("csid") String csid,
444             MultipartInput theUpdate) {
445         if (logger.isDebugEnabled()) {
446             logger.debug("updateOrgAuthority with csid=" + csid);
447         }
448         if (csid == null || "".equals(csid)) {
449             logger.error("updateOrgAuthority: missing csid!");
450             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
451                     "update failed on OrgAuthority csid=" + csid).type(
452                     "text/plain").build();
453             throw new WebApplicationException(response);
454         }
455         MultipartOutput result = null;
456         try {
457                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(theUpdate);
458             DocumentHandler handler = createDocumentHandler(ctx);
459             getRepositoryClient(ctx).update(ctx, csid, handler);
460             result = (MultipartOutput) ctx.getOutput();
461         } catch (BadRequestException bre) {
462             Response response = Response.status(
463                     Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
464             throw new WebApplicationException(response);
465         } catch (UnauthorizedException ue) {
466             Response response = Response.status(
467                     Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build();
468             throw new WebApplicationException(response);
469         } catch (DocumentNotFoundException dnfe) {
470             if (logger.isDebugEnabled()) {
471                 logger.debug("caught exception in updateOrgAuthority", dnfe);
472             }
473             Response response = Response.status(Response.Status.NOT_FOUND).entity(
474                     "Update failed on OrgAuthority csid=" + csid).type(
475                     "text/plain").build();
476             throw new WebApplicationException(response);
477         } catch (Exception e) {
478             Response response = Response.status(
479                     Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
480             throw new WebApplicationException(response);
481         }
482         return result;
483     }
484
485     /**
486      * Delete org authority.
487      * 
488      * @param csid the csid
489      * 
490      * @return the response
491      */
492     @DELETE
493     @Path("{csid}")
494     public Response deleteOrgAuthority(@PathParam("csid") String csid) {
495
496         if (logger.isDebugEnabled()) {
497             logger.debug("deleteOrgAuthority with csid=" + csid);
498         }
499         if (csid == null || "".equals(csid)) {
500             logger.error("deleteOrgAuthority: missing csid!");
501             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
502                     "delete failed on OrgAuthority csid=" + csid).type(
503                     "text/plain").build();
504             throw new WebApplicationException(response);
505         }
506         try {
507                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
508             getRepositoryClient(ctx).delete(ctx, csid);
509             return Response.status(HttpResponseCodes.SC_OK).build();
510         } catch (UnauthorizedException ue) {
511             Response response = Response.status(
512                     Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build();
513             throw new WebApplicationException(response);
514         } catch (DocumentNotFoundException dnfe) {
515             if (logger.isDebugEnabled()) {
516                 logger.debug("caught exception in deleteOrgAuthority", dnfe);
517             }
518             Response response = Response.status(Response.Status.NOT_FOUND).entity(
519                     "Delete failed on OrgAuthority csid=" + csid).type(
520                     "text/plain").build();
521             throw new WebApplicationException(response);
522         } catch (Exception e) {
523             Response response = Response.status(
524                     Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
525             throw new WebApplicationException(response);
526         }
527
528     }
529
530     /*************************************************************************
531      * Organization parts - this is a sub-resource of OrgAuthority
532      *************************************************************************/
533     @POST
534     @Path("{csid}/items")
535     public Response createOrganization(@PathParam("csid") String parentcsid, MultipartInput input) {
536         try {
537                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
538                                 input);
539             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
540             String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
541             UriBuilder path = UriBuilder.fromResource(OrgAuthorityResource.class);
542             path.path(parentcsid + "/items/" + itemcsid);
543             Response response = Response.created(path.build()).build();
544             return response;
545         } catch (BadRequestException bre) {
546             Response response = Response.status(
547                     Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
548             throw new WebApplicationException(response);
549         } catch (UnauthorizedException ue) {
550             Response response = Response.status(
551                     Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build();
552             throw new WebApplicationException(response);
553         } catch (Exception e) {
554             if (logger.isDebugEnabled()) {
555                 logger.debug("Caught exception in createOrganization", e);
556             }
557             Response response = Response.status(
558                     Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
559             throw new WebApplicationException(response);
560         }
561     }
562
563     /**
564      * Gets the organization.
565      * 
566      * @param parentcsid the parentcsid
567      * @param itemcsid the itemcsid
568      * 
569      * @return the organization
570      */
571     @GET
572     @Path("{csid}/items/{itemcsid}")
573     public MultipartOutput getOrganization(
574             @PathParam("csid") String parentcsid,
575             @PathParam("itemcsid") String itemcsid) {
576         if (logger.isDebugEnabled()) {
577             logger.debug("getOrganization with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
578         }
579         if (parentcsid == null || "".equals(parentcsid)) {
580             logger.error("getOrganization: missing csid!");
581             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
582                     "get failed on Organization csid=" + parentcsid).type(
583                     "text/plain").build();
584             throw new WebApplicationException(response);
585         }
586         if (itemcsid == null || "".equals(itemcsid)) {
587             logger.error("getOrganization: missing itemcsid!");
588             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
589                     "get failed on Organization itemcsid=" + itemcsid).type(
590                     "text/plain").build();
591             throw new WebApplicationException(response);
592         }
593         MultipartOutput result = null;
594         try {
595             // Note that we have to create the service context for the Items, not the main service
596                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
597             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
598             getRepositoryClient(ctx).get(ctx, itemcsid, handler);
599             // TODO should we assert that the item is in the passed orgAuthority?
600             result = (MultipartOutput) ctx.getOutput();
601         } catch (UnauthorizedException ue) {
602             Response response = Response.status(
603                     Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
604             throw new WebApplicationException(response);
605         } catch (DocumentNotFoundException dnfe) {
606             if (logger.isDebugEnabled()) {
607                 logger.debug("getOrganization", dnfe);
608             }
609             Response response = Response.status(Response.Status.NOT_FOUND).entity(
610                     "Get failed on Organization csid=" + itemcsid).type(
611                     "text/plain").build();
612             throw new WebApplicationException(response);
613         } catch (Exception e) {
614             if (logger.isDebugEnabled()) {
615                 logger.debug("getOrganization", e);
616             }
617             Response response = Response.status(
618                     Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
619             throw new WebApplicationException(response);
620         }
621         if (result == null) {
622             Response response = Response.status(Response.Status.NOT_FOUND).entity(
623                     "Get failed, the requested Organization CSID:" + itemcsid + ": was not found.").type(
624                     "text/plain").build();
625             throw new WebApplicationException(response);
626         }
627         return result;
628     }
629
630     /**
631      * Gets the organization list.
632      * 
633      * @param parentcsid the parentcsid
634      * @param partialTerm the partial term
635      * @param ui the ui
636      * 
637      * @return the organization list
638      */
639     @GET
640     @Path("{csid}/items")
641     @Produces("application/xml")
642     public OrganizationsCommonList getOrganizationList(
643             @PathParam("csid") String parentcsid,
644             @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
645             @Context UriInfo ui) {
646         OrganizationsCommonList organizationObjectList = new OrganizationsCommonList();
647         try {
648             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
649             // Note that docType defaults to the ServiceName, so we're fine with that.
650                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
651                                 queryParams);
652             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
653             DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
654             myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
655             myFilter.setWhereClause(OrganizationJAXBSchema.ORGANIZATIONS_COMMON +
656                         ":" + OrganizationJAXBSchema.IN_AUTHORITY + "=" +
657                         "'" + parentcsid + "'");
658             
659             // AND organizations_common:displayName LIKE '%partialTerm%'
660             if (partialTerm != null && !partialTerm.isEmpty()) {
661                 String ptClause = "AND " + OrganizationJAXBSchema.ORGANIZATIONS_COMMON +
662                         ":" + OrganizationJAXBSchema.DISPLAY_NAME +
663                         " LIKE " + "'%" + partialTerm + "%'";
664                 myFilter.appendWhereClause(ptClause);
665             }            
666             handler.setDocumentFilter(myFilter);
667             getRepositoryClient(ctx).getFiltered(ctx, handler);
668             organizationObjectList = (OrganizationsCommonList) handler.getCommonPartList();
669         } catch (UnauthorizedException ue) {
670             Response response = Response.status(
671                     Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
672             throw new WebApplicationException(response);
673         } catch (Exception e) {
674             if (logger.isDebugEnabled()) {
675                 logger.debug("Caught exception in getOrganizationList", e);
676             }
677             Response response = Response.status(
678                     Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
679             throw new WebApplicationException(response);
680         }
681         return organizationObjectList;
682     }
683
684     /**
685      * Gets the organization list by auth name.
686      * 
687      * @param parentSpecifier the parent specifier
688      * @param partialTerm the partial term
689      * @param ui the ui
690      * 
691      * @return the organization list by auth name
692      */
693     @GET
694     @Path("urn:cspace:name({specifier})/items")
695     @Produces("application/xml")
696     public OrganizationsCommonList getOrganizationListByAuthName(
697                 @PathParam("specifier") String parentSpecifier,
698             @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,            
699             @Context UriInfo ui) {
700         OrganizationsCommonList personObjectList = new OrganizationsCommonList();
701         try {
702             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
703             String whereClause =
704                 OrgAuthorityJAXBSchema.ORGAUTHORITIES_COMMON+
705                 ":"+OrgAuthorityJAXBSchema.DISPLAY_NAME+
706                 "='"+parentSpecifier+"'";
707             // Need to get an Authority by name
708             ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
709             String parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
710
711             ctx = createServiceContext(getItemServiceName(), queryParams);
712             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
713             DocumentFilter myFilter = handler.createDocumentFilter();// new DocumentFilter();
714             myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
715
716             // Add the where clause "organizations_common:inAuthority='" + parentcsid + "'"
717             myFilter.setWhereClause(OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" +
718                         OrganizationJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'");
719             
720             // AND organizations_common:displayName LIKE '%partialTerm%'
721             if (partialTerm != null && !partialTerm.isEmpty()) {
722                 String ptClause = "AND " +
723                 OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" +
724                 OrganizationJAXBSchema.DISPLAY_NAME +
725                         " LIKE " +
726                         "'%" + partialTerm + "%'";
727                 myFilter.appendWhereClause(ptClause);
728             }
729             
730             handler.setDocumentFilter(myFilter);
731             getRepositoryClient(ctx).getFiltered(ctx, handler);
732             personObjectList = (OrganizationsCommonList) handler.getCommonPartList();
733         } catch (UnauthorizedException ue) {
734             Response response = Response.status(
735                     Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
736             throw new WebApplicationException(response);
737         } catch (Exception e) {
738             if (logger.isDebugEnabled()) {
739                 logger.debug("Caught exception in getOrganizationListByAuthName", e);
740             }
741             Response response = Response.status(
742                     Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
743             throw new WebApplicationException(response);
744         }
745         return personObjectList;
746     }
747
748     /**
749      * Update organization.
750      * 
751      * @param parentcsid the parentcsid
752      * @param itemcsid the itemcsid
753      * @param theUpdate the the update
754      * 
755      * @return the multipart output
756      */
757     @PUT
758     @Path("{csid}/items/{itemcsid}")
759     public MultipartOutput updateOrganization(
760             @PathParam("csid") String parentcsid,
761             @PathParam("itemcsid") String itemcsid,
762             MultipartInput theUpdate) {
763         if (logger.isDebugEnabled()) {
764             logger.debug("updateOrganization with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
765         }
766         if (parentcsid == null || "".equals(parentcsid)) {
767             logger.error("updateOrganization: missing csid!");
768             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
769                     "update failed on Organization parentcsid=" + parentcsid).type(
770                     "text/plain").build();
771             throw new WebApplicationException(response);
772         }
773         if (itemcsid == null || "".equals(itemcsid)) {
774             logger.error("updateOrganization: missing itemcsid!");
775             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
776                     "update failed on Organization=" + itemcsid).type(
777                     "text/plain").build();
778             throw new WebApplicationException(response);
779         }
780         MultipartOutput result = null;
781         try {
782             // Note that we have to create the service context for the Items, not the main service
783                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
784                                 theUpdate);
785             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
786             getRepositoryClient(ctx).update(ctx, itemcsid, handler);
787             result = (MultipartOutput) ctx.getOutput();
788         } catch (BadRequestException bre) {
789             Response response = Response.status(
790                     Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
791             throw new WebApplicationException(response);
792         } catch (UnauthorizedException ue) {
793             Response response = Response.status(
794                     Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build();
795             throw new WebApplicationException(response);
796         } catch (DocumentNotFoundException dnfe) {
797             if (logger.isDebugEnabled()) {
798                 logger.debug("caught exception in updateOrganization", dnfe);
799             }
800             Response response = Response.status(Response.Status.NOT_FOUND).entity(
801                     "Update failed on Organization csid=" + itemcsid).type(
802                     "text/plain").build();
803             throw new WebApplicationException(response);
804         } catch (Exception e) {
805             Response response = Response.status(
806                     Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
807             throw new WebApplicationException(response);
808         }
809         return result;
810     }
811
812     /**
813      * Delete organization.
814      * 
815      * @param parentcsid the parentcsid
816      * @param itemcsid the itemcsid
817      * 
818      * @return the response
819      */
820     @DELETE
821     @Path("{csid}/items/{itemcsid}")
822     public Response deleteOrganization(
823             @PathParam("csid") String parentcsid,
824             @PathParam("itemcsid") String itemcsid) {
825         if (logger.isDebugEnabled()) {
826             logger.debug("deleteOrganization with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
827         }
828         if (parentcsid == null || "".equals(parentcsid)) {
829             logger.error("deleteOrganization: missing csid!");
830             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
831                     "delete failed on Organization parentcsid=" + parentcsid).type(
832                     "text/plain").build();
833             throw new WebApplicationException(response);
834         }
835         if (itemcsid == null || "".equals(itemcsid)) {
836             logger.error("deleteOrganization: missing itemcsid!");
837             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
838                     "delete failed on Organization=" + itemcsid).type(
839                     "text/plain").build();
840             throw new WebApplicationException(response);
841         }
842         try {
843             // Note that we have to create the service context for the Items, not the main service
844                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
845             getRepositoryClient(ctx).delete(ctx, itemcsid);
846             return Response.status(HttpResponseCodes.SC_OK).build();
847         } catch (UnauthorizedException ue) {
848             Response response = Response.status(
849                     Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build();
850             throw new WebApplicationException(response);
851         } catch (DocumentNotFoundException dnfe) {
852             if (logger.isDebugEnabled()) {
853                 logger.debug("caught exception in deleteOrganization", dnfe);
854             }
855             Response response = Response.status(Response.Status.NOT_FOUND).entity(
856                     "Delete failed on Organization itemcsid=" + itemcsid).type(
857                     "text/plain").build();
858             throw new WebApplicationException(response);
859         } catch (Exception e) {
860             Response response = Response.status(
861                     Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
862             throw new WebApplicationException(response);
863         }
864
865     }
866
867     /*************************************************************************
868      * Contact parts - this is a sub-resource of Organization (or "item")
869      *************************************************************************/
870     @POST
871     @Path("{parentcsid}/items/{itemcsid}/contacts")
872     public Response createContact(
873             @PathParam("parentcsid") String parentcsid,
874             @PathParam("itemcsid") String itemcsid,
875             MultipartInput input) {
876         try {
877             // Note that we have to create the service context and document
878             // handler for the Contact service, not the main service.
879                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName(), input);
880             DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
881             String csid = getRepositoryClient(ctx).create(ctx, handler);
882             UriBuilder path = UriBuilder.fromResource(OrgAuthorityResource.class);
883             path.path("" + parentcsid + "/items/" + itemcsid + "/contacts/" + csid);
884             Response response = Response.created(path.build()).build();
885             return response;
886         } catch (BadRequestException bre) {
887             Response response = Response.status(
888                     Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
889             throw new WebApplicationException(response);
890         } catch (UnauthorizedException ue) {
891             Response response = Response.status(
892                     Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build();
893             throw new WebApplicationException(response);
894         } catch (Exception e) {
895             if (logger.isDebugEnabled()) {
896                 logger.debug("Caught exception in createContact", e);
897             }
898             Response response = Response.status(
899                 Response.Status.INTERNAL_SERVER_ERROR)
900                 .entity("Attempt to create Contact failed.")
901                 .type("text/plain").build();
902             throw new WebApplicationException(response);
903         }
904
905     }
906
907     /**
908      * Gets the contact list.
909      * 
910      * @param parentcsid the parentcsid
911      * @param itemcsid the itemcsid
912      * @param ui the ui
913      * 
914      * @return the contact list
915      */
916     @GET
917     @Produces({"application/xml"})
918     @Path("{parentcsid}/items/{itemcsid}/contacts/")
919     public ContactsCommonList getContactList(
920             @PathParam("parentcsid") String parentcsid,
921             @PathParam("itemcsid") String itemcsid,
922             @Context UriInfo ui) {
923         ContactsCommonList contactObjectList = new ContactsCommonList();
924         try {
925             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
926                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName(),
927                                 queryParams);
928             DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
929             DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
930             myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
931             myFilter.setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" +
932                 ContactJAXBSchema.IN_AUTHORITY +
933                 "='" + parentcsid + "'" +
934                 " AND " +
935                 ContactJAXBSchema.CONTACTS_COMMON + ":" +
936                 ContactJAXBSchema.IN_ITEM +
937                 "='" + itemcsid + "'" +
938                 " AND ecm:isProxy = 0");
939             handler.setDocumentFilter(myFilter);
940             getRepositoryClient(ctx).getFiltered(ctx, handler);
941             contactObjectList = (ContactsCommonList) handler.getCommonPartList();
942         } catch (UnauthorizedException ue) {
943             Response response = Response.status(
944                     Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
945             throw new WebApplicationException(response);
946         } catch (Exception e) {
947             if (logger.isDebugEnabled()) {
948                 logger.debug("Caught exception in getContactsList", e);
949             }
950             Response response = Response.status(
951                     Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
952             throw new WebApplicationException(response);
953         }
954         return contactObjectList;
955     }
956
957     /**
958      * Gets the contact.
959      * 
960      * @param parentcsid the parentcsid
961      * @param itemcsid the itemcsid
962      * @param csid the csid
963      * 
964      * @return the contact
965      */
966     @GET
967     @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}")
968     public MultipartOutput getContact(
969             @PathParam("parentcsid") String parentcsid,
970             @PathParam("itemcsid") String itemcsid,
971             @PathParam("csid") String csid) {
972         MultipartOutput result = null;
973        if (logger.isDebugEnabled()) {
974             logger.debug("getContact with parentCsid=" + parentcsid +
975             " itemcsid=" + itemcsid + " csid=" + csid);
976         }
977         try {
978             // Note that we have to create the service context and document
979             // handler for the Contact service, not the main service.
980                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName());
981             DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
982             getRepositoryClient(ctx).get(ctx, csid, handler);
983             result = (MultipartOutput) ctx.getOutput();
984         } catch (UnauthorizedException ue) {
985             Response response = Response.status(
986                     Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
987             throw new WebApplicationException(response);
988         } catch (DocumentNotFoundException dnfe) {
989             if (logger.isDebugEnabled()) {
990                 logger.debug("getContact", dnfe);
991             }
992             Response response = Response.status(Response.Status.NOT_FOUND)
993                 .entity("Get failed, the requested Contact CSID:" + csid + ": was not found.")
994                 .type("text/plain").build();
995             throw new WebApplicationException(response);
996         } catch (Exception e) {
997             if (logger.isDebugEnabled()) {
998                 logger.debug("getContact", e);
999             }
1000             Response response = Response.status(Response.Status.INTERNAL_SERVER_ERROR)
1001                 .entity("Get contact failed")
1002                 .type("text/plain").build();
1003             throw new WebApplicationException(response);
1004         }
1005         if (result == null) {
1006             Response response = Response.status(Response.Status.NOT_FOUND)
1007                 .entity("Get failed, the requested Contact CSID:" + csid + ": was not found.")
1008                 .type("text/plain").build();
1009             throw new WebApplicationException(response);
1010         }
1011         return result;
1012
1013     }
1014
1015     /**
1016      * Update contact.
1017      * 
1018      * @param parentcsid the parentcsid
1019      * @param itemcsid the itemcsid
1020      * @param csid the csid
1021      * @param theUpdate the the update
1022      * 
1023      * @return the multipart output
1024      */
1025     @PUT
1026     @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}")
1027     public MultipartOutput updateContact(
1028             @PathParam("parentcsid") String parentcsid,
1029             @PathParam("itemcsid") String itemcsid,
1030             @PathParam("csid") String csid,
1031             MultipartInput theUpdate) {
1032        if (logger.isDebugEnabled()) {
1033             logger.debug("updateContact with parentcsid=" + parentcsid +
1034             " itemcsid=" + itemcsid + " csid=" + csid);
1035         }
1036        if (parentcsid == null || parentcsid.trim().isEmpty()) {
1037             logger.error("updateContact: missing csid!");
1038             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
1039                     "update failed on Contact parentcsid=" + parentcsid).type(
1040                     "text/plain").build();
1041             throw new WebApplicationException(response);
1042         }
1043         if (itemcsid == null || itemcsid.trim().isEmpty()) {
1044             logger.error("updateContact: missing itemcsid!");
1045             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
1046                     "update failed on Contact=" + itemcsid).type(
1047                     "text/plain").build();
1048             throw new WebApplicationException(response);
1049         }
1050         if (csid == null || csid.trim().isEmpty()) {
1051             logger.error("updateContact: missing csid!");
1052             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
1053                     "update failed on Contact=" + csid).type(
1054                     "text/plain").build();
1055             throw new WebApplicationException(response);
1056         }
1057         MultipartOutput result = null;
1058         try {
1059             // Note that we have to create the service context and document
1060             // handler for the Contact service, not the main service.
1061                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName(), theUpdate);
1062             DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
1063             getRepositoryClient(ctx).update(ctx, csid, handler);
1064             result = (MultipartOutput) ctx.getOutput();
1065         } catch (BadRequestException bre) {
1066             Response response = Response.status(
1067                     Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
1068             throw new WebApplicationException(response);
1069         } catch (UnauthorizedException ue) {
1070             Response response = Response.status(
1071                     Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build();
1072             throw new WebApplicationException(response);
1073         } catch (DocumentNotFoundException dnfe) {
1074             if (logger.isDebugEnabled()) {
1075                 logger.debug("caught exception in updateContact", dnfe);
1076             }
1077             Response response = Response.status(Response.Status.NOT_FOUND).entity(
1078                     "Update failed on Contact csid=" + itemcsid).type(
1079                     "text/plain").build();
1080             throw new WebApplicationException(response);
1081         } catch (Exception e) {
1082             Response response = Response.status(
1083                     Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
1084             throw new WebApplicationException(response);
1085         }
1086         return result;
1087     }
1088
1089     /**
1090      * Delete contact.
1091      * 
1092      * @param parentcsid the parentcsid
1093      * @param itemcsid the itemcsid
1094      * @param csid the csid
1095      * 
1096      * @return the response
1097      */
1098     @DELETE
1099     @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}")
1100     public Response deleteContact(
1101             @PathParam("parentcsid") String parentcsid,
1102             @PathParam("itemcsid") String itemcsid,
1103             @PathParam("csid") String csid) {
1104         if (logger.isDebugEnabled()) {
1105             logger.debug("deleteContact with parentCsid=" + parentcsid +
1106             " itemcsid=" + itemcsid + " csid=" + csid);
1107         }
1108         if (parentcsid == null || parentcsid.trim().isEmpty()) {
1109             logger.error("deleteContact: missing parentcsid!");
1110             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
1111                     "delete contact failed on parentcsid=" + parentcsid).type(
1112                     "text/plain").build();
1113             throw new WebApplicationException(response);
1114         }
1115         if (itemcsid == null || itemcsid.trim().isEmpty()) {
1116             logger.error("deleteContact: missing itemcsid!");
1117             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
1118                     "delete contact failed on itemcsid=" + itemcsid).type(
1119                     "text/plain").build();
1120             throw new WebApplicationException(response);
1121         }
1122         if (csid == null || csid.trim().isEmpty()) {
1123             logger.error("deleteContact: missing csid!");
1124             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
1125                     "delete contact failed on csid=" + csid).type(
1126                     "text/plain").build();
1127             throw new WebApplicationException(response);
1128         }
1129         try {
1130             // Note that we have to create the service context for the
1131             // Contact service, not the main service.
1132                 ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName());
1133             getRepositoryClient(ctx).delete(ctx, csid);
1134             return Response.status(HttpResponseCodes.SC_OK).build();
1135          } catch (UnauthorizedException ue) {
1136             Response response = Response.status(
1137                     Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build();
1138             throw new WebApplicationException(response);
1139          } catch (DocumentNotFoundException dnfe) {
1140             if (logger.isDebugEnabled()) {
1141                 logger.debug("Caught exception in deleteContact", dnfe);
1142             }
1143             Response response = Response.status(Response.Status.NOT_FOUND)
1144                 .entity("Delete failed, the requested Contact CSID:" + csid + ": was not found.")
1145                 .type("text/plain").build();
1146             throw new WebApplicationException(response);
1147        } catch (Exception e) {
1148             Response response = Response.status(
1149                     Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
1150             throw new WebApplicationException(response);
1151         }
1152     }
1153
1154 }