You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2017/09/14 20:45:54 UTC
atlas git commit: ATLAS-2028: invalid attributes in basic-search
request should fail with status code 400
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 <ma...@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 <ap...@apache.org>
Authored: Wed Sep 13 22:03:13 2017 -0700
Committer: Madhan Neethiraj <ma...@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()));