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