@Test public void testGet() { logger.info("get"); String ruleName = "ccc"; String epl = Help.ExampleRules()[0]; EPStatement st = epService.getEPAdministrator().createEPL(epl, ruleName); Result result = RulesManager.get(epService, ruleName); assertEquals(200, result.getStatusCode()); result = RulesManager.get(epService, "it does not exist, we hope"); assertEquals(404, result.getStatusCode()); EPStatement st2 = epService.getEPAdministrator().getStatement(ruleName); assertEquals(st, st2); }
public static synchronized Result get(EPServiceProvider epService, String ruleName) { try { logger.debug(String.format("rule asked for: %s", ruleName)); ruleName = ruleName == null ? "" : ruleName; EPAdministrator epa = epService.getEPAdministrator(); if (ruleName.length() != 0) { EPStatement st = epa.getStatement(ruleName); if (st == null) { return new Result(HttpServletResponse.SC_NOT_FOUND, String.format("{\"error\":\"%s not found\"}%n", ruleName)); } else { return new Result(HttpServletResponse.SC_OK, Utils.Statement2JSONObject(st).toString()); } } else { String[] sttmntNames = epa.getStatementNames(); JSONArray ja = new JSONArray(); for (String name : sttmntNames) { logger.debug(String.format("getting rule %s", name)); EPStatement st = epa.getStatement(name); ja.put(Utils.Statement2JSONObject(st)); } return new Result(HttpServletResponse.SC_OK, ja.toString()); } } catch (EPException epe) { logger.error(String.format("getting statement %s", epe)); return new Result(HttpServletResponse.SC_BAD_REQUEST, String.format("{\"error\":%s}%n", JSONObject.valueToString(epe.getMessage()))); } }
RulesManager { public static synchronized Result get(EPServiceProvider epService, String ruleName) { try { logger.debug(String.format("rule asked for: %s", ruleName)); ruleName = ruleName == null ? "" : ruleName; EPAdministrator epa = epService.getEPAdministrator(); if (ruleName.length() != 0) { EPStatement st = epa.getStatement(ruleName); if (st == null) { return new Result(HttpServletResponse.SC_NOT_FOUND, String.format("{\"error\":\"%s not found\"}%n", ruleName)); } else { return new Result(HttpServletResponse.SC_OK, Utils.Statement2JSONObject(st).toString()); } } else { String[] sttmntNames = epa.getStatementNames(); JSONArray ja = new JSONArray(); for (String name : sttmntNames) { logger.debug(String.format("getting rule %s", name)); EPStatement st = epa.getStatement(name); ja.put(Utils.Statement2JSONObject(st)); } return new Result(HttpServletResponse.SC_OK, ja.toString()); } } catch (EPException epe) { logger.error(String.format("getting statement %s", epe)); return new Result(HttpServletResponse.SC_BAD_REQUEST, String.format("{\"error\":%s}%n", JSONObject.valueToString(epe.getMessage()))); } } }
RulesManager { public static synchronized Result get(EPServiceProvider epService, String ruleName) { try { logger.debug(String.format("rule asked for: %s", ruleName)); ruleName = ruleName == null ? "" : ruleName; EPAdministrator epa = epService.getEPAdministrator(); if (ruleName.length() != 0) { EPStatement st = epa.getStatement(ruleName); if (st == null) { return new Result(HttpServletResponse.SC_NOT_FOUND, String.format("{\"error\":\"%s not found\"}%n", ruleName)); } else { return new Result(HttpServletResponse.SC_OK, Utils.Statement2JSONObject(st).toString()); } } else { String[] sttmntNames = epa.getStatementNames(); JSONArray ja = new JSONArray(); for (String name : sttmntNames) { logger.debug(String.format("getting rule %s", name)); EPStatement st = epa.getStatement(name); ja.put(Utils.Statement2JSONObject(st)); } return new Result(HttpServletResponse.SC_OK, ja.toString()); } } catch (EPException epe) { logger.error(String.format("getting statement %s", epe)); return new Result(HttpServletResponse.SC_BAD_REQUEST, String.format("{\"error\":%s}%n", JSONObject.valueToString(epe.getMessage()))); } }  }
RulesManager { public static synchronized Result get(EPServiceProvider epService, String ruleName) { try { logger.debug(String.format("rule asked for: %s", ruleName)); ruleName = ruleName == null ? "" : ruleName; EPAdministrator epa = epService.getEPAdministrator(); if (ruleName.length() != 0) { EPStatement st = epa.getStatement(ruleName); if (st == null) { return new Result(HttpServletResponse.SC_NOT_FOUND, String.format("{\"error\":\"%s not found\"}%n", ruleName)); } else { return new Result(HttpServletResponse.SC_OK, Utils.Statement2JSONObject(st).toString()); } } else { String[] sttmntNames = epa.getStatementNames(); JSONArray ja = new JSONArray(); for (String name : sttmntNames) { logger.debug(String.format("getting rule %s", name)); EPStatement st = epa.getStatement(name); ja.put(Utils.Statement2JSONObject(st)); } return new Result(HttpServletResponse.SC_OK, ja.toString()); } } catch (EPException epe) { logger.error(String.format("getting statement %s", epe)); return new Result(HttpServletResponse.SC_BAD_REQUEST, String.format("{\"error\":%s}%n", JSONObject.valueToString(epe.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 get(EPServiceProvider epService, String ruleName) { try { logger.debug(String.format("rule asked for: %s", ruleName)); ruleName = ruleName == null ? "" : ruleName; EPAdministrator epa = epService.getEPAdministrator(); if (ruleName.length() != 0) { EPStatement st = epa.getStatement(ruleName); if (st == null) { return new Result(HttpServletResponse.SC_NOT_FOUND, String.format("{\"error\":\"%s not found\"}%n", ruleName)); } else { return new Result(HttpServletResponse.SC_OK, Utils.Statement2JSONObject(st).toString()); } } else { String[] sttmntNames = epa.getStatementNames(); JSONArray ja = new JSONArray(); for (String name : sttmntNames) { logger.debug(String.format("getting rule %s", name)); EPStatement st = epa.getStatement(name); ja.put(Utils.Statement2JSONObject(st)); } return new Result(HttpServletResponse.SC_OK, ja.toString()); } } catch (EPException epe) { logger.error(String.format("getting statement %s", epe)); return new Result(HttpServletResponse.SC_BAD_REQUEST, String.format("{\"error\":%s}%n", JSONObject.valueToString(epe.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);  }