Search in sources :

Example 6 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.

the class ContractSliceSynchronizationExecutor method save.

/**
 * Save entity
 *
 * @param entity
 * @param skipProvisioning
 * @return
 */
@Override
protected IdmContractSliceDto save(IdmContractSliceDto entity, boolean skipProvisioning, SynchronizationContext context) {
    if (entity.getIdentity() == null) {
        throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_CANNOT_BE_NULL, ImmutableMap.of("property", CONTRACT_IDENTITY_FIELD));
    }
    EntityEvent<IdmContractSliceDto> event = new ContractSliceEvent(sliceService.isNew(entity) ? ContractSliceEventType.CREATE : ContractSliceEventType.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(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
    // 
    // Set dirty state during recalculation, the process of recalculation will be solved in ClearDirtyStateForContractSliceTaskExecutor
    // ClearDirtyStateForContractSliceTaskExecutor will be started with HR processes.
    event.getProperties().put(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, Boolean.TRUE);
    IdmContractSliceDto slice = sliceService.publish(event).getContent();
    if (entity.getEmbedded().containsKey(SYNC_CONTRACT_FIELD)) {
        SyncIdentityContractDto syncContract = (SyncIdentityContractDto) entity.getEmbedded().get(SYNC_CONTRACT_FIELD);
        IdmContractSliceGuaranteeFilter guaranteeFilter = new IdmContractSliceGuaranteeFilter();
        guaranteeFilter.setContractSliceId(slice.getId());
        List<IdmContractSliceGuaranteeDto> currentGuarantees = guaranteeService.find(guaranteeFilter, null).getContent();
        // Search guarantees to delete
        List<IdmContractSliceGuaranteeDto> 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<IdmContractSliceGuaranteeDto> guaranteeEvent = new ContractSliceGuaranteeEvent(ContractSliceGuaranteeEventType.DELETE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
            guaranteeService.publish(guaranteeEvent);
        });
        // Create new guarantees
        guaranteesToAdd.forEach(identity -> {
            IdmContractSliceGuaranteeDto guarantee = new IdmContractSliceGuaranteeDto();
            guarantee.setContractSlice(slice.getId());
            guarantee.setGuarantee(identity.getId());
            // 
            EntityEvent<IdmContractSliceGuaranteeDto> guaranteeEvent = new ContractSliceGuaranteeEvent(ContractSliceGuaranteeEventType.CREATE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
            guaranteeService.publish(guaranteeEvent);
        });
    }
    return slice;
}
Also used : OperationResultType(eu.bcvsolutions.idm.acc.domain.OperationResultType) ContractSliceGuaranteeEventType(eu.bcvsolutions.idm.core.model.event.ContractSliceGuaranteeEvent.ContractSliceGuaranteeEventType) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) ZonedDateTime(java.time.ZonedDateTime) ContractSliceEventType(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent.ContractSliceEventType) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ClearDirtyStateForContractSliceTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ClearDirtyStateForContractSliceTaskExecutor) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) ProcessAllAutomaticRoleByAttributeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAllAutomaticRoleByAttributeTaskExecutor) StringUtils(org.apache.commons.lang3.StringUtils) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) ContractSliceGuaranteeEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceGuaranteeEvent) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) EntityAccountService(eu.bcvsolutions.idm.acc.service.api.EntityAccountService) 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) ImmutableMap(com.google.common.collect.ImmutableMap) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) HrEndContractProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrEndContractProcess) UUID(java.util.UUID) SchedulerManager(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulerManager) Collectors(java.util.stream.Collectors) IdmContractSlice_(eu.bcvsolutions.idm.core.model.entity.IdmContractSlice_) Serializable(java.io.Serializable) SysSyncContractConfig_(eu.bcvsolutions.idm.acc.entity.SysSyncContractConfig_) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) IdmScheduledTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmScheduledTaskService) SelectCurrentContractSliceTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.SelectCurrentContractSliceTaskExecutor) List(java.util.List) EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) HrEnableContractProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrEnableContractProcess) IdmContractSliceService(eu.bcvsolutions.idm.core.api.service.IdmContractSliceService) IdmTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmTreeNodeService) BooleanUtils(org.apache.commons.lang3.BooleanUtils) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) CollectionUtils(org.apache.commons.collections4.CollectionUtils) IdmTreeNode_(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode_) MessageFormat(java.text.MessageFormat) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) CorrelationFilter(eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter) IdmContractSliceGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractSliceGuaranteeService) AccContractSliceAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractSliceAccountDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) 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) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AccContractSliceAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractSliceAccountFilter) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) SyncIdentityContractDto(eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SchedulableTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulableTaskExecutor) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) Component(org.springframework.stereotype.Component) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) ProvisioningService(eu.bcvsolutions.idm.acc.service.api.ProvisioningService) SynchronizationEntityExecutor(eu.bcvsolutions.idm.acc.service.api.SynchronizationEntityExecutor) AccContractSliceAccountService(eu.bcvsolutions.idm.acc.service.api.AccContractSliceAccountService) ContractSliceManager(eu.bcvsolutions.idm.core.api.service.ContractSliceManager) Assert(org.springframework.util.Assert) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) ContractSliceGuaranteeEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceGuaranteeEvent) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SyncIdentityContractDto(eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 7 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.

the class ContractSliceSynchronizationExecutor 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 IdmContractSliceDto fillEntity(List<SysSystemAttributeMappingDto> mappedAttributes, String uid, List<IcAttribute> icAttributes, IdmContractSliceDto 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());
            }
            // Check if new guarantees are different than current guarantees.
            SyncIdentityContractDto syncIdentityContractDto = (SyncIdentityContractDto) dto.getEmbedded().get(SYNC_CONTRACT_FIELD);
            if (syncIdentityContractDto != null && !context.isEntityDifferent()) {
                List<IdmIdentityDto> newGuarantees = syncIdentityContractDto.getGuarantees();
                if (!isGuaranteesSame(dto, newGuarantees)) {
                    // Guarantees are different
                    context.setIsEntityDifferent(true);
                    addToItemLog(context.getLogItem(), MessageFormat.format("Value of entity attribute [{0}] was changed. Entity in IdM will be updated.", attributeProperty));
                }
            }
            return;
        }
        // Valid till attribute is sets only if is that slice last!
        if (CONTRACT_VALID_TILL_FIELD.equals(attributeProperty) && dto.getParentContract() != null) {
            IdmContractSliceDto nextSlice = contractSliceManager.findNextSlice(dto, contractSliceManager.findAllSlices(dto.getParentContract()));
            if (nextSlice != null) {
                context.getLogItem().addToLog("Warning! - Valid till field wasn't changed, because the that slice is not a last!");
                return;
            }
        }
        // Set transformed value from target system to entity
        setEntityValue(uid, dto, context, attribute, attributeProperty, transformedValue);
    });
    return dto;
}
Also used : OperationResultType(eu.bcvsolutions.idm.acc.domain.OperationResultType) ContractSliceGuaranteeEventType(eu.bcvsolutions.idm.core.model.event.ContractSliceGuaranteeEvent.ContractSliceGuaranteeEventType) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) ZonedDateTime(java.time.ZonedDateTime) ContractSliceEventType(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent.ContractSliceEventType) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ClearDirtyStateForContractSliceTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ClearDirtyStateForContractSliceTaskExecutor) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) ProcessAllAutomaticRoleByAttributeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAllAutomaticRoleByAttributeTaskExecutor) StringUtils(org.apache.commons.lang3.StringUtils) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) ContractSliceGuaranteeEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceGuaranteeEvent) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) EntityAccountService(eu.bcvsolutions.idm.acc.service.api.EntityAccountService) 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) ImmutableMap(com.google.common.collect.ImmutableMap) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) HrEndContractProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrEndContractProcess) UUID(java.util.UUID) SchedulerManager(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulerManager) Collectors(java.util.stream.Collectors) IdmContractSlice_(eu.bcvsolutions.idm.core.model.entity.IdmContractSlice_) Serializable(java.io.Serializable) SysSyncContractConfig_(eu.bcvsolutions.idm.acc.entity.SysSyncContractConfig_) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) IdmScheduledTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmScheduledTaskService) SelectCurrentContractSliceTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.SelectCurrentContractSliceTaskExecutor) List(java.util.List) EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) HrEnableContractProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrEnableContractProcess) IdmContractSliceService(eu.bcvsolutions.idm.core.api.service.IdmContractSliceService) IdmTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmTreeNodeService) BooleanUtils(org.apache.commons.lang3.BooleanUtils) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) CollectionUtils(org.apache.commons.collections4.CollectionUtils) IdmTreeNode_(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode_) MessageFormat(java.text.MessageFormat) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) CorrelationFilter(eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter) IdmContractSliceGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractSliceGuaranteeService) AccContractSliceAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractSliceAccountDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) 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) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AccContractSliceAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractSliceAccountFilter) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) SyncIdentityContractDto(eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SchedulableTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulableTaskExecutor) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) Component(org.springframework.stereotype.Component) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) ProvisioningService(eu.bcvsolutions.idm.acc.service.api.ProvisioningService) SynchronizationEntityExecutor(eu.bcvsolutions.idm.acc.service.api.SynchronizationEntityExecutor) AccContractSliceAccountService(eu.bcvsolutions.idm.acc.service.api.AccContractSliceAccountService) ContractSliceManager(eu.bcvsolutions.idm.core.api.service.ContractSliceManager) Assert(org.springframework.util.Assert) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SyncIdentityContractDto(eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)

