Search in sources :

Example 1 with TariffZoneRef

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

the class FareZoneRepositoryImplTest method getFareZonesFromStopPlaceIds.

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

Example 2 with TariffZoneRef

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

the class GenericObjectDifferTest method diffStopPlaceWithTariffZone.

@Test
public void diffStopPlaceWithTariffZone() throws IllegalAccessException {
    StopPlace oldStopPlace = new StopPlace();
    StopPlace newStopPlace = new StopPlace();
    newStopPlace.getTariffZones().add(new TariffZoneRef(new TariffZone()));
    String diffString = compareObjectsAndPrint(oldStopPlace, newStopPlace);
    assertThat(diffString).contains("tariffZones");
}
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) Test(org.junit.Test)

Example 3 with TariffZoneRef

use of org.rutebanken.tiamat.model.TariffZoneRef 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)

Example 4 with TariffZoneRef

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

the class FareZoneMapper method mapAtoB.

@Override
public void mapAtoB(FareZone netexFareZone, org.rutebanken.tiamat.model.FareZone tiamatFareZone, MappingContext context) {
    super.mapAtoB(netexFareZone, tiamatFareZone, context);
    if (netexFareZone.getTransportOrganisationRef() != null && netexFareZone.getTransportOrganisationRef().getValue() != null) {
        tiamatFareZone.setTransportOrganisationRef(netexFareZone.getTransportOrganisationRef().getValue().getRef());
    }
    if (netexFareZone.getNeighbours() != null && !netexFareZone.getNeighbours().getFareZoneRef().isEmpty()) {
        Set<TariffZoneRef> tiamatNeighbours = new HashSet<>();
        final List<FareZoneRefStructure> fareZoneRef = netexFareZone.getNeighbours().getFareZoneRef();
        for (FareZoneRefStructure fareZoneRefStructure : fareZoneRef) {
            tiamatNeighbours.add(new TariffZoneRef(fareZoneRefStructure.getRef()));
        }
        tiamatFareZone.setNeighbours(tiamatNeighbours);
    }
    if (netexFareZone.getScopingMethod() != null && netexFareZone.getScopingMethod().equals(ScopingMethodEnumeration.EXPLICIT_STOPS) && netexFareZone.getMembers() != null && !netexFareZone.getMembers().getPointRef().isEmpty()) {
        var fareZoneMembers = netexFareZone.getMembers().getPointRef().stream().map(jaxbElement -> convertScheduledStopPointRefToStopPlaceRef(jaxbElement.getValue().getRef())).filter(Objects::nonNull).map(StopPlaceReference::new).collect(Collectors.toSet());
        tiamatFareZone.setFareZoneMembers(fareZoneMembers);
    }
}
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) FareZoneRefStructure(org.rutebanken.netex.model.FareZoneRefStructure) Objects(java.util.Objects) TariffZoneRef(org.rutebanken.tiamat.model.TariffZoneRef) HashSet(java.util.HashSet)

Example 5 with TariffZoneRef

use of org.rutebanken.tiamat.model.TariffZoneRef 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)

Aggregations

TariffZoneRef (org.rutebanken.tiamat.model.TariffZoneRef)13 StopPlace (org.rutebanken.tiamat.model.StopPlace)9 Test (org.junit.Test)8 EmbeddableMultilingualString (org.rutebanken.tiamat.model.EmbeddableMultilingualString)8 TiamatIntegrationTest (org.rutebanken.tiamat.TiamatIntegrationTest)6 TariffZone (org.rutebanken.tiamat.model.TariffZone)6 Instant (java.time.Instant)4 HashSet (java.util.HashSet)4 StopPlaceReference (org.rutebanken.tiamat.model.StopPlaceReference)4 List (java.util.List)3 ValidBetween (org.rutebanken.tiamat.model.ValidBetween)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Transactional (javax.transaction.Transactional)2 JAXBElement (javax.xml.bind.JAXBElement)2 CustomMapper (ma.glasnost.orika.CustomMapper)2 MappingContext (ma.glasnost.orika.MappingContext)2