Search in sources :

Example 1 with IdmTreeNode

use of eu.bcvsolutions.idm.core.model.entity.IdmTreeNode 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 2 with IdmTreeNode

use of eu.bcvsolutions.idm.core.model.entity.IdmTreeNode in project CzechIdMng by bcvsolutions.

the class TreeNodeAndTypeRestTest method getIdmTreeNode.

private IdmTreeNode getIdmTreeNode(IdmTreeType type, IdmTreeNode parent, String code, String name) {
    IdmTreeNode node2 = new IdmTreeNode();
    node2.setCode(code);
    node2.setName(name);
    node2.setTreeType(type);
    node2.setParent(parent);
    return node2;
}
Also used : IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)

Example 3 with IdmTreeNode

use of eu.bcvsolutions.idm.core.model.entity.IdmTreeNode in project CzechIdMng by bcvsolutions.

the class IdmTreeNodeController method findRevision.

@ResponseBody
@RequestMapping(value = "{backendId}/revisions/{revId}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.AUDIT_READ + "')")
@ApiOperation(value = "Tree node audit - read revision detail", nickname = "getTreeNodeRevision", tags = { IdmTreeNodeController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUDIT_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUDIT_READ, description = "") }) })
public ResponseEntity<?> findRevision(@ApiParam(value = "Node's uuid identifier.", required = true) @PathVariable("backendId") String backendId, @ApiParam(value = "Revision identifier.", required = true) @PathVariable("revId") Long revId) {
    IdmTreeNodeDto treeNode = getDto(backendId);
    if (treeNode == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("treeNode", backendId));
    }
    IdmTreeNode revision;
    try {
        revision = this.auditService.findRevision(IdmTreeNode.class, treeNode.getId(), revId);
    } catch (RevisionDoesNotExistException ex) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("revision", revId), ex);
    }
    // TODO: dto
    return new ResponseEntity<>(revision, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) RevisionDoesNotExistException(org.hibernate.envers.exception.RevisionDoesNotExistException) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with IdmTreeNode

use of eu.bcvsolutions.idm.core.model.entity.IdmTreeNode in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityContractServiceUnitTest method testPrimeContractWithWorkingPosition.

@Test
public void testPrimeContractWithWorkingPosition() {
    List<IdmIdentityContract> contracts = new ArrayList<>();
    IdmIdentityContract contractWithPosition = new IdmIdentityContract(UUID.randomUUID());
    contractWithPosition.setMain(false);
    IdmTreeNode workPosition = new IdmTreeNode();
    workPosition.setId(UUID.randomUUID());
    workPosition.setTreeType(new IdmTreeType(UUID.randomUUID()));
    contractWithPosition.setWorkPosition(workPosition);
    // 
    IdmIdentityContract otherContract = new IdmIdentityContract(UUID.randomUUID());
    otherContract.setMain(false);
    contracts.add(contractWithPosition);
    contracts.add(otherContract);
    // 
    when(applicationContext.getBean(LookupService.class)).thenReturn(lookupService);
    when(lookupService.toDto(any(), any(), any())).then(new LookupAnswer());
    when(repository.findAllByIdentity_Id(any(UUID.class), any())).thenReturn(contracts);
    when(treeConfiguration.getDefaultType()).thenReturn(null);
    when(contractSliceService.count(any(IdmContractSliceFilter.class))).thenReturn(0L);
    // 
    Assert.assertEquals(contractWithPosition.getId(), service.getPrimeContract(UUID.randomUUID()).getId());
}
Also used : IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) ArrayList(java.util.ArrayList) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) UUID(java.util.UUID) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmTreeType(eu.bcvsolutions.idm.core.model.entity.IdmTreeType) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 5 with IdmTreeNode

use of eu.bcvsolutions.idm.core.model.entity.IdmTreeNode in project CzechIdMng by bcvsolutions.

the class RebuildTreeNodeIndexTaskExecutor method processChildren.

private boolean processChildren(List<IdmTreeNode> nodes) {
    boolean canContinue = true;
    for (IdmTreeNode node : nodes) {
        if (node.getForestIndex() == null) {
            forestIndexService.index(node.getForestTreeType(), node.getId(), node.getParentId());
        }
        counter++;
        canContinue = updateState();
        if (!canContinue) {
            break;
        }
        // proces nodes childred
        canContinue = processChildren(treeNodeRepository.findDirectChildren(node, null).getContent());
        if (!canContinue) {
            break;
        }
    }
    ;
    return canContinue;
}
Also used : IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)

Aggregations

IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)14 UUID (java.util.UUID)6 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)4 IdmIdentityContract (eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)4 Predicate (javax.persistence.criteria.Predicate)4 IdmTreeType (eu.bcvsolutions.idm.core.model.entity.IdmTreeType)3 Test (org.junit.Test)3 RecursionType (eu.bcvsolutions.idm.core.api.domain.RecursionType)2 IdmContractSliceFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)2 LocalDate (java.time.LocalDate)2 ArrayList (java.util.ArrayList)2 Transactional (org.springframework.transaction.annotation.Transactional)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)1 TreeNodeException (eu.bcvsolutions.idm.core.exception.TreeNodeException)1 IdmForestIndexEntity (eu.bcvsolutions.idm.core.model.entity.IdmForestIndexEntity)1 IdmIdentityRole (eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole)1 IdmTreeNodeControllerRestTest (eu.bcvsolutions.idm.core.rest.impl.IdmTreeNodeControllerRestTest)1