Search in sources :

Example 21 with TariffZone

use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.

the class TariffZonesFetcher method get.

@Override
@Transactional
public Page<TariffZone> get(DataFetchingEnvironment environment) {
    TariffZoneSearch tariffZoneSearch = TariffZoneSearch.newTariffZoneSearchBuilder().query(environment.getArgument(QUERY)).build();
    List<TariffZone> tariffZones = tariffZoneRepository.findTariffZones(tariffZoneSearch);
    return new PageImpl<>(tariffZones, PageRequest.of(environment.getArgument(PAGE), environment.getArgument(SIZE)), tariffZones.size());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) TariffZone(org.rutebanken.tiamat.model.TariffZone) TariffZoneSearch(org.rutebanken.tiamat.exporter.params.TariffZoneSearch) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with TariffZone

use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.

the class StreamingPublicationDeliveryIntegrationTest method streamStopPlacesAndRelatedEntitiesIntoPublicationDelivery.

@Test
public void streamStopPlacesAndRelatedEntitiesIntoPublicationDelivery() throws Exception {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    TopographicPlace topographicPlace = new TopographicPlace(new EmbeddableMultilingualString("Some municipality"));
    topographicPlace.setTopographicPlaceType(TopographicPlaceTypeEnumeration.MUNICIPALITY);
    topographicPlace = topographicPlaceVersionedSaverService.saveNewVersion(topographicPlace);
    String tariffZoneId = "CRI:TariffZone:1";
    TariffZone tariffZoneV1 = new TariffZone();
    tariffZoneV1.setNetexId(tariffZoneId);
    tariffZoneV1.setVersion(1L);
    var zonedDateTime = ZonedDateTime.of(2020, 12, 01, 00, 00, 00, 000, ZoneId.systemDefault());
    Instant fromDate = zonedDateTime.toInstant();
    tariffZoneV1.setValidBetween(new ValidBetween(fromDate, null));
    tariffZoneV1 = tariffZoneRepository.save(tariffZoneV1);
    TariffZone tariffZoneV2 = new TariffZone();
    tariffZoneV2.setNetexId(tariffZoneId);
    tariffZoneV2.setVersion(2L);
    var fromDate2 = zonedDateTime.plusDays(1L).toInstant();
    tariffZoneV2.setValidBetween(new ValidBetween(fromDate2, null));
    tariffZoneV2 = tariffZoneRepository.save(tariffZoneV2);
    TariffZone tariffZoneV3 = new TariffZone();
    tariffZoneV3.setNetexId(tariffZoneId);
    tariffZoneV3.setVersion(3L);
    var fromDate3 = zonedDateTime.plusDays(2L).toInstant();
    tariffZoneV3.setValidBetween(new ValidBetween(fromDate3, null));
    tariffZoneV3 = tariffZoneRepository.save(tariffZoneV3);
    StopPlace stopPlace1 = new StopPlace(new EmbeddableMultilingualString("stop place in publication delivery"));
    // Without version, implicity v3
    stopPlace1.getTariffZones().add(new TariffZoneRef(tariffZoneId));
    stopPlace1 = stopPlaceVersionedSaverService.saveNewVersion(stopPlace1);
    final String stopPlace1NetexId = stopPlace1.getNetexId();
    StopPlace stopPlace2 = new StopPlace(new EmbeddableMultilingualString("another stop place in publication delivery"));
    // StopPlace 2 refers to tariffzone version 1. This must be included in the publication delivery, allthough v2 and v3 exists
    stopPlace2.getTariffZones().add(new TariffZoneRef(tariffZoneV1));
    stopPlace2 = stopPlaceVersionedSaverService.saveNewVersion(stopPlace2);
    final String stopPlace2NetexId = stopPlace2.getNetexId();
    GroupOfStopPlaces groupOfStopPlaces1 = new GroupOfStopPlaces(new EmbeddableMultilingualString("group of stop places"));
    groupOfStopPlaces1.getMembers().add(new StopPlaceReference(stopPlace1.getNetexId()));
    groupOfStopPlacesSaverService.saveNewVersion(groupOfStopPlaces1);
    GroupOfStopPlaces groupOfStopPlaces2 = new GroupOfStopPlaces(new EmbeddableMultilingualString("group of stop places number two"));
    groupOfStopPlaces2.getMembers().add(new StopPlaceReference(stopPlace1.getNetexId()));
    groupOfStopPlacesSaverService.saveNewVersion(groupOfStopPlaces2);
    groupOfStopPlacesRepository.flush();
    // Allows setting topographic place without lookup.
    // To have the lookup work, topographic place polygon must exist
    stopPlace1.setTopographicPlace(topographicPlace);
    stopPlaceRepository.save(stopPlace1);
    stopPlaceRepository.flush();
    tariffZoneRepository.flush();
    ExportParams exportParams = ExportParams.newExportParamsBuilder().setStopPlaceSearch(StopPlaceSearch.newStopPlaceSearchBuilder().setVersionValidity(ExportParams.VersionValidity.CURRENT_FUTURE).build()).setTopographicPlaceExportMode(ExportParams.ExportMode.RELEVANT).setTariffZoneExportMode(ExportParams.ExportMode.RELEVANT).setGroupOfStopPlacesExportMode(ExportParams.ExportMode.RELEVANT).build();
    streamingPublicationDelivery.stream(exportParams, byteArrayOutputStream);
    String xml = byteArrayOutputStream.toString();
    System.out.println(xml);
    // The unmarshaller will validate as well. But only if validateAgainstSchema is true
    validate(xml);
    // Validate using own implementation of netex xml reference validator
    netexXmlReferenceValidator.validateNetexReferences(new ByteArrayInputStream(xml.getBytes()), "publicationDelivery");
    PublicationDeliveryStructure publicationDeliveryStructure = publicationDeliveryUnmarshaller.unmarshal(new ByteArrayInputStream(xml.getBytes()));
    org.rutebanken.netex.model.SiteFrame siteFrame = publicationDeliveryHelper.findSiteFrame(publicationDeliveryStructure);
    List<org.rutebanken.netex.model.StopPlace> stops = siteFrame.getStopPlaces().getStopPlace();
    assertThat(stops).hasSize(2).as("stops expected").extracting(org.rutebanken.netex.model.StopPlace::getId).containsOnly(stopPlace1.getNetexId(), stopPlace2.getNetexId());
    // Make sure both stops have references to tariff zones and with correct version
    org.rutebanken.netex.model.StopPlace actualStopPlace1 = stops.stream().filter(sp -> sp.getId().equals(stopPlace1NetexId)).findFirst().get();
    assertThat(actualStopPlace1.getTariffZones()).as("actual stop place 1 tariff zones").isNotNull();
    org.rutebanken.netex.model.TariffZoneRef actualTariffZoneRefStopPlace1 = actualStopPlace1.getTariffZones().getTariffZoneRef().get(0);
    // Stop place 1 refers to tariff zone v2 implicity beacuse the reference does not contain version value.
    assertThat(actualTariffZoneRefStopPlace1.getRef()).as("actual stop place 1 tariff zone ref").isEqualTo(tariffZoneId);
    // Check stop place 2
    org.rutebanken.netex.model.StopPlace actualStopPlace2 = stops.stream().filter(sp -> sp.getId().equals(stopPlace2NetexId)).findFirst().get();
    org.rutebanken.netex.model.TariffZoneRef actualTariffZoneRefStopPlace2 = actualStopPlace2.getTariffZones().getTariffZoneRef().get(0);
    assertThat(actualTariffZoneRefStopPlace2.getRef()).as("actual stop place 2 tariff zone ref").isEqualTo(tariffZoneId);
    assertThat(actualTariffZoneRefStopPlace2.getVersion()).as("actual tariff zone ref for stop place 2 should point to version 1 of tariff zone").isEqualTo(String.valueOf(tariffZoneV1.getVersion()));
    // Check topographic places
    assertThat(siteFrame.getTopographicPlaces()).isNotNull();
    assertThat(siteFrame.getTopographicPlaces().getTopographicPlace()).as("site fra topopgraphic places").isNotNull().hasSize(1).extracting(org.rutebanken.netex.model.TopographicPlace::getId).containsOnly(topographicPlace.getNetexId());
    // Check tariff zones
    assertThat(siteFrame.getTariffZones()).as("site fra tariff zones").isNotNull();
    assertThat(siteFrame.getTariffZones().getTariffZone()).extracting(tariffZone -> tariffZone.getValue().getId() + "-" + tariffZone.getValue().getVersion()).as("Both tariff zones exists in publication delivery. But not the one not being reffered to (v2)").containsOnly(tariffZoneId + "-" + 1, tariffZoneId + "-" + 3);
}
Also used : TariffZone(org.rutebanken.tiamat.model.TariffZone) StopPlace(org.rutebanken.tiamat.model.StopPlace) GroupOfStopPlaces(org.rutebanken.tiamat.model.GroupOfStopPlaces) TopographicPlace(org.rutebanken.tiamat.model.TopographicPlace) StopPlaceReference(org.rutebanken.tiamat.model.StopPlaceReference) Instant(java.time.Instant) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) ExportParams(org.rutebanken.tiamat.exporter.params.ExportParams) ByteArrayInputStream(java.io.ByteArrayInputStream) TariffZoneRef(org.rutebanken.tiamat.model.TariffZoneRef) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 23 with TariffZone

