Commit f690755f by Pinal Shah Committed by nixonrodrigues

ATLAS-3880 : BasicSearch: Multiple type/tag: Log invalid and allow searching valid type/tag names

parent 06cd0cb3
...@@ -359,7 +359,7 @@ public class SearchContext { ...@@ -359,7 +359,7 @@ public class SearchContext {
Set<String> classificationNames = new HashSet<>(); Set<String> classificationNames = new HashSet<>();
if (StringUtils.isNotEmpty(classification)) { if (StringUtils.isNotEmpty(classification)) {
String[] types = classification.split(TYPENAME_DELIMITER); String[] types = classification.split(TYPENAME_DELIMITER);
Set<String> names = new HashSet<>(Arrays.asList(types)); Set<String> names = new HashSet<>(Arrays.asList(types));
names.forEach(name -> { names.forEach(name -> {
...@@ -370,11 +370,13 @@ public class SearchContext { ...@@ -370,11 +370,13 @@ public class SearchContext {
}); });
// Validate if the classification exists // Validate if the classification exists
if (CollectionUtils.isEmpty(classificationNames) || classificationNames.size() != names.size()) { if (CollectionUtils.isEmpty(classificationNames)) {
if (CollectionUtils.isNotEmpty(classificationNames)) { throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_CLASSIFICATION, classification);
names.removeAll(classificationNames);
} } else if (classificationNames.size() != names.size()) {
throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_CLASSIFICATION, String.join(TYPENAME_DELIMITER, names)); names.removeAll(classificationNames);
LOG.info("Could not search for {} , invalid classifications", String.join(TYPENAME_DELIMITER, names));
} }
} }
...@@ -398,24 +400,24 @@ public class SearchContext { ...@@ -398,24 +400,24 @@ public class SearchContext {
getEntityType(n)).filter(Objects::nonNull).collect(Collectors.toSet()); getEntityType(n)).filter(Objects::nonNull).collect(Collectors.toSet());
// Validate if the type name is incorrect // Validate if the type name is incorrect
if (CollectionUtils.isEmpty(entityTypes) || entityTypes.size() != typeNames.size()) { if (CollectionUtils.isEmpty(entityTypes)) {
if (CollectionUtils.isNotEmpty(entityTypes)) { throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME,typeName);
Set<String> validEntityTypes = new HashSet<>();
for (AtlasEntityType entityType : entityTypes) { } else if (entityTypes.size() != typeNames.size()) {
String name = entityType.getTypeName(); Set<String> validEntityTypes = new HashSet<>();
if (name.equals(MATCH_ALL_ENTITY_TYPES.getTypeName())) { for (AtlasEntityType entityType : entityTypes) {
validEntityTypes.add(ALL_ENTITY_TYPES); String name = entityType.getTypeName();
continue; if (name.equals(MATCH_ALL_ENTITY_TYPES.getTypeName())) {
} validEntityTypes.add(ALL_ENTITY_TYPES);
validEntityTypes.add(entityType.getTypeName()); continue;
} }
validEntityTypes.add(entityType.getTypeName());
typeNames.removeAll(validEntityTypes);
} }
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; return entityTypes;
......
...@@ -250,7 +250,7 @@ public class EntitySearchProcessorTest extends BasicTestSetup { ...@@ -250,7 +250,7 @@ public class EntitySearchProcessorTest extends BasicTestSetup {
@Test(expectedExceptions = AtlasBaseException.class, expectedExceptionsMessageRegExp = "Not_Exists: Unknown/invalid typename") @Test(expectedExceptions = AtlasBaseException.class, expectedExceptionsMessageRegExp = "Not_Exists: Unknown/invalid typename")
public void entityTypesNotAllowed() throws AtlasBaseException { public void entityTypesNotAllowed() throws AtlasBaseException {
SearchParameters params = new SearchParameters(); SearchParameters params = new SearchParameters();
params.setTypeName(DATABASE_TYPE+",Not_Exists"); params.setTypeName("Not_Exists");
params.setLimit(20); params.setLimit(20);
SearchContext context = new SearchContext(params, typeRegistry, graph, Collections.<String>emptySet()); SearchContext context = new SearchContext(params, typeRegistry, graph, Collections.<String>emptySet());
......
...@@ -326,9 +326,16 @@ public class DiscoveryREST { ...@@ -326,9 +326,16 @@ public class DiscoveryREST {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "Limit/offset should be non-negative"); 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()) && if (StringUtils.isEmpty(parameters.getTypeName()) && StringUtils.isEmpty(parameters.getClassification()) &&
StringUtils.isEmpty(parameters.getQuery()) && StringUtils.isEmpty(parameters.getTermName()) && StringUtils.isEmpty(parameters.getQuery()) && StringUtils.isEmpty(parameters.getTermName())) {
isEmpty(parameters.getEntityFilters()) && isEmpty(parameters.getTagFilters())) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_SEARCH_PARAMS); throw new AtlasBaseException(AtlasErrorCode.INVALID_SEARCH_PARAMS);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment