Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<properties>
<java.version>17</java.version>
<entur.helpers.version>1.0.77</entur.helpers.version>
<netex-parser-java.version>2.2.0</netex-parser-java.version>
<netex-parser-java.version>2.3.0</netex-parser-java.version>
<jaxb-version>2.3.0.1</jaxb-version>
<entur-kafka-spring-starter.version>2.9.13.2</entur-kafka-spring-starter.version>
</properties>
Expand Down Expand Up @@ -139,6 +139,12 @@
<version>1.11.3</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
<version>2.8.11</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.confluent/kafka-avro-serializer -->
<dependency>
<groupId>io.confluent</groupId>
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/no/entur/mummu/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
import no.entur.mummu.serializers.CustomSerializers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -49,18 +51,24 @@ public void configureMessageConverters(List<HttpMessageConverter<?>> converters)
converters.add(new NetexHttpMessageConverter());
}

@Override
/* @Override
public void addFormatters(FormatterRegistry registry) {
WebMvcConfigurer.super.addFormatters(registry);
registry.addFormatter(new StringToVehicleModeEnumeration());
registry.addFormatter(new StringToStopTypeEnumeration());
}
}*/

public ObjectMapper jsonObjectMapper() {
ArrayList<Module> modules = new ArrayList<>();

var customSerializersModule = new SimpleModule();
customSerializersModule.setSerializers(customSerializers);
modules.add(customSerializersModule);

JaxbAnnotationModule jaxbAnnotationModule = new JaxbAnnotationModule();
modules.add(jaxbAnnotationModule);


return Jackson2ObjectMapperBuilder.json()
.serializationInclusion(JsonInclude.Include.NON_EMPTY)
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/no/entur/mummu/resources/RestResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javax.xml.bind.JAXBElement;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;


@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.module.SimpleSerializers;
import com.fasterxml.jackson.databind.type.TypeFactory;
import org.rutebanken.netex.model.TariffZoneRefs_RelStructure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -36,6 +37,10 @@ public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType typ
return new LocalDateTimeWithConstantZoneSerializer(mummuSerializerContext);
}

if (type.getRawClass().equals(TariffZoneRefs_RelStructure.class)) {
return new TariffZoneRefsSerializer();
}

return super.findSerializer(config, type, beanDesc);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;

import javax.xml.bind.JAXBElement;
import java.io.IOException;
Expand All @@ -17,4 +18,12 @@ public void serialize(JAXBElement<?> jaxbElement, JsonGenerator jsonGenerator, S
jsonGenerator.writeObjectField("value", jaxbElement.getValue());
jsonGenerator.writeEndObject();
}

@Override
public void serializeWithType(JAXBElement<?> jaxbElement, JsonGenerator jsonGenerator, SerializerProvider serializerProvider, TypeSerializer typeSer) throws IOException {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("type", jaxbElement.getName().getLocalPart());
jsonGenerator.writeObjectField("value", jaxbElement.getValue());
jsonGenerator.writeEndObject();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package no.entur.mummu.serializers;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.rutebanken.netex.model.TariffZoneRefs_RelStructure;

import java.io.IOException;

public class TariffZoneRefsSerializer extends JsonSerializer<TariffZoneRefs_RelStructure> {
@Override
public void serialize(TariffZoneRefs_RelStructure tariffZoneRefsRelStructure, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeStartArray();
for (var tariffZone :tariffZoneRefsRelStructure.getTariffZoneRef_()) {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("ref", tariffZone.getValue().getRef());
jsonGenerator.writeObjectField("version", tariffZone.getValue().getVersion());
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
public class NetexObjectFactory extends ObjectFactory {

public static final String NAMESPACE_URI = "http://www.netex.org.uk/netex";

private static final QName _stopPlace_QNAME = new QName(NAMESPACE_URI, "stopPlace");
private static final QName _stopPlaces_QNAME = new QName(NAMESPACE_URI, "stopPlaces");
private static final QName _groupsOfStopPlaces_QNAME = new QName(NAMESPACE_URI, "groupsOfStopPlaces");
private static final QName _fareZones_QNAME = new QName(NAMESPACE_URI, "fareZones");
Expand All @@ -40,7 +42,7 @@ public JAXBElement<GroupsOfStopPlacesInFrame_RelStructure> createGroupsOfStopPla
}

public JAXBElement<StopPlacesInFrame_RelStructure> createStopPlaces(List<StopPlace> stopPlaces) {
var stopPlacesInFrame = createStopPlacesInFrame_RelStructure().withStopPlace(stopPlaces);
var stopPlacesInFrame = createStopPlacesInFrame_RelStructure().withStopPlace_(stopPlaces.stream().map(stopPlace -> new JAXBElement<>(_stopPlace_QNAME, StopPlace.class, stopPlace)).collect(Collectors.toList()));
return new JAXBElement<>(_stopPlaces_QNAME, StopPlacesInFrame_RelStructure.class, stopPlacesInFrame);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void delete(String stopPlaceId) {
log.info("couldn't find stop place in index {}", stopPlaceId);
} else {
if (stopPlace.getQuays() != null) {
stopPlace.getQuays().getQuayRefOrQuay().forEach(quay -> netexEntitiesIndex.getQuayIndex().remove(((Quay) quay).getId()));
stopPlace.getQuays().getQuayRefOrQuay().forEach(quay -> netexEntitiesIndex.getQuayIndex().remove(((Quay) quay.getValue()).getId()));
}
netexEntitiesIndex.getStopPlaceIndex().getLatestVersions().forEach(stop -> {
if (stop.getParentSiteRef() != null && stop.getParentSiteRef().getRef().equals(stopPlaceId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void testDelete() {
Assertions.assertTrue(netexEntitiesIndex.getStopPlaceIndex().getAllVersions("NSR:StopPlace:4055").size() > 0);
Collection<String> quays = netexEntitiesIndex.getStopPlaceIndex().getLatestVersion("NSR:StopPlace:4055").getQuays().getQuayRefOrQuay()
.stream()
.map(o -> (Quay) o)
.map(o -> (Quay) o.getValue())
.map(EntityStructure::getId)
.collect(Collectors.toList());

Expand Down