@Test public void testUpdateTimerRule() { logger.info("update with timed rule"); TimeRulesStore tRInfoInstance = TimeRulesStore.getInstance(); tRInfoInstance.cleanAllRules(); JSONObject body = new JSONObject(); String ruleName = "testrule@test/timerscope"; String ruleText = "select \"testrule\" as ruleName, *, current_timestamp() as currentTS " + "from pattern [every timer:interval(30 sec)]"; body.put("name", ruleName); body.put("text", ruleText); tRInfoInstance.saveTimeRules(body.toString()); EventBean[] oldEvents = new EventBean[0]; GenericListener instance = new GenericListener(); HashMap<String, Object> m = new HashMap(); m.put("one", "1"); m.put("two", 2); m.put("ruleName", "testrule"); EventBean event = new EventBeanMock(m); EventBean[] newEvents = new EventBean[]{event}; instance.update(newEvents, oldEvents); tRInfoInstance.cleanAllRules(); }
@Override public void update(EventBean[] newEvents, EventBean[] oldEvents) { try { for (EventBean event : newEvents) { JSONObject jo = Utils.Event2JSONObject(event); Map<String, Object> eventMap = Utils.JSONObject2Map(jo); JSONObject rule = TimeRulesStore.getInstance().getRuleInfo((String) eventMap.get("ruleName")); if (rule != null) { Utils.setTimerRuleHeaders(rule); LOGGER.info(String.format("Firing temporal rule: %s",event)); } else { LOGGER.info(String.format("Firing Rule: %s",event)); } 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()); if (!ok) { LOGGER.error("action post failed"); } } } catch (PropertyAccessException pae) { LOGGER.error(String.format("doing action %s",pae)); } }
GenericListener implements UpdateListener { @Override public void update(EventBean[] newEvents, EventBean[] oldEvents) { try { for (EventBean event : newEvents) { JSONObject jo = Utils.Event2JSONObject(event); Map<String, Object> eventMap = Utils.JSONObject2Map(jo); JSONObject rule = TimeRulesStore.getInstance().getRuleInfo((String) eventMap.get("ruleName")); if (rule != null) { Utils.setTimerRuleHeaders(rule); LOGGER.info(String.format("Firing temporal rule: %s",event)); } else { LOGGER.info(String.format("Firing Rule: %s",event)); } 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()); if (!ok) { LOGGER.error("action post failed"); } } } catch (PropertyAccessException pae) { LOGGER.error(String.format("doing action %s",pae)); } } }
GenericListener implements UpdateListener { @Override public void update(EventBean[] newEvents, EventBean[] oldEvents) { try { for (EventBean event : newEvents) { JSONObject jo = Utils.Event2JSONObject(event); Map<String, Object> eventMap = Utils.JSONObject2Map(jo); JSONObject rule = TimeRulesStore.getInstance().getRuleInfo((String) eventMap.get("ruleName")); if (rule != null) { Utils.setTimerRuleHeaders(rule); LOGGER.info(String.format("Firing temporal rule: %s",event)); } else { LOGGER.info(String.format("Firing Rule: %s",event)); } 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()); if (!ok) { LOGGER.error("action post failed"); } } } catch (PropertyAccessException pae) { LOGGER.error(String.format("doing action %s",pae)); } }  }
GenericListener implements UpdateListener { @Override public void update(EventBean[] newEvents, EventBean[] oldEvents) { try { for (EventBean event : newEvents) { JSONObject jo = Utils.Event2JSONObject(event); Map<String, Object> eventMap = Utils.JSONObject2Map(jo); JSONObject rule = TimeRulesStore.getInstance().getRuleInfo((String) eventMap.get("ruleName")); if (rule != null) { Utils.setTimerRuleHeaders(rule); LOGGER.info(String.format("Firing temporal rule: %s",event)); } else { LOGGER.info(String.format("Firing Rule: %s",event)); } 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()); if (!ok) { LOGGER.error("action post failed"); } } } catch (PropertyAccessException pae) { LOGGER.error(String.format("doing action %s",pae)); } }  @Override void update(EventBean[] newEvents, EventBean[] oldEvents); }
GenericListener implements UpdateListener { @Override public void update(EventBean[] newEvents, EventBean[] oldEvents) { try { for (EventBean event : newEvents) { JSONObject jo = Utils.Event2JSONObject(event); Map<String, Object> eventMap = Utils.JSONObject2Map(jo); JSONObject rule = TimeRulesStore.getInstance().getRuleInfo((String) eventMap.get("ruleName")); if (rule != null) { Utils.setTimerRuleHeaders(rule); LOGGER.info(String.format("Firing temporal rule: %s",event)); } else { LOGGER.info(String.format("Firing Rule: %s",event)); } 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()); if (!ok) { LOGGER.error("action post failed"); } } } catch (PropertyAccessException pae) { LOGGER.error(String.format("doing action %s",pae)); } }  @Override void update(EventBean[] newEvents, EventBean[] oldEvents);  }