Search in sources :

Example 1 with FareZone

use of org.rutebanken.netex.model.FareZone in project tiamat by entur.

the class TariffZoneImportHandler method handleTariffZones.

public void handleTariffZones(SiteFrame netexSiteFrame, ImportParams importParams, AtomicInteger tariffZoneImportedCounter, SiteFrame responseSiteframe) {
    if (publicationDeliveryHelper.hasTariffZones(netexSiteFrame) && importParams.importType != ImportType.ID_MATCH) {
        List<org.rutebanken.tiamat.model.TariffZone> tiamatTariffZones = netexSiteFrame.getTariffZones().getTariffZone().stream().filter(this::isTariffZone).map(jaxbElement -> (TariffZone) jaxbElement.getValue()).map(netexMapper::mapToTiamatModel).collect(Collectors.toList());
        List<org.rutebanken.tiamat.model.FareZone> tiamatFareZones = netexSiteFrame.getTariffZones().getTariffZone().stream().filter(this::isFareZone).map(jaxbElement -> (FareZone) jaxbElement.getValue()).map(netexMapper::mapToTiamatModel).collect(Collectors.toList());
        logger.debug("Mapped {} tariff zones from netex to internal model", tiamatTariffZones.size());
        List<JAXBElement<? extends Zone_VersionStructure>> importedTariffZones = tariffZoneImporter.importTariffZones(tiamatTariffZones).stream().map(tariffZone -> new ObjectFactory().createTariffZone(tariffZone)).collect(Collectors.toList());
        logger.debug("Got {} imported tariffZones ", importedTariffZones.size());
        List<JAXBElement<? extends Zone_VersionStructure>> importedFareZones = fareZoneImporter.importFareZones(tiamatFareZones).stream().map(fareZone -> new ObjectFactory().createFareZone(fareZone)).collect(Collectors.toList());
        if (!importedTariffZones.isEmpty()) {
            responseSiteframe.withTariffZones(new TariffZonesInFrame_RelStructure().withTariffZone(importedTariffZones));
        }
        if (!importedFareZones.isEmpty()) {
            responseSiteframe.withTariffZones(new TariffZonesInFrame_RelStructure().withTariffZone(importedFareZones));
        }
    }
}
Also used : FareZone(org.rutebanken.netex.model.FareZone) ImportParams(org.rutebanken.tiamat.importer.ImportParams) Logger(org.slf4j.Logger) SiteFrame(org.rutebanken.netex.model.SiteFrame) TariffZone(org.rutebanken.netex.model.TariffZone) TariffZoneImporter(org.rutebanken.tiamat.importer.TariffZoneImporter) PublicationDeliveryHelper(org.rutebanken.tiamat.netex.mapping.PublicationDeliveryHelper) JAXBElement(javax.xml.bind.JAXBElement) FareZoneImporter(org.rutebanken.tiamat.importer.FareZoneImporter) LoggerFactory(org.slf4j.LoggerFactory) NetexMapper(org.rutebanken.tiamat.netex.mapping.NetexMapper) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) List(java.util.List) TariffZonesInFrame_RelStructure(org.rutebanken.netex.model.TariffZonesInFrame_RelStructure) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Zone_VersionStructure(org.rutebanken.netex.model.Zone_VersionStructure) ObjectFactory(org.rutebanken.netex.model.ObjectFactory) ImportType(org.rutebanken.tiamat.importer.ImportType) TariffZone(org.rutebanken.netex.model.TariffZone) TariffZonesInFrame_RelStructure(org.rutebanken.netex.model.TariffZonesInFrame_RelStructure) ObjectFactory(org.rutebanken.netex.model.ObjectFactory) FareZone(org.rutebanken.netex.model.FareZone) JAXBElement(javax.xml.bind.JAXBElement) Zone_VersionStructure(org.rutebanken.netex.model.Zone_VersionStructure)

Example 2 with FareZone

use of org.rutebanken.netex.model.FareZone in project tiamat by entur.

