tpalfy commented on a change in pull request #4463:
URL: https://github.com/apache/nifi/pull/4463#discussion_r467916778



##########
File path: 
nifi-nar-bundles/nifi-cassandra-bundle/nifi-cassandra-processors/src/main/java/org/apache/nifi/processors/cassandra/QueryCassandra.java
##########
@@ -130,6 +132,23 @@
             .defaultValue(AVRO_FORMAT)
             .build();
 
+    public static final PropertyDescriptor DATE_FORMAT_PATTERN = new 
PropertyDescriptor.Builder()
+            .name("Date Format Pattern for JSON output")

Review comment:
       ```suggestion
               .name("date-format-pattern")
               .displayName("Date Format Pattern for JSON output")
   ```

##########
File path: 
nifi-nar-bundles/nifi-cassandra-bundle/nifi-cassandra-processors/src/main/java/org/apache/nifi/processors/cassandra/QueryCassandra.java
##########
@@ -467,19 +493,33 @@ public static long convertToJsonStream(final ResultSet 
rs, final OutputStream ou
     }
 
     protected static String getJsonElement(Object value) {
+        return getJsonElement(Optional.empty(), value);
+    }
+
+    protected static String getJsonElement(final Optional<ProcessContext> 
context, Object value) {
         if (value instanceof Number) {
             return value.toString();
         } else if (value instanceof Date) {
-            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd 
HH:mm:ssZ");
-            dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
-            return "\"" + dateFormat.format((Date) value) + "\"";
+            return "\"" + getFormattedDate(context, (Date) value) + "\"";
         } else if (value instanceof String) {
             return "\"" + StringEscapeUtils.escapeJson((String) value) + "\"";
         } else {
             return "\"" + value.toString() + "\"";
         }
     }
 
+    private static String getFormattedDate(final Optional<ProcessContext> 
context, Date value) {
+        final String dateFormatPattern;
+        if (context.isPresent()) {
+            dateFormatPattern = 
context.get().getProperty(DATE_FORMAT_PATTERN).getValue();
+        } else {
+            dateFormatPattern = DATE_FORMAT_PATTERN.getDefaultValue();
+        }

Review comment:
       ```suggestion
           final String dateFormatPattern = context
               .map(_context -> 
_context.getProperty(DATE_FORMAT_PATTERN).getValue())
               .orElse(DATE_FORMAT_PATTERN.getDefaultValue());
   ```




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to