use of eu.bcvsolutions.idm.core.exception.TreeNodeException in project CzechIdMng by bcvsolutions.
the class TreeNodeDeleteProcessor method process.
@Override
public EventResult<IdmTreeNodeDto> process(EntityEvent<IdmTreeNodeDto> event) {
IdmTreeNodeDto treeNode = event.getContent();
//
if (identityContractRepository.countByWorkPosition_Id(treeNode.getId()) > 0) {
throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CONTRACTS, ImmutableMap.of("treeNode", treeNode.getName()));
}
// remove related automatic roles
IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
filter.setTreeNodeId(treeNode.getId());
roleTreeNodeService.find(filter, null).forEach(roleTreeNode -> {
try {
roleTreeNodeService.delete(roleTreeNode);
} catch (AcceptedException ex) {
throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_ROLE, ImmutableMap.of("treeNode", treeNode.getName(), "roleTreeNode", roleTreeNode.getId()));
}
});
//
service.deleteInternal(treeNode);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.exception.TreeNodeException in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeService method deleteInternal.
/**
* Publish {@link TreeNodeEvent} only.
*
* @see {@link TreeNodeDeleteProcessor}
*/
@Override
@Transactional
public void deleteInternal(IdmTreeNodeDto treeNode) {
Assert.notNull(treeNode);
Assert.notNull(treeNode.getTreeType());
LOG.debug("Deleting tree node [{}] - [{}]", treeNode.getTreeType(), treeNode.getCode());
//
// if index rebuild is in progress, then throw exception
checkTreeType(treeNode.getTreeType());
//
Page<IdmTreeNode> nodes = repository.findChildren(null, treeNode.getId(), new PageRequest(0, 1));
if (nodes.getTotalElements() > 0) {
throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CHILDREN, ImmutableMap.of("treeNode", treeNode.getName()));
}
if (this.identityContractRepository.countByWorkPosition_Id(treeNode.getId()) > 0) {
throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CONTRACTS, ImmutableMap.of("treeNode", treeNode.getName()));
}
//
forestContentService.deleteIndex(treeNode.getId());
super.deleteInternal(treeNode);
}
use of eu.bcvsolutions.idm.core.exception.TreeNodeException in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeServiceIntegrationTest method testBadTreeTypeCreate.
@Test
public void testBadTreeTypeCreate() {
IdmTreeTypeDto parent1 = helper.createTreeType();
IdmTreeTypeDto parent2 = helper.createTreeType();
//
IdmTreeNodeDto node1 = helper.createTreeNode(parent1, null);
IdmTreeNodeDto node2 = helper.createTreeNode(parent1, node1);
IdmTreeNodeDto node3 = helper.createTreeNode(parent1, node2);
//
try {
helper.createTreeNode(parent2, node1);
Assert.fail();
} catch (TreeNodeException ex) {
Assert.assertTrue(ex.getMessage().contains("bad type"));
} catch (Exception e) {
Assert.fail();
}
//
try {
helper.createTreeNode(parent2, node3);
Assert.fail();
} catch (TreeNodeException ex) {
Assert.assertTrue(ex.getMessage().contains("bad type"));
} catch (Exception e) {
Assert.fail();
}
}
use of eu.bcvsolutions.idm.core.exception.TreeNodeException in project CzechIdMng by bcvsolutions.
the class IdmTreeNodeServiceIntegrationTest method testBadTreeTypeUpdate.
@Test
public void testBadTreeTypeUpdate() {
IdmTreeTypeDto parent1 = helper.createTreeType();
IdmTreeTypeDto parent2 = helper.createTreeType();
//
IdmTreeNodeDto node1 = helper.createTreeNode(parent1, null);
IdmTreeNodeDto node2 = helper.createTreeNode(parent1, node1);
IdmTreeNodeDto node3 = helper.createTreeNode(parent1, node2);
//
node3.setTreeType(parent2.getId());
try {
node3 = treeNodeService.save(node3);
Assert.fail();
} catch (TreeNodeException ex) {
Assert.assertTrue(ex.getMessage().contains("bad type"));
} catch (Exception e) {
Assert.fail();
}
//
node1.setTreeType(parent2.getId());
try {
node1 = treeNodeService.save(node1);
Assert.fail();
} catch (TreeNodeException ex) {
Assert.assertTrue(ex.getMessage().contains("bad type"));
} catch (Exception e) {
Assert.fail();
}
}
Aggregations