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;
}
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;
}
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);
}
Aggregations