atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject atlas git commit: ATLAS-2028: invalid attributes in basic-search request should fail with status code 400
Date Thu, 14 Sep 2017 20:45:54 GMT
Repository: atlas
Updated Branches:
  refs/heads/master d1c585a22 -> 6e5618520


ATLAS-2028: invalid attributes in basic-search request should fail with status code 400

Signed-off-by: Madhan Neethiraj <madhan@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/6e561852
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/6e561852
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/6e561852

Branch: refs/heads/master
Commit: 6e56185209297e20169520f076f9eb3581abad89
Parents: d1c585a
Author: apoorvnaik <apoorvnaik@apache.org>
Authored: Wed Sep 13 22:03:13 2017 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Thu Sep 14 13:45:07 2017 -0700

----------------------------------------------------------------------
 .../apache/atlas/discovery/SearchContext.java   | 25 ++++++++++++++++++++
 1 file changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/6e561852/repository/src/main/java/org/apache/atlas/discovery/SearchContext.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/discovery/SearchContext.java b/repository/src/main/java/org/apache/atlas/discovery/SearchContext.java
index d42078a..91ee1a5 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/SearchContext.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/SearchContext.java
@@ -25,6 +25,7 @@ import org.apache.atlas.model.discovery.SearchParameters.FilterCriteria;
 import org.apache.atlas.repository.graphdb.AtlasGraph;
 import org.apache.atlas.type.AtlasClassificationType;
 import org.apache.atlas.type.AtlasEntityType;
+import org.apache.atlas.type.AtlasStructType;
 import org.apache.atlas.type.AtlasTypeRegistry;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -67,6 +68,12 @@ public class SearchContext {
             throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_CLASSIFICATION, searchParameters.getClassification());
         }
 
+        // Invalid attributes will raise an exception with 400 error code
+        validateAttributes(entityType, searchParameters.getEntityFilters());
+
+        // Invalid attributes will raise an exception with 400 error code
+        validateAttributes(classificationType, searchParameters.getTagFilters());
+
         if (needFullTextProcessor()) {
             addProcessor(new FullTextSearchProcessor(this));
         }
@@ -131,6 +138,24 @@ public class SearchContext {
         return entityType != null;
     }
 
+    private void validateAttributes(final AtlasStructType structType, final FilterCriteria
filterCriteria) throws AtlasBaseException {
+        if (filterCriteria != null) {
+            FilterCriteria.Condition condition = filterCriteria.getCondition();
+
+            if (condition != null && CollectionUtils.isNotEmpty(filterCriteria.getCriterion()))
{
+                for (FilterCriteria criteria : filterCriteria.getCriterion()) {
+                    validateAttributes(structType, criteria);
+                }
+            } else {
+                String attributeName = filterCriteria.getAttributeName();
+
+                if (StringUtils.isNotEmpty(attributeName) && structType.getAttributeType(attributeName)
== null) {
+                    throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attributeName,
structType.getTypeName());
+                }
+            }
+        }
+    }
+
     private boolean hasAttributeFilter(FilterCriteria filterCriteria) {
         return filterCriteria != null &&
                (CollectionUtils.isNotEmpty(filterCriteria.getCriterion()) || StringUtils.isNotEmpty(filterCriteria.getAttributeName()));


Mime
View raw message