Search in sources :

Example 16 with TariffZone

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

the class StopPlaceMergerTest method testMergeStopPlacesWithAlternativeNames.

@Test
@Transactional
public void testMergeStopPlacesWithAlternativeNames() {
    StopPlace fromStopPlace = new StopPlace();
    fromStopPlace.setName(new EmbeddableMultilingualString("Name"));
    TariffZone tariffZone1 = new TariffZone();
    tariffZone1.setNetexId("NSR:TariffZone:1");
    tariffZone1.setVersion(1L);
    tariffZoneRepository.save(tariffZone1);
    Set<TariffZoneRef> fromTzSet = new HashSet<>();
    TariffZoneRef fromTz = new TariffZoneRef();
    fromTz.setRef(tariffZone1.getNetexId());
    fromTz.setVersion(String.valueOf(tariffZone1.getVersion()));
    fromTzSet.add(fromTz);
    fromStopPlace.setTariffZones(fromTzSet);
    AlternativeName fromAlternativeName = new AlternativeName();
    fromAlternativeName.setName(new EmbeddableMultilingualString("FROM-alternative"));
    fromStopPlace.getAlternativeNames().add(fromAlternativeName);
    StopPlace toStopPlace = new StopPlace();
    toStopPlace.setName(new EmbeddableMultilingualString("Name 2"));
    TariffZone tariffZone2 = new TariffZone();
    tariffZone2.setNetexId("NSR:TariffZone:2");
    tariffZone2.setVersion(2L);
    tariffZoneRepository.save(tariffZone2);
    Set<TariffZoneRef> toTzSet = new HashSet<>();
    TariffZoneRef toTz = new TariffZoneRef();
    toTz.setRef(tariffZone2.getNetexId());
    toTz.setVersion(String.valueOf(tariffZone2.getVersion()));
    toTzSet.add(toTz);
    toStopPlace.setTariffZones(toTzSet);
    AlternativeName toAlternativeName = new AlternativeName();
    toAlternativeName.setName(new EmbeddableMultilingualString("TO-alternative"));
    toStopPlace.getAlternativeNames().add(toAlternativeName);
    stopPlaceVersionedSaverService.saveNewVersion(fromStopPlace);
    stopPlaceVersionedSaverService.saveNewVersion(toStopPlace);
    StopPlace mergedStopPlace = stopPlaceMerger.mergeStopPlaces(fromStopPlace.getNetexId(), toStopPlace.getNetexId(), null, null, false);
    // AlternativeName
    assertThat(mergedStopPlace.getAlternativeNames()).isNotNull();
    assertThat(mergedStopPlace.getAlternativeNames()).hasSize(2);
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) TariffZone(org.rutebanken.tiamat.model.TariffZone) TariffZoneRef(org.rutebanken.tiamat.model.TariffZoneRef) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) HashSet(java.util.HashSet) AlternativeName(org.rutebanken.tiamat.model.AlternativeName) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest) Transactional(javax.transaction.Transactional)

Example 17 with TariffZone

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

the class TariffZoneRepositoryImplTest method getTariffZonesFromStopPlaceIds.

@Test
public void getTariffZonesFromStopPlaceIds() throws Exception {
    String tariffZoneNetexId = "CRI:TariffZone:1";
    TariffZone v1 = new TariffZone();
    v1.setVersion(1L);
    v1.setNetexId(tariffZoneNetexId);
    var zonedDateTime = ZonedDateTime.of(2020, 12, 01, 00, 00, 00, 000, ZoneId.systemDefault());
    Instant fromDate = zonedDateTime.toInstant();
    v1.setValidBetween(new ValidBetween(fromDate, null));
    tariffZoneRepository.save(v1);
    TariffZone v2 = new TariffZone();
    v2.setVersion(2L);
    v2.setNetexId(tariffZoneNetexId);
    var zonedDateTime2 = zonedDateTime.plusDays(10L);
    var fromDate2 = zonedDateTime2.toInstant();
    v2.setValidBetween(new ValidBetween(fromDate2, null));
    tariffZoneRepository.save(v2);
    StopPlace stopPlace = new StopPlace();
    stopPlace.getTariffZones().add(new TariffZoneRef(tariffZoneNetexId));
    stopPlaceRepository.save(stopPlace);
    List<TariffZone> tariffZones = tariffZoneRepository.getTariffZonesFromStopPlaceIds(Sets.newHashSet(stopPlace.getId()));
    assertThat(tariffZones).hasSize(1);
    assertThat(tariffZones.get(0).getVersion()).isEqualTo(v2.getVersion());
}
Also used : TariffZone(org.rutebanken.tiamat.model.TariffZone) StopPlace(org.rutebanken.tiamat.model.StopPlace) Instant(java.time.Instant) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) TariffZoneRef(org.rutebanken.tiamat.model.TariffZoneRef) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 18 with TariffZone

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

the class TariffZoneRepositoryImplTest method findTariffZonesByIdSuffix.

