Skip to content

Commit

Permalink
Extend connection list filtering (#21094)
Browse files Browse the repository at this point in the history
* Update listWorkspaceStandardSyncs to support lists of sources/destinations

* Update API spec
  • Loading branch information
gosusnp authored Jan 9, 2023
1 parent 98ee1c2 commit 0d9a3ea
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
8 changes: 6 additions & 2 deletions airbyte-api/src/main/openapi/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4730,9 +4730,13 @@ components:
workspaceId:
$ref: "#/components/schemas/WorkspaceId"
sourceId:
$ref: "#/components/schemas/SourceId"
type: array
items:
$ref: "#/components/schemas/SourceId"
destinationId:
$ref: "#/components/schemas/DestinationId"
type: array
items:
$ref: "#/components/schemas/DestinationId"
WebBackendConnectionListItem:
type: object
description: Information about a connection that shows up in the connection list view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"OptionalUsedAsFieldOrParameterType"})
public class ConfigRepository {

public record StandardSyncQuery(@Nonnull UUID workspaceId, UUID sourceId, UUID destinationId, boolean includeDeleted) {}
public record StandardSyncQuery(@Nonnull UUID workspaceId, List<UUID> sourceId, List<UUID> destinationId, boolean includeDeleted) {}

private static final Logger LOGGER = LoggerFactory.getLogger(ConfigRepository.class);
private static final String OPERATION_IDS_AGG_FIELD = "operation_ids_agg";
Expand Down Expand Up @@ -867,8 +867,10 @@ public List<StandardSync> listWorkspaceStandardSyncs(final StandardSyncQuery sta
// join with source actors so that we can filter by workspaceId
.join(ACTOR).on(CONNECTION.SOURCE_ID.eq(ACTOR.ID))
.where(ACTOR.WORKSPACE_ID.eq(standardSyncQuery.workspaceId)
.and(standardSyncQuery.destinationId == null ? noCondition() : CONNECTION.DESTINATION_ID.eq(standardSyncQuery.destinationId))
.and(standardSyncQuery.sourceId == null ? noCondition() : CONNECTION.SOURCE_ID.eq(standardSyncQuery.sourceId))
.and(standardSyncQuery.destinationId == null || standardSyncQuery.destinationId.isEmpty() ? noCondition()
: CONNECTION.DESTINATION_ID.in(standardSyncQuery.destinationId))
.and(standardSyncQuery.sourceId == null || standardSyncQuery.sourceId.isEmpty() ? noCondition()
: CONNECTION.SOURCE_ID.in(standardSyncQuery.sourceId))
.and(standardSyncQuery.includeDeleted ? noCondition() : CONNECTION.STATUS.notEqual(StatusType.deprecated)))

// group by connection.id so that the groupConcat above works
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ void testListWorkspaceStandardSyncAll() throws IOException {
@Test
void testListWorkspaceStandardSyncWithAllFiltering() throws IOException {
final UUID workspaceId = MockData.standardWorkspaces().get(0).getWorkspaceId();
final StandardSyncQuery query = new StandardSyncQuery(workspaceId, MockData.SOURCE_ID_1, MockData.DESTINATION_ID_1, false);
final StandardSyncQuery query = new StandardSyncQuery(workspaceId, List.of(MockData.SOURCE_ID_1), List.of(MockData.DESTINATION_ID_1), false);
final List<StandardSync> expectedSyncs = MockData.standardSyncs().subList(0, 3).stream()
.filter(sync -> sync.getDestinationId().equals(query.destinationId()))
.filter(sync -> sync.getSourceId().equals(query.sourceId()))
.filter(sync -> query.destinationId().contains(sync.getDestinationId()))
.filter(sync -> query.sourceId().contains(sync.getSourceId()))
.toList();
final List<StandardSync> actualSyncs = configRepository.listWorkspaceStandardSyncs(query);

Expand All @@ -211,9 +211,9 @@ void testListWorkspaceStandardSyncWithAllFiltering() throws IOException {
@Test
void testListWorkspaceStandardSyncDestinationFiltering() throws IOException {
final UUID workspaceId = MockData.standardWorkspaces().get(0).getWorkspaceId();
final StandardSyncQuery query = new StandardSyncQuery(workspaceId, null, MockData.DESTINATION_ID_1, false);
final StandardSyncQuery query = new StandardSyncQuery(workspaceId, null, List.of(MockData.DESTINATION_ID_1), false);
final List<StandardSync> expectedSyncs = MockData.standardSyncs().subList(0, 3).stream()
.filter(sync -> sync.getDestinationId().equals(query.destinationId()))
.filter(sync -> query.destinationId().contains(sync.getDestinationId()))
.toList();
final List<StandardSync> actualSyncs = configRepository.listWorkspaceStandardSyncs(query);

Expand All @@ -223,9 +223,9 @@ void testListWorkspaceStandardSyncDestinationFiltering() throws IOException {
@Test
void testListWorkspaceStandardSyncSourceFiltering() throws IOException {
final UUID workspaceId = MockData.standardWorkspaces().get(0).getWorkspaceId();
final StandardSyncQuery query = new StandardSyncQuery(workspaceId, MockData.SOURCE_ID_2, null, false);
final StandardSyncQuery query = new StandardSyncQuery(workspaceId, List.of(MockData.SOURCE_ID_2), null, false);
final List<StandardSync> expectedSyncs = MockData.standardSyncs().subList(0, 3).stream()
.filter(sync -> sync.getSourceId().equals(query.sourceId()))
.filter(sync -> query.sourceId().contains(sync.getSourceId()))
.toList();
final List<StandardSync> actualSyncs = configRepository.listWorkspaceStandardSyncs(query);

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/api/generated-api-html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11876,8 +11876,8 @@ <h3><a name="WebBackendConnectionListRequestBody"><code>WebBackendConnectionList
<div class='model-description'></div>
<div class="field-items">
<div class="param">workspaceId </div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
<div class="param">sourceId (optional)</div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
<div class="param">destinationId (optional)</div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
<div class="param">sourceId (optional)</div><div class="param-desc"><span class="param-type"><a href="#UUID">array[UUID]</a></span> format: uuid</div>
<div class="param">destinationId (optional)</div><div class="param-desc"><span class="param-type"><a href="#UUID">array[UUID]</a></span> format: uuid</div>
</div> <!-- field-items -->
</div>
<div class="model">
Expand Down

0 comments on commit 0d9a3ea

Please sign in to comment.