use of eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method checkSyncLog.
private SysSyncLogDto checkSyncLog(AbstractSysSyncConfigDto config, SynchronizationActionType actionType, int count, OperationResultType resultType) {
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();
SysSyncActionLogDto actionLog = actions.stream().filter(action -> {
return actionType == action.getSyncAction();
}).findFirst().get();
Assert.assertEquals(resultType, actionLog.getOperationResult());
SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
itemLogFilter.setSyncActionLogId(actionLog.getId());
List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
Assert.assertEquals(count, items.size());
return log;
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method handleIcObject.
/**
* Handle IC connector object
*
* @param tokenAttribute
* @param itemContext
* @return
*/
protected boolean handleIcObject(SynchronizationContext itemContext) {
Assert.notNull(itemContext);
String uid = itemContext.getUid();
IcConnectorObject icObject = itemContext.getIcObject();
AbstractSysSyncConfigDto config = itemContext.getConfig();
SysSyncLogDto log = itemContext.getLog();
List<SysSyncActionLogDto> actionLogs = itemContext.getActionLogs();
AttributeMapping tokenAttribute = itemContext.getTokenAttribute();
SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
// Synchronization by custom filter not supported DELETE
// event
IcSyncDeltaTypeEnum type = IcSyncDeltaTypeEnum.CREATE_OR_UPDATE;
itemContext.addLogItem(itemLog).addType(type);
// Find token by token attribute
// For Reconciliation can be token attribute null
Object tokenObj = null;
if (tokenAttribute != null) {
tokenObj = getValueByMappedAttribute(tokenAttribute, icObject.getAttributes(), itemContext);
}
// Token is saved in Sync as String, therefore we transform token (from
// IcObject) to String too.
String token = tokenObj != null ? tokenObj.toString() : null;
if (token != null && config.getToken() != null && token.compareTo(config.getToken()) <= -1) {
token = config.getToken();
}
// Save token
log.setToken(token);
config.setToken(token);
boolean result = startItemSynchronization(itemContext);
// We reload log (maybe was synchronization canceled)
longRunningTaskExecutor.increaseCounter();
log.setRunning(synchronizationLogService.get(log.getId()).isRunning());
if (!log.isRunning()) {
result = false;
}
if (!result) {
log.setRunning(false);
log.addToLog(MessageFormat.format("Synchronization canceled during resolve UID [{0}]", uid));
addToItemLog(itemLog, "Canceled!");
initSyncActionLog(SynchronizationActionType.IGNORE, OperationResultType.WARNING, itemLog, log, actionLogs);
}
return result;
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method exportEntity.
/**
* Start export item (entity) to target resource
*
* @param itemBuilder
* @param uidAttribute
* @param entity
*/
protected void exportEntity(SynchronizationContext itemBuilder, SysSystemAttributeMappingDto uidAttribute, AbstractDto entity) {
SystemEntityType entityType = itemBuilder.getEntityType();
AbstractSysSyncConfigDto config = itemBuilder.getConfig();
SysSyncLogDto log = itemBuilder.getLog();
List<SysSyncActionLogDto> actionsLog = itemBuilder.getActionLogs();
SysSystemDto system = itemBuilder.getSystem();
SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
try {
// Default setting for log item
itemLog.setIdentification(entity.getId().toString());
itemLog.setDisplayName(this.getDisplayNameForEntity(entity));
itemLog.setType(entityType.getEntityType().getSimpleName());
itemLog.addToLog(MessageFormat.format("Start export for entity [{0}].", this.getDisplayNameForEntity(entity)));
UUID accountId = this.getAccountByEntity(entity.getId(), system.getId());
if (accountId != null) {
initSyncActionLog(SynchronizationActionType.CREATE_ACCOUNT, OperationResultType.IGNORE, itemLog, log, actionsLog);
itemLog.addToLog(MessageFormat.format("For entity [{0}] was found AccAccount [{1}]. Export for this entity ends (only entity without AccAccount can be export)!", this.getDisplayNameForEntity(entity), accountId));
return;
}
String uid = systemAttributeMappingService.generateUid(entity, uidAttribute);
// Do export for one item (produces event)
// Start in new Transaction
//
itemBuilder.addUid(uid).addConfig(//
config).addSystem(//
system).addEntityType(//
entityType).addEntityId(entity.getId()).addLog(//
log).addLogItem(//
itemLog).addActionLogs(//
actionsLog).addExportAction(true);
CoreEvent<SysSyncItemLogDto> event = new CoreEvent<SysSyncItemLogDto>(SynchronizationEventType.START_ITEM, itemLog);
event.getProperties().put(SynchronizationService.WRAPPER_SYNC_ITEM, itemBuilder);
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);
}
// We reload log (maybe was synchronization canceled)
log.setRunning(synchronizationLogService.get(log.getId()).isRunning());
if (!log.isRunning()) {
result = false;
}
if (!result) {
log.setRunning(false);
log.addToLog(MessageFormat.format("Synchronization canceled during resolve UID [{0}]", uid));
addToItemLog(itemLog, "Canceled!");
initSyncActionLog(SynchronizationActionType.UNKNOWN, OperationResultType.WARNING, itemLog, log, actionsLog);
}
} catch (Exception ex) {
String message = MessageFormat.format("Export - error for entity {0}", entity.getId());
log.addToLog(message);
log.addToLog(Throwables.getStackTraceAsString(ex));
LOG.error(message, ex);
} finally {
config = synchronizationConfigService.save(config);
boolean existingItemLog = existItemLogInActions(actionsLog, itemLog);
actionsLog = (List<SysSyncActionLogDto>) syncActionLogService.saveAll(actionsLog);
//
if (!existingItemLog) {
addToItemLog(itemLog, MessageFormat.format("Missing action log for entity {0}!", entity.getId()));
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 AbstractSynchronizationExecutor method doItemSynchronization.
@Override
public boolean doItemSynchronization(SynchronizationContext context) {
Assert.notNull(context);
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);
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);
List<IcAttribute> icAttributes = icObject.getAttributes();
if (account == null) {
// Account doesn't exist in IDM
resolveAccountNotExistSituation(context, systemEntity, icAttributes);
} else {
// Account exist in IdM (LINKED)
context.addActionType(config.getLinkedAction().getAction());
SynchronizationSituationType situation = SynchronizationSituationType.LINKED;
if (StringUtils.hasLength(config.getLinkedActionWfKey())) {
SynchronizationLinkedActionType linkedAction = config.getLinkedAction();
SynchronizationActionType action = linkedAction.getAction();
// 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.dto.SysSyncActionLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method resolveLinkedSituation.
/**
* Method for resolve linked situation for one item.
*/
@Override
public void resolveLinkedSituation(SynchronizationLinkedActionType 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, MessageFormat.format("IdM Account ({0}) exists in IDM (LINKED)", account.getUid()));
addToItemLog(logItem, MessageFormat.format("Linked action is {0}", action));
switch(action) {
case IGNORE:
// Linked action is IGNORE. We will do nothing
initSyncActionLog(SynchronizationActionType.LINKED, OperationResultType.IGNORE, logItem, log, actionLogs);
return;
case UNLINK:
// Linked action is UNLINK
updateAccountUid(context);
doUnlink(account, false, log, logItem, actionLogs);
initSyncActionLog(SynchronizationActionType.UNLINK, OperationResultType.SUCCESS, logItem, log, actionLogs);
return;
case UNLINK_AND_REMOVE_ROLE:
// Linked action is UNLINK_AND_REMOVE_ROLE
updateAccountUid(context);
doUnlink(account, true, log, logItem, actionLogs);
initSyncActionLog(SynchronizationActionType.UNLINK, OperationResultType.SUCCESS, logItem, log, actionLogs);
return;
case UPDATE_ENTITY:
// Linked action is UPDATE_ENTITY
updateAccountUid(context);
doUpdateEntity(context);
initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.SUCCESS, logItem, log, actionLogs);
return;
case UPDATE_ACCOUNT:
// Linked action is UPDATE_ACCOUNT
updateAccountUid(context);
doUpdateAccount(account, entityType, log, logItem, actionLogs);
initSyncActionLog(SynchronizationActionType.UPDATE_ACCOUNT, OperationResultType.SUCCESS, logItem, log, actionLogs);
return;
default:
break;
}
}
Aggregations