Github user nickwallen commented on a diff in the pull request:
https://github.com/apache/metron/pull/736#discussion_r137825517
--- Diff:
metron-analytics/metron-profiler-client/src/main/java/org/apache/metron/profiler/client/stellar/ProfilerFunctions.java
---
@@ -131,50 +133,99 @@ public boolean isInitialized() {
@Override
public Object apply(List<Object> args, Context context) throws
ParseException {
- // user must provide the message as a string
- String arg0 = Util.getArg(0, String.class, args);
- if(arg0 == null) {
- throw new IllegalArgumentException(format("expected string, found
null"));
+ // the use can pass in one or more messages in a few different forms
+ Object arg0 = Util.getArg(0, Object.class, args);
+ List<JSONObject> messages = getMessages(arg0);
+
+ // user must provide the stand alone profiler
+ StandAloneProfiler profiler = Util.getArg(1,
StandAloneProfiler.class, args);
+ try {
+ for (JSONObject message : messages) {
+ profiler.apply(message);
+ }
+
+ } catch (ExecutionException e) {
+ throw new IllegalArgumentException(format("Failed to apply
message; error=%s", e.getMessage()), e);
+ }
+
+ return profiler;
+ }
+
+ /**
+ * Gets a message or messages from the function arguments.
+ *
+ * @param arg The function argument containing the message(s).
+ * @return A list of messages
+ */
+ private List<JSONObject> getMessages(Object arg) {
+ List<JSONObject> messages;
+
+ if (arg instanceof String) {
+ messages = getMessagesFromString((String) arg);
+
+ } else if (arg instanceof List) {
+ messages = getMessagesFromList((List<String>) arg);
+
+ } else if (arg instanceof JSONObject) {
+ messages = Collections.singletonList((JSONObject) arg);
+
+ } else {
+ throw new IllegalArgumentException(format("invalid message: found
'%s', expected String, List, or JSONObject",
+ ClassUtils.getShortClassName(arg, "null")));
}
- // there could be one or more messages
+ return messages;
+ }
+
+ /**
+ * Gets a message or messages from a List
+ *
+ * @param listOfStrings The function argument is a List of Strings.
+ * @return A list of messages.
+ */
+ private List<JSONObject> getMessagesFromList(List<String>
listOfStrings) {
--- End diff --
Done and done.
---