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();
}
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();
}
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()));
}
}
}
}
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);
}
}
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);
}
}
Aggregations