Search in sources :

Example 26 with IdmContractPositionDto

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

the class DefaultIdentityProjectionManagerIntegrationTest method testGetProjectionWithoutContractAuthority.

@Test
@Transactional
public void testGetProjectionWithoutContractAuthority() {
    String defaultRoleCode = roleConfiguration.getDefaultRoleCode();
    // create identity with update identity permission only
    // with password
    IdmIdentityDto identityLogged = getHelper().createIdentity();
    IdmRoleDto role = getHelper().createRole();
    // read all
    getHelper().createBasePolicy(role.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.READ, IdmBasePermission.UPDATE);
    getHelper().createIdentityRole(identityLogged, role);
    // 
    IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
    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));
    // 
    projection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
    // assigned roles
    getHelper().createIdentityRole(projection.getIdentity(), role);
    try {
        // empty property => disable default role
        getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, "");
        // 
        getHelper().login(identityLogged);
        IdmIdentityProjectionDto createdProjection = manager.get(projection, IdmBasePermission.READ);
        // 
        Assert.assertNotNull(createdProjection);
        Assert.assertNull(createdProjection.getContract());
        Assert.assertTrue(createdProjection.getOtherContracts().isEmpty());
        Assert.assertTrue(createdProjection.getOtherPositions().isEmpty());
        Assert.assertTrue(createdProjection.getIdentityRoles().isEmpty());
        // 
        createdProjection = manager.get(projection);
        // 
        Assert.assertNotNull(createdProjection);
        Assert.assertNotNull(createdProjection.getContract());
        Assert.assertFalse(createdProjection.getOtherContracts().isEmpty());
        Assert.assertFalse(createdProjection.getOtherPositions().isEmpty());
        Assert.assertFalse(createdProjection.getIdentityRoles().isEmpty());
    } finally {
        logout();
        getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, defaultRoleCode);
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) 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 27 with IdmContractPositionDto

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

the class DefaultIdentityProjectionManagerIntegrationTest method testDeleteOtherContractAndPosition.

@Test
@Transactional
public void testDeleteOtherContractAndPosition() {
    // 
    IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
    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.assertEquals(2, createdProjection.getOtherContracts().size());
    Assert.assertTrue(createdProjection.getOtherContracts().stream().anyMatch(c -> {
        return c.getWorkPosition().equals(otherContractOne.getWorkPosition()) && c.getPosition().equals(otherContractOne.getPosition());
    }));
    Assert.assertTrue(createdProjection.getOtherContracts().stream().anyMatch(c -> {
        return c.getWorkPosition().equals(otherContractTwo.getWorkPosition()) && c.getPosition().equals(otherContractTwo.getPosition()) && // preserve id
        c.getId().equals(otherContractTwo.getId());
    }));
    // other position
    Assert.assertEquals(2, createdProjection.getOtherPositions().size());
    Assert.assertTrue(createdProjection.getOtherPositions().stream().anyMatch(p -> {
        return p.getWorkPosition().equals(positionOne.getWorkPosition()) && p.getPosition().equals(positionOne.getPosition()) && p.getIdentityContract().equals(createdProjection.getContract().getId());
    }));
    Assert.assertTrue(createdProjection.getOtherPositions().stream().anyMatch(p -> {
        return p.getWorkPosition().equals(positionTwo.getWorkPosition()) && p.getPosition().equals(positionTwo.getPosition()) && p.getIdentityContract().equals(positionTwo.getIdentityContract());
    }));
    // 
    // remove contract and position
    createdProjection.getOtherContracts().removeIf(c -> {
        return c.getWorkPosition().equals(otherContractOne.getWorkPosition()) && c.getPosition().equals(otherContractOne.getPosition());
    });
    createdProjection.getOtherPositions().removeIf(p -> {
        return p.getWorkPosition().equals(positionOne.getWorkPosition()) && p.getPosition().equals(positionOne.getPosition()) && p.getIdentityContract().equals(createdProjection.getContract().getId());
    });
    IdmIdentityProjectionDto updatedProjection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, createdProjection)).getContent();
    // other contract
    Assert.assertEquals(1, updatedProjection.getOtherContracts().size());
    Assert.assertTrue(updatedProjection.getOtherContracts().stream().anyMatch(c -> {
        return c.getWorkPosition().equals(otherContractTwo.getWorkPosition()) && c.getPosition().equals(otherContractTwo.getPosition()) && // preserve id
        c.getId().equals(otherContractTwo.getId());
    }));
    // other position
    Assert.assertEquals(1, updatedProjection.getOtherPositions().size());
    Assert.assertTrue(updatedProjection.getOtherPositions().stream().anyMatch(p -> {
        return p.getWorkPosition().equals(positionTwo.getWorkPosition()) && p.getPosition().equals(positionTwo.getPosition()) && p.getIdentityContract().equals(positionTwo.getIdentityContract());
    }));
}
Also used : Lists(org.testng.collections.Lists) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException) BigDecimal(java.math.BigDecimal) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) IdmIdentityFormValue(eu.bcvsolutions.idm.core.model.entity.eav.IdmIdentityFormValue) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) UUID(java.util.UUID) RoleConfiguration(eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) InvalidFormException(eu.bcvsolutions.idm.core.api.exception.InvalidFormException) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) LocalDate(java.time.LocalDate) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) MockMvcRequestBuilders.post(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post) IdmFormProjectionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormProjectionService) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdentityProjectionEventType(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent.IdentityProjectionEventType) IdentityFormValueEvaluator(eu.bcvsolutions.idm.core.security.evaluator.eav.IdentityFormValueEvaluator) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) ApplicationContext(org.springframework.context.ApplicationContext) IdmIdentityContract_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) ChronoUnit(java.time.temporal.ChronoUnit) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SelfIdentityEvaluator(eu.bcvsolutions.idm.core.security.evaluator.identity.SelfIdentityEvaluator) AutomaticRoleAttributeRuleComparison(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) BaseController(eu.bcvsolutions.idm.core.api.rest.BaseController) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) FormDefinitionAttributes(eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes) 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 28 with IdmContractPositionDto

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

