use of org.apache.camel.component.extension.MetaDataExtension.MetaData in project syndesis by syndesisio.
the class SqlMetadataAdapterTest method adaptForSqlStoredTest.
@Test
public void adaptForSqlStoredTest() throws IOException, JSONException {
CamelContext camelContext = new DefaultCamelContext();
SqlStoredConnectorMetaDataExtension ext = new SqlStoredConnectorMetaDataExtension(camelContext);
Map<String, Object> parameters = new HashMap<>();
for (final String name : properties.stringPropertyNames()) {
parameters.put(name.substring(name.indexOf(".") + 1), properties.getProperty(name));
}
Optional<MetaData> metadata = ext.meta(parameters);
SqlMetadataRetrieval adapter = new SqlMetadataRetrieval();
SyndesisMetadata syndesisMetaData = adapter.adapt(camelContext, "sql", "sql-stored-connector", parameters, metadata.get());
String expectedListOfProcedures = IOUtils.toString(this.getClass().getResource("/sql/stored_procedure_list.json"), StandardCharsets.UTF_8).trim();
ObjectWriter writer = Json.writer();
String actualListOfProcedures = writer.with(writer.getConfig().getDefaultPrettyPrinter()).writeValueAsString(syndesisMetaData);
assertEquals(expectedListOfProcedures, actualListOfProcedures, JSONCompareMode.STRICT);
parameters.put(SqlMetadataRetrieval.PATTERN, SqlMetadataRetrieval.FROM_PATTERN);
String expectedListOfStartProcedures = IOUtils.toString(this.getClass().getResource("/sql/stored_procedure_list.json"), StandardCharsets.UTF_8).trim();
String actualListOfStartProcedures = writer.with(writer.getConfig().getDefaultPrettyPrinter()).writeValueAsString(syndesisMetaData);
assertEquals(expectedListOfStartProcedures, actualListOfStartProcedures, JSONCompareMode.STRICT);
parameters.put("procedureName", "DEMO_ADD");
SyndesisMetadata syndesisMetaData2 = adapter.adapt(camelContext, "sql", "sql-stored-connector", parameters, metadata.get());
String expectedMetadata = IOUtils.toString(this.getClass().getResource("/sql/demo_add_metadata.json"), StandardCharsets.UTF_8).trim();
String actualMetadata = writer.with(writer.getConfig().getDefaultPrettyPrinter()).writeValueAsString(syndesisMetaData2);
assertEquals(expectedMetadata, actualMetadata, JSONCompareMode.STRICT);
}
use of org.apache.camel.component.extension.MetaDataExtension.MetaData in project syndesis by syndesisio.
the class SalesforceMetadataRetrieval method adapt.
@Override
protected SyndesisMetadata adapt(final CamelContext context, final String componentId, final String actionId, final Map<String, Object> properties, final MetaData metadata) {
final ObjectSchema schema = schemaPayload(metadata);
Set<ObjectSchema> schemasToConsider;
if (isPresentAndNonNull(properties, SalesforceEndpointConfig.SOBJECT_NAME)) {
schemasToConsider = Collections.singleton(objectSchemaFrom(schema));
} else {
schemasToConsider = //
schema.getOneOf().stream().filter(SalesforceMetadataRetrieval::isObjectSchema).map(ObjectSchema.class::cast).collect(Collectors.toSet());
}
final Map<String, List<PropertyPair>> enrichedProperties = new HashMap<>();
enrichedProperties.put(SalesforceEndpointConfig.SOBJECT_NAME, //
schemasToConsider.stream().map(SalesforceMetadataRetrieval::nameAndTitlePropertyPairOf).collect(Collectors.toList()));
if (isPresent(properties, SalesforceEndpointConfig.SOBJECT_EXT_ID_NAME)) {
enrichedProperties.put(SalesforceEndpointConfig.SOBJECT_EXT_ID_NAME, //
schemasToConsider.stream().flatMap(s -> s.getProperties().entrySet().stream()).filter(//
e -> isIdLookup(e.getValue())).map(SalesforceMetadataRetrieval::createFieldPairPropertyFromSchemaEntry).collect(Collectors.toList()));
}
if (isPresentAndNonNull(properties, SalesforceEndpointConfig.SOBJECT_NAME)) {
try {
final String objectName = (String) properties.get(SalesforceEndpointConfig.SOBJECT_NAME);
final ObjectSchema inputOutputSchema = inputOutputSchemaFor(schemasToConsider, objectName);
final String specification = Json.writer().writeValueAsString(inputOutputSchema);
return new //
SyndesisMetadata(//
enrichedProperties, //
new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA).type(//
inputOutputSchema.getTitle()).name(//
"Salesforce " + objectName).description(//
"Salesforce " + objectName).specification(specification).build(), //
new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA).type(//
inputOutputSchema.getTitle()).name(//
"Salesforce " + objectName).description(//
"Salesforce " + objectName).specification(specification).build());
} catch (final JsonProcessingException e) {
throw new IllegalStateException(e);
}
}
return new SyndesisMetadata(enrichedProperties, null, null);
}
use of org.apache.camel.component.extension.MetaDataExtension.MetaData in project syndesis by syndesisio.
the class SqlMetadataAdapterTest method adaptForSqlNoParamTest.
@Test
public void adaptForSqlNoParamTest() throws IOException, JSONException {
CamelContext camelContext = new DefaultCamelContext();
SqlConnectorMetaDataExtension ext = new SqlConnectorMetaDataExtension(camelContext);
Map<String, Object> parameters = new HashMap<>();
for (final String name : properties.stringPropertyNames()) {
parameters.put(name.substring(name.indexOf('.') + 1), properties.getProperty(name));
}
parameters.put("query", "SELECT * FROM NAME");
Optional<MetaData> metadata = ext.meta(parameters);
SqlMetadataRetrieval adapter = new SqlMetadataRetrieval();
SyndesisMetadata syndesisMetaData2 = adapter.adapt(camelContext, "sql", "sql-connector", parameters, metadata.get());
String expectedMetadata = IOUtils.toString(this.getClass().getResource("/sql/name_sql_no_param_metadata.json"), StandardCharsets.UTF_8).trim();
ObjectWriter writer = Json.writer();
String actualMetadata = writer.with(writer.getConfig().getDefaultPrettyPrinter()).writeValueAsString(syndesisMetaData2);
assertEquals(expectedMetadata, actualMetadata, JSONCompareMode.STRICT);
}
use of org.apache.camel.component.extension.MetaDataExtension.MetaData in project syndesis by syndesisio.
the class SqlMetadataAdapterTest method adaptForSqlTest.
@Test
public void adaptForSqlTest() throws IOException, JSONException {
CamelContext camelContext = new DefaultCamelContext();
SqlConnectorMetaDataExtension ext = new SqlConnectorMetaDataExtension(camelContext);
Map<String, Object> parameters = new HashMap<>();
for (final String name : properties.stringPropertyNames()) {
parameters.put(name.substring(name.indexOf('.') + 1), properties.getProperty(name));
}
parameters.put("query", "SELECT * FROM NAME WHERE ID=:#id");
Optional<MetaData> metadata = ext.meta(parameters);
SqlMetadataRetrieval adapter = new SqlMetadataRetrieval();
SyndesisMetadata syndesisMetaData2 = adapter.adapt(camelContext, "sql", "sql-connector", parameters, metadata.get());
String expectedMetadata = IOUtils.toString(this.getClass().getResource("/sql/name_sql_metadata.json"), StandardCharsets.UTF_8).trim();
ObjectWriter writer = Json.writer();
String actualMetadata = writer.with(writer.getConfig().getDefaultPrettyPrinter()).writeValueAsString(syndesisMetaData2);
assertEquals(expectedMetadata, actualMetadata, JSONCompareMode.STRICT);
}
Aggregations