Example 8 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.

the class ContractSliceSynchronizationExecutor method isGuaranteesSame.

/**
 * Check if current contract's slices guarantees are same as in account values
 *
 * @param dto
 * @param newGuarantees
 * @return
 */
private boolean isGuaranteesSame(IdmContractSliceDto dto, List<IdmIdentityDto> newGuarantees) {
    // Guarantees
    IdmContractSliceGuaranteeFilter guaranteeFilter = new IdmContractSliceGuaranteeFilter();
    guaranteeFilter.setContractSliceId(dto.getId());
    List<IdmContractSliceGuaranteeDto> currentGuarantees = guaranteeService.find(guaranteeFilter, null).getContent();
    List<UUID> currentGuranteeIds = currentGuarantees.stream().map(gurrantee -> {
        return gurrantee.getGuarantee();
    }).collect(Collectors.toList());
    List<UUID> newGuranteeIds = newGuarantees.stream().map(gurrantee -> {
        return gurrantee.getId();
    }).collect(Collectors.toList());
    return CollectionUtils.isEqualCollection(currentGuranteeIds, newGuranteeIds);
}
Also used : OperationResultType(eu.bcvsolutions.idm.acc.domain.OperationResultType) ContractSliceGuaranteeEventType(eu.bcvsolutions.idm.core.model.event.ContractSliceGuaranteeEvent.ContractSliceGuaranteeEventType) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) ZonedDateTime(java.time.ZonedDateTime) ContractSliceEventType(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent.ContractSliceEventType) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ClearDirtyStateForContractSliceTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ClearDirtyStateForContractSliceTaskExecutor) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) ProcessAllAutomaticRoleByAttributeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAllAutomaticRoleByAttributeTaskExecutor) StringUtils(org.apache.commons.lang3.StringUtils) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) ContractSliceGuaranteeEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceGuaranteeEvent) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) EntityAccountService(eu.bcvsolutions.idm.acc.service.api.EntityAccountService) 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) ImmutableMap(com.google.common.collect.ImmutableMap) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) HrEndContractProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrEndContractProcess) UUID(java.util.UUID) SchedulerManager(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulerManager) Collectors(java.util.stream.Collectors) IdmContractSlice_(eu.bcvsolutions.idm.core.model.entity.IdmContractSlice_) Serializable(java.io.Serializable) SysSyncContractConfig_(eu.bcvsolutions.idm.acc.entity.SysSyncContractConfig_) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) IdmScheduledTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmScheduledTaskService) SelectCurrentContractSliceTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.SelectCurrentContractSliceTaskExecutor) List(java.util.List) EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) HrEnableContractProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrEnableContractProcess) IdmContractSliceService(eu.bcvsolutions.idm.core.api.service.IdmContractSliceService) IdmTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmTreeNodeService) BooleanUtils(org.apache.commons.lang3.BooleanUtils) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) CollectionUtils(org.apache.commons.collections4.CollectionUtils) IdmTreeNode_(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode_) MessageFormat(java.text.MessageFormat) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) CorrelationFilter(eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter) IdmContractSliceGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractSliceGuaranteeService) AccContractSliceAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractSliceAccountDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) 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) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AccContractSliceAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractSliceAccountFilter) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) SyncIdentityContractDto(eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SchedulableTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulableTaskExecutor) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) Component(org.springframework.stereotype.Component) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) ProvisioningService(eu.bcvsolutions.idm.acc.service.api.ProvisioningService) SynchronizationEntityExecutor(eu.bcvsolutions.idm.acc.service.api.SynchronizationEntityExecutor) AccContractSliceAccountService(eu.bcvsolutions.idm.acc.service.api.AccContractSliceAccountService) ContractSliceManager(eu.bcvsolutions.idm.core.api.service.ContractSliceManager) Assert(org.springframework.util.Assert) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) UUID(java.util.UUID)

