private MetadataType wrapInMessageType(MetadataType type, Object key, MetadataContext context, Optional<MetadataType> staticAttributes) throws MetadataResolvingException { MessageMetadataTypeBuilder message = new MessageMetadataTypeBuilder().payload(type); staticAttributes.ifPresent(message::attributes); if (((HasOutputModel) component).getOutputAttributes().hasDynamicType()) { MetadataResult<MetadataType> attributes = resolveOutputAttributesMetadata(context, key, Objects::nonNull); if (!attributes.isSuccess()) { throw new MetadataResolvingException("Could not resolve attributes of List<Message> output", attributes.getFailures().stream() .map(MetadataFailure::getFailureCode) .findFirst() .orElse(UNKNOWN)); } message.attributes(attributes.get()); } return message.build(); }
@Test public void customTypeOutput() throws Exception { OperationModel o = getOperation("customTypeOutput"); OutputModel output = o.getOutput(); MetadataType type = output.getType(); assertThat(output.hasDynamicType(), is(false)); assertThat(type.getMetadataFormat(), is(CSV)); assertThat(type.toString(), is("csv-object")); }
/** * The operation returns the result of one of its routes, keeping the attributes of the result message. * * @param model the model to assert on */ private void assertAssociatedProcessorsChangeOutput(final OperationModel model) { assertThat(model.getOutput().getType(), instanceOf(DefaultAnyType.class)); assertThat(model.getOutput().hasDynamicType(), is(false)); assertThat(model.getOutputAttributes().getType(), instanceOf(DefaultAnyType.class)); assertThat(model.getOutputAttributes().hasDynamicType(), is(false)); }
/** * The operation returns its input as the output. * * @param model the model to assert on */ private void assertOutputSameAsInput(final OperationModel model) { assertThat(model.getOutput().getType(), instanceOf(VoidType.class)); assertThat(model.getOutput().hasDynamicType(), is(false)); assertThat(model.getOutputAttributes().getType(), instanceOf(VoidType.class)); assertThat(model.getOutputAttributes().hasDynamicType(), is(false)); }
/** * The operation buids its own output, leaving the resulting message without attrbiutes. * * @param model the model to assert on */ private void assertComponentDeterminesOutput(final OperationModel model) { assertThat(model.getOutput().getType(), instanceOf(DefaultAnyType.class)); assertThat(model.getOutput().hasDynamicType(), is(false)); assertThat(model.getOutputAttributes().getType(), instanceOf(VoidType.class)); assertThat(model.getOutputAttributes().hasDynamicType(), is(false)); }
/** * Given a {@link MetadataKey} of a type and a {@link MetadataContext}, resolves the {@link MetadataType} of the Components's * output {@link Message#getAttributes()} using the {@link OutputTypeResolver} associated to the current component. * * @param context {@link MetadataContext} of the Metadata resolution * @param key {@link MetadataKey} of the type which's structure has to be resolved * @return a {@link MetadataResult} with the {@link MetadataType} of the components output {@link Message#getAttributes()} */ private MetadataResult<MetadataType> getOutputAttributesMetadata(final MetadataContext context, Object key) { OutputModel attributes = ((HasOutputModel) component).getOutputAttributes(); if (isVoid(attributes.getType()) || !attributes.hasDynamicType()) { return success(attributes.getType()); } return resolveOutputAttributesMetadata(context, key, (metadata) -> isMetadataResolvedCorrectly(metadata, true)); }
@Test public void scheduler() { final SourceModel schedulerModel = coreExtensionModel.getSourceModel("scheduler").get(); assertThat(schedulerModel.getStereotype(), is(SOURCE)); assertThat(schedulerModel.getErrorModels(), empty()); assertThat(schedulerModel.hasResponse(), is(false)); assertThat(schedulerModel.getOutput().getType(), instanceOf(DefaultObjectType.class)); assertThat(schedulerModel.getOutput().hasDynamicType(), is(false)); assertThat(schedulerModel.getOutputAttributes().getType(), instanceOf(DefaultObjectType.class)); assertThat(schedulerModel.getOutputAttributes().hasDynamicType(), is(false)); final List<ParameterModel> paramModels = schedulerModel.getAllParameterModels(); assertThat(paramModels, hasSize(1)); assertSchedulingStrategy(paramModels.get(0)); }
when(outputMock.hasDynamicType()).thenReturn(true); when(operationModel.getOutput()).thenReturn(outputMock); when(operationModel.getOutputAttributes()).thenReturn(outputMock);
toMetadataDescriptorResult(componentWithOutput.getOutput().getType(), componentWithOutput.getOutput().hasDynamicType(), output); MetadataResult<TypeMetadataDescriptor> attributesDescriptor =
/** * Given a {@link MetadataKey} of a type and a {@link MetadataContext}, resolves the {@link MetadataType} of the Components's * output using the {@link OutputTypeResolver} associated to the current component. * * @param context {@link MetadataContext} of the Metadata resolution * @param key {@link MetadataKey} of the type which's structure has to be resolved * @return a {@link MetadataResult} with the {@link MetadataType} of the component's output */ private MetadataResult<MetadataType> getOutputMetadata(final MetadataContext context, final Object key) { OutputModel output = ((HasOutputModel) component).getOutput(); if (isVoid(output.getType()) || !output.hasDynamicType()) { return success(output.getType()); } try { MetadataType metadata = resolverFactory.getOutputResolver().getOutputType(context, key); if (isMetadataResolvedCorrectly(metadata, true)) { return success(adaptToListIfNecessary(metadata, key, context)); } MetadataFailure failure = newFailure() .withMessage("Error resolving Output Payload metadata") .withFailureCode(NO_DYNAMIC_TYPE_AVAILABLE) .withReason(NULL_TYPE_ERROR) .onOutputPayload(); return failure(output.getType(), failure); } catch (Exception e) { return failure(output.getType(), newFailure(e).onOutputPayload()); } }
private MetadataType wrapInMessageType(MetadataType type, Object key, MetadataContext context, Optional<MetadataType> staticAttributes) throws MetadataResolvingException { MessageMetadataTypeBuilder message = new MessageMetadataTypeBuilder().payload(type); staticAttributes.ifPresent(message::attributes); if (((HasOutputModel) component).getOutputAttributes().hasDynamicType()) { MetadataResult<MetadataType> attributes = resolveOutputAttributesMetadata(context, key, Objects::nonNull); if (!attributes.isSuccess()) { throw new MetadataResolvingException("Could not resolve attributes of List<Message> output", attributes.getFailures().stream() .map(MetadataFailure::getFailureCode) .findFirst() .orElse(UNKNOWN)); } message.attributes(attributes.get()); } return message.build(); }
/** * The operation returns its input as the output. * * @param model the model to assert on */ private void assertOutputSameAsInput(final OperationModel model) { assertThat(model.getOutput().getType(), instanceOf(VoidType.class)); assertThat(model.getOutput().hasDynamicType(), is(false)); assertThat(model.getOutputAttributes().getType(), instanceOf(VoidType.class)); assertThat(model.getOutputAttributes().hasDynamicType(), is(false)); }
/** * The operation buids its own output, leaving the resulting message without attrbiutes. * * @param model the model to assert on */ private void assertComponentDeterminesOutput(final OperationModel model) { assertThat(model.getOutput().getType(), instanceOf(DefaultAnyType.class)); assertThat(model.getOutput().hasDynamicType(), is(false)); assertThat(model.getOutputAttributes().getType(), instanceOf(VoidType.class)); assertThat(model.getOutputAttributes().hasDynamicType(), is(false)); }
/** * The operation returns the result of one of its routes, keeping the attributes of the result message. * * @param model the model to assert on */ private void assertAssociatedProcessorsChangeOutput(final OperationModel model) { assertThat(model.getOutput().getType(), instanceOf(DefaultAnyType.class)); assertThat(model.getOutput().hasDynamicType(), is(false)); assertThat(model.getOutputAttributes().getType(), instanceOf(DefaultAnyType.class)); assertThat(model.getOutputAttributes().hasDynamicType(), is(false)); }
/** * Given a {@link MetadataKey} of a type and a {@link MetadataContext}, resolves the {@link MetadataType} of the Components's * output {@link Message#getAttributes()} using the {@link OutputTypeResolver} associated to the current component. * * @param context {@link MetadataContext} of the Metadata resolution * @param key {@link MetadataKey} of the type which's structure has to be resolved * @return a {@link MetadataResult} with the {@link MetadataType} of the components output {@link Message#getAttributes()} */ private MetadataResult<MetadataType> getOutputAttributesMetadata(final MetadataContext context, Object key) { OutputModel attributes = ((HasOutputModel) component).getOutputAttributes(); if (isVoid(attributes.getType()) || !attributes.hasDynamicType()) { return success(attributes.getType()); } return resolveOutputAttributesMetadata(context, key, (metadata) -> isMetadataResolvedCorrectly(metadata, true)); }
@Test public void scheduler() { final SourceModel schedulerModel = coreExtensionModel.getSourceModel("scheduler").get(); assertThat(schedulerModel.getStereotype(), is(SOURCE)); assertThat(schedulerModel.getErrorModels(), empty()); assertThat(schedulerModel.hasResponse(), is(false)); assertThat(schedulerModel.getOutput().getType(), instanceOf(DefaultObjectType.class)); assertThat(schedulerModel.getOutput().hasDynamicType(), is(false)); assertThat(schedulerModel.getOutputAttributes().getType(), instanceOf(DefaultObjectType.class)); assertThat(schedulerModel.getOutputAttributes().hasDynamicType(), is(false)); final List<ParameterModel> paramModels = schedulerModel.getAllParameterModels(); assertThat(paramModels, hasSize(1)); assertSchedulingStrategy(paramModels.get(0)); }
toMetadataDescriptorResult(componentWithOutput.getOutput().getType(), componentWithOutput.getOutput().hasDynamicType(), output); MetadataResult<TypeMetadataDescriptor> attributesDescriptor =
/** * Given a {@link MetadataKey} of a type and a {@link MetadataContext}, resolves the {@link MetadataType} of the Components's * output using the {@link OutputTypeResolver} associated to the current component. * * @param context {@link MetadataContext} of the Metadata resolution * @param key {@link MetadataKey} of the type which's structure has to be resolved * @return a {@link MetadataResult} with the {@link MetadataType} of the component's output */ private MetadataResult<MetadataType> getOutputMetadata(final MetadataContext context, final Object key) { OutputModel output = ((HasOutputModel) component).getOutput(); if (isVoid(output.getType()) || !output.hasDynamicType()) { return success(output.getType()); } try { MetadataType metadata = resolverFactory.getOutputResolver().getOutputType(context, key); if (isMetadataResolvedCorrectly(metadata, true)) { return success(adaptToListIfNecessary(metadata, key, context)); } MetadataFailure failure = newFailure() .withMessage("Error resolving Output Payload metadata") .withFailureCode(NO_DYNAMIC_TYPE_AVAILABLE) .withReason(NULL_TYPE_ERROR) .onOutputPayload(); return failure(output.getType(), failure); } catch (Exception e) { return failure(output.getType(), newFailure(e).onOutputAttributes()); } }