Search in sources :

Example 1 with IdmRoleCatalogue

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

the class RebuildRoleCatalogueIndexTaskExecutor method process.

@Override
public Boolean process() {
    if (!configurationService.getBooleanValue(DefaultForestIndexService.PROPERTY_INDEX_ENABLED, true)) {
        throw new ResultCodeException(CoreResultCode.FOREST_INDEX_DISABLED, ImmutableMap.of("property", DefaultForestIndexService.PROPERTY_INDEX_ENABLED));
    }
    String longRunningTaskId = configurationService.getValue(roleCatalogueService.getConfigurationPropertyName(IdmRoleCatalogueService.CONFIGURATION_PROPERTY_REBUILD));
    if (StringUtils.hasLength(longRunningTaskId) && !longRunningTaskId.equals(getLongRunningTaskId().toString())) {
        throw new ResultCodeException(CoreResultCode.FOREST_INDEX_RUNNING, ImmutableMap.of("type", IdmRoleCatalogue.FOREST_TREE_TYPE));
    }
    // 
    LOG.info("Starting rebuilding index for role catalogue.");
    // clear all rgt, lft
    try {
        forestIndexService.dropIndexes(IdmRoleCatalogue.FOREST_TREE_TYPE);
    } finally {
        configurationService.setBooleanValue(roleCatalogueService.getConfigurationPropertyName(IdmRoleCatalogueService.CONFIGURATION_PROPERTY_VALID), false);
    }
    try {
        configurationService.setValue(roleCatalogueService.getConfigurationPropertyName(IdmRoleCatalogueService.CONFIGURATION_PROPERTY_REBUILD), getLongRunningTaskId().toString());
        // 
        Page<IdmRoleCatalogue> nodes = roleCatalogueRepository.findAll(new PageRequest(0, 100, new Sort("id")));
        count = nodes.getTotalElements();
        counter = 0L;
        boolean canContinue = true;
        while (canContinue) {
            for (IdmRoleCatalogue node : nodes) {
                if (node.getForestIndex() == null) {
                    forestIndexService.index(node.getForestTreeType(), node.getId(), node.getParentId());
                }
                counter++;
                canContinue = updateState();
                if (!canContinue) {
                    break;
                }
            }
            ;
            if (!nodes.hasNext()) {
                break;
            }
            nodes = roleCatalogueRepository.findAll(nodes.nextPageable());
        }
        // 
        if (count.equals(counter)) {
            configurationService.deleteValue(roleCatalogueService.getConfigurationPropertyName(IdmRoleCatalogueService.CONFIGURATION_PROPERTY_VALID));
            LOG.info("Forest index for role catalogue was successfully rebuilt (index size [{}]).", counter);
            return Boolean.TRUE;
        }
        // 
        LOG.warn("Forest index for role catalogue rebuild was canceled (index size [{}]).", counter);
        return Boolean.FALSE;
    } finally {
        configurationService.deleteValue(roleCatalogueService.getConfigurationPropertyName(IdmRoleCatalogueService.CONFIGURATION_PROPERTY_REBUILD));
    }
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Sort(org.springframework.data.domain.Sort) IdmRoleCatalogue(eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogue)

Example 2 with IdmRoleCatalogue

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

the class RebuildRoleCatalogueIndexTaskExecutor method processChildren.

private boolean processChildren(List<IdmRoleCatalogue> nodes) {
    boolean canContinue = true;
    for (IdmRoleCatalogue 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(roleCatalogueRepository.findDirectChildren(node, null).getContent());
        if (!canContinue) {
            break;
        }
    }
    ;
    return canContinue;
}
Also used : IdmRoleCatalogue(eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogue)

Example 3 with IdmRoleCatalogue

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

the class RoleByRoleCatalogueEvaluator method getPredicate.

@Override
public Predicate getPredicate(Root<IdmRole> root, CriteriaQuery<?> query, CriteriaBuilder builder, AuthorizationPolicy policy, BasePermission... permission) {
    // check before apply evaluator
    UUID roleCatalogueId = getUuid(policy);
    if (roleCatalogueId == null) {
        return null;
    }
    // subquery to role catalogue role
    Subquery<IdmRoleCatalogueRole> subquery = query.subquery(IdmRoleCatalogueRole.class);
    Root<IdmRoleCatalogueRole> subRoot = subquery.from(IdmRoleCatalogueRole.class);
    subquery.select(subRoot);
    Subquery<IdmRoleCatalogue> subqueryRoleCatalogue = query.subquery(IdmRoleCatalogue.class);
    Root<IdmRoleCatalogue> subRoleCatalogueRoot = subqueryRoleCatalogue.from(IdmRoleCatalogue.class);
    subqueryRoleCatalogue.select(subRoleCatalogueRoot);
    subqueryRoleCatalogue.where(builder.and(builder.equal(subRoleCatalogueRoot.get(IdmRoleCatalogue_.id), roleCatalogueId), builder.between(subRoot.get(IdmRoleCatalogueRole_.roleCatalogue).get(IdmRoleCatalogue_.forestIndex).get(IdmForestIndexEntity_.lft), subRoleCatalogueRoot.get(IdmRoleCatalogue_.forestIndex).get(IdmForestIndexEntity_.lft), subRoleCatalogueRoot.get(IdmRoleCatalogue_.forestIndex).get(IdmForestIndexEntity_.rgt))));
    subquery.where(builder.and(// correlation attr
    builder.equal(subRoot.get(IdmRoleCatalogueRole_.role), root), builder.exists(subqueryRoleCatalogue)));
    return builder.exists(subquery);
}
Also used : IdmRoleCatalogue(eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogue) UUID(java.util.UUID) IdmRoleCatalogueRole(eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogueRole)

Example 4 with IdmRoleCatalogue

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

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

the class DefaultIdmRoleService method toPredicates.

@Override
protected List<Predicate> toPredicates(Root<IdmRole> root, CriteriaQuery<?> query, CriteriaBuilder builder, IdmRoleFilter filter) {
    List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
    // 
    // role type
    RoleType roleType = filter.getRoleType();
    if (roleType != null) {
        predicates.add(builder.equal(root.get(IdmRole_.roleType), roleType));
    }
    // role catalogue by forest index
    UUID roleCatalogueId = filter.getRoleCatalogueId();
    if (roleCatalogueId != null) {
        Subquery<IdmRoleCatalogueRole> subquery = query.subquery(IdmRoleCatalogueRole.class);
        Root<IdmRoleCatalogueRole> subRoot = subquery.from(IdmRoleCatalogueRole.class);
        subquery.select(subRoot);
        Subquery<IdmRoleCatalogue> subqueryCatalogue = query.subquery(IdmRoleCatalogue.class);
        Root<IdmRoleCatalogue> subRootCatalogue = subqueryCatalogue.from(IdmRoleCatalogue.class);
        subqueryCatalogue.select(subRootCatalogue);
        subqueryCatalogue.where(builder.and(builder.equal(subRootCatalogue.get(IdmRoleCatalogue_.id), roleCatalogueId), builder.between(subRoot.get(IdmRoleCatalogueRole_.roleCatalogue).get(IdmRoleCatalogue_.forestIndex).get(IdmForestIndexEntity_.lft), subRootCatalogue.get(IdmRoleCatalogue_.forestIndex).get(IdmForestIndexEntity_.lft), subRootCatalogue.get(IdmRoleCatalogue_.forestIndex).get(IdmForestIndexEntity_.rgt))));
        subquery.where(builder.and(// correlation attr
        builder.equal(subRoot.get(IdmRoleCatalogueRole_.role), root), builder.exists(subqueryCatalogue)));
        predicates.add(builder.exists(subquery));
    }
    // environment
    List<String> environments = filter.getEnvironments();
    if (!CollectionUtils.isEmpty(environments)) {
        predicates.add(root.get(IdmRole_.environment).in(environments));
    }
    // baseCode
    String baseCode = filter.getBaseCode();
    if (StringUtils.isNotEmpty(baseCode)) {
        predicates.add(builder.equal(root.get(IdmRole_.baseCode), baseCode));
    }
    UUID parent = filter.getParent();
    if (parent != null) {
        Subquery<IdmRoleComposition> subquery = query.subquery(IdmRoleComposition.class);
        Root<IdmRoleComposition> subRoot = subquery.from(IdmRoleComposition.class);
        subquery.select(subRoot);
        subquery.where(builder.and(// correlation attr
        builder.equal(subRoot.get(IdmRoleComposition_.sub), root), builder.equal(subRoot.get(IdmRoleComposition_.superior).get(IdmRole_.id), parent)));
        // 
        predicates.add(builder.exists(subquery));
    }
    // form definition for role attributes
    UUID definitionId = filter.getAttributeFormDefinitionId();
    if (definitionId != null) {
        predicates.add(builder.equal(root.get(IdmRole_.identityRoleAttributeDefinition).get(IdmFormDefinition_.id), definitionId));
    }
    // without role catalogue
    Boolean withoutCatalogue = filter.getWithoutCatalogue();
    if (withoutCatalogue != null) {
        Subquery<IdmRoleCatalogueRole> subquery = query.subquery(IdmRoleCatalogueRole.class);
        Root<IdmRoleCatalogueRole> subRoot = subquery.from(IdmRoleCatalogueRole.class);
        subquery.select(subRoot);
        subquery.where(builder.equal(subRoot.get(IdmRoleCatalogueRole_.role), root));
        // 
        if (withoutCatalogue) {
            // without
            predicates.add(builder.not(builder.exists(subquery)));
        } else {
            // with some
            predicates.add(builder.exists(subquery));
        }
    }
    // 
    return predicates;
}
Also used : IdmRoleComposition(eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition) RoleType(eu.bcvsolutions.idm.core.api.domain.RoleType) IdmRoleCatalogue(eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogue) IdmRoleCatalogueRole(eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogueRole) Predicate(javax.persistence.criteria.Predicate) UUID(java.util.UUID)

Aggregations

IdmRoleCatalogue (eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogue)6 UUID (java.util.UUID)3 IdmRoleCatalogueRole (eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogueRole)2 Predicate (javax.persistence.criteria.Predicate)2 RoleType (eu.bcvsolutions.idm.core.api.domain.RoleType)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 IdmForestIndexEntity (eu.bcvsolutions.idm.core.model.entity.IdmForestIndexEntity)1 IdmRoleComposition (eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition)1 PageRequest (org.springframework.data.domain.PageRequest)1 Sort (org.springframework.data.domain.Sort)1 Transactional (org.springframework.transaction.annotation.Transactional)1