Example 9 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.

the class ClearDirtyStateForContractSliceTaskExecutor method process.

@Override
public OperationResult process() {
    boolean canContinue = true;
    List<IdmEntityStateDto> dirtyStates = findAllDirtyStatesForSlices(null).getContent();
    if (count == null) {
        count = Long.valueOf(dirtyStates.size());
    }
    counter = 0l;
    List<IdmEntityStateDto> updateDirtyStates = Lists.newArrayList();
    List<IdmEntityStateDto> validDirtyStates = Lists.newArrayList();
    List<IdmEntityStateDto> futureDirtyStates = Lists.newArrayList();
    List<IdmEntityStateDto> unvalidDirtyStates = Lists.newArrayList();
    List<IdmEntityStateDto> deleteDirtyStates = Lists.newArrayList();
    dirtyStates.forEach(dirtyState -> {
        ResultModel resultModel = dirtyState.getResult().getModel();
        Map<String, Object> parameters = new HashMap<>();
        if (resultModel != null) {
            parameters = resultModel.getParameters();
        }
        boolean sliceIsToDelete = this.getBooleanProperty(ClearDirtyStateForContractSliceTaskExecutor.TO_DELETE, parameters);
        if (sliceIsToDelete) {
            deleteDirtyStates.add(dirtyState);
        } else {
            updateDirtyStates.add(dirtyState);
        }
    });
    updateDirtyStates.forEach(dirtyState -> {
        IdmContractSliceDto contractSliceDto = contractSliceService.get(dirtyState.getOwnerId());
        if (contractSliceDto == null) {
            DefaultResultModel model = new DefaultResultModel(CoreResultCode.NOT_FOUND, ImmutableMap.of("ownerId", dirtyState.getOwnerId()));
            this.logItemProcessed(dirtyState, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(model).build());
            return;
        }
        // Temporary put current slice to the dirtyState
        dirtyState.getEmbedded().put(CURRENT_SLICE, contractSliceDto);
        // Divide slices by validity
        IdmIdentityContractDto mockContract = new IdmIdentityContractDto();
        contractSliceManager.convertSliceToContract(contractSliceDto, mockContract);
        if (!mockContract.isValidNowOrInFuture()) {
            unvalidDirtyStates.add(dirtyState);
        } else if (mockContract.isValid()) {
            validDirtyStates.add(dirtyState);
        } else {
            futureDirtyStates.add(dirtyState);
        }
    });
    // Process for new and updated slices - valid
    for (IdmEntityStateDto dirtyState : validDirtyStates) {
        canContinue = processState(canContinue, dirtyState);
        if (!canContinue) {
            break;
        }
    }
    // Process for new and updated slices - future valid
    for (IdmEntityStateDto dirtyState : futureDirtyStates) {
        canContinue = processState(canContinue, dirtyState);
        if (!canContinue) {
            break;
        }
    }
    // Process for new and updated slices - invalid
    for (IdmEntityStateDto dirtyState : unvalidDirtyStates) {
        canContinue = processState(canContinue, dirtyState);
        if (!canContinue) {
            break;
        }
    }
    // Process for slices to delete
    for (IdmEntityStateDto dirtyState : deleteDirtyStates) {
        Assert.notNull(dirtyState, "State (dirty) is required.");
        Assert.notNull(dirtyState.getId(), "State identifier (dirty) is required.");
        processItemToDelete(dirtyState);
        counter++;
        // clear it (same behavior as in stateful tasks)
        if (getHibernateSession().isOpen()) {
            getHibernateSession().flush();
            getHibernateSession().clear();
        }
        canContinue &= this.updateState();
        if (!canContinue) {
            break;
        }
    }
    return new OperationResult(OperationState.EXECUTED);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) HashMap(java.util.HashMap) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 10 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.

