2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 package org.collectionspace.services.authorization;
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;
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.DocumentFilter;
51 import org.collectionspace.services.common.document.DocumentNotFoundException;
52 import org.collectionspace.services.common.document.DocumentHandler;
53 import org.collectionspace.services.common.security.UnauthorizedException;
54 import org.collectionspace.services.common.storage.StorageClient;
55 import org.collectionspace.services.common.storage.jpa.JpaStorageClientImpl;
56 import org.jboss.resteasy.util.HttpResponseCodes;
57 import org.slf4j.Logger;
58 import org.slf4j.LoggerFactory;
60 // TODO: Auto-generated Javadoc
62 * The Class RoleResource.
64 @Path("/authorization/roles")
65 @Consumes("application/xml")
66 @Produces("application/xml")
67 public class RoleResource
68 extends AbstractCollectionSpaceResourceImpl {
70 /** The service name. */
71 final private String serviceName = "authorization/roles";
73 final Logger logger = LoggerFactory.getLogger(RoleResource.class);
74 /** The storage client. */
75 final StorageClient storageClient = new JpaStorageClientImpl();
78 * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
81 protected String getVersionString() {
82 /** The last change revision. */
83 final String lastChangeRevision = "$LastChangedRevision: 1165 $";
84 return lastChangeRevision;
88 * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
91 public String getServiceName() {
96 * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
99 public Class<RoleResource> getCommonPartClass() {
100 return RoleResource.class;
104 * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceContextFactory()
107 public ServiceContextFactory getServiceContextFactory() {
108 return RemoteServiceContextFactory.get();
111 // private <T> ServiceContext createServiceContext(T obj) throws Exception {
112 // ServiceContext ctx = new RemoteServiceContextImpl<T, T>(getServiceName());
113 // ctx.setInput(obj);
114 // ctx.setDocumentType(Role.class.getPackage().getName()); //persistence unit
115 // ctx.setProperty("entity-name", Role.class.getName());
120 * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getStorageClient(org.collectionspace.services.common.context.ServiceContext)
123 public StorageClient getStorageClient(ServiceContext ctx) {
124 //FIXME use ctx to identify storage client
125 return storageClient;
129 // public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
130 // DocumentHandler docHandler = ctx.getDocumentHandler();
131 // docHandler.setCommonPart(ctx.getInput());
132 // return docHandler;
137 * @param input the input
139 * @return the response
142 public Response createRole(Role input) {
144 ServiceContext ctx = createServiceContext(input, Role.class);
145 DocumentHandler handler = createDocumentHandler(ctx);
146 String csid = getStorageClient(ctx).create(ctx, handler);
147 UriBuilder path = UriBuilder.fromResource(RoleResource.class);
148 path.path("" + csid);
149 Response response = Response.created(path.build()).build();
151 } catch (BadRequestException bre) {
152 Response response = Response.status(
153 Response.Status.BAD_REQUEST).entity(ServiceMessages.POST_FAILED
154 + bre.getErrorReason()).type("text/plain").build();
155 throw new WebApplicationException(response);
156 } catch (UnauthorizedException ue) {
157 Response response = Response.status(
158 Response.Status.UNAUTHORIZED).entity(ServiceMessages.POST_FAILED
159 + ue.getErrorReason()).type("text/plain").build();
160 throw new WebApplicationException(response);
161 } catch (Exception e) {
162 if (logger.isDebugEnabled()) {
163 logger.debug("Caught exception in createRole", e);
165 logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
166 Response response = Response.status(
167 Response.Status.INTERNAL_SERVER_ERROR).entity(ServiceMessages.POST_FAILED
168 + e.getMessage()).type("text/plain").build();
169 throw new WebApplicationException(e, response);
176 * @param csid the csid
183 @PathParam("csid") String csid) {
184 if (logger.isDebugEnabled()) {
185 logger.debug("getRole with csid=" + csid);
187 if (csid == null || "".equals(csid)) {
188 logger.error("getRole: missing csid!");
189 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
190 ServiceMessages.GET_FAILED + "role csid=").type(
191 "text/plain").build();
192 throw new WebApplicationException(response);
196 ServiceContext ctx = createServiceContext((Role) null, Role.class);
197 DocumentHandler handler = createDocumentHandler(ctx);
198 getStorageClient(ctx).get(ctx, csid, handler);
199 result = (Role) ctx.getOutput();
200 } catch (UnauthorizedException ue) {
201 Response response = Response.status(
202 Response.Status.UNAUTHORIZED).entity(ServiceMessages.GET_FAILED
203 + ue.getErrorReason()).type("text/plain").build();
204 throw new WebApplicationException(response);
205 } catch (DocumentNotFoundException dnfe) {
206 if (logger.isDebugEnabled()) {
207 logger.debug("getRole", dnfe);
209 Response response = Response.status(Response.Status.NOT_FOUND).entity(
210 ServiceMessages.GET_FAILED + "role csid=" + csid).type(
211 "text/plain").build();
212 throw new WebApplicationException(response);
213 } catch (Exception e) {
214 if (logger.isDebugEnabled()) {
215 logger.debug("getRole", e);
217 logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
218 Response response = Response.status(
219 Response.Status.INTERNAL_SERVER_ERROR).entity(ServiceMessages.GET_FAILED
220 + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
221 throw new WebApplicationException(response);
224 if (result == null) {
225 Response response = Response.status(Response.Status.NOT_FOUND).entity(
226 ServiceMessages.GET_FAILED + "role csid=" + csid + ": was not found.").type(
227 "text/plain").build();
228 throw new WebApplicationException(response);
234 * Gets the role list.
238 * @return the role list
241 @Produces("application/xml")
242 public RolesList getRoleList(
243 @Context UriInfo ui) {
244 RolesList roleList = new RolesList();
246 ServiceContext ctx = createServiceContext((Role) null, Role.class);
247 DocumentHandler handler = createDocumentHandler(ctx);
248 MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
249 DocumentFilter myFilter = handler.createDocumentFilter();
250 myFilter.setPagination(queryParams);
251 myFilter.setQueryParams(queryParams);
252 handler.setDocumentFilter(myFilter);
253 getStorageClient(ctx).getFiltered(ctx, handler);
254 roleList = (RolesList) handler.getCommonPartList();
255 } catch (UnauthorizedException ue) {
256 Response response = Response.status(
257 Response.Status.UNAUTHORIZED).entity(ServiceMessages.LIST_FAILED
258 + ue.getErrorReason()).type("text/plain").build();
259 throw new WebApplicationException(response);
261 } catch (Exception e) {
262 if (logger.isDebugEnabled()) {
263 logger.debug("Caught exception in getRoleList", e);
265 logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
266 Response response = Response.status(
267 Response.Status.INTERNAL_SERVER_ERROR).entity(ServiceMessages.LIST_FAILED
268 + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
269 throw new WebApplicationException(response);
277 * @param csid the csid
278 * @param theUpdate the the update
284 public Role updateRole(
285 @PathParam("csid") String csid,
287 if (logger.isDebugEnabled()) {
288 logger.debug("updateRole with csid=" + csid);
290 if (csid == null || "".equals(csid)) {
291 logger.error("updateRole: missing csid!");
292 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
293 ServiceMessages.PUT_FAILED + "role "
294 + ServiceMessages.MISSING_INVALID_CSID + csid).type(
295 "text/plain").build();
296 throw new WebApplicationException(response);
300 ServiceContext ctx = createServiceContext(theUpdate, Role.class);
301 DocumentHandler handler = createDocumentHandler(ctx);
302 getStorageClient(ctx).update(ctx, csid, handler);
303 result = (Role) ctx.getOutput();
304 } catch (BadRequestException bre) {
305 Response response = Response.status(
306 Response.Status.BAD_REQUEST).entity(ServiceMessages.PUT_FAILED
307 + bre.getErrorReason()).type("text/plain").build();
308 throw new WebApplicationException(response);
309 } catch (UnauthorizedException ue) {
310 Response response = Response.status(
311 Response.Status.UNAUTHORIZED).entity(ServiceMessages.PUT_FAILED
312 + ue.getErrorReason()).type("text/plain").build();
313 throw new WebApplicationException(response);
314 } catch (DocumentNotFoundException dnfe) {
315 if (logger.isDebugEnabled()) {
316 logger.debug("caugth exception in updateRole", dnfe);
318 Response response = Response.status(Response.Status.NOT_FOUND).entity(
319 ServiceMessages.PUT_FAILED + "role csid=" + csid).type(
320 "text/plain").build();
321 throw new WebApplicationException(response);
322 } catch (Exception e) {
323 logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
324 Response response = Response.status(
325 Response.Status.INTERNAL_SERVER_ERROR).entity(
326 ServiceMessages.PUT_FAILED
327 + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
328 throw new WebApplicationException(response);
336 * @param csid the csid
338 * @return the response
342 public Response deleteRole(@PathParam("csid") String csid) {
344 if (logger.isDebugEnabled()) {
345 logger.debug("deleteRole with csid=" + csid);
347 if (csid == null || "".equals(csid)) {
348 logger.error("deleteRole: missing csid!");
349 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
350 ServiceMessages.DELETE_FAILED + "role csid=" + csid).type(
351 "text/plain").build();
352 throw new WebApplicationException(response);
355 //FIXME ideally the following three operations should be in the same tx CSPACE-658
356 //delete all relationships for this permission
357 PermissionRoleSubResource permRoleResource =
358 new PermissionRoleSubResource(PermissionRoleSubResource.ROLE_PERMROLE_SERVICE);
359 permRoleResource.deletePermissionRole(csid, SubjectType.PERMISSION);
360 //delete all the account/role relationships associate with this role
361 AccountRoleSubResource accountRoleResource =
362 new AccountRoleSubResource(AccountRoleSubResource.ROLE_ACCOUNTROLE_SERVICE);
363 accountRoleResource.deleteAccountRole(csid, SubjectType.ACCOUNT);
364 //finally, delete the role itself
365 ServiceContext<Role, Role> ctx = createServiceContext((Role) null, Role.class);
366 ((JpaStorageClientImpl) getStorageClient(ctx)).deleteWhere(ctx, csid);
367 return Response.status(HttpResponseCodes.SC_OK).build();
368 } catch (UnauthorizedException ue) {
369 Response response = Response.status(
370 Response.Status.UNAUTHORIZED).entity(ServiceMessages.DELETE_FAILED + ue.getErrorReason()).type("text/plain").build();
371 throw new WebApplicationException(response);
373 } catch (DocumentNotFoundException dnfe) {
374 if (logger.isDebugEnabled()) {
375 logger.debug("caught exception in deleteRole", dnfe);
377 Response response = Response.status(Response.Status.NOT_FOUND).entity(
378 ServiceMessages.DELETE_FAILED + "role csid=" + csid).type(
379 "text/plain").build();
380 throw new WebApplicationException(response);
381 } catch (Exception e) {
382 logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
383 Response response = Response.status(
384 Response.Status.INTERNAL_SERVER_ERROR).entity(
385 ServiceMessages.DELETE_FAILED + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
386 throw new WebApplicationException(response);
392 * Creates the role permission.
394 * @param method the method
395 * @param roleCsid the role csid
396 * @param input the input
397 * @return the response
400 @Path("{csid}/permroles")
401 public Response createRolePermission(@QueryParam("_method") String method, @PathParam("csid") String roleCsid,
402 PermissionRole input) {
403 if (method != null) {
404 if ("delete".equalsIgnoreCase(method)) {
405 return deleteRolePermission(roleCsid, input);
408 if (logger.isDebugEnabled()) {
409 logger.debug("createRolePermission with roleCsid=" + roleCsid);
411 if (roleCsid == null || "".equals(roleCsid)) {
412 logger.error("createRolePermission: missing roleCsid!");
413 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
414 ServiceMessages.POST_FAILED + "permroles role "
415 + ServiceMessages.MISSING_INVALID_CSID + roleCsid).type(
416 "text/plain").build();
417 throw new WebApplicationException(response);
420 PermissionRoleSubResource subResource =
421 new PermissionRoleSubResource(PermissionRoleSubResource.ROLE_PERMROLE_SERVICE);
422 String permrolecsid = subResource.createPermissionRole(input, SubjectType.PERMISSION);
423 UriBuilder path = UriBuilder.fromResource(RoleResource.class);
424 path.path(roleCsid + "/permroles/" + permrolecsid);
425 Response response = Response.created(path.build()).build();
427 } catch (BadRequestException bre) {
428 Response response = Response.status(
429 Response.Status.BAD_REQUEST).entity("Create failed reason "
430 + bre.getErrorReason()).type("text/plain").build();
431 throw new WebApplicationException(response);
432 } catch (UnauthorizedException ue) {
433 Response response = Response.status(
434 Response.Status.UNAUTHORIZED).entity("Create failed reason "
435 + ue.getErrorReason()).type("text/plain").build();
436 throw new WebApplicationException(response);
437 } catch (Exception e) {
438 if (logger.isDebugEnabled()) {
439 logger.debug("Caught exception in createRolePermission", e);
441 logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
442 Response response = Response.status(
443 Response.Status.INTERNAL_SERVER_ERROR).entity(
444 ServiceMessages.POST_FAILED
445 + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
446 throw new WebApplicationException(response);
451 * Gets the role permission.
453 * @param roleCsid the role csid
454 * @param permrolecsid the permrolecsid
455 * @return the role permission
458 @Path("{csid}/permroles")
459 public PermissionRole getRolePermission(
460 @PathParam("csid") String roleCsid) {
461 if (logger.isDebugEnabled()) {
462 logger.debug("getRolePermission with roleCsid=" + roleCsid);
464 if (roleCsid == null || "".equals(roleCsid)) {
465 logger.error("getRolePermission: missing roleCsid!");
466 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
467 ServiceMessages.GET_FAILED + "permroles role "
468 + ServiceMessages.MISSING_INVALID_CSID + roleCsid).type(
469 "text/plain").build();
470 throw new WebApplicationException(response);
472 PermissionRole result = null;
474 PermissionRoleSubResource subResource =
475 new PermissionRoleSubResource(PermissionRoleSubResource.ROLE_PERMROLE_SERVICE);
476 //get relationships for a role
477 result = subResource.getPermissionRole(roleCsid, SubjectType.PERMISSION);
478 } catch (UnauthorizedException ue) {
479 Response response = Response.status(
480 Response.Status.UNAUTHORIZED).entity(ServiceMessages.GET_FAILED
481 + ue.getErrorReason()).type("text/plain").build();
482 throw new WebApplicationException(response);
483 } catch (DocumentNotFoundException dnfe) {
484 if (logger.isDebugEnabled()) {
485 logger.debug("getRolePermission", dnfe);
487 Response response = Response.status(Response.Status.NOT_FOUND).entity(
488 ServiceMessages.GET_FAILED + "permroles role csid=" + roleCsid).type(
489 "text/plain").build();
490 throw new WebApplicationException(response);
491 } catch (Exception e) {
492 if (logger.isDebugEnabled()) {
493 logger.debug("getRolePermission", e);
495 logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
496 Response response = Response.status(
497 Response.Status.INTERNAL_SERVER_ERROR).entity(
498 ServiceMessages.GET_FAILED
499 + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
500 throw new WebApplicationException(response);
502 if (result == null) {
503 Response response = Response.status(Response.Status.NOT_FOUND).entity(
504 ServiceMessages.GET_FAILED + "permroles role csid=" + roleCsid
505 + ": was not found.").type(
506 "text/plain").build();
507 throw new WebApplicationException(response);
513 @Path("{csid}/permroles/{id}")
514 public PermissionRoleRel getRolePermission(
515 @PathParam("csid") String roleCsid,
516 @PathParam("id") String permrolecsid) {
517 if (logger.isDebugEnabled()) {
518 logger.debug("getRolePermission with roleCsid=" + roleCsid);
520 if (roleCsid == null || "".equals(roleCsid)) {
521 logger.error("getRolePermission: missing roleCsid!");
522 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
523 ServiceMessages.GET_FAILED + "permroles role "
524 + ServiceMessages.MISSING_INVALID_CSID + roleCsid).type(
525 "text/plain").build();
526 throw new WebApplicationException(response);
528 PermissionRoleRel result = null;
530 PermissionRoleSubResource subResource =
531 new PermissionRoleSubResource(PermissionRoleSubResource.ROLE_PERMROLE_SERVICE);
532 //get relationships for a role
533 result = subResource.getPermissionRoleRel(roleCsid, SubjectType.PERMISSION, permrolecsid);
534 } catch (UnauthorizedException ue) {
535 Response response = Response.status(
536 Response.Status.UNAUTHORIZED).entity(ServiceMessages.GET_FAILED
537 + ue.getErrorReason()).type("text/plain").build();
538 throw new WebApplicationException(response);
539 } catch (DocumentNotFoundException dnfe) {
540 if (logger.isDebugEnabled()) {
541 logger.debug("getRolePermission", dnfe);
543 Response response = Response.status(Response.Status.NOT_FOUND).entity(
544 ServiceMessages.GET_FAILED + "permroles role csid=" + roleCsid).type(
545 "text/plain").build();
546 throw new WebApplicationException(response);
547 } catch (Exception e) {
548 if (logger.isDebugEnabled()) {
549 logger.debug("getRolePermission", e);
551 logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
552 Response response = Response.status(
553 Response.Status.INTERNAL_SERVER_ERROR).entity(
554 ServiceMessages.GET_FAILED
555 + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
556 throw new WebApplicationException(response);
558 if (result == null) {
559 Response response = Response.status(Response.Status.NOT_FOUND).entity(
560 ServiceMessages.GET_FAILED + "permroles role csid=" + roleCsid
561 + ": was not found.").type(
562 "text/plain").build();
563 throw new WebApplicationException(response);
569 * Delete role permission.
571 * @param roleCsid the role csid
572 * @param input the input
573 * @return the response
575 public Response deleteRolePermission(String roleCsid, PermissionRole input) {
577 if (logger.isDebugEnabled()) {
578 logger.debug("deleteRolePermission with roleCsid=" + roleCsid);
581 if (roleCsid == null || "".equals(roleCsid)) {
582 logger.error("deleteRolePermission: missing roleCsid!");
583 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
584 ServiceMessages.DELETE_FAILED + "permroles role "
585 + ServiceMessages.MISSING_INVALID_CSID + roleCsid).type(
586 "text/plain").build();
587 throw new WebApplicationException(response);
590 PermissionRoleSubResource subResource =
591 new PermissionRoleSubResource(PermissionRoleSubResource.ROLE_PERMROLE_SERVICE);
592 //delete all relationships for a permission
593 subResource.deletePermissionRole(roleCsid, SubjectType.PERMISSION, input);
594 return Response.status(HttpResponseCodes.SC_OK).build();
595 } catch (UnauthorizedException ue) {
596 Response response = Response.status(
597 Response.Status.UNAUTHORIZED).entity(ServiceMessages.DELETE_FAILED
598 + ue.getErrorReason()).type("text/plain").build();
599 throw new WebApplicationException(response);
600 } catch (DocumentNotFoundException dnfe) {
601 if (logger.isDebugEnabled()) {
602 logger.debug("caught exception in deleteRolePermission", dnfe);
604 Response response = Response.status(Response.Status.NOT_FOUND).entity(
605 ServiceMessages.DELETE_FAILED + "role csid=" + roleCsid).type(
606 "text/plain").build();
607 throw new WebApplicationException(response);
608 } catch (Exception e) {
609 logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
610 Response response = Response.status(
611 Response.Status.INTERNAL_SERVER_ERROR).entity(
612 ServiceMessages.DELETE_FAILED
613 + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
614 throw new WebApplicationException(response);
620 * Delete role permission.
622 * @param roleCsid the role csid
623 * @return the response
626 @Path("{csid}/permroles")
627 public Response deleteRolePermission(
628 @PathParam("csid") String roleCsid) {
630 if (logger.isDebugEnabled()) {
631 logger.debug("deleteRolePermission with roleCsid=" + roleCsid);
634 if (roleCsid == null || "".equals(roleCsid)) {
635 logger.error("deleteRolePermission: missing roleCsid!");
636 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
637 ServiceMessages.DELETE_FAILED + "permroles role "
638 + ServiceMessages.MISSING_INVALID_CSID + roleCsid).type(
639 "text/plain").build();
640 throw new WebApplicationException(response);
643 PermissionRoleSubResource subResource =
644 new PermissionRoleSubResource(PermissionRoleSubResource.ROLE_PERMROLE_SERVICE);
645 //delete all relationships for a permission
646 subResource.deletePermissionRole(roleCsid, SubjectType.PERMISSION);
647 return Response.status(HttpResponseCodes.SC_OK).build();
648 } catch (UnauthorizedException ue) {
649 Response response = Response.status(
650 Response.Status.UNAUTHORIZED).entity(ServiceMessages.DELETE_FAILED
651 + ue.getErrorReason()).type("text/plain").build();
652 throw new WebApplicationException(response);
653 } catch (DocumentNotFoundException dnfe) {
654 if (logger.isDebugEnabled()) {
655 logger.debug("caught exception in deleteRolePermission", dnfe);
657 Response response = Response.status(Response.Status.NOT_FOUND).entity(
658 ServiceMessages.DELETE_FAILED + "role csid=" + roleCsid).type(
659 "text/plain").build();
660 throw new WebApplicationException(response);
661 } catch (Exception e) {
662 logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
663 Response response = Response.status(
664 Response.Status.INTERNAL_SERVER_ERROR).entity(
665 ServiceMessages.DELETE_FAILED
666 + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
667 throw new WebApplicationException(response);