use of eu.bcvsolutions.idm.acc.domain.SystemEntityType 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 situation
* @param action
* @param dto
*/
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() != null ? context.getIcObject().getAttributes() : null);
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());
variables.put(SynchronizationService.WF_VARIABLE_KEY_SYNC_CONFIG_ID, config.getId());
variables.put(SynchronizationService.WF_VARIABLE_KEY_SYSTEM_ID, context.getSystem().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 != null && 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);
// We don't wont history for workflow executed in synchronization!
processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
addToItemLog(logItem, MessageFormat.format("Workflow history for process instance [{0}] was deleted.", processInstance.getId()));
} else {
// If workflow not ended, then the history will be not deleted!
addToItemLog(logItem, MessageFormat.format("Workflow (with id [{0}]) for missing entity situation not ended (will be ended asynchronously).", processInstance != null ? processInstance.getId() : null));
initSyncActionLog(situation.getAction(), OperationResultType.WF, logItem, log, actionLogs);
}
}
use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method resolveMissingAccountSituation.
/**
* Method for resolve missing account situation for one item.
*
* @param action
* @param context
*/
@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);
}
}
use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method findByCorrelationAttribute.
/**
* Find entity by correlation attribute
*
* @param attribute
* @param icAttributes
* @param context
* @return
*/
@SuppressWarnings("unchecked")
protected DTO findByCorrelationAttribute(AttributeMapping attribute, List<IcAttribute> icAttributes, SynchronizationContext context) {
Assert.notNull(attribute, "Attribute is required.");
Assert.notNull(icAttributes, "Connector attribues are required.");
Object value = getValueByMappedAttribute(attribute, icAttributes, context);
if (value == null) {
return null;
}
if (attribute.isEntityAttribute()) {
return findByAttribute(attribute.getIdmPropertyName(), value.toString(), context);
} else if (attribute.isExtendedAttribute()) {
try {
Serializable serializableValue = Serializable.class.cast(value);
SystemEntityType entityType = context.getEntityType();
Assert.notNull(entityType, "Entity type is required!");
List<? extends BaseDto> entities = formService.findOwners(entityType.getExtendedAttributeOwnerType(), attribute.getIdmPropertyName(), serializableValue, null).getContent();
if (CollectionUtils.isEmpty(entities)) {
return null;
}
if (entities.size() > 1) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_CORRELATION_TO_MANY_RESULTS, ImmutableMap.of("correlationAttribute", attribute.getName(), "value", value));
}
if (entities.size() == 1) {
return (DTO) entities.get(0);
}
} catch (ClassCastException e) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_CORRELATION_BAD_VALUE, ImmutableMap.of("value", value), e);
}
}
return null;
}
use of eu.bcvsolutions.idm.acc.domain.SystemEntityType 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 itemContext
* @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<>(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 {
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);
syncItemLogService.save(itemLog);
}
}
}
use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountService method toDto.
@Override
protected AccAccountDto toDto(AccAccount entity, AccAccountDto dto) {
AccAccountDto newDto = super.toDto(entity, dto);
// if dto exists add real uid
if (newDto != null) {
if (newDto.getSystemEntity() != null) {
SysSystemEntityDto systemEntity = DtoUtils.getEmbedded(newDto, AccAccount_.systemEntity);
newDto.setRealUid(systemEntity.getUid());
} else {
// If system entity do not exist, then return uid from account.
newDto.setRealUid(newDto.getUid());
}
// Load and set target entity. For loading a target entity is using sync
// executor.
SystemEntityType entityType = newDto.getEntityType();
if (entityType != null && entityType.isSupportsSync()) {
SynchronizationEntityExecutor executor = this.getSyncExecutor(entityType);
UUID targetEntity = executor.getEntityByAccount(newDto.getId());
newDto.setTargetEntityType(entityType.getEntityType().getName());
newDto.setTargetEntityId(targetEntity);
}
}
return newDto;
}
Aggregations