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
......@@ -370,11 +370,13 @@ public class SearchContext {
});
// Validate if the classification exists
if (CollectionUtils.isEmpty(classificationNames) || classificationNames.size() != names.size()) {
if (CollectionUtils.isNotEmpty(classificationNames)) {
if (CollectionUtils.isEmpty(classificationNames)) {
throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_CLASSIFICATION, classification);
} else if (classificationNames.size() != names.size()) {
names.removeAll(classificationNames);
}
throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_CLASSIFICATION, String.join(TYPENAME_DELIMITER, names));
LOG.info("Could not search for {} , invalid classifications", String.join(TYPENAME_DELIMITER, names));
}
}
......@@ -398,8 +400,10 @@ 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)) {
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();
......@@ -411,11 +415,9 @@ public class SearchContext {
}
typeNames.removeAll(validEntityTypes);
}
throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME, String.join(TYPENAME_DELIMITER, typeNames));
LOG.info("Could not search for {} , invalid typeNames", String.join(TYPENAME_DELIMITER, typeNames));
}
}
return entityTypes;
......
......@@ -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());
......
......@@ -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);
}
......
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