protected ValueFormatter getFormatter(ValueType valueType) { ValueFormatter formatter = FORMATTERS.get(valueType.getBaseName()); return formatter == null ? ALL_FORMATTER : formatter; }
/** * * @throws IllegalArgumentException if the value cannot be parsed or if the value type * is not supported */ public static Object fromString(String value, ValueType valueType, IdGenerator idGenerator) { StringConverter converter = CONVERTERS.get(valueType.getBaseName()); if (converter == null) { throw new IllegalArgumentException("Value type not supported: " + valueType.getBaseName()); } return converter.fromString(value, idGenerator); }
@Override protected ValueFormatter getFormatter(ValueType valueType) { if ("RECORD".equals(valueType.getBaseName())) { return RECORD_KEY_VALUE_FORMATTER; } else { return super.getFormatter(valueType); } }
public static String toString(Object value, ValueType valueType) { if (value == null) { throw new NullPointerException(); } if (!valueType.getType().isAssignableFrom(value.getClass())) { throw new IllegalArgumentException("Value is not of the type indicated by the value type. Value type" + " class: " + valueType.getType().getName() + ", value class: " + value.getClass().getName()); } StringConverter converter = CONVERTERS.get(valueType.getBaseName()); if (converter == null) { throw new IllegalArgumentException("Value type not supported: " + valueType.getBaseName()); } return converter.toString(value); }
public static List flatList(Object value, ValueType type) { if (type.getBaseName().equals("LIST")) { if (type.getNestedValueType().getBaseName() != "LIST") { return (List)value; } else { List result = Lists.newArrayList(); for (Object nValue: (List)value) { result.addAll(flatList(nValue, type.getNestedValueType())); } return result; } } else { return Collections.singletonList(value); } }
@Override public boolean accept(FieldType fieldtype) { return fieldtype.getValueType().getDeepestValueType().getBaseName().equals("LINK"); } };
private static void extract(Object value, FieldType fieldType, LinkCollector collector, FieldType ctxField, RecordId ctxRecord, LRepository repository) throws RepositoryException, InterruptedException { ValueType valueType = fieldType.getValueType(); String baseType = valueType.getDeepestValueType().getBaseName(); if (baseType.equals("LINK") || baseType.equals("RECORD")) { extract(value, collector, ctxField, ctxRecord, repository); } }
@Override public List<String> format(List<IndexValue> indexValues, LRepository repository) throws InterruptedException { List<String> result = new ArrayList<String>(); for (IndexValue indexValue : indexValues) { ValueType valueType = indexValue.fieldType.getValueType(); if (valueType.getBaseName().equals("LIST")) { // The values of the first list-level are supplied as individual IndexValues valueType = valueType.getNestedValueType(); } if (!valueType.getName().equals("STRING")) { throw new RuntimeException(this.getClass().getSimpleName() + " only supports string values, but got: " + valueType.getName()); } processPath((String)indexValue.value, result); } return result; }
/** * Returns true if the given FieldType is a version tag. */ public static boolean isVersionTag(FieldType fieldType) { String namespace = fieldType.getName().getNamespace(); return (fieldType.getScope() == Scope.NON_VERSIONED && fieldType.getValueType().getBaseName().equals("LONG") && namespace != null && namespace.equals(NAMESPACE) /* namespace is typically the longest string, therefore compare it last */ && !fieldType.getName().getName().equals("last")); /* filter out 'last' vtag, it should not be custom assigned */ }
@Override public List<String> format(List<IndexValue> indexValues, LRepository repository) throws InterruptedException { List<String> results = new ArrayList<String>(); for (IndexValue value : filterValues(indexValues)) { FormatContext formatCtx = new FormatContext(repository); ValueType valueType = value.fieldType.getValueType(); if (valueType.getBaseName().equals("LIST")) { // The values of the first list-level are supplied as individual IndexValues valueType = valueType.getNestedValueType(); } String result = formatCtx.format(value.value, valueType, formatCtx); if (result != null) { results.add(result); } else { results.addAll(formatCtx.results); } } return results; }
private Follow processFieldDeref(Element fieldEl, String derefPart) throws IndexerConfException, InterruptedException, RepositoryException { FieldType followField = ConfUtil.getFieldType(derefPart, fieldEl, systemFields, typeManager); String type = followField.getValueType().getBaseName(); if (type.equals("LIST")) { type = followField.getValueType().getNestedValueType().getBaseName(); } if (type.equals("RECORD")) { return new RecordFieldFollow(followField); } else if (type.equals("LINK")) { return new LinkFieldFollow(followField); } else { throw new IndexerConfException("Dereferencing is not possible on field of type " + followField.getValueType().getName() + ". Field: '" + derefPart); } }
/** * @param indexValues * optional, if supplied values will be added to this list, * otherwise a new list will be created and returned * @return null if there's no value */ private List<IndexValue> getValue(IndexUpdateBuilder indexUpdateBuilder, FieldType fieldType, List<IndexValue> indexValues) throws RepositoryException, InterruptedException { Record record = indexUpdateBuilder.getRecordContext().record; Object value = getValue(indexUpdateBuilder, fieldType); List<IndexValue> result; if (value == null) { return null; } if (fieldType.getValueType().getBaseName().equals("LIST")) { List<Object> values = (List<Object>) value; result = indexValues != null ? indexValues : new ArrayList<IndexValue>(values.size()); for (int i = 0; i < values.size(); i++) { result.add(new IndexValue(record, fieldType, i, values.get(i))); } return result; } else { if (indexValues != null) { indexValues.add(new IndexValue(record, fieldType, value)); result = indexValues; } else { result = Collections.singletonList(new IndexValue(record, fieldType, value)); } } return result; }
/** * Direct 'evaluation' (content extraction, formatting) of a given field * from a record. Should only be called if the field is present in the * record. */ public List<String> format(String table, Record record, FieldType fieldType, boolean extractContent, String formatterName, LRepository repository) throws InterruptedException { Object value = record.getField(fieldType.getName()); List<IndexValue> indexValues; if (fieldType.getValueType().getBaseName().equals("LIST")) { List<Object> values = (List<Object>) value; indexValues = new ArrayList<IndexValue>(values.size()); for (int i = 0; i < values.size(); i++) { indexValues.add(new IndexValue(record, fieldType, i, values.get(i))); } } else { indexValues = Collections.singletonList(new IndexValue(record, fieldType, value)); } if (fieldType.getValueType().getDeepestValueType().getBaseName().equals("BLOB") && extractContent) { return extractContent(table, indexValues, repository); } Formatter formatter = conf.getFormatters().getFormatter(formatterName); return formatter.format(indexValues, repository); }
public JsonNode valueToJson(Object value, ValueType valueType, WriteOptions options, Namespaces namespaces, LRepository repository) throws RepositoryException, InterruptedException { String name = valueType.getBaseName();
Object value = record.getField(fieldName); ValueType valueType = fieldType.getValueType(); if (!valueType.getDeepestValueType().getBaseName().equals("BLOB")) { throw new BlobNotFoundException("Blob could not be retrieved from '" + record.getId() + "', '" + fieldName + "' at index: " + Ints.join("/", indexes)); int index = indexes[i]; try { if (valueType.getBaseName().equals("LIST")) { value = ((List<Object>) value).get(index); valueType = valueType.getNestedValueType(); continue; if (valueType.getBaseName().equals("PATH")) { value = ((HierarchyPath)value).getElements()[index]; valueType = valueType.getNestedValueType(); if (!valueType.getBaseName().equals("BLOB")) { throw new BlobNotFoundException("Blob could not be retrieved from '" + record.getId() + "', '" + fieldName + "' at index: " + Ints.join("/", indexes));
throws JsonFormatException, RepositoryException, InterruptedException { String name = handle.valueType.getBaseName();
throw new RuntimeException("Field metadata is currently not supported for versioned-mutable fields."); if (fieldType.getValueType().getDeepestValueType().getBaseName().equals("BLOB")) { throw new RuntimeException("Field metadata is currently not supported for BLOB fields.");
!value.getTargetFieldType().getValueType().getDeepestValueType().getBaseName().equals("BLOB")) { throw new IndexerConfException("extractContent is used for a non-blob value at " + LocationAttributes.getLocation(fieldEl));
if (!fieldType.getValueType().getBaseName().equals("LONG")) { throw new JsonFormatException("vtag fields should be of type LONG");