the class TreeNodeDeleteBulkActionIntegrationTest method testForceDelete.

@Test
public void testForceDelete() {
    logout();
    loginAsAdmin();
    // create sub tree nodes, automatic roles, contract, contract positions
    IdmTreeNodeDto treeNode = getHelper().createTreeNode();
    IdmTreeNodeDto subTreeNode = getHelper().createTreeNode((String) null, treeNode);
    IdmTreeNodeDto subSubTreeNode = getHelper().createTreeNode((String) null, subTreeNode);
    IdmTreeNodeDto otherTreeNode = getHelper().createTreeNode();
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().createContract(identity, subTreeNode);
    IdmContractPositionDto contractPosition = getHelper().createContractPosition(contract, subSubTreeNode);
    IdmRoleDto role = getHelper().createRole();
    IdmIdentityRoleDto assignedRoleOne = getHelper().createIdentityRole(contract, role);
    IdmIdentityRoleDto assignedRoleTwo = getHelper().createIdentityRole(contractPosition, role);
    IdmIdentityRoleDto assignedRoleOther = getHelper().createIdentityRole(getHelper().getPrimeContract(identity), role);
    IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, treeNode, RecursionType.DOWN, false);
    // 
    // 3 manual, 2 automatic
    Assert.assertEquals(5, identityRoleService.findAllByIdentity(identity.getId()).size());
    // 
    // remove tree node
    Map<String, Object> properties = new HashMap<>();
    properties.put(EntityEventProcessor.PROPERTY_FORCE_DELETE, Boolean.TRUE);
    // delete by bulk action
    IdmBulkActionDto bulkAction = this.findBulkAction(IdmTreeNode.class, TreeNodeDeleteBulkAction.NAME);
    bulkAction.setIdentifiers(Sets.newHashSet(treeNode.getId()));
    bulkAction.setProperties(properties);
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    // 
    checkResultLrt(processAction, 1l, 0l, 0l);
    // 
    Assert.assertNull(treeNodeService.get(treeNode));
    Assert.assertNull(treeNodeService.get(subTreeNode));
    Assert.assertNull(treeNodeService.get(subSubTreeNode));
    Assert.assertNull(treeNodeService.get(subSubTreeNode));
    Assert.assertNotNull(identityRoleService.get(assignedRoleOne));
    Assert.assertNotNull(identityRoleService.get(assignedRoleTwo));
    Assert.assertNull(identityContractService.get(contract).getWorkPosition());
    Assert.assertNull(contractPositionService.get(contractPosition).getWorkPosition());
    Assert.assertNull(roleTreeNodeService.get(automaticRole));
    // 
    Assert.assertNotNull(treeNodeService.get(otherTreeNode));
    Assert.assertNotNull(getHelper().getPrimeContract(identity));
    Assert.assertNotNull(identityRoleService.get(assignedRoleOther));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) HashMap(java.util.HashMap) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 29 with IdmContractPositionDto

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

the class ContractSynchronizationExecutor method save.

/**
 * Save entity
 *
 * @param entity
 * @param skipProvisioning
 * @return
 */
