Skip to content

Commit

Permalink
Fix another test case
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelbey committed Nov 28, 2024
1 parent 100e704 commit 0b817a7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,20 @@
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.ClassUtil;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.eclipse.collections.api.block.function.Function0;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.impl.multimap.list.FastListMultimap;
import org.eclipse.collections.impl.factory.Lists;
import org.eclipse.collections.impl.utility.LazyIterate;
import org.eclipse.collections.impl.utility.ListIterate;
import org.finos.legend.engine.protocol.pure.v1.extension.ProtocolConverter;
import org.finos.legend.engine.protocol.pure.v1.extension.ProtocolSubTypeInfo;
import org.finos.legend.engine.protocol.pure.v1.extension.PureProtocolExtension;
Expand Down Expand Up @@ -101,9 +99,9 @@ public static <T extends ObjectMapper> T withPureProtocolExtensions(T objectMapp
return withPureProtocolExtensions(objectMapper, ObjectMapper::registerModule, ObjectMapper::registerSubtypes, excludeSubType);
}

public static Map<String, Class> getClassInstanceTypeMappings()
public static Map<String, Class<?>> getClassInstanceTypeMappings()
{
Map<String, Class> result = Maps.mutable.empty();
Map<String, Class<?>> result = Maps.mutable.empty();
result.put("path", Path.class);
result.put("rootGraphFetchTree", RootGraphFetchTree.class);
result.put(">", RelationStoreAccessor.class);
Expand All @@ -123,7 +121,7 @@ public static Map<String, Class> getClassInstanceTypeMappings()
result.put("runtimeInstance", RuntimeInstance.class);
result.put("executionContextInstance", ExecutionContextInstance.class);
result.put("alloySerializationConfig", SerializationConfig.class);
PureProtocolExtensionLoader.extensions().forEach(extension -> extension.getExtraClassInstanceTypeMappings().entrySet().forEach(e -> result.put(e.getKey(), e.getValue())));
PureProtocolExtensionLoader.extensions().forEach(extension -> extension.getExtraClassInstanceTypeMappings().forEach(result::put));
return result;
}

Expand Down Expand Up @@ -189,7 +187,13 @@ public static ObjectMapper withPureProtocolConverter(ObjectMapper objectMapper)
.flatMap(List::stream)
.collect(Collectors.toList());

FastListMultimap<JavaType, ProtocolConverter<?>> converterByType = ListIterate.groupBy(protocolConverters, x -> x.getInputType(TypeFactory.defaultInstance()));
Map<JavaType, ProtocolConverter<?>> converterByType = protocolConverters
.stream()
.collect(Collectors.toMap(
x -> x.getInputType(objectMapper.getTypeFactory()),
Function.identity(),
(a, b) -> ProtocolConverter.merge((ProtocolConverter<Object>) a, (ProtocolConverter<Object>) b))
);

DeserializationConfig deserializationConfig = objectMapper
.getDeserializationConfig()
Expand All @@ -203,21 +207,21 @@ public static ObjectMapper withPureProtocolConverter(ObjectMapper objectMapper)

