Search in sources :

Example 16 with Extension

use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.

the class ExtensionDataManagerTest method shouldGetCorrectDataByExtensionId.

@Test
public void shouldGetCorrectDataByExtensionId() throws IOException {
    final DataManager dataManager = mock(DataManager.class);
    final FileDAO extensionDataAccess = mock(FileDAO.class);
    final FileDataManager extensionDataManager = new FileDataManager(dataManager, extensionDataAccess);
    String sampleBinaryData = "Hello";
    Extension sampleMetadata = new Extension.Builder().id("1234").status(Extension.Status.Installed).extensionId("extensionId").description("Description").build();
    when(extensionDataAccess.read("/extensions/1234")).thenReturn(new ByteArrayInputStream(sampleBinaryData.getBytes(StandardCharsets.UTF_8)));
    when(dataManager.fetchIdsByPropertyValue(Extension.class, "extensionId", "extensionId", "status", Extension.Status.Installed.name())).thenReturn(Collections.singleton("1234"));
    when(dataManager.fetch(Extension.class, "1234")).thenReturn(sampleMetadata);
    assertThat(extensionDataManager.getExtensionMetadata("extensionId")).isEqualTo(sampleMetadata);
    assertThat(IOUtils.toString(extensionDataManager.getExtensionBinaryFile("extensionId"), StandardCharsets.UTF_8)).isEqualTo(sampleBinaryData);
}
Also used : Extension(io.syndesis.common.model.extension.Extension) ByteArrayInputStream(java.io.ByteArrayInputStream) DataManager(io.syndesis.server.dao.manager.DataManager) Test(org.junit.Test)

Example 17 with Extension

use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.

the class GenerateMetadataMojo method tryImportingPartialJSON.

/**
 * Loads a partial metadata json file, if configured at Maven Plugin level.
 * @throws MojoExecutionException
 */
protected void tryImportingPartialJSON() throws MojoExecutionException {
    File template;
    if (StringUtils.isNotEmpty(source)) {
        template = new File(source);
    } else {
        template = new File(metadataDestination);
    }
    if (template.exists()) {
        try {
            JsonNode tree = Json.reader().readTree(Files.newBufferedReader(template.toPath(), StandardCharsets.UTF_8));
            Extension extension = ExtensionConverter.getDefault().toInternalExtension(tree);
            getLog().info("Loaded base partial metadata configuration file: " + source);
            actions.clear();
            for (Action action : extension.getActions()) {
                action.getId().ifPresent(id -> actions.put(id, action));
            }
            extensionBuilder = extensionBuilder.createFrom(extension);
            extensionBuilder.actions(Collections.emptySet());
        } catch (IOException e) {
            throw new MojoExecutionException("Invalid input json: " + source, e);
        }
    }
}
Also used : Extension(io.syndesis.common.model.extension.Extension) StepAction(io.syndesis.common.model.action.StepAction) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Action(io.syndesis.common.model.action.Action) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) File(java.io.File)

Example 18 with Extension

use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.

the class IntegrationResourceManager method collectDependencies.

/**
 * Collect dependencies.
 */
