Skip to content

Commit 5871d76

Browse files
committed
NiFi: qol improved parse_service_reponse proc.
1 parent 7ac8b01 commit 5871d76

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

nifi/user_python_extensions/parse_service_response.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Java:
2424
implements = ['org.apache.nifi.python.processor.FlowFileTransform']
2525

2626
class ProcessorDetails:
27-
version = '0.0.1'
27+
version = '0.0.2'
2828

2929
def __init__(self, jvm: JVMView):
3030
super().__init__(jvm)
@@ -115,6 +115,8 @@ def process(self, context: ProcessContext, flowFile: JavaObject) -> FlowFileTran
115115

116116
records: dict | list[dict] = json.loads(input_raw_bytes.decode("utf-8"))
117117

118+
additional_attributes: dict = {}
119+
118120
if isinstance(records, dict):
119121
records = [records]
120122

@@ -131,6 +133,9 @@ def process(self, context: ProcessContext, flowFile: JavaObject) -> FlowFileTran
131133
if "footer" in result:
132134
for k, v in result["footer"].items():
133135
_record[k] = v
136+
137+
if self.document_id_field_name in _record:
138+
additional_attributes[self.document_id_field_name] = _record[self.document_id_field_name]
134139

135140
output_contents.append(_record)
136141

@@ -178,12 +183,15 @@ def process(self, context: ProcessContext, flowFile: JavaObject) -> FlowFileTran
178183
str(footer[self.document_id_field_name]) + "_" + str(annotation_id)
179184
)
180185

186+
additional_attributes["annotation_id"] = _output_annotated_record["annotation_id"]
187+
181188
output_contents.append(_output_annotated_record)
182189

183190
# add properties to flowfile attributes
184191
attributes: dict = {k: str(v) for k, v in flowFile.getAttributes().items()}
185192
attributes["output_text_field_name"] = str(self.output_text_field_name)
186193
attributes["mime.type"] = "application/json"
194+
attributes.update(additional_attributes)
187195

188196
return FlowFileTransformResult(
189197
relationship=self.REL_SUCCESS.name,

0 commit comments

Comments
 (0)