Search in sources :

Example 46 with SystemEntityType

use of eu.bcvsolutions.idm.acc.domain.SystemEntityType 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 47 with SystemEntityType

use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.

the class RoleCatalogueSynchronizationExecutor method doUpdateEntity.

/**
 * Fill data from IC attributes to entity (EAV and confidential storage too).
 */
@Override
protected void doUpdateEntity(SynchronizationContext context) {
    String uid = context.getUid();
    SysSyncLogDto log = context.getLog();
    SysSyncItemLogDto logItem = context.getLogItem();
    if (context.isSkipEntityUpdate()) {
        addToItemLog(logItem, MessageFormat.format("Update of entity for account with uid {0} is skipped", uid));
        return;
    }
    List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
    List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
    AccAccountDto account = context.getAccount();
    List<IcAttribute> icAttributes = context.getIcObject().getAttributes();
    UUID entityId = getEntityByAccount(account.getId());
    IdmRoleCatalogueDto roleCatalogue = null;
    if (entityId != null) {
        roleCatalogue = catalogueService.get(entityId);
    }
    if (roleCatalogue != null) {
        // Update entity
        roleCatalogue = fillEntity(mappedAttributes, uid, icAttributes, roleCatalogue, false, context);
        if (context.isEntityDifferent()) {
            roleCatalogue = this.save(roleCatalogue, true, context);
        }
        // Role catalogue Updated
        addToItemLog(logItem, MessageFormat.format("Role catalogue with id {0} was updated", roleCatalogue.getId()));
        if (logItem != null) {
            logItem.setDisplayName(roleCatalogue.getName());
        }
        SystemEntityType entityType = context.getEntityType();
        if (context.isEntityDifferent() && this.isProvisioningImplemented(entityType, logItem)) {
            // Call provisioning for this entity
            callProvisioningForEntity(roleCatalogue, entityType, logItem);
        }
        return;
    } else {
        addToItemLog(logItem, "Warning! - Role catalogue was not found and cannot be updated (maybe was deleted  within deleting of parent catalogue).");
        initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.WARNING, logItem, log, actionLogs);
        return;
    }
}
Also used : SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) UUID(java.util.UUID) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 48 with SystemEntityType

use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.

the class RoleCatalogueSynchronizationExecutor method processTreeSync.

/**
 * Execute sync for catalogue and given accounts.
 *
 * @param context
 * @param accountsMap
 */
private void processTreeSync(SynchronizationContext context, Map<String, IcConnectorObject> accountsMap) {
    AbstractSysSyncConfigDto config = context.getConfig();
    SystemEntityType entityType = context.getEntityType();
    SysSystemDto system = context.getSystem();
    List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
    SysSyncLogDto log = context.getLog();
    List<SysSyncActionLogDto> actionsLog = context.getActionLogs();
    AttributeMapping tokenAttribute = context.getTokenAttribute();
    // Find UID/PARENT/CODE attribute
    SysSystemAttributeMappingDto uidAttribute = attributeHandlingService.getUidAttribute(mappedAttributes, system);
    SysSystemAttributeMappingDto parentAttribute = getAttributeByIdmProperty(PARENT_FIELD, mappedAttributes);
    SysSystemAttributeMappingDto codeAttribute = getAttributeByIdmProperty(CODE_FIELD, mappedAttributes);
    if (parentAttribute == null) {
        LOG.warn("Parent attribute is not specified! Role catalogue will not be recomputed.");
    }
    if (codeAttribute == null) {
        LOG.warn("Code attribute is not specified!");
    }
    // Find all roots
    Collection<String> roots = findRoots(parentAttribute, accountsMap, config, context);
    if (roots.isEmpty()) {
        log.addToLog("No roots to synchronization found!");
    } else {
        log.addToLog(MessageFormat.format("We found [{0}] roots: [{1}]", roots.size(), roots));
    }
    if (parentAttribute == null) {
        // just alias all accounts as roots and process
        roots.addAll(accountsMap.keySet());
    }
    Set<String> accountsUseInTreeList = new HashSet<>(roots.size());
    for (String root : roots) {
        accountsUseInTreeList.add(root);
        IcConnectorObject account = accountsMap.get(root);
        SynchronizationContext itemContext = cloneItemContext(context);
        // 
        itemContext.addUid(// 
        root).addIcObject(// 
        account).addAccount(// 
        null).addTokenAttribute(// 
        tokenAttribute).addGeneratedUid(// 
        null);
        boolean result = handleIcObject(itemContext);
        if (!result) {
            return;
        }
        if (parentAttribute != null) {
            Object uidValueParent = this.getValueByMappedAttribute(uidAttribute, account.getAttributes(), context);
            processChildren(parentAttribute, uidValueParent, uidAttribute, accountsMap, accountsUseInTreeList, itemContext, roots);
        }
    }
    if (config.isReconciliation()) {
        // We do reconciliation (find missing account)
        startReconciliation(entityType, accountsUseInTreeList, config, system, log, actionsLog);
    }
}
Also used : SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) HashSet(java.util.HashSet)

