Search in sources :

Example 11 with IdmContractPositionDto

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

the class DefaultIdmIdentityContractServiceIntegrationTest method testSkipAndAssignAutomaticRoleOnPositionAfterChange.

@Test
public void testSkipAndAssignAutomaticRoleOnPositionAfterChange() {
    IdmTreeNodeDto otherNode = getHelper().createTreeNode();
    IdmTreeNodeDto node = getHelper().createTreeNode();
    // define automatic role for parent
    IdmRoleDto role = getHelper().createRole();
    IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, node, RecursionType.NO, true);
    // create identity with contract on node
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmContractPositionDto position = getHelper().createContractPosition(getHelper().getPrimeContract(identity), otherNode);
    // no role should be assigned now
    List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertTrue(assignedRoles.isEmpty());
    // 
    position.setWorkPosition(node.getId());
    EntityEvent<IdmContractPositionDto> event = new ContractPositionEvent(ContractPositionEventType.UPDATE, position);
    event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
    position = contractPositionService.publish(event).getContent();
    UUID positionId = position.getId();
    IdmEntityStateFilter filter = new IdmEntityStateFilter();
    filter.setStates(Lists.newArrayList(OperationState.BLOCKED));
    filter.setResultCode(CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
    filter.setOwnerType(entityStateManager.getOwnerType(IdmContractPositionDto.class));
    List<IdmEntityStateDto> skippedStates = entityStateManager.findStates(filter, null).getContent();
    Assert.assertTrue(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(positionId)));
    // 
    assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertTrue(assignedRoles.isEmpty());
    // 
    // recount skipped automatic roles
    longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor());
    skippedStates = entityStateManager.findStates(filter, null).getContent();
    Assert.assertFalse(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(automaticRole.getId())));
    // 
    assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) 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) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor) ContractPositionEvent(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 12 with IdmContractPositionDto

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

the class ProcessAutomaticRoleByTreeTaskExecutor method processPositions.

private Set<UUID> processPositions(IdmRoleTreeNodeDto automaticRole) {
    Set<UUID> processedRoles = new HashSet<>();
    // 
    IdmContractPositionFilter filter = new IdmContractPositionFilter();
    filter.setWorkPosition(automaticRole.getTreeNode());
    filter.setRecursionType(automaticRole.getRecursionType());
    filter.setValidNowOrInFuture(Boolean.TRUE);
    Pageable pageable = PageRequest.of(0, getPageSize(), new Sort(Direction.ASC, BaseEntity.PROPERTY_ID));
    boolean canContinue = true;
    // 
    do {
        Page<IdmContractPositionDto> positions = contractPositionService.find(filter, pageable);
        // 
        for (Iterator<IdmContractPositionDto> i = positions.iterator(); i.hasNext() && canContinue; ) {
            IdmContractPositionDto position = i.next();
            UUID contractId = position.getId();
            // 
            if (!requireNewTransaction()) {
                processedRoles.addAll(processPosition(position, automaticRole));
            } else {
                TransactionTemplate template = new TransactionTemplate(platformTransactionManager);
                template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
                // 
                try {
                    template.execute(new TransactionCallbackWithoutResult() {

                        @Override
                        public void doInTransactionWithoutResult(TransactionStatus status) {
                            processedRoles.addAll(processPosition(position, automaticRole));
                        }
                    });
                } catch (UnexpectedRollbackException ex) {
                    // Just log for sure ... exception solved in new transaction, but this lower transaction is marked as roll-back.
                    LOG.debug("Statefull process [{}] processed contract [{}] failed", getClass().getSimpleName(), contractId, ex);
                }
            }
            // 
            if (!this.updateState()) {
                LOG.debug("Task [{}] was canceled.", getLongRunningTaskId());
                // return null => not continue with role removal
                return null;
            }
        }
        canContinue &= positions.hasNext();
        pageable = positions.nextPageable();
    // 
    } while (canContinue);
    // 
    return processedRoles;
}
Also used : IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) UUID(java.util.UUID) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) HashSet(java.util.HashSet)

Example 13 with IdmContractPositionDto

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

the class DefaultIdentityProjectionManagerIntegrationTest method testProjectionDontSaveOtherContractsAndPositions.

