public List<DSRuleElement> getDSRules(User user) { PreparedStatement ps = null; ResultSet rs = null; List<DSRuleElement> ruleElements = new ArrayList<DSRuleElement>(); try { con.prepareStatement(SELECT_RULE_DS_QRY); ps.setInt(1, user.getId()); rs = ps.executeQuery(); while (rs.next()) { DSRuleElement dsRuleElement = new DSRuleElement(); dsRuleElement.setDataSourceID("ds" + rs.getInt("dsmaster_id")); dsRuleElement.setDataSourceName(rs.getString("dsmaster_title")); dsRuleElement.setRuleID(rs.getInt("RuleID")); dsRuleElement.setRuleName(rs.getString("Rule_Name")); ruleElements.add(dsRuleElement); } return ruleElements; } catch (SQLException e) { e.printStackTrace(); } return null; }
public static void main(String args[]) { RuleDao rd = new RuleDao(); User user = new User(); user.setId(78); rd.getAllRules(user); }
public List<Rules> getAllRules(User user) { PreparedStatement ps = null; ResultSet rs = null; List<Rules> rulesList = new ArrayList<>(); try { ps = con.prepareStatement(SELECT_ALL_RULE_QRY); ps.setInt(1, user.getId()); rs = ps.executeQuery(); while (rs.next()) { Rules rules = new Rules(); int ruleID; String ruleName; String sourceID; String ruleString; String sourceFields; int userId; ruleID = rs.getInt(RULE_ID); ruleName = rs.getString(RULE_NAME); if (ruleName == null) { ruleName = ""; } sourceID = rs.getString(SOURCE_ID); ruleString = rs.getString(RULE_QUERIES); if (ruleString == null) { ruleString = ""; } sourceFields = rs.getString(SOURCE_FIELDS); if (sourceFields == null) { sourceFields = ""; } userId = rs.getInt(USER_ID); rules.setRuleID(ruleID); rules.setRuleName(ruleName); rules.setUserId(userId); rules.setSource(sourceID); rules.setExtractFields(sourceFields); List<Rule> ruless = new ArrayList<Rule>(); if (!ruleString.equals("")) { JsonObject rulesObj = (new JsonParser()).parse(ruleString).getAsJsonObject(); JsonArray rulesJson = rulesObj.get("rules").getAsJsonArray(); for (int i = 0; i < rulesJson.size(); i++) { Rule rule = new Rule(); JsonObject tempObj = rulesJson.get(i).getAsJsonObject(); rule.setRuleOperator(tempObj.get("ruleOperator").getAsString()); rule.setDataField(tempObj.get("dataField").getAsString()); rule.setRuleParameters(tempObj.get("ruleParameters").getAsString()); ruless.add(rule); } } rules.setRules(ruless); rulesList.add(rules); } for (int i = 0; i < rulesList.size(); i++) { LOGGER.debug(rulesList.get(i).toString()); } } catch (Exception e) { e.printStackTrace(); } finally { } return rulesList; }