Search in sources :

Example 26 with ProvisioningException

use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method updateExtendedAttributes.

/**
 * Update extended attribute for given entity. Entity must be persisted first.
 *
 * @param mappedAttributes
 * @param uid
 * @param icAttributes
 * @param entity
 * @param create
 *            (is create or update entity situation)
 * @param context
 * @return
 */
@SuppressWarnings("unchecked")
protected DTO updateExtendedAttributes(List<SysSystemAttributeMappingDto> mappedAttributes, String uid, List<IcAttribute> icAttributes, DTO dto, boolean create, SynchronizationContext context) {
    mappedAttributes.stream().filter(attribute -> {
        // Skip disabled attributes
        // Only for extended attributes
        boolean fastResult = !attribute.isDisabledAttribute() && attribute.isExtendedAttribute();
        if (!fastResult) {
            return false;
        }
        // Can be value set by attribute strategy?
        return this.canSetValue(uid, attribute, dto, create);
    }).forEach(attribute -> {
        String attributeProperty = attribute.getIdmPropertyName();
        Object transformedValue = getValueByMappedAttribute(attribute, icAttributes, context);
        // Save to extended attribute
        if (!formService.isFormable(dto.getClass())) {
            String message = MessageFormat.format("Entity [{0}] is not instance of fromable entity!", dto.getId());
            throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_ERROR_DURING_SYNC_ITEM, ImmutableMap.of("uid", uid, "message", message));
        }
        IdmFormAttributeDto defAttribute = formService.getDefinition(dto.getClass()).getMappedAttributeByCode(attributeProperty);
        if (defAttribute == null) {
            // eav definition could be changed
            String message = MessageFormat.format("Form attribute defininion [{0}] was not found!", attributeProperty);
            throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_ERROR_DURING_SYNC_ITEM, ImmutableMap.of("uid", uid, "message", message));
        }
        if (transformedValue instanceof List<?>) {
            ((List<?>) transformedValue).stream().forEach(value -> {
                if (value != null && !(value instanceof Serializable)) {
                    String message = MessageFormat.format("Value is not serializable [{0}] for attribute [{1}] and UID [{2}]!", value, attribute, uid);
                    throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_ERROR_DURING_SYNC_ITEM, ImmutableMap.of("uid", uid, "message", message));
                }
            });
            formService.saveValues(dto, defAttribute, (List<Serializable>) transformedValue);
        } else {
            formService.saveValues(dto, defAttribute, Lists.newArrayList((Serializable) transformedValue));
        }
    });
    return dto;
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AttributeValueWrapperDto(eu.bcvsolutions.idm.acc.dto.AttributeValueWrapperDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) GroovyScriptService(eu.bcvsolutions.idm.core.api.service.GroovyScriptService) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) Pair(org.apache.commons.lang3.tuple.Pair) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) Map(java.util.Map) SynchronizationUnlinkedActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationUnlinkedActionType) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IcSyncTokenImpl(eu.bcvsolutions.idm.ic.impl.IcSyncTokenImpl) Loggable(eu.bcvsolutions.idm.core.api.domain.Loggable) IcFilter(eu.bcvsolutions.idm.ic.filter.api.IcFilter) Set(java.util.Set) ReconciliationMissingAccountActionType(eu.bcvsolutions.idm.acc.domain.ReconciliationMissingAccountActionType) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) SynchronizationSituationType(eu.bcvsolutions.idm.acc.domain.SynchronizationSituationType) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) IcSyncResultsHandler(eu.bcvsolutions.idm.ic.api.IcSyncResultsHandler) SynchronizationEventType(eu.bcvsolutions.idm.acc.event.SynchronizationEventType) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) Session(org.hibernate.Session) ArrayList(java.util.ArrayList) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) SysSyncConfig(eu.bcvsolutions.idm.acc.entity.SysSyncConfig) IcResultsHandler(eu.bcvsolutions.idm.ic.filter.api.IcResultsHandler) CacheManager(org.springframework.cache.CacheManager) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) SynchronizationLinkedActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationLinkedActionType) SysSystemEntityFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) IcOrFilter(eu.bcvsolutions.idm.ic.filter.impl.IcOrFilter) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) SysSchemaObjectClass_(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass_) IcFilterBuilder(eu.bcvsolutions.idm.ic.filter.impl.IcFilterBuilder) IcConnectorKey(eu.bcvsolutions.idm.ic.api.IcConnectorKey) Throwables(com.google.common.base.Throwables) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) EntityManager(javax.persistence.EntityManager) LocalDateTime(org.joda.time.LocalDateTime) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) VariableScope(org.activiti.engine.delegate.VariableScope) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SynchronizationEntityExecutor(eu.bcvsolutions.idm.acc.service.api.SynchronizationEntityExecutor) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) SysSyncActionLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncActionLogService) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) OperationResultType(eu.bcvsolutions.idm.acc.domain.OperationResultType) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) IcSyncDeltaTypeEnum(eu.bcvsolutions.idm.ic.impl.IcSyncDeltaTypeEnum) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SynchronizationMissingEntityActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationMissingEntityActionType) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Pageable(org.springframework.data.domain.Pageable) SysSyncConfigService(eu.bcvsolutions.idm.acc.service.api.SysSyncConfigService) SysSyncLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncLogService) AbstractLongRunningTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.AbstractLongRunningTaskExecutor) ImmutableMap(com.google.common.collect.ImmutableMap) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) List(java.util.List) EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) AccountType(eu.bcvsolutions.idm.acc.domain.AccountType) Optional(java.util.Optional) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) ValueWrapper(org.springframework.cache.Cache.ValueWrapper) IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) Cache(org.springframework.cache.Cache) AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) HashMap(java.util.HashMap) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) MessageFormat(java.text.MessageFormat) HashSet(java.util.HashSet) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) CollectionUtils(org.apache.commons.collections.CollectionUtils) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) CorrelationFilter(eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter) IcSyncDelta(eu.bcvsolutions.idm.ic.api.IcSyncDelta) IcAndFilter(eu.bcvsolutions.idm.ic.filter.impl.IcAndFilter) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) DateTime(org.joda.time.DateTime) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Beta(com.google.common.annotations.Beta) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SynchronizationService(eu.bcvsolutions.idm.acc.service.api.SynchronizationService) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IcFilterOperationType(eu.bcvsolutions.idm.ic.domain.IcFilterOperationType) SysSyncItemLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncItemLogService) IcSyncToken(eu.bcvsolutions.idm.ic.api.IcSyncToken) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) Serializable(java.io.Serializable) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ArrayList(java.util.ArrayList) List(java.util.List) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString)

