ChrisSamo632 commented on code in PR #9806:
URL: https://github.com/apache/nifi/pull/9806#discussion_r2031824343
##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/SearchElasticsearch.java:
##########
@@ -122,17 +138,34 @@ Scope getStateScope() {
return Scope.LOCAL;
}
+ @Override
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ if (context.getProperty(RESTART_ON_FINISH).asBoolean() != null) {
Review Comment:
```suggestion
if (context.getProperty(RESTART_ON_FINISH) != null) {
```
No need for the type conversion for a null check
##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/SearchElasticsearch.java:
##########
@@ -88,26 +90,40 @@ public class SearchElasticsearch extends
AbstractPaginatedJsonQueryElasticsearch
static final String STATE_PAGE_EXPIRATION_TIMESTAMP =
"pageExpirationTimestamp";
static final String STATE_PAGE_COUNT = "pageCount";
static final String STATE_HIT_COUNT = "hitCount";
+ static final String STATE_FINISHED = "finished";
static final PropertyDescriptor QUERY = new
PropertyDescriptor.Builder().fromPropertyDescriptor(ElasticsearchRestProcessor.QUERY)
.description("A query in JSON syntax, not Lucene syntax. Ex:
{\"query\":{\"match\":{\"somefield\":\"somevalue\"}}}. " +
"If the query is empty, a default JSON Object will be
used, which will result in a \"match_all\" query in Elasticsearch.")
.build();
- private static final Set<Relationship> relationships = Set.of(REL_HITS,
REL_AGGREGATIONS);
+ static final PropertyDescriptor RESTART_ON_FINISH = new
PropertyDescriptor.Builder()
+ .name("restart-on-finish")
+ .displayName("Restart On Finish?")
+ .description("Should the processor start from the beginning when
the query finishes?")
Review Comment:
```suggestion
.description("Whether the should processor start another search
with the same query once a paginated search has completed.")
```
Property Descriptors aren't usually written as questions
##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/SearchElasticsearch.java:
##########
@@ -88,26 +90,40 @@ public class SearchElasticsearch extends
AbstractPaginatedJsonQueryElasticsearch
static final String STATE_PAGE_EXPIRATION_TIMESTAMP =
"pageExpirationTimestamp";
static final String STATE_PAGE_COUNT = "pageCount";
static final String STATE_HIT_COUNT = "hitCount";
+ static final String STATE_FINISHED = "finished";
static final PropertyDescriptor QUERY = new
PropertyDescriptor.Builder().fromPropertyDescriptor(ElasticsearchRestProcessor.QUERY)
.description("A query in JSON syntax, not Lucene syntax. Ex:
{\"query\":{\"match\":{\"somefield\":\"somevalue\"}}}. " +
"If the query is empty, a default JSON Object will be
used, which will result in a \"match_all\" query in Elasticsearch.")
.build();
- private static final Set<Relationship> relationships = Set.of(REL_HITS,
REL_AGGREGATIONS);
+ static final PropertyDescriptor RESTART_ON_FINISH = new
PropertyDescriptor.Builder()
+ .name("restart-on-finish")
+ .displayName("Restart On Finish?")
+ .description("Should the processor start from the beginning when
the query finishes?")
+ .addValidator(StandardValidators.BOOLEAN_VALIDATOR)
+ .allowableValues(Boolean.TRUE.toString(), Boolean.FALSE.toString())
+ .defaultValue(Boolean.TRUE.toString()) // maintain existing
behavior
Review Comment:
```suggestion
.defaultValue(Boolean.TRUE.toString())
```
While this comment is helpful in terms of a PR, I don't think it's useful
for the future, the field setting is self-ecident
##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/SearchElasticsearch.java:
##########
@@ -122,17 +138,34 @@ Scope getStateScope() {
return Scope.LOCAL;
}
+ @Override
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ if (context.getProperty(RESTART_ON_FINISH).asBoolean() != null) {
+ this.restartOnFinish =
context.getProperty(RESTART_ON_FINISH).asBoolean();
+ }
+ }
+
@Override
PaginatedJsonQueryParameters buildJsonQueryParameters(final FlowFile
input, final ProcessContext context, final ProcessSession session) throws
IOException {
+ final StateMap stateMap =
context.getStateManager().getState(getStateScope());
+
+ final boolean finished = stateMap.get(STATE_FINISHED) == null ? false
: Boolean.parseBoolean(stateMap.get(STATE_FINISHED));
Review Comment:
```suggestion
final boolean finished = stateMap.get(STATE_FINISHED) != null &&
Boolean.parseBoolean(stateMap.get(STATE_FINISHED))
```
Boolean logic can be simplified
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]