Search in sources :

Example 66 with IdmTreeTypeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.

the class ScriptEvaluatorTest method testEvaluateScriptWithCreateEntity.

@Test
public void testEvaluateScriptWithCreateEntity() {
    IdmScriptDto subScript = new IdmScriptDto();
    subScript.setCategory(IdmScriptCategory.DEFAULT);
    subScript.setCode(getHelper().createName());
    subScript.setName(getHelper().createName());
    // 
    subScript.setScript(createTreeNodeScript(TREE_TYPE_CODE, TREE_TYPE_NAME));
    // 
    subScript = scriptService.save(subScript);
    // 
    createAuthority(subScript.getId(), ScriptAuthorityType.CLASS_NAME, IdmTreeTypeDto.class.getName(), null);
    // 
    createAuthority(subScript.getId(), ScriptAuthorityType.SERVICE, DefaultIdmTreeTypeService.class.getCanonicalName(), "treeTypeService");
    // 
    IdmScriptDto parent = new IdmScriptDto();
    parent.setCategory(IdmScriptCategory.DEFAULT);
    parent.setCode(getHelper().createName());
    parent.setName(getHelper().createName());
    // 
    parent.setScript(createScriptThatCallAnother(subScript, IdmScriptCategory.DEFAULT, null, true));
    parent = scriptService.save(parent);
    // 
    Object uuid = groovyScriptService.evaluate(parent.getScript(), createParametersWithEvaluator(IdmScriptCategory.DEFAULT), createExtraAllowedClass());
    // 
    assertNotNull(uuid);
    // 
    IdmTreeTypeDto treeType = this.treeTypeService.get(UUID.fromString(uuid.toString()));
    // 
    assertNotNull(treeType);
    assertEquals(this.TREE_TYPE_CODE, treeType.getCode());
    assertEquals(this.TREE_TYPE_NAME, treeType.getName());
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) DefaultIdmTreeTypeService(eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmTreeTypeService) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 67 with IdmTreeTypeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.

the class AbstractConnectorType method executeMappingStep.

/**
 * Execute simple mapping step.
 *
 * @param connectorTypeDto
 */
private void executeMappingStep(ConnectorTypeDto connectorTypeDto) {
    String schemaId = connectorTypeDto.getMetadata().get(SCHEMA_ID);
    SysSchemaObjectClassDto schemaDto = null;
    if (schemaId != null) {
        schemaDto = schemaService.get(UUID.fromString(schemaId), IdmBasePermission.READ);
    } else {
        String systemId = connectorTypeDto.getMetadata().get(SYSTEM_DTO_KEY);
        SysSchemaObjectClassFilter filter = new SysSchemaObjectClassFilter();
        Assert.isTrue(Strings.isNotBlank(systemId), "System ID cannot be empty!");
        filter.setSystemId(UUID.fromString(systemId));
        List<SysSchemaObjectClassDto> schemas = schemaService.find(filter, null, IdmBasePermission.READ).getContent().stream().sorted(Comparator.comparing(SysSchemaObjectClassDto::getCreated)).collect(Collectors.toList());
        if (!schemas.isEmpty()) {
            schemaDto = schemas.get(0);
        }
    }
    Assert.notNull(schemaDto, "System schema must exists!");
    String entityType = connectorTypeDto.getMetadata().get(ENTITY_TYPE);
    SystemEntityType systemEntityType = SystemEntityType.valueOf(entityType);
    Assert.notNull(systemEntityType, "Entity type cannot be null!");
    // For tree type have to be filled tree type ID too.
    IdmTreeTypeDto treeTypeDto = null;
    if (SystemEntityType.TREE == systemEntityType) {
        String treeTypeId = connectorTypeDto.getMetadata().get(TREE_TYPE_ID);
        Assert.notNull(treeTypeId, "Tree type ID cannot be null for TREE entity type!");
        treeTypeDto = treeTypeService.get(UUID.fromString(treeTypeId));
        Assert.notNull(treeTypeDto, "Tree type DTO cannot be null for TREE entity type!");
    }
    String operationType = connectorTypeDto.getMetadata().get(OPERATION_TYPE);
    SystemOperationType systemOperationType = SystemOperationType.valueOf(operationType);
    Assert.notNull(systemOperationType, "Operation type cannot be null!");
    // Load existing mapping or create new one.
    String mappingId = connectorTypeDto.getMetadata().get(MAPPING_ID);
    SysSystemMappingDto mappingDto = new SysSystemMappingDto();
    mappingDto.setName("Mapping");
    boolean isNew = true;
    if (mappingId != null) {
        SysSystemMappingDto mappingExisted = systemMappingService.get(mappingId, IdmBasePermission.READ);
        if (mappingExisted != null) {
            isNew = false;
            mappingDto = mappingExisted;
        }
    }
    // For tree type have to be filled tree type ID too.
    if (SystemEntityType.TREE == systemEntityType) {
        mappingDto.setTreeType(treeTypeDto.getId());
    }
    mappingDto.setEntityType(systemEntityType);
    mappingDto.setOperationType(systemOperationType);
    mappingDto.setObjectClass(schemaDto.getId());
    // Save mapping. Event must be publish with property for enable automatic mapping.
    mappingDto = systemMappingService.publish(new SystemMappingEvent(isNew ? SystemMappingEvent.SystemMappingEventType.CREATE : SystemMappingEvent.SystemMappingEventType.UPDATE, mappingDto, ImmutableMap.of(SysSystemMappingService.ENABLE_AUTOMATIC_CREATION_OF_MAPPING, Boolean.TRUE)), isNew ? IdmBasePermission.CREATE : IdmBasePermission.UPDATE).getContent();
    connectorTypeDto.getEmbedded().put(MAPPING_DTO_KEY, mappingDto);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) SystemMappingEvent(eu.bcvsolutions.idm.acc.event.SystemMappingEvent) SystemOperationType(eu.bcvsolutions.idm.acc.domain.SystemOperationType) SysSchemaObjectClassFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaObjectClassFilter) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)

