-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: alexeykozyurov <[email protected]>
- Loading branch information
1 parent
b6b37e1
commit c109c80
Showing
447 changed files
with
2,146 additions
and
3,700 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...api/src/main/java/org/opendatadiscovery/oddplatform/controller/IntegrationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.opendatadiscovery.oddplatform.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.opendatadiscovery.oddplatform.api.contract.api.IntegrationApi; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.Integration; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.IntegrationPreviewList; | ||
import org.opendatadiscovery.oddplatform.integration.service.IntegrationService; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class IntegrationController implements IntegrationApi { | ||
private final IntegrationService integrationService; | ||
|
||
@Override | ||
public Mono<ResponseEntity<Integration>> getIntegration(final String integrationId, | ||
final ServerWebExchange exchange) { | ||
return integrationService.get(integrationId).map(ResponseEntity::ok); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<IntegrationPreviewList>> getIntegrationPreviews(final ServerWebExchange exchange) { | ||
return integrationService.listPreviews().map(ResponseEntity::ok); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...-api/src/main/java/org/opendatadiscovery/oddplatform/integration/IntegrationRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.opendatadiscovery.oddplatform.integration; | ||
|
||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationOverviewDto; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationPreviewDto; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
public interface IntegrationRegistry { | ||
Mono<IntegrationOverviewDto> get(final String id); | ||
|
||
Flux<IntegrationPreviewDto> list(); | ||
} |
55 changes: 55 additions & 0 deletions
55
...c/main/java/org/opendatadiscovery/oddplatform/integration/IntegrationRegistryFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.opendatadiscovery.oddplatform.integration; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import lombok.experimental.UtilityClass; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationOverviewDto; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; | ||
import org.springframework.core.io.support.ResourcePatternResolver; | ||
|
||
import static java.util.function.Function.identity; | ||
|
||
@UtilityClass | ||
@Slf4j | ||
public class IntegrationRegistryFactory { | ||
private static final ResourcePatternResolver RESOURCE_PATTERN_RESOLVER = new PathMatchingResourcePatternResolver(); | ||
private static final String CLASSPATH_RESOURCE_LOCATION = "classpath*:META-INF/wizard/*.yaml"; | ||
private static final ObjectMapper YAML_OBJ_MAPPER = new ObjectMapper(new YAMLFactory()); | ||
|
||
public static IntegrationRegistry createResourceFilesIntegrationRegistry() { | ||
final Map<String, IntegrationOverviewDto> registry = readManifests() | ||
.stream() | ||
.collect(Collectors.toMap(o -> o.integration().id(), identity())); | ||
|
||
return new ResourceFilesIntegrationRegistry(registry); | ||
} | ||
|
||
private static List<IntegrationOverviewDto> readManifests() { | ||
try { | ||
return Arrays.stream(RESOURCE_PATTERN_RESOLVER.getResources(CLASSPATH_RESOURCE_LOCATION)) | ||
.filter(Resource::isReadable) | ||
.map(IntegrationRegistryFactory::readManifest) | ||
.toList(); | ||
} catch (final IOException e) { | ||
throw new IllegalStateException("Couldn't read wizard manifests", e); | ||
} | ||
} | ||
|
||
private static IntegrationOverviewDto readManifest(final Resource resource) { | ||
log.debug("Reading wizard manifest file: {}", resource.getFilename()); | ||
|
||
try (final InputStream is = resource.getInputStream()) { | ||
return YAML_OBJ_MAPPER.readValue(is, IntegrationOverviewDto.class); | ||
} catch (final IOException e) { | ||
throw new IllegalStateException("Couldn't read wizard manifest: %s".formatted(resource.getFilename()), e); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../java/org/opendatadiscovery/oddplatform/integration/ResourceFilesIntegrationRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.opendatadiscovery.oddplatform.integration; | ||
|
||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationOverviewDto; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationPreviewDto; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RequiredArgsConstructor | ||
public class ResourceFilesIntegrationRegistry implements IntegrationRegistry { | ||
private final Map<String, IntegrationOverviewDto> registry; | ||
|
||
@Override | ||
public Mono<IntegrationOverviewDto> get(final String id) { | ||
return Mono.justOrEmpty(registry.get(id)); | ||
} | ||
|
||
@Override | ||
public Flux<IntegrationPreviewDto> list() { | ||
return Flux.fromIterable(registry.values()).map(IntegrationOverviewDto::integration); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...n/java/org/opendatadiscovery/oddplatform/integration/config/IntegrationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.opendatadiscovery.oddplatform.integration.config; | ||
|
||
import org.opendatadiscovery.oddplatform.integration.IntegrationRegistry; | ||
import org.opendatadiscovery.oddplatform.integration.IntegrationRegistryFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class IntegrationConfiguration { | ||
@Bean | ||
public IntegrationRegistry integrationRegistry() { | ||
return IntegrationRegistryFactory.createResourceFilesIntegrationRegistry(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
.../org/opendatadiscovery/oddplatform/integration/dto/IntegrationCodeSnippetArgumentDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.opendatadiscovery.oddplatform.integration.dto; | ||
|
||
public record IntegrationCodeSnippetArgumentDto(String parameter, | ||
String name, | ||
IntegrationCodeSnippetArgumentTypeEnum type) { | ||
} |
8 changes: 8 additions & 0 deletions
8
...opendatadiscovery/oddplatform/integration/dto/IntegrationCodeSnippetArgumentTypeEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.opendatadiscovery.oddplatform.integration.dto; | ||
|
||
public enum IntegrationCodeSnippetArgumentTypeEnum { | ||
INTEGER, | ||
STRING, | ||
BOOLEAN, | ||
FLOAT | ||
} |
6 changes: 6 additions & 0 deletions
6
...ain/java/org/opendatadiscovery/oddplatform/integration/dto/IntegrationCodeSnippetDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.opendatadiscovery.oddplatform.integration.dto; | ||
|
||
import java.util.List; | ||
|
||
public record IntegrationCodeSnippetDto(String template, List<IntegrationCodeSnippetArgumentDto> arguments) { | ||
} |
6 changes: 6 additions & 0 deletions
6
...in/java/org/opendatadiscovery/oddplatform/integration/dto/IntegrationContentBlockDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.opendatadiscovery.oddplatform.integration.dto; | ||
|
||
import java.util.List; | ||
|
||
public record IntegrationContentBlockDto(String title, String content, List<IntegrationCodeSnippetDto> codeSnippets) { | ||
} |
10 changes: 10 additions & 0 deletions
10
...c/main/java/org/opendatadiscovery/oddplatform/integration/dto/IntegrationOverviewDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.opendatadiscovery.oddplatform.integration.dto; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import java.util.List; | ||
import org.opendatadiscovery.oddplatform.integration.serde.IntegrationDeserializer; | ||
|
||
@JsonDeserialize(using = IntegrationDeserializer.class) | ||
public record IntegrationOverviewDto(IntegrationPreviewDto integration, | ||
List<IntegrationContentBlockDto> contentBlocks) { | ||
} |
4 changes: 4 additions & 0 deletions
4
...rc/main/java/org/opendatadiscovery/oddplatform/integration/dto/IntegrationPreviewDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.opendatadiscovery.oddplatform.integration.dto; | ||
|
||
public record IntegrationPreviewDto(String id, String name, String description) { | ||
} |
45 changes: 45 additions & 0 deletions
45
...src/main/java/org/opendatadiscovery/oddplatform/integration/mapper/IntegrationMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.opendatadiscovery.oddplatform.integration.mapper; | ||
|
||
import java.util.List; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.Integration; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.IntegrationCodeSnippet; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.IntegrationCodeSnippetArgument; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.IntegrationCodeSnippetArgumentType; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.IntegrationContentBlock; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.IntegrationPreview; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.IntegrationPreviewList; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationCodeSnippetArgumentDto; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationCodeSnippetArgumentTypeEnum; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationCodeSnippetDto; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationContentBlockDto; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationOverviewDto; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationPreviewDto; | ||
import org.opendatadiscovery.oddplatform.mapper.MapperConfig; | ||
|
||
@Mapper(config = MapperConfig.class) | ||
public interface IntegrationMapper { | ||
@Mapping(target = "id", source = "integration.id") | ||
@Mapping(target = "name", source = "integration.name") | ||
@Mapping(target = "description", source = "integration.description") | ||
@Mapping(target = "installed", constant = "false") | ||
Integration map(final IntegrationOverviewDto dto); | ||
|
||
@Mapping(target = "installed", constant = "false") | ||
IntegrationPreview map(final IntegrationPreviewDto dto); | ||
|
||
IntegrationContentBlock map(final IntegrationContentBlockDto dto); | ||
|
||
IntegrationCodeSnippet map(final IntegrationCodeSnippetDto dto); | ||
|
||
IntegrationCodeSnippetArgument map(final IntegrationCodeSnippetArgumentDto dto); | ||
|
||
default IntegrationCodeSnippetArgumentType map(final IntegrationCodeSnippetArgumentTypeEnum dto) { | ||
return IntegrationCodeSnippetArgumentType.fromValue(dto.name()); | ||
} | ||
|
||
default IntegrationPreviewList map(final List<IntegrationPreviewDto> dtos) { | ||
return new IntegrationPreviewList().items(dtos.stream().map(this::map).toList()); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...ain/java/org/opendatadiscovery/oddplatform/integration/serde/IntegrationDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.opendatadiscovery.oddplatform.integration.serde; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationCodeSnippetArgumentDto; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationCodeSnippetArgumentTypeEnum; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationCodeSnippetDto; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationContentBlockDto; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationOverviewDto; | ||
import org.opendatadiscovery.oddplatform.integration.dto.IntegrationPreviewDto; | ||
|
||
public class IntegrationDeserializer extends StdDeserializer<IntegrationOverviewDto> { | ||
public IntegrationDeserializer() { | ||
this(null); | ||
} | ||
|
||
protected IntegrationDeserializer(final Class<?> vc) { | ||
super(vc); | ||
} | ||
|
||
@Override | ||
public IntegrationOverviewDto deserialize( | ||
final JsonParser p, | ||
final DeserializationContext ctx | ||
) throws IOException { | ||
final ObjectNode integrationNode = p.getCodec().readTree(p); | ||
|
||
final String id = integrationNode.get("id").asText(); | ||
final String name = integrationNode.get("name").asText(); | ||
final String description = integrationNode.get("description").asText(); | ||
|
||
final IntegrationPreviewDto integrationPreviewDto = new IntegrationPreviewDto(id, name, description); | ||
final List<IntegrationContentBlockDto> integrationContentBlockDtos = new ArrayList<>(); | ||
|
||
for (final JsonNode block : integrationNode.get("blocks")) { | ||
final String blockTitle = block.get("title").asText(); | ||
final String blockContent = block.get("content").asText(); | ||
final JsonNode blockSnippets = block.get("snippets"); | ||
|
||
final List<IntegrationCodeSnippetDto> snippets = new ArrayList<>(); | ||
|
||
for (final JsonNode snippet : ObjectUtils.defaultIfNull(blockSnippets, List.<JsonNode>of())) { | ||
final String snippetTemplate = snippet.get("template").asText(); | ||
|
||
final List<IntegrationCodeSnippetArgumentDto> arguments = new ArrayList<>(); | ||
final Iterable<JsonNode> snippetArgs = ObjectUtils.defaultIfNull(snippet.get("arguments"), List.of()); | ||
|
||
for (final JsonNode argument : snippetArgs) { | ||
final String argParameter = argument.get("parameter").asText(); | ||
final String argName = argument.get("name").asText(); | ||
final String type = argument.get("type").asText(); | ||
|
||
arguments.add(new IntegrationCodeSnippetArgumentDto( | ||
argParameter, | ||
argName, | ||
IntegrationCodeSnippetArgumentTypeEnum.valueOf(type.toUpperCase()) | ||
)); | ||
} | ||
|
||
snippets.add(new IntegrationCodeSnippetDto(snippetTemplate, arguments)); | ||
} | ||
|
||
integrationContentBlockDtos.add(new IntegrationContentBlockDto(blockTitle, blockContent, snippets)); | ||
} | ||
|
||
return new IntegrationOverviewDto(integrationPreviewDto, integrationContentBlockDtos); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...c/main/java/org/opendatadiscovery/oddplatform/integration/service/IntegrationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.opendatadiscovery.oddplatform.integration.service; | ||
|
||
import org.opendatadiscovery.oddplatform.api.contract.model.Integration; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.IntegrationPreviewList; | ||
import reactor.core.publisher.Mono; | ||
|
||
public interface IntegrationService { | ||
Mono<Integration> get(final String id); | ||
|
||
Mono<IntegrationPreviewList> listPreviews(); | ||
} |
26 changes: 26 additions & 0 deletions
26
...in/java/org/opendatadiscovery/oddplatform/integration/service/IntegrationServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.opendatadiscovery.oddplatform.integration.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.Integration; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.IntegrationPreviewList; | ||
import org.opendatadiscovery.oddplatform.integration.IntegrationRegistry; | ||
import org.opendatadiscovery.oddplatform.integration.mapper.IntegrationMapper; | ||
import org.springframework.stereotype.Service; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class IntegrationServiceImpl implements IntegrationService { | ||
private final IntegrationRegistry integrationRegistry; | ||
private final IntegrationMapper integrationMapper; | ||
|
||
@Override | ||
public Mono<Integration> get(final String id) { | ||
return integrationRegistry.get(id).map(integrationMapper::map); | ||
} | ||
|
||
@Override | ||
public Mono<IntegrationPreviewList> listPreviews() { | ||
return integrationRegistry.list().collectList().map(integrationMapper::map); | ||
} | ||
} |
Oops, something went wrong.