ncover21 commented on code in PR #9825: URL: https://github.com/apache/nifi/pull/9825#discussion_r2025275982
########## nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/main/java/org/apache/nifi/processors/box/ExtractStructuredBoxFileMetadata.java: ########## @@ -202,16 +267,47 @@ BoxAIExtractStructuredResponse getBoxAIExtractStructuredResponse(final String te ); } - private static @NotNull Map<String, String> getAttributes(final BoxAIExtractStructuredResponse result, - final String fileId) { - final String completionReason = result.getCompletionReason(); + /** + * Extracts metadata from a Box file using the specified fields. + * Visible for testing purposes. + * + * @param fieldsString A comma-separated list of field names to extract. + * @param fileId The ID of the Box file from which to extract metadata. + * @return The response containing the extracted metadata. + */ + BoxAIExtractStructuredResponse getBoxAIExtractStructuredResponseWithFields(final String fieldsString, + final String fileId) { + final List<BoxAIExtractField> fields = parseFields(fieldsString); + final BoxAIItem fileItem = new BoxAIItem(fileId, BoxAIItem.Type.FILE); - final Map<String, String> attributes = new HashMap<>(); - attributes.put("box.id", fileId); + return BoxAI.extractMetadataStructured( + boxAPIConnection, + Collections.singletonList(fileItem), + fields + ); + } - if (completionReason != null) { - attributes.put("box.ai.completion.reason", completionReason); + /** + * Parses a comma-separated string of field names into a list of BoxAIExtractField objects. + * + * @param fieldsString A comma-separated list of field names. + * @return A list of BoxAIExtractField objects. + */ + private List<BoxAIExtractField> parseFields(final String fieldsString) { + if (fieldsString == null || fieldsString.trim().isEmpty()) { + return Collections.emptyList(); } - return attributes; + + final List<BoxAIExtractField> fields = new ArrayList<>(); + final String[] fieldNames = fieldsString.split(","); + + for (final String fieldName : fieldNames) { + final String trimmedField = fieldName.trim(); + if (!trimmedField.isEmpty()) { + fields.add(new BoxAIExtractField(trimmedField)); Review Comment: Changed the processor to take in the flowFIle content when field type is selected and assume the schema of the API 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: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org