Example 27 with ProvisioningException

use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method findByCorrelationAttribute.

/**
 * Find entity by correlation attribute
 *
 * @param attribute
 * @param entityType
 * @param icAttributes
 * @param context
 * @return
 */
@SuppressWarnings("unchecked")
protected DTO findByCorrelationAttribute(AttributeMapping attribute, List<IcAttribute> icAttributes, SynchronizationContext context) {
    Assert.notNull(attribute);
    Assert.notNull(icAttributes);
    Object value = getValueByMappedAttribute(attribute, icAttributes, context);
    if (value == null) {
        return null;
    }
    if (attribute.isEntityAttribute()) {
        return findByAttribute(attribute.getIdmPropertyName(), value.toString());
    } else if (attribute.isExtendedAttribute()) {
        try {
            Serializable serializableValue = Serializable.class.cast(value);
            List<? extends BaseDto> entities = formService.findOwners(getEntityClass(), attribute.getIdmPropertyName(), serializableValue, null).getContent();
            if (CollectionUtils.isEmpty(entities)) {
                return null;
            }
            if (entities.size() > 1) {
                throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_CORRELATION_TO_MANY_RESULTS, ImmutableMap.of("correlationAttribute", attribute.getName(), "value", value));
            }
            if (entities.size() == 1) {
                return (DTO) entities.get(0);
            }
        } catch (ClassCastException e) {
            throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_CORRELATION_BAD_VALUE, ImmutableMap.of("value", value), e);
        }
    }
    return null;
}
Also used : Serializable(java.io.Serializable) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ArrayList(java.util.ArrayList) List(java.util.List) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto)

