Search in sources :

Example 41 with IdmContractGuaranteeDto

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

the class ContractGuaranteeSaveAndDeleteProcessorTest method testProvisioningAfterUpdateContractGuarantee.

@Test
public void testProvisioningAfterUpdateContractGuarantee() {
    SysSystemDto system = testHelper.createTestResourceSystem(true);
    // 
    IdmIdentityDto identity = testHelper.createIdentity();
    testHelper.createIdentityAccount(system, identity);
    // 
    // save identity with account, invoke provisioning = create
    identity = identityService.save(identity);
    // 
    IdmIdentityDto guarantee = testHelper.createIdentity();
    IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
    IdmContractGuaranteeDto contractGuarantee = testHelper.createContractGuarantee(primeContract.getId(), guarantee.getId());
    // 
    IdmIdentityDto newGuarantee = testHelper.createIdentity();
    contractGuarantee.setGuarantee(newGuarantee.getId());
    // save/update
    contractGuarantee = contractGuaranteeService.save(contractGuarantee);
    // 
    SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
    filter.setSystemId(system.getId());
    List<SysProvisioningArchiveDto> content = provisioningArchiveService.find(filter, null).getContent();
    // create, add contract guarantee and update = 3 operation
    assertEquals(3, content.size());
    // sort by created and found last
    SysProvisioningArchiveDto last = content.stream().max(Comparator.comparing(SysProvisioningArchiveDto::getCreated)).orElse(null);
    ;
    assertNotNull(last);
    assertEquals(ProvisioningEventType.UPDATE, last.getOperationType());
    assertEquals(SystemEntityType.IDENTITY, last.getEntityType());
    assertEquals(identity.getId(), last.getEntityIdentifier());
}
Also used : IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 42 with IdmContractGuaranteeDto

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

the class ContractGuaranteeSaveAndDeleteProcessorTest method testUpdateContractGuaranteeWithoutProvisioning.

@Test
public void testUpdateContractGuaranteeWithoutProvisioning() {
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    IdmIdentityDto guarantee = testHelper.createIdentity();
    IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
    IdmContractGuaranteeDto contractGuarantee = testHelper.createContractGuarantee(primeContract.getId(), guarantee.getId());
    // 
    IdmIdentityDto newGuarantee = testHelper.createIdentity();
    contractGuarantee.setGuarantee(newGuarantee.getId());
    // save/update
    contractGuarantee = contractGuaranteeService.save(contractGuarantee);
    // 
    SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
    filter.setEntityIdentifier(identity.getId());
    List<SysProvisioningArchiveDto> content = provisioningArchiveService.find(filter, null).getContent();
    assertEquals(0, content.size());
}
Also used : IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 43 with IdmContractGuaranteeDto

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

the class IdentityAddContractGuaranteeBulkAction method processDto.

@Override
protected OperationResult processDto(IdmIdentityDto identity) {
    Set<UUID> newGuarantees = getSelectedGuaranteeUuids(PROPERTY_NEW_GUARANTEE);
    Map<UUID, List<IdmContractGuaranteeDto>> currentGuarantees = getIdentityGuaranteesOrderedByContract(identity.getId());
    for (Map.Entry<UUID, List<IdmContractGuaranteeDto>> entry : currentGuarantees.entrySet()) {
        UUID contractId = entry.getKey();
        List<IdmContractGuaranteeDto> contractGuarantees = entry.getValue();
        Set<UUID> currentGuaranteesUuidSet = contractGuarantees.stream().map(IdmContractGuaranteeDto::getGuarantee).collect(Collectors.toSet());
        Set<UUID> guaranteesToAdd = Sets.difference(newGuarantees, currentGuaranteesUuidSet);
        // add all new contract guarantees
        for (UUID guaranteeId : guaranteesToAdd) {
            try {
                IdmContractGuaranteeDto guaranteeDto = createContractGuarantee(guaranteeId, contractId, IdmBasePermission.CREATE);
                logItemProcessed(guaranteeDto, new OperationResult.Builder(OperationState.EXECUTED).build());
            } catch (ForbiddenEntityException ex) {
                LOG.warn("Not authorized to set contract guarantee [{}] of contract [{}].", guaranteeId, contractId, ex);
                IdmIdentityContractDto dto = identityContractService.get(contractId);
                logContractGuaranteePermissionError(dto, guaranteeId, contractId, IdmBasePermission.CREATE, ex);
            } catch (ResultCodeException ex) {
                IdmIdentityContractDto dto = identityContractService.get(contractId);
                logResultCodeException(dto, ex);
            }
        }
    }
    return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) List(java.util.List) UUID(java.util.UUID) Map(java.util.Map) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException)

Example 44 with IdmContractGuaranteeDto

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

the class InitTestDataProcessor method process.

