Search in sources :

Example 1 with SysSchemaAttribute

use of eu.bcvsolutions.idm.acc.entity.SysSchemaAttribute in project CzechIdMng by bcvsolutions.

the class DefaultSysSystemAttributeMappingService method toPredicates.

@Override
protected List<Predicate> toPredicates(Root<SysSystemAttributeMapping> root, CriteriaQuery<?> query, CriteriaBuilder builder, SysSystemAttributeMappingFilter filter) {
    List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
    // fulltext
    String text = filter.getText();
    if (!StringUtils.isEmpty(text)) {
        predicates.add(builder.like(builder.lower(root.get(SysSystemAttributeMapping_.name)), "%" + text.toLowerCase() + "%"));
    }
    if (filter.getSystemMappingId() != null) {
        predicates.add(builder.equal(root.get(SysSystemAttributeMapping_.systemMapping).get(AbstractEntity_.id), filter.getSystemMappingId()));
    }
    if (filter.getSchemaAttributeId() != null) {
        predicates.add(builder.equal(root.get(SysSystemAttributeMapping_.schemaAttribute).get(AbstractEntity_.id), filter.getSchemaAttributeId()));
    }
    if (!StringUtils.isEmpty(filter.getSchemaAttributeName())) {
        Subquery<SysSchemaAttribute> subquery = query.subquery(SysSchemaAttribute.class);
        Root<SysSchemaAttribute> subRoot = subquery.from(SysSchemaAttribute.class);
        subquery.select(subRoot);
        subquery.where(builder.and(// correlation attr
        builder.equal(root.get(SysSystemAttributeMapping_.schemaAttribute), subRoot), builder.equal(subRoot.get(SysSchemaAttribute_.name), filter.getSchemaAttributeName())));
        predicates.add(builder.exists(subquery));
    }
    if (filter.getSystemId() != null) {
        Subquery<SysSystemMapping> subquerySystemMapping = query.subquery(SysSystemMapping.class);
        Root<SysSystemMapping> subRootSystemMapping = subquerySystemMapping.from(SysSystemMapping.class);
        subquerySystemMapping.select(subRootSystemMapping);
        Subquery<SysSchemaObjectClass> subqueryObjectClass = query.subquery(SysSchemaObjectClass.class);
        Root<SysSchemaObjectClass> subRootObjectClass = subqueryObjectClass.from(SysSchemaObjectClass.class);
        subqueryObjectClass.select(subRootObjectClass);
        subqueryObjectClass.where(builder.and(// correlation attr
        builder.equal(subRootSystemMapping.get(SysSystemMapping_.objectClass), subRootObjectClass), builder.equal(subRootObjectClass.get(SysSchemaObjectClass_.system).get(AbstractEntity_.id), filter.getSystemId())));
        Predicate predicate = builder.exists(subquerySystemMapping.where(builder.and(builder.equal(root.get(SysSystemAttributeMapping_.systemMapping), subRootSystemMapping), builder.exists(subqueryObjectClass.where(builder.and(// correlation attr
        builder.equal(subRootSystemMapping.get(SysSystemMapping_.objectClass), subRootObjectClass), builder.equal(subRootObjectClass.get(SysSchemaObjectClass_.system).get(AbstractEntity_.id), filter.getSystemId())))))));
        predicates.add(predicate);
    }
    if (filter.getIsUid() != null) {
        if (BooleanUtils.isFalse(filter.getIsUid())) {
            predicates.add(builder.isFalse(root.get(SysSystemAttributeMapping_.uid)));
        } else {
            predicates.add(builder.isTrue(root.get(SysSystemAttributeMapping_.uid)));
        }
    }
    if (!StringUtils.isEmpty(filter.getIdmPropertyName())) {
        predicates.add(builder.equal(root.get(SysSystemAttributeMapping_.idmPropertyName), filter.getIdmPropertyName()));
    }
    if (filter.getSendOnPasswordChange() != null) {
        if (BooleanUtils.isFalse(filter.getSendOnPasswordChange())) {
            predicates.add(builder.isFalse(root.get(SysSystemAttributeMapping_.sendOnPasswordChange)));
        } else {
            predicates.add(builder.isTrue(root.get(SysSystemAttributeMapping_.sendOnPasswordChange)));
        }
    }
    if (filter.getSendOnlyOnPasswordChange() != null) {
        if (BooleanUtils.isFalse(filter.getSendOnlyOnPasswordChange())) {
            predicates.add(builder.isFalse(root.get(SysSystemAttributeMapping_.sendOnlyOnPasswordChange)));
        } else {
            predicates.add(builder.isTrue(root.get(SysSystemAttributeMapping_.sendOnlyOnPasswordChange)));
        }
    }
    if (filter.getPasswordAttribute() != null) {
        if (BooleanUtils.isFalse(filter.getPasswordAttribute())) {
            predicates.add(builder.isFalse(root.get(SysSystemAttributeMapping_.passwordAttribute)));
        } else {
            predicates.add(builder.isTrue(root.get(SysSystemAttributeMapping_.passwordAttribute)));
        }
    }
    if (filter.getDisabledAttribute() != null) {
        if (BooleanUtils.isFalse(filter.getDisabledAttribute())) {
            predicates.add(builder.isFalse(root.get(SysSystemAttributeMapping_.disabledAttribute)));
        } else {
            predicates.add(builder.isTrue(root.get(SysSystemAttributeMapping_.disabledAttribute)));
        }
    }
    if (filter.getOperationType() != null) {
        Subquery<SysSystemMapping> subquery = query.subquery(SysSystemMapping.class);
        Root<SysSystemMapping> subRoot = subquery.from(SysSystemMapping.class);
        subquery.select(subRoot);
        subquery.where(builder.and(// correlation attr
        builder.equal(root.get(SysSystemAttributeMapping_.systemMapping), subRoot), builder.equal(subRoot.get(SysSystemMapping_.operationType), filter.getOperationType())));
        predicates.add(builder.exists(subquery));
    }
    if (filter.getEntityType() != null) {
        Subquery<SysSystemMapping> subquery = query.subquery(SysSystemMapping.class);
        Root<SysSystemMapping> subRoot = subquery.from(SysSystemMapping.class);
        subquery.select(subRoot);
        subquery.where(builder.and(// correlation attr
        builder.equal(root.get(SysSystemAttributeMapping_.systemMapping), subRoot), builder.equal(subRoot.get(SysSystemMapping_.entityType), filter.getEntityType())));
        predicates.add(builder.exists(subquery));
    }
    if (!StringUtils.isEmpty(filter.getName())) {
        predicates.add(builder.equal(root.get(SysSystemAttributeMapping_.name), filter.getName()));
    }
    if (filter.getAuthenticationAttribute() != null) {
        if (BooleanUtils.isFalse(filter.getAuthenticationAttribute())) {
            predicates.add(builder.isFalse(root.get(SysSystemAttributeMapping_.authenticationAttribute)));
        } else {
            predicates.add(builder.isTrue(root.get(SysSystemAttributeMapping_.authenticationAttribute)));
        }
    }
    if (filter.getPasswordFilter() != null) {
        if (BooleanUtils.isFalse(filter.getPasswordFilter())) {
            predicates.add(builder.isFalse(root.get(SysSystemAttributeMapping_.passwordFilter)));
        } else {
            predicates.add(builder.isTrue(root.get(SysSystemAttributeMapping_.passwordFilter)));
        }
    }
    if (filter.getStrategyType() != null) {
        predicates.add(builder.equal(root.get(SysSystemAttributeMapping_.strategyType), filter.getStrategyType()));
    }
    if (filter.getId() != null) {
        predicates.add(builder.equal(root.get(SysSystemAttributeMapping_.id), filter.getId()));
    }
    return predicates;
}
Also used : SysSchemaObjectClass(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSchemaAttribute(eu.bcvsolutions.idm.acc.entity.SysSchemaAttribute) SysSystemMapping(eu.bcvsolutions.idm.acc.entity.SysSystemMapping) Predicate(javax.persistence.criteria.Predicate)

Aggregations

SysSchemaAttribute (eu.bcvsolutions.idm.acc.entity.SysSchemaAttribute)1 SysSchemaObjectClass (eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass)1 SysSystemMapping (eu.bcvsolutions.idm.acc.entity.SysSystemMapping)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 Predicate (javax.persistence.criteria.Predicate)1