use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto 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.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method validate.
/**
* Validate synchronization on: Exist, enable, running, has mapping, has
* connector key, has connector configuration
*
* @param synchronizationConfigId
* @return
*/
protected SynchronizationContext validate(UUID synchronizationConfigId) {
SynchronizationContext context = new SynchronizationContext();
AbstractSysSyncConfigDto config = synchronizationConfigService.get(synchronizationConfigId);
//
if (config == null) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_NOT_FOUND, ImmutableMap.of("id", synchronizationConfigId));
}
// Synchronization must be enabled
if (!config.isEnabled()) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IS_NOT_ENABLED, ImmutableMap.of("name", config.getName()));
}
// Synchronization can not be running twice
SysSyncLogFilter logFilter = new SysSyncLogFilter();
logFilter.setSynchronizationConfigId(config.getId());
logFilter.setRunning(Boolean.TRUE);
if (!synchronizationLogService.find(logFilter, null).getContent().isEmpty()) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IS_RUNNING, ImmutableMap.of("name", config.getName()));
}
SysSystemMappingDto mapping = systemMappingService.get(config.getSystemMapping());
Assert.notNull(mapping);
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
SysSystemDto system = DtoUtils.getEmbedded(schemaObjectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
Assert.notNull(system);
// System must be enabled
if (system.isDisabled()) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_SYSTEM_IS_NOT_ENABLED, ImmutableMap.of("name", config.getName(), "system", system.getName()));
}
SystemEntityType entityType = mapping.getEntityType();
SysSystemAttributeMappingFilter attributeHandlingFilter = new SysSystemAttributeMappingFilter();
attributeHandlingFilter.setSystemMappingId(mapping.getId());
List<SysSystemAttributeMappingDto> mappedAttributes = systemAttributeMappingService.find(attributeHandlingFilter, null).getContent();
// Find connector identification persisted in system
IcConnectorKey connectorKey = system.getConnectorKey();
if (connectorKey == null) {
throw new ProvisioningException(AccResultCode.CONNECTOR_KEY_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// Find connector configuration persisted in system
IcConnectorConfiguration connectorConfig = systemService.getConnectorConfiguration(system);
if (connectorConfig == null) {
throw new ProvisioningException(AccResultCode.CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
context.addConfig(config).addSystem(system).addEntityType(entityType).addMappedAttributes(mappedAttributes).addConnectorConfig(connectorConfig);
return context;
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method validate.
@Override
protected SynchronizationContext validate(UUID synchronizationConfigId) {
AbstractSysSyncConfigDto config = synchronizationConfigService.get(synchronizationConfigId);
SysSystemMappingDto mapping = systemMappingService.get(config.getSystemMapping());
Assert.notNull(mapping);
SysSystemAttributeMappingFilter attributeHandlingFilter = new SysSystemAttributeMappingFilter();
attributeHandlingFilter.setSystemMappingId(mapping.getId());
List<SysSystemAttributeMappingDto> mappedAttributes = systemAttributeMappingService.find(attributeHandlingFilter, null).getContent();
SysSystemAttributeMappingDto ownerAttribute = mappedAttributes.stream().filter(attribute -> {
return CONTRACT_IDENTITY_FIELD.equals(attribute.getIdmPropertyName());
}).findFirst().orElse(null);
if (ownerAttribute == null) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_MAPPED_ATTR_MUST_EXIST, ImmutableMap.of("property", CONTRACT_IDENTITY_FIELD));
}
return super.validate(synchronizationConfigId);
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountManagementService method generateUID.
/**
* Return UID for this identity and roleSystem. First will be find and use
* transform script from roleSystem attribute. If isn't UID attribute for
* roleSystem defined, then will be use default UID attribute handling.
*
* @param entity
* @param roleSystem
* @return
*/
@Override
public String generateUID(AbstractDto entity, SysRoleSystemDto roleSystem) {
// Find attributes for this roleSystem
SysRoleSystemAttributeFilter roleSystemAttrFilter = new SysRoleSystemAttributeFilter();
roleSystemAttrFilter.setRoleSystemId(roleSystem.getId());
List<SysRoleSystemAttributeDto> attributes = roleSystemAttributeService.find(roleSystemAttrFilter, null).getContent();
List<SysRoleSystemAttributeDto> attributesUid = attributes.stream().filter(attribute -> {
return attribute.isUid();
}).collect(Collectors.toList());
if (attributesUid.size() > 1) {
IdmRoleDto roleDto = DtoUtils.getEmbedded(roleSystem, SysRoleSystem_.role, IdmRoleDto.class);
DtoUtils.getEmbedded(roleSystem, SysRoleSystem_.system, SysSystemDto.class);
SysSystemDto systemDto = DtoUtils.getEmbedded(roleSystem, SysRoleSystem_.system, SysSystemDto.class);
throw new ProvisioningException(AccResultCode.PROVISIONING_ROLE_ATTRIBUTE_MORE_UID, ImmutableMap.of("role", roleDto.getName(), "system", systemDto.getName()));
}
SysRoleSystemAttributeDto uidRoleAttribute = !attributesUid.isEmpty() ? attributesUid.get(0) : null;
// script.
if (uidRoleAttribute != null) {
// Default values (values from schema attribute handling)
SysSystemAttributeMappingDto systemAttributeMapping = systemAttributeMappingService.get(uidRoleAttribute.getSystemAttributeMapping());
uidRoleAttribute.setSchemaAttribute(systemAttributeMapping.getSchemaAttribute());
uidRoleAttribute.setTransformFromResourceScript(systemAttributeMapping.getTransformFromResourceScript());
Object uid = systemAttributeMappingService.getAttributeValue(null, entity, uidRoleAttribute);
if (uid == null) {
SysSystemDto systemEntity = DtoUtils.getEmbedded(roleSystem, SysRoleSystem_.system, SysSystemDto.class);
throw new ProvisioningException(AccResultCode.PROVISIONING_GENERATED_UID_IS_NULL, ImmutableMap.of("system", systemEntity.getName()));
}
if (!(uid instanceof String)) {
throw new ProvisioningException(AccResultCode.PROVISIONING_ATTRIBUTE_UID_IS_NOT_STRING, ImmutableMap.of("uid", uid));
}
return (String) uid;
}
SysSystemMappingDto mapping = systemMappingService.get(roleSystem.getSystemMapping());
// If roleSystem UID was not found, then we use default UID schema
// attribute handling
SysSchemaObjectClassDto objectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
SysSystemDto system = DtoUtils.getEmbedded(objectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
SysSystemAttributeMappingFilter systeAttributeMappingFilter = new SysSystemAttributeMappingFilter();
systeAttributeMappingFilter.setSystemMappingId(mapping.getId());
List<SysSystemAttributeMappingDto> schemaHandlingAttributes = systemAttributeMappingService.find(systeAttributeMappingFilter, null).getContent();
SysSystemAttributeMappingDto uidAttribute = systemAttributeMappingService.getUidAttribute(schemaHandlingAttributes, system);
return systemAttributeMappingService.generateUid(entity, uidAttribute);
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto in project CzechIdMng by bcvsolutions.
the class DefaultSynchronizationService method resolveMissingEntitySituation.
@Override
public SysSyncItemLogDto resolveMissingEntitySituation(String uid, SystemEntityType entityType, List<IcAttribute> icAttributes, UUID configId, String actionType) {
Assert.notNull(uid);
Assert.notNull(entityType);
Assert.notNull(icAttributes);
Assert.notNull(configId);
Assert.notNull(actionType);
AbstractSysSyncConfigDto config = synchronizationConfigService.get(configId);
SysSystemMappingDto mapping = systemMappingService.get(config.getSystemMapping());
SysSchemaObjectClassDto sysSchemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
SysSystemDto system = DtoUtils.getEmbedded(sysSchemaObjectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
SysSystemAttributeMappingFilter attributeHandlingFilter = new SysSystemAttributeMappingFilter();
attributeHandlingFilter.setSystemMappingId(mapping.getId());
List<SysSystemAttributeMappingDto> mappedAttributes = attributeHandlingService.find(attributeHandlingFilter, null).getContent();
SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
// Little workaround, we have only IcAttributes ... we create IcObject manually
IcConnectorObjectImpl icObject = new IcConnectorObjectImpl();
icObject.setAttributes(icAttributes);
icObject.setUidValue(uid);
SynchronizationContext context = new SynchronizationContext();
context.addUid(uid).addSystem(system).addConfig(config).addEntityType(entityType).addLogItem(itemLog).addMappedAttributes(mappedAttributes).addIcObject(icObject);
getSyncExecutor(entityType).resolveMissingEntitySituation(SynchronizationMissingEntityActionType.valueOf(actionType), context);
return itemLog;
}
Aggregations