Example 68 with IdmTreeTypeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.

the class TreeTypeDeleteBulkActionIntegrationTest method testForceDelete.

@Test
public void testForceDelete() {
    logout();
    loginAsAdmin();
    // create sub tree nodes, automatic roles, contract, contract positions, system mapping and sync
    IdmTreeTypeDto treeType = getHelper().createTreeType();
    SysSystemDto system = getHelper().createTestResourceSystem(true, getHelper().createName());
    SysSystemMappingFilter filter = new SysSystemMappingFilter();
    filter.setSystemId(system.getId());
    SysSystemMappingDto mapping = systemMappingService.find(filter, null).getContent().get(0);
    mapping.setTreeType(treeType.getId());
    mapping = systemMappingService.save(mapping);
    SysSyncConfigDto syncConfig = new SysSyncConfigDto();
    syncConfig.setName(getHelper().createName());
    syncConfig.setSystemMapping(mapping.getId());
    // finds mapped attributes in existing system
    SysSystemAttributeMappingFilter attributeFilter = new SysSystemAttributeMappingFilter();
    attributeFilter.setSystemId(system.getId());
    attributeFilter.setName(TestHelper.ATTRIBUTE_MAPPING_NAME);
    SysSystemAttributeMappingDto attribute = attributeMappingService.find(attributeFilter, null).getContent().get(0);
    syncConfig.setCorrelationAttribute(attribute.getId());
    syncConfig = (SysSyncConfigDto) syncService.save(syncConfig);
    IdmRoleDto role = getHelper().createRole();
    getHelper().createRoleSystem(role, system);
    // 
    IdmTreeNodeDto treeNode = getHelper().createTreeNode(treeType, null, null);
    IdmTreeNodeDto subTreeNode = getHelper().createTreeNode(treeType, (String) null, treeNode);
    IdmTreeNodeDto subSubTreeNode = getHelper().createTreeNode(treeType, (String) null, subTreeNode);
    IdmTreeNodeDto otherTreeNode = getHelper().createTreeNode();
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().createContract(identity, subTreeNode);
    IdmContractPositionDto contractPosition = getHelper().createContractPosition(contract, subSubTreeNode);
    IdmIdentityRoleDto assignedRoleOne = getHelper().createIdentityRole(contract, role);
    IdmIdentityRoleDto assignedRoleTwo = getHelper().createIdentityRole(contractPosition, role);
    IdmIdentityRoleDto assignedRoleOther = getHelper().createIdentityRole(getHelper().getPrimeContract(identity), role);
    IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, treeNode, RecursionType.DOWN, false);
    // 
    // 3 manual, 2 automatic
    Assert.assertEquals(5, identityRoleService.findAllByIdentity(identity.getId()).size());
    // 
    // remove tree type
    Map<String, Object> properties = new HashMap<>();
    properties.put(EntityEventProcessor.PROPERTY_FORCE_DELETE, Boolean.TRUE);
    // delete by bulk action
    IdmBulkActionDto bulkAction = this.findBulkAction(IdmTreeType.class, TreeTypeDeleteBulkAction.NAME);
    bulkAction.setIdentifiers(Sets.newHashSet(treeType.getId()));
    bulkAction.setProperties(properties);
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    // 
    checkResultLrt(processAction, 1l, 0l, 0l);
    // 
    Assert.assertNull(treeTypeService.get(treeType));
    Assert.assertNull(treeNodeService.get(treeNode));
    Assert.assertNull(treeNodeService.get(subTreeNode));
    Assert.assertNull(treeNodeService.get(subSubTreeNode));
    Assert.assertNull(treeNodeService.get(subSubTreeNode));
    Assert.assertNotNull(identityRoleService.get(assignedRoleOne));
    Assert.assertNotNull(identityRoleService.get(assignedRoleTwo));
    Assert.assertNull(identityContractService.get(contract).getWorkPosition());
    Assert.assertNull(contractPositionService.get(contractPosition).getWorkPosition());
    Assert.assertNull(roleTreeNodeService.get(automaticRole));
    Assert.assertNull(systemMappingService.get(mapping));
    Assert.assertNull(attributeMappingService.get(attribute));
    Assert.assertNull(syncService.get(syncConfig));
    // 
    Assert.assertNotNull(treeNodeService.get(otherTreeNode));
    Assert.assertNotNull(getHelper().getPrimeContract(identity));
    Assert.assertNotNull(identityRoleService.get(assignedRoleOther));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) HashMap(java.util.HashMap) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncConfigDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 69 with IdmTreeTypeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.

