use of io.gravitee.rest.api.service.exceptions.SinglePrimaryOwnerException in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMembersResource method createApplicationMember.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_MEMBER, acls = RolePermissionAction.CREATE) })
public Response createApplicationMember(@PathParam("applicationId") String applicationId, @Valid @NotNull(message = "Input must not be null.") MemberInput memberInput) {
// Does application exist ?
applicationService.findById(applicationId);
// There can be only one
if (SystemRole.PRIMARY_OWNER.name().equals(memberInput.getRole())) {
throw new SinglePrimaryOwnerException(RoleScope.APPLICATION);
}
MemberEntity membership = membershipService.addRoleToMemberOnReference(new MembershipService.MembershipReference(MembershipReferenceType.APPLICATION, applicationId), new MembershipService.MembershipMember(memberInput.getUser(), memberInput.getReference(), MembershipMemberType.USER), new MembershipService.MembershipRole(RoleScope.APPLICATION, memberInput.getRole()));
return Response.created(this.getLocationHeader(membership.getId())).entity(memberMapper.convert(membership, uriInfo)).build();
}
use of io.gravitee.rest.api.service.exceptions.SinglePrimaryOwnerException in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMembersResource method updateApplicationMemberByApplicationIdAndMemberId.
@PUT
@Path("/{memberId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_MEMBER, acls = RolePermissionAction.UPDATE) })
public Response updateApplicationMemberByApplicationIdAndMemberId(@PathParam("applicationId") String applicationId, @PathParam("memberId") String memberId, @Valid @NotNull(message = "Input must not be null.") MemberInput memberInput) {
// Does application exist ?
applicationService.findById(applicationId);
// Does user exist ?
userService.findById(memberId);
if (memberInput.getUser() != null && !memberId.equals(memberInput.getUser())) {
throw new BadRequestException("'memberInput.user' should the same as 'memberId'");
}
// There can be only one
if (SystemRole.PRIMARY_OWNER.name().equals(memberInput.getRole())) {
throw new SinglePrimaryOwnerException(RoleScope.APPLICATION);
}
MemberEntity membership = membershipService.updateRoleToMemberOnReference(new MembershipService.MembershipReference(MembershipReferenceType.APPLICATION, applicationId), new MembershipService.MembershipMember(memberId, memberInput.getReference(), MembershipMemberType.USER), new MembershipService.MembershipRole(RoleScope.APPLICATION, memberInput.getRole()));
return Response.ok(memberMapper.convert(membership, uriInfo)).build();
}
Aggregations