use of io.gravitee.management.service.exceptions.SinglePrimaryOwnerException in project gravitee-management-rest-api by gravitee-io.
the class ApiMembersResource method addOrUpdateApiMember.
@POST
@ApiOperation(value = "Add or update an API member", notes = "User must have the MANAGE_MEMBERS permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Member has been added or updated successfully"), @ApiResponse(code = 400, message = "Membership parameter is not valid"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_MEMBER, acls = RolePermissionAction.CREATE), @Permission(value = RolePermission.API_MEMBER, acls = RolePermissionAction.UPDATE) })
public Response addOrUpdateApiMember(@PathParam("api") String api, @Valid @NotNull ApiMembership apiMembership) {
if (PRIMARY_OWNER.name().equals(apiMembership.getRole())) {
throw new SinglePrimaryOwnerException(RoleScope.API);
}
apiService.findById(api);
MemberEntity membership = membershipService.addOrUpdateMember(new MembershipService.MembershipReference(MembershipReferenceType.API, api), new MembershipService.MembershipUser(apiMembership.getId(), apiMembership.getReference()), new MembershipService.MembershipRole(RoleScope.API, apiMembership.getRole()));
return Response.created(URI.create("/apis/" + api + "/members/" + membership.getId())).build();
}
use of io.gravitee.management.service.exceptions.SinglePrimaryOwnerException in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMembersResource method addOrUpdateApplicationMember.
@POST
@ApiOperation(value = "Add or update an application member", notes = "User must have the MANAGE_MEMBERS permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Member has been added or updated successfully"), @ApiResponse(code = 400, message = "Membership parameter is not valid"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_MEMBER, acls = RolePermissionAction.CREATE), @Permission(value = RolePermission.APPLICATION_MEMBER, acls = RolePermissionAction.UPDATE) })
public Response addOrUpdateApplicationMember(@PathParam("application") String application, @Valid @NotNull ApplicationMembership applicationMembership) {
if (PRIMARY_OWNER.name().equals(applicationMembership.getRole())) {
throw new SinglePrimaryOwnerException(RoleScope.APPLICATION);
}
applicationService.findById(application);
MemberEntity membership = membershipService.addOrUpdateMember(new MembershipService.MembershipReference(MembershipReferenceType.APPLICATION, application), new MembershipService.MembershipUser(applicationMembership.getId(), applicationMembership.getReference()), new MembershipService.MembershipRole(RoleScope.APPLICATION, applicationMembership.getRole()));
return Response.created(URI.create("/applications/" + application + "/members/" + membership.getId())).build();
}
Aggregations