use of eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method resolveUnlinkedSituation.
/**
* Method for resolve unlinked situation for one item.
*/
@Override
public void resolveUnlinkedSituation(SynchronizationUnlinkedActionType action, SynchronizationContext context) {
UUID entityId = context.getEntityId();
SysSyncLogDto log = context.getLog();
SysSyncItemLogDto logItem = context.getLogItem();
List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
addToItemLog(logItem, "Account doesn't exist, but an entity was found by correlation (entity unlinked).");
addToItemLog(logItem, MessageFormat.format("Unlinked action is {0}", action));
DTO entity = findById(entityId);
switch(action) {
case IGNORE:
// Ignore we will do nothing
initSyncActionLog(SynchronizationActionType.UNLINKED, OperationResultType.IGNORE, logItem, log, actionLogs);
return;
case LINK:
// Create idm account
doCreateLink(entity, false, context);
initSyncActionLog(SynchronizationActionType.LINK, OperationResultType.SUCCESS, logItem, log, actionLogs);
return;
case LINK_AND_UPDATE_ACCOUNT:
// Create idm account
doCreateLink(entity, true, context);
initSyncActionLog(SynchronizationActionType.LINK_AND_UPDATE_ACCOUNT, OperationResultType.SUCCESS, logItem, log, actionLogs);
return;
case LINK_AND_UPDATE_ENTITY:
// Create idm account
doCreateLink(entity, false, context);
doUpdateEntity(context);
initSyncActionLog(SynchronizationActionType.LINK_AND_UPDATE_ENTITY, OperationResultType.SUCCESS, logItem, log, actionLogs);
return;
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method startItemSynchronization.
/**
* Main method for synchronization item. This method is call form "custom
* filter" and "connector sync" mode.
*
* @param uid
* @param icObject
* @param type
* @param entityType
* @param itemLog
* @param config
* @param system
* @param mappedAttributes
* @param log
* @param actionsLog
* @return
*/
protected boolean startItemSynchronization(SynchronizationContext itemContext) {
String uid = itemContext.getUid();
AbstractSysSyncConfigDto config = itemContext.getConfig();
SystemEntityType entityType = itemContext.getEntityType();
SysSyncLogDto log = itemContext.getLog();
SysSyncItemLogDto itemLog = itemContext.getLogItem();
List<SysSyncActionLogDto> actionsLog = new ArrayList<>();
try {
SysSyncActionLogFilter actionFilter = new SysSyncActionLogFilter();
actionFilter.setSynchronizationLogId(log.getId());
actionsLog.addAll(syncActionLogService.find(actionFilter, null).getContent());
itemContext.addActionLogs(actionsLog);
// Default setting for log item
itemLog.setIdentification(uid);
itemLog.setDisplayName(uid);
itemLog.setType(entityType.getEntityType().getSimpleName());
// Do synchronization for one item (produces item)
// Start in new Transaction
CoreEvent<SysSyncItemLogDto> event = new CoreEvent<SysSyncItemLogDto>(SynchronizationEventType.START_ITEM, itemLog);
event.getProperties().put(SynchronizationService.WRAPPER_SYNC_ITEM, itemContext);
EventResult<SysSyncItemLogDto> lastResult = entityEventManager.process(event).getLastResult();
boolean result = false;
if (lastResult != null && lastResult.getEvent().getProperties().containsKey(SynchronizationService.RESULT_SYNC_ITEM)) {
result = (boolean) lastResult.getEvent().getProperties().get(SynchronizationService.RESULT_SYNC_ITEM);
}
return result;
} catch (Exception ex) {
Pair<SysSyncActionLogDto, SysSyncItemLogDto> actionWithItemLog = getActionLogThatContains(actionsLog, itemLog);
if (actionWithItemLog != null) {
// We have to decrement count and log as error
itemLog = actionWithItemLog.getRight();
SysSyncActionLogDto actionLogDto = actionWithItemLog.getLeft();
actionLogDto.setOperationCount(actionLogDto.getOperationCount() - 1);
actionLogDto.getLogItems().remove(itemLog);
loggingException(actionLogDto.getSyncAction(), log, itemLog, actionsLog, uid, ex);
} else {
loggingException(SynchronizationActionType.UNKNOWN, log, itemLog, actionsLog, uid, ex);
}
return true;
} finally {
config = synchronizationConfigService.save(config);
boolean existingItemLog = existItemLogInActions(actionsLog, itemLog);
actionsLog = saveActionLogs(actionsLog, log.getId());
//
if (!existingItemLog) {
addToItemLog(itemLog, MessageFormat.format("Missing action log for UID {0}!", uid));
initSyncActionLog(SynchronizationActionType.UNKNOWN, OperationResultType.ERROR, itemLog, log, actionsLog);
itemLog = syncItemLogService.save(itemLog);
}
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto 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.SysSyncActionLogDto 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);
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto in project CzechIdMng by bcvsolutions.
the class TreeSynchronizationExecutor method doUpdateEntity.
/**
* Fill data from IC attributes to entity (EAV and confidential storage too)
*
* @param account
* @param entityType
* @param uid
* @param icAttributes
* @param mappedAttributes
* @param log
* @param logItem
* @param actionLogs
*/
@Override
protected void doUpdateEntity(SynchronizationContext context) {
String uid = context.getUid();
SysSyncLogDto log = context.getLog();
SysSyncItemLogDto logItem = context.getLogItem();
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());
IdmTreeNodeDto treeNode = null;
if (entityId != null) {
treeNode = treeNodeService.get(entityId);
}
if (treeNode != null) {
// Update entity
treeNode = fillEntity(mappedAttributes, uid, icAttributes, treeNode, false, context);
treeNode = this.save(treeNode, true);
// Update extended attribute (entity must be persisted first)
updateExtendedAttributes(mappedAttributes, uid, icAttributes, treeNode, false, context);
// Update confidential attribute (entity must be persisted first)
updateConfidentialAttributes(mappedAttributes, uid, icAttributes, treeNode, false, context);
// TreeNode Updated
addToItemLog(logItem, MessageFormat.format("TreeNode with id {0} was updated", treeNode.getId()));
if (logItem != null) {
logItem.setDisplayName(treeNode.getName());
}
// Call provisioning for entity
this.callProvisioningForEntity(treeNode, context.getEntityType(), logItem);
return;
} else {
addToItemLog(logItem, "Tree - account relation (with ownership = true) was not found!");
initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.WARNING, logItem, log, actionLogs);
return;
}
}
Aggregations