// Build timerange.
final Map<String, Object> timerangeConfig = (Map<String, Object>) config.get("timerange");
final TimeRange timeRange;
if (!timerangeConfig.containsKey("type")) {
throw new InvalidRangeParametersException("range type not set");
}
final String rangeType = (String) timerangeConfig.get("type");
switch (rangeType) {
case "relative":
timeRange = new RelativeRange((Integer) timerangeConfig.get("range"));
break;
case "keyword":
timeRange = new KeywordRange((String) timerangeConfig.get("keyword"));
break;
case "absolute":
final String from = new DateTime(timerangeConfig.get("from"), DateTimeZone.UTC).toString(Tools.ES_DATE_FORMAT);
final String to = new DateTime(timerangeConfig.get("to"), DateTimeZone.UTC).toString(Tools.ES_DATE_FORMAT);
timeRange = new AbsoluteRange(from, to);
break;
default:
throw new InvalidRangeParametersException("range_type not recognized");
}
final String widgetId = UUID.randomUUID().toString();
return org.graylog2.dashboards.widgets.DashboardWidget.buildDashboardWidget(type, metricRegistry, searches,
widgetId, dashboardWidget.getDescription(), dashboardWidget.getCacheTime(),