Search in sources :

Example 6 with IdmContractPositionDto

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

the class DefaultIdmContractPositionServiceIntegrationTest method testAssingRoleByNewAutomaticRoleForExistingContracts.

@Test
public void testAssingRoleByNewAutomaticRoleForExistingContracts() {
    IdmRoleDto role = getHelper().createRole();
    IdmTreeNodeDto treeNode = getHelper().createTreeNode();
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
    IdmContractPositionDto position = getHelper().createContractPosition(contract, treeNode);
    // other
    getHelper().createContractPosition(contract, getHelper().createTreeNode());
    // 
    // TODO: this is really strange ... automatic role is assigned without automatic role id.
    IdmRoleTreeNodeDto automaticRole = new IdmRoleTreeNodeDto();
    automaticRole.setRecursionType(RecursionType.NO);
    automaticRole.setRole(role.getId());
    automaticRole.setTreeNode(treeNode.getId());
    automaticRole = saveAutomaticRole(automaticRole, true);
    // 
    List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
    Assert.assertEquals(position.getId(), assignedRoles.get(0).getContractPosition());
}
Also used : 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) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 7 with IdmContractPositionDto

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

the class DefaultIdmContractPositionServiceIntegrationTest method testReferentialIntegrityOnContractDelete.

@Test
@Transactional
public void testReferentialIntegrityOnContractDelete() {
    // prepare data
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().createContract(identity);
    getHelper().createContractPosition(contract);
    // 
    IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
    positionFilter.setIdentityContractId(contract.getId());
    List<IdmContractPositionDto> positions = service.find(positionFilter, null).getContent();
    Assert.assertEquals(1, positions.size());
    // 
    getHelper().deleteContract(contract.getId());
    // 
    positions = service.find(positionFilter, null).getContent();
    Assert.assertTrue(positions.isEmpty());
}
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) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with IdmContractPositionDto

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

the class DefaultIdmContractPositionServiceIntegrationTest method testAssingRoleForContractValidInTheFuture.

@Test
public void testAssingRoleForContractValidInTheFuture() {
    IdmRoleDto role = getHelper().createRole();
    IdmTreeNodeDto treeNode = getHelper().createTreeNode();
    IdmRoleTreeNodeDto automaticRole = getHelper().createAutomaticRole(role, treeNode);
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().createContract(identity, null, LocalDate.now().plusDays(2), null);
    IdmContractPositionDto position = getHelper().createContractPosition(contract, null);
    // 
    List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertTrue(assignedRoles.isEmpty());
    // 
    position.setWorkPosition(treeNode.getId());
    position = service.save(position);
    // 
    assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
    Assert.assertEquals(position.getId(), assignedRoles.get(0).getContractPosition());
}
Also used : 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) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 9 with IdmContractPositionDto

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

the class IdentityProvisioningTest method testProvisioningOnChangeContractPosition.

@Test
public void testProvisioningOnChangeContractPosition() {
    SysSystemDto systemDto = helper.createTestResourceSystem(true);
    SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
    schemaAttributeFilter.setSystemId(systemDto.getId());
    IdmRoleDto roleWithSystem = helper.createRole();
    helper.createRoleSystem(roleWithSystem, systemDto);
    IdmIdentityDto identity = helper.createIdentity();
    IdmIdentityContractDto primeContract = helper.getPrimeContract(identity);
    assertNotNull(primeContract);
    IdmContractPositionDto contractPosition = helper.createContractPosition(primeContract);
    helper.createIdentityRole(identity, roleWithSystem, null, null);
    identity.setFirstName(helper.createName());
    identityService.save(identity);
    TestResource resource = helper.findResource(identity.getUsername());
    assertNotNull(resource);
    String valueOnResource = resource.getFirstname();
    assertEquals(identity.getFirstName(), valueOnResource);
    // Change first name without call provisioning
    identity.setFirstName(helper.createName());
    identityService.saveInternal(identity);
    resource = helper.findResource(identity.getUsername());
    assertNotNull(resource);
    assertNotEquals(identity.getFirstName(), resource.getFirstname());
    // Save of position -> must execute provisioning
    contractPositionService.save(contractPosition);
    resource = helper.findResource(identity.getUsername());
    assertNotNull(resource);
    assertEquals(identity.getFirstName(), resource.getFirstname());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 10 with IdmContractPositionDto

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

the class DefaultIdentityProjectionManager method saveOtherPositions.

protected List<IdmContractPositionDto> saveOtherPositions(EntityEvent<IdmIdentityProjectionDto> event, BasePermission... permission) {
    IdmIdentityProjectionDto dto = event.getContent();
    IdmIdentityProjectionDto previousProjection = event.getOriginalSource();
    List<IdmContractPositionDto> savedPositions = new ArrayList<>(dto.getOtherPositions().size());
    IdmIdentityContractDto contract = dto.getContract();
    // 
    // check other contract position has to be saved
    IdmIdentityDto identity = dto.getIdentity();
    if (identity.getFormProjection() != null) {
        IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(dto.getIdentity(), IdmIdentity_.formProjection);
        if (!formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_OTHER_POSITION)) {
            LOG.debug("Projection [{}] doesn't save other contract positions.", formProjection.getCode());
            return savedPositions;
        }
    }
    // 
    for (IdmContractPositionDto otherPosition : dto.getOtherPositions()) {
        if (otherPosition.getIdentityContract() == null) {
            if (contract == null) {
                throw new ForbiddenEntityException("contract", IdmBasePermission.READ);
            }
            otherPosition.setIdentityContract(contract.getId());
        }
        ContractPositionEventType positionEventType = ContractPositionEventType.CREATE;
        if (!contractPositionService.isNew(otherPosition)) {
            positionEventType = ContractPositionEventType.UPDATE;
        }
        ContractPositionEvent positionEvent = new ContractPositionEvent(positionEventType, otherPosition);
        // 
        savedPositions.add(contractPositionService.publish(positionEvent, event, permission).getContent());
        if (previousProjection != null) {
            previousProjection.getOtherPositions().removeIf(p -> {
                return Objects.equals(p.getId(), otherPosition.getId());
            });
        }
    }
    // remove not sent positions, if previous exists
    if (previousProjection != null) {
        for (IdmContractPositionDto contractPosition : previousProjection.getOtherPositions()) {
            ContractPositionEventType positionEventType = ContractPositionEventType.DELETE;
            ContractPositionEvent positionEvent = new ContractPositionEvent(positionEventType, contractPosition);
            // 
            contractPositionService.publish(positionEvent, event, PermissionUtils.isEmpty(permission) ? null : IdmBasePermission.DELETE);
        }
    }
    // 
    return savedPositions;
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) ContractPositionEventType(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent.ContractPositionEventType) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) ArrayList(java.util.ArrayList) ContractPositionEvent(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent) 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) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException)

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