Search in sources :

Example 21 with IdmLongRunningTaskFilter

use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityContractServiceIntegrationTest method testAutomaticRolesRemovalAfterContractEnds.

@Test
public void testAutomaticRolesRemovalAfterContractEnds() {
    // automatic roles by tree structure
    prepareAutomaticRoles();
    // automatic role by attribute on contract
    String autoPosition = getHelper().createName();
    IdmRoleDto autoAttributeRole = getHelper().createRole();
    IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(autoAttributeRole.getId());
    getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT, IdmIdentityContract_.position.getName(), null, autoPosition);
    // 
    // prepare identity, contract, direct roles and automatic roles
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = service.getPrimeContract(identity.getId());
    contract.setIdentity(identity.getId());
    contract.setValidFrom(LocalDate.now().minusDays(1));
    contract.setValidTill(LocalDate.now().plusMonths(1));
    contract.setWorkPosition(nodeD.getId());
    contract.setMain(true);
    contract.setDescription("test-node-d");
    contract.setPosition(autoPosition);
    contract = service.save(contract);
    UUID contractId = contract.getId();
    IdmRoleDto directRole = getHelper().createRole();
    getHelper().createIdentityRole(contract, directRole);
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
    Assert.assertEquals(5, identityRoles.size());
    Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
        return roleA.getId().equals(ir.getRole());
    }));
    Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
        return roleB.getId().equals(ir.getRole());
    }));
    Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
        return roleC.getId().equals(ir.getRole());
    }));
    Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
        return directRole.getId().equals(ir.getRole());
    }));
    Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
        return autoAttributeRole.getId().equals(ir.getRole());
    }));
    // 
    try {
        getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
        // 
        // end contract - all roles should be removed, after asynchronous role request ends
        contract.setValidTill(LocalDate.now().minusDays(1));
        contract = service.save(contract);
        // 
        Assert.assertFalse(contract.isValidNowOrInFuture());
        // 
        getHelper().waitForResult(res -> {
            return !identityRoleService.findAllByContract(contractId).isEmpty();
        }, 300, Integer.MAX_VALUE);
        getHelper().waitForResult(res -> {
            IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
            filter.setRunning(Boolean.TRUE);
            // 
            return taskManager.findLongRunningTasks(filter, null).getTotalElements() != 0;
        });
        // 
        identityRoles = identityRoleService.findAllByContract(contract.getId());
        Assert.assertTrue(identityRoles.isEmpty());
        // 
        service.delete(contract);
    } finally {
        getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
    }
}
Also used : Lists(org.testng.collections.Lists) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) ProcessAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) LongRunningTaskEventType(eu.bcvsolutions.idm.core.scheduler.api.event.LongRunningTaskEvent.LongRunningTaskEventType) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) RecursionType(eu.bcvsolutions.idm.core.api.domain.RecursionType) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) ContractPositionEventType(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent.ContractPositionEventType) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) LongRunningFutureTask(eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask) Set(java.util.Set) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) RemoveAutomaticRoleTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.RemoveAutomaticRoleTaskExecutor) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) ContractBasePermission(eu.bcvsolutions.idm.core.security.api.domain.ContractBasePermission) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) ContractPositionEvent(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmContractPositionService(eu.bcvsolutions.idm.core.api.service.IdmContractPositionService) IdmTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmTreeNodeService) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) PermissionContext(eu.bcvsolutions.idm.core.api.dto.filter.PermissionContext) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) 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) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) SchedulerConfiguration(eu.bcvsolutions.idm.core.scheduler.api.config.SchedulerConfiguration) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) IdmContractGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService) ApplicationContext(org.springframework.context.ApplicationContext) IdmIdentityContract_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) PrivateIdentityConfiguration(eu.bcvsolutions.idm.core.api.config.domain.PrivateIdentityConfiguration) AutomaticRoleAttributeRuleComparison(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) IdentityConfiguration(eu.bcvsolutions.idm.core.api.config.domain.IdentityConfiguration) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 22 with IdmLongRunningTaskFilter

use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.

