Search in sources :

Example 86 with IdmIdentityRoleDto

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

the class DefaultIdmIdentityContractServiceIntegrationTest method testDontAssingRoleForContractValidInThePast.

@Test
public void testDontAssingRoleForContractValidInThePast() {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    // 
    IdmIdentityContractDto contractD = new IdmIdentityContractDto();
    contractD.setIdentity(identity.getId());
    contractD.setWorkPosition(nodeD.getId());
    contractD.setValidTill(LocalDate.now().minusDays(1));
    contractD = service.save(contractD);
    // 
    // create new automatic role
    automaticRoleD = new IdmRoleTreeNodeDto();
    automaticRoleD.setRecursionType(RecursionType.NO);
    automaticRoleD.setRole(roleA.getId());
    automaticRoleD.setTreeNode(nodeD.getId());
    automaticRoleD = saveAutomaticRole(automaticRoleD, true);
    // 
    // check
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contractD.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 87 with IdmIdentityRoleDto

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

the class DefaultIdmIdentityRoleServiceIntegrationTest method testMarkDuplicatesOneConceptOneIdentityRole.

@Test
public void testMarkDuplicatesOneConceptOneIdentityRole() {
    IdmIdentityDto identity = this.getHelper().createIdentity((GuardedString) null);
    IdmRoleDto role = this.getHelper().createRole();
    IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
    IdmIdentityRoleDto identityRole = this.getHelper().createIdentityRole(contract, role, null, LocalDate.now().plusDays(5));
    IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
    concept.setRole(role.getId());
    concept.setIdentityContract(contract.getId());
    Map<String, BaseDto> embedded = concept.getEmbedded();
    embedded.put(IdmConceptRoleRequest_.identityContract.getName(), contract);
    concept.setEmbedded(embedded);
    concept.setOperation(ConceptRoleRequestOperation.ADD);
    List<IdmConceptRoleRequestDto> duplicates = roleRequestService.markDuplicates(Lists.newArrayList(concept), Lists.newArrayList(identityRole));
    assertEquals(1, duplicates.size());
    DuplicateRolesDto duplicateWithRoles = duplicates.get(0).getDuplicates();
    assertFalse(concept.getDuplicate());
    assertTrue(duplicateWithRoles.getIdentityRoles().isEmpty());
    assertTrue(duplicateWithRoles.getConcepts().isEmpty());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) DuplicateRolesDto(eu.bcvsolutions.idm.core.api.dto.DuplicateRolesDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 88 with IdmIdentityRoleDto

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

the class DefaultIdmIdentityRoleServiceIntegrationTest method testDeduplicationWithConceptWithRemovedRole.

@Test
public void testDeduplicationWithConceptWithRemovedRole() {
    IdmIdentityDto identity = getHelper().createIdentity(new GuardedString());
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
    IdmRoleDto role = getHelper().createRole();
    IdmIdentityRoleDto one = getHelper().createIdentityRole(identity, role, null, null);
    List<IdmConceptRoleRequestDto> concepts = new ArrayList<IdmConceptRoleRequestDto>();
    IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
    concept.setRole(role.getId());
    concept.setIdentityContract(contract.getId());
    concept.setOperation(ConceptRoleRequestOperation.ADD);
    Map<String, BaseDto> embedded = concept.getEmbedded();
    embedded.put(IdmConceptRoleRequest_.identityContract.getName(), contract);
    concept.setEmbedded(embedded);
    concepts.add(concept);
    List<IdmConceptRoleRequestDto> removeDuplicities = roleRequestService.removeDuplicities(concepts, identity.getId());
    // concept is duplicit with one
    assertTrue(removeDuplicities.isEmpty());
    concepts = new ArrayList<IdmConceptRoleRequestDto>();
    concept.setDuplicate(null);
    concept.setDuplicates(null);
    concepts.add(concept);
    IdmConceptRoleRequestDto conceptWithremove = new IdmConceptRoleRequestDto();
    conceptWithremove.setOperation(ConceptRoleRequestOperation.REMOVE);
    conceptWithremove.setIdentityContract(contract.getId());
    conceptWithremove.setIdentityRole(one.getId());
    embedded = conceptWithremove.getEmbedded();
    embedded.put(IdmConceptRoleRequest_.identityContract.getName(), contract);
    conceptWithremove.setEmbedded(embedded);
    concepts.add(conceptWithremove);
    removeDuplicities = roleRequestService.removeDuplicities(concepts, identity.getId());
    // role will be removed
    assertFalse(removeDuplicities.isEmpty());
    assertEquals(2, removeDuplicities.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ArrayList(java.util.ArrayList) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 89 with IdmIdentityRoleDto

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

the class DefaultIdmIdentityRoleServiceIntegrationTest method testDeduplicationWithConceptAndEav.

@Test
public void testDeduplicationWithConceptAndEav() {
    IdmIdentityDto identity = getHelper().createIdentity(new GuardedString());
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
    IdmRoleDto role = createRoleWithAttributes(prepareAttributeOne());
    IdmIdentityRoleDto one = getHelper().createIdentityRole(identity, role, LocalDate.now().minusDays(10), LocalDate.now().plusDays(10));
    IdmIdentityRoleDto two = getHelper().createIdentityRole(identity, role, LocalDate.now().plusDays(15), LocalDate.now().plusDays(40));
    one = fillEavs(one);
    two = fillEavs(two);
    List<IdmFormInstanceDto> formInstances = service.getFormInstances(one);
    IdmFormValueDto valueFromOne = formInstances.get(0).getValues().get(0);
    IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(valueFromOne, IdmFormValue_.formAttribute, IdmFormAttributeDto.class);
    IdmIdentityRoleDto duplicated = service.getDuplicated(one, two, null);
    assertNull(duplicated);
    List<IdmConceptRoleRequestDto> concepts = new ArrayList<IdmConceptRoleRequestDto>();
    IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
    concept.setRole(role.getId());
    concept.setIdentityContract(contract.getId());
    concept.setValidFrom(LocalDate.now().minusDays(9));
    concept.setValidTill(LocalDate.now().plusDays(9));
    concept.setOperation(ConceptRoleRequestOperation.ADD);
    Map<String, BaseDto> embedded = concept.getEmbedded();
    embedded.put(IdmConceptRoleRequest_.identityContract.getName(), contract);
    concept.setEmbedded(embedded);
    concepts.add(concept);
    List<IdmConceptRoleRequestDto> removeDuplicities = roleRequestService.removeDuplicities(concepts, identity.getId());
    // EAVs for concept missing
    assertFalse(removeDuplicities.isEmpty());
    concepts = new ArrayList<IdmConceptRoleRequestDto>();
    IdmFormInstanceDto instance = new IdmFormInstanceDto();
    IdmFormValueDto value = new IdmFormValueDto(formAttributeDto);
    value.setValue(Long.valueOf(System.currentTimeMillis()));
    instance.setValues(Lists.newArrayList(value));
    concept.setEavs(Lists.newArrayList(instance));
    concepts.add(concept);
    removeDuplicities = roleRequestService.removeDuplicities(concepts, identity.getId());
    // EAVs for concept is different
    assertFalse(removeDuplicities.isEmpty());
    concepts = new ArrayList<IdmConceptRoleRequestDto>();
    value = new IdmFormValueDto(formAttributeDto);
    value.setValue(ATTRIBUTE_ONE_DEFAULT_VALUE);
    instance.setValues(Lists.newArrayList(value));
    concept.setEavs(Lists.newArrayList(instance));
    concepts.add(concept);
    removeDuplicities = roleRequestService.removeDuplicities(concepts, identity.getId());
    // EAVs are same
    assertTrue(removeDuplicities.isEmpty());
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ArrayList(java.util.ArrayList) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 90 with IdmIdentityRoleDto

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

the class DefaultIdmIdentityContractServiceIntegrationTest method testChangeContractPositionAndValidityWithAutomaticRolesAssigned.

@Test
public void testChangeContractPositionAndValidityWithAutomaticRolesAssigned() {
    prepareAutomaticRoles();
    // 
    // prepare identity and contract
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = new IdmIdentityContractDto();
    contract.setIdentity(identity.getId());
    contract.setWorkPosition(nodeD.getId());
    LocalDate validTill = LocalDate.now().plusDays(1);
    contract.setValidTill(validTill);
    contract = service.save(contract);
    // 
    // test after create
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
    IdmIdentityRoleDto automaticRole = identityRoles.stream().filter(ir -> {
        return roleA.getId().equals(ir.getRole());
    }).findFirst().orElse(null);
    Assert.assertNotNull(automaticRole);
    Assert.assertEquals(validTill, automaticRole.getValidTill());
    // 
    // => role A is the same => down recursion
    contract.setWorkPosition(nodeB.getId());
    LocalDate newValidTill = LocalDate.now().plusDays(3);
    contract.setValidTill(newValidTill);
    contract = service.save(contract);
    // 
    // test after change
    identityRoles = identityRoleService.findAllByContract(contract.getId());
    Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
        return roleA.getId().equals(ir.getRole()) && // prevent drop and create
        ir.getId().equals(automaticRole.getId()) && // validity is changed
        newValidTill.equals(ir.getValidTill());
    }));
}
Also used : Lists(org.testng.collections.Lists) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) ProcessAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) LongRunningTaskEventType(eu.bcvsolutions.idm.core.scheduler.api.event.LongRunningTaskEvent.LongRunningTaskEventType) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) RecursionType(eu.bcvsolutions.idm.core.api.domain.RecursionType) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) ContractPositionEventType(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent.ContractPositionEventType) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) LongRunningFutureTask(eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask) Set(java.util.Set) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) RemoveAutomaticRoleTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.RemoveAutomaticRoleTaskExecutor) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) ContractBasePermission(eu.bcvsolutions.idm.core.security.api.domain.ContractBasePermission) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) ContractPositionEvent(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmContractPositionService(eu.bcvsolutions.idm.core.api.service.IdmContractPositionService) IdmTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmTreeNodeService) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) PermissionContext(eu.bcvsolutions.idm.core.api.dto.filter.PermissionContext) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmLongRunningTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmLongRunningTaskService) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) SchedulerConfiguration(eu.bcvsolutions.idm.core.scheduler.api.config.SchedulerConfiguration) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) IdmContractGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService) ApplicationContext(org.springframework.context.ApplicationContext) IdmIdentityContract_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) PrivateIdentityConfiguration(eu.bcvsolutions.idm.core.api.config.domain.PrivateIdentityConfiguration) AutomaticRoleAttributeRuleComparison(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) IdentityConfiguration(eu.bcvsolutions.idm.core.api.config.domain.IdentityConfiguration) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Transactional(org.springframework.transaction.annotation.Transactional) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) LocalDate(java.time.LocalDate) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)511 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)407 Test (org.junit.Test)401 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)400 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)282 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)280 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)151 UUID (java.util.UUID)146 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)113 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)113 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)111 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)109 List (java.util.List)108 Autowired (org.springframework.beans.factory.annotation.Autowired)107 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)101 Transactional (org.springframework.transaction.annotation.Transactional)94 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)92 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)89 LocalDate (java.time.LocalDate)87 Assert (org.junit.Assert)79