use of io.syndesis.server.endpoint.v1.dto.Meta in project syndesis by syndesisio.
the class ConnectionActionHandlerTest method shouldSetInoutOutputShapesToAnyIfMetadataCallFails.
@Test
public void shouldSetInoutOutputShapesToAnyIfMetadataCallFails() {
@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());
@SuppressWarnings("unchecked") final Meta<ConnectorDescriptor> meta = (Meta<ConnectorDescriptor>) response.getEntity();
final ConnectorDescriptor descriptor = meta.getValue();
assertThat(descriptor.getInputDataShape()).contains(ConnectionActionHandler.ANY_SHAPE);
assertThat(descriptor.getOutputDataShape()).contains(salesforceOutputShape);
}
use of io.syndesis.server.endpoint.v1.dto.Meta in project syndesis by syndesisio.
the class ConnectionActionHandler method enrichWithMetadata.
@POST
@Path(value = "/{id}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Retrieves enriched action definition, that is an action definition that has input/output data shapes and property enums defined with respect to the given action properties")
@ApiResponses(@ApiResponse(code = 200, reference = "#/definitions/ConnectorDescriptor", message = "A map of zero or more action property suggestions keyed by the property name"))
public Response enrichWithMetadata(@PathParam("id") @ApiParam(required = true, example = "io.syndesis:salesforce-create-or-update:latest") final String id, final Map<String, String> properties) {
final ConnectorAction action = //
actions.stream().filter(//
a -> a.idEquals(id)).findAny().orElseThrow(() -> new EntityNotFoundException("Action with id: " + id));
final ConnectorDescriptor defaultDescriptor = action.getDescriptor();
if (!action.getTags().contains("dynamic")) {
return Response.ok().entity(Meta.verbatim(defaultDescriptor)).build();
}
final Map<String, String> parameters = encryptionComponent.decrypt(new HashMap<>(Optional.ofNullable(properties).orElseGet(HashMap::new)));
// put all action parameters with `null` values
defaultDescriptor.getPropertyDefinitionSteps().forEach(step -> step.getProperties().forEach((k, v) -> parameters.putIfAbsent(k, null)));
// add the pattern as a property
if (action.getPattern() != null) {
parameters.put(action.getPattern().getDeclaringClass().getSimpleName(), action.getPattern().name());
}
// lastly put all connection properties
parameters.putAll(encryptionComponent.decrypt(connection.getConfiguredProperties()));
final HystrixExecutable<DynamicActionMetadata> meta = createMetadataCommand(action, parameters);
final DynamicActionMetadata dynamicActionMetadata = meta.execute();
final ConnectorDescriptor enrichedDescriptor = applyMetadataTo(defaultDescriptor, dynamicActionMetadata);
@SuppressWarnings("unchecked") final HystrixInvokableInfo<ConnectorDescriptor> metaInfo = (HystrixInvokableInfo<ConnectorDescriptor>) meta;
final Meta<ConnectorDescriptor> metaResult = Meta.from(enrichedDescriptor, metaInfo);
final Status status = metaResult.getData().getType().map(t -> t.status).orElse(Status.OK);
return Response.status(status).entity(metaResult).build();
}
use of io.syndesis.server.endpoint.v1.dto.Meta in project syndesis by syndesisio.
the class ConnectionActionHandlerTest method shouldProvideActionDefinition.
@Test
public void shouldProvideActionDefinition() {
@SuppressWarnings({ "unchecked", "rawtypes" }) final Class<Entity<Map<String, Object>>> entityType = (Class) Entity.class;
ArgumentCaptor.forClass(entityType);
final DynamicActionMetadata suggestions = new DynamicActionMetadata.Builder().putProperty("sObjectName", Arrays.asList(DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Account", "Account"), DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Contact", "Contact"))).build();
when(metadataCommand.execute()).thenReturn(suggestions);
when(((HystrixInvokableInfo<?>) metadataCommand).isSuccessfulExecution()).thenReturn(true);
final Response response = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE, Collections.emptyMap());
assertThat(response.getStatus()).isEqualTo(Status.OK.getStatusCode());
@SuppressWarnings("unchecked") final Meta<ConnectorDescriptor> meta = (Meta<ConnectorDescriptor>) response.getEntity();
final ConnectorDescriptor enrichedDefinitioin = new ConnectorDescriptor.Builder().createFrom(createOrUpdateSalesforceObjectDescriptor).replaceConfigurationProperty("sObjectName", c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("Account", "Account"), ConfigurationProperty.PropertyValue.Builder.of("Contact", "Contact"))).inputDataShape(//
ConnectionActionHandler.ANY_SHAPE).build();
assertThat(meta.getValue()).isEqualTo(enrichedDefinitioin);
}
use of io.syndesis.server.endpoint.v1.dto.Meta 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");
}
use of io.syndesis.server.endpoint.v1.dto.Meta in project syndesis by syndesisio.
the class ConnectionActionHandlerTest method shouldElicitActionPropertySuggestions.
@Test
public void shouldElicitActionPropertySuggestions() {
final DynamicActionMetadata suggestions = new DynamicActionMetadata.Builder().putProperty("sObjectName", Collections.singletonList(DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Contact", "Contact"))).putProperty("sObjectIdName", Arrays.asList(DynamicActionMetadata.ActionPropertySuggestion.Builder.of("ID", "Contact ID"), DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Email", "Email"), DynamicActionMetadata.ActionPropertySuggestion.Builder.of("TwitterScreenName__c", "Twitter Screen Name"))).inputShape(//
salesforceContactShape).build();
when(metadataCommand.execute()).thenReturn(suggestions);
when(((HystrixInvokableInfo<?>) metadataCommand).isSuccessfulExecution()).thenReturn(true);
final ConnectorDescriptor enrichedDefinitioin = new ConnectorDescriptor.Builder().createFrom(createOrUpdateSalesforceObjectDescriptor).replaceConfigurationProperty("sObjectName", c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("Contact", "Contact"))).replaceConfigurationProperty("sObjectIdName", c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("ID", "Contact ID"))).replaceConfigurationProperty("sObjectIdName", c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("Email", "Email"))).replaceConfigurationProperty("sObjectIdName", c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("TwitterScreenName__c", "Twitter Screen Name"))).inputDataShape(//
salesforceContactShape).build();
final Map<String, String> parameters = new HashMap<>();
parameters.put("sObjectName", "Contact");
final Response response = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE, parameters);
assertThat(response.getStatus()).isEqualTo(Status.OK.getStatusCode());
@SuppressWarnings("unchecked") final Meta<ConnectorDescriptor> meta = (Meta<ConnectorDescriptor>) response.getEntity();
assertThat(meta.getValue()).isEqualTo(enrichedDefinitioin);
}
Aggregations