Search in sources :

Example 1 with PropertyPair

use of io.syndesis.connector.support.verifier.api.PropertyPair 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 PropertyPair

use of io.syndesis.connector.support.verifier.api.PropertyPair 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 PropertyPair

use of io.syndesis.connector.support.verifier.api.PropertyPair 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 4 with PropertyPair

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

the class SqlMetadataRetrieval method obtainFromProcedureList.

/**
 * Puts stored procedures in the list that have NO input parameters, which adheres to the `From`
 * pattern.
 *
 * @param procedureMap
 * @return list of property pairs containing the stored procedure names
 */
private List<PropertyPair> obtainFromProcedureList(Map<String, StoredProcedureMetadata> procedureMap) {
    final List<PropertyPair> ppList = new ArrayList<>();
    for (final StoredProcedureMetadata storedProcedure : procedureMap.values()) {
        if (!containsInputParams(storedProcedure)) {
            final PropertyPair pp = new PropertyPair(storedProcedure.getName(), storedProcedure.getName());
            ppList.add(pp);
        }
    }
    return ppList;
}
Also used : ArrayList(java.util.ArrayList) PropertyPair(io.syndesis.connector.support.verifier.api.PropertyPair) StoredProcedureMetadata(io.syndesis.connector.sql.common.stored.StoredProcedureMetadata)

Example 5 with PropertyPair

use of io.syndesis.connector.support.verifier.api.PropertyPair 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)

Aggregations

PropertyPair (io.syndesis.connector.support.verifier.api.PropertyPair)8 SyndesisMetadata (io.syndesis.connector.support.verifier.api.SyndesisMetadata)6 ObjectSchema (com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 DataShape (io.syndesis.common.model.DataShape)3 List (java.util.List)3 Test (org.junit.Test)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 StoredProcedureMetadata (io.syndesis.connector.sql.common.stored.StoredProcedureMetadata)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 Json (io.syndesis.common.util.Json)1 SyndesisServerException (io.syndesis.common.util.SyndesisServerException)1 SqlParam (io.syndesis.connector.sql.common.SqlParam)1