@Transactional
@Override
public CommandProcessingResult updateRolePermissions(final Long roleId, final JsonCommand command) {
this.context.authenticatedUser();
final Role role = this.roleRepository.findOne(roleId);
if (role == null) { throw new RoleNotFoundException(roleId); }
final Collection<Permission> allPermissions = this.permissionRepository.findAll();
final PermissionsCommand permissionsCommand = this.permissionsFromApiJsonDeserializer.commandFromApiJson(command.json());
final Map<String, Boolean> commandPermissions = permissionsCommand.getPermissions();
final Map<String, Object> changes = new HashMap<>();
final Map<String, Boolean> changedPermissions = new HashMap<>();
for (final String permissionCode : commandPermissions.keySet()) {
final boolean isSelected = commandPermissions.get(permissionCode).booleanValue();
final Permission permission = findPermissionByCode(allPermissions, permissionCode);
final boolean changed = role.updatePermission(permission, isSelected);
if (changed) {
changedPermissions.put(permissionCode, isSelected);
}
}