Search in sources :

Example 21 with IdmRoleRequestFilter

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

the class IdentityRoleByIdentityDeduplicationBulkActionTest method testSevenManuallyOneContract.

@Test
public void testSevenManuallyOneContract() {
    IdmIdentityDto identity = getHelper().createIdentity(new GuardedString());
    IdmRoleDto role = getHelper().createRole();
    IdmIdentityRoleDto one = getHelper().createIdentityRole(identity, role);
    IdmIdentityRoleDto two = getHelper().createIdentityRole(identity, role);
    IdmIdentityRoleDto three = getHelper().createIdentityRole(identity, role);
    IdmIdentityRoleDto four = getHelper().createIdentityRole(identity, role);
    IdmIdentityRoleDto five = getHelper().createIdentityRole(identity, role);
    IdmIdentityRoleDto six = getHelper().createIdentityRole(identity, role);
    IdmIdentityRoleDto seven = getHelper().createIdentityRole(identity, role);
    List<IdmIdentityRoleDto> roles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(7, roles.size());
    IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityRoleByIdentityDeduplicationBulkAction.NAME);
    bulkAction.setIdentifiers(Sets.newHashSet(identity.getId()));
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    IdmLongRunningTaskDto longRunningTask = checkResultLrt(processAction, 1l, null, null);
    Assert.assertEquals(OperationState.EXECUTED, longRunningTask.getResultState());
    // item
    List<IdmProcessedTaskItemDto> processedItems = processedTaskItemService.findLogItems(longRunningTask, null).getContent();
    Assert.assertEquals(1, processedItems.size());
    // background request
    IdmRoleRequestFilter requestFilter = new IdmRoleRequestFilter();
    requestFilter.setApplicantId(identity.getId());
    List<IdmRoleRequestDto> requests = roleRequestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    Assert.assertEquals(RoleRequestState.EXECUTED, requests.get(0).getState());
    Assert.assertEquals(OperationState.EXECUTED, processedItems.get(0).getOperationResult().getState());
    roles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, roles.size());
    IdmIdentityRoleDto actual = roles.get(0);
    assertEquals(one.getId(), actual.getId());
    assertNotEquals(two.getId(), actual.getId());
    assertNotEquals(three.getId(), actual.getId());
    assertNotEquals(four.getId(), actual.getId());
    assertNotEquals(five.getId(), actual.getId());
    assertNotEquals(six.getId(), actual.getId());
    assertNotEquals(seven.getId(), actual.getId());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) 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) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test) ChangeIdentityPermissionTest(eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest)

Example 22 with IdmRoleRequestFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter 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 23 with IdmRoleRequestFilter

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

the class IdmRequestIdentityRoleServiceIntegrationTest method testUniqueConceptValidation.

