use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method deleteContractAccountTest.
@Test
public void deleteContractAccountTest() {
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);
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());
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractFilter.setValue("1");
List<IdmIdentityContractDto> contracts = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contracts.size());
// Find the account for this contract
IdmIdentityContractDto contract = contracts.get(0);
AccContractAccountFilter contractAccountFilter = new AccContractAccountFilter();
contractAccountFilter.setContractId(contract.getId());
contractAccountFilter.setSystemId(system.getId());
List<AccContractAccountDto> contractAccounts = contractAccountService.find(contractAccountFilter, null).getContent();
Assert.assertEquals(1, contractAccounts.size());
AccContractAccountDto contractAccount = contractAccounts.get(0);
AccAccountDto account = accountService.get(contractAccount.getAccount());
Assert.assertNotNull(account);
// Delete this account directly test
accountService.delete(account);
account = accountService.get(contractAccount.getAccount());
Assert.assertNull(account);
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method checkContractInvalidWithStartHrProcessesTest.
@Test
public /**
* HR process are not executed during sync, but after sync end.
*/
void checkContractInvalidWithStartHrProcessesTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
((SysSyncContractConfigDto) config).setStartOfHrProcesses(true);
syncConfigService.save(config);
Task task = findTask(HrEnableContractProcess.class);
IdmScheduledTaskDto scheduledTask = null;
if (scheduledService.findByQuartzTaskName(task.getId()) == null) {
scheduledTask = new IdmScheduledTaskDto();
scheduledTask.setQuartzTaskName(task.getId());
scheduledService.save(scheduledTask);
}
task = findTask(HrEndContractProcess.class);
if (scheduledService.findByQuartzTaskName(task.getId()) == null) {
scheduledTask = new IdmScheduledTaskDto();
scheduledTask.setQuartzTaskName(task.getId());
scheduledService.save(scheduledTask);
}
task = findTask(HrContractExclusionProcess.class);
if (scheduledService.findByQuartzTaskName(task.getId()) == null) {
scheduledTask = new IdmScheduledTaskDto();
scheduledTask.setQuartzTaskName(task.getId());
scheduledService.save(scheduledTask);
}
IdmIdentityDto ownerOne = helper.createIdentity(CONTRACT_OWNER_ONE);
IdmIdentityDto ownerTwo = helper.createIdentity(CONTRACT_OWNER_TWO);
helper.createIdentity(CONTRACT_LEADER_ONE);
contractService.findAllByIdentity(ownerOne.getId()).forEach(contract -> {
IdentityContractEvent event = new IdentityContractEvent(IdentityContractEventType.DELETE, contract);
event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
contractService.publish(event);
});
contractService.findAllByIdentity(ownerTwo.getId()).forEach(contract -> {
IdentityContractEvent event = new IdentityContractEvent(IdentityContractEventType.DELETE, contract);
event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
contractService.publish(event);
});
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());
// Change resources (set to invalid) .. must be call in transaction
this.getBean().initContractCheckInvalidTest();
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 2);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractFilter.setValue("1");
List<IdmIdentityContractDto> contractsOne = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsOne.size());
Assert.assertFalse(contractsOne.get(0).isValid());
contractFilter.setValue("3");
List<IdmIdentityContractDto> contractsThree = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsThree.size());
Assert.assertTrue(contractsThree.get(0).isValid());
// HR processes was started, identity have to be in "correct" state
ownerOne = identityService.getByUsername(CONTRACT_OWNER_ONE);
Assert.assertTrue(ownerOne.isDisabled());
ownerTwo = identityService.getByUsername(CONTRACT_OWNER_TWO);
Assert.assertFalse(ownerTwo.isDisabled());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method defaultWorkPositionTest.
@Test
public void defaultWorkPositionTest() {
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);
helper.createIdentity(CONTRACT_LEADER_TWO);
// Set default tree type to sync configuration
IdmTreeTypeDto treeType = treeTypeService.getByCode(InitApplicationData.DEFAULT_TREE_TYPE);
Assert.assertNotNull(treeType);
SysSyncContractConfigDto configContract = (SysSyncContractConfigDto) config;
configContract.setDefaultTreeType(treeType.getId());
// Set default tree node to sync configuration
IdmTreeNodeFilter nodeFilter = new IdmTreeNodeFilter();
nodeFilter.setCode("one");
nodeFilter.setTreeTypeId(treeType.getId());
List<IdmTreeNodeDto> nodes = treeNodeService.find(nodeFilter, null).getContent();
Assert.assertEquals(1, nodes.size());
IdmTreeNodeDto defaultNode = nodes.get(0);
configContract.setDefaultTreeNode(defaultNode.getId());
config = syncConfigService.save(configContract);
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
// Start sync
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// Default work positions must be set
contractFilter.setValue("1");
List<IdmIdentityContractDto> contractsOne = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsOne.size());
Assert.assertEquals(defaultNode.getId(), contractsOne.get(0).getWorkPosition());
contractFilter.setValue("2");
List<IdmIdentityContractDto> contractsTwo = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsTwo.size());
Assert.assertEquals(defaultNode.getId(), contractsTwo.get(0).getWorkPosition());
contractFilter.setValue("3");
List<IdmIdentityContractDto> contractsThree = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsThree.size());
Assert.assertEquals(defaultNode.getId(), contractsThree.get(0).getWorkPosition());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method updateIdentityPropagateValidityTest.
@Test
public void updateIdentityPropagateValidityTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
IdmRoleDto defaultRole = helper.createRole();
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
IdmIdentityDto identityOne = helper.createIdentity(IDENTITY_ONE);
IdmIdentityContractDto primeContract = contractService.getPrimeContract(identityOne.getId());
Assert.assertNotNull(primeContract);
LocalDate validTill = LocalDate.now().plusDays(10);
LocalDate validFrom = LocalDate.now().plusDays(-10);
primeContract.setValidFrom(validFrom);
primeContract.setValidTill(validTill);
primeContract = contractService.save(primeContract);
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setUsername(IDENTITY_ONE);
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK, 1, OperationResultType.SUCCESS);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
List<IdmIdentityRoleDto> roles = identityRoleService.findAllByIdentity(identityOne.getId());
Assert.assertEquals(1, roles.size());
IdmIdentityRoleDto identityRole = roles.get(0);
Assert.assertEquals(defaultRole.getId(), identityRole.getRole());
Assert.assertEquals(identityRole.getValidFrom(), validFrom);
Assert.assertEquals(identityRole.getValidTill(), validTill);
AccIdentityAccountFilter identityAccountFilter = new AccIdentityAccountFilter();
identityAccountFilter.setIdentityRoleId(identityRole.getId());
Assert.assertEquals(1, identityAccountService.find(identityAccountFilter, null).getContent().size());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractService method prepareMainContract.
@Override
public IdmIdentityContractDto prepareMainContract(UUID identityId) {
Assert.notNull(identityId);
//
// set identity
IdmIdentityContractDto contract = new IdmIdentityContractDto();
contract.setIdentity(identityId);
contract.setMain(true);
//
// set default contract name
// TODO: add boolean attribute
contract.setPosition(DEFAULT_POSITION_NAME);
//
// set working position
IdmTreeNodeDto defaultTreeNode = treeConfiguration.getDefaultNode();
if (defaultTreeNode != null) {
contract.setWorkPosition(defaultTreeNode.getId());
}
return contract;
}
Aggregations