@Test public void shouldEnrichSplitSteps() { List<Step> steps = Arrays.asList(new Step.Builder() .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .inputDataShape(StepMetadataHelper.NO_SHAPE) .outputDataShape(new DataShape.Builder() .createFrom(collectionShape) .addVariant(elementShape) .addVariant(dummyShape()) .build()) .build()) .build()) .build(), new Step.Builder() .stepKind(StepKind.split) .build(), new Step.Builder() .stepKind(StepKind.log) .build()); final Response response = handler.enrichStepMetadata(steps); @SuppressWarnings("unchecked") final List<Step> enriched = (List<Step>) response.getEntity(); assertThat(enriched).hasSize(3); assertThat(enriched.get(0).getStepKind()).isEqualTo(StepKind.endpoint); assertThat(enriched.get(0).getAction()).isPresent(); assertThat(enriched.get(0).getAction().orElseThrow(AssertionError::new).getDescriptor().getInputDataShape()).contains(StepMetadataHelper.NO_SHAPE); assertThat(enriched.get(0).getAction().orElseThrow(AssertionError::new).getDescriptor().getOutputDataShape()).get().isEqualToComparingFieldByField(new DataShape.Builder() .createFrom(collectionShape) .addVariant(elementShape) .addVariant(dummyShape()) .build()); assertThat(enriched.get(1).getStepKind()).isEqualTo(StepKind.split); assertThat(enriched.get(1).getAction()).isPresent(); assertThat(enriched.get(1).getAction().orElseThrow(AssertionError::new).getDescriptor().getInputDataShape()).contains(StepMetadataHelper.NO_SHAPE); assertThat(enriched.get(1).getAction().orElseThrow(AssertionError::new).getDescriptor().getOutputDataShape()).get().isEqualToComparingFieldByField(new DataShape.Builder() .createFrom(elementShape) .addVariant(dummyShape()) .addVariant(collectionShape) .build()); assertThat(enriched.get(2).getAction()).isNotPresent(); assertThat(enriched.get(2).getStepKind()).isEqualTo(StepKind.log); }
@POST @Path("/descriptor") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Retrieves enriched step definitions, that is a list of steps where each step has adapted input/output data shapes " + "defined with respect to the given shape variants") @ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = Step.class))), description = "List of enriched steps") public Response enrichStepMetadata(List<Step> steps) { List<Step> enriched = new ArrayList<>(steps.size()); for (int i = 0; i < steps.size(); i++) { Step step = steps.get(i); final Optional<StepMetadataHandler> metadataHandler = findStepMetadataHandler(step.getStepKind()); if (metadataHandler.isPresent()) { StepMetadataHandler handler = metadataHandler.get(); List<Step> previousSteps; if (i == 0) { previousSteps = Collections.singletonList(step); } else { previousSteps = enriched.subList(0, i); } final DynamicActionMetadata metadata = handler.createMetadata(step, previousSteps, steps.subList(i + 1, steps.size())); final DynamicActionMetadata enrichedMetadata = handler.handle(metadata); if (enrichedMetadata.equals(DynamicActionMetadata.NOTHING)) { enriched.add(step); } else { enriched.add(applyMetadata(step, enrichedMetadata)); } } else { enriched.add(step); } } return Response.status(Status.OK).entity(enriched).build(); }
StepActionHandler extends BaseHandler { @POST @Path("/descriptor") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Retrieves enriched step definitions, that is a list of steps where each step has adapted input/output data shapes " + "defined with respect to the given shape variants") @ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = Step.class))), description = "List of enriched steps") public Response enrichStepMetadata(List<Step> steps) { List<Step> enriched = new ArrayList<>(steps.size()); for (int i = 0; i < steps.size(); i++) { Step step = steps.get(i); final Optional<StepMetadataHandler> metadataHandler = findStepMetadataHandler(step.getStepKind()); if (metadataHandler.isPresent()) { StepMetadataHandler handler = metadataHandler.get(); List<Step> previousSteps; if (i == 0) { previousSteps = Collections.singletonList(step); } else { previousSteps = enriched.subList(0, i); } final DynamicActionMetadata metadata = handler.createMetadata(step, previousSteps, steps.subList(i + 1, steps.size())); final DynamicActionMetadata enrichedMetadata = handler.handle(metadata); if (enrichedMetadata.equals(DynamicActionMetadata.NOTHING)) { enriched.add(step); } else { enriched.add(applyMetadata(step, enrichedMetadata)); } } else { enriched.add(step); } } return Response.status(Status.OK).entity(enriched).build(); } }
StepActionHandler extends BaseHandler { @POST @Path("/descriptor") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Retrieves enriched step definitions, that is a list of steps where each step has adapted input/output data shapes " + "defined with respect to the given shape variants") @ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = Step.class))), description = "List of enriched steps") public Response enrichStepMetadata(List<Step> steps) { List<Step> enriched = new ArrayList<>(steps.size()); for (int i = 0; i < steps.size(); i++) { Step step = steps.get(i); final Optional<StepMetadataHandler> metadataHandler = findStepMetadataHandler(step.getStepKind()); if (metadataHandler.isPresent()) { StepMetadataHandler handler = metadataHandler.get(); List<Step> previousSteps; if (i == 0) { previousSteps = Collections.singletonList(step); } else { previousSteps = enriched.subList(0, i); } final DynamicActionMetadata metadata = handler.createMetadata(step, previousSteps, steps.subList(i + 1, steps.size())); final DynamicActionMetadata enrichedMetadata = handler.handle(metadata); if (enrichedMetadata.equals(DynamicActionMetadata.NOTHING)) { enriched.add(step); } else { enriched.add(applyMetadata(step, enrichedMetadata)); } } else { enriched.add(step); } } return Response.status(Status.OK).entity(enriched).build(); } StepActionHandler(final DataManager dataMgr); }
StepActionHandler extends BaseHandler { @POST @Path("/descriptor") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Retrieves enriched step definitions, that is a list of steps where each step has adapted input/output data shapes " + "defined with respect to the given shape variants") @ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = Step.class))), description = "List of enriched steps") public Response enrichStepMetadata(List<Step> steps) { List<Step> enriched = new ArrayList<>(steps.size()); for (int i = 0; i < steps.size(); i++) { Step step = steps.get(i); final Optional<StepMetadataHandler> metadataHandler = findStepMetadataHandler(step.getStepKind()); if (metadataHandler.isPresent()) { StepMetadataHandler handler = metadataHandler.get(); List<Step> previousSteps; if (i == 0) { previousSteps = Collections.singletonList(step); } else { previousSteps = enriched.subList(0, i); } final DynamicActionMetadata metadata = handler.createMetadata(step, previousSteps, steps.subList(i + 1, steps.size())); final DynamicActionMetadata enrichedMetadata = handler.handle(metadata); if (enrichedMetadata.equals(DynamicActionMetadata.NOTHING)) { enriched.add(step); } else { enriched.add(applyMetadata(step, enrichedMetadata)); } } else { enriched.add(step); } } return Response.status(Status.OK).entity(enriched).build(); } StepActionHandler(final DataManager dataMgr); @POST @Path("/descriptor") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Retrieves enriched step definitions, that is a list of steps where each step has adapted input/output data shapes " + "defined with respect to the given shape variants") @ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = Step.class))), description = "List of enriched steps") Response enrichStepMetadata(List<Step> steps); @POST @Path("/{kind}/descriptor") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Retrieves enriched step definition, that is an step descriptor that has input/output data shapes " + "defined with respect to the given shape variants") @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = StepDescriptor.class)), description = "Enriched step descriptor") Response enrichStepMetadata(
        @PathParam("kind") @Parameter(required = true) final String kind,
        DynamicActionMetadata metadata); }
