public Set<QName> getFieldDependencies() { return fieldType != null ? Collections.singleton(fieldType.getName()) : Collections.<QName>emptySet(); }
public FieldTypeExistsException(FieldType fieldType) { if (fieldType != null) { this.fieldType = fieldType.getName().toString(); } }
public static Map<Scope, Set<QName>> getFieldTypeNamesAndScope(Set<SchemaId> fieldIds, FieldFilter fieldFilter, TypeManager typeManager) throws RepositoryException, InterruptedException { Map<Scope, Set<QName>> result = new HashMap<Scope, Set<QName>>(); Map<Scope, Set<FieldType>> fieldTypesByScope = getFieldTypeAndScope(fieldIds, fieldFilter, typeManager); for (Scope scope: fieldTypesByScope.keySet()) { Set<QName> schemaIds = new HashSet<QName>(); for (FieldType t: fieldTypesByScope.get(scope)) { schemaIds.add(t.getName()); } result.put(scope, schemaIds); } return result; } }
private Set<QName> getAllRepositoryFields() throws RepositoryException, InterruptedException { final Set<QName> result = new HashSet<QName>(); for (FieldType fieldType : repository.getTypeManager().getFieldTypes()) { result.add(fieldType.getName()); } 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 boolean isIndexAffectedByUpdate(VTaggedRecord vtRecord, Scope scope) throws InterruptedException, RepositoryException { if (fieldType != null && !systemFields.isSystemField(fieldType.getName())) { return vtRecord.getRecordEventHelper().getUpdatedFieldsByScope().get(scope).contains(fieldType); } return false; }
/** * Extracts the given field value from the record and transforms it into a flat (java) list, * regardless of the valueType of the field. * @param record * @param fieldType * @return */ public static List flatList(Record record, FieldType fieldType) { if (record != null && record.hasField(fieldType.getName())) { return flatList(record.getField(fieldType.getName()), fieldType.getValueType()); } else { return Collections.emptyList(); } }
@Override public FieldType createOrUpdateFieldType(FieldType fieldType) throws RepositoryException, InterruptedException { if (fieldType.getId() == null) { fieldType.setId(new SchemaIdImpl(UUID.randomUUID())); } fieldTypesByName.put(fieldType.getName(), fieldType); fieldTypes.put(fieldType.getId(), fieldType); return fieldType; }
private Object getValue(IndexUpdateBuilder indexUpdateBuilder, FieldType fieldType) throws RepositoryException, InterruptedException { Object value = null; Record record = indexUpdateBuilder.getRecordContext().record; if (systemFields.isSystemField(fieldType.getName())) { if (record != null) { value = systemFields.eval(record, fieldType, indexUpdateBuilder.getRepository().getTypeManager()); } } else { indexUpdateBuilder.addDependency(fieldType.getId()); if (record != null && record.hasField(fieldType.getName())) { value = record.getField(fieldType.getName()); } } return value; }
@Override public void collectIndexUpdate(final IndexUpdateBuilder indexUpdateBuilder) throws InterruptedException, IOException, RepositoryException { RecordContext ctx = indexUpdateBuilder.getRecordContext(); if (fieldType != null && !systemFields.isSystemField(fieldType.getName())) { indexUpdateBuilder.addDependency(fieldType.getId()); if (ctx.record != null && !ctx.record.hasField(fieldType.getName())) { return; } } follow.follow(indexUpdateBuilder, new FollowCallback() { @Override public void call() throws RepositoryException, InterruptedException, IOException { ForEachNode.super.collectIndexUpdate(indexUpdateBuilder); } }); }
public FieldType parseFieldType(JsonNode node) throws RepositoryException, ImportException, JsonFormatException, InterruptedException { if (!node.isObject()) { throw new ImportException("Field type should be specified as object node."); } FieldType fieldType = FieldTypeReader.INSTANCE.fromJson(node, namespaces, repository); if (fieldType.getName() == null) { throw new ImportException("Missing name property on field type."); } return fieldType; }
/** * Lookup name of field type, for use in debug logs. Beware, this might be slow. */ private String safeLoadTagName(SchemaId fieldTypeId) { if (fieldTypeId == null) { return "null"; } try { return repositoryManager.getDefaultRepository().getTypeManager().getFieldTypeById(fieldTypeId).getName().getName(); } catch (Throwable t) { return "failed to load name"; } }
@Override public BlobAccess getBlobAccess(Record record, QName fieldName, FieldType fieldType, int...indexes) throws BlobException { if (!(fieldType.getValueType().getDeepestValueType() instanceof BlobValueType)) { throw new BlobException("Cannot read a blob from a non-blob field type: " + fieldType.getName()); } Blob blob = getBlobFromRecord(record, fieldName, fieldType, indexes); return registry.getBlobAccess(blob); }
private void checkImmutableFieldsCorrespond(FieldType userFieldType, FieldType latestFieldType) throws FieldTypeUpdateException { if (!userFieldType.getValueType().equals(latestFieldType.getValueType())) { throw new FieldTypeUpdateException("Changing the valueType of a fieldType '" + latestFieldType.getId() + "' (current name: " + latestFieldType.getName() + ") is not allowed; old '" + latestFieldType.getValueType() + "' new '" + userFieldType.getValueType() + "'"); } if (!userFieldType.getScope().equals(latestFieldType.getScope())) { throw new FieldTypeUpdateException("Changing the scope of a fieldType '" + latestFieldType.getId() + "' (current name: " + latestFieldType.getName() + ") is not allowed; old '" + latestFieldType.getScope() + "' new '" + userFieldType.getScope() + "'"); } }
public static ObjectNode toJson(FieldType fieldType, Namespaces namespaces, boolean includeName) { ObjectNode fieldNode = JsonNodeFactory.instance.objectNode(); fieldNode.put("id", fieldType.getId().toString()); if (includeName) { fieldNode.put("name", QNameConverter.toJson(fieldType.getName(), namespaces)); } fieldNode.put("scope", fieldType.getScope().toString().toLowerCase()); fieldNode.put("valueType", ValueTypeNSConverter.toJson(fieldType.getValueType().getName(), namespaces)); return fieldNode; } }
private static void printFieldType(Pair<FieldTypeEntry, FieldType> pair, PrintStream out, int indent) { FieldTypeEntry fieldTypeEntry = pair.getV1(); FieldType fieldType = pair.getV2(); println(out, indent, "Name = " + fieldType.getName()); println(out, indent, "ID = " + fieldType.getId()); println(out, indent, "Mandatory = " + fieldTypeEntry.isMandatory()); try { println(out, indent, "ValueType = " + fieldType.getValueType().getName()); } catch (Throwable t) { // value type failed to load } }
public SolrInputDocument build() throws InterruptedException, RepositoryException { solrDoc.setField("lily.id", recordId.toString()); solrDoc.setField("lily.table", table); solrDoc.setField("lily.key", key); solrDoc.setField("lily.vtagId", vtag.toString()); solrDoc.setField("lily.vtag", typeManager.getFieldTypeById(vtag).getName().getName()); solrDoc.setField("lily.version", version); return solrDoc; }
@Override public void follow(IndexUpdateBuilder indexUpdateBuilder, FollowCallback followCallback) throws RepositoryException, IOException, InterruptedException { if (!indexUpdateBuilder.getSystemFields().isSystemField(fieldType.getName())) { indexUpdateBuilder.addDependency(fieldType.getId()); } RecordContext ctx = indexUpdateBuilder.getRecordContext(); if (ctx.record != null) { List records = IndexerUtils.flatList(ctx.record, fieldType); for (Record record: (List<Record>)records) { indexUpdateBuilder.push(record, ctx.contextRecord, ctx.dep); // TODO: pass null instead of ctx.dep? followCallback.call(); indexUpdateBuilder.pop(); } } } }
public AvroFieldType convert(FieldType fieldType) { AvroFieldType avroFieldType = new AvroFieldType(); avroFieldType.setId(convert(fieldType.getId())); avroFieldType.setName(convert(fieldType.getName())); avroFieldType.setValueType(convert(fieldType.getValueType())); avroFieldType.setScope(convert(fieldType.getScope())); return avroFieldType; }