use of eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter 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.filter.IdmTreeNodeFilter in project CzechIdMng by bcvsolutions.
the class TreeSynchronizationExecutor method findByAttribute.
@Override
protected IdmTreeNodeDto findByAttribute(String idmAttributeName, String value) {
CorrelationFilter filter = getEntityFilter();
filter.setProperty(idmAttributeName);
filter.setValue(value);
List<IdmTreeNodeDto> entities = treeNodeService.find((IdmTreeNodeFilter) 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;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeServiceIntegrationTest method testForestIndexAfterBulkMove.
@Test
public void testForestIndexAfterBulkMove() {
int rootCount = 5;
// prepare new tree type
IdmTreeTypeDto treeType = helper.createTreeType();
// create root nodes
for (int i = 0; i < rootCount; i++) {
helper.createTreeNode(treeType, null);
}
// move nodes to the first node
IdmTreeNodeFilter filter = new IdmTreeNodeFilter();
filter.setTreeTypeId(treeType.getId());
List<IdmTreeNodeDto> nodes = treeNodeService.find(filter, null).getContent();
IdmTreeNodeDto root = nodes.get(0);
for (int i = 0; i < nodes.size(); i++) {
IdmTreeNodeDto node = nodes.get(i);
if (node.equals(root)) {
continue;
}
node.setParent(root.getId());
node = treeNodeService.save(node);
}
// check
Assert.assertEquals(1L, treeNodeService.findRoots(treeType.getId(), null).getTotalElements());
Assert.assertEquals(rootCount - 1, treeNodeService.findChildrenByParent(root.getId(), null).getTotalElements());
Assert.assertEquals(rootCount - 1, treeNodeForestContentService.findDirectChildren(root.getId(), null).getTotalElements());
Assert.assertEquals(rootCount - 1, treeNodeForestContentService.findAllChildren(root.getId(), null).getTotalElements());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter in project CzechIdMng by bcvsolutions.
the class DefaultTreeSynchronizationServiceTest method provisioningB_CreateAccounts_withException.
// Provisioning tree in incorrect order
@Test(expected = ProvisioningException.class)
public void provisioningB_CreateAccounts_withException() {
IdmTreeNodeFilter filter = new IdmTreeNodeFilter();
filter.setProperty(NODE_NAME);
filter.setValue("P1");
IdmTreeNodeDto nodeRoot = treeNodeService.find(filter, null).getContent().get(0);
Assert.assertNotNull(nodeRoot);
filter.setValue("P12");
IdmTreeNodeDto nodeOne = treeNodeService.find(filter, null).getContent().get(0);
Assert.assertNotNull(nodeOne);
// Check state before provisioning
TestTreeResource one = entityManager.find(TestTreeResource.class, "P12");
Assert.assertNull(one);
// Create mapping for provisioning
this.createProvisionigMapping();
// Save IDM node (must invoke provisioning)
// We didn't provisioning for root first ... expect throw exception
treeNodeService.save(nodeOne);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter in project CzechIdMng by bcvsolutions.
the class DefaultTreeSynchronizationServiceTest method doStartSyncB_Linked_doEntityUpdate.
@Test
public void doStartSyncB_Linked_doEntityUpdate() {
SysSyncConfigFilter configFilter = new SysSyncConfigFilter();
configFilter.setName(SYNC_CONFIG_NAME);
List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent();
// Change node code to changed
this.getBean().changeOne();
Assert.assertEquals(1, syncConfigs.size());
AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0);
Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
// Set sync config
syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ENTITY);
syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
syncConfigService.save(syncConfigCustom);
// Check state before sync
IdmTreeNodeFilter nodeFilter = new IdmTreeNodeFilter();
nodeFilter.setProperty(NODE_NAME);
nodeFilter.setValue("111");
IdmTreeNodeDto treeNode = treeNodeService.find(nodeFilter, null).getContent().get(0);
Assert.assertEquals("111", treeNode.getCode());
synchornizationService.setSynchronizationConfigId(syncConfigCustom.getId());
synchornizationService.process();
//
SysSyncLogFilter logFilter = new SysSyncLogFilter();
logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
Assert.assertEquals(1, logs.size());
SysSyncLogDto log = logs.get(0);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
actionLogFilter.setSynchronizationLogId(log.getId());
List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
Assert.assertEquals(1, actions.size());
SysSyncActionLogDto actionLog = actions.stream().filter(action -> {
return SynchronizationActionType.UPDATE_ENTITY == action.getSyncAction();
}).findFirst().get();
SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
itemLogFilter.setSyncActionLogId(actionLog.getId());
List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
Assert.assertEquals(6, items.size());
// Check state after sync
treeNode = treeNodeService.get(treeNode.getId());
Assert.assertEquals(CHANGED, treeNode.getCode());
// Delete log
syncLogService.delete(log);
}
Aggregations