Search in sources :

Example 1 with ReadApiClientData

use of io.syndesis.server.dao.init.ReadApiClientData in project syndesis by syndesisio.

the class DataManager method loadData.

private void loadData() {
    try {
        final ResourcePatternResolver resolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
        final Resource[] resources = resolver.getResources("classpath:/META-INF/syndesis/connector/*.json");
        if (resources != null) {
            ReadApiClientData reader = new ReadApiClientData(encryptionComponent);
            for (Resource resource : resources) {
                try (InputStream is = resource.getInputStream()) {
                    // Replace placeholders
                    final String text = reader.findAndReplaceTokens(StreamUtils.copyToString(is, StandardCharsets.UTF_8), System.getenv());
                    Connector connector = Json.reader().forType(Connector.class).readValue(text);
                    if (connector != null) {
                        LOGGER.info("Load connector: {} from resource: {}", connector.getId().orElse(""), resource.getURI());
                        store(connector, Connector.class);
                    }
                }
            }
        }
    } catch (FileNotFoundException ignored) {
    // ignore
    } catch (IOException e) {
        throw new IllegalStateException("Cannot load connector from resources due to: " + e.getMessage(), e);
    }
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ReadApiClientData(io.syndesis.server.dao.init.ReadApiClientData)

Example 2 with ReadApiClientData

use of io.syndesis.server.dao.init.ReadApiClientData in project syndesis by syndesisio.

the class ReadApiClientDataTest method tokenReplacementDataTest.

@Test
public void tokenReplacementDataTest() throws IOException {
    final String fileName = "io/syndesis/server/dao/test-data.json";
    final Map<String, String> env = new HashMap<>();
    env.put("POSTGRESQL_SAMPLEDB_PASSWORD", "password123");
    try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName)) {
        ReadApiClientData readApiClientData = new ReadApiClientData();
        String jsonText = readApiClientData.from(is);
        jsonText = readApiClientData.findAndReplaceTokens(jsonText, env);
        Assert.assertTrue(jsonText.contains("@SECRET_NOT_IN_ENV@"));
        Assert.assertFalse(jsonText.contains("@POSTGRESQL_SAMPLEDB_PASSWORD@"));
        // passing in the updated String with replaced tokens
        List<ModelData<?>> modelDataList = readApiClientData.readDataFromString(jsonText);
        Assert.assertTrue("We should find some ModelData", 0 < modelDataList.size());
        // the second item is the sampledb-connection
        Connection connection = (Connection) modelDataList.get(1).getData();
        String pw = connection.getConfiguredProperties().get("password");
        Assert.assertEquals("password123", pw);
    }
}
Also used : ModelData(io.syndesis.common.model.ModelData) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Connection(io.syndesis.common.model.connection.Connection) ReadApiClientData(io.syndesis.server.dao.init.ReadApiClientData) Test(org.junit.Test)

Example 3 with ReadApiClientData

use of io.syndesis.server.dao.init.ReadApiClientData in project syndesis by syndesisio.

the class ReadApiClientDataTest method loadApiClientDataTest.

@Test
public void loadApiClientDataTest() throws IOException {
    List<ModelData<?>> modelDataList = new ReadApiClientData().readDataFromFile("io/syndesis/server/dao/deployment.json");
    Assert.assertTrue("We should find some ModelData", 0 < modelDataList.size());
    List<Object> items = new ArrayList<>();
    for (ModelData<?> md : modelDataList) {
        if (md.getKind() == Kind.ConnectorTemplate) {
            items.add(md.getData());
        }
    }
    Assert.assertFalse("We should find some Connectors", items.isEmpty());
}
Also used : ModelData(io.syndesis.common.model.ModelData) ArrayList(java.util.ArrayList) ReadApiClientData(io.syndesis.server.dao.init.ReadApiClientData) Test(org.junit.Test)

Example 4 with ReadApiClientData

use of io.syndesis.server.dao.init.ReadApiClientData in project syndesis by syndesisio.

the class Application method generateIntegrationProject.

