mirror of
https://github.com/apache/nifi.git
synced 2025-02-28 22:49:10 +00:00
NIFI-11483 Correctly use DescribedValue for JsonQueryElasticsearch
This closes #7195 Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
parent
ffaf81ec46
commit
99b2412ad4
@ -65,7 +65,7 @@ public abstract class AbstractJsonQueryElasticsearch<Q extends JsonQueryParamete
|
||||
.name("el-rest-split-up-hits")
|
||||
.displayName("Search Results Split")
|
||||
.description("Output a flowfile containing all hits or one flowfile for each individual hit.")
|
||||
.allowableValues(ResultOutputStrategy.PER_RESPONSE.getValue(), ResultOutputStrategy.PER_HIT.getValue())
|
||||
.allowableValues(ResultOutputStrategy.getNonPaginatedResponseOutputStrategies())
|
||||
.defaultValue(ResultOutputStrategy.PER_RESPONSE.getValue())
|
||||
.required(true)
|
||||
.expressionLanguageSupported(ExpressionLanguageScope.NONE)
|
||||
@ -84,7 +84,7 @@ public abstract class AbstractJsonQueryElasticsearch<Q extends JsonQueryParamete
|
||||
.name("el-rest-split-up-aggregations")
|
||||
.displayName("Aggregation Results Split")
|
||||
.description("Output a flowfile containing all aggregations or one flowfile for each individual aggregation.")
|
||||
.allowableValues(ResultOutputStrategy.PER_RESPONSE.getValue(), ResultOutputStrategy.PER_HIT.getValue())
|
||||
.allowableValues(ResultOutputStrategy.getNonPaginatedResponseOutputStrategies())
|
||||
.defaultValue(ResultOutputStrategy.PER_RESPONSE.getValue())
|
||||
.required(true)
|
||||
.expressionLanguageSupported(ExpressionLanguageScope.NONE)
|
||||
|
@ -20,6 +20,7 @@ package org.apache.nifi.processors.elasticsearch.api;
|
||||
import org.apache.nifi.components.DescribedValue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
|
||||
public enum ResultOutputStrategy implements DescribedValue {
|
||||
PER_HIT("splitUp-yes", "Flowfile per hit."),
|
||||
@ -52,6 +53,10 @@ public enum ResultOutputStrategy implements DescribedValue {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static EnumSet<ResultOutputStrategy> getNonPaginatedResponseOutputStrategies() {
|
||||
return EnumSet.of(PER_RESPONSE, PER_HIT);
|
||||
}
|
||||
|
||||
public static ResultOutputStrategy fromValue(final String value) {
|
||||
return Arrays.stream(ResultOutputStrategy.values()).filter(v -> v.getValue().equals(value)).findFirst()
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format("Unknown value %s", value)));
|
||||
|
@ -21,14 +21,16 @@ import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import org.apache.nifi.components.state.Scope
|
||||
import org.apache.nifi.flowfile.FlowFile
|
||||
import org.apache.nifi.processors.elasticsearch.api.AggregationResultsFormat
|
||||
import org.apache.nifi.processors.elasticsearch.api.SearchResultsFormat
|
||||
import org.apache.nifi.processors.elasticsearch.api.ResultOutputStrategy
|
||||
import org.apache.nifi.processors.elasticsearch.api.SearchResultsFormat
|
||||
import org.apache.nifi.provenance.ProvenanceEventType
|
||||
import org.apache.nifi.util.MockFlowFile
|
||||
import org.apache.nifi.util.TestRunner
|
||||
import org.apache.nifi.util.TestRunners
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
import java.util.stream.Collectors
|
||||
|
||||
import static groovy.json.JsonOutput.prettyPrint
|
||||
import static groovy.json.JsonOutput.toJson
|
||||
import static org.hamcrest.CoreMatchers.equalTo
|
||||
@ -95,9 +97,12 @@ abstract class AbstractJsonQueryElasticsearchTest<P extends AbstractJsonQueryEla
|
||||
runner.setProperty(AbstractJsonQueryElasticsearch.SEARCH_RESULTS_SPLIT, "not-enum2")
|
||||
runner.setProperty(AbstractJsonQueryElasticsearch.OUTPUT_NO_HITS, "not-boolean")
|
||||
|
||||
final String nonPaginatedResultOutputStrategies = ResultOutputStrategy.getNonPaginatedResponseOutputStrategies()
|
||||
.stream().map(r -> r.getValue())
|
||||
.collect(Collectors.joining(", "))
|
||||
final String expectedAllowedSplitHits = processor instanceof AbstractPaginatedJsonQueryElasticsearch
|
||||
? ResultOutputStrategy.values().collect {r -> r.getValue()}.join(", ")
|
||||
: [ResultOutputStrategy.PER_RESPONSE.getValue(), ResultOutputStrategy.PER_HIT.getValue()].join(", ")
|
||||
: nonPaginatedResultOutputStrategies
|
||||
|
||||
final AssertionError assertionError = assertThrows(AssertionError.class, runner.&run)
|
||||
assertThat(assertionError.getMessage(), equalTo(String.format("Processor has 8 validation failures:\n" +
|
||||
@ -115,7 +120,7 @@ abstract class AbstractJsonQueryElasticsearchTest<P extends AbstractJsonQueryEla
|
||||
AbstractJsonQueryElasticsearch.TYPE.getName(), AbstractJsonQueryElasticsearch.TYPE.getName(),
|
||||
AbstractJsonQueryElasticsearch.CLIENT_SERVICE.getDisplayName(),
|
||||
AbstractJsonQueryElasticsearch.SEARCH_RESULTS_SPLIT.getName(), expectedAllowedSplitHits,
|
||||
AbstractJsonQueryElasticsearch.AGGREGATION_RESULTS_SPLIT.getName(), [ResultOutputStrategy.PER_RESPONSE.getValue(), ResultOutputStrategy.PER_HIT.getValue()].join(", "),
|
||||
AbstractJsonQueryElasticsearch.AGGREGATION_RESULTS_SPLIT.getName(), nonPaginatedResultOutputStrategies,
|
||||
AbstractJsonQueryElasticsearch.OUTPUT_NO_HITS.getName(),
|
||||
AbstractJsonQueryElasticsearch.CLIENT_SERVICE.getDisplayName()
|
||||
)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user