use of eu.bcvsolutions.idm.acc.entity.SysRoleSystem in project CzechIdMng by bcvsolutions.
the class DefaultSysRoleSystemService method delete.
@Override
@Transactional
public void delete(SysRoleSystemDto roleSystem, BasePermission... permission) {
Assert.notNull(roleSystem, "Role system relation is required.");
Assert.notNull(roleSystem.getId(), "Role system relation identifier is required.");
SysRoleSystem roleSystemEntity = this.getEntity(roleSystem.getId());
// Identity-role check.
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setRoleSystemId(roleSystemEntity.getId());
long count = identityRoleService.count(identityRoleFilter);
if (count > 0) {
IdmRoleDto roleDto = DtoUtils.getEmbedded(roleSystem, SysRoleSystem_.role, IdmRoleDto.class, null);
throw new ResultCodeException(AccResultCode.ROLE_SYSTEM_IS_USE_IN_IDENTITY_ROLE, ImmutableMap.of("role", roleDto != null ? roleDto.getBaseCode() : "-", "count", count));
}
//
// delete attributes
SysRoleSystemAttributeFilter filter = new SysRoleSystemAttributeFilter();
filter.setRoleSystemId(roleSystem.getId());
List<SysRoleSystemAttributeDto> attributes = roleSystemAttributeService.find(filter, null).getContent();
// controlled values are created by service.
for (SysRoleSystemAttributeDto attribute : attributes) {
roleSystemAttributeService.delete(attribute);
}
//
// clear identityAccounts - only link on roleSystem
AccIdentityAccountFilter identityAccountFilter = new AccIdentityAccountFilter();
identityAccountFilter.setRoleSystemId(roleSystemEntity.getId());
identityAccountService.find(identityAccountFilter, null).getContent().forEach(identityAccount -> {
identityAccount.setRoleSystem(null);
identityAccountService.save(identityAccount);
});
//
// Cancel requests and request items using that deleting DTO
requestManager.onDeleteRequestable(roleSystem);
super.delete(roleSystem, permission);
}
Aggregations