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