use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.

the class StreamingPublicationDeliveryIntegrationTest method handleExportModeSetToNone.

/**
 * Set export modes to none, to see that export netex is valid
 */
@Test
public void handleExportModeSetToNone() throws InterruptedException, IOException, XMLStreamException, SAXException, JAXBException, NetexReferenceValidatorException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    TopographicPlace county = new TopographicPlace(new EmbeddableMultilingualString("county"));
    county.setTopographicPlaceType(TopographicPlaceTypeEnumeration.COUNTY);
    county = topographicPlaceVersionedSaverService.saveNewVersion(county);
    TopographicPlace municipality = new TopographicPlace(new EmbeddableMultilingualString("Some municipality"));
    municipality.setTopographicPlaceType(TopographicPlaceTypeEnumeration.MUNICIPALITY);
    municipality.setParentTopographicPlaceRef(new TopographicPlaceRefStructure(county.getNetexId(), String.valueOf(county.getVersion())));
    municipality = topographicPlaceVersionedSaverService.saveNewVersion(municipality);
    TariffZone tariffZone = new TariffZone();
    tariffZone.setVersion(1L);
    tariffZone = tariffZoneRepository.save(tariffZone);
    StopPlace stopPlace = new StopPlace(new EmbeddableMultilingualString("stop place"));
    stopPlace.setTopographicPlace(municipality);
    stopPlace.getTariffZones().add(new TariffZoneRef(tariffZone));
    stopPlaceRepository.save(stopPlace);
    stopPlaceRepository.flush();
    GroupOfStopPlaces groupOfStopPlaces = new GroupOfStopPlaces(new EmbeddableMultilingualString("group"));
    groupOfStopPlaces.getMembers().add(new StopPlaceReference(stopPlace.getNetexId()));
    groupOfStopPlacesSaverService.saveNewVersion(groupOfStopPlaces);
    ExportParams exportParams = ExportParams.newExportParamsBuilder().setStopPlaceSearch(StopPlaceSearch.newStopPlaceSearchBuilder().setVersionValidity(ExportParams.VersionValidity.CURRENT_FUTURE).build()).setTopographicPlaceExportMode(ExportParams.ExportMode.NONE).setTariffZoneExportMode(ExportParams.ExportMode.NONE).setGroupOfStopPlacesExportMode(ExportParams.ExportMode.NONE).build();
    streamingPublicationDelivery.stream(exportParams, byteArrayOutputStream);
    String xml = byteArrayOutputStream.toString();
    System.out.println(xml);
    netexXmlReferenceValidator.validateNetexReferences(new ByteArrayInputStream(xml.getBytes()), "publicationDelivery");
}
Also used : TopographicPlaceRefStructure(org.rutebanken.tiamat.model.TopographicPlaceRefStructure) TariffZone(org.rutebanken.tiamat.model.TariffZone) StopPlace(org.rutebanken.tiamat.model.StopPlace) ExportParams(org.rutebanken.tiamat.exporter.params.ExportParams) GroupOfStopPlaces(org.rutebanken.tiamat.model.GroupOfStopPlaces) ByteArrayInputStream(java.io.ByteArrayInputStream) TopographicPlace(org.rutebanken.tiamat.model.TopographicPlace) StopPlaceReference(org.rutebanken.tiamat.model.StopPlaceReference) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TariffZoneRef(org.rutebanken.tiamat.model.TariffZoneRef) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 24 with TariffZone