Example 28 with ProvisioningException

use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method findSystemEntity.

private SysSystemEntityDto findSystemEntity(String uid, SysSystemDto system, SystemEntityType entityType) {
    SysSystemEntityFilter systemEntityFilter = new SysSystemEntityFilter();
    systemEntityFilter.setEntityType(entityType);
    systemEntityFilter.setSystemId(system.getId());
    systemEntityFilter.setUid(uid);
    List<SysSystemEntityDto> systemEntities = systemEntityService.find(systemEntityFilter, null).getContent();
    SysSystemEntityDto systemEntity = null;
    if (systemEntities.size() == 1) {
        systemEntity = systemEntities.get(0);
    } else if (systemEntities.size() > 1) {
        throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TO_MANY_SYSTEM_ENTITY, uid);
    }
    return systemEntity;
}
Also used : ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysSystemEntityFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter)

Example 29 with ProvisioningException

use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.

the class ContractSynchronizationExecutor method fillEntity.

/**
 * Fill entity with attributes from IC module (by mapped attributes).
 *
 * @param mappedAttributes
 * @param uid
 * @param icAttributes
 * @param entity
 * @param create
 *            (is create or update entity situation)
 * @param context
 * @return
 */
protected IdmIdentityContractDto fillEntity(List<SysSystemAttributeMappingDto> mappedAttributes, String uid, List<IcAttribute> icAttributes, IdmIdentityContractDto dto, boolean create, SynchronizationContext context) {
    mappedAttributes.stream().filter(attribute -> {
        // Skip disabled attributes
        // Skip extended attributes (we need update/ create entity first)
        // Skip confidential attributes (we need update/ create entity
        // first)
        boolean fastResult = !attribute.isDisabledAttribute() && attribute.isEntityAttribute() && !attribute.isConfidentialAttribute();
        if (!fastResult) {
            return false;
        }
        // Can be value set by attribute strategy?
        return this.canSetValue(uid, attribute, dto, create);
    }).forEach(attribute -> {
        String attributeProperty = attribute.getIdmPropertyName();
        Object transformedValue = getValueByMappedAttribute(attribute, icAttributes, context);
        // they), but to the embedded map.
        if (CONTRACT_GUARANTEES_FIELD.equals(attributeProperty)) {
            if (transformedValue instanceof SyncIdentityContractDto) {
                dto.getEmbedded().put(SYNC_CONTRACT_FIELD, (SyncIdentityContractDto) transformedValue);
            } else {
                dto.getEmbedded().put(SYNC_CONTRACT_FIELD, new SyncIdentityContractDto());
            }
            return;
        }
        // Set transformed value from target system to entity
        try {
            EntityUtils.setEntityValue(dto, attributeProperty, transformedValue);
        } catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | ProvisioningException e) {
            throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_NOT_SET, ImmutableMap.of("property", attributeProperty, "uid", uid), e);
        }
    });
    return dto;
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ContractGuaranteeEventType(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent.ContractGuaranteeEventType) GroovyScriptService(eu.bcvsolutions.idm.core.api.service.GroovyScriptService) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) AccContractAccountService(eu.bcvsolutions.idm.acc.service.api.AccContractAccountService) HrEndContractProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrEndContractProcess) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) HrEnableContractProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrEnableContractProcess) AccContractAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractAccountFilter) IdmTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmTreeNodeService) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) IdmConfigurationService(eu.bcvsolutions.idm.core.api.service.IdmConfigurationService) BooleanUtils(org.apache.commons.lang3.BooleanUtils) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) IdmTreeNode_(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode_) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) HrContractExclusionProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrContractExclusionProcess) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) SyncIdentityContractDto(eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) EntityManager(javax.persistence.EntityManager) LocalDateTime(org.joda.time.LocalDateTime) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SynchronizationEntityExecutor(eu.bcvsolutions.idm.acc.service.api.SynchronizationEntityExecutor) AccContractAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractAccountDto) SysSyncActionLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncActionLogService) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) OperationResultType(eu.bcvsolutions.idm.acc.domain.OperationResultType) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) ProcessAllAutomaticRoleByAttributeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAllAutomaticRoleByAttributeTaskExecutor) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) ContractGuaranteeEvent(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent) SysSyncConfigService(eu.bcvsolutions.idm.acc.service.api.SysSyncConfigService) SysSyncLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncLogService) ImmutableMap(com.google.common.collect.ImmutableMap) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) UUID(java.util.UUID) SchedulerManager(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulerManager) Collectors(java.util.stream.Collectors) SysSyncContractConfig_(eu.bcvsolutions.idm.acc.entity.SysSyncContractConfig_) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) IdmScheduledTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmScheduledTaskService) List(java.util.List) EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) IdmAutomaticRoleAttributeService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeService) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) MessageFormat(java.text.MessageFormat) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) CollectionUtils(org.apache.commons.collections.CollectionUtils) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) CorrelationFilter(eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter) IdmLongRunningTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmLongRunningTaskService) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmContractGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService) SchedulableTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulableTaskExecutor) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) Component(org.springframework.stereotype.Component) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) ProvisioningService(eu.bcvsolutions.idm.acc.service.api.ProvisioningService) SysSyncItemLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncItemLogService) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) Assert(org.springframework.util.Assert) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IntrospectionException(java.beans.IntrospectionException) SyncIdentityContractDto(eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 30 with ProvisioningException

use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.

the class ContractSynchronizationExecutor method save.

/**
 * Save entity
 *
 * @param entity
 * @param skipProvisioning
 * @return
 */
@Override
protected IdmIdentityContractDto save(IdmIdentityContractDto entity, boolean skipProvisioning) {
    if (entity.getIdentity() == null) {
        throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_CANNOT_BE_NULL, ImmutableMap.of("property", CONTRACT_IDENTITY_FIELD));
    }
    EntityEvent<IdmIdentityContractDto> event = new IdentityContractEvent(contractService.isNew(entity) ? IdentityContractEventType.CREATE : IdentityContractEventType.UPDATE, entity, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
    // We do not want execute HR processes for every contract. We need start
    // them for every identity only once.
    // For this we skip them now. HR processes must be start after whole
    // sync finished (by using dependent scheduled task)!
    event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
    // 
    // We don't want recalculate automatic role by attribute recalculation for every contract.
    // Recalculation will be started only once.
    event.getProperties().put(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION, Boolean.TRUE);
    IdmIdentityContractDto contract = contractService.publish(event).getContent();
    if (entity.getEmbedded().containsKey(SYNC_CONTRACT_FIELD)) {
        SyncIdentityContractDto syncContract = (SyncIdentityContractDto) entity.getEmbedded().get(SYNC_CONTRACT_FIELD);
        IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
        guaranteeFilter.setIdentityContractId(contract.getId());
        List<IdmContractGuaranteeDto> currentGuarantees = guaranteeService.find(guaranteeFilter, null).getContent();
        // Search guarantees to delete
        List<IdmContractGuaranteeDto> guaranteesToDelete = currentGuarantees.stream().filter(sysImplementer -> {
            return sysImplementer.getGuarantee() != null && !syncContract.getGuarantees().contains(new IdmIdentityDto(sysImplementer.getGuarantee()));
        }).collect(Collectors.toList());
        // Search guarantees to add
        List<IdmIdentityDto> guaranteesToAdd = syncContract.getGuarantees().stream().filter(identity -> {
            return !currentGuarantees.stream().filter(currentGuarrantee -> {
                return identity.getId().equals(currentGuarrantee.getGuarantee());
            }).findFirst().isPresent();
        }).collect(Collectors.toList());
        // Delete guarantees
        guaranteesToDelete.forEach(guarantee -> {
            EntityEvent<IdmContractGuaranteeDto> guaranteeEvent = new ContractGuaranteeEvent(ContractGuaranteeEventType.DELETE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
            guaranteeService.publish(guaranteeEvent);
        });
        // Create new guarantees
        guaranteesToAdd.forEach(identity -> {
            IdmContractGuaranteeDto guarantee = new IdmContractGuaranteeDto();
            guarantee.setIdentityContract(contract.getId());
            guarantee.setGuarantee(identity.getId());
            // 
            EntityEvent<IdmContractGuaranteeDto> guaranteeEvent = new ContractGuaranteeEvent(ContractGuaranteeEventType.CREATE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
            guaranteeService.publish(guaranteeEvent);
        });
    }
    return contract;
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ContractGuaranteeEventType(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent.ContractGuaranteeEventType) GroovyScriptService(eu.bcvsolutions.idm.core.api.service.GroovyScriptService) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) AccContractAccountService(eu.bcvsolutions.idm.acc.service.api.AccContractAccountService) HrEndContractProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrEndContractProcess) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) HrEnableContractProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrEnableContractProcess) AccContractAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractAccountFilter) IdmTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmTreeNodeService) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) IdmConfigurationService(eu.bcvsolutions.idm.core.api.service.IdmConfigurationService) BooleanUtils(org.apache.commons.lang3.BooleanUtils) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) IdmTreeNode_(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode_) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) HrContractExclusionProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrContractExclusionProcess) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) SyncIdentityContractDto(eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) EntityManager(javax.persistence.EntityManager) LocalDateTime(org.joda.time.LocalDateTime) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SynchronizationEntityExecutor(eu.bcvsolutions.idm.acc.service.api.SynchronizationEntityExecutor) AccContractAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractAccountDto) SysSyncActionLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncActionLogService) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) OperationResultType(eu.bcvsolutions.idm.acc.domain.OperationResultType) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) ProcessAllAutomaticRoleByAttributeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAllAutomaticRoleByAttributeTaskExecutor) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) ContractGuaranteeEvent(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent) SysSyncConfigService(eu.bcvsolutions.idm.acc.service.api.SysSyncConfigService) SysSyncLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncLogService) ImmutableMap(com.google.common.collect.ImmutableMap) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) UUID(java.util.UUID) SchedulerManager(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulerManager) Collectors(java.util.stream.Collectors) SysSyncContractConfig_(eu.bcvsolutions.idm.acc.entity.SysSyncContractConfig_) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) IdmScheduledTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmScheduledTaskService) List(java.util.List) EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) IdmAutomaticRoleAttributeService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeService) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) MessageFormat(java.text.MessageFormat) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) CollectionUtils(org.apache.commons.collections.CollectionUtils) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) CorrelationFilter(eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter) IdmLongRunningTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmLongRunningTaskService) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmContractGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService) SchedulableTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulableTaskExecutor) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) Component(org.springframework.stereotype.Component) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) ProvisioningService(eu.bcvsolutions.idm.acc.service.api.ProvisioningService) SysSyncItemLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncItemLogService) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) Assert(org.springframework.util.Assert) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) SyncIdentityContractDto(eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) ContractGuaranteeEvent(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent)

Aggregations

ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)41 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)20 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)19 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)17 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)16 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)15 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)14 IcConnectorConfiguration (eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration)14 List (java.util.List)13 UUID (java.util.UUID)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 AccResultCode (eu.bcvsolutions.idm.acc.domain.AccResultCode)12 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)12 SysSchemaObjectClassService (eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService)12 SysSystemAttributeMappingService (eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService)12 SysSystemMappingService (eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService)12 ArrayList (java.util.ArrayList)12 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)11 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)11 SysSchemaAttributeService (eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService)11