use of eu.bcvsolutions.idm.acc.domain.SynchronizationActionType in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method resolveAccountNotExistSituation.
/**
* Resolve "Account doesn't exist in IDM" situation. Result can be UNLINKED or
* UNMATCHED situations.
*
* @param context
* @param systemEntity
* @param icAttributes
*/
protected void resolveAccountNotExistSituation(SynchronizationContext context, SysSystemEntityDto systemEntity, List<IcAttribute> icAttributes) {
Assert.notNull(context, "Context is required.");
AbstractSysSyncConfigDto config = context.getConfig();
SysSyncItemLogDto logItem = context.getLogItem();
addToItemLog(logItem, "Account doesn't exist in IdM");
DTO entity = findByCorrelationAttribute(systemAttributeMappingService.get(config.getCorrelationAttribute()), icAttributes, context);
if (entity != null) {
// Account not exist but, entity by correlation was
// found (UNLINKED)
context.addActionType(config.getUnlinkedAction().getAction());
SynchronizationSituationType situation = SynchronizationSituationType.UNLINKED;
if (StringUtils.hasLength(config.getUnlinkedActionWfKey())) {
SynchronizationUnlinkedActionType unlinkedActionType = config.getUnlinkedAction();
SynchronizationActionType action = unlinkedActionType.getAction();
// We will start specific workflow
startWorkflow(config.getUnlinkedActionWfKey(), situation, action, entity, context);
} else {
context.addEntityId(entity.getId()).addSystemEntity(systemEntity);
resolveUnlinkedSituation(config.getUnlinkedAction(), context);
}
} else {
// Account not exist and entity too (UNMATCHED)
context.addActionType(config.getMissingEntityAction().getAction());
SynchronizationSituationType situation = SynchronizationSituationType.MISSING_ENTITY;
if (StringUtils.hasLength(config.getMissingEntityActionWfKey())) {
SynchronizationMissingEntityActionType missingEntityAction = config.getMissingEntityAction();
SynchronizationActionType action = missingEntityAction.getAction();
// We will start specific workflow
startWorkflow(config.getMissingEntityActionWfKey(), situation, action, entity, context);
} else {
resolveMissingEntitySituation(config.getMissingEntityAction(), context);
}
}
}
use of eu.bcvsolutions.idm.acc.domain.SynchronizationActionType in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method initSyncActionLog.
/**
* Init sync action log
*
* @param actionType
* @param resultType
* @param logItem
* @param log
* @param actionLogs
* @param interateCount
*/
protected void initSyncActionLog(SynchronizationActionType actionType, OperationResultType resultType, SysSyncItemLogDto logItem, SysSyncLogDto log, List<SysSyncActionLogDto> actionLogs, boolean interateCount) {
if (logItem == null || actionLogs == null) {
// maybe)
return;
}
// WARNING, then have priority
if (this.existItemLogInActions(actionLogs, logItem)) {
if (OperationResultType.ERROR != resultType && OperationResultType.WARNING != resultType) {
return;
}
Pair<SysSyncActionLogDto, SysSyncItemLogDto> actionWithItemLog = getActionLogThatContains(actionLogs, logItem);
if (OperationResultType.ERROR == resultType && OperationResultType.ERROR == actionWithItemLog.getLeft().getOperationResult()) {
return;
}
if (OperationResultType.WARNING == resultType && OperationResultType.WARNING == actionWithItemLog.getLeft().getOperationResult()) {
return;
}
}
SysSyncActionLogDto actionLog;
Optional<SysSyncActionLogDto> optionalActionLog = actionLogs.stream().filter(al -> {
return actionType == al.getSyncAction() && resultType == al.getOperationResult();
}).findFirst();
if (optionalActionLog.isPresent()) {
actionLog = optionalActionLog.get();
} else {
actionLog = new SysSyncActionLogDto();
actionLog.setOperationResult(resultType);
actionLog.setSyncAction(actionType);
actionLog.setSyncLog(log.getId());
actionLogs.add(actionLog);
}
actionLog.addLogItems(logItem);
if (interateCount) {
actionLog.setOperationCount(actionLog.getOperationCount() + 1);
addToItemLog(logItem, MessageFormat.format("Operation count for [{0}] is [{1}]", actionLog.getSyncAction(), actionLog.getOperationCount()));
}
}
use of eu.bcvsolutions.idm.acc.domain.SynchronizationActionType in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method doItemSynchronization.
@Override
public boolean doItemSynchronization(SynchronizationContext context) {
Assert.notNull(context, "Context is required.");
String uid = context.getUid();
IcConnectorObject icObject = context.getIcObject();
IcSyncDeltaTypeEnum type = context.getType();
AbstractSysSyncConfigDto config = context.getConfig();
SysSystemDto system = context.getSystem();
SystemEntityType entityType = context.getEntityType();
AccAccountDto account = context.getAccount();
SysSyncLogDto log = context.getLog();
SysSyncItemLogDto logItem = context.getLogItem();
List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
// Set default unknown action type
context.addActionType(SynchronizationActionType.UNKNOWN);
// If differential sync is disabled, then is every entity marks as different.
context.setIsEntityDifferent(!config.isDifferentialSync());
try {
// Find system entity for uid
SysSystemEntityDto systemEntity = findSystemEntity(uid, system, entityType);
context.addSystemEntity(systemEntity);
// Find acc account for uid or system entity
if (account == null) {
account = findAccount(context);
if (systemEntity == null) {
addToItemLog(logItem, "SystemEntity for this uid doesn't exist. We will create it.");
systemEntity = createSystemEntity(uid, entityType, system);
}
}
context.addSystemEntity(systemEntity).addAccount(account);
if (IcSyncDeltaTypeEnum.CREATE == type || IcSyncDeltaTypeEnum.UPDATE == type || IcSyncDeltaTypeEnum.CREATE_OR_UPDATE == type) {
// Update or create
Assert.notNull(icObject, "Connector object is required.");
List<IcAttribute> icAttributes = icObject.getAttributes();
if (account == null) {
// Account doesn't exist in IDM
systemEntity = removeSystemEntityWishIfPossible(systemEntity, false, context);
context.addSystemEntity(systemEntity);
resolveAccountNotExistSituation(context, systemEntity, icAttributes);
} else {
// Account exist in IdM (LINKED)
SynchronizationLinkedActionType linkedAction = config.getLinkedAction();
SynchronizationActionType action = linkedAction.getAction();
context.addActionType(action);
SynchronizationSituationType situation = SynchronizationSituationType.LINKED;
// configured
if (linkedAction == SynchronizationLinkedActionType.UPDATE_ENTITY || linkedAction == SynchronizationLinkedActionType.UPDATE_ACCOUNT) {
systemEntity = removeSystemEntityWishIfPossible(systemEntity, true, context);
context.addSystemEntity(systemEntity);
}
if (StringUtils.hasLength(config.getLinkedActionWfKey())) {
// We will start specific workflow
startWorkflow(config.getLinkedActionWfKey(), situation, action, null, context);
} else {
resolveLinkedSituation(config.getLinkedAction(), context);
}
addToItemLog(logItem, "Account exist in IdM (LINKED) - ended");
}
} else if (IcSyncDeltaTypeEnum.DELETE == type) {
// Missing account situation, can be call from connector
// (support delete account event) and from reconciliation
context.addActionType(config.getMissingAccountAction().getAction());
SynchronizationSituationType situation = SynchronizationSituationType.MISSING_ACCOUNT;
if (StringUtils.hasLength(config.getMissingAccountActionWfKey())) {
ReconciliationMissingAccountActionType missingAccountActionType = config.getMissingAccountAction();
SynchronizationActionType action = missingAccountActionType.getAction();
// We will start specific workflow
startWorkflow(config.getMissingAccountActionWfKey(), situation, action, null, context);
} else {
// Resolve missing account situation for one item
this.resolveMissingAccountSituation(config.getMissingAccountAction(), context);
}
} else if (context.isExportAction()) {
// Export situation - create account to system
this.resolveUnlinkedSituation(SynchronizationUnlinkedActionType.LINK_AND_UPDATE_ACCOUNT, context);
}
// Call hard hibernate session flush and clear
if (getHibernateSession().isOpen()) {
getHibernateSession().flush();
getHibernateSession().clear();
}
return true;
} catch (Exception e) {
loggingException(context.getActionType(), log, logItem, actionLogs, uid, e);
throw e;
}
}
use of eu.bcvsolutions.idm.acc.domain.SynchronizationActionType in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method checkSyncLog.
private SysSyncLogDto checkSyncLog(AbstractSysSyncConfigDto config, SynchronizationActionType actionType, int count) {
SysSyncLogFilter logFilter = new SysSyncLogFilter();
logFilter.setSynchronizationConfigId(config.getId());
List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
Assert.assertEquals(1, logs.size());
SysSyncLogDto log = logs.get(0);
SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
actionLogFilter.setSynchronizationLogId(log.getId());
List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
List<SysSyncActionLogDto> actionLogs = actions.stream().filter(action -> {
return actionType == action.getSyncAction();
}).collect(Collectors.toList());
List<SysSyncItemLogDto> result = new ArrayList<>();
actionLogs.forEach(actionLog -> {
SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
itemLogFilter.setSyncActionLogId(actionLog.getId());
List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
result.addAll(items);
});
Assert.assertEquals(count, result.size());
return log;
}
Aggregations