Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Master]- Dg-980: Data Product Visibility Persona indexsearch change. #2909

Merged
merged 8 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class IndexSearchParams extends SearchParams {
* (this will include related attributes which has relationshipStatus as DELETED along with ACTIVE ones)
* */
private boolean allowDeletedRelations;
private boolean accessControlExclusive;

@Override
public String getQuery() {
Expand All @@ -46,6 +47,14 @@ public boolean isAllowDeletedRelations() {
return allowDeletedRelations;
}

public boolean isAccessControlExclusive() {
return accessControlExclusive;
}

public void setAccessControlExclusive(boolean accessControlExclusive) {
this.accessControlExclusive = accessControlExclusive;
}

public void setAllowDeletedRelations(boolean allowDeletedRelations) {
this.allowDeletedRelations = allowDeletedRelations;
}
Expand Down Expand Up @@ -78,6 +87,7 @@ public String toString() {
", persona='" + persona + '\'' +
", queryString='" + queryString + '\'' +
", allowDeletedRelations=" + allowDeletedRelations +
", accessControlExclusive=" + accessControlExclusive +
", utmTags="+ getUtmTags() +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1149,9 +1149,57 @@ private String getIndexName(IndexSearchParams params) throws AtlasBaseException
String aliasName = parts[parts.length - 1];

if (StringUtils.isNotEmpty(aliasName)) {
if(params.isAccessControlExclusive()) {
accessControlExclusiveDsl(params, aliasName);
aliasName = aliasName+","+VERTEX_INDEX_NAME;
}
return aliasName;
} else {
throw new AtlasBaseException("ES alias not found for purpose/persona " + params.getPurpose());
}
}

private void accessControlExclusiveDsl(IndexSearchParams params, String aliasName) {

List<Map<String, Object>> mustClauses = new ArrayList<>();
Map<String, Object> clientQuery = (Map<String, Object>) params.getDsl().get("query");

mustClauses.add(clientQuery);

List<Map<String, Object>>filterClauses = new ArrayList<>();
filterClauses.add(getMap("terms", getMap("_index", Collections.singletonList(aliasName))));

Map<String, Object> boolQuery = new HashMap<>();
boolQuery.put("must", mustClauses);
boolQuery.put("filter",filterClauses);

List<Map<String, Object>> shouldClauses = new ArrayList<>();
shouldClauses.add(getMap("bool", boolQuery));
shouldClauses.add(getStaticBoolQuery());

Map<String, Object> topBoolQuery = getMap("bool", getMap("should", shouldClauses));

Map copyOfDsl = new HashMap(params.getDsl());
copyOfDsl.put("query", topBoolQuery);

params.setDsl(copyOfDsl);
}

private Map<String, Object> getStaticBoolQuery() {
List<Map<String, Object>> mustClauses = new ArrayList<>();
Map<String, Object> mustClause = getMap("bool", getMap("should", Arrays.asList(
getMap("term", getMap("daapVisibility", "Public")),
getMap("term", getMap("daapVisibility", "Protected"))
)));
mustClauses.add(mustClause);

List<Map<String, Object>>filterClauses = new ArrayList<>();
filterClauses.add(getMap("terms", getMap("_index", Collections.singletonList(VERTEX_INDEX_NAME))));

Map<String, Object> boolQuery = new HashMap<>();
boolQuery.put("must", mustClauses);
boolQuery.put("filter", filterClauses);

return getMap("bool", boolQuery);
}
}
Loading