Search in sources :

Example 11 with DataType

use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.

the class TransformationGraph method removeConverter.

public void removeConverter(Converter converter) {
    if (!registeredConverters.contains(converter)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Attempt to remove an unregistered converter: " + converter);
        }
        return;
    }
    DataType returnDataType = converter.getReturnDataType();
    for (DataType sourceDataType : converter.getSourceDataTypes()) {
        Set<TransformationEdge> allEdges = getAllEdges(sourceDataType, returnDataType);
        for (TransformationEdge edge : allEdges) {
            if (edge.getConverter() == converter) {
                DataType source = getEdgeSource(edge);
                DataType target = getEdgeTarget(edge);
                removeEdge(edge);
                if (inDegreeOf(source) == 0 && outDegreeOf(source) == 0) {
                    removeVertex(source);
                }
                if (inDegreeOf(target) == 0 && outDegreeOf(target) == 0) {
                    removeVertex(target);
                }
            }
        }
    }
    registeredConverters.remove(converter);
}
Also used : DataType(org.mule.runtime.api.metadata.DataType)

Example 12 with DataType

use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.

the class TransformationGraphLookupStrategy method lookupConverters.

/**
 * Looks for {@link Converter} to convert from the source to the target data types.
 * All {@link Converter}s found will have a source that is compatible with {@param source}
 * (since if a converter can convert a super type, it should be able to convert any type that extends it)
 * and a target such that {@param target} isCompatibleWith() the {@link Converter}'s one
 * (since if we want a converter that returns an specific type, it should return exactly that type or any type that extends it.)
 *
 * @param source data type to be converted
 * @param target data type to be converted to
 * @return a list of {@link Converter} that are able to convert from the source to the target data types.
 */
public List<Converter> lookupConverters(DataType source, DataType target) {
    List<Converter> converters = new LinkedList<>();
    if (!graph.containsVertexOrSuper(source)) {
        return converters;
    }
    if (!graph.containsVertexOrSub(target)) {
        return converters;
    }
    // Since we should have all possible transformations we should check for them all.
    List<DataType> compatibleSourceVertexes = graph.getSuperVertexes(source);
    List<DataType> compatibleTargetVertexes = graph.getSubVertexes(target);
    List<List<TransformationEdge>> transformationPaths = new LinkedList<>();
    for (DataType sourceVertex : compatibleSourceVertexes) {
        for (DataType targetVertex : compatibleTargetVertexes) {
            transformationPaths.addAll(findTransformationPaths(sourceVertex, targetVertex, new HashSet<>()));
        }
    }
    converters = createConverters(transformationPaths);
    return converters;
}
Also used : Converter(org.mule.runtime.core.api.transformer.Converter) CompositeConverter(org.mule.runtime.core.privileged.transformer.CompositeConverter) DataType(org.mule.runtime.api.metadata.DataType) List(java.util.List) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 13 with DataType

use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.

the class ContentTypeHandlingTestCase method setEncodingInMimeTypeAndParam.

@Test
public void setEncodingInMimeTypeAndParam() throws Exception {
    CoreEvent response = runFlow("setEncodingInMimeTypeAndParam");
    DataType dataType = response.getMessage().getPayload().getDataType();
    assertThat(dataType.getMediaType().getPrimaryType(), is("application"));
    assertThat(dataType.getMediaType().getSubType(), is("json"));
    assertThat(dataType.getMediaType().getCharset().get(), is(StandardCharsets.UTF_16));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType) Test(org.junit.Test)

Example 14 with DataType

use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.

the class ContentTypeHandlingTestCase method overridesContentType.

@Test
public void overridesContentType() throws Exception {
    Charset lastSupportedEncoding = availableCharsets().values().stream().reduce((first, last) -> last).get();
    CoreEvent response = runFlow("setsContentTypeProgrammatically");
    final DataType dataType = response.getMessage().getPayload().getDataType();
    assertCustomMimeType(dataType);
    assertThat(dataType.getMediaType().getCharset().get(), is(lastSupportedEncoding));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) SystemProperty(org.mule.tck.junit4.rule.SystemProperty) Charset.defaultCharset(java.nio.charset.Charset.defaultCharset) BeforeClass(org.junit.BeforeClass) DataType(org.mule.runtime.api.metadata.DataType) UTF_8(java.nio.charset.StandardCharsets.UTF_8) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TEXT(org.mule.runtime.api.metadata.MediaType.TEXT) Test(org.junit.Test) StandardCharsets(java.nio.charset.StandardCharsets) Assert.assertThat(org.junit.Assert.assertThat) Rule(org.junit.Rule) ISO_8859_1(java.nio.charset.StandardCharsets.ISO_8859_1) Charset(java.nio.charset.Charset) Charset.availableCharsets(java.nio.charset.Charset.availableCharsets) SystemUtils.getDefaultEncoding(org.mule.runtime.core.api.util.SystemUtils.getDefaultEncoding) FlowRunner(org.mule.functional.api.flow.FlowRunner) MediaType(org.mule.runtime.api.metadata.MediaType) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Charset.defaultCharset(java.nio.charset.Charset.defaultCharset) Charset(java.nio.charset.Charset) DataType(org.mule.runtime.api.metadata.DataType) Test(org.junit.Test)

Example 15 with DataType

use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.

the class ContentTypeHandlingTestCase method onlySetEncodingOnXml.

@Test
public void onlySetEncodingOnXml() throws Exception {
    CoreEvent response = runFlow("onlySetEncodingOnXml");
    DataType dataType = response.getMessage().getPayload().getDataType();
    assertCustomEncoding(dataType);
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType) Test(org.junit.Test)

Aggregations

DataType (org.mule.runtime.api.metadata.DataType)102 Test (org.junit.Test)67 SmallTest (org.mule.tck.size.SmallTest)29 DefaultCollectionDataType (org.mule.runtime.core.internal.metadata.DefaultCollectionDataType)24 FunctionDataType (org.mule.runtime.api.metadata.FunctionDataType)20 DefaultFunctionDataType (org.mule.runtime.core.internal.metadata.DefaultFunctionDataType)20 DefaultMapDataType (org.mule.runtime.core.internal.metadata.DefaultMapDataType)20 SimpleDataType (org.mule.runtime.core.internal.metadata.SimpleDataType)20 Message (org.mule.runtime.api.message.Message)18 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)18 TypedValue (org.mule.runtime.api.metadata.TypedValue)12 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)12 CompiledExpression (org.mule.mvel2.compiler.CompiledExpression)10 CollectionDataType (org.mule.runtime.api.metadata.CollectionDataType)10 Transformer (org.mule.runtime.core.api.transformer.Transformer)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 ParserContext (org.mule.mvel2.ParserContext)7 MapDataType (org.mule.runtime.api.metadata.MapDataType)6 MVELExpressionLanguage (org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage)6