default Collection<Dependency> collectDependencies(Collection<? extends Step> steps, boolean resolveExtensionTags) {
    final List<Dependency> dependencies = new ArrayList<>();
    for (Step step : steps) {
        step.getAction().filter(WithDependencies.class::isInstance).map(WithDependencies.class::cast).map(WithDependencies::getDependencies).ifPresent(dependencies::addAll);
        List<Dependency> connectorDependencies = step.getConnection().flatMap(Connection::getConnector).map(WithDependencies::getDependencies).orElse(Collections.emptyList());
        dependencies.addAll(connectorDependencies);
        List<Dependency> lookedUpConnectorDependecies = step.getConnection().filter(c -> !c.getConnector().isPresent()).map(Connection::getConnectorId).flatMap(this::loadConnector).map(WithDependencies::getDependencies).orElse(Collections.emptyList());
        dependencies.addAll(lookedUpConnectorDependecies);
        // Connector extension
        Stream.concat(connectorDependencies.stream(), lookedUpConnectorDependecies.stream()).filter(Dependency::isExtension).map(Dependency::getId).map(this::loadExtension).filter(Optional::isPresent).map(Optional::get).map(Extension::getDependencies).forEach(dependencies::addAll);
        // Step extension
        step.getExtension().map(WithDependencies::getDependencies).ifPresent(dependencies::addAll);
        step.getExtension().map(Extension::getExtensionId).map(Dependency::extension).ifPresent(dependencies::add);
    }
    if (resolveExtensionTags) {
        return dependencies.stream().flatMap(dep -> {
            if (dep.isExtensionTag()) {
                List<Extension> extensions = this.loadExtensionsByTag(dep.getId());
                Stream<Dependency> extensionDependency = extensions.stream().map(ext -> Dependency.extension(ext.getExtensionId()));
                Stream<Dependency> transitive = extensions.stream().map(Extension::getDependencies).flatMap(Collection::stream);
                return Stream.concat(extensionDependency, transitive);
            } else {
                return Stream.of(dep);
            }
        }).collect(Collectors.toCollection(ArrayList::new));
    } else {
        return dependencies;
    }
}
Also used : Extension(io.syndesis.common.model.extension.Extension) Step(io.syndesis.common.model.integration.Step) Collection(java.util.Collection) Connector(io.syndesis.common.model.connection.Connector) Extension(io.syndesis.common.model.extension.Extension) WithDependencies(io.syndesis.common.model.WithDependencies) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Dependency(io.syndesis.common.model.Dependency) List(java.util.List) Stream(java.util.stream.Stream) Connection(io.syndesis.common.model.connection.Connection) Optional(java.util.Optional) Integration(io.syndesis.common.model.integration.Integration) Collections(java.util.Collections) InputStream(java.io.InputStream) WithDependencies(io.syndesis.common.model.WithDependencies) Optional(java.util.Optional) ArrayList(java.util.ArrayList) Connection(io.syndesis.common.model.connection.Connection) ArrayList(java.util.ArrayList) List(java.util.List) Stream(java.util.stream.Stream) InputStream(java.io.InputStream) Dependency(io.syndesis.common.model.Dependency) Step(io.syndesis.common.model.integration.Step)

Example 19 with Extension

use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.

the class ExtensionSchemaValidationTest method validateStepExtensionTest.

@Test
public void validateStepExtensionTest() throws ProcessingException, IOException {
    String syndesisExtensionSchema = "/syndesis/syndesis-extension-definition-schema.json";
    JsonSchema schema = JsonSchemaFactory.byDefault().getJsonSchema("resource:" + syndesisExtensionSchema);
    ExtensionConverter converter = new DefaultExtensionConverter();
    Extension extension = new Extension.Builder().extensionId("my-extension").name("Name").description("Description").uses(OptionalInt.empty()).version("1.0.0").schemaVersion(ExtensionConverter.getCurrentSchemaVersion()).addAction(new StepAction.Builder().id("action-1").name("action-1-name").description("Action 1 Description").pattern(Action.Pattern.From).descriptor(new StepDescriptor.Builder().entrypoint("direct:hello").kind(StepAction.Kind.ENDPOINT).build()).build()).build();
    JsonNode tree = converter.toPublicExtension(extension);
    ProcessingReport report = schema.validate(tree);
    assertFalse(report.toString(), report.iterator().hasNext());
    Extension extensionClone = converter.toInternalExtension(tree);
    assertEquals(extensionClone, extension);
}
Also used : Extension(io.syndesis.common.model.extension.Extension) ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) JsonSchema(com.github.fge.jsonschema.main.JsonSchema) StepDescriptor(io.syndesis.common.model.action.StepDescriptor) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Aggregations

Extension (io.syndesis.common.model.extension.Extension)19 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Test (org.junit.Test)5 Connection (io.syndesis.common.model.connection.Connection)4 Step (io.syndesis.common.model.integration.Step)4 ProcessingReport (com.github.fge.jsonschema.core.report.ProcessingReport)3 JsonSchema (com.github.fge.jsonschema.main.JsonSchema)3 Connector (io.syndesis.common.model.connection.Connector)3 Integration (io.syndesis.common.model.integration.Integration)3 Date (java.util.Date)3 Action (io.syndesis.common.model.action.Action)2 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)2 StepAction (io.syndesis.common.model.action.StepAction)2 DataManager (io.syndesis.server.dao.manager.DataManager)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 POST (javax.ws.rs.POST)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ApiResponses (io.swagger.annotations.ApiResponses)1