use of com.yahoo.document.annotation.AnnotationType in project vespa by vespa-engine.
the class DocumentModelBuilder method convert.
private NewDocumentType convert(SDDocumentType sdoc) {
Map<AnnotationType, String> annotationInheritance = new HashMap<>();
Map<StructDataType, String> structInheritance = new HashMap<>();
NewDocumentType dt = new NewDocumentType(new NewDocumentType.Name(sdoc.getName()), sdoc.getDocumentType().getHeaderType(), sdoc.getDocumentType().getBodyType(), sdoc.getFieldSets(), convertDocumentReferencesToNames(sdoc.getDocumentReferences()));
for (SDDocumentType n : sdoc.getInheritedTypes()) {
NewDocumentType.Name name = new NewDocumentType.Name(n.getName());
NewDocumentType inherited = model.getDocumentManager().getDocumentType(name);
if (inherited != null) {
dt.inherit(inherited);
}
}
for (SDDocumentType type : sdoc.getTypes()) {
if (type.isStruct()) {
handleStruct(dt, type);
} else {
throw new IllegalArgumentException("Data type '" + sdoc.getName() + "' is not a struct => tostring='" + sdoc.toString() + "'.");
}
}
for (AnnotationType annotation : sdoc.getAnnotations()) {
dt.add(annotation);
}
for (AnnotationType annotation : sdoc.getAnnotations()) {
SDAnnotationType sa = (SDAnnotationType) annotation;
if (annotation.getInheritedTypes().isEmpty() && (sa.getInherits() != null)) {
annotationInheritance.put(annotation, sa.getInherits());
}
if (annotation.getDataType() == null) {
if (sa.getSdDocType() != null) {
StructDataType s = handleStruct(dt, sa.getSdDocType());
annotation.setDataType(s);
if ((sa.getInherits() != null)) {
structInheritance.put(s, "annotation." + sa.getInherits());
}
} else if (sa.getInherits() != null) {
StructDataType s = new StructDataType("annotation." + annotation.getName());
if (anyParentsHavePayLoad(sa, sdoc)) {
annotation.setDataType(s);
addType(dt, s);
}
structInheritance.put(s, "annotation." + sa.getInherits());
}
}
}
for (Map.Entry<AnnotationType, String> e : annotationInheritance.entrySet()) {
e.getKey().inherit(dt.getAnnotationType(e.getValue()));
}
for (Map.Entry<StructDataType, String> e : structInheritance.entrySet()) {
StructDataType s = (StructDataType) dt.getDataType(e.getValue());
if (s != null) {
e.getKey().inherit(s);
}
}
handleStruct(dt, sdoc.getDocumentType().getHeaderType());
handleStruct(dt, sdoc.getDocumentType().getBodyType());
extractDataTypesFromFields(dt, sdoc.fieldSet());
return dt;
}
use of com.yahoo.document.annotation.AnnotationType in project vespa by vespa-engine.
the class DocumentTypes method buildConfig.
private void buildConfig(NewDocumentType documentType, DocumenttypesConfig.Builder builder) {
if (documentType == VespaDocumentType.INSTANCE) {
return;
}
DocumenttypesConfig.Documenttype.Builder db = new DocumenttypesConfig.Documenttype.Builder();
db.id(documentType.getId()).name(documentType.getName()).headerstruct(documentType.getHeader().getId()).bodystruct(documentType.getBody().getId());
Set<Integer> built = new HashSet<>();
for (NewDocumentType inherited : documentType.getInherited()) {
db.inherits(new DocumenttypesConfig.Documenttype.Inherits.Builder().id(inherited.getId()));
markAsBuilt(built, inherited.getAllTypes());
}
for (DataType dt : documentType.getTypes()) {
buildConfig(dt, db, built);
}
for (AnnotationType annotation : documentType.getAnnotations()) {
DocumenttypesConfig.Documenttype.Annotationtype.Builder atb = new DocumenttypesConfig.Documenttype.Annotationtype.Builder();
db.annotationtype(atb);
buildConfig(annotation, atb);
}
buildConfig(documentType.getFieldSets(), db);
builder.documenttype(db);
}
use of com.yahoo.document.annotation.AnnotationType in project vespa by vespa-engine.
the class SchemaMappingAndAccessesTest method getDoc.
private Document getDoc() {
DocumentType type = new DocumentType("album");
AnnotationType personType = new AnnotationType("person");
Annotation person = new Annotation(personType);
type.addField("title", DataType.STRING);
type.addField("artist", DataType.STRING);
type.addField("guitarist", DataType.STRING);
type.addField("year", DataType.INT);
type.addField("labels", DataType.getArray(DataType.STRING));
Document doc = new Document(type, new DocumentId("doc:map:test:1"));
doc.setFieldValue("title", new StringFieldValue("Black Rock"));
StringFieldValue joe = new StringFieldValue("Joe Bonamassa");
joe.setSpanTree(new SpanTree("mytree").annotate(person));
doc.setFieldValue("artist", joe);
doc.setFieldValue("year", new IntegerFieldValue(2010));
Array<StringFieldValue> labels = new Array<>(type.getField("labels").getDataType());
labels.add(new StringFieldValue("audun"));
labels.add(new StringFieldValue("tylden"));
doc.setFieldValue("labels", labels);
StructDataType personStructType = new StructDataType("artist");
personStructType.addField(new com.yahoo.document.Field("firstname", DataType.STRING));
personStructType.addField(new com.yahoo.document.Field("lastname", DataType.STRING));
type.addField("listeners", DataType.getArray(personStructType));
Array<Struct> listeners = new Array<>(type.getField("listeners").getDataType());
Struct listenerOne = new Struct(personStructType);
listenerOne.setFieldValue("firstname", new StringFieldValue("per"));
listenerOne.setFieldValue("lastname", new StringFieldValue("olsen"));
Struct listenerTwo = new Struct(personStructType);
listenerTwo.setFieldValue("firstname", new StringFieldValue("anders"));
listenerTwo.setFieldValue("lastname", new StringFieldValue("and"));
listeners.add(listenerOne);
listeners.add(listenerTwo);
doc.setFieldValue("listeners", listeners);
return doc;
}
use of com.yahoo.document.annotation.AnnotationType in project vespa by vespa-engine.
the class DocumentTypeManagerConfigurer method setupAnnotationRefTypes.
private static void setupAnnotationRefTypes(DocumentmanagerConfig config, DocumentTypeManager manager) {
for (int i = 0; i < config.datatype().size(); i++) {
DocumentmanagerConfig.Datatype thisDataType = config.datatype(i);
int id = thisDataType.id();
for (Object o : thisDataType.annotationreftype()) {
DocumentmanagerConfig.Datatype.Annotationreftype annRefType = (DocumentmanagerConfig.Datatype.Annotationreftype) o;
AnnotationType annotationType = manager.getAnnotationTypeRegistry().getType(annRefType.annotation());
if (annotationType == null) {
throw new IllegalArgumentException("Found reference to " + annRefType.annotation() + ", which does not exist!");
}
AnnotationReferenceDataType type = new AnnotationReferenceDataType(annotationType, id);
manager.register(type);
}
}
}
use of com.yahoo.document.annotation.AnnotationType in project vespa by vespa-engine.
the class DocumentTypeManagerConfigurer method setupAnnotationTypesWithoutPayloads.
private static void setupAnnotationTypesWithoutPayloads(DocumentmanagerConfig config, DocumentTypeManager manager) {
for (DocumentmanagerConfig.Annotationtype annType : config.annotationtype()) {
AnnotationType annotationType = new AnnotationType(annType.name(), annType.id());
manager.getAnnotationTypeRegistry().register(annotationType);
}
}
Aggregations