Search in sources :

Example 11 with SysRoleSystemFilter

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);
}
Also used : SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Aggregations

SysRoleSystemFilter (eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 SysRoleSystemDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto)8 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)8 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)7 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 Test (org.junit.Test)5 SysRoleSystemAttributeDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto)3 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)3 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 AccResultCode (eu.bcvsolutions.idm.acc.domain.AccResultCode)2 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)2 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)2 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)2 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)2 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)2 SysRoleSystemAttributeFilter (eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemAttributeFilter)2 SysRoleSystem_ (eu.bcvsolutions.idm.acc.entity.SysRoleSystem_)2 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)2