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());
}
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);
}
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);
});
}
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;
}
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));
}
Aggregations