use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method doCreateLink.
/**
* Create account and relation on him
*
* @param uid
* @param callProvisioning
* @param dto
* @param systemEntity
* @param entityType
* @param system
* @param logItem
*/
@SuppressWarnings("unchecked")
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();
// 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 = 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);
String entityIdentification = dto.getId().toString();
if (dto instanceof Codeable) {
entityIdentification = ((Codeable) dto).getCode();
}
// 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.setDisplayName(entityIdentification);
logItem.setType(entityAccount.getClass().getSimpleName());
logItem.setIdentification(entityAccount.getId().toString());
if (callProvisioning) {
// Call provisioning for this identity
callProvisioningForEntity(dto, entityType, logItem);
}
}
use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method startReconciliation.
/**
* Start reconciliation. Is call after synchronization. Main purpose is find and
* resolve missing accounts
*
* @param entityType
* @param systemAccountsMap
* @param config
* @param system
* @param log
* @param actionsLog
*/
protected void startReconciliation(SystemEntityType entityType, Set<String> allAccountsSet, AbstractSysSyncConfigDto config, SysSystemDto system, SysSyncLogDto log, List<SysSyncActionLogDto> actionsLog) {
if (!log.isRunning()) {
return;
}
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setSystemId(system.getId());
List<AccAccountDto> accounts = accountService.find(accountFilter, null).getContent();
for (AccAccountDto account : accounts) {
String uid = account.getRealUid();
if (!allAccountsSet.contains(uid)) {
SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
try {
// Default setting for log item
itemLog.setIdentification(uid);
itemLog.setDisplayName(uid);
itemLog.setType(entityType.getEntityType().getSimpleName());
// Do reconciliation for one item (produces event)
// Start in new Transaction
SynchronizationContext builder = new SynchronizationContext();
builder.addUid(uid).addType(IcSyncDeltaTypeEnum.DELETE).addConfig(config).addSystem(system).addEntityType(entityType).addAccount(account).addLog(log).addLogItem(itemLog).addActionLogs(actionsLog);
CoreEvent<SysSyncItemLogDto> event = new CoreEvent<SysSyncItemLogDto>(SynchronizationEventType.START_ITEM, itemLog);
event.getProperties().put(SynchronizationService.WRAPPER_SYNC_ITEM, builder);
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("Reconciliation - error for uid {0}", uid);
log.addToLog(message);
log.addToLog(Throwables.getStackTraceAsString(ex));
LOG.error(message, ex);
} finally {
config = 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);
itemLog = syncItemLogService.save(itemLog);
}
}
}
}
}
use of eu.bcvsolutions.idm.acc.dto.AccAccountDto 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.AccAccountDto 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.AccAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountService method getAccount.
@Override
public AccAccountDto getAccount(String uid, UUID systemId) {
Assert.notNull(uid, "UID cannot be null!");
Assert.notNull(systemId, "System ID cannot be null!");
AccAccountFilter filter = new AccAccountFilter();
filter.setUid(uid);
filter.setSystemId(systemId);
List<AccAccountDto> accounts = this.find(filter, null).getContent();
if (accounts.isEmpty()) {
return null;
}
return accounts.get(0);
}
Aggregations