use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method resolveMissingAccountSituation.
/**
* Method for resolve missing account situation for one item.
*/
@Override
public void resolveMissingAccountSituation(ReconciliationMissingAccountActionType action, SynchronizationContext context) {
SystemEntityType entityType = context.getEntityType();
SysSyncLogDto log = context.getLog();
SysSyncItemLogDto logItem = context.getLogItem();
List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
AccAccountDto account = context.getAccount();
addToItemLog(logItem, "Account doesn't exist on target system, but account in IdM was found (missing account).");
addToItemLog(logItem, MessageFormat.format("Missing account action is {0}", action));
switch(action) {
case IGNORE:
// Ignore we will do nothing
initSyncActionLog(SynchronizationActionType.MISSING_ACCOUNT, OperationResultType.IGNORE, logItem, log, actionLogs);
return;
case CREATE_ACCOUNT:
doUpdateAccount(account, entityType, log, logItem, actionLogs);
initSyncActionLog(SynchronizationActionType.CREATE_ACCOUNT, OperationResultType.SUCCESS, logItem, log, actionLogs);
return;
case DELETE_ENTITY:
doDeleteEntity(account, entityType, log, logItem, actionLogs);
initSyncActionLog(SynchronizationActionType.DELETE_ENTITY, OperationResultType.SUCCESS, logItem, log, actionLogs);
return;
case UNLINK:
doUnlink(account, false, log, logItem, actionLogs);
initSyncActionLog(SynchronizationActionType.UNLINK, OperationResultType.SUCCESS, logItem, log, actionLogs);
return;
case UNLINK_AND_REMOVE_ROLE:
doUnlink(account, true, log, logItem, actionLogs);
initSyncActionLog(SynchronizationActionType.UNLINK_AND_REMOVE_ROLE, OperationResultType.SUCCESS, logItem, log, actionLogs);
return;
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method startWorkflow.
/**
* Start workflow process by wfDefinitionKey. Create input variables and put
* them to the process. If log variable is present after the process started,
* then add the log to the synchronization log.
*
* @param wfDefinitionKey
* @param uid
* @param situation
* @param action
* @param icAttributes
* @param dto
* @param account
* @param entityType
* @param config
* @param log
* @param logItem
* @param actionLogs
*/
private void startWorkflow(String wfDefinitionKey, SynchronizationSituationType situation, SynchronizationActionType action, DTO dto, SynchronizationContext context) {
SystemEntityType entityType = context.getEntityType();
SysSyncLogDto log = context.getLog();
SysSyncItemLogDto logItem = context.getLogItem();
List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
AccAccountDto account = context.getAccount();
String uid = context.getUid();
AbstractSysSyncConfigDto config = context.getConfig();
addToItemLog(logItem, MessageFormat.format("Workflow for {0} situation was found. We will start it.", situation));
Map<String, Object> variables = new HashMap<>();
variables.put(SynchronizationService.WF_VARIABLE_KEY_UID, uid);
variables.put(SynchronizationService.WF_VARIABLE_KEY_ENTITY_TYPE, entityType);
variables.put(SynchronizationService.WF_VARIABLE_KEY_SYNC_SITUATION, situation.name());
variables.put(SynchronizationService.WF_VARIABLE_KEY_IC_ATTRIBUTES, context.getIcObject().getAttributes());
variables.put(SynchronizationService.WF_VARIABLE_KEY_ACTION_TYPE, action.name());
variables.put(SynchronizationService.WF_VARIABLE_KEY_ENTITY_ID, dto != null ? dto.getId() : null);
variables.put(SynchronizationService.WF_VARIABLE_KEY_ACC_ACCOUNT_ID, account != null ? account.getId() : null);
variables.put(SynchronizationService.WF_VARIABLE_KEY_SYNC_CONFIG_ID, config.getId());
ProcessInstance processInstance = workflowProcessInstanceService.startProcess(wfDefinitionKey, SysSyncConfig.class.getSimpleName(), uid, config.getId().toString(), variables);
if (processInstance instanceof VariableScope) {
Object logItemObj = ((VariableScope) processInstance).getVariable(SynchronizationService.WF_VARIABLE_KEY_LOG_ITEM);
if (logItemObj instanceof String) {
addToItemLog(logItem, (String) logItemObj);
}
}
if (processInstance.isEnded()) {
addToItemLog(logItem, MessageFormat.format("Workflow (with id {0}) for missing entity situation ended.", processInstance.getId()));
initSyncActionLog(situation.getAction(), OperationResultType.WF, logItem, log, actionLogs);
} else {
addToItemLog(logItem, MessageFormat.format("Workflow (with id {0}) for missing entity situation not ended (will be ended asynchronously).", processInstance.getId()));
initSyncActionLog(situation.getAction(), OperationResultType.WF, logItem, log, actionLogs);
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto 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.SysSyncLogDto 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.SysSyncLogDto 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;
}
Aggregations