Search in sources :

Example 6 with PropertyPair

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

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

the class SqlMetadataRetrieval method adaptForStoredSql.

@SuppressWarnings({ "PMD.CyclomaticComplexity", "PMD.StdCyclomaticComplexity", "PMD.ModifiedCyclomaticComplexity" })
public SyndesisMetadata adaptForStoredSql(final String actionId, final Map<String, Object> properties, final MetaData metadata) {
    final Map<String, List<PropertyPair>> enrichedProperties = new HashMap<>();
    if (isPresentAndNonNull(properties, PROCEDURE_NAME)) {
        // fetch metadata for the named procedure
        final List<PropertyPair> ppList = new ArrayList<>();
        @SuppressWarnings("unchecked") final Map<String, StoredProcedureMetadata> procedureMap = (Map<String, StoredProcedureMetadata>) metadata.getPayload();
        final String procedureName = (String) properties.get(PROCEDURE_NAME);
        final StoredProcedureMetadata storedProcedure = procedureMap.get(procedureName);
        ppList.add(new PropertyPair(storedProcedure.getTemplate(), PROCEDURE_TEMPLATE));
        enrichedProperties.put(PROCEDURE_TEMPLATE, ppList);
        // build the input and output schemas
        final ObjectSchema builderIn = new ObjectSchema();
        builderIn.set$schema("http://json-schema.org/schema#");
        builderIn.setTitle(procedureName + "_IN");
        final ObjectSchema builderOut = new ObjectSchema();
        builderOut.setTitle(procedureName + "_OUT");
        builderOut.set$schema("http://json-schema.org/schema#");
        if (storedProcedure.getColumnList() != null && !storedProcedure.getColumnList().isEmpty()) {
            for (final StoredProcedureColumn column : storedProcedure.getColumnList()) {
                if (column.getMode().equals(ColumnMode.IN) || column.getMode().equals(ColumnMode.INOUT)) {
                    builderIn.putProperty(column.getName(), schemaFor(column.getJdbcType()));
                }
                if (column.getMode().equals(ColumnMode.OUT) || column.getMode().equals(ColumnMode.INOUT)) {
                    builderOut.putProperty(column.getName(), schemaFor(column.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(procedureName + " Parameter").description(String.format("Parameters of Stored Procedure '%s'", procedureName)).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(procedureName + " Return").description(String.format("Return value of Stored Procedure '%s'", procedureName)).specification(Json.writer().writeValueAsString(builderOut));
            }
            return new SyndesisMetadata(enrichedProperties, inDataShapeBuilder.build(), outDataShapeBuilder.build());
        } catch (JsonProcessingException e) {
            throw new IllegalStateException(e);
        }
    }
    // return list of stored procedures in the database
    @SuppressWarnings("unchecked") final Map<String, StoredProcedureMetadata> procedureMap = (Map<String, StoredProcedureMetadata>) metadata.getPayload();
    if (isPresentAndNonNull(properties, PATTERN) && FROM_PATTERN.equalsIgnoreCase(String.valueOf(properties.get(PATTERN)))) {
        enrichedProperties.put(PROCEDURE_NAME, obtainFromProcedureList(procedureMap));
    } else {
        enrichedProperties.put(PROCEDURE_NAME, obtainToProcedureList(procedureMap));
    }
    return new SyndesisMetadata(enrichedProperties, null, null);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PropertyPair(io.syndesis.connector.support.verifier.api.PropertyPair) StoredProcedureColumn(io.syndesis.connector.sql.common.stored.StoredProcedureColumn) DataShape(io.syndesis.common.model.DataShape) StoredProcedureMetadata(io.syndesis.connector.sql.common.stored.StoredProcedureMetadata) SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) ObjectSchema(com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 8 with PropertyPair

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

the class SqlMetadataRetrieval method obtainToProcedureList.

/**
 * Puts all stored procedures in the list, as all queries adhere to the `To` pattern.
 *
 * @param procedureMap
 * @return list of property pairs containing the stored procedure names
 */
private List<PropertyPair> obtainToProcedureList(Map<String, StoredProcedureMetadata> procedureMap) {
    final List<PropertyPair> ppList = new ArrayList<>();
    for (final String storedProcedureName : procedureMap.keySet()) {
        final PropertyPair pp = new PropertyPair(storedProcedureName, storedProcedureName);
        ppList.add(pp);
    }
    return ppList;
}
Also used : ArrayList(java.util.ArrayList) PropertyPair(io.syndesis.connector.support.verifier.api.PropertyPair)

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