@Override
protected IdmIdentityContractDto save(IdmIdentityContractDto entity, boolean skipProvisioning, SynchronizationContext context) {
    if (entity.getIdentity() == null) {
        throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_CANNOT_BE_NULL, ImmutableMap.of("property", CONTRACT_IDENTITY_FIELD));
    }
    EntityEvent<IdmIdentityContractDto> event = new IdentityContractEvent(contractService.isNew(entity) ? IdentityContractEventType.CREATE : IdentityContractEventType.UPDATE, entity, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
    // We do not want execute HR processes for every contract. We need start
    // them for every identity only once.
    // For this we skip them now. HR processes must be start after whole
    // sync finished (by using dependent scheduled task)!
    event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
    // 
    // We don't want recalculate automatic role by attribute recalculation for every
    // contract.
    // Recalculation will be started only once.
    event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
    EventContext<IdmIdentityContractDto> publishContext = contractService.publish(event);
    IdmIdentityContractDto contract = publishContext.getContent();
    // We need to flag recalculation for contract immediately to prevent synchronization ends before flag is created by NOTIFY event asynchronously.
    Map<String, Serializable> properties = new HashMap<>();
    EventResult<IdmIdentityContractDto> lastResult = publishContext.getLastResult();
    if (lastResult != null) {
        // original contract as property
        properties.put(EntityEvent.EVENT_PROPERTY_ORIGINAL_SOURCE, lastResult.getEvent().getOriginalSource());
    }
    if (contract.isValidNowOrInFuture()) {
        entityStateManager.createState(contract, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED, properties);
    } else {
        entityStateManager.createState(contract, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED_INVALID_CONTRACT, properties);
    }
    // 
    if (entity.getEmbedded().containsKey(SYNC_CONTRACT_FIELD)) {
        SyncIdentityContractDto syncContract = (SyncIdentityContractDto) entity.getEmbedded().get(SYNC_CONTRACT_FIELD);
        // Positions
        IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
        positionFilter.setIdentityContractId(contract.getId());
        List<IdmContractPositionDto> currentPositions = contractPositionService.find(positionFilter, null).getContent();
        // Search positions to delete
        List<IdmContractPositionDto> positionsToDelete = currentPositions.stream().filter(position -> {
            return position.getWorkPosition() != null && !syncContract.getPositions().contains(new IdmTreeNodeDto(position.getWorkPosition()));
        }).collect(Collectors.toList());
        // Search positions to add
        List<IdmTreeNodeDto> positionsToAdd = syncContract.getPositions().stream().filter(position -> {
            return !currentPositions.stream().filter(currentPosition -> {
                return position.getId().equals(currentPosition.getWorkPosition());
            }).findFirst().isPresent();
        }).collect(Collectors.toList());
        // Create new positions
        positionsToAdd.forEach(position -> {
            IdmContractPositionDto contractPosition = new IdmContractPositionDto();
            contractPosition.setIdentityContract(contract.getId());
            contractPosition.setWorkPosition(position.getId());
            // 
            EntityEvent<IdmContractPositionDto> positionEvent = new ContractPositionEvent(ContractPositionEventType.CREATE, contractPosition, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning, AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE));
            contractPosition = contractPositionService.publish(positionEvent).getContent();
            // We need to flag recalculation for contract immediately to prevent synchronization ends before flag is created by NOTIFY event asynchronously.
            if (contract.isValidNowOrInFuture()) {
                entityStateManager.createState(contractPosition, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED, null);
            }
        });
        // Delete positions - should be after new positions are created (prevent to drop and create => delete is sync).
        positionsToDelete.forEach(position -> {
            EntityEvent<IdmContractPositionDto> positionEvent = new ContractPositionEvent(ContractPositionEventType.DELETE, position, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning, AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE));
            contractPositionService.publish(positionEvent);
        });
        // Guarantees
        IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
        guaranteeFilter.setIdentityContractId(contract.getId());
        List<IdmContractGuaranteeDto> currentGuarantees = guaranteeService.find(guaranteeFilter, null).getContent();
        // Search guarantees to delete
        List<IdmContractGuaranteeDto> guaranteesToDelete = currentGuarantees.stream().filter(sysImplementer -> {
            return sysImplementer.getGuarantee() != null && !syncContract.getGuarantees().contains(new IdmIdentityDto(sysImplementer.getGuarantee()));
        }).collect(Collectors.toList());
        // Search guarantees to add
        List<IdmIdentityDto> guaranteesToAdd = syncContract.getGuarantees().stream().filter(identity -> {
            return !currentGuarantees.stream().filter(currentGuarrantee -> {
                return identity.getId().equals(currentGuarrantee.getGuarantee());
            }).findFirst().isPresent();
        }).collect(Collectors.toList());
        // Delete guarantees
        guaranteesToDelete.forEach(guarantee -> {
            EntityEvent<IdmContractGuaranteeDto> guaranteeEvent = new ContractGuaranteeEvent(ContractGuaranteeEventType.DELETE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
            guaranteeService.publish(guaranteeEvent);
        });
        // Create new guarantees
        guaranteesToAdd.forEach(identity -> {
            IdmContractGuaranteeDto guarantee = new IdmContractGuaranteeDto();
            guarantee.setIdentityContract(contract.getId());
            guarantee.setGuarantee(identity.getId());
            // 
            EntityEvent<IdmContractGuaranteeDto> guaranteeEvent = new ContractGuaranteeEvent(ContractGuaranteeEventType.CREATE, guarantee, ImmutableMap.of(ProvisioningService.SKIP_PROVISIONING, skipProvisioning));
            guaranteeService.publish(guaranteeEvent);
        });
    }
    return contract;
}
Also used : OperationResultType(eu.bcvsolutions.idm.acc.domain.OperationResultType) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) ZonedDateTime(java.time.ZonedDateTime) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) 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) ContractGuaranteeEventType(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent.ContractGuaranteeEventType) StringUtils(org.apache.commons.lang3.StringUtils) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) ContractGuaranteeEvent(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) EntityAccountService(eu.bcvsolutions.idm.acc.service.api.EntityAccountService) Map(java.util.Map) 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) 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) AccContractAccountService(eu.bcvsolutions.idm.acc.service.api.AccContractAccountService) 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) Serializable(java.io.Serializable) SysSyncContractConfig_(eu.bcvsolutions.idm.acc.entity.SysSyncContractConfig_) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) IdmScheduledTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmScheduledTaskService) List(java.util.List) EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) ContractPositionEvent(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) HrEnableContractProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrEnableContractProcess) AccContractAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractAccountFilter) IdmContractPositionService(eu.bcvsolutions.idm.core.api.service.IdmContractPositionService) IdmTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmTreeNodeService) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) 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) 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) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) CorrelationFilter(eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) 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) 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) IdmContractGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService) SchedulableTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulableTaskExecutor) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) 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) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) 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) AccContractAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractAccountDto) Assert(org.springframework.util.Assert) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) Serializable(java.io.Serializable) HashMap(java.util.HashMap) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) ContractPositionEvent(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) SyncIdentityContractDto(eu.bcvsolutions.idm.acc.dto.SyncIdentityContractDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) ContractGuaranteeEvent(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent)

