use of io.syndesis.server.endpoint.v1.dto.MetaData in project syndesis by syndesisio.
the class ConnectionActionHandler method applyMetadataTo.
private static ConnectorDescriptor applyMetadataTo(final ConnectorDescriptor descriptor, final DynamicActionMetadata dynamicMetadata) {
final Map<String, List<DynamicActionMetadata.ActionPropertySuggestion>> actionPropertySuggestions = dynamicMetadata.properties();
final ConnectorDescriptor.Builder enriched = new ConnectorDescriptor.Builder().createFrom(descriptor);
actionPropertySuggestions.forEach((k, vals) -> enriched.replaceConfigurationProperty(k, b -> b.addAllEnum(vals.stream().map(s -> ConfigurationProperty.PropertyValue.Builder.from(s))::iterator)));
// Setting the defaultValue as suggested by the metadata
for (final Entry<String, List<DynamicActionMetadata.ActionPropertySuggestion>> suggestions : actionPropertySuggestions.entrySet()) {
if (suggestions.getValue().size() == 1) {
for (final DynamicActionMetadata.ActionPropertySuggestion suggestion : suggestions.getValue()) {
enriched.replaceConfigurationProperty(suggestion.displayValue(), v -> v.defaultValue(suggestion.value()));
}
}
}
final DataShape input = dynamicMetadata.inputShape();
if (shouldEnrichDataShape(descriptor.getInputDataShape(), input)) {
enriched.inputDataShape(input);
}
final DataShape output = dynamicMetadata.outputShape();
if (shouldEnrichDataShape(descriptor.getOutputDataShape(), output)) {
enriched.outputDataShape(output);
}
return adaptDataShapes(enriched);
}
use of io.syndesis.server.endpoint.v1.dto.MetaData in project syndesis by syndesisio.
the class ConnectionActionHandlerTest method shouldAddMetaAndSetStatusToBadRequestIfMetaCallFails.
@Test
public void shouldAddMetaAndSetStatusToBadRequestIfMetaCallFails() {
@SuppressWarnings({ "unchecked", "rawtypes" }) final Class<Entity<Map<String, Object>>> entityType = (Class) Entity.class;
ArgumentCaptor.forClass(entityType);
// simulates fallback return
final DynamicActionMetadata fallback = new DynamicActionMetadata.Builder().build();
when(metadataCommand.execute()).thenReturn(fallback);
when(((HystrixInvokableInfo<?>) metadataCommand).isSuccessfulExecution()).thenReturn(false);
final Response response = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE, Collections.emptyMap());
assertThat(response.getStatus()).isEqualTo(Status.BAD_REQUEST.getStatusCode());
@SuppressWarnings("unchecked") final Meta<ConnectorDescriptor> meta = (Meta<ConnectorDescriptor>) response.getEntity();
final ConnectorDescriptor descriptor = new ConnectorDescriptor.Builder().createFrom(createOrUpdateSalesforceObjectDescriptor).inputDataShape(//
ConnectionActionHandler.ANY_SHAPE).outputDataShape(//
salesforceOutputShape).build();
assertThat(meta.getValue()).isEqualTo(descriptor);
final MetaData metadata = meta.getData();
assertThat(metadata).isNotNull();
assertThat(metadata.getType()).contains(MetaData.Type.WARNING);
assertThat(metadata.getMessage()).contains("The query did not succeed");
}
Aggregations