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());
}
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");
}
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);
}
}
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);
}
}
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);
}
Aggregations