ncover21 commented on code in PR #9825:
URL: https://github.com/apache/nifi/pull/9825#discussion_r2025269047
##########
nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/main/java/org/apache/nifi/processors/box/CreateBoxMetadataTemplate.java:
##########
@@ -270,77 +224,65 @@ public void onTrigger(final ProcessContext context, final
ProcessSession session
}
private void processRecord(final Record record,
- final RecordPath keyRecordPath,
- final RecordPath typeRecordPath,
- final RecordPath displayNameRecordPath,
final List<MetadataTemplate.Field> fields,
final Set<String> processedKeys,
final List<String> errors) {
- final RecordPathResult keyPathResult = keyRecordPath.evaluate(record);
- final List<FieldValue> keyValues =
keyPathResult.getSelectedFields().toList();
-
- if (keyValues.isEmpty()) {
- errors.add("Record is missing a key field");
- return;
- }
-
- final Object keyObj = keyValues.getFirst().getValue();
+ // Extract and validate key (required)
+ final Object keyObj = record.getValue("key");
if (keyObj == null) {
- errors.add("Record has a null key value");
+ errors.add("Record is missing a key field");
return;
}
-
final String key = keyObj.toString();
- // Skip if we've already processed this key
if (processedKeys.contains(key)) {
- getLogger().warn("Duplicate key '{}' found in record, skipping",
key);
+ errors.add("Duplicate key '" + key + "' found in record,
skipping");
return;
}
- final RecordPathResult typePathResult =
typeRecordPath.evaluate(record);
- final List<FieldValue> typeValues =
typePathResult.getSelectedFields().toList();
-
- if (typeValues.isEmpty()) {
+ // Extract and validate type (required)
+ final Object typeObj = record.getValue("type");
+ if (typeObj == null) {
errors.add("Record with key '" + key + "' is missing a type
field");
return;
}
+ final String normalizedType = typeObj.toString().toLowerCase();
- final Object typeObj = typeValues.getFirst().getValue();
- if (typeObj == null) {
- errors.add("Record with key '" + key + "' has a null type value");
+ if (!VALID_FIELD_TYPES.contains(normalizedType)) {
+ errors.add("Record with key '" + key + "' has an invalid type: '"
+ normalizedType +
+ "'. Valid types are: " + String.join(", ",
VALID_FIELD_TYPES));
return;
}
- final String type = typeObj.toString().toLowerCase();
+ final MetadataTemplate.Field metadataField = new
MetadataTemplate.Field();
+ metadataField.setKey(key);
+ metadataField.setType(normalizedType);
+
+ final Object displayNameObj = record.getValue("displayName");
+ if (displayNameObj != null) {
+ metadataField.setDisplayName(displayNameObj.toString());
+ }
- // Validate field type
- if (!VALID_FIELD_TYPES.contains(type)) {
- errors.add("Record with key '" + key + "' has an invalid type: '"
+ type + "'. Valid types are: " +
- String.join(", ", VALID_FIELD_TYPES));
- return;
+ final Object hiddenObj = record.getValue("hidden");
+ if (hiddenObj != null) {
+
metadataField.setIsHidden(Boolean.parseBoolean(hiddenObj.toString()));
}
- // Get the display name from the record (falls back to key if missing)
- String displayName = key;
- if (displayNameRecordPath != null) {
- final RecordPathResult displayNamePathResult =
displayNameRecordPath.evaluate(record);
- final List<FieldValue> displayNameValues =
displayNamePathResult.getSelectedFields().toList();
+ final Object descriptionObj = record.getValue("description");
+ if (descriptionObj != null) {
+ metadataField.setDescription(descriptionObj.toString());
+ }
- if (!displayNameValues.isEmpty()) {
- final Object displayNameObj =
displayNameValues.getFirst().getValue();
- if (displayNameObj != null) {
- displayName = displayNameObj.toString();
- }
+ if ("enum".equals(normalizedType) ||
"multiSelect".equals(normalizedType)) {
+ final Object optionsObj = record.getValue("options");
+ if (optionsObj instanceof List<?> optionsList) {
+ final List<String> options = optionsList.stream()
+ .map(obj -> obj != null ? obj.toString() : "")
Review Comment:
Throws exception now
--
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]