Search in sources :

Example 1 with SyndesisMetadata

use of io.syndesis.connector.support.verifier.api.SyndesisMetadata in project syndesis by syndesisio.

the class SalesforceMetadataRetrievalTest method shouldAdaptObjectMetadataForProperties.

@Test
public void shouldAdaptObjectMetadataForProperties() {
    final Map<String, Object> properties = new HashMap<>();
    properties.put("sObjectName", "SimpleObject");
    properties.put("sObjectIdName", null);
    final SyndesisMetadata metadata = adapter.adapt(null, null, null, properties, MetaDataBuilder.on(CONTEXT).withAttribute("scope", "object").withPayload(payload).build());
    assertThat(metadata.properties).containsKey("sObjectIdName");
    final List<PropertyPair> values = metadata.properties.get("sObjectIdName");
    assertThat(values).containsOnly(new PropertyPair("uniqueProperty1", "Unique property 1"), new PropertyPair("uniqueProperty2", "Unique property 2"));
}
Also used : SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) HashMap(java.util.HashMap) PropertyPair(io.syndesis.connector.support.verifier.api.PropertyPair) Test(org.junit.Test)

Example 2 with SyndesisMetadata

use of io.syndesis.connector.support.verifier.api.SyndesisMetadata in project syndesis by syndesisio.

the class SalesforceMetadataRetrievalTest method shouldAdaptObjectTypesMetadataForProperties.

@Test
public void shouldAdaptObjectTypesMetadataForProperties() {
    final ObjectSchema globalObjectsPayload = new ObjectSchema();
    final HashSet<Object> oneOf = new HashSet<>();
    oneOf.add(simpleObjectSchema("Object1", "Object1 Label"));
    oneOf.add(simpleObjectSchema("Object2", "Object2 Label"));
    globalObjectsPayload.setOneOf(oneOf);
    final SyndesisMetadata metadata = adapter.adapt(null, null, null, NOT_USED, MetaDataBuilder.on(CONTEXT).withPayload(globalObjectsPayload).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) ObjectSchema(com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema) PropertyPair(io.syndesis.connector.support.verifier.api.PropertyPair) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with SyndesisMetadata

use of io.syndesis.connector.support.verifier.api.SyndesisMetadata 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);
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) SqlStoredConnectorMetaDataExtension(io.syndesis.connector.sql.stored.SqlStoredConnectorMetaDataExtension) 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 4 with SyndesisMetadata

use of io.syndesis.connector.support.verifier.api.SyndesisMetadata in project syndesis by syndesisio.

the class SqlMetadataRetrieval method adaptForSql.

@SuppressWarnings({ "PMD.CyclomaticComplexity", "PMD.StdCyclomaticComplexity", "PMD.ModifiedCyclomaticComplexity" })
public SyndesisMetadata adaptForSql(final String actionId, final Map<String, Object> properties, final MetaData metadata) {
    final Map<String, List<PropertyPair>> enrichedProperties = new HashMap<>();
    final List<PropertyPair> ppList = new ArrayList<>();
    @SuppressWarnings("unchecked") final SqlStatementMetaData sqlStatementMetaData = (SqlStatementMetaData) metadata.getPayload();
    if (sqlStatementMetaData != null) {
        ppList.add(new PropertyPair(sqlStatementMetaData.getSqlStatement(), QUERY));
        enrichedProperties.put(QUERY, ppList);
        // build the input and output schemas
        final ObjectSchema builderIn = new ObjectSchema();
        builderIn.set$schema("http://json-schema.org/schema#");
        builderIn.setTitle("SQL_PARAM_IN");
        for (SqlParam inParam : sqlStatementMetaData.getInParams()) {
            builderIn.putProperty(inParam.getName(), schemaFor(inParam.getJdbcType()));
        }
        final ObjectSchema builderOut = new ObjectSchema();
        builderOut.setTitle("SQL_PARAM_OUT");
        builderOut.set$schema("http://json-schema.org/schema#");
        for (SqlParam outParam : sqlStatementMetaData.getOutParams()) {
            builderOut.putProperty(outParam.getName(), schemaFor(outParam.getJdbcType()));
        }
        try {
            DataShape.Builder inDataShapeBuilder = new DataShape.Builder().type(builderIn.getTitle());
            if (builderIn.getProperties().isEmpty()) {
                inDataShapeBuilder.kind(DataShapeKinds.NONE);
            } else {
                inDataShapeBuilder.kind(DataShapeKinds.JSON_SCHEMA).name("SQL Parameter").description(String.format("Parameters of SQL [%s]", sqlStatementMetaData.getSqlStatement())).specification(Json.writer().writeValueAsString(builderIn));
            }
            DataShape.Builder outDataShapeBuilder = new DataShape.Builder().type(builderOut.getTitle());
            if (builderOut.getProperties().isEmpty()) {
                outDataShapeBuilder.kind(DataShapeKinds.NONE);
            } else {
                outDataShapeBuilder.kind(DataShapeKinds.JSON_SCHEMA).name("SQL Result").description(String.format("Result of SQL [%s]", sqlStatementMetaData.getSqlStatement())).specification(Json.writer().writeValueAsString(builderOut));
            }
            return new SyndesisMetadata(enrichedProperties, inDataShapeBuilder.build(), outDataShapeBuilder.build());
        } catch (JsonProcessingException e) {
            throw new IllegalStateException(e);
        }
    } else {
        return new SyndesisMetadata(enrichedProperties, null, null);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PropertyPair(io.syndesis.connector.support.verifier.api.PropertyPair) DataShape(io.syndesis.common.model.DataShape) SqlStatementMetaData(io.syndesis.connector.sql.common.SqlStatementMetaData) SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) ObjectSchema(com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema) ArrayList(java.util.ArrayList) List(java.util.List) SqlParam(io.syndesis.connector.sql.common.SqlParam) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 5 with SyndesisMetadata

use of io.syndesis.connector.support.verifier.api.SyndesisMetadata in project syndesis by syndesisio.

the class ActionDefinitionEndpointTest method shouldMetadata.

@Test
public void shouldMetadata() throws Exception {
    final CamelContext context = new DefaultCamelContext();
    context.addComponent("petstore", new PetstoreComponent(PAYLOAD));
    try {
        context.start();
        final PetstoreMetadataRetrieval adapter = new PetstoreMetadataRetrieval(PAYLOAD, PROPERTIES, INPUT, OUTPUT);
        final SyndesisMetadata metadata = adapter.fetch(context, "petstore", "dog-food", Collections.emptyMap());
        assertThat(metadata.properties).isSameAs(PROPERTIES);
        assertThat(metadata.inputShape).isSameAs(INPUT);
        assertThat(metadata.outputShape).isSameAs(OUTPUT);
    } finally {
        context.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) 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