Search in sources :

Example 1 with IdmForestIndexEntity

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

the class DefaultIdmTreeNodeService method saveInternal.

@Override
@Transactional
public IdmTreeNodeDto saveInternal(IdmTreeNodeDto treeNode) {
    // if index rebuild is in progress, then throw exception
    checkTreeType(treeNode.getTreeType());
    // 
    if (isNew(treeNode)) {
        this.validate(treeNode, true);
        // create new
        treeNode = super.saveInternal(treeNode);
        IdmForestIndexEntity index = forestContentService.createIndex(IdmTreeNode.toForestTreeType(treeNode.getTreeType()), treeNode.getId(), treeNode.getParent());
        return setForestIndex(treeNode, index);
    }
    this.validate(treeNode, false);
    // update - we need to reindex first
    IdmForestIndexEntity index = forestContentService.updateIndex(IdmTreeNode.toForestTreeType(treeNode.getTreeType()), treeNode.getId(), treeNode.getParent());
    treeNode = super.saveInternal(treeNode);
    return setForestIndex(treeNode, index);
}
Also used : IdmForestIndexEntity(eu.bcvsolutions.idm.core.model.entity.IdmForestIndexEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with IdmForestIndexEntity

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

the class DefaultIdmRoleCatalogueService method toPredicates.

@Override
protected List<Predicate> toPredicates(Root<IdmRoleCatalogue> root, CriteriaQuery<?> query, CriteriaBuilder builder, IdmRoleCatalogueFilter filter) {
    List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
    // quick
    String text = filter.getText();
    if (StringUtils.isNotEmpty(text)) {
        text = text.toLowerCase();
        predicates.add(builder.or(builder.like(builder.lower(root.get(IdmRoleCatalogue_.name)), "%" + text + "%"), builder.like(builder.lower(root.get(IdmRoleCatalogue_.code)), "%" + text + "%")));
    }
    String code = filter.getCode();
    if (StringUtils.isNotEmpty(code)) {
        predicates.add(builder.equal(root.get(IdmRoleCatalogue_.code), code));
    }
    String name = filter.getName();
    if (StringUtils.isNotEmpty(name)) {
        predicates.add(builder.equal(root.get(IdmRoleCatalogue_.name), name));
    }
    UUID parent = filter.getParent();
    if (parent != null) {
        // recursively
        if (filter.isRecursively()) {
            Subquery<IdmRoleCatalogue> subquery = query.subquery(IdmRoleCatalogue.class);
            Root<IdmRoleCatalogue> subRoot = subquery.from(IdmRoleCatalogue.class);
            subquery.select(subRoot);
            Path<IdmForestIndexEntity> forestIndexPath = subRoot.get(IdmRoleCatalogue_.forestIndex);
            subquery.where(builder.and(builder.equal(subRoot.get(AbstractEntity_.id), parent), builder.between(root.get(IdmRoleCatalogue_.forestIndex).get(IdmForestIndexEntity_.lft), builder.sum(forestIndexPath.get(IdmForestIndexEntity_.lft), 1L), builder.diff(forestIndexPath.get(IdmForestIndexEntity_.rgt), 1L))));
            predicates.add(builder.exists(subquery));
        } else {
            predicates.add(builder.equal(root.get(IdmRoleCatalogue_.parent).get(IdmRoleCatalogue_.id), parent));
        }
    }
    // roots
    Boolean roots = filter.getRoots();
    if (roots != null) {
        if (roots) {
            predicates.add(builder.isNull(root.get(IdmRoleCatalogue_.parent)));
        } else {
            predicates.add(builder.isNotNull(root.get(IdmRoleCatalogue_.parent)));
        }
    }
    return predicates;
}
Also used : IdmRoleCatalogue(eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogue) UUID(java.util.UUID) IdmForestIndexEntity(eu.bcvsolutions.idm.core.model.entity.IdmForestIndexEntity) Predicate(javax.persistence.criteria.Predicate)

Example 3 with IdmForestIndexEntity

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

the class DefaultIdmTreeNodeService method toPredicates.

@Override
protected List<Predicate> toPredicates(Root<IdmTreeNode> root, CriteriaQuery<?> query, CriteriaBuilder builder, IdmTreeNodeFilter filter) {
    List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
    // fulltext
    if (!StringUtils.isEmpty(filter.getText())) {
        predicates.add(builder.or(builder.like(builder.lower(root.get(IdmTreeNode_.code)), "%" + filter.getText().toLowerCase() + "%"), builder.like(builder.lower(root.get(IdmTreeNode_.name)), "%" + filter.getText().toLowerCase() + "%")));
    }
    // tree type identifier
    if (filter.getTreeTypeId() != null) {
        predicates.add(builder.equal(root.get(IdmTreeNode_.treeType).get(AbstractEntity_.id), filter.getTreeTypeId()));
    }
    // tree type code
    String treeTypeCode = filter.getTreeTypeCode();
    if (StringUtils.isNotEmpty(treeTypeCode)) {
        predicates.add(builder.equal(root.get(IdmTreeNode_.treeType).get(IdmTreeType_.code), treeTypeCode));
    }
    // parent node
    UUID parent = filter.getParent();
    if (parent != null) {
        if (filter.isRecursively()) {
            // forest index needs tree type => same numbers in different trees
            Subquery<IdmTreeType> subqueryTreeType = query.subquery(IdmTreeType.class);
            Root<IdmTreeNode> subRootTreeType = subqueryTreeType.from(IdmTreeNode.class);
            subqueryTreeType.select(subRootTreeType.get(IdmTreeNode_.treeType));
            subqueryTreeType.where(builder.equal(subRootTreeType.get(IdmTreeNode_.id), parent));
            // 
            Subquery<IdmTreeNode> subquery = query.subquery(IdmTreeNode.class);
            Root<IdmTreeNode> subRoot = subquery.from(IdmTreeNode.class);
            subquery.select(subRoot);
            Join<IdmTreeNode, IdmForestIndexEntity> forestIndexPath = subRoot.join(IdmTreeNode_.forestIndex);
            subquery.where(builder.and(builder.equal(subRoot.get(IdmTreeNode_.id), parent), // join tree type
            builder.equal(root.get(IdmTreeNode_.treeType), subqueryTreeType), // Remember that between clause looks like this a >= x <= b, where a and b are boundaries, in our case lft+1 and rgt-1.
            builder.between(root.join(IdmTreeNode_.forestIndex).get(IdmForestIndexEntity_.lft), builder.sum(forestIndexPath.get(IdmForestIndexEntity_.lft), 1L), builder.diff(forestIndexPath.get(IdmForestIndexEntity_.rgt), 1L))));
            predicates.add(builder.exists(subquery));
        } else {
            predicates.add(builder.equal(root.get(IdmTreeNode_.parent).get(AbstractEntity_.id), parent));
        }
    }
    // default tree type
    if (filter.getDefaultTreeType() != null) {
        IdmTreeTypeDto defaultTreeType = treeTypeService.getDefaultTreeType();
        if (defaultTreeType == null) {
            // nothing to find
            predicates.add(builder.disjunction());
        } else {
            predicates.add(builder.equal(root.get(IdmTreeNode_.treeType).get(IdmTreeType_.id), defaultTreeType.getId()));
        }
    }
    // roots
    Boolean roots = filter.getRoots();
    if (roots != null) {
        if (roots) {
            predicates.add(builder.isNull(root.get(IdmTreeNode_.parent)));
        } else {
            predicates.add(builder.isNotNull(root.get(IdmTreeNode_.parent)));
        }
    }
    // 
    return predicates;
}
Also used : IdmTreeType(eu.bcvsolutions.idm.core.model.entity.IdmTreeType) Predicate(javax.persistence.criteria.Predicate) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) UUID(java.util.UUID) IdmForestIndexEntity(eu.bcvsolutions.idm.core.model.entity.IdmForestIndexEntity)