private static class ConverterHandlerInstantiator extends HandlerInstantiator
{
private final FastListMultimap<JavaType, ProtocolConverter<?>> converterByType;
private final Map<JavaType, ProtocolConverter<?>> converterByType;

public ConverterHandlerInstantiator(FastListMultimap<JavaType, ProtocolConverter<?>> converterByType)
public ConverterHandlerInstantiator(Map<JavaType, ProtocolConverter<?>> converterByType)
{
this.converterByType = converterByType;
}

@Override
public JsonDeserializer<?> deserializerInstance(DeserializationConfig config, Annotated annotated, Class<?> deserClass)
{
MutableList<ProtocolConverter<?>> converters = this.converterByType.get(annotated.getType());
if (!converters.isEmpty())
ProtocolConverter<?> converter = this.converterByType.get(annotated.getType());
if (converter != null)
{
JsonDeserializer<?> deser = (JsonDeserializer<?>) ClassUtil.createInstance(deserClass, config.canOverrideAccessModifiers());
return new StdDelegatingDeserializer<>(ProtocolConverter.merge((List) converters), annotated.getType(), deser);
JsonDeserializer<?> deserializer = (JsonDeserializer<?>) ClassUtil.createInstance(deserClass, config.canOverrideAccessModifiers());
return new StdDelegatingDeserializer(converter, annotated.getType(), deserializer);
}
return null;
}
Expand Down Expand Up @@ -249,20 +253,20 @@ public TypeIdResolver typeIdResolverInstance(MapperConfig<?> config, Annotated a

private static class ConverterBeanDeserializerModifier extends BeanDeserializerModifier
{
private final FastListMultimap<JavaType, ProtocolConverter<?>> converterByType;
private final Map<JavaType, ProtocolConverter<?>> converterByType;

public ConverterBeanDeserializerModifier(FastListMultimap<JavaType, ProtocolConverter<?>> converterByType)
public ConverterBeanDeserializerModifier(Map<JavaType, ProtocolConverter<?>> converterByType)
{
this.converterByType = converterByType;
}

@Override
public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer)
{
MutableList<ProtocolConverter<?>> converters = this.converterByType.get(beanDesc.getType());
if (!converters.isEmpty())
ProtocolConverter<?> converter = this.converterByType.get(beanDesc.getType());
if (converter != null)
{
return new StdDelegatingDeserializer<Object>(ProtocolConverter.merge((List) converters), beanDesc.getType(), deserializer);
return new StdDelegatingDeserializer(converter, beanDesc.getType(), deserializer);
}
return deserializer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.Converter;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.impl.factory.Lists;
import org.eclipse.collections.impl.utility.ListIterate;

public class ProtocolConverter<T> implements Converter<T, T>
{
private final List<? extends Converter<T, T>> converters;
private final List<Converter<T, T>> converters;

public ProtocolConverter(Converter<T, T> converters)
{
this(Lists.fixedSize.of(converters));
}

public ProtocolConverter(List<? extends Converter<T, T>> converters)
public ProtocolConverter(List<Converter<T, T>> converters)
{
this.converters = converters;
}
Expand All @@ -55,9 +55,9 @@ public T convert(T value)
return ListIterate.injectInto(value, this.converters, (t, c) -> c.convert(t));
}

public static <T> ProtocolConverter<T> merge(List<ProtocolConverter<T>> converters)
public static <T> ProtocolConverter<T> merge(ProtocolConverter<T> one, ProtocolConverter<T> two)
{
List<? extends Converter<T, T>> allConverters = converters.stream().flatMap(x -> x.converters.stream()).collect(Collectors.toList());
MutableList<Converter<T, T>> allConverters = Lists.mutable.withAll(one.converters).withAll(two.converters);
return new ProtocolConverter<>(allConverters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,23 @@
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import java.io.IOException;
import java.util.Map;
import org.eclipse.collections.api.factory.Lists;
import org.finos.legend.engine.protocol.pure.v1.PureProtocolObjectMapperFactory;
import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecificationVisitor;

import java.io.IOException;
import java.util.Map;

@JsonDeserialize(using = ClassInstance.InstanceValueDeserializer.class)
public class ClassInstance extends One
{
private static Map<String, java.lang.Class> classMap = PureProtocolObjectMapperFactory.getClassInstanceTypeMappings();
private static final Map<String, java.lang.Class<?>> classMap = PureProtocolObjectMapperFactory.getClassInstanceTypeMappings();

public String type;
@JsonSerialize(using = ClassInstance.ValueSerializer.class, contentUsing = ClassInstance.ValueSerializer.class)
Expand Down Expand Up @@ -72,7 +70,7 @@ public ClassInstance deserialize(JsonParser jsonParser, DeserializationContext d
JsonNode node = oc.readTree(jsonParser);
ClassInstance result = new ClassInstance();
result.type = node.get("type").textValue();
java.lang.Class _class = classMap.get(result.type);
Class<?> _class = classMap.get(result.type);
if (_class == null)
{
throw new RuntimeException("Can't parse the ClassInstance value for type '" + result.type + "'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1204,8 +1204,8 @@ public void testServiceTestSuiteWithServiceStore()
" | gerParam=1&floatParam=1.123&booleanParam=false\n" +
" |\n" +
"Query: booleanParam = false | booleanParam: false\n" +
"Query: stringParam = dummy | stringParam: dummy\n" +
"Query: floatParam = 1.123 | floatParam: 1.123\n" +
"Query: stringParam = dummy | stringParam: dummy\n" +
" |\n" +
" |\n" +
"-----------------------------------------------------------------------------------------------------------------------\n")));
Expand Down

0 comments on commit 0b817a7

Please sign in to comment.