Search in sources :

Example 16 with IdmContractGuaranteeDto

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

the class DefaultIdmIdentityServiceIntegrationTest method testReferentialIntegrity.

@Test
@Transactional
public void testReferentialIntegrity() {
    IdmIdentityDto identity = getHelper().createIdentity();
    String username = identity.getUsername();
    // eav
    IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmIdentity.class);
    IdmFormValueDto value1 = new IdmFormValueDto(formDefinition.getMappedAttributeByCode(InitDemoDataProcessor.FORM_ATTRIBUTE_PASSWORD));
    value1.setValue("one");
    formService.saveValues(identity.getId(), IdmIdentity.class, formDefinition, Lists.newArrayList(value1));
    // role with guarantee
    IdmRoleDto role = getHelper().createRole();
    getHelper().createRoleGuarantee(role, identity);
    // contract
    IdmIdentityContractDto contract = getHelper().createContract(identity);
    // contract guarantee
    IdmIdentityContractDto contract2 = getHelper().createContract(identityService.getByUsername(InitTestDataProcessor.TEST_USER_1));
    contractGuaranteeService.save(new IdmContractGuaranteeDto(contract2.getId(), identity.getId()));
    // assigned role
    getHelper().createIdentityRole(contract, role);
    IdmIdentityRoleFilter identityRolefilter = new IdmIdentityRoleFilter();
    identityRolefilter.setIdentityId(identity.getId());
    // profile
    getHelper().createProfile(identity);
    // token
    IdmTokenDto token = new IdmTokenDto();
    token.setToken("token");
    token.setTokenType("test");
    token = tokenManager.saveToken(identity, token);
    // 
    Assert.assertNotNull(tokenManager.getToken(token.getId()));
    Assert.assertNotNull(profileService.findOneByIdentity(identity.getId()));
    Assert.assertNotNull(identityService.getByUsername(username));
    Assert.assertNotNull(passwordService.findOneByIdentity(identity.getId()));
    Assert.assertEquals(1, formService.getValues(identity).size());
    Assert.assertEquals(identity.getId(), roleGuaranteeService.findByRole(role.getId(), null).getContent().get(0).getGuarantee());
    Assert.assertEquals(1, identityRoleService.find(identityRolefilter, null).getTotalElements());
    // + default contract is created
    Assert.assertEquals(2, identityContractService.findAllByIdentity(identity.getId()).size());
    IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
    filter.setIdentityContractId(contract2.getId());
    List<IdmContractGuaranteeDto> guarantees = contractGuaranteeService.find(filter, null).getContent();
    Assert.assertEquals(1, guarantees.size());
    Assert.assertEquals(identity.getId(), guarantees.get(0).getGuarantee());
    // 
    identityService.delete(identity);
    role = roleService.get(role.getId());
    // 
    Assert.assertEquals(0L, roleGuaranteeService.findByRole(role.getId(), null).getTotalElements());
    Assert.assertNull(identityService.getByUsername(username));
    Assert.assertNull(passwordService.findOneByIdentity(identity.getId()));
    Assert.assertEquals(0, identityContractService.findAllByIdentity(identity.getId()).size());
    Assert.assertEquals(0, identityRoleService.find(identityRolefilter, null).getTotalElements());
    Assert.assertEquals(0, contractGuaranteeService.find(filter, null).getTotalElements());
    Assert.assertNull(profileService.findOneByIdentity(identity.getId()));
    Assert.assertTrue(tokenManager.getToken(token.getId()).isDisabled());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with IdmContractGuaranteeDto

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

the class IdentityContractSyncTest method defaultLeaderTest.

