Search in sources :

Example 11 with Parameter

use of org.graylog2.contentpacks.model.parameters.Parameter in project graylog2-server by Graylog2.

the class ReferenceConverterTest method convertParameterValue.

@Test
public void convertParameterValue() {
    final Reference reference = createReference("parameter", "wat");
    assertThat(reference).isEqualTo(ValueReference.createParameter("wat"));
}
Also used : ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) Reference(org.graylog2.contentpacks.model.entities.references.Reference) Test(org.junit.Test)

Example 12 with Parameter

use of org.graylog2.contentpacks.model.parameters.Parameter in project graylog2-server by Graylog2.

the class Search method applyExecutionState.

public Search applyExecutionState(ObjectMapper objectMapper, ExecutionState executionState) {
    final Builder builder = toBuilder();
    if (!executionState.parameterBindings().isEmpty()) {
        final ImmutableSet<Parameter> parameters = parameters().stream().map(param -> param.applyBindings(executionState.parameterBindings())).collect(toImmutableSet());
        builder.parameters(parameters);
    }
    if (executionState.queries() != null || executionState.globalOverride() != null) {
        final ImmutableSet<Query> queries = queries().stream().map(query -> applyStateToQuery(executionState, query)).collect(toImmutableSet());
        builder.queries(queries);
    }
    return builder.build();
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Id(org.mongojack.Id) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) DateTimeZone(org.joda.time.DateTimeZone) Supplier(java.util.function.Supplier) SearchEntity(org.graylog2.contentpacks.model.entities.SearchEntity) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSet.of(com.google.common.collect.ImmutableSet.of) ImmutableSet(com.google.common.collect.ImmutableSet) ContentPackable(org.graylog2.contentpacks.ContentPackable) ImmutableMap(com.google.common.collect.ImmutableMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) ObjectId(org.mongojack.ObjectId) Set(java.util.Set) JsonAutoDetect(com.fasterxml.jackson.annotation.JsonAutoDetect) JsonPOJOBuilder(com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) PluginMetadataSummary(org.graylog.plugins.views.search.views.PluginMetadataSummary) ExecutionStateGlobalOverride(org.graylog.plugins.views.search.rest.ExecutionStateGlobalOverride) ExecutionState(org.graylog.plugins.views.search.rest.ExecutionState) MissingStreamPermissionException(org.graylog2.shared.rest.exceptions.MissingStreamPermissionException) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) AutoValue(com.google.auto.value.AutoValue) Optional(java.util.Optional) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) Collections(java.util.Collections) JsonPOJOBuilder(com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder)

Example 13 with Parameter

use of org.graylog2.contentpacks.model.parameters.Parameter in project graylog2-server by Graylog2.

the class ContentPackService method validateParameters.

private ImmutableMap<String, ValueReference> validateParameters(Map<String, ValueReference> parameters, Set<Parameter> contentPackParameters) {
    final Set<String> contentPackParameterNames = contentPackParameters.stream().map(Parameter::name).collect(Collectors.toSet());
    checkUnknownParameters(parameters, contentPackParameterNames);
    checkMissingParameters(parameters, contentPackParameterNames);
    final Map<String, ValueType> contentPackParameterValueTypes = contentPackParameters.stream().collect(Collectors.toMap(Parameter::name, Parameter::valueType));
    final Set<String> invalidParameters = parameters.entrySet().stream().filter(entry -> entry.getValue().valueType() != contentPackParameterValueTypes.get(entry.getKey())).map(Map.Entry::getKey).collect(Collectors.toSet());
    if (!invalidParameters.isEmpty()) {
        throw new InvalidParametersException(invalidParameters);
    }
    final ImmutableMap.Builder<String, ValueReference> validatedParameters = ImmutableMap.builder();
    for (Parameter contentPackParameter : contentPackParameters) {
        final String name = contentPackParameter.name();
        final ValueReference providedParameter = parameters.get(name);
        if (providedParameter == null) {
            final Optional<?> defaultValue = contentPackParameter.defaultValue();
            final Object value = defaultValue.orElseThrow(() -> new EmptyDefaultValueException(name));
            final ValueReference valueReference = ValueReference.builder().valueType(contentPackParameter.valueType()).value(value).build();
            validatedParameters.put(name, valueReference);
        } else if (providedParameter.valueType() != contentPackParameter.valueType()) {
            throw new InvalidParameterTypeException(contentPackParameter.valueType(), providedParameter.valueType());
        } else {
            validatedParameters.put(name, providedParameter);
        }
    }
    return validatedParameters.build();
}
Also used : InvalidParameterTypeException(org.graylog2.contentpacks.exceptions.InvalidParameterTypeException) ValueType(org.graylog2.contentpacks.model.entities.references.ValueType) InvalidParametersException(org.graylog2.contentpacks.exceptions.InvalidParametersException) EmptyDefaultValueException(org.graylog2.contentpacks.exceptions.EmptyDefaultValueException) ImmutableMap(com.google.common.collect.ImmutableMap) Parameter(org.graylog2.contentpacks.model.parameters.Parameter) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference)

Example 14 with Parameter

use of org.graylog2.contentpacks.model.parameters.Parameter in project graylog2-server by Graylog2.

the class RotationStrategyResource method isEnabledRotationStrategy.

// Limit available rotation strategies to those specified by configuration parameter enabled_index_rotation_strategies
private boolean isEnabledRotationStrategy(String strategyName) {
    final Provider<RotationStrategy> provider = rotationStrategies.get(strategyName);
    if (provider == null) {
        throw new NotFoundException("Couldn't find rotation strategy for given type " + strategyName);
    }
    final RotationStrategy rotationStrategy = provider.get();
    return elasticsearchConfiguration.getEnabledRotationStrategies().contains(rotationStrategy.getStrategyName());
}
Also used : RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy) NotFoundException(javax.ws.rs.NotFoundException)

Aggregations

Test (org.junit.Test)4 ApiOperation (io.swagger.annotations.ApiOperation)3 Timed (com.codahale.metrics.annotation.Timed)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Nullable (javax.annotation.Nullable)2 GET (javax.ws.rs.GET)2 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)2 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 Query (org.graylog.plugins.views.search.Query)2 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)2 AlertSummary (org.graylog2.rest.models.streams.alerts.AlertSummary)2 DateTime (org.joda.time.DateTime)2 JsonAutoDetect (com.fasterxml.jackson.annotation.JsonAutoDetect)1 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1