Search in sources :

Example 1 with TriggerType

use of nl.nn.adapterframework.monitoring.ITrigger.TriggerType in project iaf by ibissource.

the class ShowMonitors method handleTrigger.

@SuppressWarnings("unchecked")
private void handleTrigger(ITrigger trigger, Map<String, Object> json) {
    List<String> eventList = null;
    TriggerType type = null;
    SeverityEnum severity = null;
    int threshold = 0;
    int period = 0;
    String filter = null;
    List<String> adapters = null;
    Map<String, List<String>> sources = null;
    for (Entry<String, Object> entry : json.entrySet()) {
        String key = entry.getKey();
        if (key.equalsIgnoreCase("events") && entry.getValue() instanceof List<?>) {
            eventList = (List<String>) entry.getValue();
        } else if (key.equalsIgnoreCase("type")) {
            type = EnumUtils.parse(TriggerType.class, entry.getValue().toString());
        } else if (key.equalsIgnoreCase("severity")) {
            severity = EnumUtils.parse(SeverityEnum.class, entry.getValue().toString());
        } else if (key.equalsIgnoreCase("threshold")) {
            threshold = (Integer.parseInt("" + entry.getValue()));
            if (threshold < 0) {
                throw new ApiException("threshold must be a positive number");
            }
        } else if (key.equalsIgnoreCase("period")) {
            period = (Integer.parseInt("" + entry.getValue()));
            if (period < 0) {
                throw new ApiException("period must be a positive number");
            }
        } else if (key.equalsIgnoreCase("filter")) {
            filter = entry.getValue().toString();
        } else if (key.equalsIgnoreCase("adapters") && entry.getValue() instanceof List<?>) {
            adapters = (List<String>) entry.getValue();
        } else if (key.equalsIgnoreCase("sources") && entry.getValue() instanceof Map<?, ?>) {
            sources = (Map<String, List<String>>) entry.getValue();
        }
    }
    // If no parse errors have occured we can continue!
    trigger.setEventCodes(eventList.toArray(new String[eventList.size()]));
    trigger.setTriggerType(type);
    trigger.setSeverityEnum(severity);
    trigger.setThreshold(threshold);
    trigger.setPeriod(period);
    trigger.clearAdapterFilters();
    if ("adapter".equals(filter)) {
        trigger.setSourceFilteringEnum(SourceFiltering.ADAPTER);
        for (String adapter : adapters) {
            AdapterFilter adapterFilter = new AdapterFilter();
            adapterFilter.setAdapter(adapter);
            trigger.registerAdapterFilter(adapterFilter);
        }
    } else if ("source".equals(filter)) {
        trigger.setSourceFilteringEnum(SourceFiltering.SOURCE);
        for (Map.Entry<String, List<String>> entry : sources.entrySet()) {
            AdapterFilter adapterFilter = new AdapterFilter();
            adapterFilter.setAdapter(entry.getKey());
            for (String subObject : entry.getValue()) {
                adapterFilter.registerSubObject(subObject);
            }
            trigger.registerAdapterFilter(adapterFilter);
        }
    } else {
        trigger.setSourceFilteringEnum(SourceFiltering.NONE);
    }
}
Also used : TriggerType(nl.nn.adapterframework.monitoring.ITrigger.TriggerType) SeverityEnum(nl.nn.adapterframework.monitoring.SeverityEnum) Entry(java.util.Map.Entry) AdapterFilter(nl.nn.adapterframework.monitoring.AdapterFilter) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 AdapterFilter (nl.nn.adapterframework.monitoring.AdapterFilter)1 TriggerType (nl.nn.adapterframework.monitoring.ITrigger.TriggerType)1 SeverityEnum (nl.nn.adapterframework.monitoring.SeverityEnum)1