use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method datesValidFilterTest.
@Test
public void datesValidFilterTest() {
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto identity2 = helper.createIdentity();
IdmIdentityDto identity3 = helper.createIdentity();
IdmIdentityDto identity4 = helper.createIdentity();
IdmTreeNodeDto node = helper.createTreeNode();
IdmTreeNodeDto node2 = helper.createTreeNode();
IdmTreeNodeDto node3 = helper.createTreeNode();
IdmTreeNodeDto node4 = helper.createTreeNode();
IdmIdentityContractDto contract = helper.createIdentityContact(identity, node, org.joda.time.LocalDate.now(), org.joda.time.LocalDate.parse("2021-06-05"));
IdmIdentityContractDto contract2 = helper.createIdentityContact(identity2, node2, org.joda.time.LocalDate.now(), org.joda.time.LocalDate.parse("2020-05-05"));
IdmIdentityContractDto contract3 = helper.createIdentityContact(identity3, node3, org.joda.time.LocalDate.now(), org.joda.time.LocalDate.parse("2016-05-05"));
IdmIdentityContractDto contract4 = helper.createIdentityContact(identity4, node4, org.joda.time.LocalDate.parse("2018-05-05"), org.joda.time.LocalDate.parse("2025-05-05"));
IdmIdentityContractFilter filter = new IdmIdentityContractFilter();
filter.setValidFrom(contract.getValidFrom());
Page<IdmIdentityContractDto> result = service.find(filter, null);
assertTrue(result.getContent().contains(contract));
filter.setValidFrom(null);
filter.setValidTill(contract2.getValidTill());
result = service.find(filter, null);
assertTrue(result.getContent().contains(contract2));
filter.setValidTill(null);
filter.setValid(true);
result = service.find(filter, null);
assertTrue(result.getContent().contains(contract));
assertTrue(result.getContent().contains(contract2));
assertFalse(result.getContent().contains(contract3));
filter.setValid(null);
filter.setValidNowOrInFuture(true);
result = service.find(filter, null);
assertTrue(result.getContent().contains(contract4));
filter.setValidNowOrInFuture(false);
result = service.find(filter, null);
assertTrue(result.getContent().contains(contract3));
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method textFilterTest.
@Test
public void textFilterTest() {
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto identity2 = helper.createIdentity();
IdmIdentityDto identity3 = helper.createIdentity();
IdmIdentityDto identity4 = helper.createIdentity();
IdmTreeNodeDto node = helper.createTreeNode();
node.setName("Position105");
treeNodeService.save(node);
IdmTreeNodeDto node2 = helper.createTreeNode();
node2.setName("Position006");
treeNodeService.save(node2);
IdmTreeNodeDto node3 = helper.createTreeNode();
node3.setCode("Position007");
treeNodeService.save(node3);
IdmTreeNodeDto node4 = helper.createTreeNode();
node4.setCode("Position108");
treeNodeService.save(node4);
IdmIdentityContractDto contract = helper.createIdentityContact(identity, node);
IdmIdentityContractDto contract2 = helper.createIdentityContact(identity2, node2);
IdmIdentityContractDto contract3 = helper.createIdentityContact(identity3, node3);
IdmIdentityContractDto contract4 = helper.createIdentityContact(identity4, node4);
contract.setPosition("Position001");
contract = service.save(contract);
contract2.setPosition("Position102");
service.save(contract2);
contract3.setPosition("Position103");
service.save(contract3);
contract4.setPosition("Position104");
service.save(contract4);
IdmIdentityContractFilter filter = new IdmIdentityContractFilter();
filter.setText("Position00");
Page<IdmIdentityContractDto> result = service.find(filter, null);
assertEquals("Wrong Text", 3, result.getTotalElements());
assertTrue(result.getContent().contains(contract));
assertTrue(result.getContent().contains(contract2));
assertTrue(result.getContent().contains(contract3));
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method checkContractInvalidTest.
@Test
public /**
* HR process are not executed during sync. If contract is invalid, then HR
* process disable the Identity. But in the sync we need skip this
* functionality.
*/
void checkContractInvalidTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
((SysSyncContractConfigDto) config).setStartOfHrProcesses(false);
syncConfigService.save(config);
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 not started, identity have to be in "incorrect" state
ownerOne = identityService.getByUsername(CONTRACT_OWNER_ONE);
Assert.assertFalse(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.filter.IdmIdentityContractFilter in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method defaultTreeTest.
@Test
public void defaultTreeTest() {
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());
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());
// None work positions can be found
contractFilter.setValue("1");
List<IdmIdentityContractDto> contractsOne = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsOne.size());
Assert.assertEquals(null, contractsOne.get(0).getWorkPosition());
contractFilter.setValue("2");
List<IdmIdentityContractDto> contractsTwo = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsTwo.size());
Assert.assertEquals(null, contractsTwo.get(0).getWorkPosition());
contractFilter.setValue("3");
List<IdmIdentityContractDto> contractsThree = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsThree.size());
Assert.assertEquals(null, contractsThree.get(0).getWorkPosition());
// Delete log
syncLogService.delete(log);
// Set work positions to resources
this.getBean().initContractDefaultTreeTest();
// Start sync again (we want to see some work positions)
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
log = checkSyncLog(config, SynchronizationActionType.UPDATE_ENTITY, 3);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// For contract One must be found workposition (one)
contractFilter.setValue("1");
contractsOne = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsOne.size());
IdmTreeNodeDto workposition = DtoUtils.getEmbedded(contractsOne.get(0), IdmIdentityContract_.workPosition, IdmTreeNodeDto.class);
Assert.assertEquals("one", workposition.getCode());
// For contract Two must not be found workposition (WRONG node is not in
// default
// tree)
contractFilter.setValue("2");
contractsTwo = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsTwo.size());
Assert.assertEquals(null, contractsTwo.get(0).getWorkPosition());
contractFilter.setValue("3");
contractsThree = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractsThree.size());
Assert.assertEquals(null, contractsThree.get(0).getWorkPosition());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method findByAttribute.
@Override
protected IdmIdentityContractDto findByAttribute(String idmAttributeName, String value) {
CorrelationFilter filter = getEntityFilter();
filter.setProperty(idmAttributeName);
filter.setValue(value);
List<IdmIdentityContractDto> entities = contractService.find((IdmIdentityContractFilter) filter, null).getContent();
if (CollectionUtils.isEmpty(entities)) {
return null;
}
if (entities.size() > 1) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_CORRELATION_TO_MANY_RESULTS, ImmutableMap.of("correlationAttribute", idmAttributeName, "value", value));
}
if (entities.size() == 1) {
return entities.get(0);
}
return null;
}
Aggregations