aditya-gupta36 commented on code in PR #373:
URL: https://github.com/apache/atlas/pull/373#discussion_r2197293780
##########
webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java:
##########
@@ -892,27 +892,48 @@ private void validateSearchParameters(SearchParameters
parameters) throws AtlasB
private void validateEntityFilter(SearchParameters parameters) throws
AtlasBaseException {
FilterCriteria entityFilter = parameters.getEntityFilters();
+ FilterCriteria tagFilter = parameters.getTagFilters();
- if (entityFilter == null) {
- return;
+ if (isNotEmpty(entityFilter) ) {
+ validateNestedCriteria(entityFilter);
}
- if (entityFilter.getCriterion() != null &&
- !entityFilter.getCriterion().isEmpty()) {
- if (entityFilter.getCondition() == null ||
StringUtils.isEmpty(entityFilter.getCondition().toString())) {
+ if (isNotEmpty(tagFilter)) {
+ validateNestedCriteria(tagFilter);
+ }
+ }
+
+ private boolean isNotEmpty(FilterCriteria filter) {
+ if (filter == null) {
+ return false;
+ }
+
+ if (filter.getAttributeName() != null && filter.getOperator() != null
&& filter.getAttributeValue() != null) {
+ return true;
+ }
+
+ return filter.getCriterion() != null &&
!filter.getCriterion().isEmpty();
+ }
+
+ private void validateNestedCriteria(SearchParameters.FilterCriteria
criteria) throws AtlasBaseException {
+ if (criteria.getCriterion() != null &&
Review Comment:
You're right that we could technically skip the boolean check helper method
and call validateNestedCriteria() directly. However, the helper is
intentionally included to guard against edge cases, specifically when clients
send an empty object ({}) instead of null for entityFilters or tagFilters.
In such scenarios, the filter object is non-null but contains no attributes
(i.e., no criterion, no attributeName, etc.). If we skip the check and pass
this directly into validation, it would eventually reach the leaf validation
and throw exceptions due to missing fields like attributeName or operator.
So the helper (checkEmptyFilterCriteria()) is designed to detect and skip
empty filter objects, improving robustness and avoiding false negatives during
validation.
I've also rearranged the code for clarity so the flow is easier to
understand and maintain.
--
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]