the class ClearDirtyStateForContractSliceTaskExecutor method processItemToDelete.

/**
 * Process one dirty state for contract slice to delete
 *
 * @param dirtyState
 */
private void processItemToDelete(IdmEntityStateDto dirtyState) {
    try {
        if (dirtyState.getOwnerType() == null || !dirtyState.getOwnerType().equals(IdmContractSlice.class.getName())) {
            this.logItemProcessed(dirtyState, new OperationResult.Builder(OperationState.NOT_EXECUTED).build());
            return;
        }
        IdmContractSliceDto contractSliceDto = contractSliceService.get(dirtyState.getOwnerId());
        ;
        if (contractSliceDto == null) {
            DefaultResultModel model = new DefaultResultModel(CoreResultCode.NOT_FOUND, ImmutableMap.of("ownerId", dirtyState.getOwnerId()));
            this.logItemProcessed(dirtyState, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(model).build());
            return;
        }
        ResultModel resultModel = dirtyState.getResult().getModel();
        Map<String, Object> parameters = new HashMap<>();
        if (resultModel != null) {
            parameters = resultModel.getParameters();
        }
        // Transform saved parameters into map string and serializable value
        Map<String, Serializable> transformedParameters = transformParameters(parameters);
        EntityEvent<IdmContractSliceDto> event = new ContractSliceEvent(ContractSliceEventType.DELETE, contractSliceDto, transformedParameters);
        // Delete slice (with recalculation)
        contractSliceService.publish(event);
        this.logItemProcessed(contractSliceDto, new OperationResult.Builder(OperationState.EXECUTED).build());
    } catch (Exception e) {
        this.logItemProcessed(dirtyState, new OperationResult.Builder(OperationState.EXCEPTION).setCause(e).build());
    }
}
Also used : ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) Serializable(java.io.Serializable) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) HashMap(java.util.HashMap) IdmContractSlice(eu.bcvsolutions.idm.core.model.entity.IdmContractSlice) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)

Aggregations

IdmContractSliceDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)72 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)44 Test (org.junit.Test)44 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)42 IdmContractSliceFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter)36 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)35 ContractSliceEvent (eu.bcvsolutions.idm.core.model.event.ContractSliceEvent)26 UUID (java.util.UUID)22 IdmContractSliceGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto)21 IdmContractSliceGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter)21 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)20 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)19 HashMap (java.util.HashMap)19 ImmutableMap (com.google.common.collect.ImmutableMap)17 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)17 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)17 ContractSliceManager (eu.bcvsolutions.idm.core.api.service.ContractSliceManager)17 List (java.util.List)17 Autowired (org.springframework.beans.factory.annotation.Autowired)17 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)16