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.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;
61 // TODO: Auto-generated Javadoc
63 * The Class RoleResource.
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 {
71 /** The service name. */
72 final private String serviceName = "authorization/roles";
74 final Logger logger = LoggerFactory.getLogger(RoleResource.class);
75 /** The storage client. */
76 final StorageClient storageClient = new JpaStorageClientImpl();
79 * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
82 protected String getVersionString() {
83 /** The last change revision. */
84 final String lastChangeRevision = "$LastChangedRevision: 1165 $";
85 return lastChangeRevision;
89 * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
92 public String getServiceName() {
97 * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
100 public Class<RoleResource> getCommonPartClass() {
101 return RoleResource.class;
105 * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceContextFactory()
108 public ServiceContextFactory getServiceContextFactory() {
109 return RemoteServiceContextFactory.get();
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());
121 * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getStorageClient(org.collectionspace.services.common.context.ServiceContext)
124 public StorageClient getStorageClient(ServiceContext ctx) {
125 //FIXME use ctx to identify storage client
126 return storageClient;
130 // public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
131 // DocumentHandler docHandler = ctx.getDocumentHandler();
132 // docHandler.setCommonPart(ctx.getInput());
133 // return docHandler;
138 * @param input the input
140 * @return the response
143 public Response createRole(Role input) {
144 Response response = null;
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);
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);
185 * @param csid the csid
192 @PathParam("csid") String csid) {
193 if (logger.isDebugEnabled()) {
194 logger.debug("getRole with csid=" + csid);
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);
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);
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);
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);
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);
243 * Gets the role list.
247 * @return the role list
250 @Produces("application/xml")
251 public RolesList getRoleList(
252 @Context UriInfo ui) {
253 RolesList roleList = new RolesList();
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);
270 } catch (Exception e) {
271 if (logger.isDebugEnabled()) {
272 logger.debug("Caught exception in getRoleList", e);
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);
286 * @param csid the csid
287 * @param theUpdate the the update
293 public Role updateRole(
294 @PathParam("csid") String csid,
296 if (logger.isDebugEnabled()) {
297 logger.debug("updateRole with csid=" + csid);
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);
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);
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);
345 * @param csid the csid
347 * @return the response
351 public Response deleteRole(@PathParam("csid") String csid) {
353 if (logger.isDebugEnabled()) {
354 logger.debug("deleteRole with csid=" + csid);
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);
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);
382 } catch (DocumentNotFoundException dnfe) {
383 if (logger.isDebugEnabled()) {
384 logger.debug("caught exception in deleteRole", dnfe);
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);
401 * Creates the role permission.
403 * @param method the method
404 * @param roleCsid the role csid
405 * @param input the input
406 * @return the response
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);
417 if (logger.isDebugEnabled()) {
418 logger.debug("createRolePermission with roleCsid=" + roleCsid);
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);
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();
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);
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);
460 * Gets the role permission.
462 * @param roleCsid the role csid
463 * @param permrolecsid the permrolecsid
464 * @return the role permission
467 @Path("{csid}/permroles")
468 public PermissionRole getRolePermission(
469 @PathParam("csid") String roleCsid) {
470 if (logger.isDebugEnabled()) {
471 logger.debug("getRolePermission with roleCsid=" + roleCsid);
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);
481 PermissionRole result = null;
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);
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);
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);
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);
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);
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);
537 PermissionRoleRel result = null;
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);
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);
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);
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);
578 * Delete role permission.
580 * @param roleCsid the role csid
581 * @param input the input
582 * @return the response
584 public Response deleteRolePermission(String roleCsid, PermissionRole input) {
586 if (logger.isDebugEnabled()) {
587 logger.debug("deleteRolePermission with roleCsid=" + roleCsid);
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);
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);
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);
629 * Delete role permission.
631 * @param roleCsid the role csid
632 * @return the response
635 @Path("{csid}/permroles")
636 public Response deleteRolePermission(
637 @PathParam("csid") String roleCsid) {
638 if (logger.isDebugEnabled()) {
639 logger.debug("deleteRolePermission with roleCsid=" + roleCsid);
642 if (roleCsid == null || "".equals(roleCsid)) {
643 logger.error("deleteRolePermission: missing roleCsid!");
644 Response response = Response.status(Response.Status.BAD_REQUEST).entity(
645 ServiceMessages.DELETE_FAILED + "permroles role "
646 + ServiceMessages.MISSING_INVALID_CSID + roleCsid).type(
647 "text/plain").build();
648 throw new WebApplicationException(response);
651 PermissionRoleSubResource subResource =
652 new PermissionRoleSubResource(PermissionRoleSubResource.ROLE_PERMROLE_SERVICE);
653 //delete all relationships for a permission
654 subResource.deletePermissionRole(roleCsid, SubjectType.PERMISSION);
655 return Response.status(HttpResponseCodes.SC_OK).build();
656 } catch (UnauthorizedException ue) {
657 Response response = Response.status(
658 Response.Status.UNAUTHORIZED).entity(ServiceMessages.DELETE_FAILED
659 + ue.getErrorReason()).type("text/plain").build();
660 throw new WebApplicationException(response);
661 } catch (DocumentNotFoundException dnfe) {
662 if (logger.isDebugEnabled()) {
663 logger.debug("caught exception in deleteRolePermission", dnfe);
665 Response response = Response.status(Response.Status.NOT_FOUND).entity(
666 ServiceMessages.DELETE_FAILED + "role csid=" + roleCsid).type(
667 "text/plain").build();
668 throw new WebApplicationException(response);
669 } catch (Exception e) {
670 logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
671 Response response = Response.status(
672 Response.Status.INTERNAL_SERVER_ERROR).entity(
673 ServiceMessages.DELETE_FAILED
674 + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
675 throw new WebApplicationException(response);