Search in sources :

Example 11 with ObjectFactory

use of org.rutebanken.netex.model.ObjectFactory in project tiamat by entur.

the class PublicationDeliveryExporter method createPublicationDelivery.

@SuppressWarnings("unchecked")
public PublicationDeliveryStructure createPublicationDelivery(org.rutebanken.netex.model.SiteFrame siteFrame) {
    PublicationDeliveryStructure publicationDeliveryStructure = createPublicationDelivery();
    publicationDeliveryStructure.withDataObjects(new PublicationDeliveryStructure.DataObjects().withCompositeFrameOrCommonFrame(new ObjectFactory().createSiteFrame(siteFrame)));
    logger.info("Returning publication delivery {} with site frame", publicationDeliveryStructure);
    return publicationDeliveryStructure;
}
Also used : ObjectFactory(org.rutebanken.netex.model.ObjectFactory) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure)

Example 12 with ObjectFactory

use of org.rutebanken.netex.model.ObjectFactory in project tiamat by entur.

the class PublicationDeliveryExporter method createPublicationDelivery.

@SuppressWarnings("unchecked")
public PublicationDeliveryStructure createPublicationDelivery(org.rutebanken.netex.model.SiteFrame siteFrame, org.rutebanken.netex.model.FareFrame fareFrame) {
    PublicationDeliveryStructure publicationDeliveryStructure = createPublicationDelivery();
    publicationDeliveryStructure.withDataObjects(new PublicationDeliveryStructure.DataObjects().withCompositeFrameOrCommonFrame(new ObjectFactory().createSiteFrame(siteFrame)).withCompositeFrameOrCommonFrame(new ObjectFactory().createFareFrame(fareFrame)));
    logger.info("Returning publication delivery {} with site frame and fare frame", publicationDeliveryStructure);
    return publicationDeliveryStructure;
}
Also used : ObjectFactory(org.rutebanken.netex.model.ObjectFactory) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure)

Example 13 with ObjectFactory

use of org.rutebanken.netex.model.ObjectFactory 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);
    }
}
Also used : TariffZone(org.rutebanken.netex.model.TariffZone) TariffZonesInFrame_RelStructure(org.rutebanken.netex.model.TariffZonesInFrame_RelStructure) GroupsOfTariffZonesInFrame_RelStructure(org.rutebanken.netex.model.GroupsOfTariffZonesInFrame_RelStructure) ObjectFactory(org.rutebanken.netex.model.ObjectFactory) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement) Zone_VersionStructure(org.rutebanken.netex.model.Zone_VersionStructure)

Example 14 with ObjectFactory

use of org.rutebanken.netex.model.ObjectFactory in project tiamat by entur.

the class StreamingPublicationDelivery method createPassengerStopAssignment.

private JAXBElement<? extends StopAssignment_VersionStructure> createPassengerStopAssignment(String netexId, long version, String scheduledStopPointNetexId, int passengerStopAssignmentOrder, LocalDateTime validFrom, LocalDateTime validTo, boolean isQuay) {
    var passengerStopAssignmentId = netexIdHelper.extractIdPostfix(scheduledStopPointNetexId);
    var idPrefix = netexIdHelper.extractIdPrefix(scheduledStopPointNetexId);
    final PassengerStopAssignment passengerStopAssignment = new PassengerStopAssignment();
    passengerStopAssignment.withId(idPrefix + ":PassengerStopAssignment:P" + passengerStopAssignmentId);
    passengerStopAssignment.withVersion(String.valueOf(version));
    passengerStopAssignment.withOrder(BigInteger.valueOf(passengerStopAssignmentOrder));
    ValidBetween validBetween = new ValidBetween().withFromDate(validFrom).withToDate(validTo);
    passengerStopAssignment.withValidBetween(validBetween);
    if (isQuay) {
        passengerStopAssignment.withQuayRef(new QuayRefStructure().withRef(netexId).withVersion(String.valueOf(version)));
    } else {
        passengerStopAssignment.withStopPlaceRef(new StopPlaceRefStructure().withRef(netexId).withVersion(String.valueOf(version)));
    }
    final JAXBElement<ScheduledStopPointRefStructure> scheduledStopPointRef = new ObjectFactory().createScheduledStopPointRef(new ScheduledStopPointRefStructure().withRef(scheduledStopPointNetexId).withVersionRef(String.valueOf(version)));
    passengerStopAssignment.withScheduledStopPointRef(scheduledStopPointRef);
    return new ObjectFactory().createPassengerStopAssignment(passengerStopAssignment);
}
Also used : ObjectFactory(org.rutebanken.netex.model.ObjectFactory) QuayRefStructure(org.rutebanken.netex.model.QuayRefStructure) PassengerStopAssignment(org.rutebanken.netex.model.PassengerStopAssignment) StopPlaceRefStructure(org.rutebanken.netex.model.StopPlaceRefStructure) ScheduledStopPointRefStructure(org.rutebanken.netex.model.ScheduledStopPointRefStructure) ValidBetween(org.rutebanken.netex.model.ValidBetween)

