Search in sources :

Example 41 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class SidecarCollectorConfigurationFacade method decode.

private NativeEntity<Configuration> decode(EntityV1 entity, Map<String, ValueReference> parameters) {
    final SidecarCollectorConfigurationEntity configurationEntity = objectMapper.convertValue(entity.data(), SidecarCollectorConfigurationEntity.class);
    final Configuration configuration = Configuration.create(configurationEntity.collectorId().asString(parameters), configurationEntity.title().asString(parameters), configurationEntity.color().asString(parameters), configurationEntity.template().asString(parameters));
    final Configuration savedConfiguration = configurationService.save(configuration);
    return NativeEntity.create(entity.id(), savedConfiguration.id(), TYPE_V1, configuration.name(), savedConfiguration);
}
Also used : Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity)

Example 42 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class UrlWhitelistFacade method createNativeEntity.

@Override
public NativeEntity<WhitelistEntry> createNativeEntity(Entity entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities, String username) {
    if (!(entity instanceof EntityV1)) {
        throw new IllegalArgumentException("Unsupported entity version: " + entity.getClass());
    }
    final WhitelistEntry whitelistEntry = objectMapper.convertValue(((EntityV1) entity).data(), WhitelistEntry.class);
    urlWhitelistService.addEntry(whitelistEntry);
    return NativeEntity.create(entity.id(), whitelistEntry.id(), TYPE_V1, createTitle(whitelistEntry), whitelistEntry);
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) WhitelistEntry(org.graylog2.system.urlwhitelist.WhitelistEntry)

Example 43 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class DashboardV1Facade method convertEntity.

private EntityV1 convertEntity(EntityV1 entityV1, Map<String, ValueReference> parameters) {
    final DashboardEntity dashboardEntity = objectMapper.convertValue(entityV1.data(), DashboardEntity.class);
    final ViewEntity viewEntity = entityConverter.convert(dashboardEntity, parameters);
    final JsonNode data = objectMapper.convertValue(viewEntity, JsonNode.class);
    return entityV1.toBuilder().data(data).type(ModelTypes.DASHBOARD_V2).build();
}
Also used : DashboardEntity(org.graylog2.contentpacks.model.entities.DashboardEntity) ViewEntity(org.graylog2.contentpacks.model.entities.ViewEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 44 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class DashboardV1Facade method createNativeEntity.

@Override
public NativeEntity<ViewDTO> createNativeEntity(Entity entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities, String username) {
    ensureV1(entity);
    final User user = Optional.ofNullable(userService.load(username)).orElseThrow(() -> new IllegalStateException("Cannot load user <" + username + "> from db"));
    return decode((EntityV1) entity, parameters, nativeEntities, user);
}
Also used : User(org.graylog2.plugin.database.users.User)

Aggregations

ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)18 Entity (org.graylog2.contentpacks.model.entities.Entity)16 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)16 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)16 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 Map (java.util.Map)10 ContentPackException (org.graylog2.contentpacks.exceptions.ContentPackException)10 ModelType (org.graylog2.contentpacks.model.ModelType)10 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)10 Set (java.util.Set)9 ImmutableSet (com.google.common.collect.ImmutableSet)8 Graph (com.google.common.graph.Graph)8 GraphBuilder (com.google.common.graph.GraphBuilder)8 ImmutableGraph (com.google.common.graph.ImmutableGraph)8 MutableGraph (com.google.common.graph.MutableGraph)8 HashMap (java.util.HashMap)8 Optional (java.util.Optional)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7 Collection (java.util.Collection)7