@Test(expected = InvalidFormException.class)
public void testUniqueConceptValidation() {
    // Create role with attribute (include the sub-definition)
    IdmRoleDto role = createRoleWithAttributes(true);
    IdmRoleFormAttributeFilter filter = new IdmRoleFormAttributeFilter();
    filter.setRole(role.getId());
    List<IdmRoleFormAttributeDto> list = roleFormAttributeService.find(filter, null).getContent();
    Assert.assertEquals(2, list.size());
    IdmFormDefinitionDto formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
    Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
    // Delete IP attribute from the sub-definition
    list.stream().filter(roleFormAttributeDto -> {
        IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(roleFormAttributeDto, IdmRoleFormAttribute_.formAttribute.getName(), IdmFormAttributeDto.class);
        return formAttributeDto.getCode().equals(IP);
    }).forEach(roleFormAttributeDto -> roleFormAttributeService.delete(roleFormAttributeDto));
    formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
    Assert.assertEquals(1, formAttributeSubdefinition.getFormAttributes().size());
    Assert.assertEquals(NUMBER_OF_FINGERS, formAttributeSubdefinition.getFormAttributes().get(0).getCode());
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
    IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
    identityRoleFilter.setIdentityContractId(contract.getId());
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
    assertEquals(0, identityRoles.size());
    // Create request identity-role
    IdmRequestIdentityRoleDto createdRequestIdentityRole = new IdmRequestIdentityRoleDto();
    createdRequestIdentityRole.setIdentityContract(contract.getId());
    // Change the valid from
    createdRequestIdentityRole.setValidFrom(LocalDate.now());
    createdRequestIdentityRole.setRole(role.getId());
    // Create role attribute value in concept
    IdmFormDefinitionDto formDefinitionDto = roleService.getFormAttributeSubdefinition(role);
    IdmFormInstanceDto formInstanceDto = new IdmFormInstanceDto();
    IdmFormAttributeDto attribute = formDefinitionDto.getMappedAttributeByCode(NUMBER_OF_FINGERS);
    IdmFormValueDto formValueDto = new IdmFormValueDto(attribute);
    formValueDto.setValue(5);
    List<IdmFormValueDto> values = Lists.newArrayList(formValueDto);
    formInstanceDto.setValues(values);
    List<IdmFormInstanceDto> forms = Lists.newArrayList(formInstanceDto);
    createdRequestIdentityRole.setEavs(forms);
    createdRequestIdentityRole = requestIdentityRoleService.save(createdRequestIdentityRole);
    IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
    Assert.assertNotNull(request);
    // Execute a role-request.
    getHelper().executeRequest(request, false, true);
    IdmRequestIdentityRoleFilter filterRequestIdentityRole = new IdmRequestIdentityRoleFilter();
    filterRequestIdentityRole.setIdentityId(identity.getId());
    filterRequestIdentityRole.setRoleRequestId(request.getId());
    // Include EAV attributes
    filterRequestIdentityRole.setIncludeEav(true);
    // Check EAV value in the request-identity-role
    List<IdmRequestIdentityRoleDto> requestIdentityRoles = requestIdentityRoleService.find(filterRequestIdentityRole, null).getContent();
    Assert.assertEquals(1, requestIdentityRoles.size());
    Assert.assertEquals(role.getId(), requestIdentityRoles.get(0).getRole());
    Assert.assertEquals(1, requestIdentityRoles.get(0).getEavs().size());
    IdmFormInstanceDto formInstance = requestIdentityRoles.get(0).getEavs().get(0);
    Assert.assertEquals(1, formInstance.getValues().size());
    IdmFormValueDto formValue = formInstance.getValues().get(0);
    Serializable value = formValue.getValue();
    Assert.assertEquals(((BigDecimal) formValueDto.getValue()).longValue(), ((BigDecimal) value).longValue());
    IdmFormAttributeDto mappedAttribute = formInstance.getMappedAttribute(formValue.getFormAttribute());
    Assert.assertNotNull(mappedAttribute);
    Assert.assertNull(formInstance.getValidationErrors());
    identityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
    assertEquals(1, identityRoles.size());
    // Create request identity-role
    createdRequestIdentityRole = new IdmRequestIdentityRoleDto();
    createdRequestIdentityRole.setIdentityContract(contract.getId());
    // Change the valid from
    createdRequestIdentityRole.setValidFrom(LocalDate.now());
    createdRequestIdentityRole.setRole(role.getId());
    // Create role attribute value in concept
    formDefinitionDto = roleService.getFormAttributeSubdefinition(role);
    formInstanceDto = new IdmFormInstanceDto();
    attribute = formDefinitionDto.getMappedAttributeByCode(NUMBER_OF_FINGERS);
    formValueDto = new IdmFormValueDto(attribute);
    formValueDto.setValue(5);
    values = Lists.newArrayList(formValueDto);
    formInstanceDto.setValues(values);
    forms = Lists.newArrayList(formInstanceDto);
    createdRequestIdentityRole.setEavs(forms);
    requestIdentityRoleService.save(createdRequestIdentityRole);
}
Also used : IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) BigDecimal(java.math.BigDecimal) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmRequestIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmRequestIdentityRoleService) After(org.junit.After) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Set(java.util.Set) UUID(java.util.UUID) InvalidFormException(eu.bcvsolutions.idm.core.api.exception.InvalidFormException) Serializable(java.io.Serializable) List(java.util.List) LocalDate(java.time.LocalDate) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmRoleFormAttribute_(eu.bcvsolutions.idm.core.model.entity.IdmRoleFormAttribute_) IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) Lists(com.google.common.collect.Lists) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) Sets(org.mockito.internal.util.collections.Sets) ImmutableList(com.google.common.collect.ImmutableList) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleFormAttributeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) Test(org.junit.Test) IdmRoleFormAttributeService(eu.bcvsolutions.idm.core.api.service.IdmRoleFormAttributeService) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Assert.assertNull(org.junit.Assert.assertNull) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) Assert(org.junit.Assert) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Serializable(java.io.Serializable) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleFormAttributeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) 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) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 24 with IdmRoleRequestFilter

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

the class IdmRequestIdentityRoleServiceIntegrationTest method testUpdateUpdatingConcept.

