]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
13393df66e84dd77e43cd40ae3007f28f197c5bb
[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.authorization;
25
26 import javax.ws.rs.Consumes;
27 import javax.ws.rs.GET;
28 import javax.ws.rs.Path;
29 import javax.ws.rs.Produces;
30 import javax.ws.rs.DELETE;
31 import javax.ws.rs.POST;
32 import javax.ws.rs.PUT;
33 import javax.ws.rs.PathParam;
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.account.AccountRoleSubResource;
43 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
44 //import org.collectionspace.services.common.context.RemoteServiceContextImpl;
45 import org.collectionspace.services.common.ServiceMessages;
46 import org.collectionspace.services.common.context.ServiceContext;
47 import org.collectionspace.services.common.context.ServiceContextFactory;
48 import org.collectionspace.services.common.context.RemoteServiceContextFactory;
49 import org.collectionspace.services.common.document.BadRequestException;
50 import org.collectionspace.services.common.document.DocumentException;
51 import org.collectionspace.services.common.document.DocumentFilter;
52 import org.collectionspace.services.common.document.DocumentNotFoundException;
53 import org.collectionspace.services.common.document.DocumentHandler;
54 import org.collectionspace.services.common.security.UnauthorizedException;
55 import org.collectionspace.services.common.storage.StorageClient;
56 import org.collectionspace.services.common.storage.jpa.JpaStorageClientImpl;
57 import org.jboss.resteasy.util.HttpResponseCodes;
58 import org.slf4j.Logger;
59 import org.slf4j.LoggerFactory;
60
61 // TODO: Auto-generated Javadoc
62 /**
63  * The Class RoleResource.
64  */
65 @Path("/authorization/roles") //FIXME: REM - Replace string constant with RoleClient.SERVICE_PATH
66 @Consumes("application/xml")
67 @Produces("application/xml")
68 public class RoleResource
69         extends AbstractCollectionSpaceResourceImpl {
70
71     /** The service name. */
72     final private String serviceName = "authorization/roles";
73     /** The logger. */
74     final Logger logger = LoggerFactory.getLogger(RoleResource.class);
75     /** The storage client. */
76     final StorageClient storageClient = new JpaStorageClientImpl();
77
78     /* (non-Javadoc)
79      * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
80      */
81     @Override
82     protected String getVersionString() {
83         /** The last change revision. */
84         final String lastChangeRevision = "$LastChangedRevision: 1165 $";
85         return lastChangeRevision;
86     }
87
88     /* (non-Javadoc)
89      * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
90      */
91     @Override
92     public String getServiceName() {
93         return serviceName;
94     }
95
96     /* (non-Javadoc)
97      * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
98      */
99     @Override
100     public Class<RoleResource> getCommonPartClass() {
101         return RoleResource.class;
102     }
103
104     /* (non-Javadoc)
105      * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceContextFactory()
106      */
107     @Override
108     public ServiceContextFactory getServiceContextFactory() {
109         return RemoteServiceContextFactory.get();
110     }
111
112 //    private <T> ServiceContext createServiceContext(T obj) throws Exception {
113 //        ServiceContext ctx = new RemoteServiceContextImpl<T, T>(getServiceName());
114 //        ctx.setInput(obj);
115 //        ctx.setDocumentType(Role.class.getPackage().getName()); //persistence unit
116 //        ctx.setProperty("entity-name", Role.class.getName());
117 //        return ctx;
118 //    }
119
120     /* (non-Javadoc)
121      * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getStorageClient(org.collectionspace.services.common.context.ServiceContext)
122      */
123     @Override
124     public StorageClient getStorageClient(ServiceContext ctx) {
125         //FIXME use ctx to identify storage client
126         return storageClient;
127     }
128
129 //    @Override
130 //    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
131 //        DocumentHandler docHandler = ctx.getDocumentHandler();
132 //        docHandler.setCommonPart(ctx.getInput());
133 //        return docHandler;
134 //    }
135     /**
136      * Creates the role.
137      *
138      * @param input the input
139      *
140      * @return the response
141      */
142     @POST
143     public Response createRole(Role input) {
144         Response response = null;
145
146         try {
147             ServiceContext ctx = createServiceContext(input, Role.class);
148             DocumentHandler handler = createDocumentHandler(ctx);
149             String csid = getStorageClient(ctx).create(ctx, handler);
150             UriBuilder path = UriBuilder.fromResource(RoleResource.class);
151             path.path("" + csid);
152             response = Response.created(path.build()).build();
153         } catch (BadRequestException bre) {
154             response = Response.status(
155                     Response.Status.BAD_REQUEST).entity(ServiceMessages.POST_FAILED
156                     + bre.getErrorReason()).type("text/plain").build();
157             throw new WebApplicationException(response);
158         } catch (DocumentException bre) {
159             response = Response.status(
160                     Response.Status.BAD_REQUEST).entity(ServiceMessages.POST_FAILED
161                     + bre.getErrorReason()).type("text/plain").build();
162             throw new WebApplicationException(response);
163         } catch (UnauthorizedException ue) {
164             response = Response.status(
165                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.POST_FAILED
166                     + ue.getErrorReason()).type("text/plain").build();
167             throw new WebApplicationException(response);
168         } catch (Exception e) {
169             if (logger.isDebugEnabled()) {
170                 logger.debug("Caught a general exception in RoleResource:createRole post: ", e);
171             }
172             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
173             response = Response.status(
174                     Response.Status.INTERNAL_SERVER_ERROR).entity(ServiceMessages.POST_FAILED
175                     + e.getMessage()).type("text/plain").build();
176             throw new WebApplicationException(e, response);
177         }
178         
179         return response;        
180     }
181
182     /**
183      * Gets the role.
184      * 
185      * @param csid the csid
186      * 
187      * @return the role
188      */
189     @GET
190     @Path("{csid}")
191     public Role getRole(
192             @PathParam("csid") String csid) {
193         if (logger.isDebugEnabled()) {
194             logger.debug("getRole with csid=" + csid);
195         }
196         if (csid == null || "".equals(csid)) {
197             logger.error("getRole: missing csid!");
198             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
199                     ServiceMessages.GET_FAILED + "role csid=").type(
200                     "text/plain").build();
201             throw new WebApplicationException(response);
202         }
203         Role result = null;
204         try {
205             ServiceContext ctx = createServiceContext((Role) null, Role.class);
206             DocumentHandler handler = createDocumentHandler(ctx);
207             getStorageClient(ctx).get(ctx, csid, handler);
208             result = (Role) ctx.getOutput();
209         } catch (UnauthorizedException ue) {
210             Response response = Response.status(
211                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.GET_FAILED
212                     + ue.getErrorReason()).type("text/plain").build();
213             throw new WebApplicationException(response);
214         } catch (DocumentNotFoundException dnfe) {
215             if (logger.isDebugEnabled()) {
216                 logger.debug("getRole", dnfe);
217             }
218             Response response = Response.status(Response.Status.NOT_FOUND).entity(
219                     ServiceMessages.GET_FAILED + "role csid=" + csid).type(
220                     "text/plain").build();
221             throw new WebApplicationException(response);
222         } catch (Exception e) {
223             if (logger.isDebugEnabled()) {
224                 logger.debug("getRole", e);
225             }
226             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
227             Response response = Response.status(
228                     Response.Status.INTERNAL_SERVER_ERROR).entity(ServiceMessages.GET_FAILED
229                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
230             throw new WebApplicationException(response);
231         }
232
233         if (result == null) {
234             Response response = Response.status(Response.Status.NOT_FOUND).entity(
235                     ServiceMessages.GET_FAILED + "role csid=" + csid + ": was not found.").type(
236                     "text/plain").build();
237             throw new WebApplicationException(response);
238         }
239         return result;
240     }
241
242     /**
243      * Gets the role list.
244      * 
245      * @param ui the ui
246      * 
247      * @return the role list
248      */
249     @GET
250     @Produces("application/xml")
251     public RolesList getRoleList(
252             @Context UriInfo ui) {
253         RolesList roleList = new RolesList();
254         try {
255             ServiceContext ctx = createServiceContext((Role) null, Role.class);
256             DocumentHandler handler = createDocumentHandler(ctx);
257             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
258             DocumentFilter myFilter = handler.createDocumentFilter();
259             myFilter.setPagination(queryParams);
260             myFilter.setQueryParams(queryParams);
261             handler.setDocumentFilter(myFilter);
262             getStorageClient(ctx).getFiltered(ctx, handler);
263             roleList = (RolesList) handler.getCommonPartList();
264         } catch (UnauthorizedException ue) {
265             Response response = Response.status(
266                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.LIST_FAILED
267                     + ue.getErrorReason()).type("text/plain").build();
268             throw new WebApplicationException(response);
269
270         } catch (Exception e) {
271             if (logger.isDebugEnabled()) {
272                 logger.debug("Caught exception in getRoleList", e);
273             }
274             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
275             Response response = Response.status(
276                     Response.Status.INTERNAL_SERVER_ERROR).entity(ServiceMessages.LIST_FAILED
277                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
278             throw new WebApplicationException(response);
279         }
280         return roleList;
281     }
282
283     /**
284      * Update role.
285      * 
286      * @param csid the csid
287      * @param theUpdate the the update
288      * 
289      * @return the role
290      */
291     @PUT
292     @Path("{csid}")
293     public Role updateRole(
294             @PathParam("csid") String csid,
295             Role theUpdate) {
296         if (logger.isDebugEnabled()) {
297             logger.debug("updateRole with csid=" + csid);
298         }
299         if (csid == null || "".equals(csid)) {
300             logger.error("updateRole: missing csid!");
301             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
302                     ServiceMessages.PUT_FAILED + "role "
303                     + ServiceMessages.MISSING_INVALID_CSID + csid).type(
304                     "text/plain").build();
305             throw new WebApplicationException(response);
306         }
307         Role result = null;
308         try {
309             ServiceContext ctx = createServiceContext(theUpdate, Role.class);
310             DocumentHandler handler = createDocumentHandler(ctx);
311             getStorageClient(ctx).update(ctx, csid, handler);
312             result = (Role) ctx.getOutput();
313         } catch (BadRequestException bre) {
314             Response response = Response.status(
315                     Response.Status.BAD_REQUEST).entity(ServiceMessages.PUT_FAILED
316                     + bre.getErrorReason()).type("text/plain").build();
317             throw new WebApplicationException(response);
318         } catch (UnauthorizedException ue) {
319             Response response = Response.status(
320                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.PUT_FAILED
321                     + ue.getErrorReason()).type("text/plain").build();
322             throw new WebApplicationException(response);
323         } catch (DocumentNotFoundException dnfe) {
324             if (logger.isDebugEnabled()) {
325                 logger.debug("caugth exception in updateRole", dnfe);
326             }
327             Response response = Response.status(Response.Status.NOT_FOUND).entity(
328                     ServiceMessages.PUT_FAILED + "role csid=" + csid).type(
329                     "text/plain").build();
330             throw new WebApplicationException(response);
331         } catch (Exception e) {
332             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
333             Response response = Response.status(
334                     Response.Status.INTERNAL_SERVER_ERROR).entity(
335                     ServiceMessages.PUT_FAILED
336                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
337             throw new WebApplicationException(response);
338         }
339         return result;
340     }
341
342     /**
343      * Delete role.
344      * 
345      * @param csid the csid
346      * 
347      * @return the response
348      */
349     @DELETE
350     @Path("{csid}")
351     public Response deleteRole(@PathParam("csid") String csid) {
352
353         if (logger.isDebugEnabled()) {
354             logger.debug("deleteRole with csid=" + csid);
355         }
356         if (csid == null || "".equals(csid)) {
357             logger.error("deleteRole: missing csid!");
358             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
359                     ServiceMessages.DELETE_FAILED + "role csid=" + csid).type(
360                     "text/plain").build();
361             throw new WebApplicationException(response);
362         }
363         try {
364             //FIXME ideally the following three operations should be in the same tx CSPACE-658
365             //delete all relationships for this permission
366             PermissionRoleSubResource permRoleResource =
367                     new PermissionRoleSubResource(PermissionRoleSubResource.ROLE_PERMROLE_SERVICE);
368             permRoleResource.deletePermissionRole(csid, SubjectType.PERMISSION);
369             //delete all the account/role relationships associate with this role
370             AccountRoleSubResource accountRoleResource =
371                 new AccountRoleSubResource(AccountRoleSubResource.ROLE_ACCOUNTROLE_SERVICE);
372             accountRoleResource.deleteAccountRole(csid, SubjectType.ACCOUNT);
373             //finally, delete the role itself
374             ServiceContext<Role, Role> ctx = createServiceContext((Role) null, Role.class);
375             ((JpaStorageClientImpl) getStorageClient(ctx)).deleteWhere(ctx, csid);
376             return Response.status(HttpResponseCodes.SC_OK).build();
377         } catch (UnauthorizedException ue) {
378             Response response = Response.status(
379                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.DELETE_FAILED + ue.getErrorReason()).type("text/plain").build();
380             throw new WebApplicationException(response);
381
382         } catch (DocumentNotFoundException dnfe) {
383             if (logger.isDebugEnabled()) {
384                 logger.debug("caught exception in deleteRole", dnfe);
385             }
386             Response response = Response.status(Response.Status.NOT_FOUND).entity(
387                     ServiceMessages.DELETE_FAILED + "role csid=" + csid).type(
388                     "text/plain").build();
389             throw new WebApplicationException(response);
390         } catch (Exception e) {
391             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
392             Response response = Response.status(
393                     Response.Status.INTERNAL_SERVER_ERROR).entity(
394                     ServiceMessages.DELETE_FAILED + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
395             throw new WebApplicationException(response);
396         }
397
398     }
399
400     /**
401      * Creates the role permission.
402      *
403      * @param method the method
404      * @param roleCsid the role csid
405      * @param input the input
406      * @return the response
407      */
408     @POST
409     @Path("{csid}/permroles")
410     public Response createRolePermission(@QueryParam("_method") String method, @PathParam("csid") String roleCsid,
411             PermissionRole input) {
412         if (method != null) {
413             if ("delete".equalsIgnoreCase(method)) {
414                 return deleteRolePermission(roleCsid, input);
415             }
416         }
417         if (logger.isDebugEnabled()) {
418             logger.debug("createRolePermission with roleCsid=" + roleCsid);
419         }
420         if (roleCsid == null || "".equals(roleCsid)) {
421             logger.error("createRolePermission: missing roleCsid!");
422             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
423                     ServiceMessages.POST_FAILED + "permroles role "
424                     + ServiceMessages.MISSING_INVALID_CSID + roleCsid).type(
425                     "text/plain").build();
426             throw new WebApplicationException(response);
427         }
428         try {
429             PermissionRoleSubResource subResource =
430                     new PermissionRoleSubResource(PermissionRoleSubResource.ROLE_PERMROLE_SERVICE);
431             String permrolecsid = subResource.createPermissionRole(input, SubjectType.PERMISSION);
432             UriBuilder path = UriBuilder.fromResource(RoleResource.class);
433             path.path(roleCsid + "/permroles/" + permrolecsid);
434             Response response = Response.created(path.build()).build();
435             return response;
436         } catch (BadRequestException bre) {
437             Response response = Response.status(
438                     Response.Status.BAD_REQUEST).entity("Create failed reason "
439                     + bre.getErrorReason()).type("text/plain").build();
440             throw new WebApplicationException(response);
441         } catch (UnauthorizedException ue) {
442             Response response = Response.status(
443                     Response.Status.UNAUTHORIZED).entity("Create failed reason "
444                     + ue.getErrorReason()).type("text/plain").build();
445             throw new WebApplicationException(response);
446         } catch (Exception e) {
447             if (logger.isDebugEnabled()) {
448                 logger.debug("Caught exception in createRolePermission", e);
449             }
450             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
451             Response response = Response.status(
452                     Response.Status.INTERNAL_SERVER_ERROR).entity(
453                     ServiceMessages.POST_FAILED
454                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
455             throw new WebApplicationException(response);
456         }
457     }
458
459     /**
460      * Gets the role permission.
461      *
462      * @param roleCsid the role csid
463      * @param permrolecsid the permrolecsid
464      * @return the role permission
465      */
466     @GET
467     @Path("{csid}/permroles")
468     public PermissionRole getRolePermission(
469             @PathParam("csid") String roleCsid) {
470         if (logger.isDebugEnabled()) {
471             logger.debug("getRolePermission with roleCsid=" + roleCsid);
472         }
473         if (roleCsid == null || "".equals(roleCsid)) {
474             logger.error("getRolePermission: missing roleCsid!");
475             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
476                     ServiceMessages.GET_FAILED + "permroles role "
477                     + ServiceMessages.MISSING_INVALID_CSID + roleCsid).type(
478                     "text/plain").build();
479             throw new WebApplicationException(response);
480         }
481         PermissionRole result = null;
482         try {
483             PermissionRoleSubResource subResource =
484                     new PermissionRoleSubResource(PermissionRoleSubResource.ROLE_PERMROLE_SERVICE);
485             //get relationships for a role
486             result = subResource.getPermissionRole(roleCsid, SubjectType.PERMISSION);
487         } catch (UnauthorizedException ue) {
488             Response response = Response.status(
489                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.GET_FAILED
490                     + ue.getErrorReason()).type("text/plain").build();
491             throw new WebApplicationException(response);
492         } catch (DocumentNotFoundException dnfe) {
493             if (logger.isDebugEnabled()) {
494                 logger.debug("getRolePermission", dnfe);
495             }
496             Response response = Response.status(Response.Status.NOT_FOUND).entity(
497                     ServiceMessages.GET_FAILED + "permroles role csid=" + roleCsid).type(
498                     "text/plain").build();
499             throw new WebApplicationException(response);
500         } catch (Exception e) {
501             if (logger.isDebugEnabled()) {
502                 logger.debug("getRolePermission", e);
503             }
504             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
505             Response response = Response.status(
506                     Response.Status.INTERNAL_SERVER_ERROR).entity(
507                     ServiceMessages.GET_FAILED
508                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
509             throw new WebApplicationException(response);
510         }
511         if (result == null) {
512             Response response = Response.status(Response.Status.NOT_FOUND).entity(
513                     ServiceMessages.GET_FAILED + "permroles role csid=" + roleCsid
514                     + ": was not found.").type(
515                     "text/plain").build();
516             throw new WebApplicationException(response);
517         }
518         return result;
519     }
520
521     @GET
522     @Path("{csid}/permroles/{id}")
523     public PermissionRoleRel getRolePermission(
524             @PathParam("csid") String roleCsid,
525             @PathParam("id") String permrolecsid) {
526         if (logger.isDebugEnabled()) {
527             logger.debug("getRolePermission with roleCsid=" + roleCsid);
528         }
529         if (roleCsid == null || "".equals(roleCsid)) {
530             logger.error("getRolePermission: missing roleCsid!");
531             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
532                     ServiceMessages.GET_FAILED + "permroles role "
533                     + ServiceMessages.MISSING_INVALID_CSID + roleCsid).type(
534                     "text/plain").build();
535             throw new WebApplicationException(response);
536         }
537         PermissionRoleRel result = null;
538         try {
539             PermissionRoleSubResource subResource =
540                     new PermissionRoleSubResource(PermissionRoleSubResource.ROLE_PERMROLE_SERVICE);
541             //get relationships for a role
542             result = subResource.getPermissionRoleRel(roleCsid, SubjectType.PERMISSION, permrolecsid);
543         } catch (UnauthorizedException ue) {
544             Response response = Response.status(
545                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.GET_FAILED
546                     + ue.getErrorReason()).type("text/plain").build();
547             throw new WebApplicationException(response);
548         } catch (DocumentNotFoundException dnfe) {
549             if (logger.isDebugEnabled()) {
550                 logger.debug("getRolePermission", dnfe);
551             }
552             Response response = Response.status(Response.Status.NOT_FOUND).entity(
553                     ServiceMessages.GET_FAILED + "permroles role csid=" + roleCsid).type(
554                     "text/plain").build();
555             throw new WebApplicationException(response);
556         } catch (Exception e) {
557             if (logger.isDebugEnabled()) {
558                 logger.debug("getRolePermission", e);
559             }
560             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
561             Response response = Response.status(
562                     Response.Status.INTERNAL_SERVER_ERROR).entity(
563                     ServiceMessages.GET_FAILED
564                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
565             throw new WebApplicationException(response);
566         }
567         if (result == null) {
568             Response response = Response.status(Response.Status.NOT_FOUND).entity(
569                     ServiceMessages.GET_FAILED + "permroles role csid=" + roleCsid
570                     + ": was not found.").type(
571                     "text/plain").build();
572             throw new WebApplicationException(response);
573         }
574         return result;
575     }
576
577     /**
578      * Delete role permission.
579      *
580      * @param roleCsid the role csid
581      * @param input the input
582      * @return the response
583      */
584     public Response deleteRolePermission(String roleCsid, PermissionRole input) {
585
586         if (logger.isDebugEnabled()) {
587             logger.debug("deleteRolePermission with roleCsid=" + roleCsid);
588         }
589
590         if (roleCsid == null || "".equals(roleCsid)) {
591             logger.error("deleteRolePermission: missing roleCsid!");
592             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
593                     ServiceMessages.DELETE_FAILED + "permroles role "
594                     + ServiceMessages.MISSING_INVALID_CSID + roleCsid).type(
595                     "text/plain").build();
596             throw new WebApplicationException(response);
597         }
598         try {
599             PermissionRoleSubResource subResource =
600                     new PermissionRoleSubResource(PermissionRoleSubResource.ROLE_PERMROLE_SERVICE);
601             //delete all relationships for a permission
602             subResource.deletePermissionRole(roleCsid, SubjectType.PERMISSION, input);
603             return Response.status(HttpResponseCodes.SC_OK).build();
604         } catch (UnauthorizedException ue) {
605             Response response = Response.status(
606                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.DELETE_FAILED
607                     + ue.getErrorReason()).type("text/plain").build();
608             throw new WebApplicationException(response);
609         } catch (DocumentNotFoundException dnfe) {
610             if (logger.isDebugEnabled()) {
611                 logger.debug("caught exception in deleteRolePermission", dnfe);
612             }
613             Response response = Response.status(Response.Status.NOT_FOUND).entity(
614                     ServiceMessages.DELETE_FAILED + "role csid=" + roleCsid).type(
615                     "text/plain").build();
616             throw new WebApplicationException(response);
617         } catch (Exception e) {
618             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
619             Response response = Response.status(
620                     Response.Status.INTERNAL_SERVER_ERROR).entity(
621                     ServiceMessages.DELETE_FAILED
622                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
623             throw new WebApplicationException(response);
624         }
625
626     }
627
628     /**
629      * Delete role permission.
630      *
631      * @param roleCsid the role csid
632      * @return the response
633      */
634     @DELETE
635     @Path("{csid}/permroles")
636     public Response deleteRolePermission(
637                 @PathParam("csid") String roleCsid) {
638
639         if (logger.isDebugEnabled()) {
640             logger.debug("deleteRolePermission with roleCsid=" + roleCsid);
641         }
642
643         if (roleCsid == null || "".equals(roleCsid)) {
644             logger.error("deleteRolePermission: missing roleCsid!");
645             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
646                     ServiceMessages.DELETE_FAILED + "permroles role "
647                     + ServiceMessages.MISSING_INVALID_CSID + roleCsid).type(
648                     "text/plain").build();
649             throw new WebApplicationException(response);
650         }
651         try {
652             PermissionRoleSubResource subResource =
653                     new PermissionRoleSubResource(PermissionRoleSubResource.ROLE_PERMROLE_SERVICE);
654             //delete all relationships for a permission
655             subResource.deletePermissionRole(roleCsid, SubjectType.PERMISSION);
656             return Response.status(HttpResponseCodes.SC_OK).build();
657         } catch (UnauthorizedException ue) {
658             Response response = Response.status(
659                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.DELETE_FAILED
660                     + ue.getErrorReason()).type("text/plain").build();
661             throw new WebApplicationException(response);
662         } catch (DocumentNotFoundException dnfe) {
663             if (logger.isDebugEnabled()) {
664                 logger.debug("caught exception in deleteRolePermission", dnfe);
665             }
666             Response response = Response.status(Response.Status.NOT_FOUND).entity(
667                     ServiceMessages.DELETE_FAILED + "role csid=" + roleCsid).type(
668                     "text/plain").build();
669             throw new WebApplicationException(response);
670         } catch (Exception e) {
671             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
672             Response response = Response.status(
673                     Response.Status.INTERNAL_SERVER_ERROR).entity(
674                     ServiceMessages.DELETE_FAILED
675                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
676             throw new WebApplicationException(response);
677         }
678
679     }
680 }