Skip to content

Commit

Permalink
Improve listSourcesForWorkspace route (#18207)
Browse files Browse the repository at this point in the history
  • Loading branch information
malikdiarra authored Oct 24, 2022
1 parent 4b93a9b commit 1ee02d4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,23 @@ public List<SourceConnection> listSourceConnection() throws JsonValidationExcept
return persistence.listConfigs(ConfigSchema.SOURCE_CONNECTION, SourceConnection.class);
}

/**
* Returns all sources for a workspace. Does not contain secrets.
*
* @param workspaceId - id of the workspace
* @return sources
* @throws JsonValidationException - throws if returned sources are invalid
* @throws IOException - you never know when you IO
*/
public List<SourceConnection> listWorkspaceSourceConnection(final UUID workspaceId) throws IOException {
final Result<Record> result = database.query(ctx -> ctx.select(asterisk())
.from(ACTOR)
.where(ACTOR.ACTOR_TYPE.eq(ActorType.source))
.and(ACTOR.WORKSPACE_ID.eq(workspaceId))
.andNot(ACTOR.TOMBSTONE).fetch());
return result.stream().map(DbConverter::buildSourceConnection).collect(Collectors.toList());
}

/**
* Returns destination with a given id. Does not contain secrets. To hydrate with secrets see
* { @link SecretsRepositoryReader#getDestinationConnectionWithSecrets(final UUID destinationId) }.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ void testListPublicSourceDefinitions() throws IOException {
assertEquals(List.of(MockData.publicSourceDefinition()), actualDefinitions);
}

@Test
void testListWorkspaceSources() throws IOException {
UUID workspaceId = MockData.standardWorkspaces().get(1).getWorkspaceId();
final List<SourceConnection> expectedSources = MockData.sourceConnections().stream()
.filter(source -> source.getWorkspaceId().equals(workspaceId)).collect(Collectors.toList());
final List<SourceConnection> sources = configRepository.listWorkspaceSourceConnection(workspaceId);
assertThat(sources).hasSameElementsAs(expectedSources);
}

@Test
void testSourceDefinitionGrants() throws IOException {
final UUID workspaceId = MockData.standardWorkspaces().get(0).getWorkspaceId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ public SourceRead cloneSource(final SourceCloneRequestBody sourceCloneRequestBod
public SourceReadList listSourcesForWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody)
throws ConfigNotFoundException, IOException, JsonValidationException {

final List<SourceConnection> sourceConnections = configRepository.listSourceConnection()
.stream()
.filter(sc -> sc.getWorkspaceId().equals(workspaceIdRequestBody.getWorkspaceId()) && !MoreBooleans.isTruthy(sc.getTombstone()))
.toList();
final List<SourceConnection> sourceConnections = configRepository.listWorkspaceSourceConnection(workspaceIdRequestBody.getWorkspaceId());

final List<SourceRead> reads = Lists.newArrayList();
for (final SourceConnection sc : sourceConnections) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void testListSourcesForWorkspace() throws JsonValidationException, ConfigNotFoun
when(configRepository.getSourceConnection(sourceConnection.getSourceId())).thenReturn(sourceConnection);
when(configRepository.getSourceConnection(sourceConnection.getSourceId())).thenReturn(sourceConnection);

when(configRepository.listSourceConnection()).thenReturn(Lists.newArrayList(sourceConnection));
when(configRepository.listWorkspaceSourceConnection(sourceConnection.getWorkspaceId())).thenReturn(Lists.newArrayList(sourceConnection));
when(configRepository.getStandardSourceDefinition(sourceDefinitionSpecificationRead.getSourceDefinitionId()))
.thenReturn(standardSourceDefinition);
when(configRepository.getSourceDefinitionFromSource(sourceConnection.getSourceId())).thenReturn(standardSourceDefinition);
Expand Down

0 comments on commit 1ee02d4

Please sign in to comment.