diff --git a/src/main/java/no/entur/uttu/export/netex/producer/NetexIdProducer.java b/src/main/java/no/entur/uttu/export/netex/producer/NetexIdProducer.java index ec5bb7a8..bdc1005b 100644 --- a/src/main/java/no/entur/uttu/export/netex/producer/NetexIdProducer.java +++ b/src/main/java/no/entur/uttu/export/netex/producer/NetexIdProducer.java @@ -25,6 +25,7 @@ import org.rutebanken.netex.model.EntityInVersionStructure; import org.rutebanken.netex.model.EntityStructure; import org.rutebanken.netex.model.VersionOfObjectRefStructure; +import org.rutebanken.netex.model.VersionedChildStructure; public class NetexIdProducer { @@ -42,7 +43,7 @@ public static Ref replaceEntityName(Ref ref, String newEntityName) { public static String getId(N netex, Ref ref) { return getId( NetexIdProducer.getObjectIdPrefix(ref.id), - netex.getClass().getSimpleName(), + getEntityName(netex), NetexIdProducer.getObjectIdSuffix(ref.id) ); } @@ -123,6 +124,10 @@ public static String getEntityName(E entity) { if (localPart.endsWith("Structure")) { localPart = localPart.substring(0, localPart.lastIndexOf("Structure")); } + } else if (entity instanceof VersionedChildStructure) { + if (localPart.endsWith("VersionedChildStructure")) { + localPart = localPart.substring(0, localPart.lastIndexOf("_VersionedChildStructure")); + } } return localPart; } diff --git a/src/test/java/no/entur/uttu/export/netex/producer/NetexObjectFactoryTest.java b/src/test/java/no/entur/uttu/export/netex/producer/NetexObjectFactoryTest.java new file mode 100644 index 00000000..c456cdab --- /dev/null +++ b/src/test/java/no/entur/uttu/export/netex/producer/NetexObjectFactoryTest.java @@ -0,0 +1,27 @@ +package no.entur.uttu.export.netex.producer; + +import no.entur.uttu.config.ExportTimeZone; +import no.entur.uttu.model.Ref; +import no.entur.uttu.util.DateUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.rutebanken.netex.model.ServiceLinkInJourneyPattern_VersionedChildStructure; + +public class NetexObjectFactoryTest { + + @Test + void populateIdReturnsValidIdForVersionedChildStructureElements() { + NetexObjectFactory factory = new NetexObjectFactory( + new DateUtils(), + new ExportTimeZone() + ); + + Assertions.assertEquals( + "ENT:ServiceLinkInJourneyPattern:1", + factory.populateId( + new ServiceLinkInJourneyPattern_VersionedChildStructure(), + new Ref("ENT:ServiceLink:1", "1") + ).getId() + ); + } +}