Example 4 with IdmForestIndexEntity

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

the class DefaultIdmRoleCatalogueService method saveInternal.

@Override
@Transactional
public IdmRoleCatalogueDto saveInternal(IdmRoleCatalogueDto roleCatalogue) {
    if (isNew(roleCatalogue)) {
        this.validate(roleCatalogue, true);
        // create new
        roleCatalogue = super.saveInternal(roleCatalogue);
        IdmForestIndexEntity index = forestContentService.createIndex(IdmRoleCatalogue.FOREST_TREE_TYPE, roleCatalogue.getId(), roleCatalogue.getParent());
        return setForestIndex(roleCatalogue, index);
    }
    this.validate(roleCatalogue, false);
    // update - we need to reindex first
    IdmForestIndexEntity index = forestContentService.updateIndex(IdmRoleCatalogue.FOREST_TREE_TYPE, roleCatalogue.getId(), roleCatalogue.getParent());
    roleCatalogue = super.saveInternal(roleCatalogue);
    // 
    return setForestIndex(roleCatalogue, index);
}
Also used : IdmForestIndexEntity(eu.bcvsolutions.idm.core.model.entity.IdmForestIndexEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmForestIndexEntity (eu.bcvsolutions.idm.core.model.entity.IdmForestIndexEntity)4 UUID (java.util.UUID)2 Predicate (javax.persistence.criteria.Predicate)2 Transactional (org.springframework.transaction.annotation.Transactional)2 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)1 IdmRoleCatalogue (eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogue)1 IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)1 IdmTreeType (eu.bcvsolutions.idm.core.model.entity.IdmTreeType)1