private void generateIntegrationProject(File project) throws IOException {
    final ReadApiClientData reader = new ReadApiClientData();
    final ArrayList<Step> steps = new ArrayList<>();
    String deploymentText;
    try (InputStream is = resourceLoader.getResource("io/syndesis/server/dao/deployment.json").getInputStream()) {
        deploymentText = reader.from(is);
    }
    final List<ModelData<?>> modelList = reader.readDataFromString(deploymentText);
    for (final ModelData<?> model : modelList) {
        if (model.getKind() == Kind.Connector) {
            final Connector connector = (Connector) model.getData();
            for (final Action action : connector.getActions()) {
                steps.add(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().connector(connector).connectorId(connector.getId().get()).build()).action(action).build());
            }
        }
        if (model.getKind() == Kind.ConnectorTemplate) {
            final ConnectorTemplate template = (ConnectorTemplate) model.getData();
            steps.add(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().connectorId("connector-" + template.getId()).build()).action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().camelConnectorGAV(template.getCamelConnectorGAV()).camelConnectorPrefix(template.getCamelConnectorPrefix()).build()).build()).build());
        }
    }
    try {
        final ResourcePatternResolver resolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
        final Resource[] resources = resolver.getResources("classpath:/META-INF/syndesis/connector/*.json");
        if (resources != null) {
            for (Resource resource : resources) {
                Connector connector = Json.reader().forType(Connector.class).readValue(resource.getInputStream());
                if (connector != null) {
                    for (final Action action : connector.getActions()) {
                        steps.add(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().connector(connector).connectorId(connector.getId().get()).build()).action(action).build());
                    }
                }
            }
        }
    } catch (FileNotFoundException ignored) {
    // ignore
    }
    Integration integration = new Integration.Builder().id("Integration").name("Integration").description("This integration is used to prime the .m2 repo").steps(steps).build();
    generate(integration, project);
}
Also used : ModelData(io.syndesis.common.model.ModelData) Connector(io.syndesis.common.model.connection.Connector) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Action(io.syndesis.common.model.action.Action) Integration(io.syndesis.common.model.integration.Integration) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Connection(io.syndesis.common.model.connection.Connection) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) FileNotFoundException(java.io.FileNotFoundException) Step(io.syndesis.common.model.integration.Step) ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) ReadApiClientData(io.syndesis.server.dao.init.ReadApiClientData)

Example 5 with ReadApiClientData

use of io.syndesis.server.dao.init.ReadApiClientData in project syndesis by syndesisio.

the class GenerateMapperInspectionsMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        final Resource resource = new Resource();
        resource.setDirectory(outputDir.getCanonicalPath());
        project.addResource(resource);
        final Set<File> generated = new HashSet<>();
        final ReadApiClientData reader = new ReadApiClientData();
        final List<ModelData<?>> modelList = reader.readDataFromFile("io/syndesis/server/dao/deployment.json");
        for (final ModelData<?> model : modelList) {
            if (model.getKind() == Kind.Connector) {
                final Connector connector = (Connector) model.getData();
                for (final ConnectorAction action : connector.getActions()) {
                    process(generated, connector, action, action.getInputDataShape());
                    process(generated, connector, action, action.getOutputDataShape());
                }
            }
        }
    } catch (final IOException e) {
        throw new MojoFailureException(e.getMessage(), e);
    }
}
Also used : ModelData(io.syndesis.common.model.ModelData) Connector(io.syndesis.common.model.connection.Connector) Resource(org.apache.maven.model.Resource) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) IOException(java.io.IOException) File(java.io.File) HashSet(java.util.HashSet) ReadApiClientData(io.syndesis.server.dao.init.ReadApiClientData)

Aggregations

ReadApiClientData (io.syndesis.server.dao.init.ReadApiClientData)5 ModelData (io.syndesis.common.model.ModelData)4 Connector (io.syndesis.common.model.connection.Connector)3 InputStream (java.io.InputStream)3 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)2 Connection (io.syndesis.common.model.connection.Connection)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Resource (org.springframework.core.io.Resource)2 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)2 Action (io.syndesis.common.model.action.Action)1 ConnectorTemplate (io.syndesis.common.model.connection.ConnectorTemplate)1 Integration (io.syndesis.common.model.integration.Integration)1 Step (io.syndesis.common.model.integration.Step)1 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Resource (org.apache.maven.model.Resource)1