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;
}
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;
}
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
}
}
}
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());
}
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()));
}
Aggregations