Search in sources :

Example 11 with IdentityProjectionEvent

use of eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManagerIntegrationTest method testAssignAutomaticRoleIdentityAndContractEav.

@Test
public void testAssignAutomaticRoleIdentityAndContractEav() throws Exception {
    UUID identityId = null;
    try {
        getHelper().enableAsynchronousProcessing();
        // create form definition, roles, automatic role etc.
        IdmRoleDto role = getHelper().createRole();
        IdmRoleDto subRole = getHelper().createRole();
        getHelper().createRoleComposition(role, subRole);
        IdmRoleDto roleContract = getHelper().createRole();
        IdmRoleDto subRoleContract = getHelper().createRole();
        getHelper().createRoleComposition(roleContract, subRoleContract);
        // 
        IdmFormAttributeDto formAttributeOne = new IdmFormAttributeDto(getHelper().createName());
        IdmFormDefinitionDto formDefinition = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(formAttributeOne));
        formAttributeOne = formDefinition.getMappedAttributeByCode(formAttributeOne.getCode());
        // 
        IdmFormAttributeDto formAttributeContract = new IdmFormAttributeDto(getHelper().createName());
        IdmFormDefinitionDto formDefinitionContract = formService.createDefinition(IdmIdentityContractDto.class, getHelper().createName(), Lists.newArrayList(formAttributeContract));
        formAttributeContract = formDefinitionContract.getMappedAttributeByCode(formAttributeContract.getCode());
        // 
        IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
        getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, formAttributeOne.getId(), "mockOne");
        IdmAutomaticRoleAttributeDto automaticRoleContract = getHelper().createAutomaticRole(roleContract.getId());
        getHelper().createAutomaticRoleRule(automaticRoleContract.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, formAttributeContract.getId(), "mockContract");
        // form projection
        IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
        formProjection.setCode(getHelper().createName());
        formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
        formProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_LOAD_ASSIGNED_ROLES, false);
        formProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS, true);
        FormDefinitionAttributes attributes = new FormDefinitionAttributes();
        attributes.setDefinition(formDefinition.getId());
        attributes.getAttributes().add(formAttributeOne.getId());
        FormDefinitionAttributes attributesContract = new FormDefinitionAttributes();
        attributesContract.setDefinition(formDefinitionContract.getId());
        attributesContract.getAttributes().add(formAttributeContract.getId());
        formProjection.setCode(getHelper().createName());
        formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
        formProjection.setFormDefinitions(mapper.writeValueAsString(Lists.newArrayList(attributes, attributesContract)));
        formProjection = projectionService.save(formProjection);
        // 
        // prepare identity projection with two contract
        IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
        identity.setFormProjection(formProjection.getId());
        IdmFormValueDto formValue = new IdmFormValueDto(formAttributeOne);
        formValue.setValue("mockOne");
        identity.getEavs().add(new IdmFormInstanceDto(identity, formDefinition, Lists.newArrayList(formValue)));
        IdmIdentityContractDto contractOne = new IdmIdentityContractDto();
        contractOne.setPosition(getHelper().createName());
        IdmIdentityContractDto contractTwo = new IdmIdentityContractDto();
        contractTwo.setPosition(getHelper().createName());
        IdmFormValueDto formValueContract = new IdmFormValueDto(formAttributeContract);
        formValueContract.setValue("mockContract");
        contractTwo.getEavs().add(new IdmFormInstanceDto(contractTwo, formDefinitionContract, Lists.newArrayList(formValueContract)));
        IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
        projection.setContract(contractOne);
        projection.setOtherContracts(Lists.newArrayList(contractTwo));
        // 
        // create by projection
        projection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
        IdmIdentityProjectionDto createdProjection = manager.get(projection);
        identityId = createdProjection.getIdentity().getId();
        Assert.assertEquals(identity.getUsername(), createdProjection.getIdentity().getUsername());
        IdmIdentityContractDto primeContract = createdProjection.getContract();
        Assert.assertNotNull(primeContract);
        Assert.assertEquals(contractOne.getPosition(), primeContract.getPosition());
        Assert.assertEquals(1, createdProjection.getOtherContracts().size());
        IdmIdentityContractDto otherContract = createdProjection.getOtherContracts().get(0);
        Assert.assertEquals(contractTwo.getPosition(), otherContract.getPosition());
        // 
        // 6 roles
        IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
        filter.setIdentityId(createdProjection.getIdentity().getId());
        getHelper().waitForResult(res -> {
            return identityRoleService.find(filter, null).getContent().size() != 6;
        });
        List<IdmIdentityRoleDto> identityRoles = Lists.newArrayList(identityRoleService.find(filter, null).getContent());
        Assert.assertEquals(6, identityRoles.size());
        Assert.assertEquals(2, identityRoles.stream().filter(ir -> ir.getRole().equals(role.getId())).count());
        Assert.assertEquals(2, identityRoles.stream().filter(ir -> ir.getRole().equals(subRole.getId())).count());
        Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(roleContract.getId())).count());
        Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(subRoleContract.getId())).count());
        // 
        // change eav value => remove all automatic roles
        formValue.setValue("mockUpdate");
        createdProjection.getIdentity().getEavs().clear();
        createdProjection.getIdentity().getEavs().add(new IdmFormInstanceDto(identity, formDefinition, Lists.newArrayList(formValue)));
        manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, createdProjection)).getContent();
        getHelper().waitForResult(res -> {
            return identityRoleService.find(filter, null).getContent().size() != 2;
        });
        // 
        identityRoles = Lists.newArrayList(identityRoleService.find(filter, null).getContent());
        Assert.assertEquals(2, identityRoles.size());
        Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(roleContract.getId())).count());
        Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(subRoleContract.getId())).count());
    } finally {
        getHelper().disableAsynchronousProcessing();
        getHelper().deleteIdentity(identityId);
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) FormDefinitionAttributes(eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 12 with IdentityProjectionEvent

use of eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManagerIntegrationTest method testGetProjectionEavReadOnly.

@Test
@Transactional
public void testGetProjectionEavReadOnly() {
    // create identity with read permission only
    // with password
    IdmIdentityDto identityLogged = getHelper().createIdentity();
    IdmRoleDto role = getHelper().createRole();
    // read all
    getHelper().createBasePolicy(role.getId(), // form definition autocomplete is required
    IdmBasePermission.AUTOCOMPLETE, IdmBasePermission.READ);
    getHelper().createIdentityRole(identityLogged, role);
    // 
    // prepare eav definition
    IdmFormAttributeDto attributeOne = new IdmFormAttributeDto(getHelper().createName());
    attributeOne.setPersistentType(PersistentType.SHORTTEXT);
    IdmFormAttributeDto attributeTwo = new IdmFormAttributeDto(getHelper().createName());
    attributeTwo.setPersistentType(PersistentType.SHORTTEXT);
    IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(attributeOne, attributeTwo));
    attributeOne = formDefinitionOne.getMappedAttributeByCode(attributeOne.getCode());
    attributeTwo = formDefinitionOne.getMappedAttributeByCode(attributeTwo.getCode());
    IdmFormAttributeDto attributeThree = new IdmFormAttributeDto(getHelper().createName());
    attributeThree.setPersistentType(PersistentType.SHORTTEXT);
    IdmFormDefinitionDto formDefinitionTwo = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(attributeThree));
    attributeThree = formDefinitionTwo.getMappedAttributeByCode(attributeThree.getCode());
    IdmFormAttributeDto attributeContract = new IdmFormAttributeDto(getHelper().createName());
    attributeContract.setPersistentType(PersistentType.SHORTTEXT);
    IdmFormDefinitionDto formDefinitionContract = formService.createDefinition(IdmIdentityContractDto.class, getHelper().createName(), Lists.newArrayList(attributeContract));
    attributeContract = formDefinitionContract.getMappedAttributeByCode(attributeContract.getCode());
    // 
    IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
    IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
    // 
    // set eav
    IdmFormInstanceDto instanceOne = new IdmFormInstanceDto();
    instanceOne.setFormDefinition(formDefinitionOne);
    IdmFormValueDto valueOne = new IdmFormValueDto(attributeOne);
    valueOne.setValue(getHelper().createName());
    IdmFormValueDto valueTwo = new IdmFormValueDto(attributeTwo);
    valueTwo.setValue(getHelper().createName());
    instanceOne.setValues(Lists.newArrayList(valueOne, valueTwo));
    IdmFormInstanceDto instanceTwo = new IdmFormInstanceDto();
    instanceTwo.setFormDefinition(formDefinitionTwo);
    IdmFormValueDto valueThree = new IdmFormValueDto(attributeThree);
    valueThree.setValue(getHelper().createName());
    instanceTwo.setValues(Lists.newArrayList(valueThree));
    identity.setEavs(Lists.newArrayList(instanceOne, instanceTwo));
    // 
    // 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);
    IdmFormInstanceDto instanceContract = new IdmFormInstanceDto();
    instanceContract.setFormDefinition(formDefinitionContract);
    IdmFormValueDto valueContract = new IdmFormValueDto(attributeContract);
    valueContract.setValue(getHelper().createName());
    instanceContract.setValues(Lists.newArrayList(valueContract));
    primeContract.setEavs(Lists.newArrayList(instanceContract));
    // 
    projection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
    getHelper().login(identityLogged);
    try {
        IdmIdentityProjectionDto createdProjection = manager.get(projection, IdmBasePermission.READ);
        // 
        Assert.assertNotNull(createdProjection);
        Assert.assertNotNull(createdProjection.getId());
        Assert.assertEquals(createdProjection.getId(), createdProjection.getIdentity().getId());
        Assert.assertTrue(createdProjection.getIdentity().getEavs().stream().allMatch(i -> {
            return i.getFormDefinition().getFormAttributes().stream().allMatch(IdmFormAttributeDto::isReadonly);
        }));
        // eavs
        Assert.assertEquals(valueOne.getValue(), createdProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionOne.getId())).findFirst().get().toSinglePersistentValue(attributeOne.getCode()));
        Assert.assertEquals(valueTwo.getValue(), createdProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionOne.getId())).findFirst().get().toSinglePersistentValue(attributeTwo.getCode()));
        Assert.assertEquals(valueThree.getValue(), createdProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionTwo.getId())).findFirst().get().toSinglePersistentValue(attributeThree.getCode()));
        // prime contract eavs
        Assert.assertTrue(createdProjection.getContract().getEavs().stream().allMatch(i -> {
            return i.getFormDefinition().getFormAttributes().stream().allMatch(IdmFormAttributeDto::isReadonly);
        }));
        Assert.assertEquals(valueContract.getValue(), createdProjection.getContract().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionContract.getId())).findFirst().get().toSinglePersistentValue(attributeContract.getCode()));
    } finally {
        logout();
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) 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) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) 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 13 with IdentityProjectionEvent

