in repository/src/main/java/org/apache/atlas/discovery/SearchContext.java [101:245]
public SearchContext(SearchParameters searchParameters, AtlasTypeRegistry typeRegistry, AtlasGraph graph, Set<String> indexedKeys) throws AtlasBaseException {
this.searchParameters = searchParameters;
this.typeRegistry = typeRegistry;
this.graph = graph;
this.indexedKeys = indexedKeys;
this.entityAttributes = new HashSet<>();
this.relationAttributes = new HashSet<>();
this.entityTypes = getEntityTypes(searchParameters.getTypeName());
this.classificationNames = getClassificationNames(searchParameters.getClassification());
this.classificationTypes = getClassificationTypes(this.classificationNames);
this.relationshipTypes = getRelationshipTypes(searchParameters.getRelationshipName());
AtlasVertex glossaryTermVertex = getGlossaryTermVertex(searchParameters.getTermName());
// Validate if the term exists
if (StringUtils.isNotEmpty(searchParameters.getTermName()) && glossaryTermVertex == null) {
throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_GLOSSARY_TERM, searchParameters.getTermName());
}
// Invalid attributes or unsupported attribute in a type, will raise an exception with 400 error code
if (CollectionUtils.isNotEmpty(entityTypes)) {
for (AtlasEntityType entityType : entityTypes) {
validateAttributes(entityType, searchParameters.getEntityFilters());
validateAttributes(entityType, searchParameters.getSortBy());
}
}
//Wildcard tag with filter will raise an exception with 400 error code
if (CollectionUtils.isNotEmpty(classificationNames) && hasAttributeFilter(searchParameters.getTagFilters())) {
for (String classificationName : classificationNames) {
//in case of '*' , filters are allowed, but
//in case of regex 'PI*', filters are not allowed ( if present in any of the requested tag)
if (classificationName.contains(WILDCARD_CLASSIFICATIONS) && !classificationName.equals(WILDCARD_CLASSIFICATIONS)) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "TagFilters specified with wildcard tag name");
}
}
}
// Invalid attributes will raise an exception with 400 error code
if (CollectionUtils.isNotEmpty(classificationTypes)) {
for (AtlasClassificationType classificationType : classificationTypes) {
validateAttributes(classificationType, searchParameters.getTagFilters());
}
}
// Invalid relationship attributes will raise an exception with 400 error code
if (CollectionUtils.isNotEmpty(relationshipTypes)) {
for (AtlasRelationshipType relationshipType : relationshipTypes) {
validateAttributes(relationshipType, searchParameters.getRelationshipFilters());
}
}
if (StringUtils.isNotEmpty(searchParameters.getMarker())) {
marker = MarkerUtil.decodeMarker(searchParameters);
}
//remove other types if builtin type is present
filterStructTypes();
//validate 'attributes' field
validateAttributes();
//gather all classifications and its corresponding subtypes
Set<String> classificationTypeAndSubTypes = new HashSet<>();
String classificationTypeAndSubTypesQryStr = null;
if (CollectionUtils.isNotEmpty(classificationTypes) && classificationTypes.iterator().next() != MATCH_ALL_NOT_CLASSIFIED) {
for (AtlasClassificationType classificationType : classificationTypes) {
if (classificationType == MATCH_ALL_CLASSIFICATION_TYPES) {
classificationTypeAndSubTypes = Collections.emptySet();
classificationTypeAndSubTypesQryStr = ALL_TYPE_QUERY;
break;
} else {
Set<String> allTypes = searchParameters.getIncludeSubClassifications() ? classificationType.getTypeAndAllSubTypes() : Collections.singleton(classificationType.getTypeName());
classificationTypeAndSubTypes.addAll(allTypes);
}
}
if (CollectionUtils.isNotEmpty(classificationTypeAndSubTypes)) {
classificationTypeAndSubTypesQryStr = AtlasAttribute.escapeIndexQueryValue(classificationTypeAndSubTypes, true);
}
} else {
classificationTypeAndSubTypes = Collections.emptySet();
classificationTypeAndSubTypesQryStr = "";
}
this.classificationTypeAndSubTypes = classificationTypeAndSubTypes;
this.classificationTypeAndSubTypesQryStr = classificationTypeAndSubTypesQryStr;
//gather all types and its corresponding subtypes
Set<String> typeAndSubTypes = new HashSet<>();
String typeAndSubTypesQryStr = null;
if (CollectionUtils.isNotEmpty(entityTypes)) {
for (AtlasEntityType entityType : entityTypes) {
if (entityType.equals(MATCH_ALL_ENTITY_TYPES)) {
typeAndSubTypes = Collections.emptySet();
typeAndSubTypesQryStr = ALL_TYPE_QUERY;
break;
} else {
Set<String> allTypes = searchParameters.getIncludeSubTypes() ? entityType.getTypeAndAllSubTypes() : Collections.singleton(entityType.getTypeName());
typeAndSubTypes.addAll(allTypes);
}
}
if (CollectionUtils.isNotEmpty(typeAndSubTypes)) {
typeAndSubTypesQryStr = AtlasAttribute.escapeIndexQueryValue(typeAndSubTypes, true);
}
} else {
typeAndSubTypes = Collections.emptySet();
typeAndSubTypesQryStr = "";
}
this.typeAndSubTypes = typeAndSubTypes;
this.typeAndSubTypesQryStr = typeAndSubTypesQryStr;
if (glossaryTermVertex != null) {
addProcessor(new TermSearchProcessor(this, getAssignedEntities(glossaryTermVertex)));
}
if (needFullTextProcessor()) {
if (AtlasRepositoryConfiguration.isFreeTextSearchEnabled()) {
LOG.debug("Using Free Text index based search.");
addProcessor(new FreeTextSearchProcessor(this));
} else {
LOG.debug("Using Full Text index based search.");
addProcessor(new FullTextSearchProcessor(this));
}
}
if (needClassificationProcessor()) {
addProcessor(new ClassificationSearchProcessor(this));
}
if (needEntityProcessor()) {
addProcessor(new EntitySearchProcessor(this));
}
}