Search in sources :

Example 16 with ConnectorAction

use of io.syndesis.common.model.action.ConnectorAction 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();
}
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) Status(javax.ws.rs.core.Response.Status) HashMap(java.util.HashMap) DynamicActionMetadata(io.syndesis.common.model.connection.DynamicActionMetadata) EntityNotFoundException(javax.persistence.EntityNotFoundException) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 17 with ConnectorAction

use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.

the class ActiveMQConnectionTest method newActiveMQEndpointStep.

// **************************
// Helpers
// **************************
protected Step newActiveMQEndpointStep(String actionId, Consumer<Step.Builder> consumer) {
    final Connector connector = getResourceManager().mandatoryLoadConnector("activemq");
    final ConnectorAction action = getResourceManager().mandatoryLookupAction(connector, actionId);
    final Step.Builder builder = new Step.Builder().stepKind(StepKind.endpoint).action(action).connection(new io.syndesis.common.model.connection.Connection.Builder().connector(connector).build());
    consumer.accept(builder);
    return builder.build();
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Step(io.syndesis.common.model.integration.Step)

Example 18 with ConnectorAction

use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.

the class BaseSwaggerGeneratorExampleTest method shouldGenerateAsExpected.

@SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts")
public void shouldGenerateAsExpected() throws IOException {
    final ConnectorSettings connectorSettings = // 
    new ConnectorSettings.Builder().putConfiguredProperty("specification", // 
    specification).build();
    final Connector generated = generator().generate(SWAGGER_TEMPLATE, connectorSettings);
    final Map<String, String> generatedConfiguredProperties = generated.getConfiguredProperties();
    final String generatedSpecification = generatedConfiguredProperties.get("specification");
    final Map<String, String> expectedConfiguredProperties = expected.getConfiguredProperties();
    final String expectedSpecification = expectedConfiguredProperties.get("specification");
    assertThat(reformatJson(generatedSpecification)).isEqualTo(reformatJson(expectedSpecification));
    assertThat(without(generatedConfiguredProperties, "specification")).containsAllEntriesOf(without(expectedConfiguredProperties, "specification"));
    assertThat(generated.getProperties().keySet()).as("Expecting the same properties to be generated").containsOnlyElementsOf(expected.getProperties().keySet());
    assertThat(generated.getProperties()).containsAllEntriesOf(expected.getProperties());
    assertThat(generated).isEqualToIgnoringGivenFields(expected, "id", "icon", "properties", "configuredProperties", "actions");
    assertThat(generated.getIcon()).startsWith("data:image");
    assertThat(generated.getActions()).hasSameSizeAs(expected.getActions());
    for (final ConnectorAction expectedAction : expected.getActions()) {
        final String actionId = expectedAction.getId().get().replace("_id_", generated.getId().get());
        final Optional<ConnectorAction> maybeGeneratedAction = generated.findActionById(actionId);
        assertThat(maybeGeneratedAction).as("No action with id: " + actionId + " was generated").isPresent();
        final ConnectorAction generatedAction = maybeGeneratedAction.get();
        assertThat(generatedAction).as("Difference found for action: " + actionId).isEqualToIgnoringGivenFields(expectedAction, "id", "descriptor");
        assertThat(generatedAction.getDescriptor().getPropertyDefinitionSteps()).as("Generated and expected action definition property definition steps for action with id: " + actionId + " differs").isEqualTo(expectedAction.getDescriptor().getPropertyDefinitionSteps());
        if (expectedAction.getDescriptor().getInputDataShape().isPresent()) {
            final DataShape generatedInputDataShape = generatedAction.getDescriptor().getInputDataShape().get();
            final DataShape expectedInputDataShape = expectedAction.getDescriptor().getInputDataShape().get();
            assertThat(generatedInputDataShape).as("Generated and expected input data shape for action with id: " + actionId + " differs").isEqualToIgnoringGivenFields(expectedInputDataShape, "specification");
            if (generatedInputDataShape.getKind() == DataShapeKinds.JSON_SCHEMA) {
                assertThat(reformatJson(generatedInputDataShape.getSpecification())).as("Input data shape specification for action with id: " + actionId + " differ").isEqualTo(reformatJson(expectedInputDataShape.getSpecification()));
            } else {
                assertThat(c14Xml(generatedInputDataShape.getSpecification())).as("Input data shape specification for action with id: " + actionId + " differ").isEqualTo(c14Xml(expectedInputDataShape.getSpecification()));
            }
        }
        if (expectedAction.getDescriptor().getOutputDataShape().isPresent()) {
            final DataShape generatedOutputDataShape = generatedAction.getDescriptor().getOutputDataShape().get();
            final DataShape expectedOutputDataShape = expectedAction.getDescriptor().getOutputDataShape().get();
            assertThat(generatedOutputDataShape).as("Generated and expected output data shape for action with id: " + actionId + " differs").isEqualToIgnoringGivenFields(expectedOutputDataShape, "specification");
            if (generatedOutputDataShape.getKind() == DataShapeKinds.JSON_SCHEMA) {
                assertThat(reformatJson(generatedOutputDataShape.getSpecification())).as("Output data shape specification for action with id: " + actionId + " differ").isEqualTo(reformatJson(expectedOutputDataShape.getSpecification()));
            } else {
                assertThat(c14Xml(generatedOutputDataShape.getSpecification())).as("Output data shape specification for action with id: " + actionId + " differ").isEqualTo(c14Xml(expectedOutputDataShape.getSpecification()));
            }
        }
    }
}
Also used : Connector(io.syndesis.common.model.connection.Connector) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) DataShape(io.syndesis.common.model.DataShape)

