Search in sources :

Example 26 with Value

use of com.enonic.xp.data.Value in project xp by enonic.

the class ContentMappingConstraint method matches.

public boolean matches(final Content content) {
    final String val = trimQuotes(this.value);
    if (ID_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.getId().toString());
    } else if (NAME_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.getName().toString());
    } else if (PATH_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.getPath().toString());
    } else if (TYPE_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.getType().toString());
    } else if (DISPLAY_NAME_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.getDisplayName());
    } else if (HAS_CHILDREN_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.hasChildren());
    } else if (LANGUAGE_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.getLanguage() == null ? "" : content.getLanguage().toLanguageTag());
    } else if (VALID_PROPERTY.equals(this.id)) {
        return valueMatches(val, content.isValid());
    } else if (this.id.startsWith(DATA_PROPERTY_PREFIX)) {
        final String dataPath = id.substring(DATA_PROPERTY_PREFIX.length());
        final Property prop = content.getData().getProperty(dataPath);
        if (prop == null || prop.getValue() == null) {
            return false;
        }
        final Value propertyValue = convert(val, prop.getValue().getType());
        return propertyValue != null && valueMatches(propertyValue.asString(), prop.getValue().asString());
    } else if (this.id.startsWith(XDATA_PROPERTY_PREFIX)) {
        final String dataPath = id.substring(XDATA_PROPERTY_PREFIX.length());
        final String appPrefix;
        final String mixinName;
        final String propertyName;
        final int firstIndex = dataPath.indexOf(".");
        if (firstIndex == -1) {
            appPrefix = dataPath;
            mixinName = "";
            propertyName = "";
        } else {
            appPrefix = dataPath.substring(0, firstIndex);
            final int secondIndex = dataPath.indexOf(".", firstIndex + 1);
            mixinName = secondIndex == -1 ? dataPath.substring(firstIndex + 1) : dataPath.substring(firstIndex + 1, secondIndex);
            propertyName = secondIndex == -1 ? "" : dataPath.substring(secondIndex + 1);
        }
        final PropertyTree xData = getXData(content.getAllExtraData(), appPrefix, mixinName);
        if (xData == null) {
            return false;
        }
        final Property prop = xData.getProperty(propertyName);
        if (prop == null || prop.getValue() == null) {
            return false;
        }
        final Value propertyValue = convert(val, prop.getValue().getType());
        return propertyValue != null && valueMatches(propertyValue.asString(), prop.getValue().asString());
    }
    return false;
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Value(com.enonic.xp.data.Value) Property(com.enonic.xp.data.Property)

Example 27 with Value

use of com.enonic.xp.data.Value in project xp by enonic.

the class FilterBuilderFactory method createRangeFilter.

private QueryBuilder createRangeFilter(final RangeFilter filter) {
    final Value from = filter.getFrom();
    final Value to = filter.getTo();
    if (from == null && to == null) {
        return null;
    }
    final String queryFieldName = this.fieldNameResolver.resolve(filter.getFieldName(), from != null ? from : to);
    RangeQueryBuilder builder = new RangeQueryBuilder(queryFieldName).from(from).to(to).includeLower(filter.isIncludeLower()).includeUpper(filter.isIncludeUpper());
    return builder;
}
Also used : Value(com.enonic.xp.data.Value) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder)

Example 28 with Value

use of com.enonic.xp.data.Value in project xp by enonic.

the class ContentTypeMapper method serializeDefaultValue.

private void serializeDefaultValue(final MapGenerator gen, final Input input) {
    if (input.getDefaultValue() != null) {
        try {
            final Value defaultValue = InputTypes.BUILTIN.resolve(input.getInputType()).createDefaultValue(input);
            if (defaultValue != null) {
                gen.map("default");
                gen.value("value", defaultValue.getObject());
                gen.value("type", defaultValue.getType().getName());
                gen.end();
            }
        } catch (IllegalArgumentException ex) {
        // DO NOTHING
        }
    }
}
Also used : Value(com.enonic.xp.data.Value)

Example 29 with Value

use of com.enonic.xp.data.Value in project xp by enonic.

the class RepoDumper method getVersions.

private NodeVersionQueryResult getVersions(final NodeId nodeId) {
    final NodeVersionQuery.Builder queryBuilder = NodeVersionQuery.create().nodeId(nodeId).size(this.maxVersions != null ? this.maxVersions : -1);
    if (this.maxAge != null) {
        final Value ageValue = ValueFactory.newDateTime(Instant.now().minus(Duration.ofDays(this.maxAge)));
        queryBuilder.addQueryFilter(RangeFilter.create().from(ageValue).build());
    }
    return this.nodeService.findVersions(queryBuilder.build());
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) Value(com.enonic.xp.data.Value)

Example 30 with Value

use of com.enonic.xp.data.Value in project xp by enonic.

the class LikeExpressionBuilder method build.

public static QueryBuilder build(final CompareExpr compareExpr, final QueryFieldNameResolver resolver) {
    final String queryFieldName = resolver.resolve(compareExpr.getField().getFieldPath());
    if (compareExpr.getFirstValue() == null) {
        throw new IllegalArgumentException("Invalid compare expression [" + compareExpr + "]");
    }
    final Value value = compareExpr.getFirstValue().getValue();
    return QueryBuilders.wildcardQuery(queryFieldName, IndexValueNormalizer.normalize(value.asString()));
}
Also used : Value(com.enonic.xp.data.Value)

Aggregations

Value (com.enonic.xp.data.Value)62 Test (org.junit.jupiter.api.Test)48 Input (com.enonic.xp.form.Input)24 Property (com.enonic.xp.data.Property)4 PropertySet (com.enonic.xp.data.PropertySet)4 PropertyTree (com.enonic.xp.data.PropertyTree)3 InputType (com.enonic.xp.inputtype.InputType)2 Instant (java.time.Instant)2 PropertyPath (com.enonic.xp.data.PropertyPath)1 FieldSet (com.enonic.xp.form.FieldSet)1 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)1 IndexConfig (com.enonic.xp.index.IndexConfig)1 IndexValueProcessor (com.enonic.xp.index.IndexValueProcessor)1 AttachedBinary (com.enonic.xp.node.AttachedBinary)1 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)1 Node (com.enonic.xp.node.Node)1 NodePath (com.enonic.xp.node.NodePath)1 NodeQuery (com.enonic.xp.node.NodeQuery)1 NodeVersion (com.enonic.xp.node.NodeVersion)1 NodeVersionQuery (com.enonic.xp.node.NodeVersionQuery)1