@Test
@Transactional
public void testUpdateUpdatingConcept() {
    IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
    IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
    IdmRoleDto role = this.getHelper().createRole();
    this.getHelper().createIdentityRole(contract, role, LocalDate.now().minusDays(1), null);
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
    Assert.assertEquals(1, identityRoles.size());
    // Create request for updated identity-role
    IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
    dto.setIdentityContract(contract.getId());
    dto.setIdentityRole(identityRoles.get(0).getId());
    dto.setId(dto.getIdentityRole());
    dto.setValidFrom(LocalDate.now().plusDays(5));
    dto.setValidTill(LocalDate.now().minusDays(10));
    IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.save(dto);
    Assert.assertEquals(LocalDate.now().plusDays(5), createdRequestIdentityRole.getValidFrom());
    Assert.assertEquals(LocalDate.now().minusDays(10), createdRequestIdentityRole.getValidTill());
    // We want to update created concept -> update validity
    createdRequestIdentityRole.setValidFrom(LocalDate.now().minusDays(1));
    createdRequestIdentityRole.setValidTill(LocalDate.now().plusDays(10));
    createdRequestIdentityRole = requestIdentityRoleService.save(createdRequestIdentityRole);
    Assert.assertNotNull(createdRequestIdentityRole);
    // Request must been created
    Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
    Assert.assertEquals(role.getId(), createdRequestIdentityRole.getRole());
    Assert.assertEquals(contract.getId(), createdRequestIdentityRole.getIdentityContract());
    IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
    Assert.assertNotNull(request);
    // Concepts are not empty now
    Assert.assertEquals(1, request.getConceptRoles().size());
    // Applicant must be ours identity
    Assert.assertEquals(contract.getIdentity(), request.getApplicant());
    IdmConceptRoleRequestDto concept = request.getConceptRoles().get(0);
    Assert.assertEquals(contract.getId(), concept.getIdentityContract());
    Assert.assertEquals(role.getId(), concept.getRole());
    Assert.assertEquals(ConceptRoleRequestOperation.UPDATE, concept.getOperation());
    Assert.assertEquals(createdRequestIdentityRole.getValidFrom(), concept.getValidFrom());
    Assert.assertEquals(createdRequestIdentityRole.getValidTill(), concept.getValidTill());
    this.getHelper().executeRequest(request, false, true);
    identityRoles = identityRoleService.findAllByContract(contract.getId());
    Assert.assertEquals(1, identityRoles.size());
    Assert.assertEquals(LocalDate.now().minusDays(1), identityRoles.get(0).getValidFrom());
    Assert.assertEquals(LocalDate.now().plusDays(10), identityRoles.get(0).getValidTill());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) 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) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with IdmRoleRequestFilter

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

the class IdmRequestIdentityRoleServiceIntegrationTest method testRemoveAddingConcept.

@Test
@Transactional
public void testRemoveAddingConcept() {
    IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
    IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
    IdmRoleDto role = this.getHelper().createRole();
    // Create request for new identity-role
    IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
    dto.setIdentityContract(contract.getId());
    dto.setRole(role.getId());
    dto.setValidFrom(LocalDate.now().minusDays(1));
    dto.setValidTill(LocalDate.now().plusDays(10));
    IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.save(dto);
    Assert.assertNotNull(createdRequestIdentityRole);
    // Request must been created
    Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
    Assert.assertEquals(role.getId(), createdRequestIdentityRole.getRole());
    Assert.assertEquals(contract.getId(), createdRequestIdentityRole.getIdentityContract());
    IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
    Assert.assertNotNull(request);
    // Concepts are not empty now
    Assert.assertEquals(1, request.getConceptRoles().size());
    // Applicant must be ours identity
    Assert.assertEquals(contract.getIdentity(), request.getApplicant());
    // Delete adding concept
    requestIdentityRoleService.deleteRequestIdentityRole(createdRequestIdentityRole);
    request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
    Assert.assertNotNull(request);
    // Concepts are empty now
    Assert.assertEquals(0, request.getConceptRoles().size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmRoleRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter)27 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)21 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)19 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)16 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)16 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)15 Test (org.junit.Test)15 Transactional (org.springframework.transaction.annotation.Transactional)15 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)13 IdmRequestIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto)11 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)10 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)10 Serializable (java.io.Serializable)8 UUID (java.util.UUID)8 RoleRequestState (eu.bcvsolutions.idm.core.api.domain.RoleRequestState)6 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)6 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)5 IdmRoleRequestService (eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService)5 PersistentType (eu.bcvsolutions.idm.core.eav.api.domain.PersistentType)5 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)5