@Test public void shouldNotContactVerifierForNonDynamicActions() { final ConnectorDescriptor defaultDefinition = new ConnectorDescriptor.Builder().build(); final Response response = handler.enrichWithMetadata(SALESFORCE_LIMITS, null); assertThat(response.getStatus()).isEqualTo(Status.OK.getStatusCode()); @SuppressWarnings("unchecked") final Meta<ConnectorDescriptor> returnValue = (Meta<ConnectorDescriptor>) response.getEntity(); assertThat(returnValue.getValue()).isEqualTo(defaultDefinition); }
@POST @Path(value = "/{actionId}") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "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") @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ConnectorDescriptor.class)), description = "A map of zero or more action property suggestions keyed by the property name") public Response enrichWithMetadata( @PathParam("actionId") @Parameter(required = true, example = "io.syndesis:salesforce-create-or-update:latest") final String actionId, final Map<String, Object> props) { final Map<String, String> properties = new HashMap<>(); if (props != null) { for (Map.Entry<String, Object> entry : props.entrySet()) { if (entry.getValue() == null) { properties.put(entry.getKey(), null); } else if (entry.getValue() instanceof String[]) { String value = StringUtils.join((String[]) entry.getValue(), ConfigurationProperty.MULTIPLE_SEPARATOR); properties.put(entry.getKey(), value); } else if (entry.getValue() instanceof Iterable) { String value = StringUtils.join((Iterable) entry.getValue(), ConfigurationProperty.MULTIPLE_SEPARATOR); properties.put(entry.getKey(), value); } else { properties.put(entry.getKey(), entry.getValue().toString()); } } } final ConnectorAction action = actions.stream() .filter(a -> a.idEquals(actionId)) .findAny() .orElseThrow(() -> new EntityNotFoundException("Action with id: " + actionId)); final ConnectorDescriptor originalDescriptor = action.getDescriptor(); ConnectorDescriptor.Builder generatedDescriptorBuilder = new ConnectorDescriptor.Builder().createFrom(originalDescriptor); action.getProperties().forEach((k, v) -> { if (v.getGenerator() != null && v.getDefaultValue() == null) { generatedDescriptorBuilder.replaceConfigurationProperty(k, c -> c.defaultValue(RandomValueGenerator.generate(v.getGenerator()))); } }); ConnectorDescriptor generatedDescriptor = generatedDescriptorBuilder.build(); if (!action.getTags().contains("dynamic")) { return Response.ok().entity(Meta.verbatim(generatedDescriptor)).build(); } final Map<String, String> parameters = encryptionComponent.decrypt(new HashMap<>(properties)); generatedDescriptor.getPropertyDefinitionSteps() .forEach(step -> step.getProperties().forEach((k, v) -> parameters.putIfAbsent(k, null))); if (action.getPattern() != null) { parameters.put(action.getPattern().getDeclaringClass().getSimpleName(), action.getPattern().name()); } parameters.putAll(encryptionComponent.decrypt(connection.getConfiguredProperties())); final HystrixExecutable<DynamicActionMetadata> meta = createMetadataCommandAction(action, parameters); final DynamicActionMetadata dynamicActionMetadata = meta.execute(); final ConnectorDescriptor enrichedDescriptor = applyMetadataTo(generatedDescriptor, 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(); }
ConnectionActionHandler { @POST @Path(value = "/{actionId}") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "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") @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ConnectorDescriptor.class)), description = "A map of zero or more action property suggestions keyed by the property name") public Response enrichWithMetadata( @PathParam("actionId") @Parameter(required = true, example = "io.syndesis:salesforce-create-or-update:latest") final String actionId, final Map<String, Object> props) { final Map<String, String> properties = new HashMap<>(); if (props != null) { for (Map.Entry<String, Object> entry : props.entrySet()) { if (entry.getValue() == null) { properties.put(entry.getKey(), null); } else if (entry.getValue() instanceof String[]) { String value = StringUtils.join((String[]) entry.getValue(), ConfigurationProperty.MULTIPLE_SEPARATOR); properties.put(entry.getKey(), value); } else if (entry.getValue() instanceof Iterable) { String value = StringUtils.join((Iterable) entry.getValue(), ConfigurationProperty.MULTIPLE_SEPARATOR); properties.put(entry.getKey(), value); } else { properties.put(entry.getKey(), entry.getValue().toString()); } } } final ConnectorAction action = actions.stream() .filter(a -> a.idEquals(actionId)) .findAny() .orElseThrow(() -> new EntityNotFoundException("Action with id: " + actionId)); final ConnectorDescriptor originalDescriptor = action.getDescriptor(); ConnectorDescriptor.Builder generatedDescriptorBuilder = new ConnectorDescriptor.Builder().createFrom(originalDescriptor); action.getProperties().forEach((k, v) -> { if (v.getGenerator() != null && v.getDefaultValue() == null) { generatedDescriptorBuilder.replaceConfigurationProperty(k, c -> c.defaultValue(RandomValueGenerator.generate(v.getGenerator()))); } }); ConnectorDescriptor generatedDescriptor = generatedDescriptorBuilder.build(); if (!action.getTags().contains("dynamic")) { return Response.ok().entity(Meta.verbatim(generatedDescriptor)).build(); } final Map<String, String> parameters = encryptionComponent.decrypt(new HashMap<>(properties)); generatedDescriptor.getPropertyDefinitionSteps() .forEach(step -> step.getProperties().forEach((k, v) -> parameters.putIfAbsent(k, null))); if (action.getPattern() != null) { parameters.put(action.getPattern().getDeclaringClass().getSimpleName(), action.getPattern().name()); } parameters.putAll(encryptionComponent.decrypt(connection.getConfiguredProperties())); final HystrixExecutable<DynamicActionMetadata> meta = createMetadataCommandAction(action, parameters); final DynamicActionMetadata dynamicActionMetadata = meta.execute(); final ConnectorDescriptor enrichedDescriptor = applyMetadataTo(generatedDescriptor, 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(); } }
ConnectionActionHandler { @POST @Path(value = "/{actionId}") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "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") @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ConnectorDescriptor.class)), description = "A map of zero or more action property suggestions keyed by the property name") public Response enrichWithMetadata( @PathParam("actionId") @Parameter(required = true, example = "io.syndesis:salesforce-create-or-update:latest") final String actionId, final Map<String, Object> props) { final Map<String, String> properties = new HashMap<>(); if (props != null) { for (Map.Entry<String, Object> entry : props.entrySet()) { if (entry.getValue() == null) { properties.put(entry.getKey(), null); } else if (entry.getValue() instanceof String[]) { String value = StringUtils.join((String[]) entry.getValue(), ConfigurationProperty.MULTIPLE_SEPARATOR); properties.put(entry.getKey(), value); } else if (entry.getValue() instanceof Iterable) { String value = StringUtils.join((Iterable) entry.getValue(), ConfigurationProperty.MULTIPLE_SEPARATOR); properties.put(entry.getKey(), value); } else { properties.put(entry.getKey(), entry.getValue().toString()); } } } final ConnectorAction action = actions.stream() .filter(a -> a.idEquals(actionId)) .findAny() .orElseThrow(() -> new EntityNotFoundException("Action with id: " + actionId)); final ConnectorDescriptor originalDescriptor = action.getDescriptor(); ConnectorDescriptor.Builder generatedDescriptorBuilder = new ConnectorDescriptor.Builder().createFrom(originalDescriptor); action.getProperties().forEach((k, v) -> { if (v.getGenerator() != null && v.getDefaultValue() == null) { generatedDescriptorBuilder.replaceConfigurationProperty(k, c -> c.defaultValue(RandomValueGenerator.generate(v.getGenerator()))); } }); ConnectorDescriptor generatedDescriptor = generatedDescriptorBuilder.build(); if (!action.getTags().contains("dynamic")) { return Response.ok().entity(Meta.verbatim(generatedDescriptor)).build(); } final Map<String, String> parameters = encryptionComponent.decrypt(new HashMap<>(properties)); generatedDescriptor.getPropertyDefinitionSteps() .forEach(step -> step.getProperties().forEach((k, v) -> parameters.putIfAbsent(k, null))); if (action.getPattern() != null) { parameters.put(action.getPattern().getDeclaringClass().getSimpleName(), action.getPattern().name()); } parameters.putAll(encryptionComponent.decrypt(connection.getConfiguredProperties())); final HystrixExecutable<DynamicActionMetadata> meta = createMetadataCommandAction(action, parameters); final DynamicActionMetadata dynamicActionMetadata = meta.execute(); final ConnectorDescriptor enrichedDescriptor = applyMetadataTo(generatedDescriptor, 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(); } ConnectionActionHandler(final ConnectionBase connection, final MetadataConfigurationProperties config,
                                   final EncryptionComponent encryptionComponent); }
