use of org.graylog2.contentpacks.model.entities.DashboardWidgetEntity in project graylog2-server by Graylog2.
the class DashboardWidgetConverter method convert.
public List<WidgetEntity> convert(DashboardWidgetEntity dashboardWidgetEntity, Map<String, ValueReference> parameters) {
this.dashboardWidgetEntity = dashboardWidgetEntity;
this.config = new WidgetConfig(dashboardWidgetEntity.configuration(), parameters);
this.parameters = parameters;
final String type = dashboardWidgetEntity.type().asString(parameters);
switch(type.toUpperCase(Locale.ENGLISH)) {
case "SEARCH_RESULT_CHART":
return createHistogramWidget();
case "FIELD_CHART":
return createFieldChartWidget();
case "STACKED_CHART":
return createStackedChartWidget();
case "STATS_COUNT":
return createStatsCountWidget();
case "QUICKVALUES":
return createQuickValueWidgets();
case "STREAM_SEARCH_RESULT_COUNT":
case "SEARCH_RESULT_COUNT":
return createSearchResultCount();
case "QUICKVALUES_HISTOGRAM":
return createQuickValueHistogramWidgets();
case "ORG.GRAYLOG.PLUGINS.MAP.WIDGET.STRATEGY.MAPWIDGETSTRATEGY":
return createMapWidget();
default:
{
throw new RuntimeException("The provided entity does not have a valid Widget type: " + type);
}
}
}
use of org.graylog2.contentpacks.model.entities.DashboardWidgetEntity in project graylog2-server by Graylog2.
the class EntityConverter method convert.
public ViewEntity convert(DashboardEntity dashboardEntity, Map<String, ValueReference> parameters) {
this.parameters = parameters;
this.dashboardEntity = dashboardEntity;
final String queryId = UUID.randomUUID().toString();
final Map<DashboardWidgetEntity, List<WidgetEntity>> widgets = convertWidgets();
final Map<String, WidgetPositionDTO> widgetPositionMap = DashboardEntity.positionMap(parameters, widgets);
final Titles titles = DashboardEntity.widgetTitles(widgets, parameters);
final Map<String, Set<String>> widgetMapping = new HashMap<>();
final Set<SearchTypeEntity> searchTypes = new HashSet<>();
createSearchTypes(widgets, widgetMapping, searchTypes);
SearchEntity searchEntity;
try {
searchEntity = createSearchEntity(queryId, searchTypes);
} catch (InvalidRangeParametersException e) {
throw new IllegalArgumentException("The provided entity does not have a valid TimeRange", e);
}
final ViewStateEntity viewStateEntity = ViewStateEntity.builder().widgets(widgets.values().stream().flatMap(Collection::stream).collect(Collectors.toSet())).titles(titles).widgetMapping(widgetMapping).widgetPositions(widgetPositionMap).build();
final Map<String, ViewStateEntity> viewStateEntityMap = ImmutableMap.of(queryId, viewStateEntity);
return ViewEntity.builder().search(searchEntity).state(viewStateEntityMap).title(dashboardEntity.title()).properties(Collections.emptySet()).description(dashboardEntity.description()).requires(Collections.emptyMap()).summary(ValueReference.of("Converted Dashboard")).createdAt(DateTime.now(DateTimeZone.UTC)).type(ViewEntity.Type.DASHBOARD).build();
}
use of org.graylog2.contentpacks.model.entities.DashboardWidgetEntity in project graylog2-server by Graylog2.
the class ValueReferenceTypeIdResolverTest method testEmbeddedDeserialization.
@Test
public void testEmbeddedDeserialization() throws IOException {
String json = "{" + " \"id\" : {" + " \"@value\" : \"12345\"," + " \"@type\" : \"string\"" + " }," + " \"cache_time\" : {" + " \"@value\" : 120," + " \"@type\" : \"integer\"" + " }," + " \"position\" : null," + " \"description\" : {" + " \"@value\" : \"Histogram\"," + " \"@type\" : \"string\"" + " }," + " \"time_range\" : {" + " \"type\" : {" + " \"@type\" : \"string\"," + " \"@value\" : \"relative\"" + " }," + " \"range\" : {" + " \"@type\" : \"integer\"," + " \"@value\" : 300" + " }" + " }," + " \"type\" : {" + " \"@value\" : \"SEARCH_RESULT_CHART\"," + " \"@type\" : \"string\"" + " }," + " \"configuration\" : {" + " \"timerange\" : {" + " \"range\" : {" + " \"@value\" : 300," + " \"@type\" : \"integer\"" + " }," + " \"type\" : {" + " \"@value\" : \"relative\"," + " \"@type\" : \"string\"" + " }" + " }," + " \"query\" : {" + " \"@value\" : \"\"," + " \"@type\" : \"string\"" + " }," + " \"interval\" : {" + " \"@type\" : \"string\"," + " \"@value\" : \"minute\"" + " }" + " }" + "}";
final DashboardWidgetEntity entity = objectMapper.readValue(json, DashboardWidgetEntity.class);
assertThat(entity).isNotNull();
}
Aggregations