@Test
@Transactional
public void testProjectionDontSaveOtherContractsAndPositions() {
    IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
    formProjection.setCode(getHelper().createName());
    formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
    formProjection = projectionService.save(formProjection);
    // 
    IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
    identity.setFormProjection(formProjection.getId());
    IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
    // 
    // set contract
    IdmIdentityContractDto primeContract = new IdmIdentityContractDto();
    primeContract.setMain(true);
    primeContract.setWorkPosition(getHelper().createTreeNode().getId());
    primeContract.setPosition(getHelper().createName());
    primeContract.setValidFrom(LocalDate.now().minus(1l, ChronoUnit.DAYS));
    primeContract.setValidFrom(LocalDate.now().plus(1l, ChronoUnit.DAYS));
    projection.setContract(primeContract);
    // 
    // set other contract
    IdmIdentityContractDto otherContractOne = new IdmIdentityContractDto();
    otherContractOne.setWorkPosition(getHelper().createTreeNode().getId());
    otherContractOne.setPosition(getHelper().createName());
    // preset uuid
    IdmIdentityContractDto otherContractTwo = new IdmIdentityContractDto(UUID.randomUUID());
    otherContractTwo.setWorkPosition(getHelper().createTreeNode().getId());
    otherContractTwo.setPosition(getHelper().createName());
    projection.setOtherContracts(Lists.newArrayList(otherContractOne, otherContractTwo));
    // 
    // set other contract position
    IdmContractPositionDto positionOne = new IdmContractPositionDto();
    positionOne.setWorkPosition(getHelper().createTreeNode().getId());
    positionOne.setPosition(getHelper().createName());
    IdmContractPositionDto positionTwo = new IdmContractPositionDto();
    positionTwo.setWorkPosition(getHelper().createTreeNode().getId());
    positionTwo.setPosition(getHelper().createName());
    positionTwo.setIdentityContract(otherContractTwo.getId());
    projection.setOtherPositions(Lists.newArrayList(positionOne, positionTwo));
    IdmIdentityProjectionDto createdProjection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
    // other contract
    Assert.assertTrue(createdProjection.getOtherContracts().isEmpty());
    // other position
    Assert.assertTrue(createdProjection.getOtherPositions().isEmpty());
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with IdmContractPositionDto

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

the class IdmContractPositionControllerRestTest method testFilterByContract.

@Test
public void testFilterByContract() {
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity);
    IdmIdentityContractDto otherContract = getHelper().createContract(identity);
    // 
    IdmContractPositionDto dtoOne = createDto(new IdmContractPositionDto(primeContract.getId(), null));
    // other
    createDto(new IdmContractPositionDto(otherContract.getId(), null));
    // 
    IdmContractPositionFilter filter = new IdmContractPositionFilter();
    filter.setIdentityContractId(primeContract.getId());
    // 
    List<IdmContractPositionDto> results = find(filter);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(dtoOne.getId(), results.get(0).getId());
}
Also used : IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 15 with IdmContractPositionDto

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

the class IdmContractPositionControllerRestTest method testFilterByWorkPosition.

@Test
public void testFilterByWorkPosition() {
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity);
    // 
    IdmTreeNodeDto treeNodeOne = getHelper().createTreeNode();
    IdmContractPositionDto dtoOne = createDto(new IdmContractPositionDto(primeContract.getId(), treeNodeOne.getId()));
    // other
    createDto(new IdmContractPositionDto(primeContract.getId(), getHelper().createTreeNode().getId()));
    // 
    IdmContractPositionFilter filter = new IdmContractPositionFilter();
    filter.setWorkPosition(treeNodeOne.getId());
    // 
    List<IdmContractPositionDto> results = find(filter);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(dtoOne.getId(), results.get(0).getId());
}
Also used : IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Aggregations

IdmContractPositionDto (eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto)40 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)37 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)30 Test (org.junit.Test)29 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)22 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)21 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)18 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)18 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)14 Transactional (org.springframework.transaction.annotation.Transactional)14 IdmContractPositionFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter)12 UUID (java.util.UUID)10 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 List (java.util.List)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)7 EntityEvent (eu.bcvsolutions.idm.core.api.event.EntityEvent)6 IdmIdentityContractService (eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService)6 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)6 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)5