@Override
public EventResult<ModuleDescriptorDto> process(EntityEvent<ModuleDescriptorDto> event) {
    IdmTreeTypeDto treeType = treeTypeService.getByCode(InitApplicationData.DEFAULT_TREE_TYPE);
    IdmTreeNodeDto rootOrganization = treeNodeService.findRoots(treeType.getId(), PageRequest.of(0, 1)).getContent().get(0);
    // 
    if (!configurationService.getBooleanValue(PARAMETER_TEST_DATA_CREATED, false)) {
        LOG.info("Creating test data ...");
        // 
        IdmRoleDto role1 = new IdmRoleDto();
        role1.setCode(TEST_USER_ROLE);
        role1 = this.roleService.save(role1);
        LOG.info("Test role created [id: {}]", role1.getId());
        // 
        IdmRoleDto role2 = new IdmRoleDto();
        role2.setCode(TEST_CUSTOM_ROLE);
        role2 = this.roleService.save(role2);
        LOG.info("Test role created [id: {}]", role2.getId());
        // 
        // Users for JUnit testing
        IdmIdentityDto testUser1 = new IdmIdentityDto();
        testUser1.setUsername(TEST_USER_1);
        testUser1.setPassword(new GuardedString("heslo"));
        testUser1.setFirstName("Test");
        testUser1.setLastName("First User");
        testUser1.setEmail("test1@bscsolutions.eu");
        testUser1 = this.identityService.save(testUser1);
        LOG.info("Identity created [id: {}]", testUser1.getId());
        IdmIdentityDto testUser2 = new IdmIdentityDto();
        testUser2.setUsername(TEST_USER_2);
        testUser2.setPassword(new GuardedString("heslo"));
        testUser2.setFirstName("Test");
        testUser2.setLastName("Second User");
        testUser2.setEmail("test2@bscsolutions.eu");
        testUser2 = this.identityService.save(testUser2);
        LOG.info("Identity created [id: {}]", testUser2.getId());
        IdmTreeTypeDto type = this.treeTypeService.get(rootOrganization.getTreeType());
        IdmTreeNodeDto organization = new IdmTreeNodeDto();
        organization.setCode("test");
        organization.setName("Organization Test");
        organization.setCreator("ja");
        organization.setParent(rootOrganization.getId());
        organization.setTreeType(type.getId());
        organization = this.treeNodeService.save(organization);
        IdmIdentityContractDto identityWorkPosition2 = new IdmIdentityContractDto();
        identityWorkPosition2.setIdentity(testUser1.getId());
        identityWorkPosition2.setWorkPosition(organization.getId());
        identityWorkPosition2 = identityContractService.save(identityWorkPosition2);
        IdmContractGuaranteeDto contractGuarantee = new IdmContractGuaranteeDto();
        contractGuarantee.setIdentityContract(identityWorkPosition2.getId());
        contractGuarantee.setGuarantee(testUser2.getId());
        contractGuaranteeService.save(contractGuarantee);
        // 
        LOG.info("Test data was created.");
        // 
        configurationService.setBooleanValue(PARAMETER_TEST_DATA_CREATED, true);
    }
    // create default password policy for validate (We need to set min length of password ot 0 in tests.)
    createValidatePolicy();
    // create default password policy for generate (Must be here, because default init password processor is skipped for test profile.)
    createGeneratePolicy();
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 45 with IdmContractGuaranteeDto

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

the class IdentityChangeContractGuaranteeBulkActionTest method isContractGuarantee.

/**
 * Tests if there are all identities contract guarantees
 * If some of them are not contract guarantees, they are returned
 * Empty returned List means that there are all identities contract guarantees
 *
 * @param contract
 * @param guarantees
 * @return
 */
private List<IdmIdentityDto> isContractGuarantee(IdmIdentityContractDto contract, List<IdmIdentityDto> guarantees) {
    IdmContractGuaranteeFilter filt = new IdmContractGuaranteeFilter();
    filt.setIdentityContractId(contract.getId());
    Set<UUID> cgUUIDs = contractGuaranteeService.find(filt, null).getContent().stream().map(IdmContractGuaranteeDto::getGuarantee).collect(Collectors.toSet());
    return guarantees.stream().filter(ident -> !cgUUIDs.contains(ident.getId())).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) HashMap(java.util.HashMap) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) IdmContractGuarantee(eu.bcvsolutions.idm.core.model.entity.IdmContractGuarantee) ArrayList(java.util.ArrayList) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Map(java.util.Map) After(org.junit.After) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Before(org.junit.Before) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) UUID(java.util.UUID) IdmContractGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService) Collectors(java.util.stream.Collectors) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) UUID(java.util.UUID) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter)

Aggregations

IdmContractGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto)54 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)42 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)41 Test (org.junit.Test)31 UUID (java.util.UUID)27 IdmContractGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter)20 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)17 HashMap (java.util.HashMap)16 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)15 AbstractBulkActionTest (eu.bcvsolutions.idm.test.api.AbstractBulkActionTest)13 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)12 List (java.util.List)12 Transactional (org.springframework.transaction.annotation.Transactional)10 IdmContractGuaranteeService (eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService)9 Map (java.util.Map)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 Collectors (java.util.stream.Collectors)8 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)7 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)6 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)6