the class FareZoneImportTest method publicationDeliveryWithFareZone.

@Test
public void publicationDeliveryWithFareZone() throws Exception {
    LocalDateTime validFrom = LocalDateTime.now().minusDays(3);
    List<JAXBElement<? extends Zone_VersionStructure>> tariffZones = new ArrayList<>();
    FareZone fareZone = new FareZone().withName(new MultilingualString().withValue("V02")).withVersion("1").withValidBetween(new ValidBetween().withFromDate(validFrom)).withId("RUT:FareZone:01");
    tariffZones.add(new ObjectFactory().createFareZone(fareZone));
    SiteFrame siteFrame = publicationDeliveryTestHelper.siteFrame().withTariffZones(new TariffZonesInFrame_RelStructure().withTariffZone(tariffZones));
    PublicationDeliveryStructure publicationDeliveryStructure = publicationDeliveryTestHelper.publicationDelivery(siteFrame);
    PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDeliveryStructure);
    final List<JAXBElement<? extends Zone_VersionStructure>> actualZones = publicationDeliveryTestHelper.findSiteFrame(response).getTariffZones().getTariffZone();
    assertThat(actualZones).isNotEmpty();
    assertThat(actualZones.get(0).getValue().getName().getValue()).isEqualTo(fareZone.getName().getValue());
}
Also used : LocalDateTime(java.time.LocalDateTime) SiteFrame(org.rutebanken.netex.model.SiteFrame) TariffZonesInFrame_RelStructure(org.rutebanken.netex.model.TariffZonesInFrame_RelStructure) ObjectFactory(org.rutebanken.netex.model.ObjectFactory) ArrayList(java.util.ArrayList) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) JAXBElement(javax.xml.bind.JAXBElement) Zone_VersionStructure(org.rutebanken.netex.model.Zone_VersionStructure) FareZone(org.rutebanken.netex.model.FareZone) MultilingualString(org.rutebanken.netex.model.MultilingualString) ValidBetween(org.rutebanken.netex.model.ValidBetween) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 3 with FareZone

use of org.rutebanken.netex.model.FareZone in project tiamat by entur.

the class FareZoneImportTest method publicationDeliveryWithFareZoneAndStopPlace.

@Test
public void publicationDeliveryWithFareZoneAndStopPlace() throws Exception {
    LocalDateTime validFrom = LocalDateTime.now().minusDays(3);
    List<JAXBElement<? extends Zone_VersionStructure>> tariffZones = new ArrayList<>();
    FareZone fareZone = new FareZone().withName(new MultilingualString().withValue("V02")).withVersion("1").withValidBetween(new ValidBetween().withFromDate(validFrom)).withId("RUT:FareZone:05");
    tariffZones.add(new ObjectFactory().createFareZone(fareZone));
    StopPlace stopPlace = new StopPlace();
    stopPlace.withId("XYZ:StopPlace:32111");
    stopPlace.setVersion("1");
    stopPlace.setTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withVersion(fareZone.getVersion()).withRef(fareZone.getId())));
    SiteFrame siteFrame = publicationDeliveryTestHelper.siteFrame().withTariffZones(new TariffZonesInFrame_RelStructure().withTariffZone(tariffZones)).withStopPlaces(new StopPlacesInFrame_RelStructure().withStopPlace(stopPlace));
    PublicationDeliveryStructure publicationDeliveryStructure = publicationDeliveryTestHelper.publicationDelivery(siteFrame);
    ImportParams importParams = new ImportParams();
    importParams.importType = ImportType.INITIAL;
    // First
    publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDeliveryStructure, importParams);
    PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDeliveryStructure, importParams);
    List<JAXBElement<? extends Zone_VersionStructure>> actualZones = publicationDeliveryTestHelper.findSiteFrame(response).getTariffZones().getTariffZone();
    assertThat(actualZones).isNotEmpty();
    assertThat(actualZones.get(0).getValue().getName().getValue()).isEqualTo(fareZone.getName().getValue());
    // Versions for tariff zones are incremented.
    assertThat(actualZones.get(0).getValue().getVersion()).isEqualTo("2");
}
Also used : LocalDateTime(java.time.LocalDateTime) TariffZoneRefs_RelStructure(org.rutebanken.netex.model.TariffZoneRefs_RelStructure) StopPlace(org.rutebanken.netex.model.StopPlace) SiteFrame(org.rutebanken.netex.model.SiteFrame) TariffZonesInFrame_RelStructure(org.rutebanken.netex.model.TariffZonesInFrame_RelStructure) ArrayList(java.util.ArrayList) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) JAXBElement(javax.xml.bind.JAXBElement) FareZone(org.rutebanken.netex.model.FareZone) ValidBetween(org.rutebanken.netex.model.ValidBetween) StopPlacesInFrame_RelStructure(org.rutebanken.netex.model.StopPlacesInFrame_RelStructure) ObjectFactory(org.rutebanken.netex.model.ObjectFactory) ImportParams(org.rutebanken.tiamat.importer.ImportParams) Zone_VersionStructure(org.rutebanken.netex.model.Zone_VersionStructure) MultilingualString(org.rutebanken.netex.model.MultilingualString) TariffZoneRef(org.rutebanken.netex.model.TariffZoneRef) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 4 with FareZone

