Search in sources :

Example 1 with Occurrence

use of org.structr.api.search.Occurrence in project structr by structr.

the class UuidSearchAttribute method includeInResult.

@Override
public boolean includeInResult(final GraphObject entity) {
    String nodeValue = entity.getProperty(getKey());
    Occurrence occur = getOccurrence();
    String searchValue = getValue();
    if (occur.equals(Occurrence.FORBIDDEN)) {
        if ((nodeValue != null) && compare(nodeValue, searchValue) == 0) {
            // don't add, do not check other results
            return false;
        }
    } else {
        if (nodeValue != null) {
            if (compare(nodeValue, searchValue) != 0) {
                return false;
            }
        } else {
            if (searchValue != null && StringUtils.isNotBlank(searchValue)) {
                return false;
            }
        }
    }
    return true;
}
Also used : Occurrence(org.structr.api.search.Occurrence)

Example 2 with Occurrence

use of org.structr.api.search.Occurrence in project structr by structr.

the class QueryConfig method handleFieldArguments.

public void handleFieldArguments(final SecurityContext securityContext, final Class type, final Field parentField, final Field field) throws FrameworkException {
    final ConfigurationProvider config = StructrApp.getConfiguration();
    final PropertyKey parentKey = config.getPropertyKeyForJSONName(type, parentField.getName());
    final PropertyKey key = config.getPropertyKeyForJSONName(type, field.getName(), false);
    final List<SearchTuple> searchTuples = new LinkedList<>();
    Occurrence occurrence = Occurrence.REQUIRED;
    // parse arguments
    for (final Argument argument : field.getArguments()) {
        final String name = argument.getName();
        final Value value = argument.getValue();
        switch(name) {
            case "_equals":
                searchTuples.add(new SearchTuple(castValue(securityContext, key.relatedType(), key, value), true));
                break;
            case "_contains":
                searchTuples.add(new SearchTuple(castValue(securityContext, key.relatedType(), key, value), false));
                break;
            case "_conj":
                occurrence = getOccurrence(value);
                break;
            default:
                break;
        }
    }
    // only add field if a value was set
    for (final SearchTuple tuple : searchTuples) {
        addAttribute(parentKey, key.getSearchAttribute(securityContext, occurrence, tuple.value, tuple.exact, null), occurrence);
    }
}
Also used : Argument(graphql.language.Argument) ConfigurationProvider(org.structr.schema.ConfigurationProvider) ObjectValue(graphql.language.ObjectValue) Value(graphql.language.Value) StringValue(graphql.language.StringValue) IntValue(graphql.language.IntValue) BooleanValue(graphql.language.BooleanValue) Occurrence(org.structr.api.search.Occurrence) PropertyKey(org.structr.core.property.PropertyKey) LinkedList(java.util.LinkedList)

Example 3 with Occurrence

use of org.structr.api.search.Occurrence in project structr by structr.

the class EmptySearchAttribute method includeInResult.

@Override
public boolean includeInResult(GraphObject entity) {
    Occurrence occur = getOccurrence();
    T searchValue = getValue();
    T nodeValue = entity.getProperty(getKey());
    if (occur.equals(Occurrence.FORBIDDEN)) {
        if ((nodeValue != null) && !equal(nodeValue, searchValue)) {
            // don't add, do not check other results
            return false;
        }
    } else {
        if (nodeValue != null) {
            if (!equal(nodeValue, searchValue)) {
                return false;
            }
        } else {
            if (searchValue != null) {
                return false;
            }
        }
    }
    return true;
}
Also used : Occurrence(org.structr.api.search.Occurrence)

Example 4 with Occurrence

use of org.structr.api.search.Occurrence in project structr by structr.

the class NotBlankSearchAttribute method includeInResult.

@Override
public boolean includeInResult(GraphObject entity) {
    Occurrence occur = getOccurrence();
    T nodeValue = entity.getProperty(getKey());
    if (occur.equals(Occurrence.FORBIDDEN)) {
        // reverse
        return nodeValue == null;
    } else {
        return nodeValue != null;
    }
}
Also used : Occurrence(org.structr.api.search.Occurrence)

Example 5 with Occurrence

use of org.structr.api.search.Occurrence in project structr by structr.

the class PropertySearchAttribute method includeInResult.

@Override
public boolean includeInResult(final GraphObject entity) {
    T nodeValue = entity.getProperty(getKey());
    Occurrence occur = getOccurrence();
    T searchValue = getValue();
    if (occur.equals(Occurrence.FORBIDDEN)) {
        if ((nodeValue != null) && compare(nodeValue, searchValue) == 0) {
            // don't add, do not check other results
            return false;
        }
    } else {
        if (nodeValue != null) {
            if (!isExactMatch) {
                if (nodeValue instanceof String && searchValue instanceof String) {
                    String n = (String) nodeValue;
                    String s = (String) searchValue;
                    return StringUtils.containsIgnoreCase(n, s);
                }
            }
            if (compare(nodeValue, searchValue) != 0) {
                return false;
            }
        } else {
            if (searchValue != null && StringUtils.isNotBlank(searchValue.toString())) {
                return false;
            }
        }
    }
    return true;
}
Also used : Occurrence(org.structr.api.search.Occurrence)

Aggregations

Occurrence (org.structr.api.search.Occurrence)6 Argument (graphql.language.Argument)1 BooleanValue (graphql.language.BooleanValue)1 IntValue (graphql.language.IntValue)1 ObjectValue (graphql.language.ObjectValue)1 StringValue (graphql.language.StringValue)1 Value (graphql.language.Value)1 LinkedList (java.util.LinkedList)1 PropertyKey (org.structr.core.property.PropertyKey)1 ConfigurationProvider (org.structr.schema.ConfigurationProvider)1