use of org.graylog2.contentpacks.model.entities.references.ValueReference 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.references.ValueReference in project graylog2-server by Graylog2.
the class EventDefinitionFacadeTest method resolveForInstallation.
@Test
@MongoDBFixtures("EventDefinitionFacadeTest.json")
public void resolveForInstallation() {
EntityV1 eventEntityV1 = createTestEntity();
final NotificationEntity notificationEntity = NotificationEntity.builder().title(ValueReference.of("title")).description(ValueReference.of("description")).config(HttpEventNotificationConfigEntity.builder().url(ValueReference.of("http://url")).build()).build();
final JsonNode data = objectMapper.convertValue(notificationEntity, JsonNode.class);
final EntityV1 notificationV1 = EntityV1.builder().data(data).id(ModelId.of("123123")).type(ModelTypes.EVENT_DEFINITION_V1).build();
final EntityDescriptor entityDescriptor = EntityDescriptor.create("123123", ModelTypes.NOTIFICATION_V1);
Map<String, ValueReference> parameters = ImmutableMap.of();
Map<EntityDescriptor, Entity> entities = ImmutableMap.of(entityDescriptor, notificationV1);
Graph<Entity> graph = facade.resolveForInstallation(eventEntityV1, parameters, entities);
assertThat(graph).isNotNull();
Set<Entity> expectedNodes = ImmutableSet.of(eventEntityV1, notificationV1);
assertThat(graph.nodes()).isEqualTo(expectedNodes);
}
use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method resolveMatchingDependecyForInstallation.
@Test
public void resolveMatchingDependecyForInstallation() {
final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "%{PORTAL}"), JsonNode.class)).build();
final Entity grokPatternEntityDependency = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("PORTAL", "\\d\\d"), JsonNode.class)).build();
final EntityDescriptor dependencyDescriptor = grokPatternEntityDependency.toEntityDescriptor();
final Map<EntityDescriptor, Entity> entityDescriptorEntityMap = new HashMap(1);
entityDescriptorEntityMap.put(dependencyDescriptor, grokPatternEntityDependency);
final Map<String, ValueReference> parameters = Collections.emptyMap();
Graph<Entity> graph = facade.resolveForInstallation(grokPatternEntity, parameters, entityDescriptorEntityMap);
assertThat(graph.nodes().toArray()).contains(grokPatternEntityDependency);
}
use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.
the class ContentPackInstallationRequestTest method testSerialisation.
@Test
public void testSerialisation() {
final ImmutableMap<String, ValueReference> parameters = ImmutableMap.of("param1", ValueReference.of("string"), "param2", ValueReference.of(42), "param3", ValueReference.of(3.14d), "param4", ValueReference.of(true));
final ContentPackInstallationRequest request = ContentPackInstallationRequest.create(parameters, "comment");
final JsonNode node = objectMapper.valueToTree(request);
assertThat(node.path("comment").asText()).isEqualTo("comment");
assertThat(node.path("parameters").path("param1").path("@type").asText()).isEqualTo("string");
assertThat(node.path("parameters").path("param1").path("@value").asText()).isEqualTo("string");
assertThat(node.path("parameters").path("param2").path("@type").asText()).isEqualTo("integer");
assertThat(node.path("parameters").path("param2").path("@value").asInt()).isEqualTo(42);
assertThat(node.path("parameters").path("param3").path("@type").asText()).isEqualTo("double");
assertThat(node.path("parameters").path("param3").path("@value").asDouble()).isEqualTo(3.14d);
assertThat(node.path("parameters").path("param4").path("@type").asText()).isEqualTo("boolean");
assertThat(node.path("parameters").path("param4").path("@value").asBoolean()).isEqualTo(true);
}
use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method notResolveNotMatchingDependecyForInstallation.
@Test
public void notResolveNotMatchingDependecyForInstallation() {
final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "%{DOOM}"), JsonNode.class)).build();
final Entity grokPatternEntityDependency = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("PORTAL", "\\d\\d"), JsonNode.class)).build();
final EntityDescriptor dependencyDescriptor = grokPatternEntityDependency.toEntityDescriptor();
final Map<EntityDescriptor, Entity> entityDescriptorEntityMap = new HashMap(1);
entityDescriptorEntityMap.put(dependencyDescriptor, grokPatternEntityDependency);
final Map<String, ValueReference> parameters = Collections.emptyMap();
Graph<Entity> graph = facade.resolveForInstallation(grokPatternEntity, parameters, entityDescriptorEntityMap);
assertThat(graph.nodes().toArray()).doesNotContain(grokPatternEntityDependency);
}
Aggregations