@Test
public void defaultLeaderTest() {
    SysSystemDto system = initData();
    Assert.assertNotNull(system);
    AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
    Assert.assertTrue(config instanceof SysSyncContractConfigDto);
    helper.createIdentity(CONTRACT_OWNER_ONE);
    helper.createIdentity(CONTRACT_OWNER_TWO);
    helper.createIdentity(CONTRACT_LEADER_ONE);
    IdmIdentityDto defaultLeader = helper.createIdentity(CONTRACT_LEADER_TWO);
    // Set default leader to sync configuration
    SysSyncContractConfigDto configContract = (SysSyncContractConfigDto) config;
    configContract.setDefaultLeader(defaultLeader.getId());
    config = syncConfigService.save(configContract);
    IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
    contractFilter.setProperty(IdmIdentityContract_.position.getName());
    contractFilter.setValue("1");
    Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
    contractFilter.setValue("2");
    Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
    helper.startSynchronization(config);
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    contractFilter.setValue("1");
    List<IdmIdentityContractDto> contractsOne = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsOne.size());
    IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
    guaranteeFilter.setIdentityContractId(contractsOne.get(0).getId());
    List<IdmContractGuaranteeDto> gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
    Assert.assertEquals(1, gurantees.size());
    IdmIdentityDto guarantee = DtoUtils.getEmbedded(gurantees.get(0), IdmContractGuarantee_.guarantee);
    // Direct leader from resource
    Assert.assertEquals(CONTRACT_LEADER_ONE, guarantee.getUsername());
    contractFilter.setValue("2");
    List<IdmIdentityContractDto> contractsTwo = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsTwo.size());
    guaranteeFilter.setIdentityContractId(contractsTwo.get(0).getId());
    gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
    Assert.assertEquals(1, gurantees.size());
    guarantee = DtoUtils.getEmbedded(gurantees.get(0), IdmContractGuarantee_.guarantee);
    // Default leader
    Assert.assertEquals(CONTRACT_LEADER_TWO, guarantee.getUsername());
    contractFilter.setValue("3");
    List<IdmIdentityContractDto> contractsThree = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contractsThree.size());
    guaranteeFilter.setIdentityContractId(contractsThree.get(0).getId());
    gurantees = guaranteeService.find(guaranteeFilter, null).getContent();
    Assert.assertEquals(1, gurantees.size());
    guarantee = DtoUtils.getEmbedded(gurantees.get(0), IdmContractGuarantee_.guarantee);
    // Default leader
    Assert.assertEquals(CONTRACT_LEADER_TWO, guarantee.getUsername());
    // Delete log
    syncLogService.delete(log);
}
Also used : AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 18 with IdmContractGuaranteeDto

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

the class DefaultContractSliceManager method copyGuarantees.

