This is an automated email from the ASF dual-hosted git repository.
nixon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/master by this push:
new f690755 ATLAS-3880 : BasicSearch: Multiple type/tag: Log invalid and
allow searching valid type/tag names
f690755 is described below
commit f690755f79f9696e3214b9a3f158977b3bd5f4a7
Author: Pinal Shah <[email protected]>
AuthorDate: Tue Jul 7 19:03:40 2020 +0530
ATLAS-3880 : BasicSearch: Multiple type/tag: Log invalid and allow
searching valid type/tag names
Signed-off-by: nixonrodrigues <[email protected]>
---
.../org/apache/atlas/discovery/SearchContext.java | 42 +++++++++++-----------
.../atlas/discovery/EntitySearchProcessorTest.java | 2 +-
.../org/apache/atlas/web/rest/DiscoveryREST.java | 11 ++++--
3 files changed, 32 insertions(+), 23 deletions(-)
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 04e8218..dd24a8c 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/SearchContext.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/SearchContext.java
@@ -359,7 +359,7 @@ public class SearchContext {
Set<String> classificationNames = new HashSet<>();
if (StringUtils.isNotEmpty(classification)) {
- String[] types =
classification.split(TYPENAME_DELIMITER);
+ String[] types = classification.split(TYPENAME_DELIMITER);
Set<String> names = new HashSet<>(Arrays.asList(types));
names.forEach(name -> {
@@ -370,11 +370,13 @@ public class SearchContext {
});
// Validate if the classification exists
- if (CollectionUtils.isEmpty(classificationNames) ||
classificationNames.size() != names.size()) {
- if (CollectionUtils.isNotEmpty(classificationNames)) {
- names.removeAll(classificationNames);
- }
- throw new
AtlasBaseException(AtlasErrorCode.UNKNOWN_CLASSIFICATION,
String.join(TYPENAME_DELIMITER, names));
+ if (CollectionUtils.isEmpty(classificationNames)) {
+ throw new
AtlasBaseException(AtlasErrorCode.UNKNOWN_CLASSIFICATION, classification);
+
+ } else if (classificationNames.size() != names.size()) {
+ names.removeAll(classificationNames);
+
+ LOG.info("Could not search for {} , invalid classifications",
String.join(TYPENAME_DELIMITER, names));
}
}
@@ -398,24 +400,24 @@ public class SearchContext {
getEntityType(n)).filter(Objects::nonNull).collect(Collectors.toSet());
// Validate if the type name is incorrect
- if (CollectionUtils.isEmpty(entityTypes) || entityTypes.size() !=
typeNames.size()) {
- if (CollectionUtils.isNotEmpty(entityTypes)) {
- Set<String> validEntityTypes = new HashSet<>();
- for (AtlasEntityType entityType : entityTypes) {
- String name = entityType.getTypeName();
- if (name.equals(MATCH_ALL_ENTITY_TYPES.getTypeName()))
{
- validEntityTypes.add(ALL_ENTITY_TYPES);
- continue;
- }
- validEntityTypes.add(entityType.getTypeName());
+ if (CollectionUtils.isEmpty(entityTypes)) {
+ throw new
AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME,typeName);
+
+ } else if (entityTypes.size() != typeNames.size()) {
+ Set<String> validEntityTypes = new HashSet<>();
+ for (AtlasEntityType entityType : entityTypes) {
+ String name = entityType.getTypeName();
+ if (name.equals(MATCH_ALL_ENTITY_TYPES.getTypeName())) {
+ validEntityTypes.add(ALL_ENTITY_TYPES);
+ continue;
}
-
- typeNames.removeAll(validEntityTypes);
+ validEntityTypes.add(entityType.getTypeName());
}
- throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME,
String.join(TYPENAME_DELIMITER, typeNames));
- }
+ typeNames.removeAll(validEntityTypes);
+ LOG.info("Could not search for {} , invalid typeNames",
String.join(TYPENAME_DELIMITER, typeNames));
+ }
}
return entityTypes;
diff --git
a/repository/src/test/java/org/apache/atlas/discovery/EntitySearchProcessorTest.java
b/repository/src/test/java/org/apache/atlas/discovery/EntitySearchProcessorTest.java
index b7ce978..8e42d17 100644
---
a/repository/src/test/java/org/apache/atlas/discovery/EntitySearchProcessorTest.java
+++
b/repository/src/test/java/org/apache/atlas/discovery/EntitySearchProcessorTest.java
@@ -250,7 +250,7 @@ public class EntitySearchProcessorTest extends
BasicTestSetup {
@Test(expectedExceptions = AtlasBaseException.class,
expectedExceptionsMessageRegExp = "Not_Exists: Unknown/invalid typename")
public void entityTypesNotAllowed() throws AtlasBaseException {
SearchParameters params = new SearchParameters();
- params.setTypeName(DATABASE_TYPE+",Not_Exists");
+ params.setTypeName("Not_Exists");
params.setLimit(20);
SearchContext context = new SearchContext(params, typeRegistry, graph,
Collections.<String>emptySet());
diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
b/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
index 140ed9a..cdeb912 100644
--- a/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
+++ b/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
@@ -326,9 +326,16 @@ public class DiscoveryREST {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST,
"Limit/offset should be non-negative");
}
+ if (StringUtils.isEmpty(parameters.getTypeName()) &&
!isEmpty(parameters.getEntityFilters())) {
+ throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST,
"EntityFilters specified without Type name");
+ }
+
+ if (StringUtils.isEmpty(parameters.getClassification()) &&
!isEmpty(parameters.getTagFilters())) {
+ throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST,
"TagFilters specified without tag name");
+ }
+
if (StringUtils.isEmpty(parameters.getTypeName()) &&
StringUtils.isEmpty(parameters.getClassification()) &&
- StringUtils.isEmpty(parameters.getQuery()) &&
StringUtils.isEmpty(parameters.getTermName()) &&
- isEmpty(parameters.getEntityFilters()) &&
isEmpty(parameters.getTagFilters())) {
+ StringUtils.isEmpty(parameters.getQuery()) &&
StringUtils.isEmpty(parameters.getTermName())) {
throw new
AtlasBaseException(AtlasErrorCode.INVALID_SEARCH_PARAMS);
}