Search in sources :

Example 1 with ClearDirtyStateForContractSliceTaskExecutor

use of eu.bcvsolutions.idm.core.scheduler.task.impl.ClearDirtyStateForContractSliceTaskExecutor 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 2 with ClearDirtyStateForContractSliceTaskExecutor

use of eu.bcvsolutions.idm.core.scheduler.task.impl.ClearDirtyStateForContractSliceTaskExecutor in project CzechIdMng by bcvsolutions.

the class ContractSliceSynchronizationExecutor method executeClearDirtyStateForContractSlice.

/**
 * Execute {@link SelectCurrentContractSliceTaskExecutor}
 *
 * @param log
 * @return
 */
private SysSyncLogDto executeClearDirtyStateForContractSlice(SysSyncLogDto log) {
    ClearDirtyStateForContractSliceTaskExecutor executor = new ClearDirtyStateForContractSliceTaskExecutor();
    log.addToLog(MessageFormat.format("After success sync have to be run clear dirty state for contract slices. We start him (synchronously) now [{0}].", ZonedDateTime.now()));
    OperationResult executeSync = longRunningTaskManager.executeSync(executor);
    if (executeSync != null) {
        if (executeSync.getState() == OperationState.EXECUTED) {
            log.addToLog(MessageFormat.format("Clear dirty state end in [{0}].", ZonedDateTime.now()));
        } else if (executeSync.getState() == OperationState.EXCEPTION) {
            log.addToLog(MessageFormat.format("Warning - clear dirty state is not executed correctly. Ended in [{0}].", ZonedDateTime.now()));
        }
    } else {
        log.addToLog(MessageFormat.format("Warning - select corrent contract slice is not executed correctly, Returned operation result is null. Ended in [{0}].", ZonedDateTime.now()));
    }
    return log;
}
Also used : ClearDirtyStateForContractSliceTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ClearDirtyStateForContractSliceTaskExecutor) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult)

Example 3 with ClearDirtyStateForContractSliceTaskExecutor

use of eu.bcvsolutions.idm.core.scheduler.task.impl.ClearDirtyStateForContractSliceTaskExecutor in project CzechIdMng by bcvsolutions.

the class ContractSliceManagerTest method clearStateExecutorTest.

@Test
public void clearStateExecutorTest() {
    IdmIdentityDto identity = this.getHelper().createIdentity();
    // remove all contracts
    List<IdmIdentityContractDto> allByIdentity = contractService.findAllByIdentity(identity.getId());
    allByIdentity.forEach(contract -> {
        contractService.delete(contract);
    });
    IdmContractSliceDto slice = new IdmContractSliceDto();
    slice.setContractCode("test");
    slice.setIdentity(identity.getId());
    slice.setValidFrom(LocalDate.now().minusDays(1));
    slice.setValidTill(LocalDate.now().plusDays(5));
    slice.setContractValidFrom(LocalDate.now().minusDays(50));
    slice.setMain(true);
    IdmContractSliceDto sliceTwo = new IdmContractSliceDto();
    sliceTwo.setContractCode("test");
    sliceTwo.setIdentity(identity.getId());
    sliceTwo.setValidFrom(LocalDate.now().minusDays(10));
    sliceTwo.setValidTill(LocalDate.now().minusDays(2));
    sliceTwo.setContractValidFrom(LocalDate.now().minusDays(50));
    sliceTwo.setMain(true);
    EventContext<IdmContractSliceDto> eventContextOne = contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.CREATE, slice, ImmutableMap.of(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, Boolean.TRUE)));
    EventContext<IdmContractSliceDto> eventContextTwo = contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.CREATE, sliceTwo, ImmutableMap.of(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, Boolean.TRUE)));
    // slice has skip recalculation and dirty state isn't create
    allByIdentity = contractService.findAllByIdentity(identity.getId());
    assertTrue(allByIdentity.isEmpty());
    List<IdmEntityStateDto> dirtyStates = findDirtyStatesForSlice(null);
    assertFalse(dirtyStates.isEmpty());
    assertEquals(2, dirtyStates.size());
    ClearDirtyStateForContractSliceTaskExecutor executor = new ClearDirtyStateForContractSliceTaskExecutor();
    OperationResult result = longRunningTaskManager.executeSync(executor);
    assertEquals(OperationState.EXECUTED, result.getState());
    dirtyStates = findDirtyStatesForSlice(null);
    assertTrue(dirtyStates.isEmpty());
    assertEquals(0, dirtyStates.size());
    allByIdentity = contractService.findAllByIdentity(identity.getId());
    assertEquals(1, allByIdentity.size());
    IdmIdentityContractDto contractDto = allByIdentity.get(0);
    assertTrue(contractDto.getControlledBySlices());
    assertEquals(LocalDate.now().minusDays(50), contractDto.getValidFrom());
    // Delete unused slices
    contractSliceService.delete(eventContextOne.getContent());
    contractSliceService.delete(eventContextTwo.getContent());
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) ClearDirtyStateForContractSliceTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ClearDirtyStateForContractSliceTaskExecutor) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with ClearDirtyStateForContractSliceTaskExecutor

