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"));
}
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"));
}
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);
}
}
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;
}
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);
}
Aggregations