Search in sources :

Example 1 with SDAnnotationType

use of com.yahoo.searchdefinition.document.annotation.SDAnnotationType 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;
}
Also used : SDAnnotationType(com.yahoo.searchdefinition.document.annotation.SDAnnotationType) HashMap(java.util.HashMap) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) SDAnnotationType(com.yahoo.searchdefinition.document.annotation.SDAnnotationType) AnnotationType(com.yahoo.document.annotation.AnnotationType) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) StructDataType(com.yahoo.document.StructDataType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with SDAnnotationType

use of com.yahoo.searchdefinition.document.annotation.SDAnnotationType in project vespa by vespa-engine.

the class DocumentModelBuilder method anyParentsHavePayLoad.

private static boolean anyParentsHavePayLoad(SDAnnotationType sa, SDDocumentType sdoc) {
    if (sa.getInherits() != null) {
        AnnotationType tmp = sdoc.findAnnotation(sa.getInherits());
        SDAnnotationType inherited = (SDAnnotationType) tmp;
        return ((inherited.getSdDocType() != null) || anyParentsHavePayLoad(inherited, sdoc));
    }
    return false;
}
Also used : SDAnnotationType(com.yahoo.searchdefinition.document.annotation.SDAnnotationType) SDAnnotationType(com.yahoo.searchdefinition.document.annotation.SDAnnotationType) AnnotationType(com.yahoo.document.annotation.AnnotationType)

Aggregations

AnnotationType (com.yahoo.document.annotation.AnnotationType)2 SDAnnotationType (com.yahoo.searchdefinition.document.annotation.SDAnnotationType)2 StructDataType (com.yahoo.document.StructDataType)1 NewDocumentType (com.yahoo.documentmodel.NewDocumentType)1 SDDocumentType (com.yahoo.searchdefinition.document.SDDocumentType)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1