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);
}
}
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);
}
}
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());
}
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);
}
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);
}
}
Aggregations