use of org.graylog2.dashboards.widgets.DashboardWidget in project graylog2-server by Graylog2.
the class BundleImporter method createDashboardWidget.
@SuppressWarnings("unchecked")
private org.graylog2.dashboards.widgets.DashboardWidget createDashboardWidget(final DashboardWidget dashboardWidget, final String userName) throws InvalidRangeParametersException, org.graylog2.dashboards.widgets.DashboardWidget.NoSuchWidgetTypeException, InvalidWidgetConfigurationException {
final String type = dashboardWidget.getType();
final Map<String, Object> config = dashboardWidget.getConfiguration();
// Replace "stream_id" in config if it's set
final String streamReference = (String) config.get("stream_id");
if (!isNullOrEmpty(streamReference)) {
final org.graylog2.plugin.streams.Stream stream = streamsByReferenceId.get(streamReference);
if (null != stream) {
config.put("stream_id", stream.getId());
} else {
LOG.warn("Couldn't find referenced stream {}", streamReference);
}
}
// Build timerange.
final Map<String, Object> timerangeConfig = (Map<String, Object>) config.get("timerange");
final TimeRange timeRange = timeRangeFactory.create(timerangeConfig);
final String widgetId = UUID.randomUUID().toString();
return dashboardWidgetCreator.buildDashboardWidget(type, widgetId, dashboardWidget.getDescription(), dashboardWidget.getCacheTime(), config, timeRange, userName);
}
use of org.graylog2.dashboards.widgets.DashboardWidget in project graylog2-server by Graylog2.
the class DashboardServiceImpl method create.
private Dashboard create(ObjectId id, Map<String, Object> fields) {
final Dashboard dashboard = new DashboardImpl(id, fields);
// Add all widgets of this dashboard.
if (fields.containsKey(DashboardImpl.EMBEDDED_WIDGETS)) {
if (fields.get(DashboardImpl.EMBEDDED_WIDGETS) instanceof List) {
for (BasicDBObject widgetFields : (List<BasicDBObject>) fields.get(DashboardImpl.EMBEDDED_WIDGETS)) {
try {
final DashboardWidget widget = dashboardWidgetCreator.fromPersisted(widgetFields);
dashboard.addPersistedWidget(widget);
} catch (DashboardWidget.NoSuchWidgetTypeException e) {
LOG.error("No such widget type: [" + widgetFields.get("type") + "] - Dashboard: [" + dashboard.getId() + "]", e);
} catch (InvalidRangeParametersException e) {
LOG.error("Invalid range parameters of widget in dashboard: [" + dashboard.getId() + "]", e);
} catch (InvalidWidgetConfigurationException e) {
LOG.error("Invalid configuration of widget in dashboard: [" + dashboard.getId() + "]", e);
}
}
}
}
return dashboard;
}
use of org.graylog2.dashboards.widgets.DashboardWidget in project graylog2-server by Graylog2.
the class DashboardWidgetCreator method fromRequest.
public DashboardWidget fromRequest(String widgetId, AddWidgetRequest awr, String userId) throws DashboardWidget.NoSuchWidgetTypeException, InvalidRangeParametersException, InvalidWidgetConfigurationException {
final String id = isNullOrEmpty(widgetId) ? UUID.randomUUID().toString() : widgetId;
// Build timerange.
final Map<String, Object> timerangeConfig = (Map<String, Object>) awr.config().get("timerange");
final TimeRange timeRange = timeRangeFactory.create(timerangeConfig);
return buildDashboardWidget(awr.type(), id, awr.description(), 0, awr.config(), timeRange, userId);
}
use of org.graylog2.dashboards.widgets.DashboardWidget in project graylog2-server by Graylog2.
the class DashboardWidgetsResourceTest method updateWidgetMustSendUpdatedWidgetEvent.
@Test
public void updateWidgetMustSendUpdatedWidgetEvent() throws Exception {
final DashboardWidget updatedWidget = mock(DashboardWidget.class);
when(updatedWidget.getId()).thenReturn(widgetId);
final AddWidgetRequest addWidgetRequest = AddWidgetRequest.create("new description", "new type", 60, Collections.emptyMap());
when(dashboardWidgetCreator.fromRequest(eq(widgetId), eq(addWidgetRequest), eq(creatorUserId))).thenReturn(updatedWidget);
this.dashboardWidgetsResource.updateWidget(dashboardId, widgetId, addWidgetRequest);
verifyWidgetUpdatedEvent(widgetId);
}
Aggregations