use of org.rutebanken.netex.model.TariffZone 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));
}
}
}
use of org.rutebanken.netex.model.TariffZone in project tiamat by entur.
the class TariffZoneImportTest method publicationDeliveryWithTariffZoneAndStopPlace.
@Test
public void publicationDeliveryWithTariffZoneAndStopPlace() throws Exception {
LocalDateTime validFrom = LocalDateTime.now().minusDays(3);
List<JAXBElement<? extends Zone_VersionStructure>> tariffZones = new ArrayList<>();
TariffZone tariffZone = new TariffZone().withName(new MultilingualString().withValue("V02")).withVersion("1").withValidBetween(new ValidBetween().withFromDate(validFrom)).withId("RUT:TariffZone:05");
tariffZones.add(new ObjectFactory().createTariffZone(tariffZone));
StopPlace stopPlace = new StopPlace();
stopPlace.withId("XYZ:StopPlace:32111");
stopPlace.setVersion("1");
stopPlace.setTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withVersion(tariffZone.getVersion()).withRef(tariffZone.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(tariffZone.getName().getValue());
// Versions for tariff zones are incremented.
assertThat(actualZones.get(0).getValue().getVersion()).isEqualTo("2");
}
use of org.rutebanken.netex.model.TariffZone in project OpenTripPlanner by opentripplanner.
the class NetexImportDataIndex method readOnlyView.
public NetexImportDataIndexReadOnlyView readOnlyView() {
return new NetexImportDataIndexReadOnlyView() {
/**
* Lookup a Network given a GroupOfLine id or an Network id. If the given
* {@code groupOfLineOrNetworkId} is a GroupOfLine ID, we lookup the GroupOfLine, and then
* lookup its Network. If the given {@code groupOfLineOrNetworkId} is a Network ID then we
* can lookup the Network directly.
* <p/>
* If no Network is found {@code null} is returned.
*/
public Network lookupNetworkForLine(String groupOfLineOrNetworkId) {
GroupOfLines groupOfLines = groupOfLinesById.lookup(groupOfLineOrNetworkId);
String networkId = groupOfLines == null ? groupOfLineOrNetworkId : networkIdByGroupOfLineId.lookup(groupOfLines.getId());
return networkById.lookup(networkId);
}
public ReadOnlyHierarchicalMapById<Authority> getAuthoritiesById() {
return authoritiesById;
}
public ReadOnlyHierarchicalMapById<DayType> getDayTypeById() {
return dayTypeById;
}
public ReadOnlyHierarchicalMap<String, Collection<DayTypeAssignment>> getDayTypeAssignmentByDayTypeId() {
return dayTypeAssignmentByDayTypeId;
}
public Iterable<DayTypeRefsToServiceIdAdapter> getDayTypeRefs() {
return Collections.unmodifiableSet(dayTypeRefs);
}
public ReadOnlyHierarchicalMapById<DestinationDisplay> getDestinationDisplayById() {
return destinationDisplayById;
}
public ReadOnlyHierarchicalMapById<GroupOfStopPlaces> getGroupOfStopPlacesById() {
return groupOfStopPlacesById;
}
public ReadOnlyHierarchicalMapById<JourneyPattern> getJourneyPatternsById() {
return journeyPatternsById;
}
public ReadOnlyHierarchicalMapById<Line> getLineById() {
return lineById;
}
public ReadOnlyHierarchicalMapById<StopPlace> getMultiModalStopPlaceById() {
return multiModalStopPlaceById;
}
public ReadOnlyHierarchicalMapById<Notice> getNoticeById() {
return noticeById;
}
public ReadOnlyHierarchicalMapById<NoticeAssignment> getNoticeAssignmentById() {
return noticeAssignmentById;
}
public ReadOnlyHierarchicalMapById<OperatingPeriod> getOperatingPeriodById() {
return operatingPeriodById;
}
public ReadOnlyHierarchicalMapById<Operator> getOperatorsById() {
return operatorsById;
}
public ReadOnlyHierarchicalMap<String, Collection<TimetabledPassingTime>> getPassingTimeByStopPointId() {
return passingTimeByStopPointId;
}
public ReadOnlyHierarchicalVersionMapById<Quay> getQuayById() {
return quayById;
}
public ReadOnlyHierarchicalMap<String, String> getQuayIdByStopPointRef() {
return quayIdByStopPointRef;
}
public ReadOnlyHierarchicalMapById<Route> getRouteById() {
return routeById;
}
public ReadOnlyHierarchicalMap<String, Collection<ServiceJourney>> getServiceJourneyByPatternId() {
return serviceJourneyByPatternId;
}
public ReadOnlyHierarchicalMapById<ServiceLink> getServiceLinkById() {
return serviceLinkById;
}
public ReadOnlyHierarchicalVersionMapById<StopPlace> getStopPlaceById() {
return stopPlaceById;
}
public ReadOnlyHierarchicalMapById<TariffZone> getTariffZonesById() {
return tariffZonesById;
}
public String getTimeZone() {
return timeZone.get();
}
};
}
use of org.rutebanken.netex.model.TariffZone in project tiamat by entur.
the class StreamingPublicationDelivery method prepareTariffZones.
private void prepareTariffZones(ExportParams exportParams, Set<Long> stopPlacePrimaryIds, AtomicInteger mappedTariffZonesCount, SiteFrame netexSiteFrame, EntitiesEvictor evicter) {
Iterator<org.rutebanken.tiamat.model.TariffZone> tariffZoneIterator;
if (exportParams.getTariffZoneExportMode() == null || exportParams.getTariffZoneExportMode().equals(ExportParams.ExportMode.ALL)) {
logger.info("Preparing to scroll all tariff zones, regardless of version");
tariffZoneIterator = tariffZoneRepository.scrollTariffZones(exportParams);
} else if (exportParams.getTariffZoneExportMode().equals(ExportParams.ExportMode.RELEVANT)) {
logger.info("Preparing to scroll relevant tariff zones from stop place ids");
tariffZoneIterator = tariffZoneRepository.scrollTariffZones(stopPlacePrimaryIds);
} else {
logger.info("Tariff zone export mode is {}. Will not export tariff zones", exportParams.getTariffZoneExportMode());
tariffZoneIterator = Collections.emptyIterator();
}
List<JAXBElement<? extends Zone_VersionStructure>> netexTariffZones = new ArrayList<>();
while (tariffZoneIterator.hasNext()) {
final TariffZone tariffZone = netexMapper.mapToNetexModel(tariffZoneIterator.next());
final JAXBElement<TariffZone> tariffZoneJAXBElement = new ObjectFactory().createTariffZone(tariffZone);
netexTariffZones.add(tariffZoneJAXBElement);
mappedTariffZonesCount.incrementAndGet();
}
if (!netexTariffZones.isEmpty()) {
var tariffZonesInFrameRelStructure = new TariffZonesInFrame_RelStructure();
setField(TariffZonesInFrame_RelStructure.class, "tariffZone", tariffZonesInFrameRelStructure, netexTariffZones);
netexSiteFrame.setTariffZones(tariffZonesInFrameRelStructure);
} else {
logger.info("No tariff zones to export");
netexSiteFrame.setTariffZones(null);
}
}
use of org.rutebanken.netex.model.TariffZone in project tiamat by entur.
the class TariffZoneImportTest method mergeTariffZonesForStopPlace.
@Test
public void mergeTariffZonesForStopPlace() 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<>();
TariffZone tariffZone1 = new TariffZone().withName(new MultilingualString().withValue("V03")).withVersion("1").withId("ATB:TariffZone:01");
tariffZones1.add(new ObjectFactory().createTariffZone(tariffZone1));
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(tariffZone1.getVersion()).withRef(tariffZone1.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<>();
TariffZone tariffZone2 = new TariffZone().withName(new MultilingualString().withValue("X08")).withVersion("1").withId("NTR:TariffZone:03");
tariffZones2.add(new ObjectFactory().createTariffZone(tariffZone2));
StopPlace stopPlace2 = new StopPlace().withId("NTR:StopPlace:322").withVersion("2").withStopPlaceType(StopTypeEnumeration.ONSTREET_BUS).withTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withVersion(tariffZone2.getVersion()).withRef(tariffZone2.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);
}
Aggregations