@Transactional
  @Override
  public Long updateRole(RoleCommand command) {

    AppUser currentUser = context.authenticatedUser();

    RoleCommandValidator validator = new RoleCommandValidator(command);
    validator.validateForUpdate();

    List<Permission> selectedPermissions =
        assembleListOfSelectedPermissions(command.getPermissions());

    Role role =
        this.roleRepository.findOne(rolesThatMatch(currentUser.getOrganisation(), command.getId()));
    if (role == null) {
      throw new RoleNotFoundException(command.getId());
    }
    role.update(command.getName(), command.getDescription(), selectedPermissions);

    this.roleRepository.save(role);

    return role.getId();
  }
  @Transactional
  @Override
  public Long createRole(final RoleCommand command) {

    AppUser currentUser = context.authenticatedUser();

    RoleCommandValidator validator = new RoleCommandValidator(command);
    validator.validateForCreate();

    List<Permission> selectedPermissions =
        assembleListOfSelectedPermissions(command.getPermissions());

    Role entity =
        new Role(
            currentUser.getOrganisation(),
            command.getName(),
            command.getDescription(),
            selectedPermissions);

    this.roleRepository.save(entity);

    return entity.getId();
  }