dan-s1 commented on code in PR #9785:
URL: https://github.com/apache/nifi/pull/9785#discussion_r2007773805
##########
nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-processors/src/main/java/org/apache/nifi/processors/jolt/JoltTransformJSON.java:
##########
@@ -122,14 +143,34 @@ public void onTrigger(final ProcessContext context,
ProcessSession session) thro
final ComponentLog logger = getLogger();
final StopWatch stopWatch = new StopWatch(true);
-
final Object inputJson;
- try (final InputStream in = session.read(original)) {
- inputJson = jsonUtil.jsonToObject(in);
- } catch (final Exception e) {
- logger.error("JSON parsing failed for {}", original, e);
- session.transfer(original, REL_FAILURE);
- return;
+ final boolean sourceStrategyFlowFile = SourceStrategy.FLOW_FILE ==
context.getProperty(JSON_SOURCE).asAllowableValue(SourceStrategy.class);
+ String jsonSourceAttributeName = null;
+
+ if (sourceStrategyFlowFile) {
+ try (final InputStream in = session.read(original)) {
+ inputJson = jsonUtil.jsonToObject(in);
+ } catch (final Exception e) {
+ logger.error("JSON parsing failed on FlowFile content for {}",
original, e);
+ session.transfer(original, REL_FAILURE);
+ return;
+ }
+ } else {
+ jsonSourceAttributeName =
context.getProperty(JSON_SOURCE_ATTRIBUTE).getValue();
+ final String jsonSourceAttributeValue =
original.getAttribute(jsonSourceAttributeName);
+ if (StringUtils.isBlank(jsonSourceAttributeValue)) {
+ logger.error("FlowFile attribute [{}] value is blank",
jsonSourceAttributeName);
+ session.transfer(original, REL_FAILURE);
+ return;
+ } else {
+ try {
+ inputJson =
jsonUtil.jsonToObject(jsonSourceAttributeValue);
+ } catch (final Exception e) {
+ logger.error("JSON parsing failed on FlowFile attribute
for {}", original, e);
Review Comment:
It might be a good idea to include the name of the attribute like you did
above.
```suggestion
logger.error("JSON parsing failed on attribute '{}' of
FlowFile {}", jsonSourceAttributeName, original, e);
```
##########
nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-processors/src/main/java/org/apache/nifi/processors/jolt/JoltTransformJSON.java:
##########
@@ -152,13 +193,18 @@ public void onTrigger(final ProcessContext context,
ProcessSession session) thro
}
}
- FlowFile transformed = session.write(original, out ->
out.write(jsonString.getBytes(StandardCharsets.UTF_8)));
-
- final String transformType =
context.getProperty(JOLT_TRANSFORM).getValue();
- transformed = session.putAttribute(transformed,
CoreAttributes.MIME_TYPE.key(), "application/json");
- session.transfer(transformed, REL_SUCCESS);
- session.getProvenanceReporter().modifyContent(transformed, "Modified
With " + transformType, stopWatch.getElapsed(TimeUnit.MILLISECONDS));
- logger.info("Transform completed for {}", original);
+ if (sourceStrategyFlowFile) {
+ FlowFile transformed = session.write(original, out ->
out.write(jsonString.getBytes(StandardCharsets.UTF_8)));
+ final String transformType =
context.getProperty(JOLT_TRANSFORM).getValue();
+ transformed = session.putAttribute(transformed,
CoreAttributes.MIME_TYPE.key(), "application/json");
+ session.transfer(transformed, REL_SUCCESS);
+ session.getProvenanceReporter().modifyContent(transformed,
"Modified With " + transformType, stopWatch.getElapsed(TimeUnit.MILLISECONDS));
+ logger.info("Transform completed on FlowFile content for {}",
original);
+ } else {
+ session.putAttribute(original, jsonSourceAttributeName,
jsonString);
+ session.transfer(original, REL_SUCCESS);
+ logger.info("Transform completed on FlowFile attribute for {}",
original);
+ }
Review Comment:
Again, it may be beneficial to name the attribute which was transformed so
it is clear in the logs
```suggestion
logger.info("Transform completed on attribute {} of FlowFile
{}", sonSourceAttributeName, original);
}
```
--
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]