Skip to content

Commit 68ae1cb

Browse files
authored
Merge pull request #1183 from atlanhq/FT-679
FT-679 Modified findByType to use regular expression.
2 parents b32f74e + db00096 commit 68ae1cb

File tree

1 file changed

+24
-38
lines changed

1 file changed

+24
-38
lines changed

sdk/src/main/java/com/atlan/model/workflow/WorkflowSearchRequest.java

+24-38
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,30 @@ public static WorkflowSearchResult findRunByName(AtlanClient client, String work
169169
*/
170170
public static List<WorkflowSearchResult> findByType(AtlanClient client, AtlanPackageType type, int maxResults)
171171
throws AtlanException {
172-
return findByPrefix(client, type.getValue(), maxResults);
172+
String regExBuilder = type.getValue().replace("-", "[-]") + "[-][0-9]{10}";
173+
SortOptions sort = SortOptions.of(s -> s.field(FieldSort.of(f -> f.field("metadata.creationTimestamp")
174+
.order(SortOrder.Desc)
175+
.nested(NestedSortValue.of(v -> v.path("metadata"))))));
176+
177+
Query term = RegexpQuery.of(t -> t.field("metadata.name.keyword").value(regExBuilder))
178+
._toQuery();
179+
180+
Query nested = NestedQuery.of(n -> n.path("metadata").query(term))._toQuery();
181+
182+
Query query = BoolQuery.of(b -> b.filter(nested))._toQuery();
183+
184+
WorkflowSearchRequest request = WorkflowSearchRequest.builder()
185+
.from(0)
186+
.size(maxResults)
187+
.sortOption(sort)
188+
.query(query)
189+
.build();
190+
191+
WorkflowSearchResponse response = client.workflows.search(request);
192+
if (response != null && response.getHits() != null) {
193+
return response.getHits().getHits();
194+
}
195+
return null;
173196
}
174197

175198
/**
@@ -196,41 +219,4 @@ public static WorkflowSearchResult findById(AtlanClient client, String id) throw
196219
}
197220
return null;
198221
}
199-
200-
/**
201-
* Find workflows based on their type.
202-
*
203-
* @param client connectivity to the Atlan tenant on which to find the workflows
204-
* @param prefix of the workflow
205-
* @param maxResults the maximum number of results to retrieve
206-
* @return the list of workflows of the provided type, with the most-recently created first
207-
* @throws AtlanException on any API communication issue
208-
*/
209-
private static List<WorkflowSearchResult> findByPrefix(AtlanClient client, String prefix, int maxResults)
210-
throws AtlanException {
211-
212-
SortOptions sort = SortOptions.of(s -> s.field(FieldSort.of(f -> f.field("metadata.creationTimestamp")
213-
.order(SortOrder.Desc)
214-
.nested(NestedSortValue.of(v -> v.path("metadata"))))));
215-
216-
Query term = PrefixQuery.of(t -> t.field("metadata.name.keyword").value(prefix))
217-
._toQuery();
218-
219-
Query nested = NestedQuery.of(n -> n.path("metadata").query(term))._toQuery();
220-
221-
Query query = BoolQuery.of(b -> b.filter(nested))._toQuery();
222-
223-
WorkflowSearchRequest request = WorkflowSearchRequest.builder()
224-
.from(0)
225-
.size(maxResults)
226-
.sortOption(sort)
227-
.query(query)
228-
.build();
229-
230-
WorkflowSearchResponse response = client.workflows.search(request);
231-
if (response != null && response.getHits() != null) {
232-
return response.getHits().getHits();
233-
}
234-
return null;
235-
}
236222
}

0 commit comments

Comments
 (0)