Skip to content

Commit

Permalink
Merge pull request #197 from telefonicaid/task/notify_timed_rule_to_p…
Browse files Browse the repository at this point in the history
…erseo_fe_with_simple_name

Task/notify timed rule to perseo fe with simple name
  • Loading branch information
fgalan authored Mar 11, 2022
2 parents 4735e04 + 66d2ccc commit 13743ee
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@
import com.espertech.esper.runtime.client.EPStatement;
import com.espertech.esper.runtime.client.EPRuntime;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
*
Expand Down Expand Up @@ -59,22 +64,32 @@ public void update(EventBean[] newEvents, EventBean[] oldEvents, EPStatement sta

// Get Rule Information from TimeRulesStore
String ruleName = (String) eventMap.get("ruleName");

// TBD: include service and subservice
JSONObject rule = TimeRulesStore.getInstance().getRuleInfo(ruleName);
LOGGER.debug(String.format("Rule name: %s event %s jo %s",
ruleName, event, jo));

// Alt. if event.getEventType().getName().endsWith("_wrapoutwild_") -> Timed rule?
if (rule != null) {

// Is a timed Rule. Set special headers using rule saved information
Utils.setTimerRuleHeaders(rule);
// Timed rule is stored in TImesRuleStored with normalized/unique name)
// But simple rule name should be used in order to post perseo-fe
List<String> name = new ArrayList(Arrays.asList(ruleName.split("@")));
jo.put("ruleName", name.get(0));
LOGGER.info(String.format("Firing temporal rule: %s with name %s from event: %s",
rule.toString(), ruleName, event));

} else {
LOGGER.info(String.format("Firing Rule with name: %s from Event: %s",
ruleName, event));
LOGGER.info(String.format("Firing Rule with name: %s from Event: %s Jo: %s",
ruleName, event, jo));
}
JSONObject errors = jo.optJSONObject("errors");
if (errors != null) {
LOGGER.info(String.format("result errors: %s", errors));
}

LOGGER.debug(String.format("result errors: %s",jo.optJSONObject("errors")));
LOGGER.debug(String.format("result json: %s", jo));

boolean ok = Utils.DoHTTPPost(Configuration.getActionURL(), jo.toString());
Expand Down

0 comments on commit 13743ee

Please sign in to comment.