Search in sources :

Example 1 with MetaData

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);
}
Also used : ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) HashMap(java.util.HashMap) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) ApiResponses(io.swagger.annotations.ApiResponses) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) Map(java.util.Map) EntityNotFoundException(javax.persistence.EntityNotFoundException) Api(io.swagger.annotations.Api) Status(javax.ws.rs.core.Response.Status) POST(javax.ws.rs.POST) DataShape(io.syndesis.common.model.DataShape) MetadataConfigurationProperties(io.syndesis.server.verifier.MetadataConfigurationProperties) Connector(io.syndesis.common.model.connection.Connector) Collectors(java.util.stream.Collectors) DataShapeKinds(io.syndesis.common.model.DataShapeKinds) Meta(io.syndesis.server.endpoint.v1.dto.Meta) List(java.util.List) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) HystrixExecutable(com.netflix.hystrix.HystrixExecutable) DynamicActionMetadata(io.syndesis.common.model.connection.DynamicActionMetadata) Entry(java.util.Map.Entry) Optional(java.util.Optional) ConnectionBase(io.syndesis.common.model.connection.ConnectionBase) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) DynamicActionMetadata(io.syndesis.common.model.connection.DynamicActionMetadata) List(java.util.List) DataShape(io.syndesis.common.model.DataShape)

Example 2 with MetaData

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");
}
Also used : Entity(javax.ws.rs.client.Entity) Meta(io.syndesis.server.endpoint.v1.dto.Meta) DynamicActionMetadata(io.syndesis.common.model.connection.DynamicActionMetadata) Response(javax.ws.rs.core.Response) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) MetaData(io.syndesis.server.endpoint.v1.dto.MetaData) HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo) Test(org.junit.Test)

Aggregations

HystrixInvokableInfo (com.netflix.hystrix.HystrixInvokableInfo)2 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)2 DynamicActionMetadata (io.syndesis.common.model.connection.DynamicActionMetadata)2 Meta (io.syndesis.server.endpoint.v1.dto.Meta)2 Response (javax.ws.rs.core.Response)2 HystrixExecutable (com.netflix.hystrix.HystrixExecutable)1 Api (io.swagger.annotations.Api)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 DataShape (io.syndesis.common.model.DataShape)1 DataShapeKinds (io.syndesis.common.model.DataShapeKinds)1 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)1 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)1 ConnectionBase (io.syndesis.common.model.connection.ConnectionBase)1 Connector (io.syndesis.common.model.connection.Connector)1 EncryptionComponent (io.syndesis.server.dao.manager.EncryptionComponent)1 MetaData (io.syndesis.server.endpoint.v1.dto.MetaData)1 MetadataConfigurationProperties (io.syndesis.server.verifier.MetadataConfigurationProperties)1