use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.

the class TariffZonesFromStopsExporterTest method handleUnresolvableTariffZoneRef.

@Test
public void handleUnresolvableTariffZoneRef() {
    TariffZone tariffZone = new TariffZone();
    tariffZone.setNetexId("VKT:TariffZone:201");
    tariffZone.setVersion(1L);
    tariffZoneRepository.save(tariffZone);
    StopPlace netexStopPlace = new StopPlace();
    netexStopPlace.setId("NSR:StopPlace:1");
    netexStopPlace.withTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withRef("NSR:TariffZone:1")));
    SiteFrame siteFrame = new SiteFrame();
    tariffZonesFromStopsExporter.resolveTariffZones(Arrays.asList(netexStopPlace), siteFrame);
    assertThat(siteFrame.getTariffZones()).as("Number of tariffzones returned").isNull();
}
Also used : TariffZoneRefs_RelStructure(org.rutebanken.netex.model.TariffZoneRefs_RelStructure) TariffZone(org.rutebanken.tiamat.model.TariffZone) StopPlace(org.rutebanken.netex.model.StopPlace) SiteFrame(org.rutebanken.netex.model.SiteFrame) TariffZoneRef(org.rutebanken.netex.model.TariffZoneRef) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 25 with TariffZone

use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.

the class TariffZonesFromStopsExporterTest method keepExistingTariffZones.