the class IdentityInitUniformPasswordProcessor method conditional.

@Override
public boolean conditional(EntityEvent<IdmIdentityDto> event) {
    UUID identityId = event.getContent().getId();
    UUID transactionId = event.getContent().getTransactionId();
    if (identityId == null || transactionId == null) {
        return false;
    }
    IdmLongRunningTaskFilter longRunningTaskFilter = new IdmLongRunningTaskFilter();
    longRunningTaskFilter.setTransactionId(transactionId);
    longRunningTaskFilter.setRunning(Boolean.TRUE);
    // TODO: Check only for contract sync?
    longRunningTaskFilter.setTaskType(SynchronizationSchedulableTaskExecutor.class.getCanonicalName());
    long count = longRunningTaskService.count(longRunningTaskFilter);
    return super.conditional(event) && count > 0;
}
Also used : SynchronizationSchedulableTaskExecutor(eu.bcvsolutions.idm.acc.scheduler.task.impl.SynchronizationSchedulableTaskExecutor) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) UUID(java.util.UUID)

Example 23 with IdmLongRunningTaskFilter

use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.

the class LongRunningTaskCancelBulkActionIntegrationTest method testProcessBulkActionByFilter.

@Test
public void testProcessBulkActionByFilter() {
    List<IdmLongRunningTaskDto> tasks = createTasks(5);
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
    filter.setId(tasks.get(2).getId());
    List<IdmLongRunningTaskDto> checkEvents = service.find(filter, null).getContent();
    Assert.assertEquals(1, checkEvents.size());
    IdmBulkActionDto bulkAction = findBulkAction(IdmLongRunningTask.class, LongRunningTaskCancelBulkAction.NAME);
    bulkAction.setTransformedFilter(filter);
    bulkAction.setFilter(toMap(filter));
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    checkResultLrt(processAction, 1l, null, null);
    Assert.assertEquals(OperationState.CANCELED, service.get(tasks.get(2)).getResultState());
    Assert.assertEquals(OperationState.RUNNING, service.get(tasks.get(1)).getResultState());
    Assert.assertEquals(OperationState.RUNNING, service.get(tasks.get(3)).getResultState());
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 24 with IdmLongRunningTaskFilter

use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.

the class AbstractSchedulableStatefulExecutorIntegrationTest method getContext.

/**
 * LRT with loaded counters.
 *
 * @return
 */
private IdmLongRunningTaskFilter getContext() {
    IdmLongRunningTaskFilter context = new IdmLongRunningTaskFilter();
    context.setIncludeItemCounts(true);
    // 
    return context;
}
Also used : IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter)

Example 25 with IdmLongRunningTaskFilter

use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.

the class LongRunningTaskDeleteBulkActionIntegrationTest method testPreventDeleteItself.

@Test
public void testPreventDeleteItself() {
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
    filter.setTaskType(LongRunningTaskDeleteBulkAction.class.getCanonicalName());
    // 
    IdmBulkActionDto bulkAction = findBulkAction(IdmLongRunningTask.class, LongRunningTaskDeleteBulkAction.NAME);
    bulkAction.setTransformedFilter(filter);
    bulkAction.setFilter(toMap(filter));
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    checkResultLrt(processAction, null, 0L, 0L);
    Assert.assertEquals(OperationState.EXECUTED, service.get(bulkAction.getLongRunningTaskId()).getResultState());
}
Also used : IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Aggregations

IdmLongRunningTaskFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter)54 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)41 Test (org.junit.Test)31 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)21 UUID (java.util.UUID)18 Transactional (org.springframework.transaction.annotation.Transactional)11 AbstractBulkActionTest (eu.bcvsolutions.idm.test.api.AbstractBulkActionTest)9 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)8 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)8 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)8 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)8 List (java.util.List)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 LongRunningFutureTask (eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask)7 Assert (org.junit.Assert)7 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)6 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)5 EventConfiguration (eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration)5 AutomaticRoleAttributeRuleComparison (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison)5 AutomaticRoleAttributeRuleType (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType)5