protected boolean matches()

in core/persistence-common/src/main/java/org/apache/syncope/core/persistence/common/dao/AbstractAnyMatchDAO.java [402:498]


    protected boolean matches(final Any any, final AnyCond cond, final boolean not) {
        // Keeps track of difference between entity's getKey() and @Id fields
        if ("key".equals(cond.getSchema())) {
            cond.setSchema("id");
        }

        PropertyDescriptor pd;
        Object anyAttrValue;
        try {
            pd = BeanUtils.getPropertyDescriptor(any.getClass(), cond.getSchema());
            if (pd == null) {
                LOG.warn("Ignoring invalid schema '{}'", cond.getSchema());
                return false;
            }

            anyAttrValue = pd.getReadMethod().invoke(any);
        } catch (Exception e) {
            LOG.error("While accessing {}.{}", any, cond.getSchema(), e);
            return false;
        }

        boolean found;
        switch (cond.getType()) {
            case ISNULL:
                found = anyAttrValue == null;
                break;

            case ISNOTNULL:
                found = anyAttrValue != null;
                break;

            default:
                PlainSchema schema = entityFactory.newEntity(PlainSchema.class);
                schema.setKey(pd.getName());
                for (AttrSchemaType attrSchemaType : AttrSchemaType.values()) {
                    if (pd.getPropertyType().isAssignableFrom(attrSchemaType.getType())) {
                        schema.setType(attrSchemaType);
                    }
                }

                // Deal with any Integer fields logically mapping to boolean values
                boolean foundBooleanMin = false;
                boolean foundBooleanMax = false;
                if (Integer.class.equals(pd.getPropertyType())) {
                    for (Annotation annotation : pd.getPropertyType().getAnnotations()) {
                        if (Min.class.equals(annotation.annotationType())) {
                            foundBooleanMin = ((Min) annotation).value() == 0;
                        } else if (Max.class.equals(annotation.annotationType())) {
                            foundBooleanMax = ((Max) annotation).value() == 1;
                        }
                    }
                }
                if (foundBooleanMin && foundBooleanMax) {
                    schema.setType(AttrSchemaType.Boolean);
                }

                // Deal with any fields representing relationships to other entities
                relationshipFieldMatches(pd, cond, schema);

                PlainAttrValue attrValue = new PlainAttrValue();
                if (cond.getType() != AttrCond.Type.LIKE
                        && cond.getType() != AttrCond.Type.ILIKE
                        && cond.getType() != AttrCond.Type.ISNULL
                        && cond.getType() != AttrCond.Type.ISNOTNULL) {

                    try {
                        validator.validate(schema, cond.getExpression(), attrValue);
                    } catch (ValidationException e) {
                        LOG.error("Could not validate expression '{}'", cond.getExpression(), e);
                        return false;
                    }
                }

                List<PlainAttrValue> anyAttrValues = new ArrayList<>();
                anyAttrValues.add(new PlainAttrValue());
                switch (anyAttrValue) {
                    case String aString ->
                        anyAttrValues.getFirst().setStringValue(aString);
                    case Long aLong ->
                        anyAttrValues.getFirst().setLongValue(aLong);
                    case Double aDouble ->
                        anyAttrValues.getFirst().setDoubleValue(aDouble);
                    case Boolean aBoolean ->
                        anyAttrValues.getFirst().setBooleanValue(aBoolean);
                    case OffsetDateTime offsetDateTime ->
                        anyAttrValues.getFirst().setDateValue(offsetDateTime);
                    case byte[] bytea ->
                        anyAttrValues.getFirst().setBinaryValue(bytea);
                    default -> {
                    }
                }

                found = matches(anyAttrValues, attrValue, schema, cond);

        }
        return not ? !found : found;
    }