Example 19 with ConnectorAction

use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.

the class GenerateMetadataMojo method generateAtlasMapInspections.

// ****************************************
// Inspections
// ****************************************
/**
 * Generate atlasmap inspections, no matter if they come from annotations or they are written directly into source json
 */
private void generateAtlasMapInspections() throws MojoExecutionException {
    try {
        Map<String, Action> processedActions = new TreeMap<>();
        for (Map.Entry<String, Action> actionEntry : actions.entrySet()) {
            Optional<DataShape> input = generateInspections(actionEntry.getKey(), actionEntry.getValue().getInputDataShape());
            Optional<DataShape> output = generateInspections(actionEntry.getKey(), actionEntry.getValue().getOutputDataShape());
            Action newAction;
            if (Action.TYPE_CONNECTOR.equals(actionEntry.getValue().getActionType())) {
                newAction = new ConnectorAction.Builder().createFrom((ConnectorAction) actionEntry.getValue()).descriptor(new ConnectorDescriptor.Builder().createFrom((ConnectorDescriptor) actionEntry.getValue().getDescriptor()).inputDataShape(input).outputDataShape(output).build()).build();
            } else if (Action.TYPE_STEP.equals(actionEntry.getValue().getActionType())) {
                newAction = new StepAction.Builder().createFrom((StepAction) actionEntry.getValue()).descriptor(new StepDescriptor.Builder().createFrom((StepDescriptor) actionEntry.getValue().getDescriptor()).inputDataShape(input).outputDataShape(output).build()).build();
            } else {
                throw new IllegalArgumentException("Unsupported action type: " + actionEntry.getValue().getActionType());
            }
            processedActions.put(actionEntry.getKey(), newAction);
        }
        this.actions = processedActions;
    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ex) {
        throw new MojoExecutionException("Error processing atlasmap inspections", ex);
    }
}
Also used : StepAction(io.syndesis.common.model.action.StepAction) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Action(io.syndesis.common.model.action.Action) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TreeMap(java.util.TreeMap) DataShape(io.syndesis.common.model.DataShape) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) StepAction(io.syndesis.common.model.action.StepAction) StepDescriptor(io.syndesis.common.model.action.StepDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 20 with ConnectorAction

use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.

the class GenerateConnectorInspectionsMojo method execute.

@Override
@SuppressWarnings("PMD.CyclomaticComplexity")
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        inspectionsOutputDir.mkdirs();
        File root = new File(output, CONNECTORS_META_PATH);
        if (root.exists()) {
            File[] files = root.listFiles((dir, name) -> name.endsWith(".json"));
            if (files == null) {
                return;
            }
            for (File file : files) {
                final Connector connector = Json.reader().forType(Connector.class).readValue(file);
                final List<ConnectorAction> actions = new ArrayList<>();
                for (ConnectorAction action : connector.getActions()) {
                    Optional<DataShape> inputDataShape = generateInspections(connector, action.getDescriptor().getInputDataShape());
                    Optional<DataShape> outputDataShape = generateInspections(connector, action.getDescriptor().getOutputDataShape());
                    if (inspectionMode == InspectionMode.SPECIFICATION || inspectionMode == InspectionMode.RESOURCE_AND_SPECIFICATION) {
                        if (inputDataShape.isPresent() || outputDataShape.isPresent()) {
                            ConnectorDescriptor.Builder descriptorBuilder = new ConnectorDescriptor.Builder().createFrom(action.getDescriptor());
                            inputDataShape.ifPresent(descriptorBuilder::inputDataShape);
                            outputDataShape.ifPresent(descriptorBuilder::outputDataShape);
                            actions.add(new ConnectorAction.Builder().createFrom(action).descriptor(descriptorBuilder.build()).build());
                        } else {
                            actions.add(action);
                        }
                    }
                }
                if (!actions.isEmpty()) {
                    Json.writer().writeValue(file, new Connector.Builder().createFrom(connector).actions(actions).build());
                }
            }
        }
    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) {
        throw new MojoExecutionException("", e);
    }
}
Also used : Connector(io.syndesis.common.model.connection.Connector) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) DataShape(io.syndesis.common.model.DataShape) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) File(java.io.File)

Aggregations

ConnectorAction (io.syndesis.common.model.action.ConnectorAction)21 Connector (io.syndesis.common.model.connection.Connector)16 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)11 Step (io.syndesis.common.model.integration.Step)8 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)5 Connection (io.syndesis.common.model.connection.Connection)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 DataShape (io.syndesis.common.model.DataShape)4 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 Test (org.junit.Test)3 ConnectorSettings (io.syndesis.common.model.connection.ConnectorSettings)2 Integration (io.syndesis.common.model.integration.Integration)2 MavenProperties (io.syndesis.common.util.MavenProperties)2 IntegrationProjectGenerator (io.syndesis.integration.api.IntegrationProjectGenerator)2 ComponentProxyComponent (io.syndesis.integration.component.proxy.ComponentProxyComponent)2 File (java.io.File)2