Example 30 with IdmContractPositionDto

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

the class ContractSynchronizationExecutor method isPositionsSame.

/**
 * Check if current contract's positions are same as in account values
 *
 * @param dto
 * @param newPositions
 * @return
 */
private boolean isPositionsSame(IdmIdentityContractDto dto, List<IdmTreeNodeDto> newPositions) {
    // Find current positions
    IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
    positionFilter.setIdentityContractId(dto.getId());
    List<IdmContractPositionDto> currentPositions = contractPositionService.find(positionFilter, null).getContent();
    List<UUID> currentPositionsIds = currentPositions.stream().map(position -> {
        return position.getWorkPosition();
    }).collect(Collectors.toList());
    List<UUID> newPositionIds = newPositions.stream().map(position -> {
        return position.getId();
    }).collect(Collectors.toList());
    return CollectionUtils.isEqualCollection(currentPositionsIds, newPositionIds);
}
Also used : OperationResultType(eu.bcvsolutions.idm.acc.domain.OperationResultType) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) ZonedDateTime(java.time.ZonedDateTime) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) 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) ContractGuaranteeEventType(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent.ContractGuaranteeEventType) StringUtils(org.apache.commons.lang3.StringUtils) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) ContractGuaranteeEvent(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) EntityAccountService(eu.bcvsolutions.idm.acc.service.api.EntityAccountService) Map(java.util.Map) 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) 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) AccContractAccountService(eu.bcvsolutions.idm.acc.service.api.AccContractAccountService) 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) Serializable(java.io.Serializable) SysSyncContractConfig_(eu.bcvsolutions.idm.acc.entity.SysSyncContractConfig_) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) IdmScheduledTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmScheduledTaskService) List(java.util.List) EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) ContractPositionEvent(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) HrEnableContractProcess(eu.bcvsolutions.idm.core.scheduler.task.impl.hr.HrEnableContractProcess) AccContractAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractAccountFilter) IdmContractPositionService(eu.bcvsolutions.idm.core.api.service.IdmContractPositionService) IdmTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmTreeNodeService) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) 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) 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) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) CorrelationFilter(eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) 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) 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) IdmContractGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService) SchedulableTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulableTaskExecutor) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) 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) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) 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) AccContractAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractAccountDto) Assert(org.springframework.util.Assert) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) UUID(java.util.UUID)

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