Search in sources :

Example 6 with SyndesisMetadata

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);
}
Also used : PropertyPair(io.syndesis.connector.support.verifier.api.PropertyPair) MetaData(org.apache.camel.component.extension.MetaDataExtension.MetaData) HashMap(java.util.HashMap) ComponentMetadataRetrieval(io.syndesis.connector.support.verifier.api.ComponentMetadataRetrieval) HashSet(java.util.HashSet) SimpleTypeSchema(com.fasterxml.jackson.module.jsonSchema.types.SimpleTypeSchema) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonUtils(org.apache.camel.component.salesforce.api.utils.JsonUtils) CamelContext(org.apache.camel.CamelContext) DataShape(io.syndesis.common.model.DataShape) SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) JsonSchema(com.fasterxml.jackson.module.jsonSchema.JsonSchema) ObjectSchema(com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) DataShapeKinds(io.syndesis.common.model.DataShapeKinds) List(java.util.List) SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) SyndesisServerException(io.syndesis.common.util.SyndesisServerException) Entry(java.util.Map.Entry) SalesforceEndpointConfig(org.apache.camel.component.salesforce.SalesforceEndpointConfig) Collections(java.util.Collections) Json(io.syndesis.common.util.Json) HashMap(java.util.HashMap) DataShape(io.syndesis.common.model.DataShape) SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) ObjectSchema(com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema) List(java.util.List) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 7 with SyndesisMetadata

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"));
}
Also used : SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) JsonNode(com.fasterxml.jackson.databind.JsonNode) PropertyPair(io.syndesis.connector.support.verifier.api.PropertyPair) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 8 with SyndesisMetadata

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);
}
Also used : SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) ObjectSchema(com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 9 with SyndesisMetadata

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);
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) HashMap(java.util.HashMap) MetaData(org.apache.camel.component.extension.MetaDataExtension.MetaData) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 10 with SyndesisMetadata

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);
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) HashMap(java.util.HashMap) MetaData(org.apache.camel.component.extension.MetaDataExtension.MetaData) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

SyndesisMetadata (io.syndesis.connector.support.verifier.api.SyndesisMetadata)11 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 PropertyPair (io.syndesis.connector.support.verifier.api.PropertyPair)6 ObjectSchema (com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema)5 CamelContext (org.apache.camel.CamelContext)5 MetaData (org.apache.camel.component.extension.MetaDataExtension.MetaData)4 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)3 DataShape (io.syndesis.common.model.DataShape)3 List (java.util.List)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JsonSchema (com.fasterxml.jackson.module.jsonSchema.JsonSchema)1 SimpleTypeSchema (com.fasterxml.jackson.module.jsonSchema.types.SimpleTypeSchema)1 DataShapeKinds (io.syndesis.common.model.DataShapeKinds)1