this.context.authenticatedUser();
this.fromApiJsonDeserializer.validateForUpdateRole(command);
final Group group = this.groupRepository.findOneWithNotFoundDetection(command.getGroupId());
final GroupRole groupRole = this.groupRoleRepository.findOneWithNotFoundDetection(command.entityId());
final Map<String, Object> actualChanges = groupRole.update(command);
if (actualChanges.containsKey(GroupingTypesApiConstants.roleParamName)) {
final Long newValue = command.longValueOfParameterNamed(GroupingTypesApiConstants.roleParamName);
CodeValue role = null;
if (newValue != null) {
role = this.codeValueRepository.findOneWithNotFoundDetection(newValue);
}
groupRole.updateRole(role);
}
if (actualChanges.containsKey(GroupingTypesApiConstants.clientIdParamName)) {
final Long newValue = command.longValueOfParameterNamed(GroupingTypesApiConstants.clientIdParamName);
Client client = null;
if (newValue != null) {
client = this.clientRepository.findOneWithNotFoundDetection(newValue);
if (!group.hasClientAsMember(client)) { throw new ClientNotInGroupException(newValue, command.getGroupId()); }
}
groupRole.updateClient(client);
}
this.groupRoleRepository.saveAndFlush(groupRole);
return new CommandProcessingResultBuilder().with(actualChanges).withGroupId(group.getId()).withEntityId(groupRole.getId())
.build();
} catch (final DataIntegrityViolationException dve) {
handleGroupDataIntegrityIssues(command, dve);
return CommandProcessingResult.empty();
}