use of eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManagerIntegrationTest method testSaveAndGetFullProjectionGreenLine.

@Test
@Transactional
public void testSaveAndGetFullProjectionGreenLine() {
    // role request implementer is needed
    loginAsAdmin();
    Assert.assertFalse(eventConfiguration.isAsynchronous());
    // 
    try {
        // prepare eav definition
        IdmFormAttributeDto attributeOne = new IdmFormAttributeDto(getHelper().createName());
        attributeOne.setPersistentType(PersistentType.SHORTTEXT);
        IdmFormAttributeDto attributeTwo = new IdmFormAttributeDto(getHelper().createName());
        attributeTwo.setPersistentType(PersistentType.SHORTTEXT);
        IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(attributeOne, attributeTwo));
        attributeOne = formDefinitionOne.getMappedAttributeByCode(attributeOne.getCode());
        attributeTwo = formDefinitionOne.getMappedAttributeByCode(attributeTwo.getCode());
        IdmFormAttributeDto attributeThree = new IdmFormAttributeDto(getHelper().createName());
        attributeThree.setPersistentType(PersistentType.SHORTTEXT);
        IdmFormDefinitionDto formDefinitionTwo = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(attributeThree));
        attributeThree = formDefinitionTwo.getMappedAttributeByCode(attributeThree.getCode());
        IdmFormAttributeDto attributeContract = new IdmFormAttributeDto(getHelper().createName());
        attributeContract.setPersistentType(PersistentType.SHORTTEXT);
        IdmFormDefinitionDto formDefinitionContract = formService.createDefinition(IdmIdentityContractDto.class, getHelper().createName(), Lists.newArrayList(attributeContract));
        attributeContract = formDefinitionContract.getMappedAttributeByCode(attributeContract.getCode());
        // 
        IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
        IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
        // 
        // set eav
        IdmFormInstanceDto instanceOne = new IdmFormInstanceDto();
        instanceOne.setFormDefinition(formDefinitionOne);
        IdmFormValueDto valueOne = new IdmFormValueDto(attributeOne);
        valueOne.setValue(getHelper().createName());
        IdmFormValueDto valueTwo = new IdmFormValueDto(attributeTwo);
        valueTwo.setValue(getHelper().createName());
        instanceOne.setValues(Lists.newArrayList(valueOne, valueTwo));
        IdmFormInstanceDto instanceTwo = new IdmFormInstanceDto();
        instanceTwo.setFormDefinition(formDefinitionTwo);
        IdmFormValueDto valueThree = new IdmFormValueDto(attributeThree);
        valueThree.setValue(getHelper().createName());
        instanceTwo.setValues(Lists.newArrayList(valueThree));
        identity.setEavs(Lists.newArrayList(instanceOne, instanceTwo));
        // 
        // 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);
        IdmFormInstanceDto instanceContract = new IdmFormInstanceDto();
        instanceContract.setFormDefinition(formDefinitionContract);
        IdmFormValueDto valueContract = new IdmFormValueDto(attributeContract);
        valueContract.setValue(getHelper().createName());
        instanceContract.setValues(Lists.newArrayList(valueContract));
        primeContract.setEavs(Lists.newArrayList(instanceContract));
        // 
        // 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));
        // 
        // set assigned roles
        IdmRoleDto roleOne = getHelper().createRole();
        IdmRoleDto roleTwo = getHelper().createRole();
        IdmIdentityRoleDto identityRoleOne = new IdmIdentityRoleDto();
        identityRoleOne.setRole(roleOne.getId());
        identityRoleOne.setValidFrom(LocalDate.now().plus(2l, ChronoUnit.DAYS));
        IdmIdentityRoleDto identityRoleTwo = new IdmIdentityRoleDto();
        identityRoleTwo.setRole(roleTwo.getId());
        identityRoleTwo.setIdentityContract(otherContractTwo.getId());
        projection.setIdentityRoles(Lists.newArrayList(identityRoleOne, identityRoleTwo));
        // 
        IdentityProjectionEvent identityProjectionEvent = new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection);
        identityProjectionEvent.setPriority(PriorityType.IMMEDIATE);
        projection = manager.publish(identityProjectionEvent).getContent();
        IdmIdentityProjectionDto createdProjection = manager.get(projection);
        // 
        Assert.assertNotNull(createdProjection);
        Assert.assertNotNull(createdProjection.getId());
        Assert.assertEquals(createdProjection.getId(), createdProjection.getIdentity().getId());
        // eavs
        Assert.assertEquals(valueOne.getValue(), createdProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionOne.getId())).findFirst().get().toSinglePersistentValue(attributeOne.getCode()));
        Assert.assertEquals(valueTwo.getValue(), createdProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionOne.getId())).findFirst().get().toSinglePersistentValue(attributeTwo.getCode()));
        Assert.assertEquals(valueThree.getValue(), createdProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionTwo.getId())).findFirst().get().toSinglePersistentValue(attributeThree.getCode()));
        // prime contract
        IdmIdentityContractDto createdPrimeContract = createdProjection.getContract();
        Assert.assertEquals(primeContract.getWorkPosition(), createdPrimeContract.getWorkPosition());
        Assert.assertEquals(primeContract.getPosition(), createdPrimeContract.getPosition());
        Assert.assertEquals(primeContract.getValidFrom(), createdPrimeContract.getValidFrom());
        Assert.assertEquals(primeContract.getValidTill(), createdPrimeContract.getValidTill());
        Assert.assertEquals(createdProjection.getIdentity().getId(), createdPrimeContract.getIdentity());
        // eavs
        Assert.assertEquals(valueContract.getValue(), createdProjection.getContract().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionContract.getId())).findFirst().get().toSinglePersistentValue(attributeContract.getCode()));
        // 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(createdPrimeContract.getId());
        }));
        Assert.assertTrue(createdProjection.getOtherPositions().stream().anyMatch(p -> {
            return p.getWorkPosition().equals(positionTwo.getWorkPosition()) && p.getPosition().equals(positionTwo.getPosition()) && p.getIdentityContract().equals(positionTwo.getIdentityContract());
        }));
        // assigned roles
        // check directly by service
        IdmRoleRequestFilter roleRequestFilter = new IdmRoleRequestFilter();
        roleRequestFilter.setApplicantId(createdProjection.getIdentity().getId());
        List<IdmRoleRequestDto> roleRequests = roleRequestService.find(roleRequestFilter, null).getContent();
        Assert.assertFalse(roleRequests.isEmpty());
        Assert.assertTrue(roleRequests.stream().allMatch(r -> r.getState() == RoleRequestState.EXECUTED));
        List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(createdProjection.getIdentity().getId());
        Assert.assertEquals(2, assignedRoles.size());
        Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> {
            return ir.getRole().equals(roleOne.getId()) && ir.getValidFrom().equals(identityRoleOne.getValidFrom()) && ir.getIdentityContract().equals(createdPrimeContract.getId());
        }));
        Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> {
            return ir.getRole().equals(roleTwo.getId()) && ir.getIdentityContract().equals(otherContractTwo.getId());
        }));
        // check by projection
        Assert.assertEquals(2, createdProjection.getIdentityRoles().size());
        Assert.assertTrue(createdProjection.getIdentityRoles().stream().anyMatch(ir -> {
            return ir.getRole().equals(roleOne.getId()) && ir.getValidFrom().equals(identityRoleOne.getValidFrom()) && ir.getIdentityContract().equals(createdPrimeContract.getId());
        }));
        Assert.assertTrue(createdProjection.getIdentityRoles().stream().anyMatch(ir -> {
            return ir.getRole().equals(roleTwo.getId()) && ir.getIdentityContract().equals(otherContractTwo.getId());
        }));
        // 
        // simple update
        String newUsername = getHelper().createName();
        createdProjection.getIdentity().setUsername(newUsername);
        // 
        IdmIdentityProjectionDto updatedProjection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, createdProjection)).getContent();
        // IdmIdentityProjectionDto updatedProjection = manager.get(projection);
        // 
        Assert.assertNotNull(updatedProjection);
        Assert.assertNotNull(updatedProjection.getId());
        Assert.assertEquals(createdProjection.getId(), updatedProjection.getIdentity().getId());
        Assert.assertEquals(newUsername, updatedProjection.getIdentity().getUsername());
        // eavs
        Assert.assertEquals(valueOne.getValue(), updatedProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionOne.getId())).findFirst().get().toSinglePersistentValue(attributeOne.getCode()));
        Assert.assertEquals(valueTwo.getValue(), updatedProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionOne.getId())).findFirst().get().toSinglePersistentValue(attributeTwo.getCode()));
        Assert.assertEquals(valueThree.getValue(), updatedProjection.getIdentity().getEavs().stream().filter(i -> i.getFormDefinition().getId().equals(formDefinitionTwo.getId())).findFirst().get().toSinglePersistentValue(attributeThree.getCode()));
        // prime contract
        IdmIdentityContractDto updatedPrimeContract = updatedProjection.getContract();
        Assert.assertEquals(primeContract.getWorkPosition(), updatedPrimeContract.getWorkPosition());
        Assert.assertEquals(primeContract.getPosition(), updatedPrimeContract.getPosition());
        Assert.assertEquals(primeContract.getValidFrom(), updatedPrimeContract.getValidFrom());
        Assert.assertEquals(primeContract.getValidTill(), updatedPrimeContract.getValidTill());
        Assert.assertEquals(updatedProjection.getIdentity().getId(), updatedPrimeContract.getIdentity());
        Assert.assertFalse(updatedPrimeContract.getControlledBySlices());
        // other contract
        Assert.assertEquals(2, updatedProjection.getOtherContracts().size());
        Assert.assertTrue(updatedProjection.getOtherContracts().stream().anyMatch(c -> {
            return c.getWorkPosition().equals(otherContractOne.getWorkPosition()) && c.getPosition().equals(otherContractOne.getPosition());
        }));
        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());
        }));
        Assert.assertTrue(updatedProjection.getOtherContracts().stream().allMatch(c -> {
            return !c.getControlledBySlices();
        }));
        // other position
        Assert.assertEquals(2, updatedProjection.getOtherPositions().size());
        Assert.assertTrue(updatedProjection.getOtherPositions().stream().anyMatch(p -> {
            return p.getWorkPosition().equals(positionOne.getWorkPosition()) && p.getPosition().equals(positionOne.getPosition()) && p.getIdentityContract().equals(updatedPrimeContract.getId());
        }));
        Assert.assertTrue(updatedProjection.getOtherPositions().stream().anyMatch(p -> {
            return p.getWorkPosition().equals(positionTwo.getWorkPosition()) && p.getPosition().equals(positionTwo.getPosition()) && p.getIdentityContract().equals(positionTwo.getIdentityContract());
        }));
        // assigned roles
        Assert.assertEquals(2, updatedProjection.getIdentityRoles().size());
        Assert.assertTrue(updatedProjection.getIdentityRoles().stream().anyMatch(ir -> {
            return ir.getRole().equals(roleOne.getId()) && ir.getValidFrom().equals(identityRoleOne.getValidFrom()) && ir.getIdentityContract().equals(updatedPrimeContract.getId());
        }));
        Assert.assertTrue(updatedProjection.getIdentityRoles().stream().anyMatch(ir -> {
            return ir.getRole().equals(roleTwo.getId()) && ir.getIdentityContract().equals(otherContractTwo.getId());
        }));
    } finally {
        logout();
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) 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) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with IdentityProjectionEvent

use of eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent 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 15 with IdentityProjectionEvent

use of eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent 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)

Aggregations

IdentityProjectionEvent (eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent)23 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)22 IdmIdentityProjectionDto (eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)22 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)21 Test (org.junit.Test)21 Transactional (org.springframework.transaction.annotation.Transactional)20 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)18 IdmFormProjectionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto)17 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)15 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)15 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)15 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)13 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)8 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)7 IdmContractPositionDto (eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto)7 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)7 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)7 FormDefinitionAttributes (eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes)7 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)6