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;
}
Aggregations