use of org.rutebanken.netex.model.FareZone in project tiamat by entur.

the class FareZoneImportTest method mergeFareZonesForStopPlace.

@Test
public void mergeFareZonesForStopPlace() throws Exception {
    SimplePoint_VersionStructure point = new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("77")).withLongitude(new BigDecimal("9.7")));
    List<JAXBElement<? extends Zone_VersionStructure>> tariffZones1 = new ArrayList<>();
    FareZone fareZone1 = new FareZone().withName(new MultilingualString().withValue("V03")).withVersion("1").withId("ATB:FareZone:01");
    tariffZones1.add(new ObjectFactory().createFareZone(fareZone1));
    StopPlace stopPlace = new StopPlace().withId("ATB:StopPlace:322").withName(new MultilingualString().withValue("name")).withCentroid(point).withVersion("1").withStopPlaceType(StopTypeEnumeration.ONSTREET_BUS).withTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withVersion(fareZone1.getVersion()).withRef(fareZone1.getId())));
    SiteFrame siteFrame = publicationDeliveryTestHelper.siteFrame().withTariffZones(new TariffZonesInFrame_RelStructure().withTariffZone(tariffZones1)).withStopPlaces(new StopPlacesInFrame_RelStructure().withStopPlace(stopPlace));
    PublicationDeliveryStructure publicationDeliveryStructure = publicationDeliveryTestHelper.publicationDelivery(siteFrame);
    ImportParams importParams = new ImportParams();
    importParams.importType = ImportType.INITIAL;
    // First
    publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDeliveryStructure, importParams);
    List<JAXBElement<? extends Zone_VersionStructure>> tariffZones2 = new ArrayList<>();
    FareZone fareZone2 = new FareZone().withName(new MultilingualString().withValue("X08")).withVersion("1").withId("NTR:FareZone:03");
    tariffZones2.add(new ObjectFactory().createFareZone(fareZone2));
    StopPlace stopPlace2 = new StopPlace().withId("NTR:StopPlace:322").withVersion("2").withStopPlaceType(StopTypeEnumeration.ONSTREET_BUS).withTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withVersion(fareZone2.getVersion()).withRef(fareZone2.getId())));
    SiteFrame siteFrame2 = publicationDeliveryTestHelper.siteFrame().withTariffZones(new TariffZonesInFrame_RelStructure().withTariffZone(tariffZones2)).withStopPlaces(new StopPlacesInFrame_RelStructure().withStopPlace(stopPlace2));
    PublicationDeliveryStructure publicationDeliveryStructure2 = publicationDeliveryTestHelper.publicationDelivery(siteFrame2);
    // Second import should match and merge tariffzones
    importParams.importType = ImportType.MATCH;
    PublicationDeliveryStructure matchReponse = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDeliveryStructure2, importParams);
    List<JAXBElement<? extends Zone_VersionStructure>> actualZones = publicationDeliveryTestHelper.findSiteFrame(matchReponse).getTariffZones().getTariffZone();
    assertThat(actualZones).isNotEmpty();
    assertThat(actualZones).hasSize(2);
    List<StopPlace> actualIdMatchedStopPlaces = publicationDeliveryTestHelper.extractStopPlaces(matchReponse);
    assertThat(actualIdMatchedStopPlaces).hasSize(1);
    assertThat(actualIdMatchedStopPlaces.get(0).getTariffZones().getTariffZoneRef()).as("number of tariff zone refs").hasSize(2);
    importParams.importType = ImportType.ID_MATCH;
    PublicationDeliveryStructure idMatchResponse = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDeliveryStructure2, importParams);
    actualZones = publicationDeliveryTestHelper.findSiteFrame(idMatchResponse).getTariffZones().getTariffZone();
    assertThat(actualZones).isNotEmpty();
    assertThat(actualZones).hasSize(2);
    actualIdMatchedStopPlaces = publicationDeliveryTestHelper.extractStopPlaces(matchReponse);
    assertThat(actualIdMatchedStopPlaces).hasSize(1);
    assertThat(actualIdMatchedStopPlaces.get(0).getTariffZones().getTariffZoneRef()).as("number of tariff zone refs").hasSize(2);
}
Also used : TariffZoneRefs_RelStructure(org.rutebanken.netex.model.TariffZoneRefs_RelStructure) StopPlace(org.rutebanken.netex.model.StopPlace) SiteFrame(org.rutebanken.netex.model.SiteFrame) TariffZonesInFrame_RelStructure(org.rutebanken.netex.model.TariffZonesInFrame_RelStructure) ArrayList(java.util.ArrayList) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) JAXBElement(javax.xml.bind.JAXBElement) FareZone(org.rutebanken.netex.model.FareZone) StopPlacesInFrame_RelStructure(org.rutebanken.netex.model.StopPlacesInFrame_RelStructure) LocationStructure(org.rutebanken.netex.model.LocationStructure) BigDecimal(java.math.BigDecimal) ObjectFactory(org.rutebanken.netex.model.ObjectFactory) ImportParams(org.rutebanken.tiamat.importer.ImportParams) Zone_VersionStructure(org.rutebanken.netex.model.Zone_VersionStructure) MultilingualString(org.rutebanken.netex.model.MultilingualString) TariffZoneRef(org.rutebanken.netex.model.TariffZoneRef) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 5 with FareZone

