@Test public void testMake() { logger.info("make"); String ruleName = "ccc"; String epl = Help.ExampleRules()[0]; String text = String.format("{\"name\":\"%s\",\"text\":\"%s\"}", ruleName, epl); Result result = RulesManager.make(epService, text); assertEquals(200, result.getStatusCode()); EPStatement st = epService.getEPAdministrator().getStatement(ruleName); assertEquals(epl, st.getText()); assertEquals(ruleName, st.getName()); }
public static synchronized Result make(EPServiceProvider epService, String text) { try { logger.debug(String.format("rule text: %s", text)); org.json.JSONObject jo = new JSONObject(text); logger.debug(String.format("rule as JSONObject: %s", jo)); String name = jo.optString("name", ""); logger.info(String.format("post rule: %s",name)); if ("".equals(name.trim())) { return new Result(HttpServletResponse.SC_BAD_REQUEST, "{\"error\":\"missing name\"}"); } String newEpl = jo.optString("text", ""); if ("".equals(newEpl.trim())) { return new Result(HttpServletResponse.SC_BAD_REQUEST, "{\"error\":\"missing text\"}"); } logger.debug(String.format("statement name: %s",name)); logger.debug(String.format("statement text: %s",newEpl)); EPStatement statement; EPStatement prevStmnt = epService.getEPAdministrator().getStatement(name); if (prevStmnt == null) { logger.debug(String.format("found new statement: %s",name)); statement = epService.getEPAdministrator().createEPL(newEpl, name); logger.debug(String.format("statement json: %s", Utils.Statement2JSONObject(statement))); statement.addListener(new GenericListener()); } else { String oldEpl = prevStmnt.getText(); logger.debug(String.format("old epl: %s", oldEpl)); if (!newEpl.equals(oldEpl)) { logger.debug(String.format("found changed statement: %s",name)); prevStmnt.destroy(); logger.debug(String.format("deleted statement: %s",name)); statement = epService.getEPAdministrator().createEPL(newEpl, name); logger.debug(String.format("re-created statement: %s", name)); logger.debug(String.format("statement json: %s", Utils.Statement2JSONObject(statement))); statement.addListener(new GenericListener()); } else { logger.debug(String.format("found repeated statement: %s", name)); statement = prevStmnt; } } return new Result(HttpServletResponse.SC_OK, Utils.Statement2JSONObject(statement).toString()); } catch (EPException epe) { logger.error(String.format("creating statement %s", epe)); return new Result(HttpServletResponse.SC_BAD_REQUEST, String.format("{\"error\":%s}%n", JSONObject.valueToString(epe.getMessage()))); } catch (JSONException je) { logger.error(String.format("creating statement %s",je)); return new Result(HttpServletResponse.SC_BAD_REQUEST, String.format("{\"error\":%s}%n", JSONObject.valueToString(je.getMessage()))); } }
RulesManager { public static synchronized Result make(EPServiceProvider epService, String text) { try { logger.debug(String.format("rule text: %s", text)); org.json.JSONObject jo = new JSONObject(text); logger.debug(String.format("rule as JSONObject: %s", jo)); String name = jo.optString("name", ""); logger.info(String.format("post rule: %s",name)); if ("".equals(name.trim())) { return new Result(HttpServletResponse.SC_BAD_REQUEST, "{\"error\":\"missing name\"}"); } String newEpl = jo.optString("text", ""); if ("".equals(newEpl.trim())) { return new Result(HttpServletResponse.SC_BAD_REQUEST, "{\"error\":\"missing text\"}"); } logger.debug(String.format("statement name: %s",name)); logger.debug(String.format("statement text: %s",newEpl)); EPStatement statement; EPStatement prevStmnt = epService.getEPAdministrator().getStatement(name); if (prevStmnt == null) { logger.debug(String.format("found new statement: %s",name)); statement = epService.getEPAdministrator().createEPL(newEpl, name); logger.debug(String.format("statement json: %s", Utils.Statement2JSONObject(statement))); statement.addListener(new GenericListener()); } else { String oldEpl = prevStmnt.getText(); logger.debug(String.format("old epl: %s", oldEpl)); if (!newEpl.equals(oldEpl)) { logger.debug(String.format("found changed statement: %s",name)); prevStmnt.destroy(); logger.debug(String.format("deleted statement: %s",name)); statement = epService.getEPAdministrator().createEPL(newEpl, name); logger.debug(String.format("re-created statement: %s", name)); logger.debug(String.format("statement json: %s", Utils.Statement2JSONObject(statement))); statement.addListener(new GenericListener()); } else { logger.debug(String.format("found repeated statement: %s", name)); statement = prevStmnt; } } return new Result(HttpServletResponse.SC_OK, Utils.Statement2JSONObject(statement).toString()); } catch (EPException epe) { logger.error(String.format("creating statement %s", epe)); return new Result(HttpServletResponse.SC_BAD_REQUEST, String.format("{\"error\":%s}%n", JSONObject.valueToString(epe.getMessage()))); } catch (JSONException je) { logger.error(String.format("creating statement %s",je)); return new Result(HttpServletResponse.SC_BAD_REQUEST, String.format("{\"error\":%s}%n", JSONObject.valueToString(je.getMessage()))); } } }
RulesManager { public static synchronized Result make(EPServiceProvider epService, String text) { try { logger.debug(String.format("rule text: %s", text)); org.json.JSONObject jo = new JSONObject(text); logger.debug(String.format("rule as JSONObject: %s", jo)); String name = jo.optString("name", ""); logger.info(String.format("post rule: %s",name)); if ("".equals(name.trim())) { return new Result(HttpServletResponse.SC_BAD_REQUEST, "{\"error\":\"missing name\"}"); } String newEpl = jo.optString("text", ""); if ("".equals(newEpl.trim())) { return new Result(HttpServletResponse.SC_BAD_REQUEST, "{\"error\":\"missing text\"}"); } logger.debug(String.format("statement name: %s",name)); logger.debug(String.format("statement text: %s",newEpl)); EPStatement statement; EPStatement prevStmnt = epService.getEPAdministrator().getStatement(name); if (prevStmnt == null) { logger.debug(String.format("found new statement: %s",name)); statement = epService.getEPAdministrator().createEPL(newEpl, name); logger.debug(String.format("statement json: %s", Utils.Statement2JSONObject(statement))); statement.addListener(new GenericListener()); } else { String oldEpl = prevStmnt.getText(); logger.debug(String.format("old epl: %s", oldEpl)); if (!newEpl.equals(oldEpl)) { logger.debug(String.format("found changed statement: %s",name)); prevStmnt.destroy(); logger.debug(String.format("deleted statement: %s",name)); statement = epService.getEPAdministrator().createEPL(newEpl, name); logger.debug(String.format("re-created statement: %s", name)); logger.debug(String.format("statement json: %s", Utils.Statement2JSONObject(statement))); statement.addListener(new GenericListener()); } else { logger.debug(String.format("found repeated statement: %s", name)); statement = prevStmnt; } } return new Result(HttpServletResponse.SC_OK, Utils.Statement2JSONObject(statement).toString()); } catch (EPException epe) { logger.error(String.format("creating statement %s", epe)); return new Result(HttpServletResponse.SC_BAD_REQUEST, String.format("{\"error\":%s}%n", JSONObject.valueToString(epe.getMessage()))); } catch (JSONException je) { logger.error(String.format("creating statement %s",je)); return new Result(HttpServletResponse.SC_BAD_REQUEST, String.format("{\"error\":%s}%n", JSONObject.valueToString(je.getMessage()))); } }  }
RulesManager { public static synchronized Result make(EPServiceProvider epService, String text) { try { logger.debug(String.format("rule text: %s", text)); org.json.JSONObject jo = new JSONObject(text); logger.debug(String.format("rule as JSONObject: %s", jo)); String name = jo.optString("name", ""); logger.info(String.format("post rule: %s",name)); if ("".equals(name.trim())) { return new Result(HttpServletResponse.SC_BAD_REQUEST, "{\"error\":\"missing name\"}"); } String newEpl = jo.optString("text", ""); if ("".equals(newEpl.trim())) { return new Result(HttpServletResponse.SC_BAD_REQUEST, "{\"error\":\"missing text\"}"); } logger.debug(String.format("statement name: %s",name)); logger.debug(String.format("statement text: %s",newEpl)); EPStatement statement; EPStatement prevStmnt = epService.getEPAdministrator().getStatement(name); if (prevStmnt == null) { logger.debug(String.format("found new statement: %s",name)); statement = epService.getEPAdministrator().createEPL(newEpl, name); logger.debug(String.format("statement json: %s", Utils.Statement2JSONObject(statement))); statement.addListener(new GenericListener()); } else { String oldEpl = prevStmnt.getText(); logger.debug(String.format("old epl: %s", oldEpl)); if (!newEpl.equals(oldEpl)) { logger.debug(String.format("found changed statement: %s",name)); prevStmnt.destroy(); logger.debug(String.format("deleted statement: %s",name)); statement = epService.getEPAdministrator().createEPL(newEpl, name); logger.debug(String.format("re-created statement: %s", name)); logger.debug(String.format("statement json: %s", Utils.Statement2JSONObject(statement))); statement.addListener(new GenericListener()); } else { logger.debug(String.format("found repeated statement: %s", name)); statement = prevStmnt; } } return new Result(HttpServletResponse.SC_OK, Utils.Statement2JSONObject(statement).toString()); } catch (EPException epe) { logger.error(String.format("creating statement %s", epe)); return new Result(HttpServletResponse.SC_BAD_REQUEST, String.format("{\"error\":%s}%n", JSONObject.valueToString(epe.getMessage()))); } catch (JSONException je) { logger.error(String.format("creating statement %s",je)); return new Result(HttpServletResponse.SC_BAD_REQUEST, String.format("{\"error\":%s}%n", JSONObject.valueToString(je.getMessage()))); } }  static synchronized Result get(EPServiceProvider epService, String ruleName); static synchronized Result make(EPServiceProvider epService, String text); static synchronized Result updateAll(EPServiceProvider epService, String text); static synchronized Result delete(EPServiceProvider epService, String ruleName); }
RulesManager { public static synchronized Result make(EPServiceProvider epService, String text) { try { logger.debug(String.format("rule text: %s", text)); org.json.JSONObject jo = new JSONObject(text); logger.debug(String.format("rule as JSONObject: %s", jo)); String name = jo.optString("name", ""); logger.info(String.format("post rule: %s",name)); if ("".equals(name.trim())) { return new Result(HttpServletResponse.SC_BAD_REQUEST, "{\"error\":\"missing name\"}"); } String newEpl = jo.optString("text", ""); if ("".equals(newEpl.trim())) { return new Result(HttpServletResponse.SC_BAD_REQUEST, "{\"error\":\"missing text\"}"); } logger.debug(String.format("statement name: %s",name)); logger.debug(String.format("statement text: %s",newEpl)); EPStatement statement; EPStatement prevStmnt = epService.getEPAdministrator().getStatement(name); if (prevStmnt == null) { logger.debug(String.format("found new statement: %s",name)); statement = epService.getEPAdministrator().createEPL(newEpl, name); logger.debug(String.format("statement json: %s", Utils.Statement2JSONObject(statement))); statement.addListener(new GenericListener()); } else { String oldEpl = prevStmnt.getText(); logger.debug(String.format("old epl: %s", oldEpl)); if (!newEpl.equals(oldEpl)) { logger.debug(String.format("found changed statement: %s",name)); prevStmnt.destroy(); logger.debug(String.format("deleted statement: %s",name)); statement = epService.getEPAdministrator().createEPL(newEpl, name); logger.debug(String.format("re-created statement: %s", name)); logger.debug(String.format("statement json: %s", Utils.Statement2JSONObject(statement))); statement.addListener(new GenericListener()); } else { logger.debug(String.format("found repeated statement: %s", name)); statement = prevStmnt; } } return new Result(HttpServletResponse.SC_OK, Utils.Statement2JSONObject(statement).toString()); } catch (EPException epe) { logger.error(String.format("creating statement %s", epe)); return new Result(HttpServletResponse.SC_BAD_REQUEST, String.format("{\"error\":%s}%n", JSONObject.valueToString(epe.getMessage()))); } catch (JSONException je) { logger.error(String.format("creating statement %s",je)); return new Result(HttpServletResponse.SC_BAD_REQUEST, String.format("{\"error\":%s}%n", JSONObject.valueToString(je.getMessage()))); } }  static synchronized Result get(EPServiceProvider epService, String ruleName); static synchronized Result make(EPServiceProvider epService, String text); static synchronized Result updateAll(EPServiceProvider epService, String text); static synchronized Result delete(EPServiceProvider epService, String ruleName);  }