Search in sources :

Example 1 with SystemOperationType

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

the class DefaultSysSystemMappingService method toPredicates.

@Override
protected List<Predicate> toPredicates(Root<SysSystemMapping> root, CriteriaQuery<?> query, CriteriaBuilder builder, SysSystemMappingFilter 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(SysSystemMapping_.name)), "%" + text + "%"));
        textPredicates.add(builder.like(builder.lower(root.get(SysSystemMapping_.objectClass).get(SysSchemaObjectClass_.system).get(SysSystem_.name)), "%" + text + "%"));
        // 
        predicates.add(builder.or(textPredicates.toArray(new Predicate[textPredicates.size()])));
    }
    // 
    UUID systemId = filter.getSystemId();
    if (systemId != null) {
        predicates.add(builder.equal(root.get(SysSystemMapping_.objectClass).get(SysSchemaObjectClass_.system).get(SysSystem_.id), systemId));
    }
    UUID objectClassId = filter.getObjectClassId();
    if (objectClassId != null) {
        predicates.add(builder.equal(root.get(SysSystemMapping_.objectClass).get(SysSchemaObjectClass_.id), objectClassId));
    }
    SystemOperationType operationType = filter.getOperationType();
    if (operationType != null) {
        predicates.add(builder.equal(root.get(SysSystemMapping_.operationType), operationType));
    }
    UUID treeTypeId = filter.getTreeTypeId();
    if (treeTypeId != null) {
        predicates.add(builder.equal(root.get(SysSystemMapping_.treeType).get(IdmTreeType_.id), treeTypeId));
    }
    // 
    SystemEntityType entityType = filter.getEntityType();
    if (entityType != null) {
        predicates.add(builder.equal(root.get(SysSystemMapping_.entityType), entityType));
    }
    // 
    return predicates;
}
Also used : SystemOperationType(eu.bcvsolutions.idm.acc.domain.SystemOperationType) ArrayList(java.util.ArrayList) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) UUID(java.util.UUID) Predicate(javax.persistence.criteria.Predicate)

Example 2 with SystemOperationType

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

the class AbstractSystemMappingAutoAttributesProcessor method conditional.

@Override
public boolean conditional(EntityEvent<SysSystemMappingDto> event) {
    SysSystemMappingDto systemMappingDto = event.getContent();
    if (getSystemEntityType() != systemMappingDto.getEntityType()) {
        return false;
    }
    // Attributes will be generated only for defined operation type. Or for all if is null.
    SystemOperationType operationType = getSystemOperationType();
    if (operationType != null && operationType != systemMappingDto.getOperationType()) {
        return false;
    }
    // Attributes will be generated only for defined schema.
    SysSchemaObjectClassDto objectClassDto = lookupService.lookupEmbeddedDto(systemMappingDto, SysSystemMapping_.objectClass.getName());
    if (!getSchemaType().equals(objectClassDto.getObjectClassName())) {
        return false;
    }
    if (event.getBooleanProperty(SysSystemMappingService.ENABLE_AUTOMATIC_CREATION_OF_MAPPING)) {
        return super.conditional(event);
    }
    return false;
}
Also used : SystemOperationType(eu.bcvsolutions.idm.acc.domain.SystemOperationType) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)

Example 3 with SystemOperationType

use of eu.bcvsolutions.idm.acc.domain.SystemOperationType 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)

Aggregations

SystemOperationType (eu.bcvsolutions.idm.acc.domain.SystemOperationType)3 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)2 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)2 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)2 SysSchemaObjectClassFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSchemaObjectClassFilter)1 SystemMappingEvent (eu.bcvsolutions.idm.acc.event.SystemMappingEvent)1 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Predicate (javax.persistence.criteria.Predicate)1