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"));
}
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();
}
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();
}
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());
}
Aggregations