use of io.syndesis.connector.support.verifier.api.SyndesisMetadata 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 io.syndesis.connector.support.verifier.api.SyndesisMetadata in project syndesis by syndesisio.
the class SalesforceMetadataRetrievalTest method shouldAdaptObjectTypesMetadataForPropertiesLegacy.
@Test
public void shouldAdaptObjectTypesMetadataForPropertiesLegacy() throws IOException {
final JsonNode payload = new ObjectMapper().readTree("[{\"name\":\"Object1\",\"label\":\"Object1 Label\"},{\"name\":\"Object2\",\"label\":\"Object2 Label\"}]");
final SyndesisMetadata metadata = adapter.adapt(null, null, null, NOT_USED, MetaDataBuilder.on(CONTEXT).withAttribute("scope", "object_types").withPayload(payload).build());
assertThat(metadata.properties).containsKey("sObjectName");
final List<PropertyPair> values = metadata.properties.get("sObjectName");
assertThat(values).containsOnly(new PropertyPair("Object1", "Object1 Label"), new PropertyPair("Object2", "Object2 Label"));
}
use of io.syndesis.connector.support.verifier.api.SyndesisMetadata in project syndesis by syndesisio.
the class SalesforceMetadataRetrievalTest method shouldAdaptObjectMetadataForSchema.
@Test
public void shouldAdaptObjectMetadataForSchema() throws IOException {
final Map<String, Object> properties = new HashMap<>();
properties.put("sObjectName", "SimpleObject");
final SyndesisMetadata metadata = adapter.adapt(null, null, null, properties, MetaDataBuilder.on(CONTEXT).withAttribute("scope", "object").withPayload(payload).build());
assertThat(metadata.inputShape).isSameAs(metadata.inputShape);
final Object oneOf = payload.getOneOf().iterator().next();
final ObjectSchema inSchema = Json.reader().forType(ObjectSchema.class).readValue(metadata.inputShape.getSpecification());
assertThat(inSchema).isEqualTo(oneOf);
assertThat(inSchema.get$schema()).isEqualTo(JsonUtils.SCHEMA4);
}
use of io.syndesis.connector.support.verifier.api.SyndesisMetadata 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 io.syndesis.connector.support.verifier.api.SyndesisMetadata 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