use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto 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.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method doCreateLink.
/**
* Create account and relation on him
*
* @param callProvisioning
* @param dto
* @param context
*/
protected void doCreateLink(DTO dto, boolean callProvisioning, SynchronizationContext context) {
String uid = context.getUid();
SystemEntityType entityType = context.getEntityType();
SysSystemDto system = context.getSystem();
SysSyncItemLogDto logItem = context.getLogItem();
SysSystemEntityDto systemEntity = context.getSystemEntity();
String entityIdentification = dto.getId().toString();
if (dto instanceof Codeable) {
entityIdentification = ((Codeable) dto).getCode();
}
logItem.setDisplayName(entityIdentification);
// 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
String attributeUid = this.generateUID(context);
AccAccountDto account = doCreateIdmAccount(attributeUid, system);
if (systemEntity != null) {
// If SystemEntity for this account already exist, then we linked
// him to new account
account.setSystemEntity(systemEntity.getId());
}
account = this.applySpecificSettingsBeforeLink(account, dto, context);
if (account == null) {
// Identity account won't be created
addToItemLog(logItem, MessageFormat.format("Link between uid [{0}] and entity [{1}] will not be created due to specific settings of synchronization. " + "Processing of this item is finished.", uid, entityIdentification));
return;
}
account = accountService.save(account);
addToItemLog(logItem, MessageFormat.format("Account with uid [{0}] and id [{1}] was created", uid, account.getId()));
// Create new entity account relation
EntityAccountDto entityAccount = this.createEntityAccount(account, dto, context);
entityAccount = (EntityAccountDto) getEntityAccountService().save(entityAccount);
context.addAccount(account);
// Identity account Created
addToItemLog(logItem, MessageFormat.format("Entity account relation with id [{0}], between account [{1}] and entity [{2}] was created", entityAccount.getId(), uid, entityIdentification));
logItem.setType(entityAccount.getClass().getSimpleName());
logItem.setIdentification(entityAccount.getId().toString());
if (callProvisioning) {
if (this.isProvisioningImplemented(entityType, logItem)) {
// Call provisioning for this entity
callProvisioningForEntity(dto, entityType, logItem);
}
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto 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.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method exportEntity.
/**
* Start export item (entity) to target resource
*
* @param context
* @param uidAttribute
* @param entity
*/
protected void exportEntity(SynchronizationContext context, SysSystemAttributeMappingDto uidAttribute, AbstractDto entity) {
SystemEntityType entityType = context.getEntityType();
AbstractSysSyncConfigDto config = context.getConfig();
SysSyncLogDto log = context.getLog();
List<SysSyncActionLogDto> actionsLog = context.getActionLogs();
SysSystemDto system = context.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}] AccAccount [{1}] was found. Export for this entity ends (only entity without AccAccount can be exported)!", this.getDisplayNameForEntity(entity), accountId));
return;
}
String uid = systemAttributeMappingService.generateUid(entity, uidAttribute);
// Do export for one item (produces event)
// Start in new Transaction
//
context.addUid(uid).addConfig(//
config).addSystem(//
system).addEntityType(//
entityType).addEntityId(entity.getId()).addLog(//
log).addLogItem(//
itemLog).addActionLogs(//
actionsLog).addExportAction(true);
CoreEvent<SysSyncItemLogDto> event = new CoreEvent<>(SynchronizationEventType.START_ITEM, itemLog);
event.getProperties().put(SynchronizationService.WRAPPER_SYNC_ITEM, context);
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);
}
// Update (increased counter) and check state of sync (maybe was cancelled from
// sync or LRT)
updateAndCheckState(result, log);
} 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 {
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);
syncItemLogService.save(itemLog);
}
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.
the class DefaultSynchronizationService method resolveMissingEntitySituation.
@Override
public SysSyncItemLogDto resolveMissingEntitySituation(String uid, SystemEntityType entityType, List<IcAttribute> icAttributes, UUID configId, String actionType) {
Assert.notNull(uid, "Uid is required.");
Assert.notNull(entityType, "Entity type is required.");
Assert.notNull(icAttributes, "Connector attribues are required.");
Assert.notNull(configId, "Configuration identifier is required.");
Assert.notNull(actionType, "Action type is required.");
AbstractSysSyncConfigDto config = synchronizationConfigService.get(configId);
SysSystemMappingDto mapping = systemMappingService.get(config.getSystemMapping());
SysSchemaObjectClassDto sysSchemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
SysSystemDto system = DtoUtils.getEmbedded(sysSchemaObjectClassDto, SysSchemaObjectClass_.system);
SysSystemAttributeMappingFilter attributeHandlingFilter = new SysSystemAttributeMappingFilter();
attributeHandlingFilter.setSystemMappingId(mapping.getId());
List<SysSystemAttributeMappingDto> mappedAttributes = attributeHandlingService.find(attributeHandlingFilter, null).getContent();
SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
// Little workaround, we have only IcAttributes ... we create IcObject manually
IcConnectorObjectImpl icObject = new IcConnectorObjectImpl();
icObject.setAttributes(icAttributes);
icObject.setUidValue(uid);
SynchronizationContext context = new SynchronizationContext();
//
context.addUid(uid).addSystem(//
system).addConfig(//
config).addEntityType(//
entityType).addLogItem(//
itemLog).addMappedAttributes(//
mappedAttributes).addIcObject(//
icObject);
getSyncExecutor(entityType, configId).resolveMissingEntitySituation(SynchronizationMissingEntityActionType.valueOf(actionType), context);
return itemLog;
}
Aggregations