Search in sources :

Example 1 with KafkaConnectEnumFields

use of io.atlasmap.kafkaconnect.v2.KafkaConnectEnumFields in project atlasmap by atlasmap.

the class KafkaConnectInspector method populateFields.

private List<KafkaConnectField> populateFields(List<org.apache.kafka.connect.data.Field> kcFields, AtlasPath parentPath) {
    List<KafkaConnectField> answer = new ArrayList<>();
    for (org.apache.kafka.connect.data.Field connectField : kcFields) {
        KafkaConnectField field;
        AtlasPath path = parentPath.clone();
        CollectionType collectionType = CollectionType.NONE;
        Schema connectSchema = connectField.schema();
        if (Type.ARRAY == connectSchema.type()) {
            path.appendField(connectField.name() + AtlasPath.PATH_LIST_SUFFIX);
            collectionType = CollectionType.LIST;
            connectSchema = connectSchema.valueSchema();
        } else if (Type.MAP == connectSchema.type()) {
            path.appendField(connectField.name() + AtlasPath.PATH_MAP_SUFFIX);
            collectionType = CollectionType.MAP;
            connectSchema = connectSchema.valueSchema();
        } else {
            path.appendField(connectField.name());
        }
        if (connectSchema.parameters() != null) {
            KafkaConnectComplexType complex = AtlasKafkaConnectModelFactory.createKafkaConnectComplexType();
            complex.setKafkaConnectEnumFields(new KafkaConnectEnumFields());
            complex.setEnumeration(true);
            List<KafkaConnectEnumField> symbols = complex.getKafkaConnectEnumFields().getKafkaConnectEnumField();
            boolean first = true;
            for (Entry<String, String> entry : connectSchema.parameters().entrySet()) {
                // FIXME dirty hack - it seems the first entry is for some control, the others are the actual values
                if (first) {
                    first = false;
                    continue;
                }
                KafkaConnectEnumField f = new KafkaConnectEnumField();
                f.setName(entry.getValue());
                symbols.add(f);
            }
            field = complex;
        } else if (connectSchema.type().isPrimitive()) {
            field = AtlasKafkaConnectModelFactory.createKafkaConnectField();
            field.setFieldType(KafkaConnectUtil.getFieldType(connectSchema.type()));
        } else {
            KafkaConnectComplexType complex = AtlasKafkaConnectModelFactory.createKafkaConnectComplexType();
            List<KafkaConnectField> children = populateFields(connectSchema.fields(), path);
            if ("io.confluent.connect.avro.Union".equals(connectSchema.name())) {
                // We don't support union until it's built into Kafka Connect Schema
                complex.setStatus(FieldStatus.UNSUPPORTED);
            }
            complex.getKafkaConnectFields().getKafkaConnectField().addAll(children);
            field = complex;
        }
        field.setName(connectField.name());
        field.setPath(path.toString());
        field.setCollectionType(collectionType);
        answer.add(field);
    }
    return answer;
}
Also used : KafkaConnectComplexType(io.atlasmap.kafkaconnect.v2.KafkaConnectComplexType) KafkaConnectEnumFields(io.atlasmap.kafkaconnect.v2.KafkaConnectEnumFields) Schema(org.apache.kafka.connect.data.Schema) ArrayList(java.util.ArrayList) CollectionType(io.atlasmap.v2.CollectionType) AtlasPath(io.atlasmap.core.AtlasPath) KafkaConnectEnumField(io.atlasmap.kafkaconnect.v2.KafkaConnectEnumField) ArrayList(java.util.ArrayList) List(java.util.List) KafkaConnectField(io.atlasmap.kafkaconnect.v2.KafkaConnectField)

Aggregations

AtlasPath (io.atlasmap.core.AtlasPath)1 KafkaConnectComplexType (io.atlasmap.kafkaconnect.v2.KafkaConnectComplexType)1 KafkaConnectEnumField (io.atlasmap.kafkaconnect.v2.KafkaConnectEnumField)1 KafkaConnectEnumFields (io.atlasmap.kafkaconnect.v2.KafkaConnectEnumFields)1 KafkaConnectField (io.atlasmap.kafkaconnect.v2.KafkaConnectField)1 CollectionType (io.atlasmap.v2.CollectionType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Schema (org.apache.kafka.connect.data.Schema)1