@Transactional
@Override
public void copyGuarantees(IdmContractSliceDto slice, IdmIdentityContractDto contract) {
    Assert.notNull(slice, "Contract slice is required.");
    Assert.notNull(slice.getId(), "Contract slice identifier is required.");
    Assert.notNull(contract, "Contract is required.");
    Assert.notNull(contract.getId(), "Contract identifier is required.");
    IdmContractSliceGuaranteeFilter guaranteeFilter = new IdmContractSliceGuaranteeFilter();
    guaranteeFilter.setContractSliceId(slice.getId());
    List<IdmContractSliceGuaranteeDto> guarantees = contractSliceGuaranteeService.find(guaranteeFilter, null).getContent();
    List<IdmContractGuaranteeDto> resultGuarantees = new ArrayList<>();
    guarantees.forEach(guarantee -> {
        IdmContractGuaranteeDto result = this.cloneGuarante(guarantee);
        result.setIdentityContract(contract.getId());
        resultGuarantees.add(result);
    });
    IdmContractGuaranteeFilter contractGuaranteeFilter = new IdmContractGuaranteeFilter();
    contractGuaranteeFilter.setIdentityContractId(contract.getId());
    List<IdmContractGuaranteeDto> currentGuarantees = contractGuaranteeService.find(contractGuaranteeFilter, null).getContent();
    // Find and create new guarantees
    resultGuarantees.stream().filter(guarantee -> {
        // 
        return !// 
        currentGuarantees.stream().filter(// 
        cg -> guarantee.getGuarantee().equals(cg.getGuarantee())).findFirst().isPresent();
    }).forEach(guaranteeToAdd -> {
        ContractGuaranteeEvent event = new ContractGuaranteeEvent(contractGuaranteeService.isNew(guaranteeToAdd) ? ContractGuaranteeEventType.CREATE : ContractGuaranteeEventType.UPDATE, guaranteeToAdd, ImmutableMap.of(ContractSliceManager.SKIP_CHECK_FOR_SLICES, Boolean.TRUE));
        contractGuaranteeService.publish(event);
    });
    // Find and remove guarantees which missing in the current result set
    currentGuarantees.stream().filter(guarantee -> {
        // 
        return !// 
        resultGuarantees.stream().filter(// 
        cg -> guarantee.getGuarantee().equals(cg.getGuarantee())).findFirst().isPresent();
    }).forEach(guaranteeToRemove -> {
        ContractGuaranteeEvent event = new ContractGuaranteeEvent(ContractGuaranteeEventType.DELETE, guaranteeToRemove, ImmutableMap.of(ContractSliceManager.SKIP_CHECK_FOR_SLICES, Boolean.TRUE));
        contractGuaranteeService.publish(event);
    });
}
Also used : IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) ContractSliceEventType(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent.ContractSliceEventType) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ContractGuaranteeEventType(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent.ContractGuaranteeEventType) ContractGuaranteeEvent(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent) ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) Map(java.util.Map) ContractSliceConfiguration(eu.bcvsolutions.idm.core.api.config.domain.ContractSliceConfiguration) Pageable(org.springframework.data.domain.Pageable) Objects(com.google.common.base.Objects) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) ImmutableMap(com.google.common.collect.ImmutableMap) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Serializable(java.io.Serializable) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) List(java.util.List) LocalDate(java.time.LocalDate) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdmContractSliceService(eu.bcvsolutions.idm.core.api.service.IdmContractSliceService) HashMap(java.util.HashMap) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) Strings(com.google.common.base.Strings) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) Service(org.springframework.stereotype.Service) IdmContractSliceGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractSliceGuaranteeService) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Logger(org.slf4j.Logger) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IdmContractGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService) ApplicationContext(org.springframework.context.ApplicationContext) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) ChronoUnit(java.time.temporal.ChronoUnit) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) Comparator(java.util.Comparator) ContractSliceManager(eu.bcvsolutions.idm.core.api.service.ContractSliceManager) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) ArrayList(java.util.ArrayList) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) ContractGuaranteeEvent(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with IdmContractGuaranteeDto

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

the class IdmContractGuaranteeControllerRestTest method prepareDto.

@Override
protected IdmContractGuaranteeDto prepareDto() {
    IdmContractGuaranteeDto dto = new IdmContractGuaranteeDto();
    dto.setIdentityContract(getHelper().getPrimeContract(getHelper().createIdentity().getId()).getId());
    dto.setGuarantee(getHelper().createIdentity().getId());
    return dto;
}
Also used : IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto)

Example 20 with IdmContractGuaranteeDto

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

the class AbstractContractGuaranteeBulkAction method getContractGuaranteeIdentities.

/**
 * Get the ids of identities who are the guarantees for users selected
 * for the bulk action.
 *
 * @param bulkAction
 * @return
 */
protected List<UUID> getContractGuaranteeIdentities(IdmBulkActionDto bulkAction) throws FilterSizeExceededException {
    List<UUID> selectedUsers = getUsersFromBulkAction(bulkAction);
    IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
    filter.setIdentities(selectedUsers);
    List<IdmContractGuaranteeDto> guarantees = contractGuaranteeService.find(filter, null, IdmBasePermission.READ).getContent();
    List<UUID> guaranteeIdentityIds = guarantees.stream().map(IdmContractGuaranteeDto::getGuarantee).collect(Collectors.toList());
    // remove duplicated identities
    return new ArrayList<>(new HashSet<>(guaranteeIdentityIds));
}
Also used : IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) ArrayList(java.util.ArrayList) 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