use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method getValueByMappedAttribute.
@Override
protected Object getValueByMappedAttribute(AttributeMapping attribute, List<IcAttribute> icAttributes, SynchronizationContext context) {
Object transformedValue = super.getValueByMappedAttribute(attribute, icAttributes, context);
// Transform contract state enumeration from string
if (CONTRACT_STATE_FIELD.equals(attribute.getIdmPropertyName()) && transformedValue instanceof String && attribute.isEntityAttribute()) {
return ContractState.valueOf((String) transformedValue);
}
// Transform contract guarantees
if (CONTRACT_GUARANTEES_FIELD.equals(attribute.getIdmPropertyName()) && attribute.isEntityAttribute()) {
return transformGuarantees(context, transformedValue);
}
// Transform work position (tree node)
if (CONTRACT_WORK_POSITION_FIELD.equals(attribute.getIdmPropertyName()) && attribute.isEntityAttribute()) {
if (transformedValue != null) {
IdmTreeNodeDto workposition = this.findTreeNode(transformedValue, context);
if (workposition != null) {
return workposition.getId();
}
return null;
} else {
if (getConfig(context).getDefaultTreeNode() != null) {
UUID defaultNode = ((SysSyncContractConfigDto) context.getConfig()).getDefaultTreeNode();
IdmTreeNodeDto node = (IdmTreeNodeDto) lookupService.lookupDto(IdmTreeNodeDto.class, defaultNode);
if (node != null) {
context.getLogItem().addToLog(MessageFormat.format("Warning! - None workposition was defined for this realtion, we use default workposition [{0}]!", node.getCode()));
return node.getId();
}
}
}
}
// Transform contract owner
if (transformedValue != null && CONTRACT_IDENTITY_FIELD.equals(attribute.getIdmPropertyName()) && attribute.isEntityAttribute()) {
context.getLogItem().addToLog(MessageFormat.format("Finding contract owner [{0}].", transformedValue));
IdmIdentityDto identity = this.findIdentity(transformedValue, context);
if (identity == null) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_CANNOT_BE_NULL, ImmutableMap.of("property", CONTRACT_IDENTITY_FIELD));
}
return identity.getId();
}
return transformedValue;
}
use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method findByAttribute.
@Override
protected IdmIdentityContractDto findByAttribute(String idmAttributeName, String value) {
CorrelationFilter filter = getEntityFilter();
filter.setProperty(idmAttributeName);
filter.setValue(value);
List<IdmIdentityContractDto> entities = contractService.find((IdmIdentityContractFilter) filter, null).getContent();
if (CollectionUtils.isEmpty(entities)) {
return null;
}
if (entities.size() > 1) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_CORRELATION_TO_MANY_RESULTS, ImmutableMap.of("correlationAttribute", idmAttributeName, "value", value));
}
if (entities.size() == 1) {
return entities.get(0);
}
return null;
}
use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class TreeProvisioningExecutor method getAttributeValue.
@Override
protected Object getAttributeValue(String uid, IdmTreeNodeDto entity, AttributeMapping attribute) {
Object idmValue = super.getAttributeValue(uid, entity, attribute);
if (attribute.isEntityAttribute() && TreeSynchronizationExecutor.PARENT_FIELD.equals(attribute.getIdmPropertyName())) {
// parent format (UID of parent)
if (idmValue instanceof UUID) {
// Generally we expect IdmTreeNode as parent (we will do
// transform)
AccTreeAccountFilter treeAccountFilter = new AccTreeAccountFilter();
treeAccountFilter.setSystemId(this.getSytemFromSchemaAttribute(attribute.getSchemaAttribute()).getId());
treeAccountFilter.setTreeNodeId(((UUID) idmValue));
List<AccTreeAccountDto> treeAccounts = treeAccountService.find(treeAccountFilter, null).getContent();
if (treeAccounts.isEmpty()) {
throw new ProvisioningException(AccResultCode.PROVISIONING_TREE_PARENT_ACCOUNT_NOT_FOUND, ImmutableMap.of("parentNode", idmValue));
}
if (treeAccounts.size() != 1) {
throw new ProvisioningException(AccResultCode.PROVISIONING_TREE_TOO_MANY_PARENT_ACCOUNTS, ImmutableMap.of("parentNode", idmValue));
}
AccTreeAccountDto treeAccount = treeAccounts.get(0);
String parentUid = accountService.get(treeAccount.getAccount()).getUid();
return parentUid;
} else {
// without any transform
return idmValue;
}
}
return idmValue;
}
use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class TreeSynchronizationExecutor 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();
List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
SysSystemMappingDto systemMapping = systemMappingService.get(context.getConfig().getSystemMapping());
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(systemMapping.getObjectClass());
IcObjectClass objectClass = new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName());
// Load last token
Object lastToken = config.isReconciliation() ? null : config.getToken();
// 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 with full IC object (used in tree sync)
Map<String, IcConnectorObject> accountsMap = new HashMap<>();
longRunningTaskExecutor.setCounter(0L);
try {
log = synchronizationLogService.save(log);
List<SysSyncActionLogDto> actionsLog = new ArrayList<>();
// Add logs to context
context.addLog(log).addActionLogs(actionsLog);
boolean export = false;
if (export) {
// Start exporting entities to resource
log.addToLog("Exporting entities to resource started...");
this.startExport(entityType, config, mappedAttributes, log, actionsLog);
} else {
if (config.getTokenAttribute() == null && !config.isReconciliation()) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TOKEN_ATTRIBUTE_NOT_FOUND);
}
TreeResultsHandler resultHandler = new TreeResultsHandler(accountsMap);
// We have to search all data for tree
IcFilter filter = null;
log.addToLog(MessageFormat.format("Start search with filter {0}.", "NONE"));
log = synchronizationLogService.save(log);
connectorFacade.search(system.getConnectorInstance(), connectorConfig, objectClass, filter, resultHandler);
// Execute sync for this tree and searched accounts
processTreeSync(context, accountsMap);
log = context.getLog();
}
//
log.addToLog(MessageFormat.format("Synchronization was correctly ended in {0}.", LocalDateTime.now()));
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.exception.ProvisioningException in project CzechIdMng by bcvsolutions.
the class DefaultSynchronizationService method stopSynchronization.
@Override
public AbstractSysSyncConfigDto stopSynchronization(AbstractSysSyncConfigDto config) {
Assert.notNull(config);
// Synchronization must be running
SysSyncLogFilter logFilter = new SysSyncLogFilter();
logFilter.setSynchronizationConfigId(config.getId());
logFilter.setRunning(Boolean.TRUE);
List<SysSyncLogDto> logs = synchronizationLogService.find(logFilter, null).getContent();
if (logs.isEmpty()) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IS_NOT_RUNNING, ImmutableMap.of("name", config.getName()));
}
logs.forEach(log -> {
log.setRunning(false);
log.setEnded(LocalDateTime.now());
});
synchronizationLogService.saveAll(logs);
return config;
}
Aggregations