@Test public void basicEmptyEventFilterTest() throws JsonProcessingException { String clientId = "myClientId"; EventFilter filter = new EventFilter(clientId); Map<String, List<String>> params = new HashMap<>(); List<String> subIdParam = new ArrayList<>(); subIdParam.add("mySubId"); params.put(MantisSourceJobConstants.SUBSCRIPTION_ID_PARAM_NAME, subIdParam); Func1<String, Boolean> materializedFilter = filter.call(params); List<String> matchedClients = new ArrayList<>(); matchedClients.add(clientId + "_" + "mySubId"); matchedClients.add(clientId + "_" + "BlahSubId"); Map<String, Object> payLoad = new HashMap<>(); String payloadStr = mapper.writeValueAsString(payLoad); assertFalse(materializedFilter.call(payloadStr)); try { assertFalse(materializedFilter.call(null)); } catch (Exception e) { fail(); } }
@Override public Func1<String, Boolean> call(Map<String, List<String>> parameters) { Func1<String, Boolean> filter = t1 -> true; if (parameters != null) { if (parameters.containsKey(MantisSourceJobConstants.FILTER_PARAM_NAME)) { String filterBy = parameters.get(MantisSourceJobConstants.FILTER_PARAM_NAME).get(0); List<String> terms = convertCommaSeparatedEventsToList(filterBy); LOGGER.info("terms: " + terms); filter = new SourceEventFilter(terms); } else if (parameters.containsKey(MantisSourceJobConstants.SUBSCRIPTION_ID_PARAM_NAME)) { String subId = parameters.get(MantisSourceJobConstants.SUBSCRIPTION_ID_PARAM_NAME).get(0); List<String> terms = new ArrayList<String>(); terms.add(clientId + "_" + subId); filter = new SourceEventFilter(terms); } return filter; } return filter; }
EventFilter implements Func1<Map<String, List<String>>, Func1<String, Boolean>> { @Override public Func1<String, Boolean> call(Map<String, List<String>> parameters) { Func1<String, Boolean> filter = t1 -> true; if (parameters != null) { if (parameters.containsKey(MantisSourceJobConstants.FILTER_PARAM_NAME)) { String filterBy = parameters.get(MantisSourceJobConstants.FILTER_PARAM_NAME).get(0); List<String> terms = convertCommaSeparatedEventsToList(filterBy); LOGGER.info("terms: " + terms); filter = new SourceEventFilter(terms); } else if (parameters.containsKey(MantisSourceJobConstants.SUBSCRIPTION_ID_PARAM_NAME)) { String subId = parameters.get(MantisSourceJobConstants.SUBSCRIPTION_ID_PARAM_NAME).get(0); List<String> terms = new ArrayList<String>(); terms.add(clientId + "_" + subId); filter = new SourceEventFilter(terms); } return filter; } return filter; } }
EventFilter implements Func1<Map<String, List<String>>, Func1<String, Boolean>> { @Override public Func1<String, Boolean> call(Map<String, List<String>> parameters) { Func1<String, Boolean> filter = t1 -> true; if (parameters != null) { if (parameters.containsKey(MantisSourceJobConstants.FILTER_PARAM_NAME)) { String filterBy = parameters.get(MantisSourceJobConstants.FILTER_PARAM_NAME).get(0); List<String> terms = convertCommaSeparatedEventsToList(filterBy); LOGGER.info("terms: " + terms); filter = new SourceEventFilter(terms); } else if (parameters.containsKey(MantisSourceJobConstants.SUBSCRIPTION_ID_PARAM_NAME)) { String subId = parameters.get(MantisSourceJobConstants.SUBSCRIPTION_ID_PARAM_NAME).get(0); List<String> terms = new ArrayList<String>(); terms.add(clientId + "_" + subId); filter = new SourceEventFilter(terms); } return filter; } return filter; } EventFilter(String clientId); }
EventFilter implements Func1<Map<String, List<String>>, Func1<String, Boolean>> { @Override public Func1<String, Boolean> call(Map<String, List<String>> parameters) { Func1<String, Boolean> filter = t1 -> true; if (parameters != null) { if (parameters.containsKey(MantisSourceJobConstants.FILTER_PARAM_NAME)) { String filterBy = parameters.get(MantisSourceJobConstants.FILTER_PARAM_NAME).get(0); List<String> terms = convertCommaSeparatedEventsToList(filterBy); LOGGER.info("terms: " + terms); filter = new SourceEventFilter(terms); } else if (parameters.containsKey(MantisSourceJobConstants.SUBSCRIPTION_ID_PARAM_NAME)) { String subId = parameters.get(MantisSourceJobConstants.SUBSCRIPTION_ID_PARAM_NAME).get(0); List<String> terms = new ArrayList<String>(); terms.add(clientId + "_" + subId); filter = new SourceEventFilter(terms); } return filter; } return filter; } EventFilter(String clientId); @Override Func1<String, Boolean> call(Map<String, List<String>> parameters); }
EventFilter implements Func1<Map<String, List<String>>, Func1<String, Boolean>> { @Override public Func1<String, Boolean> call(Map<String, List<String>> parameters) { Func1<String, Boolean> filter = t1 -> true; if (parameters != null) { if (parameters.containsKey(MantisSourceJobConstants.FILTER_PARAM_NAME)) { String filterBy = parameters.get(MantisSourceJobConstants.FILTER_PARAM_NAME).get(0); List<String> terms = convertCommaSeparatedEventsToList(filterBy); LOGGER.info("terms: " + terms); filter = new SourceEventFilter(terms); } else if (parameters.containsKey(MantisSourceJobConstants.SUBSCRIPTION_ID_PARAM_NAME)) { String subId = parameters.get(MantisSourceJobConstants.SUBSCRIPTION_ID_PARAM_NAME).get(0); List<String> terms = new ArrayList<String>(); terms.add(clientId + "_" + subId); filter = new SourceEventFilter(terms); } return filter; } return filter; } EventFilter(String clientId); @Override Func1<String, Boolean> call(Map<String, List<String>> parameters);  }