use of eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysRoleSystemService method save.
@Override
public SysRoleSystemDto save(SysRoleSystemDto dto, BasePermission... permission) {
Assert.notNull(dto, "RoleSystem cannot be null!");
Assert.notNull(dto.getRole(), "Role cannot be null!");
Assert.notNull(dto.getSystem(), "System cannot be null!");
SysRoleSystemFilter filter = new SysRoleSystemFilter();
filter.setRoleId(dto.getRole());
filter.setSystemId(dto.getSystem());
List<SysRoleSystemDto> roleSystems = this.find(filter, null).getContent();
boolean isDuplicated = roleSystems.stream().filter(roleSystem -> {
return !roleSystem.getId().equals(dto.getId());
}).findFirst().isPresent();
if (isDuplicated) {
IdmRoleDto roleDto = roleService.get(dto.getRole());
SysSystemDto systemDto = DtoUtils.getEmbedded(dto, SysRoleSystem_.system, SysSystemDto.class);
throw new ResultCodeException(AccResultCode.ROLE_SYSTEM_ALREADY_EXISTS, ImmutableMap.of("role", roleDto.getName(), "system", systemDto.getName()));
}
return super.save(dto, permission);
}
Aggregations