Search in sources :

Example 1 with TreeNodeException

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);
}
Also used : IdmRoleTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter) TreeNodeException(eu.bcvsolutions.idm.core.exception.TreeNodeException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException)

Example 2 with TreeNodeException

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);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) TreeNodeException(eu.bcvsolutions.idm.core.exception.TreeNodeException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with TreeNodeException

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();
    }
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) TreeNodeException(eu.bcvsolutions.idm.core.exception.TreeNodeException) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) TreeNodeException(eu.bcvsolutions.idm.core.exception.TreeNodeException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 4 with TreeNodeException

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();
    }
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) TreeNodeException(eu.bcvsolutions.idm.core.exception.TreeNodeException) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) TreeNodeException(eu.bcvsolutions.idm.core.exception.TreeNodeException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Aggregations

TreeNodeException (eu.bcvsolutions.idm.core.exception.TreeNodeException)4 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)3 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)2 Test (org.junit.Test)2 IdmRoleTreeNodeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter)1 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)1 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)1 IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)1 PageRequest (org.springframework.data.domain.PageRequest)1 Transactional (org.springframework.transaction.annotation.Transactional)1