use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningOperationService method toPredicates.
@Override
protected List<Predicate> toPredicates(Root<SysProvisioningOperation> root, CriteriaQuery<?> query, CriteriaBuilder builder, SysProvisioningOperationFilter filter) {
List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
// quick - "fulltext"
if (StringUtils.isNotEmpty(filter.getText())) {
throw new ResultCodeException(CoreResultCode.BAD_FILTER, "Filter by text is not supported.");
}
// System Id
UUID systemId = filter.getSystemId();
if (systemId != null) {
predicates.add(builder.equal(root.get(SysProvisioningOperation_.system).get(SysSystem_.id), systemId));
}
// From
ZonedDateTime from = filter.getFrom();
if (from != null) {
predicates.add(builder.greaterThanOrEqualTo(root.get(SysProvisioningOperation_.created), from));
}
// Till
ZonedDateTime till = filter.getTill();
if (till != null) {
predicates.add(builder.lessThanOrEqualTo(root.get(SysProvisioningOperation_.created), till));
}
// Operation type
ProvisioningEventType operationType = filter.getOperationType();
if (operationType != null) {
predicates.add(builder.equal(root.get(SysProvisioningOperation_.operationType), operationType));
}
// Entity type
SystemEntityType entityType = filter.getEntityType();
if (entityType != null) {
predicates.add(builder.equal(root.get(SysProvisioningOperation_.entityType), entityType));
}
// Entity identifier
UUID entityIdentifier = filter.getEntityIdentifier();
if (entityIdentifier != null) {
predicates.add(builder.equal(root.get(SysProvisioningOperation_.entityIdentifier), entityIdentifier));
}
// System entity
UUID systemEntity = filter.getSystemEntity();
if (systemEntity != null) {
predicates.add(builder.equal(root.get(SysProvisioningOperation_.systemEntity).get(SysSystemEntity_.id), systemEntity));
}
// System entity UID
String systemEntityUid = filter.getSystemEntityUid();
if (StringUtils.isNotEmpty(systemEntityUid)) {
predicates.add(builder.equal(root.get(SysProvisioningOperation_.systemEntity).get(SysSystemEntity_.uid), systemEntityUid));
}
// Operation result and his state
OperationState resultState = filter.getResultState();
if (resultState != null) {
predicates.add(builder.equal(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_STATE), resultState));
}
// Is not in this operation state
OperationState notInState = filter.getNotInState();
if (notInState != null) {
predicates.add(builder.notEqual(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_STATE), notInState));
}
// Batch ID
UUID batchId = filter.getBatchId();
if (batchId != null) {
predicates.add(builder.equal(root.get(SysProvisioningOperation_.batch).get(SysProvisioningBatch_.id), batchId));
}
// Role-request ID
UUID roleRequestId = filter.getRoleRequestId();
if (roleRequestId != null) {
predicates.add(builder.equal(root.get(SysProvisioningOperation_.roleRequestId), roleRequestId));
}
// updated attributes
List<String> attributeUpdated = filter.getAttributeUpdated();
if (!CollectionUtils.isEmpty(attributeUpdated)) {
Subquery<SysProvisioningAttribute> subquery = query.subquery(SysProvisioningAttribute.class);
Root<SysProvisioningAttribute> subRoot = subquery.from(SysProvisioningAttribute.class);
subquery.select(subRoot);
subquery.where(builder.and(// correlation attr
builder.equal(subRoot.get(SysProvisioningAttribute_.provisioningId), root.get(SysProvisioningArchive_.id)), subRoot.get(SysProvisioningAttribute_.name).in(attributeUpdated), builder.isFalse(subRoot.get(SysProvisioningAttribute_.removed))));
predicates.add(builder.exists(subquery));
}
// removed attributes
List<String> attributeRemoved = filter.getAttributeRemoved();
if (!CollectionUtils.isEmpty(attributeRemoved)) {
Subquery<SysProvisioningAttribute> subquery = query.subquery(SysProvisioningAttribute.class);
Root<SysProvisioningAttribute> subRoot = subquery.from(SysProvisioningAttribute.class);
subquery.select(subRoot);
subquery.where(builder.and(// correlation attr
builder.equal(subRoot.get(SysProvisioningAttribute_.provisioningId), root.get(SysProvisioningArchive_.id)), subRoot.get(SysProvisioningAttribute_.name).in(attributeRemoved), builder.isTrue(subRoot.get(SysProvisioningAttribute_.removed))));
predicates.add(builder.exists(subquery));
}
// empty provisioning
Boolean emptyProvisioning = filter.getEmptyProvisioning();
EmptyProvisioningType emptyProvisioningType = filter.getEmptyProvisioningType();
if (emptyProvisioning != null || emptyProvisioningType != null) {
if (BooleanUtils.isTrue(emptyProvisioning) && emptyProvisioningType != null && emptyProvisioningType != EmptyProvisioningType.EMPTY) {
// empty + not empty => nothing
predicates.add(builder.disjunction());
} else if (BooleanUtils.isFalse(emptyProvisioning) && emptyProvisioningType != null && emptyProvisioningType != EmptyProvisioningType.NON_EMPTY) {
// not empty + filled somehow => nothing
predicates.add(builder.disjunction());
} else if (emptyProvisioningType == null) {
// fill by boolean value
emptyProvisioningType = emptyProvisioning ? EmptyProvisioningType.EMPTY : EmptyProvisioningType.NON_EMPTY;
}
Subquery<SysProvisioningAttribute> subquery = query.subquery(SysProvisioningAttribute.class);
Root<SysProvisioningAttribute> subRoot = subquery.from(SysProvisioningAttribute.class);
subquery.select(subRoot);
subquery.where(// correlation attr)
builder.and(builder.equal(subRoot.get(SysProvisioningAttribute_.provisioningId), root.get(SysProvisioningArchive_.id))));
//
// has attributes
Predicate provisioningPredicate = builder.exists(subquery);
Predicate notProcessedPredicate = builder.or(// Not executed operations (already in queue, created) are not wanted - attributes are not computed in this phase.
builder.equal(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_STATE), OperationState.CREATED), builder.equal(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_STATE), OperationState.RUNNING), builder.equal(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_STATE), OperationState.BLOCKED), builder.and(builder.equal(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_STATE), OperationState.NOT_EXECUTED), // only readOnly has attributes evaluated
builder.or(builder.isNull(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_CODE)), builder.notEqual(root.get(SysProvisioningOperation_.result).get(OperationResultDto.PROPERTY_CODE), AccResultCode.PROVISIONING_SYSTEM_READONLY.name()))));
switch(emptyProvisioningType) {
case EMPTY:
{
provisioningPredicate = builder.and(// empty
builder.not(provisioningPredicate), // delete operations are not considered as empty
builder.notEqual(root.get(SysProvisioningOperation_.operationType), ProvisioningEventType.DELETE), builder.not(notProcessedPredicate));
break;
}
case NON_EMPTY:
{
// delete operations are not considered as empty or filled => show all time
provisioningPredicate = builder.and(builder.or(provisioningPredicate, builder.equal(root.get(SysProvisioningOperation_.operationType), ProvisioningEventType.DELETE)), builder.not(notProcessedPredicate));
break;
}
case NOT_PROCESSED:
{
provisioningPredicate = notProcessedPredicate;
break;
}
default:
{
throw new UnsupportedOperationException(String.format("Empty profisioning type [%s] is not supported by filter predicates.", emptyProvisioningType));
}
}
predicates.add(provisioningPredicate);
}
return predicates;
}
use of eu.bcvsolutions.idm.acc.domain.SystemEntityType 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.domain.SystemEntityType 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.domain.SystemEntityType 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.domain.SystemEntityType in project CzechIdMng by bcvsolutions.
the class DefaultSynchronizationService method startSynchronization.
/**
* Prepare and execute sync executor
*/
@Override
public void startSynchronization(AbstractSysSyncConfigDto config, AbstractSchedulableTaskExecutor<Boolean> longRunningTaskExecutor) {
Assert.notNull(config, "Sync configuration is required!");
Assert.notNull(config.getId(), "Id of sync configuration is required!");
if (synchronizationConfigService.isRunning(config)) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IS_RUNNING, ImmutableMap.of("name", config.getName()));
}
UUID syncConfigId = config.getId();
SysSystemMappingDto mapping = systemMappingService.get(config.getSystemMapping());
Assert.notNull(mapping, "Mapping is required.");
SystemEntityType entityType = mapping.getEntityType();
SynchronizationEntityExecutor executor = getSyncExecutor(entityType, syncConfigId);
executor.setLongRunningTaskExecutor(longRunningTaskExecutor);
executor.process(config.getId());
}
Aggregations