/**
  * filters test based on given filterKey/filterValue. If the any of the filter key/value pairs
  * found from data object, then returns true.
  *
  * @param data test data
  * @return true if test is selected after applying filter, false otherwise
  */
 private boolean checkAgainstFilterProperties(
     HierarchicalConfiguration data, HierarchicalConfiguration context) {
   boolean included = true;
   String filterKeys[] = null;
   String filterValues[] = null;
   if (context.containsKey(ARG_FILTER_KEY)
       && !context.getString(ARG_FILTER_KEY).trim().equals("")) {
     filterKeys = context.getStringArray(ARG_FILTER_KEY);
     filterValues = context.getStringArray(ARG_FILTER_VALUE);
   } else if (DDConfig.getSingleton().getData().containsKey(ARG_FILTER_KEY)
       && !DDConfig.getSingleton().getData().getString(ARG_FILTER_KEY).trim().equals("")) {
     filterKeys = DDConfig.getSingleton().getData().getStringArray(ARG_FILTER_KEY);
     filterValues = DDConfig.getSingleton().getData().getStringArray(ARG_FILTER_VALUE);
   }
   if (filterKeys != null && filterValues != null) {
     included = false;
     for (int index = 0; index < filterKeys.length; index++) {
       String filterKey = filterKeys[index];
       String filterValue = null;
       if (index >= filterValues.length) {
         filterValue = "";
       } else {
         filterValue = filterValues[index];
       }
       if (data.containsKey(filterKey) && data.getString(filterKey, "").equals(filterValue)) {
         included = true;
         break;
       }
     }
   }
   return included;
 }
示例#2
0
  @Override
  @SuppressWarnings("unchecked")
  public List<UserAlert> getAvailableAlerts() {
    List<UserAlert> alerts = new ArrayList<UserAlert>();

    final SortedMap<Integer, Pair> categoryNames = new ConcurrentSkipListMap<Integer, Pair>();

    HierarchicalConfiguration hc = (HierarchicalConfiguration) configuration;
    List<HierarchicalConfiguration> categories = hc.configurationsAt(ALERTS_CATEGORIES_CATEGORY);

    for (HierarchicalConfiguration c : categories) {
      String key = c.getString("[@key]");
      int order = c.getInt("[@displayOrder]", categoryNames.size());
      String value = c.getString("");

      categoryNames.put(order, new Pair<String, String>(key, value));
    }

    final String[] weeklyCategories = hc.getStringArray(ALERTS_WEEKLY);
    final String[] monthlyCategories = hc.getStringArray(ALERTS_MONTHLY);
    final String[] subjectFilters = hc.getStringArray(SUBJECT_FILTER);

    final Set<Map.Entry<Integer, Pair>> categoryNamesSet = categoryNames.entrySet();

    for (final Map.Entry<Integer, Pair> category : categoryNamesSet) {
      final String key = (String) category.getValue().getFirst();
      boolean weeklyCategoryKey = false;
      boolean monthlyCategoryKey = false;
      boolean subjectFilter = false;

      if (ArrayUtils.contains(weeklyCategories, key)) {
        weeklyCategoryKey = true;
      }
      if (ArrayUtils.contains(monthlyCategories, key)) {
        monthlyCategoryKey = true;
      }
      if (ArrayUtils.contains(subjectFilters, key)) {
        subjectFilter = true;
      }

      alerts.add(
          new UserAlert(
              (String) category.getValue().getFirst(),
              (String) category.getValue().getSecond(),
              weeklyCategoryKey,
              monthlyCategoryKey,
              subjectFilter));
    }
    return alerts;
  }
 @Override
 protected void doConfigure(HierarchicalConfiguration arg0) throws ConfigurationException {
   String[] mapConf = arg0.getStringArray("mapping");
   mappings = Maps.newHashMap();
   if (mapConf != null && mapConf.length > 0) {
     for (String aMapConf : mapConf) {
       mappings.putAll(RecipientRewriteTableUtil.getXMLMappings(aMapConf));
     }
   } else {
     throw new ConfigurationException("No mapping configured");
   }
 }