You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "EndzeitBegins (via GitHub)" <gi...@apache.org> on 2023/12/01 16:52:15 UTC
[PR] NIFI-12446 Refactor FilterAttribute to align with code conventions [nifi]
EndzeitBegins opened a new pull request, #8098:
URL: https://github.com/apache/nifi/pull/8098
<!-- Licensed to the Apache Software Foundation (ASF) under one or more -->
<!-- contributor license agreements. See the NOTICE file distributed with -->
<!-- this work for additional information regarding copyright ownership. -->
<!-- The ASF licenses this file to You under the Apache License, Version 2.0 -->
<!-- (the "License"); you may not use this file except in compliance with -->
<!-- the License. You may obtain a copy of the License at -->
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
<!-- Unless required by applicable law or agreed to in writing, software -->
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
<!-- See the License for the specific language governing permissions and -->
<!-- limitations under the License. -->
# Summary
Refactors the recently added `FilterAttribute` processor to align with common code practices followed by other processors, before it's included in a first release version.
[NIFI-12446](https://issues.apache.org/jira/browse/NIFI-12446)
Note: This targets the `support/nifi-1.x` branch. The `main` will be receive a PR once the changes have finalized and this PR is merged.
# Tracking
Please complete the following tracking steps prior to pull request creation.
### Issue Tracking
- [x] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
### Pull Request Tracking
- [x] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-12446`
- [x] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-12446`
### Pull Request Formatting
- [x] Pull Request based on current revision of the ~~`main`~~`support/nifi-1.x` branch
- [x] Pull Request refers to a feature branch with one commit containing changes
# Verification
Please indicate the verification steps performed prior to pull request creation.
### Build
- [x] Build completed using `mvn clean install -P contrib-check`
- [x] ~~JDK 21~~JDK 1.8
### Licensing
- [x] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
- [x] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
### Documentation
- [x] Documentation formatting appears as expected in rendered files
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-12446 Refactor FilterAttribute to align with code conventions [nifi]
Posted by "EndzeitBegins (via GitHub)" <gi...@apache.org>.
EndzeitBegins commented on PR #8098:
URL: https://github.com/apache/nifi/pull/8098#issuecomment-1836462075
I've taken a first shot at refactoring the `FilterAttribute` processor.
I'd appreciate if you'd take a look at the changes @mosermw / @exceptionfactory as you both are familiar with the topic.
I've encountered that `allowableValues` actually support passing in an enum class (that implements `DescribedValue`) and that's used by a multitude of existing processors. I thought that is a good match to align the declaration and usage, instead of passing `String` values around. Let me know what you think about that.
Also I noticed that we did a trim where that was not needed, as were trimming all values beforehand:
```Java
.map(String::trim)
.filter(attributeName -> !attributeName.trim().isEmpty())`
```
It seems there is no `not()` function available (at least for Java 1.8). I think the expression without the trim is now readable enough to: `!attributeName.isEmpty()`. Do you agree @exceptionfactory?
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-12446 Refactor FilterAttribute to align with code conventions [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #8098:
URL: https://github.com/apache/nifi/pull/8098#discussion_r1412707184
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FilterAttribute.java:
##########
@@ -257,17 +215,93 @@ private static String getDelimiter() {
private static Pattern getAttributeRegex(ProcessContext context, FlowFile flowFile) {
return Pattern.compile(
- context.getProperty(ATTRIBUTE_REGEX).evaluateAttributeExpressions(flowFile).getValue()
+ context.getProperty(ATTRIBUTE_PATTERN).evaluateAttributeExpressions(flowFile).getValue()
+ );
+ }
+
+ enum FilterMode implements DescribedValue {
+ RETAIN(
+ "Retain",
+ "Retains only the attributes matching the filter, all other attributes are removed."
+ ),
+ REMOVE(
+ "Remove",
+ "Removes the attributes matching the filter, all other attributes are retained."
);
+
+ private final String value;
+ private final String description;
+
+ FilterMode(final String value, final String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
Review Comment:
Instead of returning `value`, this can return `name()` so that the enum value matches the configured property value. That allows FilterMode.valueOf() to work directly with the configured property value.
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FilterAttribute.java:
##########
@@ -257,17 +215,93 @@ private static String getDelimiter() {
private static Pattern getAttributeRegex(ProcessContext context, FlowFile flowFile) {
return Pattern.compile(
- context.getProperty(ATTRIBUTE_REGEX).evaluateAttributeExpressions(flowFile).getValue()
+ context.getProperty(ATTRIBUTE_PATTERN).evaluateAttributeExpressions(flowFile).getValue()
+ );
+ }
+
+ enum FilterMode implements DescribedValue {
+ RETAIN(
+ "Retain",
+ "Retains only the attributes matching the filter, all other attributes are removed."
+ ),
+ REMOVE(
+ "Remove",
+ "Removes the attributes matching the filter, all other attributes are retained."
);
+
+ private final String value;
+ private final String description;
+
+ FilterMode(final String value, final String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return this.value;
+ }
+
+ @Override
+ public String getDescription() {
+ return this.description;
+ }
+
+ public static FilterMode fromValue(final String value) {
+ return FilterAttribute.enumConstantFromValue(FilterMode.class, value);
+ }
}
- private enum FilterMode {
- RETAIN,
- REMOVE,
+ enum MatchingStrategy implements DescribedValue {
+ ENUMERATION(
+ "Enumerate attributes",
+ "Provides a set of attribute keys to filter for, separated by a comma delimiter ','."
+ ),
+ PATTERN(
+ "Use regular expression",
+ "Provides a regular expression to match keys of attributes to filter for."
+ );
+
+ private final String value;
+ private final String description;
+
+ MatchingStrategy(final String value, final String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return this.value;
+ }
+
+ @Override
+ public String getDescription() {
+ return this.description;
+ }
+
+ public static MatchingStrategy fromValue(final String value) {
+ return FilterAttribute.enumConstantFromValue(MatchingStrategy.class, value);
+ }
}
- private enum MatchingStrategy {
- ENUMERATION,
- REGEX,
+ private static <E extends Enum<E> & DescribedValue> E enumConstantFromValue(final Class<E> enumClass, final String value) {
+ for (E enumConstant : enumClass.getEnumConstants()) {
+ if (enumConstant.getValue().equals(value)) {
+ return enumConstant;
+ }
+ }
+
+ throw new IllegalArgumentException(String.format("Unknown %s value [%s]", enumClass.getSimpleName(), value));
}
Review Comment:
As mentioned in relation to the property value, switching `getValue()` to return the enum `name()` should obviated the need for this method.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-12446 Refactor FilterAttribute to align with code conventions [nifi]
Posted by "EndzeitBegins (via GitHub)" <gi...@apache.org>.
EndzeitBegins commented on code in PR #8098:
URL: https://github.com/apache/nifi/pull/8098#discussion_r1412846205
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FilterAttribute.java:
##########
@@ -257,17 +215,93 @@ private static String getDelimiter() {
private static Pattern getAttributeRegex(ProcessContext context, FlowFile flowFile) {
return Pattern.compile(
- context.getProperty(ATTRIBUTE_REGEX).evaluateAttributeExpressions(flowFile).getValue()
+ context.getProperty(ATTRIBUTE_PATTERN).evaluateAttributeExpressions(flowFile).getValue()
+ );
+ }
+
+ enum FilterMode implements DescribedValue {
+ RETAIN(
+ "Retain",
+ "Retains only the attributes matching the filter, all other attributes are removed."
+ ),
+ REMOVE(
+ "Remove",
+ "Removes the attributes matching the filter, all other attributes are retained."
);
+
+ private final String value;
+ private final String description;
+
+ FilterMode(final String value, final String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return this.value;
+ }
+
+ @Override
+ public String getDescription() {
+ return this.description;
+ }
+
+ public static FilterMode fromValue(final String value) {
+ return FilterAttribute.enumConstantFromValue(FilterMode.class, value);
+ }
}
- private enum FilterMode {
- RETAIN,
- REMOVE,
+ enum MatchingStrategy implements DescribedValue {
+ ENUMERATION(
+ "Enumerate attributes",
+ "Provides a set of attribute keys to filter for, separated by a comma delimiter ','."
+ ),
+ PATTERN(
+ "Use regular expression",
+ "Provides a regular expression to match keys of attributes to filter for."
+ );
+
+ private final String value;
+ private final String description;
+
+ MatchingStrategy(final String value, final String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return this.value;
+ }
+
+ @Override
+ public String getDescription() {
+ return this.description;
+ }
+
+ public static MatchingStrategy fromValue(final String value) {
+ return FilterAttribute.enumConstantFromValue(MatchingStrategy.class, value);
+ }
}
- private enum MatchingStrategy {
- ENUMERATION,
- REGEX,
+ private static <E extends Enum<E> & DescribedValue> E enumConstantFromValue(final Class<E> enumClass, final String value) {
+ for (E enumConstant : enumClass.getEnumConstants()) {
+ if (enumConstant.getValue().equals(value)) {
+ return enumConstant;
+ }
+ }
+
+ throw new IllegalArgumentException(String.format("Unknown %s value [%s]", enumClass.getSimpleName(), value));
}
Review Comment:
I was talking about the UI users first and foremost.
I'm somewhat confused though. Due to [this comment](https://github.com/apache/nifi/pull/8064#discussion_r1411195114) I was under the impression one should aim to use the same value for both `value` and `display name` for new implementations, where possible.
I assumed this would be applicable to `AllowableValue`s as well.
Or was that comment directed at `PropertyDescriptor`s exclusively?
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-12446 Refactor FilterAttribute to align with code conventions [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #8098:
URL: https://github.com/apache/nifi/pull/8098#discussion_r1412852050
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FilterAttribute.java:
##########
@@ -257,17 +215,93 @@ private static String getDelimiter() {
private static Pattern getAttributeRegex(ProcessContext context, FlowFile flowFile) {
return Pattern.compile(
- context.getProperty(ATTRIBUTE_REGEX).evaluateAttributeExpressions(flowFile).getValue()
+ context.getProperty(ATTRIBUTE_PATTERN).evaluateAttributeExpressions(flowFile).getValue()
+ );
+ }
+
+ enum FilterMode implements DescribedValue {
+ RETAIN(
+ "Retain",
+ "Retains only the attributes matching the filter, all other attributes are removed."
+ ),
+ REMOVE(
+ "Remove",
+ "Removes the attributes matching the filter, all other attributes are retained."
);
+
+ private final String value;
+ private final String description;
+
+ FilterMode(final String value, final String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return this.value;
+ }
+
+ @Override
+ public String getDescription() {
+ return this.description;
+ }
+
+ public static FilterMode fromValue(final String value) {
+ return FilterAttribute.enumConstantFromValue(FilterMode.class, value);
+ }
}
- private enum FilterMode {
- RETAIN,
- REMOVE,
+ enum MatchingStrategy implements DescribedValue {
+ ENUMERATION(
+ "Enumerate attributes",
+ "Provides a set of attribute keys to filter for, separated by a comma delimiter ','."
+ ),
+ PATTERN(
+ "Use regular expression",
+ "Provides a regular expression to match keys of attributes to filter for."
+ );
+
+ private final String value;
+ private final String description;
+
+ MatchingStrategy(final String value, final String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return this.value;
+ }
+
+ @Override
+ public String getDescription() {
+ return this.description;
+ }
+
+ public static MatchingStrategy fromValue(final String value) {
+ return FilterAttribute.enumConstantFromValue(MatchingStrategy.class, value);
+ }
}
- private enum MatchingStrategy {
- ENUMERATION,
- REGEX,
+ private static <E extends Enum<E> & DescribedValue> E enumConstantFromValue(final Class<E> enumClass, final String value) {
+ for (E enumConstant : enumClass.getEnumConstants()) {
+ if (enumConstant.getValue().equals(value)) {
+ return enumConstant;
+ }
+ }
+
+ throw new IllegalArgumentException(String.format("Unknown %s value [%s]", enumClass.getSimpleName(), value));
}
Review Comment:
Thanks for the reply @EndzeitBegins, and for referencing the comments in relation to the Property Names.
Although this is focusing on the property value, you are right to reference the same question as it relates to user experience in both cases. That's also a good point about the default value.
On further consideration, maintaining parity between the value and display name of the property value seems the most consistent, so your current approach looks good.
Thanks again for the thoughtful interaction on this question. With this covered, I think the changes should be ready to go, so I will follow up soon.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-12446 Refactor FilterAttribute to align with code conventions [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #8098:
URL: https://github.com/apache/nifi/pull/8098#discussion_r1412841911
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FilterAttribute.java:
##########
@@ -257,17 +215,93 @@ private static String getDelimiter() {
private static Pattern getAttributeRegex(ProcessContext context, FlowFile flowFile) {
return Pattern.compile(
- context.getProperty(ATTRIBUTE_REGEX).evaluateAttributeExpressions(flowFile).getValue()
+ context.getProperty(ATTRIBUTE_PATTERN).evaluateAttributeExpressions(flowFile).getValue()
+ );
+ }
+
+ enum FilterMode implements DescribedValue {
+ RETAIN(
+ "Retain",
+ "Retains only the attributes matching the filter, all other attributes are removed."
+ ),
+ REMOVE(
+ "Remove",
+ "Removes the attributes matching the filter, all other attributes are retained."
);
+
+ private final String value;
+ private final String description;
+
+ FilterMode(final String value, final String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return this.value;
+ }
+
+ @Override
+ public String getDescription() {
+ return this.description;
+ }
+
+ public static FilterMode fromValue(final String value) {
+ return FilterAttribute.enumConstantFromValue(FilterMode.class, value);
+ }
}
- private enum FilterMode {
- RETAIN,
- REMOVE,
+ enum MatchingStrategy implements DescribedValue {
+ ENUMERATION(
+ "Enumerate attributes",
+ "Provides a set of attribute keys to filter for, separated by a comma delimiter ','."
+ ),
+ PATTERN(
+ "Use regular expression",
+ "Provides a regular expression to match keys of attributes to filter for."
+ );
+
+ private final String value;
+ private final String description;
+
+ MatchingStrategy(final String value, final String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return this.value;
+ }
+
+ @Override
+ public String getDescription() {
+ return this.description;
+ }
+
+ public static MatchingStrategy fromValue(final String value) {
+ return FilterAttribute.enumConstantFromValue(MatchingStrategy.class, value);
+ }
}
- private enum MatchingStrategy {
- ENUMERATION,
- REGEX,
+ private static <E extends Enum<E> & DescribedValue> E enumConstantFromValue(final Class<E> enumClass, final String value) {
+ for (E enumConstant : enumClass.getEnumConstants()) {
+ if (enumConstant.getValue().equals(value)) {
+ return enumConstant;
+ }
+ }
+
+ throw new IllegalArgumentException(String.format("Unknown %s value [%s]", enumClass.getSimpleName(), value));
}
Review Comment:
The changes proposed for NIFI-12452 look useful, so thanks for working on those improvements.
In either case, the question comes down to differentiating between the value itself and the display name. In this scenario, the value could match the enum, such as `RETAIN`, but the display name could be `Retain` for presentation purposes. When you refer to the user experience, are you referencing the UI, or programmatic interaction with the REST API?
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-12446 Refactor FilterAttribute to align with code conventions [nifi]
Posted by "EndzeitBegins (via GitHub)" <gi...@apache.org>.
EndzeitBegins commented on code in PR #8098:
URL: https://github.com/apache/nifi/pull/8098#discussion_r1412846205
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FilterAttribute.java:
##########
@@ -257,17 +215,93 @@ private static String getDelimiter() {
private static Pattern getAttributeRegex(ProcessContext context, FlowFile flowFile) {
return Pattern.compile(
- context.getProperty(ATTRIBUTE_REGEX).evaluateAttributeExpressions(flowFile).getValue()
+ context.getProperty(ATTRIBUTE_PATTERN).evaluateAttributeExpressions(flowFile).getValue()
+ );
+ }
+
+ enum FilterMode implements DescribedValue {
+ RETAIN(
+ "Retain",
+ "Retains only the attributes matching the filter, all other attributes are removed."
+ ),
+ REMOVE(
+ "Remove",
+ "Removes the attributes matching the filter, all other attributes are retained."
);
+
+ private final String value;
+ private final String description;
+
+ FilterMode(final String value, final String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return this.value;
+ }
+
+ @Override
+ public String getDescription() {
+ return this.description;
+ }
+
+ public static FilterMode fromValue(final String value) {
+ return FilterAttribute.enumConstantFromValue(FilterMode.class, value);
+ }
}
- private enum FilterMode {
- RETAIN,
- REMOVE,
+ enum MatchingStrategy implements DescribedValue {
+ ENUMERATION(
+ "Enumerate attributes",
+ "Provides a set of attribute keys to filter for, separated by a comma delimiter ','."
+ ),
+ PATTERN(
+ "Use regular expression",
+ "Provides a regular expression to match keys of attributes to filter for."
+ );
+
+ private final String value;
+ private final String description;
+
+ MatchingStrategy(final String value, final String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return this.value;
+ }
+
+ @Override
+ public String getDescription() {
+ return this.description;
+ }
+
+ public static MatchingStrategy fromValue(final String value) {
+ return FilterAttribute.enumConstantFromValue(MatchingStrategy.class, value);
+ }
}
- private enum MatchingStrategy {
- ENUMERATION,
- REGEX,
+ private static <E extends Enum<E> & DescribedValue> E enumConstantFromValue(final Class<E> enumClass, final String value) {
+ for (E enumConstant : enumClass.getEnumConstants()) {
+ if (enumConstant.getValue().equals(value)) {
+ return enumConstant;
+ }
+ }
+
+ throw new IllegalArgumentException(String.format("Unknown %s value [%s]", enumClass.getSimpleName(), value));
}
Review Comment:
I was talking about the UI users first and foremost.
I'm somewhat confused though. Due to [this comment](https://github.com/apache/nifi/pull/8064#discussion_r1411195114) I was under the impression one should aim to use the same value for both `value` and `display name` for new implementations, where possible.
I assumed this would be applicable to `AllowableValue`s as well.
Or was that comment directed at `PropertyDescriptor`s exclusively?
Additionally @mosermw pointed out in [the Jira ticket](https://issues.apache.org/jira/browse/NIFI-12446), the UI shows default value `value` but the options in the drop-down are the `display name`s. Thus, if both are not the same, the default value is not an selectable option to the user. I don't think this will be an issue between `RETAIN` and `Retain` but might be more confusing in other cases.
I'm fine with using the enum's `name()`, however this contradicts with the comment in the Jira ticket.
Not sure what's the better approach now.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-12446 Refactor FilterAttribute to align with code conventions [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory closed pull request #8098: NIFI-12446 Refactor FilterAttribute to align with code conventions
URL: https://github.com/apache/nifi/pull/8098
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-12446 Refactor FilterAttribute to align with code conventions [nifi]
Posted by "EndzeitBegins (via GitHub)" <gi...@apache.org>.
EndzeitBegins commented on code in PR #8098:
URL: https://github.com/apache/nifi/pull/8098#discussion_r1412738209
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FilterAttribute.java:
##########
@@ -257,17 +215,93 @@ private static String getDelimiter() {
private static Pattern getAttributeRegex(ProcessContext context, FlowFile flowFile) {
return Pattern.compile(
- context.getProperty(ATTRIBUTE_REGEX).evaluateAttributeExpressions(flowFile).getValue()
+ context.getProperty(ATTRIBUTE_PATTERN).evaluateAttributeExpressions(flowFile).getValue()
+ );
+ }
+
+ enum FilterMode implements DescribedValue {
+ RETAIN(
+ "Retain",
+ "Retains only the attributes matching the filter, all other attributes are removed."
+ ),
+ REMOVE(
+ "Remove",
+ "Removes the attributes matching the filter, all other attributes are retained."
);
+
+ private final String value;
+ private final String description;
+
+ FilterMode(final String value, final String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return this.value;
+ }
+
+ @Override
+ public String getDescription() {
+ return this.description;
+ }
+
+ public static FilterMode fromValue(final String value) {
+ return FilterAttribute.enumConstantFromValue(FilterMode.class, value);
+ }
}
- private enum FilterMode {
- RETAIN,
- REMOVE,
+ enum MatchingStrategy implements DescribedValue {
+ ENUMERATION(
+ "Enumerate attributes",
+ "Provides a set of attribute keys to filter for, separated by a comma delimiter ','."
+ ),
+ PATTERN(
+ "Use regular expression",
+ "Provides a regular expression to match keys of attributes to filter for."
+ );
+
+ private final String value;
+ private final String description;
+
+ MatchingStrategy(final String value, final String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return this.value;
+ }
+
+ @Override
+ public String getDescription() {
+ return this.description;
+ }
+
+ public static MatchingStrategy fromValue(final String value) {
+ return FilterAttribute.enumConstantFromValue(MatchingStrategy.class, value);
+ }
}
- private enum MatchingStrategy {
- ENUMERATION,
- REGEX,
+ private static <E extends Enum<E> & DescribedValue> E enumConstantFromValue(final Class<E> enumClass, final String value) {
+ for (E enumConstant : enumClass.getEnumConstants()) {
+ if (enumConstant.getValue().equals(value)) {
+ return enumConstant;
+ }
+ }
+
+ throw new IllegalArgumentException(String.format("Unknown %s value [%s]", enumClass.getSimpleName(), value));
}
Review Comment:
I thought about this as well. However this prevents providing more readable names to the users of the processor.
As far as I know best practice of naming enum entries is using all UPPERCASE.
Thus, all properties using allowableValues based on an enum would be restricted to be in uppercase. I'm not sure if that's a favourable user experience, additionally it somewhat reveals implementation details.
In case NIFI-12452 / #8102 gets accepted, this method would be provided "globally", reducing the complexity to implement something like this time and time again.
Scanning through the code I found multiple places where a method similar to this is used. I was hoping NIFI-12452 could be the basis to simplify and align the implementation at these places.
What are you thoughts on this? Or do you think it's not worth "only" to support more readable names?
In case NIFI-12452 is agreed upon, I would like to backport it into the 1.x line as well and refactor this PR to base on those changes.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-12446 Refactor FilterAttribute to align with code conventions [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on PR #8098:
URL: https://github.com/apache/nifi/pull/8098#issuecomment-1839991223
Merged in https://github.com/apache/nifi/commit/c565e08ccca6c1fce17b1d3de49d7a160cfbee38
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org