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

FT-679 Modified findByType to use regular expression. #1183

Merged
merged 1 commit into from
Jan 2, 2025
Merged
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 @@ -169,7 +169,30 @@ public static WorkflowSearchResult findRunByName(AtlanClient client, String work
*/
public static List<WorkflowSearchResult> findByType(AtlanClient client, AtlanPackageType type, int maxResults)
throws AtlanException {
return findByPrefix(client, type.getValue(), maxResults);
String regExBuilder = type.getValue().replace("-", "[-]") + "[-][0-9]{10}";
SortOptions sort = SortOptions.of(s -> s.field(FieldSort.of(f -> f.field("metadata.creationTimestamp")
.order(SortOrder.Desc)
.nested(NestedSortValue.of(v -> v.path("metadata"))))));

Query term = RegexpQuery.of(t -> t.field("metadata.name.keyword").value(regExBuilder))
._toQuery();

Query nested = NestedQuery.of(n -> n.path("metadata").query(term))._toQuery();

Query query = BoolQuery.of(b -> b.filter(nested))._toQuery();

WorkflowSearchRequest request = WorkflowSearchRequest.builder()
.from(0)
.size(maxResults)
.sortOption(sort)
.query(query)
.build();

WorkflowSearchResponse response = client.workflows.search(request);
if (response != null && response.getHits() != null) {
return response.getHits().getHits();
}
return null;
}

/**
Expand All @@ -196,41 +219,4 @@ public static WorkflowSearchResult findById(AtlanClient client, String id) throw
}
return null;
}

/**
* Find workflows based on their type.
*
* @param client connectivity to the Atlan tenant on which to find the workflows
* @param prefix of the workflow
* @param maxResults the maximum number of results to retrieve
* @return the list of workflows of the provided type, with the most-recently created first
* @throws AtlanException on any API communication issue
*/
private static List<WorkflowSearchResult> findByPrefix(AtlanClient client, String prefix, int maxResults)
throws AtlanException {

SortOptions sort = SortOptions.of(s -> s.field(FieldSort.of(f -> f.field("metadata.creationTimestamp")
.order(SortOrder.Desc)
.nested(NestedSortValue.of(v -> v.path("metadata"))))));

Query term = PrefixQuery.of(t -> t.field("metadata.name.keyword").value(prefix))
._toQuery();

Query nested = NestedQuery.of(n -> n.path("metadata").query(term))._toQuery();

Query query = BoolQuery.of(b -> b.filter(nested))._toQuery();

WorkflowSearchRequest request = WorkflowSearchRequest.builder()
.from(0)
.size(maxResults)
.sortOption(sort)
.query(query)
.build();

WorkflowSearchResponse response = client.workflows.search(request);
if (response != null && response.getHits() != null) {
return response.getHits().getHits();
}
return null;
}
}
Loading