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