Example 49 with SystemEntityType

use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.

the class DefaultSysSystemEntityService method toPredicates.

@Override
protected List<Predicate> toPredicates(Root<SysSystemEntity> root, CriteriaQuery<?> query, CriteriaBuilder builder, SysSystemEntityFilter filter) {
    List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
    // 
    String text = filter.getText();
    if (StringUtils.isNotEmpty(text)) {
        text = text.toLowerCase();
        List<Predicate> textPredicates = new ArrayList<>(2);
        // 
        textPredicates.add(builder.like(builder.lower(root.get(SysSystemEntity_.uid)), "%" + text + "%"));
        // 
        predicates.add(builder.or(textPredicates.toArray(new Predicate[textPredicates.size()])));
    }
    // 
    UUID systemId = filter.getSystemId();
    if (systemId != null) {
        predicates.add(builder.equal(root.get(SysSystemEntity_.system).get(SysSystem_.id), systemId));
    }
    String uid = filter.getUid();
    if (StringUtils.isNotEmpty(uid)) {
        predicates.add(builder.equal(root.get(SysSystemEntity_.uid), uid));
    }
    SystemEntityType entityType = filter.getEntityType();
    if (entityType != null) {
        predicates.add(builder.equal(root.get(SysSystemEntity_.entityType), entityType));
    }
    // 
    return predicates;
}
Also used : ArrayList(java.util.ArrayList) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) UUID(java.util.UUID) Predicate(javax.persistence.criteria.Predicate)

Example 50 with SystemEntityType

use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.

the class TreeSynchronizationExecutor method processTreeSync.

/**
 * Execute sync for tree and given accounts.
 *
 * @param context
 * @param accountsMap
 */
private void processTreeSync(SynchronizationContext context, Map<String, IcConnectorObject> accountsMap) {
    AbstractSysSyncConfigDto config = context.getConfig();
    SystemEntityType entityType = context.getEntityType();
    SysSystemDto system = context.getSystem();
    List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
    SysSyncLogDto log = context.getLog();
    List<SysSyncActionLogDto> actionsLog = context.getActionLogs();
    AttributeMapping tokenAttribute = context.getTokenAttribute();
    // Find UID/PARENT/CODE attribute
    SysSystemAttributeMappingDto uidAttribute = attributeHandlingService.getUidAttribute(mappedAttributes, system);
    SysSystemAttributeMappingDto parentAttribute = getAttributeByIdmProperty(PARENT_FIELD, mappedAttributes);
    SysSystemAttributeMappingDto codeAttribute = getAttributeByIdmProperty(CODE_FIELD, mappedAttributes);
    if (parentAttribute == null) {
        LOG.warn("Parent attribute is not specified! Organization tree will not be recomputed.");
    }
    if (codeAttribute == null) {
        LOG.warn("Code attribute is not specified!");
    }
    // Find all roots
    Collection<String> roots = findRoots(parentAttribute, accountsMap, config, context);
    if (roots.isEmpty()) {
        log.addToLog("No roots to synchronization found!");
    } else {
        log.addToLog(MessageFormat.format("We found [{0}] roots: [{1}]", roots.size(), roots));
    }
    if (parentAttribute == null) {
        // just alias all accounts as roots and process
        roots.addAll(accountsMap.keySet());
    }
    Set<String> accountsUseInTreeList = new HashSet<>(roots.size());
    for (String root : roots) {
        accountsUseInTreeList.add(root);
        IcConnectorObject account = accountsMap.get(root);
        SynchronizationContext itemContext = cloneItemContext(context);
        // 
        itemContext.addUid(// 
        root).addIcObject(// 
        account).addAccount(// 
        null).addTokenAttribute(// 
        tokenAttribute).addGeneratedUid(// 
        null);
        boolean result = handleIcObject(itemContext);
        if (!result) {
            return;
        }
        if (parentAttribute != null) {
            Object uidValueParent = this.getValueByMappedAttribute(uidAttribute, account.getAttributes(), context);
            processChildren(parentAttribute, uidValueParent, uidAttribute, accountsMap, accountsUseInTreeList, itemContext, roots);
        }
    }
    if (config.isReconciliation()) {
        // We do reconciliation (find missing account)
        startReconciliation(entityType, accountsUseInTreeList, config, system, log, actionsLog);
    }
}
Also used : SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) HashSet(java.util.HashSet)

Aggregations

SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)71 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)51 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)36 Test (org.junit.Test)36 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)28 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)28 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)26 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)21 SysProvisioningOperationFilter (eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter)17 UUID (java.util.UUID)17 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)15 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)15 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)15 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)15 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)13 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)11 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)11 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)11 AttributeMappingStrategyType (eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType)10 SysProvisioningArchiveDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto)10