@Test
public void keepExistingTariffZones() {
    TariffZone tariffZone = new TariffZone();
    tariffZone.setNetexId("VKT:TariffZone:201");
    tariffZone.setVersion(1L);
    tariffZoneRepository.save(tariffZone);
    org.rutebanken.netex.model.TariffZone alreadyAddedTariffZone = new org.rutebanken.netex.model.TariffZone().withId("VKT:TariffZone:123").withVersion("2");
    StopPlace netexStopPlace = new StopPlace();
    netexStopPlace.setId("NSR:StopPlace:1");
    netexStopPlace.withTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withRef(tariffZone.getNetexId()).withVersion("1")));
    SiteFrame siteFrame = new SiteFrame();
    siteFrame.withTariffZones(new TariffZonesInFrame_RelStructure().withTariffZone(new ObjectFactory().createTariffZone(alreadyAddedTariffZone)));
    tariffZonesFromStopsExporter.resolveTariffZones(Arrays.asList(netexStopPlace), siteFrame);
    assertThat(siteFrame.getTariffZones().getTariffZone()).as("Number of tariffzones returned").hasSize(2);
}
Also used : TariffZoneRefs_RelStructure(org.rutebanken.netex.model.TariffZoneRefs_RelStructure) TariffZone(org.rutebanken.tiamat.model.TariffZone) StopPlace(org.rutebanken.netex.model.StopPlace) SiteFrame(org.rutebanken.netex.model.SiteFrame) TariffZonesInFrame_RelStructure(org.rutebanken.netex.model.TariffZonesInFrame_RelStructure) ObjectFactory(org.rutebanken.netex.model.ObjectFactory) TariffZoneRef(org.rutebanken.netex.model.TariffZoneRef) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Aggregations

TariffZone (org.rutebanken.tiamat.model.TariffZone)25 Test (org.junit.Test)18 TiamatIntegrationTest (org.rutebanken.tiamat.TiamatIntegrationTest)16 EmbeddableMultilingualString (org.rutebanken.tiamat.model.EmbeddableMultilingualString)14 StopPlace (org.rutebanken.tiamat.model.StopPlace)8 Instant (java.time.Instant)5 Coordinate (org.locationtech.jts.geom.Coordinate)5 Geometry (org.locationtech.jts.geom.Geometry)5 LinearRing (org.locationtech.jts.geom.LinearRing)5 CoordinateArraySequence (org.locationtech.jts.geom.impl.CoordinateArraySequence)5 TariffZoneSearch (org.rutebanken.tiamat.exporter.params.TariffZoneSearch)5 TariffZoneRef (org.rutebanken.tiamat.model.TariffZoneRef)5 ValidBetween (org.rutebanken.tiamat.model.ValidBetween)4 SiteFrame (org.rutebanken.netex.model.SiteFrame)3 StopPlace (org.rutebanken.netex.model.StopPlace)3 TariffZoneRef (org.rutebanken.netex.model.TariffZoneRef)3 TariffZoneRefs_RelStructure (org.rutebanken.netex.model.TariffZoneRefs_RelStructure)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2