RulesManager { public List<Rule> getRuleObjects(EntityManager em, String tenantId) throws Exception { List<Rule> rules = new ArrayList<>(); try { List<Rules> results = getRules(em, tenantId); for (Rules rule : results) { if (rule.getRuleContent() != null) { rules.add(RuleSerializer.deserializeJSONStringToRule(rule.getRuleContent())); } else { rules.add(new SimpleRule(rule.getRuleId(), "", false, null, new Action[] {})); } } return rules; } catch (Exception e) { logger.log(Level.SEVERE, "Failed to load rule objects for tenant:" + tenantId, e); throw e; } } private  RulesManager(); static RulesManager getInstance(); short createNewRule(EntityManager em, Rules dbRule, Tenant tenant); Rule saveRule(EntityManager em, Rules dbRule, Tenant tenant, Rule currRule, ApplicationManager am); void sendRuleToKafka(boolean delete, String tenantId, Rule rule, ApplicationManager am); void sendRuleToKafka(boolean delete, String tenantId, String ruleJson, ApplicationManager am); Rules getRule(EntityManager em, String tenantId, short ruleId); List<Short> getRuleByTemplateId(EntityManager em, String tenantId, short templateId); void deleteRule(EntityManager em, String tenantId, short ruleId, ApplicationManager am); void deleteRules(EntityManager em, Tenant tenant, ApplicationManager am); void disableAllRules(EntityManager em, String tenantId, ApplicationManager am); List<Rule> getRuleObjects(EntityManager em, String tenantId); List<Rules> getRules(EntityManager em, String tenantId); String getRuleContents(EntityManager em, String tenantId, boolean pretty, int filter); Rules enableDisableRule(EntityManager em, boolean ruleState, String tenantId, short ruleId,
			ApplicationManager am); Tenant getTenant(EntityManager em, String tenantId);  }
@Test public void testGetRuleObjects() throws Exception { Rules rule = new Rules(); Tenant tenant = RulesManager.getInstance().getTenant(em, TENANT_ID_2); short ruleId = RulesManager.getInstance().createNewRule(em, rule, tenant); try { List<Rule> rules = RulesManager.getInstance().getRuleObjects(em, TENANT_ID_2); assertEquals(1, rules.size()); assertEquals(ruleId, rules.get(0).getRuleId()); assertEquals("", rules.get(0).getName()); } catch (NoResultException e) { } rule = new Rules(); rule.setRuleContent(RuleSerializer.serializeRuleToJSONString( new SimpleRule(ruleId, "simple-rule", true, new EqualsCondition("host", "symcpe"), new Action[] { new TemplatedAlertAction((short) 0, templateId) }), false)); tenant = RulesManager.getInstance().getTenant(em, TENANT_ID_2); ruleId = RulesManager.getInstance().createNewRule(em, rule, tenant); try { List<Rule> rules = RulesManager.getInstance().getRuleObjects(em, TENANT_ID_2); assertEquals(2, rules.size()); for (Rule rule2 : rules) { if (rule2.getRuleId() == ruleId) { assertEquals("simple-rule", rule2.getName()); assertEquals("host", ((EqualsCondition) rule2.getCondition()).getkey()); } } } catch (NoResultException e) { } }