use of org.rutebanken.netex.model.FareZone in project tiamat by entur.

the class FareZoneMapper method mapBtoA.

@Override
public void mapBtoA(org.rutebanken.tiamat.model.FareZone tiamatFareZone, FareZone netexFareZone, MappingContext context) {
    super.mapBtoA(tiamatFareZone, netexFareZone, context);
    if (tiamatFareZone.getTransportOrganisationRef() != null) {
        final JAXBElement<AuthorityRefStructure> authorityRef = objectFactory.createAuthorityRef(new AuthorityRefStructure().withRef(tiamatFareZone.getTransportOrganisationRef()));
        netexFareZone.withTransportOrganisationRef(authorityRef);
    }
    if (!tiamatFareZone.getNeighbours().isEmpty()) {
        final List<FareZoneRefStructure> fareZoneRefs = tiamatFareZone.getNeighbours().stream().map(tariffZoneRef -> new FareZoneRefStructure().withRef(tariffZoneRef.getRef())).collect(Collectors.toList());
        final FareZoneRefs_RelStructure fareZoneRefsRelStructure = new FareZoneRefs_RelStructure().withFareZoneRef(fareZoneRefs);
        netexFareZone.withNeighbours(fareZoneRefsRelStructure);
    }
    if (!tiamatFareZone.getFareZoneMembers().isEmpty()) {
        List<JAXBElement<? extends PointRefStructure>> fareZoneMember = tiamatFareZone.getFareZoneMembers().stream().map(members -> convertStopPlaceRefToScheduledStopPointRef(members.getRef())).filter(Objects::nonNull).map(spRef -> new ObjectFactory().createScheduledStopPointRef(new ScheduledStopPointRefStructure().withRef(spRef))).collect(Collectors.toList());
        PointRefs_RelStructure pointRefsRelStructure = new PointRefs_RelStructure().withPointRef(fareZoneMember);
        netexFareZone.withMembers(pointRefsRelStructure);
    }
}
Also used : CustomMapper(ma.glasnost.orika.CustomMapper) FareZone(org.rutebanken.netex.model.FareZone) PointRefs_RelStructure(org.rutebanken.netex.model.PointRefs_RelStructure) ScheduledStopPointRefStructure(org.rutebanken.netex.model.ScheduledStopPointRefStructure) StopPlaceReference(org.rutebanken.tiamat.model.StopPlaceReference) JAXBElement(javax.xml.bind.JAXBElement) Set(java.util.Set) FareZoneRefs_RelStructure(org.rutebanken.netex.model.FareZoneRefs_RelStructure) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) MappingContext(ma.glasnost.orika.MappingContext) TariffZoneRef(org.rutebanken.tiamat.model.TariffZoneRef) HashSet(java.util.HashSet) Objects(java.util.Objects) AuthorityRefStructure(org.rutebanken.netex.model.AuthorityRefStructure) List(java.util.List) FareZoneRefStructure(org.rutebanken.netex.model.FareZoneRefStructure) ObjectFactory(org.rutebanken.netex.model.ObjectFactory) PointRefStructure(org.rutebanken.netex.model.PointRefStructure) ScopingMethodEnumeration(org.rutebanken.netex.model.ScopingMethodEnumeration) AuthorityRefStructure(org.rutebanken.netex.model.AuthorityRefStructure) ScheduledStopPointRefStructure(org.rutebanken.netex.model.ScheduledStopPointRefStructure) PointRefStructure(org.rutebanken.netex.model.PointRefStructure) ScheduledStopPointRefStructure(org.rutebanken.netex.model.ScheduledStopPointRefStructure) JAXBElement(javax.xml.bind.JAXBElement) FareZoneRefStructure(org.rutebanken.netex.model.FareZoneRefStructure) FareZoneRefs_RelStructure(org.rutebanken.netex.model.FareZoneRefs_RelStructure) ObjectFactory(org.rutebanken.netex.model.ObjectFactory) PointRefs_RelStructure(org.rutebanken.netex.model.PointRefs_RelStructure) Objects(java.util.Objects)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)7 FareZone (org.rutebanken.netex.model.FareZone)7 ObjectFactory (org.rutebanken.netex.model.ObjectFactory)7 SiteFrame (org.rutebanken.netex.model.SiteFrame)5 TariffZonesInFrame_RelStructure (org.rutebanken.netex.model.TariffZonesInFrame_RelStructure)5 Zone_VersionStructure (org.rutebanken.netex.model.Zone_VersionStructure)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 MultilingualString (org.rutebanken.netex.model.MultilingualString)4 PublicationDeliveryStructure (org.rutebanken.netex.model.PublicationDeliveryStructure)4 TiamatIntegrationTest (org.rutebanken.tiamat.TiamatIntegrationTest)4 ImportParams (org.rutebanken.tiamat.importer.ImportParams)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 StopPlace (org.rutebanken.netex.model.StopPlace)3 StopPlacesInFrame_RelStructure (org.rutebanken.netex.model.StopPlacesInFrame_RelStructure)3 TariffZoneRef (org.rutebanken.netex.model.TariffZoneRef)3 TariffZoneRefs_RelStructure (org.rutebanken.netex.model.TariffZoneRefs_RelStructure)3 BigDecimal (java.math.BigDecimal)2 LocalDateTime (java.time.LocalDateTime)2