ConnectionActionHandler { @POST @Path(value = "/{actionId}") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "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") @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ConnectorDescriptor.class)), description = "A map of zero or more action property suggestions keyed by the property name") public Response enrichWithMetadata( @PathParam("actionId") @Parameter(required = true, example = "io.syndesis:salesforce-create-or-update:latest") final String actionId, final Map<String, Object> props) { final Map<String, String> properties = new HashMap<>(); if (props != null) { for (Map.Entry<String, Object> entry : props.entrySet()) { if (entry.getValue() == null) { properties.put(entry.getKey(), null); } else if (entry.getValue() instanceof String[]) { String value = StringUtils.join((String[]) entry.getValue(), ConfigurationProperty.MULTIPLE_SEPARATOR); properties.put(entry.getKey(), value); } else if (entry.getValue() instanceof Iterable) { String value = StringUtils.join((Iterable) entry.getValue(), ConfigurationProperty.MULTIPLE_SEPARATOR); properties.put(entry.getKey(), value); } else { properties.put(entry.getKey(), entry.getValue().toString()); } } } final ConnectorAction action = actions.stream() .filter(a -> a.idEquals(actionId)) .findAny() .orElseThrow(() -> new EntityNotFoundException("Action with id: " + actionId)); final ConnectorDescriptor originalDescriptor = action.getDescriptor(); ConnectorDescriptor.Builder generatedDescriptorBuilder = new ConnectorDescriptor.Builder().createFrom(originalDescriptor); action.getProperties().forEach((k, v) -> { if (v.getGenerator() != null && v.getDefaultValue() == null) { generatedDescriptorBuilder.replaceConfigurationProperty(k, c -> c.defaultValue(RandomValueGenerator.generate(v.getGenerator()))); } }); ConnectorDescriptor generatedDescriptor = generatedDescriptorBuilder.build(); if (!action.getTags().contains("dynamic")) { return Response.ok().entity(Meta.verbatim(generatedDescriptor)).build(); } final Map<String, String> parameters = encryptionComponent.decrypt(new HashMap<>(properties)); generatedDescriptor.getPropertyDefinitionSteps() .forEach(step -> step.getProperties().forEach((k, v) -> parameters.putIfAbsent(k, null))); if (action.getPattern() != null) { parameters.put(action.getPattern().getDeclaringClass().getSimpleName(), action.getPattern().name()); } parameters.putAll(encryptionComponent.decrypt(connection.getConfiguredProperties())); final HystrixExecutable<DynamicActionMetadata> meta = createMetadataCommandAction(action, parameters); final DynamicActionMetadata dynamicActionMetadata = meta.execute(); final ConnectorDescriptor enrichedDescriptor = applyMetadataTo(generatedDescriptor, 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(); } ConnectionActionHandler(final ConnectionBase connection, final MetadataConfigurationProperties config,
                                   final EncryptionComponent encryptionComponent); @POST @Path(value = "/{actionId}") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "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") @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ConnectorDescriptor.class)), description = "A map of zero or more action property suggestions keyed by the property name") Response enrichWithMetadata(
        @PathParam("actionId") @Parameter(required = true, example = "io.syndesis:salesforce-create-or-update:latest") final String actionId,
        final Map<String, Object> props); }
