Search in sources :

Example 1 with SysRoleSystem

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);
}
Also used : SysRoleSystemAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemAttributeFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysRoleSystem(eu.bcvsolutions.idm.acc.entity.SysRoleSystem) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SysRoleSystemAttributeDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto)1 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)1 SysRoleSystemAttributeFilter (eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemAttributeFilter)1 SysRoleSystem (eu.bcvsolutions.idm.acc.entity.SysRoleSystem)1 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)1 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 Transactional (org.springframework.transaction.annotation.Transactional)1