@Test
public void findTariffZonesByIdSuffix() throws Exception {
    TariffZone tariffZone2V = new TariffZone();
    tariffZone2V.setName(new EmbeddableMultilingualString("2V"));
    tariffZone2V.setNetexId("RUT:TariffZone:2V");
    TariffZone tariffZone412 = new TariffZone();
    tariffZone412.setNetexId("BRA:TariffZone:412");
    tariffZone412.setName(new EmbeddableMultilingualString("Kongsberg"));
    tariffZoneRepository.save(tariffZone2V);
    tariffZoneRepository.save(tariffZone412);
    TariffZoneSearch search = TariffZoneSearch.newTariffZoneSearchBuilder().query(tariffZone2V.getName().getValue()).build();
    List<TariffZone> tariffZoneList = tariffZoneRepository.findTariffZones(search);
    assertThat(tariffZoneList).hasSize(1).extracting(TariffZone::getNetexId).containsOnly(tariffZone2V.getNetexId());
}
Also used : TariffZone(org.rutebanken.tiamat.model.TariffZone) TariffZoneSearch(org.rutebanken.tiamat.exporter.params.TariffZoneSearch) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 19 with TariffZone

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

the class TariffZonesLookupServiceTest method getTariffZones.

@Test
public void getTariffZones() {
    TariffZone firstVersion = new TariffZone();
    firstVersion.setNetexId("NSR:TariffZone:1");
    firstVersion.setVersion(1L);
    Point point = geometryFactory.createPoint(new Coordinate(9.84, 59.26));
    Geometry geometry = point.buffer(20);
    LinearRing linearRing = new LinearRing(new CoordinateArraySequence(geometry.getCoordinates()), geometryFactory);
    firstVersion.setPolygon(geometryFactory.createPolygon(linearRing, null));
    TariffZone secondVersion = new TariffZone();
    secondVersion.setNetexId("NSR:TariffZone:1");
    secondVersion.setVersion(2L);
    secondVersion.setPolygon(geometryFactory.createPolygon(linearRing, null));
    TariffZone anotherOne = new TariffZone();
    anotherOne.setNetexId("NSR:TariffZone:2");
    anotherOne.setVersion(3L);
    anotherOne.setPolygon(geometryFactory.createPolygon(linearRing, null));
    when(tariffZoneRepository.findAllValidTariffZones()).thenReturn(Arrays.asList(firstVersion, secondVersion, anotherOne));
    java.util.function.Supplier<List<Pair<String, Polygon>>> actual = tariffZonesLookupService.getTariffZones();
    assertThat(actual.get()).hasSize(2);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) TariffZone(org.rutebanken.tiamat.model.TariffZone) Coordinate(org.locationtech.jts.geom.Coordinate) List(java.util.List) Point(org.locationtech.jts.geom.Point) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) CoordinateArraySequence(org.locationtech.jts.geom.impl.CoordinateArraySequence) Test(org.junit.Test)

Example 20 with TariffZone

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

the class StopPlaceMergerTest method testMergeStopPlacesWithTariffZones.

@Test
@Transactional
public void testMergeStopPlacesWithTariffZones() {
    StopPlace fromStopPlace = new StopPlace();
    fromStopPlace.setName(new EmbeddableMultilingualString("Name"));
    TariffZone tariffZone1 = new TariffZone();
    tariffZone1.setNetexId("NSR:TariffZone:1");
    tariffZone1.setVersion(1L);
    tariffZoneRepository.save(tariffZone1);
    Set<TariffZoneRef> fromTzSet = new HashSet<>();
    TariffZoneRef fromTz = new TariffZoneRef();
    fromTz.setRef(tariffZone1.getNetexId());
    fromTz.setVersion(String.valueOf(tariffZone1.getVersion()));
    fromTzSet.add(fromTz);
    fromStopPlace.setTariffZones(fromTzSet);
    StopPlace toStopPlace = new StopPlace();
    toStopPlace.setName(new EmbeddableMultilingualString("Name 2"));
    TariffZone tariffZone2 = new TariffZone();
    tariffZone2.setNetexId("NSR:TariffZone:2");
    tariffZone2.setVersion(2L);
    tariffZoneRepository.save(tariffZone2);
    Set<TariffZoneRef> toTzSet = new HashSet<>();
    TariffZoneRef toTz = new TariffZoneRef();
    toTz.setRef(tariffZone2.getNetexId());
    toTz.setVersion(String.valueOf(tariffZone2.getVersion()));
    toTzSet.add(toTz);
    toStopPlace.setTariffZones(toTzSet);
    stopPlaceVersionedSaverService.saveNewVersion(fromStopPlace);
    stopPlaceVersionedSaverService.saveNewVersion(toStopPlace);
    StopPlace mergedStopPlace = stopPlaceMerger.mergeStopPlaces(fromStopPlace.getNetexId(), toStopPlace.getNetexId(), null, null, false);
    assertThat(mergedStopPlace.getTariffZones()).hasSize(2);
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) TariffZone(org.rutebanken.tiamat.model.TariffZone) TariffZoneRef(org.rutebanken.tiamat.model.TariffZoneRef) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) HashSet(java.util.HashSet) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest) Transactional(javax.transaction.Transactional)

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