StepActionHandler extends BaseHandler { @POST @Path("/descriptor") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Retrieves enriched step definitions, that is a list of steps where each step has adapted input/output data shapes " + "defined with respect to the given shape variants") @ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = Step.class))), description = "List of enriched steps") public Response enrichStepMetadata(List<Step> steps) { List<Step> enriched = new ArrayList<>(steps.size()); for (int i = 0; i < steps.size(); i++) { Step step = steps.get(i); final Optional<StepMetadataHandler> metadataHandler = findStepMetadataHandler(step.getStepKind()); if (metadataHandler.isPresent()) { StepMetadataHandler handler = metadataHandler.get(); List<Step> previousSteps; if (i == 0) { previousSteps = Collections.singletonList(step); } else { previousSteps = enriched.subList(0, i); } final DynamicActionMetadata metadata = handler.createMetadata(step, previousSteps, steps.subList(i + 1, steps.size())); final DynamicActionMetadata enrichedMetadata = handler.handle(metadata); if (enrichedMetadata.equals(DynamicActionMetadata.NOTHING)) { enriched.add(step); } else { enriched.add(applyMetadata(step, enrichedMetadata)); } } else { enriched.add(step); } } return Response.status(Status.OK).entity(enriched).build(); } StepActionHandler(final DataManager dataMgr); @POST @Path("/descriptor") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Retrieves enriched step definitions, that is a list of steps where each step has adapted input/output data shapes " + "defined with respect to the given shape variants") @ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = Step.class))), description = "List of enriched steps") Response enrichStepMetadata(List<Step> steps); @POST @Path("/{kind}/descriptor") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Retrieves enriched step definition, that is an step descriptor that has input/output data shapes " + "defined with respect to the given shape variants") @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = StepDescriptor.class)), description = "Enriched step descriptor") Response enrichStepMetadata(
        @PathParam("kind") @Parameter(required = true) final String kind,
        DynamicActionMetadata metadata);  }