mirror of https://github.com/apache/nifi.git
NIFI-12214 This closes #7869. ConsumeElasticsearch Query Builder properties do not dependOn the Query Definition Style
Signed-off-by: Joseph Witt <joewitt@apache.org>
This commit is contained in:
parent
f2927525f3
commit
584b3fc165
|
@ -413,6 +413,16 @@ public final class PropertyDescriptor implements Comparable<PropertyDescriptor>
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all Allowable Values from this Property
|
||||
*
|
||||
* @return the builder
|
||||
*/
|
||||
public Builder clearAllowableValues() {
|
||||
this.allowableValues = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Allowable Values for this Property
|
||||
*
|
||||
|
@ -455,6 +465,16 @@ public final class PropertyDescriptor implements Comparable<PropertyDescriptor>
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all Validators from this Property
|
||||
*
|
||||
* @return the builder
|
||||
*/
|
||||
public Builder clearValidators() {
|
||||
validators.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies that this property provides the identifier of a Controller
|
||||
* Service that implements the given interface
|
||||
|
@ -607,6 +627,16 @@ public final class PropertyDescriptor implements Comparable<PropertyDescriptor>
|
|||
return dependsOn(property, dependentValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all Dependencies from this Property
|
||||
*
|
||||
* @return the builder
|
||||
*/
|
||||
public Builder clearDependsOn() {
|
||||
this.dependencies = new HashSet<>();
|
||||
return this;
|
||||
}
|
||||
|
||||
private AllowableValue toAllowableValue(DescribedValue describedValue) {
|
||||
return new AllowableValue(describedValue.getValue(), describedValue.getDisplayName(), describedValue.getDescription());
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.util.stream.Stream;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
|
@ -188,4 +189,36 @@ public class TestPropertyDescriptor {
|
|||
// Test the literal value 'target'
|
||||
assertTrue(withElNotAllowed.validate("target", validationContext).isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClearingValues() {
|
||||
final PropertyDescriptor dep1 = new PropertyDescriptor.Builder()
|
||||
.name("dep1")
|
||||
.allowableValues("delVal1")
|
||||
.build();
|
||||
|
||||
final PropertyDescriptor pd1 = new PropertyDescriptor.Builder()
|
||||
.name("test")
|
||||
.addValidator(Validator.VALID)
|
||||
.allowableValues("val1")
|
||||
.dependsOn(dep1, "depVal1")
|
||||
.build();
|
||||
|
||||
final PropertyDescriptor pd2 = new PropertyDescriptor.Builder()
|
||||
.fromPropertyDescriptor(pd1)
|
||||
.clearValidators()
|
||||
.clearAllowableValues()
|
||||
.clearDependsOn()
|
||||
.build();
|
||||
|
||||
assertEquals("test", pd1.getName());
|
||||
assertFalse(pd1.getValidators().isEmpty());
|
||||
assertFalse(pd1.getDependencies().isEmpty());
|
||||
assertNotNull(pd1.getAllowableValues());
|
||||
|
||||
assertEquals("test", pd2.getName());
|
||||
assertTrue(pd2.getValidators().isEmpty());
|
||||
assertTrue(pd2.getDependencies().isEmpty());
|
||||
assertNull(pd2.getAllowableValues());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,6 +85,31 @@ import java.util.stream.Collectors;
|
|||
public class ConsumeElasticsearch extends SearchElasticsearch {
|
||||
static final String STATE_RANGE_VALUE = "trackingRangeValue";
|
||||
|
||||
public static final PropertyDescriptor SIZE = new PropertyDescriptor.Builder()
|
||||
.fromPropertyDescriptor(ElasticsearchRestProcessor.SIZE)
|
||||
.clearDependsOn() // always show the Query Builder properties for ConsumeElasticsearch
|
||||
.build();
|
||||
|
||||
public static final PropertyDescriptor AGGREGATIONS = new PropertyDescriptor.Builder()
|
||||
.fromPropertyDescriptor(ElasticsearchRestProcessor.AGGREGATIONS)
|
||||
.clearDependsOn() // always show the Query Builder properties for ConsumeElasticsearch
|
||||
.build();
|
||||
|
||||
public static final PropertyDescriptor SORT = new PropertyDescriptor.Builder()
|
||||
.fromPropertyDescriptor(ElasticsearchRestProcessor.SORT)
|
||||
.clearDependsOn() // always show the Query Builder properties for ConsumeElasticsearch
|
||||
.build();
|
||||
|
||||
public static final PropertyDescriptor FIELDS = new PropertyDescriptor.Builder()
|
||||
.fromPropertyDescriptor(ElasticsearchRestProcessor.FIELDS)
|
||||
.clearDependsOn() // always show the Query Builder properties for ConsumeElasticsearch
|
||||
.build();
|
||||
|
||||
public static final PropertyDescriptor SCRIPT_FIELDS = new PropertyDescriptor.Builder()
|
||||
.fromPropertyDescriptor(ElasticsearchRestProcessor.SCRIPT_FIELDS)
|
||||
.clearDependsOn() // always show the Query Builder properties for ConsumeElasticsearch
|
||||
.build();
|
||||
|
||||
public static final PropertyDescriptor RANGE_FIELD = new PropertyDescriptor.Builder()
|
||||
.name("es-rest-range-field")
|
||||
.displayName("Range Query Field")
|
||||
|
@ -163,6 +188,13 @@ public class ConsumeElasticsearch extends SearchElasticsearch {
|
|||
.filter(pd -> !QUERY.equals(pd) && !QUERY_CLAUSE.equals(pd) && !QUERY_DEFINITION_STYLE.equals(pd))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
// replace Query Builder properties with updated version without the property dependencies that are invalid for ConsumeElasticsearch
|
||||
descriptors.set(descriptors.indexOf(ElasticsearchRestProcessor.SIZE), ConsumeElasticsearch.SIZE);
|
||||
descriptors.set(descriptors.indexOf(ElasticsearchRestProcessor.AGGREGATIONS), ConsumeElasticsearch.AGGREGATIONS);
|
||||
descriptors.set(descriptors.indexOf(ElasticsearchRestProcessor.SORT), ConsumeElasticsearch.SORT);
|
||||
descriptors.set(descriptors.indexOf(ElasticsearchRestProcessor.FIELDS), ConsumeElasticsearch.FIELDS);
|
||||
descriptors.set(descriptors.indexOf(ElasticsearchRestProcessor.SCRIPT_FIELDS), ConsumeElasticsearch.SCRIPT_FIELDS);
|
||||
|
||||
propertyDescriptors = Collections.unmodifiableList(descriptors);
|
||||
}
|
||||
|
||||
|
|
|
@ -175,7 +175,7 @@ public class ConsumeElasticsearchTest extends SearchElasticsearchTest {
|
|||
@Test
|
||||
void testNoSorts() throws IOException {
|
||||
final TestRunner runner = createRunner(false);
|
||||
runner.removeProperty(ElasticsearchRestProcessor.SORT);
|
||||
runner.removeProperty(ConsumeElasticsearch.SORT);
|
||||
|
||||
final Map<String, Object> query = new HashMap<>();
|
||||
((ConsumeElasticsearch) runner.getProcessor()).addSortClause(query, null, runner.getProcessContext());
|
||||
|
@ -186,7 +186,7 @@ public class ConsumeElasticsearchTest extends SearchElasticsearchTest {
|
|||
@Test
|
||||
void testSingleAdditionalSort() throws IOException {
|
||||
final TestRunner runner = createRunner(false);
|
||||
runner.setProperty(ElasticsearchRestProcessor.SORT, "{\"foo\":\"bar\"}");
|
||||
runner.setProperty(ConsumeElasticsearch.SORT, "{\"foo\":\"bar\"}");
|
||||
|
||||
final Map<String, Object> query = new HashMap<>();
|
||||
((ConsumeElasticsearch) runner.getProcessor()).addSortClause(query, null, runner.getProcessContext());
|
||||
|
@ -200,7 +200,7 @@ public class ConsumeElasticsearchTest extends SearchElasticsearchTest {
|
|||
@Test
|
||||
void testMultipleAdditionalSorts() throws IOException {
|
||||
final TestRunner runner = createRunner(false);
|
||||
runner.setProperty(ElasticsearchRestProcessor.SORT, "[{\"foo\":\"bar\"},{\"baz\":\"biz\"}]");
|
||||
runner.setProperty(ConsumeElasticsearch.SORT, "[{\"foo\":\"bar\"},{\"baz\":\"biz\"}]");
|
||||
|
||||
final Map<String, Object> query = new HashMap<>();
|
||||
((ConsumeElasticsearch) runner.getProcessor()).addSortClause(query, null, runner.getProcessContext());
|
||||
|
@ -216,7 +216,7 @@ public class ConsumeElasticsearchTest extends SearchElasticsearchTest {
|
|||
void testTrackingFieldSortAlreadyPresent() throws IOException {
|
||||
final TestRunner runner = createRunner(false);
|
||||
final String existingRangeFieldSort = String.format("{\"%s\":\"bar\"}", RANGE_FIELD_NAME);
|
||||
runner.setProperty(ElasticsearchRestProcessor.SORT, existingRangeFieldSort);
|
||||
runner.setProperty(ConsumeElasticsearch.SORT, existingRangeFieldSort);
|
||||
|
||||
final Map<String, Object> query = new HashMap<>();
|
||||
((ConsumeElasticsearch) runner.getProcessor()).addSortClause(query, null, runner.getProcessContext());
|
||||
|
|
|
@ -52,7 +52,7 @@ import static org.apache.http.auth.AuthScope.ANY;
|
|||
public abstract class AbstractElasticsearchITBase {
|
||||
// default Elasticsearch version should (ideally) match that in the nifi-elasticsearch-bundle#pom.xml for the integration-tests profile
|
||||
protected static final DockerImageName IMAGE = DockerImageName
|
||||
.parse(System.getProperty("elasticsearch.docker.image", "docker.elastic.co/elasticsearch/elasticsearch:8.10.2"));
|
||||
.parse(System.getProperty("elasticsearch.docker.image", "docker.elastic.co/elasticsearch/elasticsearch:8.10.3"));
|
||||
protected static final String ELASTIC_USER_PASSWORD = System.getProperty("elasticsearch.elastic_user.password", RandomStringUtils.randomAlphanumeric(10, 20));
|
||||
private static final int PORT = 9200;
|
||||
protected static final ElasticsearchContainer ELASTICSEARCH_CONTAINER = new ElasticsearchContainer(IMAGE)
|
||||
|
|
|
@ -94,7 +94,7 @@ language governing permissions and limitations under the License. -->
|
|||
</activation>
|
||||
<properties>
|
||||
<!-- also update the default Elasticsearch version in nifi-elasticsearch-test-utils#src/main/java/org/apache/nifi/elasticsearch/integration/AbstractElasticsearchITBase.java-->
|
||||
<elasticsearch_docker_image>8.10.2</elasticsearch_docker_image>
|
||||
<elasticsearch_docker_image>8.10.3</elasticsearch_docker_image>
|
||||
<elasticsearch.elastic.password>s3cret</elasticsearch.elastic.password>
|
||||
</properties>
|
||||
<build>
|
||||
|
@ -125,7 +125,7 @@ language governing permissions and limitations under the License. -->
|
|||
<profile>
|
||||
<id>elasticsearch7</id>
|
||||
<properties>
|
||||
<elasticsearch_docker_image>7.17.13</elasticsearch_docker_image>
|
||||
<elasticsearch_docker_image>7.17.14</elasticsearch_docker_image>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
|
Loading…
Reference in New Issue