use of eu.bcvsolutions.idm.core.scheduler.task.impl.ClearDirtyStateForContractSliceTaskExecutor in project CzechIdMng by bcvsolutions.

the class ContractSliceManagerTest method clearStateExecutorPageTest.

@Test
public void clearStateExecutorPageTest() {
    IdmIdentityDto identity = this.getHelper().createIdentity();
    List<IdmEntityStateDto> dirtyStates = findAllDirtyStatesForSlices();
    assertEquals(0, dirtyStates.size());
    for (int index = 0; index < 21; index++) {
        IdmContractSliceDto createContractSlice = this.getHelper().createContractSlice(identity);
        createDirtyState(createContractSlice);
    }
    dirtyStates = findAllDirtyStatesForSlices();
    assertEquals(21, dirtyStates.size());
    ClearDirtyStateForContractSliceTaskExecutor executor = new ClearDirtyStateForContractSliceTaskExecutor();
    OperationResult result = longRunningTaskManager.executeSync(executor);
    assertEquals(OperationState.EXECUTED, result.getState());
    dirtyStates = findAllDirtyStatesForSlices();
    assertEquals(0, dirtyStates.size());
    IdmLongRunningTaskDto taskDto = longRunningTaskService.get(executor.getLongRunningTaskId());
    assertNotNull(taskDto.getCount());
    assertNotNull(taskDto.getCounter());
    assertEquals(21, taskDto.getCount().longValue());
    assertEquals(21, taskDto.getCounter().longValue());
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) ClearDirtyStateForContractSliceTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ClearDirtyStateForContractSliceTaskExecutor) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)4 ClearDirtyStateForContractSliceTaskExecutor (eu.bcvsolutions.idm.core.scheduler.task.impl.ClearDirtyStateForContractSliceTaskExecutor)4 IdmContractSliceDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)2 ContractSliceEvent (eu.bcvsolutions.idm.core.model.event.ContractSliceEvent)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 AccResultCode (eu.bcvsolutions.idm.acc.domain.AccResultCode)1 AttributeMapping (eu.bcvsolutions.idm.acc.domain.AttributeMapping)1 OperationResultType (eu.bcvsolutions.idm.acc.domain.OperationResultType)1 SynchronizationActionType (eu.bcvsolutions.idm.acc.domain.SynchronizationActionType)1 SynchronizationContext (eu.bcvsolutions.idm.acc.domain.SynchronizationContext)1 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)1 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)1 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)1 AccContractSliceAccountDto (eu.bcvsolutions.idm.acc.dto.AccContractSliceAccountDto)1 EntityAccountDto (eu.bcvsolutions.idm.acc.dto.EntityAccountDto)1 SyncIdentityContractDto (eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto)1 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)1 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)1