the class TreeTypeDeleteBulkActionIntegrationTest method testWithoutForceDelete.

@Test(expected = TreeTypeException.class)
public void testWithoutForceDelete() {
    // create sub tree nodes, automatic roles, contract, contract positions, system mapping and sync
    IdmTreeTypeDto treeType = getHelper().createTreeType();
    SysSystemDto system = getHelper().createTestResourceSystem(true, getHelper().createName());
    SysSystemMappingFilter filter = new SysSystemMappingFilter();
    filter.setSystemId(system.getId());
    SysSystemMappingDto mapping = systemMappingService.find(filter, null).getContent().get(0);
    mapping.setTreeType(treeType.getId());
    mapping = systemMappingService.save(mapping);
    // 
    treeTypeService.delete(treeType);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 70 with IdmTreeTypeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.

the class ContractSliceSyncTest method setDirtyStateAndCheckIt.

@Test
public void setDirtyStateAndCheckIt() {
    // create tree type and node, tree node is used as position in contrac slice synchronization
    IdmTreeTypeDto treeType = this.getHelper().createTreeType();
    IdmTreeNodeDto treeNode = this.getHelper().createTreeNode(treeType, null);
    // create two roles, one role is used as automatic role by organization structure
    // second role is used as manually added
    IdmRoleDto roleOne = this.getHelper().createRole();
    IdmRoleDto roleTwo = this.getHelper().createRole();
    this.getHelper().createAutomaticRole(roleOne, treeNode);
    // init system
    SysSystemDto system = initData();
    // set default tree type for synchronization
    SysSyncContractConfigDto config = (SysSyncContractConfigDto) doCreateSyncConfig(system);
    config.setDefaultTreeType(treeType.getId());
    syncConfigService.save(config);
    IdmIdentityDto identity = helper.createIdentity();
    // for sure remove all contracts
    contractService.findAllByIdentity(identity.getId()).forEach(contract -> {
        contractService.delete(contract);
    });
    // check current delete audits record for identity (and their related entities)
    IdmAuditFilter filter = new IdmAuditFilter();
    filter.setOwnerId(identity.getId().toString());
    filter.setModification("DELETE");
    List<IdmAuditDto> audits = auditService.find(filter, null).getContent();
    assertEquals(0, audits.size());
    // check current slices
    IdmContractSliceFilter contractSliceFilter = new IdmContractSliceFilter();
    contractSliceFilter.setIdentity(identity.getId());
    List<IdmContractSliceDto> slices = contractSliceService.find(contractSliceFilter, null).getContent();
    assertEquals(0, slices.size());
    // check current contracts
    List<IdmIdentityContractDto> allByIdentity = contractService.findAllByIdentity(identity.getId());
    assertEquals(0, allByIdentity.size());
    // delete all data in resource
    this.getBean().deleteAllResourceData();
    // create step one data, please see inside method
    this.getBean().createTestDataStepOne(identity.getUsername(), treeNode.getCode());
    // start synchronization
    helper.startSynchronization(config);
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    // after first synchronization exists one contract
    allByIdentity = contractService.findAllByIdentity(identity.getId());
    assertEquals(1, allByIdentity.size());
    // after first synchronization exists one slice
    slices = contractSliceService.find(contractSliceFilter, null).getContent();
    assertEquals(1, slices.size());
    // after first synchronization exists one identity role - automatic role
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    IdmIdentityRoleDto identityRoleDto = identityRoles.get(0);
    // manually create identity account for check if identity account will be changed or deleted after second synchronization
    // this state create two audit records for the identity account
    AccIdentityAccountDto identityAccount = helper.createIdentityAccount(system, identity);
    identityAccount.setIdentityRole(identityRoleDto.getId());
    identityAccount = identityAccountService.save(identityAccount);
    // add manually role
    IdmIdentityContractDto identityContractDto = allByIdentity.get(0);
    this.getHelper().createIdentityRole(identityContractDto, roleTwo);
    // check current identity roles - one is automatic, second is manually added
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(2, identityRoles.size());
    // prepare data for second step
    this.getBean().createTestDataStepTwo(identity.getUsername(), treeNode.getCode());
    helper.startSynchronization(config);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    // after second synchronization still exists one contract
    allByIdentity = contractService.findAllByIdentity(identity.getId());
    assertEquals(1, allByIdentity.size());
    // after second synchronization exists two slices
    slices = contractSliceService.find(contractSliceFilter, null).getContent();
    assertEquals(2, slices.size());
    // after second synchronization must also exists both roles
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(2, identityRoles.size());
    // check delete operation for identity and their related entities
    filter = new IdmAuditFilter();
    filter.setOwnerId(identity.getId().toString());
    filter.setModification("DELETE");
    audits = auditService.find(filter, null).getContent();
    assertEquals(0, audits.size());
    // check audit for identity roles
    for (IdmIdentityRoleDto identityRole : identityRoles) {
        filter = new IdmAuditFilter();
        filter.setEntityId(identityRole.getId());
        List<IdmAuditDto> auditsForIdentityRole = auditService.find(filter, null).getContent();
        if (identityRole.getAutomaticRole() == null) {
            // manually added role, just create
            assertEquals(1, auditsForIdentityRole.size());
        } else {
            // automatic role change validity
            assertEquals(2, auditsForIdentityRole.size());
        }
    }
    // Check audit records for identity account, exists three record, because helper
    // create one and second create save with change identity role and third is
    // delete of this identity-account (role does not mapping the system)
    filter = new IdmAuditFilter();
    filter.setEntityId(identityAccount.getId());
    List<IdmAuditDto> auditsForIdentityAccount = auditService.find(filter, null).getContent();
    assertEquals(3, auditsForIdentityAccount.size());
    // some tests expect data as contract slice with id 1. Just for sure we clear test slices
    slices = contractSliceService.find(contractSliceFilter, null).getContent();
    slices.forEach(slice -> {
        contractSliceService.delete(slice);
    });
    identityService.delete(identity);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) IdmAuditFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmAuditFilter) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)123 Test (org.junit.Test)91 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)89 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)64 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)44 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)33 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)32 UUID (java.util.UUID)26 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)21 IdmTreeNodeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter)21 Transactional (org.springframework.transaction.annotation.Transactional)19 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)18 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)18 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)18 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)16 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)13 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)13 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)11 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)11 LocalDate (java.time.LocalDate)10