@Test public void testRoomMatch() { condition.key = "room_id"; condition.pattern = TEST_ROOM_ID; Assert.assertTrue(condition.isSatisfied(event)); event.roomId = "!otherroomid:matrix.org"; Assert.assertFalse(condition.isSatisfied(event)); }
public boolean isSatisfied(Event event) { String fieldVal = null; if (event.isEncrypted() && (null != event.getClearEvent())) { JsonObject eventJson = event.getClearEvent().toJsonObject(); fieldVal = extractField(eventJson, key); } if (TextUtils.isEmpty(fieldVal)) { JsonObject eventJson = event.toJsonObject(); fieldVal = extractField(eventJson, key); } if (TextUtils.isEmpty(fieldVal)) { return false; } if (TextUtils.equals(pattern, fieldVal)) { return true; } if (null == mPatternByRule) { mPatternByRule = new HashMap<>(); } Pattern patternEx = mPatternByRule.get(pattern); if (null == patternEx) { patternEx = Pattern.compile(globToRegex(pattern), Pattern.CASE_INSENSITIVE); mPatternByRule.put(pattern, patternEx); } return patternEx.matcher(fieldVal).matches(); }
EventMatchCondition extends Condition { public boolean isSatisfied(Event event) { String fieldVal = null; if (event.isEncrypted() && (null != event.getClearEvent())) { JsonObject eventJson = event.getClearEvent().toJsonObject(); fieldVal = extractField(eventJson, key); } if (TextUtils.isEmpty(fieldVal)) { JsonObject eventJson = event.toJsonObject(); fieldVal = extractField(eventJson, key); } if (TextUtils.isEmpty(fieldVal)) { return false; } if (TextUtils.equals(pattern, fieldVal)) { return true; } if (null == mPatternByRule) { mPatternByRule = new HashMap<>(); } Pattern patternEx = mPatternByRule.get(pattern); if (null == patternEx) { patternEx = Pattern.compile(globToRegex(pattern), Pattern.CASE_INSENSITIVE); mPatternByRule.put(pattern, patternEx); } return patternEx.matcher(fieldVal).matches(); } }
EventMatchCondition extends Condition { public boolean isSatisfied(Event event) { String fieldVal = null; if (event.isEncrypted() && (null != event.getClearEvent())) { JsonObject eventJson = event.getClearEvent().toJsonObject(); fieldVal = extractField(eventJson, key); } if (TextUtils.isEmpty(fieldVal)) { JsonObject eventJson = event.toJsonObject(); fieldVal = extractField(eventJson, key); } if (TextUtils.isEmpty(fieldVal)) { return false; } if (TextUtils.equals(pattern, fieldVal)) { return true; } if (null == mPatternByRule) { mPatternByRule = new HashMap<>(); } Pattern patternEx = mPatternByRule.get(pattern); if (null == patternEx) { patternEx = Pattern.compile(globToRegex(pattern), Pattern.CASE_INSENSITIVE); mPatternByRule.put(pattern, patternEx); } return patternEx.matcher(fieldVal).matches(); } EventMatchCondition(); }
EventMatchCondition extends Condition { public boolean isSatisfied(Event event) { String fieldVal = null; if (event.isEncrypted() && (null != event.getClearEvent())) { JsonObject eventJson = event.getClearEvent().toJsonObject(); fieldVal = extractField(eventJson, key); } if (TextUtils.isEmpty(fieldVal)) { JsonObject eventJson = event.toJsonObject(); fieldVal = extractField(eventJson, key); } if (TextUtils.isEmpty(fieldVal)) { return false; } if (TextUtils.equals(pattern, fieldVal)) { return true; } if (null == mPatternByRule) { mPatternByRule = new HashMap<>(); } Pattern patternEx = mPatternByRule.get(pattern); if (null == patternEx) { patternEx = Pattern.compile(globToRegex(pattern), Pattern.CASE_INSENSITIVE); mPatternByRule.put(pattern, patternEx); } return patternEx.matcher(fieldVal).matches(); } EventMatchCondition(); @Override String toString(); boolean isSatisfied(Event event); }
EventMatchCondition extends Condition { public boolean isSatisfied(Event event) { String fieldVal = null; if (event.isEncrypted() && (null != event.getClearEvent())) { JsonObject eventJson = event.getClearEvent().toJsonObject(); fieldVal = extractField(eventJson, key); } if (TextUtils.isEmpty(fieldVal)) { JsonObject eventJson = event.toJsonObject(); fieldVal = extractField(eventJson, key); } if (TextUtils.isEmpty(fieldVal)) { return false; } if (TextUtils.equals(pattern, fieldVal)) { return true; } if (null == mPatternByRule) { mPatternByRule = new HashMap<>(); } Pattern patternEx = mPatternByRule.get(pattern); if (null == patternEx) { patternEx = Pattern.compile(globToRegex(pattern), Pattern.CASE_INSENSITIVE); mPatternByRule.put(pattern, patternEx); } return patternEx.matcher(fieldVal).matches(); } EventMatchCondition(); @Override String toString(); boolean isSatisfied(Event event); public String key; public String pattern; }