use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method startExport.
/**
* Start export entities to target resource
*
* @param entityType
* @param config
* @param mappedAttributes
* @param log
* @param actionsLog
*/
@Beta
protected void startExport(SystemEntityType entityType, AbstractSysSyncConfigDto config, List<SysSystemAttributeMappingDto> mappedAttributes, SysSyncLogDto log, List<SysSyncActionLogDto> actionsLog) {
SysSystemMappingDto systemMapping = systemMappingService.get(config.getSystemMapping());
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(systemMapping.getObjectClass());
SysSystemDto system = DtoUtils.getEmbedded(schemaObjectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
SysSystemAttributeMappingDto uidAttribute = systemAttributeMappingService.getUidAttribute(mappedAttributes, system);
List<DTO> entities = this.findAll();
entities.stream().forEach(entity -> {
// TODO: evaluate to groovy script
SynchronizationContext itemBuilder = new SynchronizationContext();
//
itemBuilder.addConfig(config).addSystem(//
system).addEntityType(//
entityType).addEntityId(//
entity.getId()).addLog(//
log).addActionLogs(actionsLog);
// Start export for this entity
exportEntity(itemBuilder, uidAttribute, entity);
});
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method generateUID.
/**
* Generate UID value from mapped attribute marked as UID (Unique ID). UID
* mapped attribute must exist and returned value must be not null and must be
* String.
*
* If is generated UID in the context, then will used.
*
* @param context
* @return
*/
private String generateUID(SynchronizationContext context) {
Assert.notNull(context, "Context is required!");
SysSystemDto system = context.getSystem();
List<IcAttribute> icAttributes = context.getIcObject().getAttributes();
List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
String generatedUid = context.getGeneratedUid();
if (generatedUid == null) {
context.addGeneratedUid(systemAttributeMappingService.getUidValueFromResource(icAttributes, mappedAttributes, system));
}
return context.getGeneratedUid();
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method fillEntity.
/**
* Fill entity with attributes from IC module (by mapped attributes).
*
* @param mappedAttributes
* @param uid
* @param icAttributes
* @param entity
* @param create
* (is create or update entity situation)
* @param context
* @return
*/
protected IdmIdentityContractDto fillEntity(List<SysSystemAttributeMappingDto> mappedAttributes, String uid, List<IcAttribute> icAttributes, IdmIdentityContractDto dto, boolean create, SynchronizationContext context) {
mappedAttributes.stream().filter(attribute -> {
// Skip disabled attributes
// Skip extended attributes (we need update/ create entity first)
// Skip confidential attributes (we need update/ create entity
// first)
boolean fastResult = !attribute.isDisabledAttribute() && attribute.isEntityAttribute() && !attribute.isConfidentialAttribute();
if (!fastResult) {
return false;
}
// Can be value set by attribute strategy?
return this.canSetValue(uid, attribute, dto, create);
}).forEach(attribute -> {
String attributeProperty = attribute.getIdmPropertyName();
Object transformedValue = getValueByMappedAttribute(attribute, icAttributes, context);
// they), but to the embedded map.
if (CONTRACT_GUARANTEES_FIELD.equals(attributeProperty)) {
if (transformedValue instanceof SyncIdentityContractDto) {
dto.getEmbedded().put(SYNC_CONTRACT_FIELD, (SyncIdentityContractDto) transformedValue);
} else {
dto.getEmbedded().put(SYNC_CONTRACT_FIELD, new SyncIdentityContractDto());
}
return;
}
// Set transformed value from target system to entity
try {
EntityUtils.setEntityValue(dto, attributeProperty, transformedValue);
} catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | ProvisioningException e) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_NOT_SET, ImmutableMap.of("property", attributeProperty, "uid", uid), e);
}
});
return dto;
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class TreeSynchronizationExecutor method process.
@Override
public AbstractSysSyncConfigDto process(UUID synchronizationConfigId) {
// Clear cache
this.clearCache();
// Validate and create basic context
SynchronizationContext context = this.validate(synchronizationConfigId);
AbstractSysSyncConfigDto config = context.getConfig();
SystemEntityType entityType = context.getEntityType();
SysSystemDto system = context.getSystem();
IcConnectorConfiguration connectorConfig = context.getConnectorConfig();
List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
SysSystemMappingDto systemMapping = systemMappingService.get(context.getConfig().getSystemMapping());
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(systemMapping.getObjectClass());
IcObjectClass objectClass = new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName());
// Load last token
Object lastToken = config.isReconciliation() ? null : config.getToken();
// Create basic synchronization log
SysSyncLogDto log = new SysSyncLogDto();
log.setSynchronizationConfig(config.getId());
log.setStarted(LocalDateTime.now());
log.setRunning(true);
log.setToken(lastToken != null ? lastToken.toString() : null);
log.addToLog(MessageFormat.format("Synchronization was started in {0}.", log.getStarted()));
// List of all accounts with full IC object (used in tree sync)
Map<String, IcConnectorObject> accountsMap = new HashMap<>();
longRunningTaskExecutor.setCounter(0L);
try {
log = synchronizationLogService.save(log);
List<SysSyncActionLogDto> actionsLog = new ArrayList<>();
// Add logs to context
context.addLog(log).addActionLogs(actionsLog);
boolean export = false;
if (export) {
// Start exporting entities to resource
log.addToLog("Exporting entities to resource started...");
this.startExport(entityType, config, mappedAttributes, log, actionsLog);
} else {
if (config.getTokenAttribute() == null && !config.isReconciliation()) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TOKEN_ATTRIBUTE_NOT_FOUND);
}
TreeResultsHandler resultHandler = new TreeResultsHandler(accountsMap);
// We have to search all data for tree
IcFilter filter = null;
log.addToLog(MessageFormat.format("Start search with filter {0}.", "NONE"));
log = synchronizationLogService.save(log);
connectorFacade.search(system.getConnectorInstance(), connectorConfig, objectClass, filter, resultHandler);
// Execute sync for this tree and searched accounts
processTreeSync(context, accountsMap);
log = context.getLog();
}
//
log.addToLog(MessageFormat.format("Synchronization was correctly ended in {0}.", LocalDateTime.now()));
synchronizationConfigService.save(config);
} catch (Exception e) {
String message = "Error during synchronization";
log.addToLog(message);
log.setContainsError(true);
log.addToLog(Throwables.getStackTraceAsString(e));
LOG.error(message, e);
} finally {
log.setRunning(false);
log.setEnded(LocalDateTime.now());
log = synchronizationLogService.save(log);
//
longRunningTaskExecutor.setCount(longRunningTaskExecutor.getCounter());
longRunningTaskExecutor.updateState();
// Clear cache
this.clearCache();
}
return config;
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto 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();
Set<String> accountsUseInTreeList = new HashSet<>();
// 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());
}
for (String root : roots) {
accountsUseInTreeList.add(root);
IcConnectorObject account = accountsMap.get(root);
SynchronizationContext itemContext = SynchronizationContext.cloneContext(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