ConnectionActionHandler { @POST @Path(value = "/{actionId}") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "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") @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ConnectorDescriptor.class)), description = "A map of zero or more action property suggestions keyed by the property name") public Response enrichWithMetadata( @PathParam("actionId") @Parameter(required = true, example = "io.syndesis:salesforce-create-or-update:latest") final String actionId, final Map<String, Object> props) { final Map<String, String> properties = new HashMap<>(); if (props != null) { for (Map.Entry<String, Object> entry : props.entrySet()) { if (entry.getValue() == null) { properties.put(entry.getKey(), null); } else if (entry.getValue() instanceof String[]) { String value = StringUtils.join((String[]) entry.getValue(), ConfigurationProperty.MULTIPLE_SEPARATOR); properties.put(entry.getKey(), value); } else if (entry.getValue() instanceof Iterable) { String value = StringUtils.join((Iterable) entry.getValue(), ConfigurationProperty.MULTIPLE_SEPARATOR); properties.put(entry.getKey(), value); } else { properties.put(entry.getKey(), entry.getValue().toString()); } } } final ConnectorAction action = actions.stream() .filter(a -> a.idEquals(actionId)) .findAny() .orElseThrow(() -> new EntityNotFoundException("Action with id: " + actionId)); final ConnectorDescriptor originalDescriptor = action.getDescriptor(); ConnectorDescriptor.Builder generatedDescriptorBuilder = new ConnectorDescriptor.Builder().createFrom(originalDescriptor); action.getProperties().forEach((k, v) -> { if (v.getGenerator() != null && v.getDefaultValue() == null) { generatedDescriptorBuilder.replaceConfigurationProperty(k, c -> c.defaultValue(RandomValueGenerator.generate(v.getGenerator()))); } }); ConnectorDescriptor generatedDescriptor = generatedDescriptorBuilder.build(); if (!action.getTags().contains("dynamic")) { return Response.ok().entity(Meta.verbatim(generatedDescriptor)).build(); } final Map<String, String> parameters = encryptionComponent.decrypt(new HashMap<>(properties)); generatedDescriptor.getPropertyDefinitionSteps() .forEach(step -> step.getProperties().forEach((k, v) -> parameters.putIfAbsent(k, null))); if (action.getPattern() != null) { parameters.put(action.getPattern().getDeclaringClass().getSimpleName(), action.getPattern().name()); } parameters.putAll(encryptionComponent.decrypt(connection.getConfiguredProperties())); final HystrixExecutable<DynamicActionMetadata> meta = createMetadataCommandAction(action, parameters); final DynamicActionMetadata dynamicActionMetadata = meta.execute(); final ConnectorDescriptor enrichedDescriptor = applyMetadataTo(generatedDescriptor, 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(); } ConnectionActionHandler(final ConnectionBase connection, final MetadataConfigurationProperties config,
                                   final EncryptionComponent encryptionComponent); @POST @Path(value = "/{actionId}") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "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") @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ConnectorDescriptor.class)), description = "A map of zero or more action property suggestions keyed by the property name") Response enrichWithMetadata(
        @PathParam("actionId") @Parameter(required = true, example = "io.syndesis:salesforce-create-or-update:latest") final String actionId,
        final Map<String, Object> props); static final DataShape ANY_SHAPE; static final DataShape NO_SHAPE; }