Search in sources :

Example 11 with SysAttributeControlledValueFilter

use of eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter in project CzechIdMng by bcvsolutions.

the class ProvisioningMergeTest method testDisableAttribteControlledValues.

@Test
public void testDisableAttribteControlledValues() {
    SysSystemDto system = helper.createSystem("test_resource");
    SysSystemMappingDto mapping = helper.createMapping(system);
    IdmRoleDto roleOne = helper.createRole();
    IdmRoleDto roleTwo = helper.createRole();
    SysRoleSystemDto roleSystemOne = helper.createRoleSystem(roleOne, system);
    SysRoleSystemDto roleSystemTwo = helper.createRoleSystem(roleTwo, system);
    SysSchemaAttributeDto rightsSchemaAttribute = new SysSchemaAttributeDto();
    rightsSchemaAttribute.setObjectClass(mapping.getObjectClass());
    rightsSchemaAttribute.setName(RIGHTS_ATTRIBUTE);
    rightsSchemaAttribute.setMultivalued(true);
    rightsSchemaAttribute.setClassType(String.class.getName());
    rightsSchemaAttribute.setReadable(true);
    rightsSchemaAttribute.setUpdateable(true);
    rightsSchemaAttribute = schemaAttributeService.save(rightsSchemaAttribute);
    SysSystemAttributeMappingDto rightsAttribute = new SysSystemAttributeMappingDto();
    rightsAttribute.setSchemaAttribute(rightsSchemaAttribute.getId());
    rightsAttribute.setSystemMapping(mapping.getId());
    rightsAttribute.setName(RIGHTS_ATTRIBUTE);
    rightsAttribute.setStrategyType(AttributeMappingStrategyType.MERGE);
    rightsAttribute = attributeMappingService.save(rightsAttribute);
    SysRoleSystemAttributeDto roleAttributeOne = new SysRoleSystemAttributeDto();
    roleAttributeOne.setName(RIGHTS_ATTRIBUTE);
    roleAttributeOne.setRoleSystem(roleSystemOne.getId());
    roleAttributeOne.setStrategyType(AttributeMappingStrategyType.MERGE);
    roleAttributeOne.setSystemAttributeMapping(rightsAttribute.getId());
    roleAttributeOne.setTransformToResourceScript("return '" + ONE_VALUE + "';");
    roleAttributeOne = roleSystemAttributeService.saveInternal(roleAttributeOne);
    List<Serializable> controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    SysRoleSystemAttributeDto roleAttributeTwo = new SysRoleSystemAttributeDto();
    roleAttributeTwo.setName(RIGHTS_ATTRIBUTE);
    roleAttributeTwo.setRoleSystem(roleSystemTwo.getId());
    roleAttributeTwo.setStrategyType(AttributeMappingStrategyType.MERGE);
    roleAttributeTwo.setSystemAttributeMapping(rightsAttribute.getId());
    roleAttributeTwo.setTransformToResourceScript("return '" + TWO_VALUE + "';");
    roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
    controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    assertNotNull(controlledAttributeValues);
    assertEquals(2, controlledAttributeValues.size());
    assertTrue(controlledAttributeValues.contains(ONE_VALUE));
    assertTrue(controlledAttributeValues.contains(TWO_VALUE));
    SysAttributeControlledValueFilter attributeControlledValueFilter = new SysAttributeControlledValueFilter();
    attributeControlledValueFilter.setAttributeMappingId(rightsAttribute.getId());
    attributeControlledValueFilter.setHistoricValue(Boolean.TRUE);
    List<Serializable> historicControlledValues = // 
    attributeControlledValueService.find(attributeControlledValueFilter, // 
    null).getContent().stream().map(// 
    SysAttributeControlledValueDto::getValue).collect(Collectors.toList());
    assertNotNull(historicControlledValues);
    assertEquals(0, historicControlledValues.size());
    // Set attribute TWO as disabled (should be disappears from controlled values
    // and appears in the history)
    roleAttributeTwo.setDisabledAttribute(true);
    roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
    controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    assertNotNull(controlledAttributeValues);
    assertEquals(1, controlledAttributeValues.size());
    assertTrue(controlledAttributeValues.contains(ONE_VALUE));
    // Search historic controlled values for that attribute
    historicControlledValues = // 
    attributeControlledValueService.find(attributeControlledValueFilter, // 
    null).getContent().stream().map(// 
    SysAttributeControlledValueDto::getValue).collect(Collectors.toList());
    assertNotNull(historicControlledValues);
    assertEquals(1, historicControlledValues.size());
    assertTrue(historicControlledValues.contains(TWO_VALUE));
    // Set attribute TWO as enabled (should be appears in controlled values
    // and disappears from the history)
    roleAttributeTwo.setDisabledAttribute(false);
    roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
    controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    assertNotNull(controlledAttributeValues);
    assertEquals(2, controlledAttributeValues.size());
    assertTrue(controlledAttributeValues.contains(ONE_VALUE));
    assertTrue(controlledAttributeValues.contains(TWO_VALUE));
    // Recalculation
    attributeMappingService.getCachedControlledAndHistoricAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    // Search historic controlled values for that attribute
    historicControlledValues = // 
    attributeControlledValueService.find(attributeControlledValueFilter, // 
    null).getContent().stream().map(// 
    SysAttributeControlledValueDto::getValue).collect(Collectors.toList());
    assertNotNull(historicControlledValues);
    assertEquals(0, historicControlledValues.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Serializable(java.io.Serializable) SysAttributeControlledValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysAttributeControlledValueFilter(eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 12 with SysAttributeControlledValueFilter

use of eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter in project CzechIdMng by bcvsolutions.

the class ProvisioningMergeTest method testChangeValueDefinition.

@Test
public void testChangeValueDefinition() {
    SysSystemDto system = helper.createSystem("test_resource");
    SysSystemMappingDto mapping = helper.createMapping(system);
    IdmRoleDto roleOne = helper.createRole();
    IdmRoleDto roleTwo = helper.createRole();
    SysRoleSystemDto roleSystemOne = helper.createRoleSystem(roleOne, system);
    SysRoleSystemDto roleSystemTwo = helper.createRoleSystem(roleTwo, system);
    SysSchemaAttributeDto rightsSchemaAttribute = new SysSchemaAttributeDto();
    rightsSchemaAttribute.setObjectClass(mapping.getObjectClass());
    rightsSchemaAttribute.setName(RIGHTS_ATTRIBUTE);
    rightsSchemaAttribute.setMultivalued(true);
    rightsSchemaAttribute.setClassType(String.class.getName());
    rightsSchemaAttribute.setReadable(true);
    rightsSchemaAttribute.setUpdateable(true);
    rightsSchemaAttribute = schemaAttributeService.save(rightsSchemaAttribute);
    SysSystemAttributeMappingDto rightsAttribute = new SysSystemAttributeMappingDto();
    rightsAttribute.setSchemaAttribute(rightsSchemaAttribute.getId());
    rightsAttribute.setSystemMapping(mapping.getId());
    rightsAttribute.setName(RIGHTS_ATTRIBUTE);
    rightsAttribute.setStrategyType(AttributeMappingStrategyType.MERGE);
    rightsAttribute = attributeMappingService.save(rightsAttribute);
    SysRoleSystemAttributeDto roleAttributeOne = new SysRoleSystemAttributeDto();
    roleAttributeOne.setName(RIGHTS_ATTRIBUTE);
    roleAttributeOne.setRoleSystem(roleSystemOne.getId());
    roleAttributeOne.setStrategyType(AttributeMappingStrategyType.MERGE);
    roleAttributeOne.setSystemAttributeMapping(rightsAttribute.getId());
    roleAttributeOne.setTransformToResourceScript("return '" + ONE_VALUE + "';");
    roleAttributeOne = roleSystemAttributeService.saveInternal(roleAttributeOne);
    List<Serializable> controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    SysRoleSystemAttributeDto roleAttributeTwo = new SysRoleSystemAttributeDto();
    roleAttributeTwo.setName(RIGHTS_ATTRIBUTE);
    roleAttributeTwo.setRoleSystem(roleSystemTwo.getId());
    roleAttributeTwo.setStrategyType(AttributeMappingStrategyType.MERGE);
    roleAttributeTwo.setSystemAttributeMapping(rightsAttribute.getId());
    roleAttributeTwo.setTransformToResourceScript("return '" + TWO_VALUE + "';");
    roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
    controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    assertNotNull(controlledAttributeValues);
    assertEquals(2, controlledAttributeValues.size());
    assertTrue(controlledAttributeValues.contains(ONE_VALUE));
    assertTrue(controlledAttributeValues.contains(TWO_VALUE));
    SysAttributeControlledValueFilter attributeControlledValueFilter = new SysAttributeControlledValueFilter();
    attributeControlledValueFilter.setAttributeMappingId(rightsAttribute.getId());
    attributeControlledValueFilter.setHistoricValue(Boolean.TRUE);
    List<Serializable> historicControlledValues = // 
    attributeControlledValueService.find(attributeControlledValueFilter, // 
    null).getContent().stream().map(// 
    SysAttributeControlledValueDto::getValue).collect(Collectors.toList());
    assertNotNull(historicControlledValues);
    assertEquals(0, historicControlledValues.size());
    // Change value definition on attribute TWO (should be changed in controlled
    // values
    // and old value appears in the history)
    roleAttributeTwo.setTransformToResourceScript("return '" + TWO_VALUE + "Changed';");
    roleAttributeTwo = roleSystemAttributeService.saveInternal(roleAttributeTwo);
    controlledAttributeValues = attributeMappingService.getControlledAttributeValues(system.getId(), mapping.getEntityType(), RIGHTS_ATTRIBUTE);
    assertNotNull(controlledAttributeValues);
    assertEquals(2, controlledAttributeValues.size());
    assertTrue(controlledAttributeValues.contains(ONE_VALUE));
    assertTrue(controlledAttributeValues.contains(TWO_VALUE + "Changed"));
    // Search historic controlled values for that attribute
    historicControlledValues = // 
    attributeControlledValueService.find(attributeControlledValueFilter, // 
    null).getContent().stream().map(// 
    SysAttributeControlledValueDto::getValue).collect(Collectors.toList());
    assertNotNull(historicControlledValues);
    assertEquals(1, historicControlledValues.size());
    assertTrue(historicControlledValues.contains(TWO_VALUE));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Serializable(java.io.Serializable) SysAttributeControlledValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysAttributeControlledValueFilter(eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 13 with SysAttributeControlledValueFilter

use of eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter in project CzechIdMng by bcvsolutions.

the class DefaultSysRoleSystemAttributeServiceTest method testArchiveControledValuesAfterRoleIsDeleted.

@Test
public void testArchiveControledValuesAfterRoleIsDeleted() {
    // prepare mapped attribute with controled value
    IdmRoleDto role = helper.createRole();
    SysSystemDto system = helper.createTestResourceSystem(true);
    systemService.generateSchema(system);
    // 
    // create eav attribute
    String attributeName = helper.getSchemaColumnName("EAV_ATTRIBUTE");
    SysSchemaAttributeFilter schemaAttFilter = new SysSchemaAttributeFilter();
    schemaAttFilter.setSystemId(system.getId());
    schemaAttFilter.setName(attributeName);
    List<SysSchemaAttributeDto> schemaAttrs = schemaAttributeService.find(schemaAttFilter, null).getContent();
    Assert.assertEquals(1, schemaAttrs.size());
    SysSchemaAttributeDto schemaAttributeDto = schemaAttrs.get(0);
    schemaAttributeDto.setMultivalued(true);
    schemaAttributeDto = schemaAttributeService.save(schemaAttributeDto);
    SysSystemMappingDto systemMapping = helper.getDefaultMapping(system);
    SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
    schemaAttributeFilter.setSystemId(system.getId());
    schemaAttributeFilter.setName(attributeName);
    List<SysSchemaAttributeDto> atts = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
    Assert.assertEquals(1, atts.size());
    SysSchemaAttributeDto sysSchemaAttributeEav = atts.get(0);
    // 
    // create eav attribute mapping with merge
    SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
    attributeMapping.setExtendedAttribute(true);
    attributeMapping.setName(attributeName);
    attributeMapping.setIdmPropertyName(attributeName);
    attributeMapping.setStrategyType(AttributeMappingStrategyType.MERGE);
    attributeMapping.setSchemaAttribute(sysSchemaAttributeEav.getId());
    attributeMapping.setSystemMapping(systemMapping.getId());
    attributeMapping = systemAttributeMappingService.save(attributeMapping);
    // 
    // role system mapping with merge value
    SysRoleSystemDto roleSystem = helper.createRoleSystem(role, system);
    SysRoleSystemAttributeDto overloadedRoleOne = new SysRoleSystemAttributeDto();
    overloadedRoleOne.setSystemAttributeMapping(attributeMapping.getId());
    overloadedRoleOne.setEntityAttribute(false);
    overloadedRoleOne.setExtendedAttribute(true);
    overloadedRoleOne.setStrategyType(AttributeMappingStrategyType.MERGE);
    overloadedRoleOne.setName(attributeMapping.getName());
    overloadedRoleOne.setDisabledDefaultAttribute(false);
    overloadedRoleOne.setIdmPropertyName(attributeName);
    overloadedRoleOne.setRoleSystem(roleSystem.getId());
    String valueOne = helper.createName();
    overloadedRoleOne.setTransformToResourceScript("return '" + valueOne + "';");
    overloadedRoleOne = roleSystemAttributeService.save(overloadedRoleOne);
    // 
    // assign role to identity
    IdmIdentityDto identity = helper.createIdentity();
    attributeMapping = systemAttributeMappingService.get(attributeMapping.getId());
    Assert.assertTrue(attributeMapping.isEvictControlledValuesCache());
    IdmRoleRequestDto request = helper.createRoleRequest(identity, role);
    request = helper.executeRequest(request, false, true);
    UUID identityRoleId = request.getConceptRoles().get(0).getIdentityRole();
    IdmIdentityRoleDto identityRole = identityRoleService.get(identityRoleId);
    List<AccAccountDto> accounts = accountService.getAccounts(system.getId(), identity.getId());
    Assert.assertEquals(1, accounts.size());
    // Account was created, provisioning was finished, but attribute was still not
    // recalculated, because provisioning for create of account doesn't need a
    // controlled values, so attribute is not recalculated now.
    attributeMapping = systemAttributeMappingService.get(attributeMapping.getId());
    Assert.assertTrue(attributeMapping.isEvictControlledValuesCache());
    // Execute update provisioning -> executes recalculation of the attribute
    identityService.save(identity);
    attributeMapping = systemAttributeMappingService.get(attributeMapping.getId());
    Assert.assertFalse(attributeMapping.isEvictControlledValuesCache());
    // 
    // find controlled values
    SysAttributeControlledValueFilter valueFilter = new SysAttributeControlledValueFilter();
    valueFilter.setAttributeMappingId(attributeMapping.getId());
    List<SysAttributeControlledValueDto> controlledValues = attributeControlledValueService.find(valueFilter, null).getContent();
    Assert.assertEquals(1, controlledValues.size());
    Assert.assertEquals(valueOne, controlledValues.get(0).getValue());
    // try to delete role => role is still assigned
    try {
        roleService.delete(role);
    } catch (ResultCodeException ex) {
        Assert.assertEquals(CoreResultCode.ROLE_DELETE_FAILED_IDENTITY_ASSIGNED.getCode(), ((ResultCodeException) ex).getError().getError().getStatusEnum());
    }
    // 
    controlledValues = attributeControlledValueService.find(valueFilter, null).getContent();
    Assert.assertEquals(1, controlledValues.size());
    Assert.assertEquals(valueOne, controlledValues.get(0).getValue());
    Assert.assertTrue(controlledValues.stream().allMatch(v -> !v.isHistoricValue()));
    // 
    // remove assigned role and remove role with controller values
    identityRoleService.delete(identityRole);
    roleService.delete(role);
    attributeMapping = systemAttributeMappingService.get(attributeMapping.getId());
    Assert.assertTrue(attributeMapping.isEvictControlledValuesCache());
    // Manual recalculation of the attribute
    systemAttributeMappingService.recalculateAttributeControlledValues(system.getId(), SystemEntityType.IDENTITY, attributeName, attributeMapping);
    // Attribute must be recalculated now
    attributeMapping = systemAttributeMappingService.get(attributeMapping.getId());
    Assert.assertFalse(attributeMapping.isEvictControlledValuesCache());
    // 
    controlledValues = attributeControlledValueService.find(valueFilter, null).getContent();
    Assert.assertEquals(1, controlledValues.size());
    Assert.assertEquals(valueOne, controlledValues.get(0).getValue());
    Assert.assertTrue(controlledValues.stream().allMatch(v -> v.isHistoricValue()));
    // 
    // delete system (referential integrity just for sure)
    systemService.delete(system);
    controlledValues = attributeControlledValueService.find(valueFilter, null).getContent();
    Assert.assertTrue(controlledValues.isEmpty());
}
Also used : AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) Autowired(org.springframework.beans.factory.annotation.Autowired) SysAttributeControlledValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto) SysAttributeControlledValueFilter(eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) IcObjectClassInfo(eu.bcvsolutions.idm.ic.api.IcObjectClassInfo) SysRoleSystemService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemService) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) SysRoleSystemAttributeService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) SysAttributeControlledValueService(eu.bcvsolutions.idm.acc.service.api.SysAttributeControlledValueService) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) SystemOperationType(eu.bcvsolutions.idm.acc.domain.SystemOperationType) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Test(org.junit.Test) UUID(java.util.UUID) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) List(java.util.List) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) TestHelper(eu.bcvsolutions.idm.acc.TestHelper) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) Assert(org.junit.Assert) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysAttributeControlledValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysAttributeControlledValueFilter(eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 14 with SysAttributeControlledValueFilter

use of eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter in project CzechIdMng by bcvsolutions.

the class DefaultSysSystemAttributeMappingService method delete.

@Override
@Transactional
public void delete(SysSystemAttributeMappingDto dto, BasePermission... permission) {
    Assert.notNull(dto, "DTO is required.");
    SysSystemAttributeMapping entity = this.getEntity(dto.getId());
    Assert.notNull(entity, "Entity is required.");
    SysSystemMappingDto systemMappingDto = DtoUtils.getEmbedded(dto, SysSystemAttributeMapping_.systemMapping, SysSystemMappingDto.class);
    SysSchemaObjectClassDto objectClassDto = DtoUtils.getEmbedded(systemMappingDto, SysSystemMapping_.objectClass, SysSchemaObjectClassDto.class);
    SysSystemDto systemDto = DtoUtils.getEmbedded(objectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
    // Check if attribute is used in some systems group.
    SysSystemGroupSystemFilter groupSystemFilter = new SysSystemGroupSystemFilter();
    groupSystemFilter.setMergeMappingAttributeId(entity.getId());
    long count = systemGroupSystemService.count(groupSystemFilter);
    if (count > 0) {
        throw new ResultCodeException(AccResultCode.SYSTEM_DELETE_FAILED_HAS_SYSTEM_GROUPS, ImmutableMap.of("attribute", dto.getName(), "count", count));
    }
    if (syncConfigRepository.countByCorrelationAttribute_Id(dto.getId()) > 0) {
        throw new ResultCodeException(AccResultCode.ATTRIBUTE_MAPPING_DELETE_FAILED_USED_IN_SYNC, ImmutableMap.of("attribute", dto.getName(), "system", systemDto.getName()));
    }
    if (syncConfigRepository.countByFilterAttribute(entity) > 0) {
        throw new ResultCodeException(AccResultCode.ATTRIBUTE_MAPPING_DELETE_FAILED_USED_IN_SYNC, ImmutableMap.of("attribute", dto.getName(), "system", systemDto.getName()));
    }
    if (syncConfigRepository.countByTokenAttribute(entity) > 0) {
        throw new ResultCodeException(AccResultCode.ATTRIBUTE_MAPPING_DELETE_FAILED_USED_IN_SYNC, ImmutableMap.of("attribute", dto.getName(), "system", systemDto.getName()));
    }
    List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.findRoleConfigByMemberOfAttribute(entity.getId());
    if (syncConfigs.size() > 0) {
        systemMappingDto = DtoUtils.getEmbedded(syncConfigs.get(0), SysSyncRoleConfig_.systemMapping, SysSystemMappingDto.class);
        objectClassDto = DtoUtils.getEmbedded(systemMappingDto, SysSystemMapping_.objectClass, SysSchemaObjectClassDto.class);
        systemDto = DtoUtils.getEmbedded(objectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
        throw new ResultCodeException(AccResultCode.ATTRIBUTE_MAPPING_DELETE_FAILED_USED_IN_SYNC, ImmutableMap.of("attribute", dto.getName(), "system", systemDto.getName()));
    }
    // Delete attributes
    roleSystemAttributeRepository.deleteBySystemAttributeMapping(entity);
    // Delete of controlled and historic values
    if (dto.getId() != null) {
        SysAttributeControlledValueFilter attributeControlledValueFilter = new SysAttributeControlledValueFilter();
        attributeControlledValueFilter.setAttributeMappingId(dto.getId());
        List<SysAttributeControlledValueDto> controlledAndHistoricValues = attributeControlledValueService.find(attributeControlledValueFilter, null).getContent();
        controlledAndHistoricValues.forEach(value -> attributeControlledValueService.delete(value));
    }
    super.delete(dto, permission);
}
Also used : AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSystemGroupSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemGroupSystemFilter) SysAttributeControlledValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysAttributeControlledValueFilter(eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) SysSystemAttributeMapping(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SysAttributeControlledValueFilter (eu.bcvsolutions.idm.acc.dto.filter.SysAttributeControlledValueFilter)14 SysAttributeControlledValueDto (eu.bcvsolutions.idm.acc.dto.SysAttributeControlledValueDto)13 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)12 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)12 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)11 SysRoleSystemAttributeDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto)10 SysRoleSystemDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto)10 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)10 Serializable (java.io.Serializable)10 Test (org.junit.Test)10 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)9 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)4 SysSchemaAttributeFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter)4 SysAttributeControlledValueService (eu.bcvsolutions.idm.acc.service.api.SysAttributeControlledValueService)4 SysSystemAttributeMappingService (eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 List (java.util.List)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 TestHelper (eu.bcvsolutions.idm.acc.TestHelper)3