use of eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method initSyncActionLog.
/**
* Init sync action log
*
* @param actionType
* @param resultType
* @param logItem
* @param log
* @param actionLogs
*/
protected void initSyncActionLog(SynchronizationActionType actionType, OperationResultType resultType, SysSyncItemLogDto logItem, SysSyncLogDto log, List<SysSyncActionLogDto> actionLogs, boolean interateCount) {
if (logItem == null || actionLogs == null) {
// maybe)
return;
}
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 = null;
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.SysSyncActionLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor 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();
SysSystemMappingDto systemMapping = systemMappingService.get(config.getSystemMapping());
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(systemMapping.getObjectClass());
IcObjectClass objectClass = new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName());
// Load last token
Object lastToken = config.isReconciliation() ? null : config.getToken();
IcSyncToken lastIcToken = lastToken != null ? new IcSyncTokenImpl(lastToken) : null;
// 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 keys (used in reconciliation)
Set<String> systemAccountsList = new HashSet<>();
// TODO: Export is not fully implemented (FE, configuration and Groovy
// part missing)
boolean export = false;
longRunningTaskExecutor.setCounter(0L);
try {
log = synchronizationLogService.save(log);
List<SysSyncActionLogDto> actionsLog = new ArrayList<>();
// add logs to context
context.addLog(log).addActionLogs(actionsLog);
if (export) {
// Start exporting entities to resource
log.addToLog("Exporting entities to resource started...");
this.startExport(entityType, config, context.getMappedAttributes(), log, actionsLog);
} else if (config.isCustomFilter() || config.isReconciliation()) {
// Custom filter Sync
log.addToLog("Synchronization will use custom filter (not synchronization implemented in connector).");
AttributeMapping tokenAttribute = null;
if (config.getTokenAttribute() != null) {
tokenAttribute = systemAttributeMappingService.get(config.getTokenAttribute());
}
if (tokenAttribute == null && !config.isReconciliation()) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TOKEN_ATTRIBUTE_NOT_FOUND);
}
context.addTokenAttribute(tokenAttribute);
// Resolve filter for custom search
IcFilter filter = resolveSynchronizationFilter(config);
log.addToLog(MessageFormat.format("Start search with filter {0}.", filter != null ? filter : "NONE"));
connectorFacade.search(system.getConnectorInstance(), connectorConfig, objectClass, filter, new DefaultResultHandler(context, systemAccountsList));
} else {
// Inner Sync
log.addToLog("Synchronization will use inner connector synchronization implementation.");
DefalutSyncResultHandler syncResultsHandler = new DefalutSyncResultHandler(context, systemAccountsList);
connectorFacade.synchronization(system.getConnectorInstance(), connectorConfig, objectClass, lastIcToken, syncResultsHandler);
}
// We do reconciliation (find missing account)
if (config.isReconciliation() && log.isRunning()) {
startReconciliation(entityType, systemAccountsList, config, system, log, actionsLog);
}
// Sync is correctly ends if wasn't cancelled
if (log.isRunning()) {
log = syncCorrectlyEnded(log, context);
}
config = 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;
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method doUpdateEntity.
/**
* Fill data from IC attributes to entity (EAV and confidential storage too)
*
* @param account
* @param entityType
* @param uid
* @param icAttributes
* @param mappedAttributes
* @param log
* @param logItem
* @param actionLogs
*/
protected void doUpdateEntity(SynchronizationContext context) {
String uid = context.getUid();
SysSyncLogDto log = context.getLog();
SysSyncItemLogDto logItem = context.getLogItem();
List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
AccAccountDto account = context.getAccount();
List<IcAttribute> icAttributes = context.getIcObject().getAttributes();
UUID entityId = getEntityByAccount(account.getId());
DTO entity = null;
if (entityId != null) {
entity = this.getService().get(entityId);
}
if (entity != null) {
// Update entity
entity = fillEntity(mappedAttributes, uid, icAttributes, entity, false, context);
this.save(entity, true);
// Update extended attribute (entity must be persisted first)
updateExtendedAttributes(mappedAttributes, uid, icAttributes, entity, false, context);
// Update confidential attribute (entity must be persisted
// first)
updateConfidentialAttributes(mappedAttributes, uid, icAttributes, entity, false, context);
// Entity updated
addToItemLog(logItem, MessageFormat.format("Entity with id {0} was updated", entity.getId()));
if (logItem != null) {
logItem.setDisplayName(this.getDisplayNameForEntity(entity));
}
// Call provisioning for entity
this.callProvisioningForEntity(entity, context.getEntityType(), logItem);
return;
} else {
addToItemLog(logItem, "Entity-account relation (with ownership = true) was not found!");
initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.WARNING, logItem, log, actionLogs);
return;
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method resolveMissingEntitySituation.
/**
* Method for resolve missing entity situation for one item.
*/
@Override
public void resolveMissingEntitySituation(SynchronizationMissingEntityActionType actionType, SynchronizationContext context) {
String uid = context.getUid();
SystemEntityType entityType = context.getEntityType();
SysSystemDto system = context.getSystem();
SysSyncLogDto log = context.getLog();
SysSyncItemLogDto logItem = context.getLogItem();
List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
List<IcAttribute> icAttributes = context.getIcObject().getAttributes();
addToItemLog(logItem, "Account and entity doesn't exist (missing entity).");
switch(actionType) {
case IGNORE:
// Ignore we will do nothing
addToItemLog(logItem, "Missing entity action is IGNORE, we will do nothing.");
initSyncActionLog(SynchronizationActionType.MISSING_ENTITY, OperationResultType.IGNORE, logItem, log, actionLogs);
return;
case CREATE_ENTITY:
// 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);
// Create idm account
AccAccountDto account = doCreateIdmAccount(attributeUid, system);
// Find and set SystemEntity (must exist)
account.setSystemEntity(this.findSystemEntity(uid, system, entityType).getId());
account = accountService.save(account);
// Create new entity
doCreateEntity(entityType, mappedAttributes, logItem, uid, icAttributes, account, context);
initSyncActionLog(SynchronizationActionType.CREATE_ENTITY, OperationResultType.SUCCESS, logItem, log, actionLogs);
return;
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSyncActionLogService method save.
@Override
public SysSyncActionLogDto save(SysSyncActionLogDto dto, BasePermission... permission) {
Assert.notNull(dto);
//
if (!ObjectUtils.isEmpty(permission)) {
SysSyncActionLog persistEntity = null;
if (dto.getId() != null) {
persistEntity = this.getEntity(dto.getId());
if (persistEntity != null) {
// check access on previous entity - update is needed
checkAccess(persistEntity, IdmBasePermission.UPDATE);
}
}
// TODO: remove one checkAccess?
checkAccess(toEntity(dto, persistEntity), permission);
}
//
// save
SysSyncActionLogDto newDto = saveInternal(dto);
// iterate over all log items
for (SysSyncItemLogDto item : dto.getLogItems()) {
item.setSyncActionLog(newDto.getId());
item = syncItemLogService.save(item);
newDto.addLogItems(item);
}
return newDto;
}
Aggregations