diff --git a/sdk/src/main/java/com/atlan/model/workflow/WorkflowSearchRequest.java b/sdk/src/main/java/com/atlan/model/workflow/WorkflowSearchRequest.java index 1dd00cd980..1231f22eba 100644 --- a/sdk/src/main/java/com/atlan/model/workflow/WorkflowSearchRequest.java +++ b/sdk/src/main/java/com/atlan/model/workflow/WorkflowSearchRequest.java @@ -169,7 +169,30 @@ public static WorkflowSearchResult findRunByName(AtlanClient client, String work */ public static List 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; } /** @@ -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 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; - } }