use of nl.nn.adapterframework.monitoring.SeverityEnum 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);
}
}
Aggregations