lkuchars commented on code in PR #10105:
URL: https://github.com/apache/nifi/pull/10105#discussion_r2254208989
##########
nifi-extension-bundles/nifi-confluent-platform-bundle/nifi-confluent-schema-registry-service/src/main/java/org/apache/nifi/confluent/schemaregistry/client/RestSchemaRegistryClient.java:
##########
@@ -211,6 +221,91 @@ public RecordSchema getSchema(final int schemaId) throws
IOException, SchemaNotF
return createRecordSchema(completeSchema);
}
+ @Override
+ public SchemaDefinition getSchemaDefinition(SchemaIdentifier identifier)
throws SchemaNotFoundException {
+ JsonNode schemaJson;
+ String subject = null;
+ Integer version = null;
+
+ // If we have an ID, get the schema by ID first
+ // Using schemaVersionId, because that is what is set by
ConfluentEncodedSchemaReferenceReader.
+ // probably identifier field should be used, but I'm not changing
ConfluentEncodedSchemaReferenceReader for backward compatibility reasons.
+ if (identifier.getSchemaVersionId().isPresent()) {
+ long schemaId = identifier.getSchemaVersionId().getAsLong();
+ String schemaPath = getSchemaPath(schemaId);
+ schemaJson = fetchJsonResponse(schemaPath, "id " + schemaId);
+ } else if (identifier.getName().isPresent()) {
+ // If we have a name or (name and version), get the schema by those
+ subject = identifier.getName().get();
+ version = identifier.getVersion().isPresent() ?
identifier.getVersion().getAsInt() : null;
+ // if no version was specified, the latest version will be used.
See @getSubjectPath method.
+ String pathSuffix = getSubjectPath(subject, version);
+ schemaJson = fetchJsonResponse(pathSuffix, "name " + subject);
+ } else {
+ throw new SchemaNotFoundException("Schema identifier must contain
either a version identifier or a subject name");
+ }
+
+ // Extract schema information
+ String schemaText = schemaJson.get(SCHEMA_TEXT_FIELD_NAME).asText();
+ String schemaTypeText =
schemaJson.get(SCHEMA_TYPE_FIELD_NAME).asText();
+ SchemaType schemaType = toSchemaType(schemaTypeText);
+
+ long schemaId;
+ if (schemaJson.has(ID_FIELD_NAME)) {
+ schemaId = schemaJson.get(ID_FIELD_NAME).asLong();
+ } else {
+ schemaId = identifier.getSchemaVersionId().getAsLong();
+ }
+
+ if (subject == null && schemaJson.has(SUBJECT_FIELD_NAME)) {
+ subject = schemaJson.get(SUBJECT_FIELD_NAME).asText();
+ }
+
+ if (version == null && schemaJson.has(VERSION_FIELD_NAME)) {
+ version = schemaJson.get(VERSION_FIELD_NAME).asInt();
+ }
+
+ // Build schema identifier with all available information
+ SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder()
+ .id(schemaId)
+ .name(subject)
+ .version(version)
+ .build();
+
+ // Process references if present
+ Map<String, SchemaDefinition> references = new HashMap<>();
+ if (schemaJson.has(REFERENCES_FIELD_NAME) &&
!schemaJson.get(REFERENCES_FIELD_NAME).isNull()) {
+ ArrayNode refsArray = (ArrayNode)
schemaJson.get(REFERENCES_FIELD_NAME);
Review Comment:
If it exists and it's not null there is no way it can be of other type.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]