@Test public void shouldExtractJavaInputElementVariant() throws IOException { DynamicActionMetadata metadata = new DynamicActionMetadata.Builder() .inputShape(new DataShape.Builder() .kind(DataShapeKinds.JAVA) .specification(getSpecification("person-list-spec.json")) .description("person-list") .collectionType("List") .type(Person.class.getName()) .collectionClassName(List.class.getName()) .putMetadata(DataShapeMetaData.VARIANT, DataShapeMetaData.VARIANT_COLLECTION) .addVariant(new DataShape.Builder() .kind(DataShapeKinds.JAVA) .specification(getSpecification("person-spec.json")) .type(Person.class.getName()) .putMetadata(DataShapeMetaData.VARIANT, DataShapeMetaData.VARIANT_ELEMENT) .build()) .addVariant(dummyShape(DataShapeKinds.JSON_INSTANCE)) .build()) .outputShape(StepMetadataHelper.NO_SHAPE) .build(); DynamicActionMetadata enrichedMetadata = metadataHandler.handle(metadata); Assert.assertNotNull(enrichedMetadata.inputShape()); Assert.assertEquals(DataShapeKinds.JAVA, enrichedMetadata.inputShape().getKind()); Assert.assertEquals(DataShapeMetaData.VARIANT_ELEMENT, enrichedMetadata.inputShape().getMetadata(DataShapeMetaData.VARIANT).orElse("")); Assert.assertEquals(getSpecification("person-spec.json"), enrichedMetadata.inputShape().getSpecification()); Assert.assertEquals(2, enrichedMetadata.inputShape().getVariants().size()); Assert.assertEquals("dummy", enrichedMetadata.inputShape().getVariants().get(0).getMetadata().get(DataShapeMetaData.VARIANT)); Assert.assertEquals(DataShapeMetaData.VARIANT_COLLECTION, enrichedMetadata.inputShape().getVariants().get(1).getMetadata().get(DataShapeMetaData.VARIANT)); Assert.assertEquals("person-list", enrichedMetadata.inputShape().getVariants().get(1).getDescription()); Assert.assertEquals(StepMetadataHelper.NO_SHAPE, enrichedMetadata.outputShape()); }
@Override public DynamicActionMetadata handle(DynamicActionMetadata metadata) { DataShape outputShape = metadata.outputShape(); DataShape inputShape = metadata.inputShape(); try { if (metadata.outputShape() != null) { outputShape = adaptOutputShape(new DataShape.Builder() .createFrom(metadata.outputShape()) .decompress() .build()); } } catch (IOException e) { LOG.warn("Unable to read input data shape on dynamic meta data inspection", e); LOG.warn("Using original input shape as fallback"); } try { if (metadata.inputShape() != null) { inputShape = adaptInputShape(new DataShape.Builder() .createFrom(metadata.inputShape()) .decompress() .build()); } } catch (IOException e) { LOG.warn("Unable to read output data shape on dynamic meta data inspection", e); LOG.warn("Using original output shape as fallback"); } return new DynamicActionMetadata.Builder() .createFrom(metadata) .inputShape(inputShape) .outputShape(outputShape) .build(); }
AggregateMetadataHandler implements StepMetadataHandler { @Override public DynamicActionMetadata handle(DynamicActionMetadata metadata) { DataShape outputShape = metadata.outputShape(); DataShape inputShape = metadata.inputShape(); try { if (metadata.outputShape() != null) { outputShape = adaptOutputShape(new DataShape.Builder() .createFrom(metadata.outputShape()) .decompress() .build()); } } catch (IOException e) { LOG.warn("Unable to read input data shape on dynamic meta data inspection", e); LOG.warn("Using original input shape as fallback"); } try { if (metadata.inputShape() != null) { inputShape = adaptInputShape(new DataShape.Builder() .createFrom(metadata.inputShape()) .decompress() .build()); } } catch (IOException e) { LOG.warn("Unable to read output data shape on dynamic meta data inspection", e); LOG.warn("Using original output shape as fallback"); } return new DynamicActionMetadata.Builder() .createFrom(metadata) .inputShape(inputShape) .outputShape(outputShape) .build(); } }
AggregateMetadataHandler implements StepMetadataHandler { @Override public DynamicActionMetadata handle(DynamicActionMetadata metadata) { DataShape outputShape = metadata.outputShape(); DataShape inputShape = metadata.inputShape(); try { if (metadata.outputShape() != null) { outputShape = adaptOutputShape(new DataShape.Builder() .createFrom(metadata.outputShape()) .decompress() .build()); } } catch (IOException e) { LOG.warn("Unable to read input data shape on dynamic meta data inspection", e); LOG.warn("Using original input shape as fallback"); } try { if (metadata.inputShape() != null) { inputShape = adaptInputShape(new DataShape.Builder() .createFrom(metadata.inputShape()) .decompress() .build()); } } catch (IOException e) { LOG.warn("Unable to read output data shape on dynamic meta data inspection", e); LOG.warn("Using original output shape as fallback"); } return new DynamicActionMetadata.Builder() .createFrom(metadata) .inputShape(inputShape) .outputShape(outputShape) .build(); }  }
AggregateMetadataHandler implements StepMetadataHandler { @Override public DynamicActionMetadata handle(DynamicActionMetadata metadata) { DataShape outputShape = metadata.outputShape(); DataShape inputShape = metadata.inputShape(); try { if (metadata.outputShape() != null) { outputShape = adaptOutputShape(new DataShape.Builder() .createFrom(metadata.outputShape()) .decompress() .build()); } } catch (IOException e) { LOG.warn("Unable to read input data shape on dynamic meta data inspection", e); LOG.warn("Using original input shape as fallback"); } try { if (metadata.inputShape() != null) { inputShape = adaptInputShape(new DataShape.Builder() .createFrom(metadata.inputShape()) .decompress() .build()); } } catch (IOException e) { LOG.warn("Unable to read output data shape on dynamic meta data inspection", e); LOG.warn("Using original output shape as fallback"); } return new DynamicActionMetadata.Builder() .createFrom(metadata) .inputShape(inputShape) .outputShape(outputShape) .build(); }  @Override boolean canHandle(StepKind kind); @Override DynamicActionMetadata createMetadata(Step step, List<Step> previousSteps, List<Step> subsequentSteps); @Override DynamicActionMetadata handle(DynamicActionMetadata metadata); }
AggregateMetadataHandler implements StepMetadataHandler { @Override public DynamicActionMetadata handle(DynamicActionMetadata metadata) { DataShape outputShape = metadata.outputShape(); DataShape inputShape = metadata.inputShape(); try { if (metadata.outputShape() != null) { outputShape = adaptOutputShape(new DataShape.Builder() .createFrom(metadata.outputShape()) .decompress() .build()); } } catch (IOException e) { LOG.warn("Unable to read input data shape on dynamic meta data inspection", e); LOG.warn("Using original input shape as fallback"); } try { if (metadata.inputShape() != null) { inputShape = adaptInputShape(new DataShape.Builder() .createFrom(metadata.inputShape()) .decompress() .build()); } } catch (IOException e) { LOG.warn("Unable to read output data shape on dynamic meta data inspection", e); LOG.warn("Using original output shape as fallback"); } return new DynamicActionMetadata.Builder() .createFrom(metadata) .inputShape(inputShape) .outputShape(outputShape) .build(); }  @Override boolean canHandle(StepKind kind); @Override DynamicActionMetadata createMetadata(Step step, List<Step> previousSteps, List<Step> subsequentSteps); @Override DynamicActionMetadata handle(DynamicActionMetadata metadata); static final String BODY; }