private String convertToString(final Object value, final String format) { if (value == null) { return null; } return DataTypeUtils.toString(value, format); }
public static String toString(final Object value, final Supplier<DateFormat> format) { return toString(value, format, StandardCharsets.UTF_8); }
public static String toString(final Object value, final String format) { return toString(value, format, StandardCharsets.UTF_8); }
@Override protected boolean test(final FieldValue fieldValue, final RecordPathEvaluationContext context) { final String fieldVal = DataTypeUtils.toString(fieldValue.getValue(), (String) null); if (fieldVal == null) { return true; } return fieldVal.isEmpty(); } }
@Override protected boolean test(final FieldValue fieldValue, final RecordPathEvaluationContext context) { final String fieldVal = DataTypeUtils.toString(fieldValue.getValue(), (String) null); if (fieldVal == null) { return true; } return fieldVal.trim().isEmpty(); } }
public static String getFirstStringValue(final RecordPathSegment segment, final RecordPathEvaluationContext context) { final Optional<FieldValue> stringFieldValue = segment.evaluate(context).findFirst(); if (!stringFieldValue.isPresent()) { return null; } final String stringValue = DataTypeUtils.toString(stringFieldValue.get().getValue(), (String) null); if (stringValue == null) { return null; } return stringValue; } }
public ContainsRegex(RecordPathSegment recordPath, final RecordPathSegment regexPath) { super(recordPath); this.regexPath = regexPath; if (regexPath instanceof LiteralValuePath) { final FieldValue fieldValue = ((LiteralValuePath) regexPath).evaluate((RecordPathEvaluationContext) null).findFirst().get(); final Object value = fieldValue.getValue(); final String regex = DataTypeUtils.toString(value, (String) null); compiledPattern = Pattern.compile(regex); } else { compiledPattern = null; } }
public MatchesRegex(RecordPathSegment recordPath, final RecordPathSegment regexPath) { super(recordPath); this.regexPath = regexPath; if (regexPath instanceof LiteralValuePath) { final FieldValue fieldValue = ((LiteralValuePath) regexPath).evaluate((RecordPathEvaluationContext) null).findFirst().get(); final Object value = fieldValue.getValue(); final String regex = DataTypeUtils.toString(value, (String) null); compiledPattern = Pattern.compile(regex); } else { compiledPattern = null; } }
public ReplaceRegex(final RecordPathSegment recordPath, final RecordPathSegment searchValue, final RecordPathSegment replacementValue, final boolean absolute) { super("replaceRegex", null, absolute); this.recordPath = recordPath; this.searchValuePath = searchValue; if (searchValue instanceof LiteralValuePath) { final FieldValue fieldValue = ((LiteralValuePath) searchValue).evaluate((RecordPathEvaluationContext) null).findFirst().get(); final Object value = fieldValue.getValue(); final String regex = DataTypeUtils.toString(value, (String) null); compiledPattern = Pattern.compile(regex); } else { compiledPattern = null; } this.replacementValuePath = replacementValue; }
public Map<String, String> getAttributes() { final Map<String, String> attributes = new HashMap<>(); for (final Map.Entry<String, List<ValueWrapper>> entry : values.entrySet()) { final List<ValueWrapper> values = entry.getValue(); // If there are no values or there are multiple values, don't create an attribute. if (values.size() != 1) { continue; } // If value is null, don't create an attribute final Object value = values.get(0).get(); if (value == null) { continue; } // If value is not scalar, don't create an attribute if (value instanceof Object[] || value instanceof Map || value instanceof Record) { continue; } // There exists a single value that is scalar. Create attribute using the property name as the attribute name final String attributeValue = DataTypeUtils.toString(value, (String) null); attributes.put(entry.getKey(), attributeValue); } return attributes; }
@Override protected boolean test(final FieldValue fieldValue, final RecordPathEvaluationContext context) { final Pattern pattern; if (compiledPattern == null) { final Optional<FieldValue> fieldValueOption = regexPath.evaluate(context).findFirst(); if (!fieldValueOption.isPresent()) { return false; } final Object value = fieldValueOption.get().getValue(); if (value == null) { return false; } final String regex = DataTypeUtils.toString(value, (String) null); pattern = Pattern.compile(regex); } else { pattern = compiledPattern; } final String searchString = DataTypeUtils.toString(fieldValue.getValue(), (String) null); if (searchString == null) { return false; } return pattern.matcher(searchString).matches(); }
@Override protected boolean test(final FieldValue fieldValue, final RecordPathEvaluationContext context) { final String fieldVal = DataTypeUtils.toString(fieldValue.getValue(), (String) null); if (fieldVal == null) { return false; } final Optional<FieldValue> firstValue = searchValuePath.evaluate(context).findFirst(); if (!firstValue.isPresent()) { return false; } final String searchValue = DataTypeUtils.toString(firstValue.get().getValue(), (String) null); if (searchValue == null) { return false; } return isMatch(fieldVal, searchValue); }
@Override protected boolean test(final FieldValue fieldValue, final RecordPathEvaluationContext context) { final Pattern pattern; if (compiledPattern == null) { final Optional<FieldValue> fieldValueOption = regexPath.evaluate(context).findFirst(); if (!fieldValueOption.isPresent()) { return false; } final Object value = fieldValueOption.get().getValue(); if (value == null) { return false; } final String regex = DataTypeUtils.toString(value, (String) null); pattern = Pattern.compile(regex); } else { pattern = compiledPattern; } final String searchString = DataTypeUtils.toString(fieldValue.getValue(), (String) null); if (searchString == null) { return false; } return pattern.matcher(searchString).find(); }
@Override public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) { Stream<FieldValue> concatenated = Stream.empty(); for (final RecordPathSegment valuePath : valuePaths) { final Stream<FieldValue> stream = valuePath.evaluate(context); concatenated = Stream.concat(concatenated, stream); } final StringBuilder sb = new StringBuilder(); concatenated.forEach(fv -> sb.append(DataTypeUtils.toString(fv.getValue(), (String) null))); final RecordField field = new RecordField("concat", RecordFieldType.STRING.getDataType()); final FieldValue responseValue = new StandardFieldValue(sb.toString(), field, null); return Stream.of(responseValue); }
@Override public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) { final Stream<FieldValue> fieldValues = recordPath.evaluate(context); return fieldValues.filter(fv -> fv.getValue() != null) .map(fv -> { final String searchValue = RecordPathUtils.getFirstStringValue(searchValuePath, context); if (searchValue == null || searchValue.isEmpty()) { return fv; } final String value = DataTypeUtils.toString(fv.getValue(), (String) null); final int index = value.lastIndexOf(searchValue); if (index < 0) { return fv; } return new StandardFieldValue(value.substring(0, index), fv.getField(), fv.getParent().orElse(null)); }); }
@Override public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) { final Stream<FieldValue> fieldValues = recordPath.evaluate(context); return fieldValues.filter(fv -> fv.getValue() != null) .map(fv -> { final String searchValue = RecordPathUtils.getFirstStringValue(searchValuePath, context); if (searchValue == null || searchValue.isEmpty()) { return fv; } final String value = DataTypeUtils.toString(fv.getValue(), (String) null); final int index = value.indexOf(searchValue); if (index < 0) { return fv; } return new StandardFieldValue(value.substring(0, index), fv.getField(), fv.getParent().orElse(null)); }); }
@Override public String getAsString(final String fieldName) { final Optional<DataType> dataTypeOption = schema.getDataType(fieldName); if (dataTypeOption.isPresent()) { return convertToString(getValue(fieldName), dataTypeOption.get().getFormat()); } return DataTypeUtils.toString(getValue(fieldName), (Supplier<DateFormat>) null); }
@Override public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) { final Stream<FieldValue> fieldValues = recordPath.evaluate(context); return fieldValues.filter(fv -> fv.getValue() != null) .map(fv -> { final String searchValue = RecordPathUtils.getFirstStringValue(searchValuePath, context); if (searchValue == null || searchValue.isEmpty()) { return fv; } final String value = DataTypeUtils.toString(fv.getValue(), (String) null); final int index = value.indexOf(searchValue); if (index < 0) { return fv; } if (value.length() < index + 1) { return new StandardFieldValue("", fv.getField(), fv.getParent().orElse(null)); } return new StandardFieldValue(value.substring(index + searchValue.length()), fv.getField(), fv.getParent().orElse(null)); }); }
@Override public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) { final Stream<FieldValue> fieldValues = recordPath.evaluate(context); return fieldValues.filter(fv -> fv.getValue() != null) .map(fv -> { final String searchValue = RecordPathUtils.getFirstStringValue(searchValuePath, context); if (searchValue == null || searchValue.isEmpty()) { return fv; } final String value = DataTypeUtils.toString(fv.getValue(), (String) null); final int index = value.lastIndexOf(searchValue); if (index < 0) { return fv; } if (value.length() < index + 1) { return new StandardFieldValue("", fv.getField(), fv.getParent().orElse(null)); } return new StandardFieldValue(value.substring(index + searchValue.length()), fv.getField(), fv.getParent().orElse(null)); }); }
@Override public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) { final Stream<FieldValue> fieldValues = recordPath.evaluate(context); return fieldValues.filter(fv -> fv.getValue() != null) .map(fv -> { final String searchValue = RecordPathUtils.getFirstStringValue(searchValuePath, context); if (searchValue == null) { return fv; } final String replacementValue = RecordPathUtils.getFirstStringValue(replacementValuePath, context); if (replacementValue == null) { return fv; } final String value = DataTypeUtils.toString(fv.getValue(), (String) null); final String replaced = value.replace(searchValue, replacementValue); return new StandardFieldValue(replaced, fv.getField(), fv.getParent().orElse(null)); }); }