OrganizationMembershipServiceImpl extends BaseServiceImpl<OrganizationMembership> implements OrganizationMembershipService { @Override public OrganizationMembership changeRole(OrganizationMembership membership, Role role) { BoundStatement stmtChangeRole = stmtChangeRoleInstance.get(); membership.setRole(role); stmtChangeRole.setUUID("role", membership.getRole().getIdAsUUID()); update(membership, stmtChangeRole); Persona persona = personaService.getById(membership.getMember().getIdAsUUID()); Resource resource = resourceService.getById(membership.getOrganization().getIdAsUUID()); resourceService.revokeAllForPersona(resource, persona); resourceService.addRoleToPersona(resource, persona, role); logger.organizationMembershipRoleChanged(membership.getId(), role.getName()); return membership; }  @Override OrganizationMembership create(Organization organization, Persona persona, Role role); @Override List<OrganizationMembership> getMembershipsForPersona(Persona persona); @Override List<OrganizationMembership> getMembershipsForOrganization(Organization organization); @Override List<OrganizationMembership> getPersonaMembershipsForOrganization(Persona persona,
                                                                                       Organization organization); @Override OrganizationMembership getMembershipById(String id); @Override OrganizationMembership getById(UUID id); @Override OrganizationMembership changeRole(OrganizationMembership membership, Role role); @Override void remove(OrganizationMembership organizationMembership); @Override void remove(UUID id);  }
@Test public void changeRole() { HawkularUser jdoe = userService.getOrCreateById(UUID.randomUUID().toString()); HawkularUser jsmith = userService.getOrCreateById(UUID.randomUUID().toString()); Organization acme = organizationService.createOrganization(UUID.randomUUID().toString(), "", jdoe); Invitation invitation = invitationService.create("", jdoe, acme, monitor); invitationService.accept(invitation, jsmith); OrganizationMembership jsmithAtAcme = membershipService.getMembershipsForPersona(jsmith).get(0); membershipService.changeRole(jsmithAtAcme, superUser); List<OrganizationMembership> memberships = membershipService.getPersonaMembershipsForOrganization(jsmith, acme); assertEquals("jsmith should be only super user at acme at this point", 1, memberships.size()); assertEquals("jsmith should be only super user at acme at this point", "SuperUser", memberships.get(0).getRole().getName()); membershipService.changeRole(jsmithAtAcme, monitor); memberships = membershipService.getPersonaMembershipsForOrganization(jsmith, acme); assertEquals("jsmith should be only monitor at acme at this point", 1, memberships.size()); assertEquals("jsmith should be only monitor at acme at this point", "Monitor", memberships.get(0).getRole().getName()); }