Example 15 with ObjectFactory

use of org.rutebanken.netex.model.ObjectFactory in project tiamat by entur.

the class FareZoneImportTest method publicationDeliveryWithFareZoneAndStopPlaceMergeZonesImportTypeMatch.

@Test
public void publicationDeliveryWithFareZoneAndStopPlaceMergeZonesImportTypeMatch() throws Exception {
    SimplePoint_VersionStructure point = new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("9.6")).withLongitude(new BigDecimal("76")));
    List<JAXBElement<? extends Zone_VersionStructure>> tariffZones1 = new ArrayList<>();
    FareZone fareZone1 = new FareZone().withName(new MultilingualString().withValue("V02")).withVersion("1").withId("RUT:FareZone:01");
    tariffZones1.add(new ObjectFactory().createFareZone(fareZone1));
    StopPlace stopPlace = new StopPlace().withId("RUT:StopPlace:321").withName(new MultilingualString().withValue("name")).withCentroid(point).withVersion("1").withStopPlaceType(StopTypeEnumeration.ONSTREET_BUS).withTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withVersion(fareZone1.getVersion()).withRef(fareZone1.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<>();
    FareZone fareZone2 = new FareZone().withName(new MultilingualString().withValue("X09")).withVersion("1").withId("BRA:FareZone:02");
    tariffZones2.add(new ObjectFactory().createFareZone(fareZone2));
    stopPlace.withId("BRA:Stopplace:3").withTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withVersion(fareZone2.getVersion()).withRef(fareZone2.getId())));
    SiteFrame siteFrame2 = publicationDeliveryTestHelper.siteFrame().withTariffZones(new TariffZonesInFrame_RelStructure().withTariffZone(tariffZones2)).withStopPlaces(new StopPlacesInFrame_RelStructure().withStopPlace(stopPlace));
    PublicationDeliveryStructure publicationDeliveryStructure2 = publicationDeliveryTestHelper.publicationDelivery(siteFrame2);
    // Second import should match and merge farezones
    importParams.importType = ImportType.MATCH;
    PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDeliveryStructure2, importParams);
    List<JAXBElement<? extends Zone_VersionStructure>> actualZones = publicationDeliveryTestHelper.findSiteFrame(response).getTariffZones().getTariffZone();
    assertThat(actualZones).isNotEmpty();
    assertThat(actualZones).hasSize(2);
}
Also used : TariffZoneRefs_RelStructure(org.rutebanken.netex.model.TariffZoneRefs_RelStructure) StopPlace(org.rutebanken.netex.model.StopPlace) SiteFrame(org.rutebanken.netex.model.SiteFrame) TariffZonesInFrame_RelStructure(org.rutebanken.netex.model.TariffZonesInFrame_RelStructure) ArrayList(java.util.ArrayList) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) JAXBElement(javax.xml.bind.JAXBElement) FareZone(org.rutebanken.netex.model.FareZone) StopPlacesInFrame_RelStructure(org.rutebanken.netex.model.StopPlacesInFrame_RelStructure) LocationStructure(org.rutebanken.netex.model.LocationStructure) BigDecimal(java.math.BigDecimal) ObjectFactory(org.rutebanken.netex.model.ObjectFactory) ImportParams(org.rutebanken.tiamat.importer.ImportParams) Zone_VersionStructure(org.rutebanken.netex.model.Zone_VersionStructure) MultilingualString(org.rutebanken.netex.model.MultilingualString) TariffZoneRef(org.rutebanken.netex.model.TariffZoneRef) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Aggregations

ObjectFactory (org.rutebanken.netex.model.ObjectFactory)21 PublicationDeliveryStructure (org.rutebanken.netex.model.PublicationDeliveryStructure)14 SiteFrame (org.rutebanken.netex.model.SiteFrame)13 Test (org.junit.Test)12 TariffZonesInFrame_RelStructure (org.rutebanken.netex.model.TariffZonesInFrame_RelStructure)12 TiamatIntegrationTest (org.rutebanken.tiamat.TiamatIntegrationTest)12 JAXBElement (javax.xml.bind.JAXBElement)11 Zone_VersionStructure (org.rutebanken.netex.model.Zone_VersionStructure)10 ArrayList (java.util.ArrayList)9 StopPlace (org.rutebanken.netex.model.StopPlace)9 TariffZoneRef (org.rutebanken.netex.model.TariffZoneRef)9 TariffZoneRefs_RelStructure (org.rutebanken.netex.model.TariffZoneRefs_RelStructure)9 MultilingualString (org.rutebanken.netex.model.MultilingualString)8 ImportParams (org.rutebanken.tiamat.importer.ImportParams)7 FareZone (org.rutebanken.netex.model.FareZone)6 StopPlacesInFrame_RelStructure (org.rutebanken.netex.model.StopPlacesInFrame_RelStructure)6 TariffZone (org.rutebanken.netex.model.TariffZone)6 ValidBetween (org.rutebanken.netex.model.ValidBetween)5 BigDecimal (java.math.BigDecimal)4 LocalDateTime (java.time.LocalDateTime)4