Search in sources :

Example 1 with StopPlacesInFrame_RelStructure

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

the class StopPlaceImportHandler method handleStops.

public void handleStops(SiteFrame netexSiteFrame, ImportParams importParams, AtomicInteger stopPlacesCreatedMatchedOrUpdated, SiteFrame responseSiteframe) {
    if (publicationDeliveryHelper.hasStops(netexSiteFrame)) {
        List<StopPlace> tiamatStops = netexMapper.mapStopsToTiamatModel(netexSiteFrame.getStopPlaces().getStopPlace());
        tiamatStops = stopPlaceTypeFilter.filter(tiamatStops, importParams.allowOnlyStopTypes);
        if (importParams.ignoreStopTypes != null && !importParams.ignoreStopTypes.isEmpty()) {
            tiamatStops = stopPlaceTypeFilter.filter(tiamatStops, importParams.ignoreStopTypes, true);
        }
        boolean isImportTypeIdMatch = importParams.importType != null && importParams.importType.equals(ImportType.ID_MATCH);
        if (!isImportTypeIdMatch) {
            logger.info("Running stop place pre steps");
            tiamatStops = stopPlacePreSteps.run(tiamatStops);
        }
        int numberOfStopBeforeFiltering = tiamatStops.size();
        logger.info("About to filter {} stops based on topographic references: {}", tiamatStops.size(), importParams.targetTopographicPlaces);
        tiamatStops = zoneTopographicPlaceFilter.filterByTopographicPlaceMatch(importParams.targetTopographicPlaces, tiamatStops);
        logger.info("Got {} stops (was {}) after filtering by: {}", tiamatStops.size(), numberOfStopBeforeFiltering, importParams.targetTopographicPlaces);
        if (importParams.onlyMatchOutsideTopographicPlaces != null && !importParams.onlyMatchOutsideTopographicPlaces.isEmpty()) {
            numberOfStopBeforeFiltering = tiamatStops.size();
            logger.info("Filtering stops outside given list of topographic places: {}", importParams.onlyMatchOutsideTopographicPlaces);
            tiamatStops = zoneTopographicPlaceFilter.filterByTopographicPlaceMatch(importParams.onlyMatchOutsideTopographicPlaces, tiamatStops, true);
            logger.info("Got {} stops (was {}) after filtering", tiamatStops.size(), numberOfStopBeforeFiltering);
        }
        if (!isImportTypeIdMatch) {
            logger.info("Running stop place post filter steps");
            tiamatStops = stopPlacePostFilterSteps.run(tiamatStops);
        }
        if (importParams.forceStopType != null) {
            logger.info("Forcing stop type to " + importParams.forceStopType);
            tiamatStops.forEach(stopPlace -> stopPlace.setStopPlaceType(importParams.forceStopType));
        }
        Collection<org.rutebanken.netex.model.StopPlace> importedOrMatchedNetexStopPlaces;
        logger.info("The import type is: {}", importParams.importType);
        if (importParams.importType != null && importParams.importType.equals(ImportType.ID_MATCH)) {
            importedOrMatchedNetexStopPlaces = stopPlaceIdMatcher.matchStopPlaces(tiamatStops, stopPlacesCreatedMatchedOrUpdated);
        } else {
            final Lock lock = hazelcastInstance.getCPSubsystem().getLock(STOP_PLACE_IMPORT_LOCK_KEY);
            lock.lock();
            try {
                if (importParams.importType == null || importParams.importType.equals(ImportType.MERGE)) {
                    importedOrMatchedNetexStopPlaces = transactionalMergingStopPlacesImporter.importStopPlaces(tiamatStops, stopPlacesCreatedMatchedOrUpdated);
                } else if (importParams.importType.equals(ImportType.INITIAL)) {
                    importedOrMatchedNetexStopPlaces = parallelInitialStopPlaceImporter.importStopPlaces(tiamatStops, stopPlacesCreatedMatchedOrUpdated);
                } else if (importParams.importType.equals(ImportType.MATCH)) {
                    importedOrMatchedNetexStopPlaces = matchingAppendingIdStopPlacesImporter.importStopPlaces(tiamatStops, stopPlacesCreatedMatchedOrUpdated);
                } else {
                    throw new NotImplementedException("Import type " + importParams.importType + " not implemented ");
                }
            } finally {
                lock.unlock();
            }
        }
        // Filter uniques by StopPlace.id#version
        Map<String, org.rutebanken.netex.model.StopPlace> uniqueById = new HashMap<>();
        importedOrMatchedNetexStopPlaces.stream().forEach(e -> uniqueById.put(e.getId() + "#" + e.getVersion(), e));
        importedOrMatchedNetexStopPlaces = uniqueById.values();
        logger.info("Imported/matched/updated {} stop places", stopPlacesCreatedMatchedOrUpdated);
        tariffZonesFromStopsExporter.resolveTariffZones(importedOrMatchedNetexStopPlaces, responseSiteframe);
        if (responseSiteframe.getTariffZones() != null && responseSiteframe.getTariffZones().getTariffZone() != null && responseSiteframe.getTariffZones().getTariffZone().isEmpty()) {
            responseSiteframe.setTariffZones(null);
        }
        if (EXPORT_TOPOGRAPHIC_PLACES_FOR_STOPS) {
            List<TopographicPlace> netexTopographicPlaces = topographicPlacesExporter.export(findTopographicPlaceRefsFromStops(tiamatStops));
            if (!netexTopographicPlaces.isEmpty()) {
                responseSiteframe.withTopographicPlaces(new TopographicPlacesInFrame_RelStructure().withTopographicPlace(netexTopographicPlaces));
            }
        } else {
            clearTopographicPlaceRefs(importedOrMatchedNetexStopPlaces);
        }
        if (!importedOrMatchedNetexStopPlaces.isEmpty()) {
            logger.info("Add {} stops to response site frame", importedOrMatchedNetexStopPlaces.size());
            responseSiteframe.withStopPlaces(new StopPlacesInFrame_RelStructure().withStopPlace(importedOrMatchedNetexStopPlaces));
        } else {
            logger.info("No stops in response");
        }
    }
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) HashMap(java.util.HashMap) TopographicPlace(org.rutebanken.netex.model.TopographicPlace) NotImplementedException(org.apache.commons.lang3.NotImplementedException) StopPlacesInFrame_RelStructure(org.rutebanken.netex.model.StopPlacesInFrame_RelStructure) Lock(java.util.concurrent.locks.Lock) TopographicPlacesInFrame_RelStructure(org.rutebanken.netex.model.TopographicPlacesInFrame_RelStructure)

Example 2 with StopPlacesInFrame_RelStructure

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

the class FareZoneImportTest method publicationDeliveryWithFareZoneAndStopPlace.

@Test
public void publicationDeliveryWithFareZoneAndStopPlace() throws Exception {
    LocalDateTime validFrom = LocalDateTime.now().minusDays(3);
    List<JAXBElement<? extends Zone_VersionStructure>> tariffZones = new ArrayList<>();
    FareZone fareZone = new FareZone().withName(new MultilingualString().withValue("V02")).withVersion("1").withValidBetween(new ValidBetween().withFromDate(validFrom)).withId("RUT:FareZone:05");
    tariffZones.add(new ObjectFactory().createFareZone(fareZone));
    StopPlace stopPlace = new StopPlace();
    stopPlace.withId("XYZ:StopPlace:32111");
    stopPlace.setVersion("1");
    stopPlace.setTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withVersion(fareZone.getVersion()).withRef(fareZone.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(fareZone.getName().getValue());
    // Versions for tariff zones are incremented.
    assertThat(actualZones.get(0).getValue().getVersion()).isEqualTo("2");
}
Also used : LocalDateTime(java.time.LocalDateTime) 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) JAXBElement(javax.xml.bind.JAXBElement) FareZone(org.rutebanken.netex.model.FareZone) ValidBetween(org.rutebanken.netex.model.ValidBetween) StopPlacesInFrame_RelStructure(org.rutebanken.netex.model.StopPlacesInFrame_RelStructure) 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)

Example 3 with StopPlacesInFrame_RelStructure

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

the class FareZoneImportTest method mergeFareZonesForStopPlace.

@Test
public void mergeFareZonesForStopPlace() 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<>();
    FareZone fareZone1 = new FareZone().withName(new MultilingualString().withValue("V03")).withVersion("1").withId("ATB:FareZone:01");
    tariffZones1.add(new ObjectFactory().createFareZone(fareZone1));
    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(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("X08")).withVersion("1").withId("NTR:FareZone:03");
    tariffZones2.add(new ObjectFactory().createFareZone(fareZone2));
    StopPlace stopPlace2 = new StopPlace().withId("NTR:StopPlace:322").withVersion("2").withStopPlaceType(StopTypeEnumeration.ONSTREET_BUS).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(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);
}
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)

Example 4 with StopPlacesInFrame_RelStructure

use of org.rutebanken.netex.model.StopPlacesInFrame_RelStructure 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");
}
Also used : LocalDateTime(java.time.LocalDateTime) TariffZoneRefs_RelStructure(org.rutebanken.netex.model.TariffZoneRefs_RelStructure) TariffZone(org.rutebanken.netex.model.TariffZone) 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) JAXBElement(javax.xml.bind.JAXBElement) ValidBetween(org.rutebanken.netex.model.ValidBetween) StopPlacesInFrame_RelStructure(org.rutebanken.netex.model.StopPlacesInFrame_RelStructure) 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)

Example 5 with StopPlacesInFrame_RelStructure

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

the class StreamingPublicationDelivery method prepareStopPlaces.

private void prepareStopPlaces(ExportParams exportParams, Set<Long> stopPlacePrimaryIds, AtomicInteger mappedStopPlaceCount, SiteFrame netexSiteFrame, EntitiesEvictor evicter) {
    // Override lists with custom iterator to be able to scroll database results on the fly.
    if (!stopPlacePrimaryIds.isEmpty()) {
        logger.info("There are stop places to export");
        final Iterator<org.rutebanken.tiamat.model.StopPlace> stopPlaceIterator = stopPlaceRepository.scrollStopPlaces(stopPlacePrimaryIds);
        StopPlacesInFrame_RelStructure stopPlacesInFrame_relStructure = new StopPlacesInFrame_RelStructure();
        // Use Listening iterator to collect stop place IDs.
        ParentStopFetchingIterator parentStopFetchingIterator = new ParentStopFetchingIterator(stopPlaceIterator, stopPlaceRepository);
        NetexMappingIterator<org.rutebanken.tiamat.model.StopPlace, StopPlace> netexMappingIterator = new NetexMappingIterator<>(netexMapper, parentStopFetchingIterator, StopPlace.class, mappedStopPlaceCount, evicter);
        List<StopPlace> stopPlaces = new NetexMappingIteratorList<>(() -> new NetexReferenceRemovingIterator(netexMappingIterator, exportParams));
        setField(StopPlacesInFrame_RelStructure.class, "stopPlace", stopPlacesInFrame_relStructure, stopPlaces);
        netexSiteFrame.setStopPlaces(stopPlacesInFrame_relStructure);
    } else {
        logger.info("No stop places to export");
    }
}
Also used : StopPlace(org.rutebanken.netex.model.StopPlace) ParentStopFetchingIterator(org.rutebanken.tiamat.exporter.async.ParentStopFetchingIterator) NetexMappingIteratorList(org.rutebanken.tiamat.exporter.async.NetexMappingIteratorList) NetexMappingIterator(org.rutebanken.tiamat.exporter.async.NetexMappingIterator) NetexReferenceRemovingIterator(org.rutebanken.tiamat.exporter.async.NetexReferenceRemovingIterator) StopPlacesInFrame_RelStructure(org.rutebanken.netex.model.StopPlacesInFrame_RelStructure) GroupsOfStopPlacesInFrame_RelStructure(org.rutebanken.netex.model.GroupsOfStopPlacesInFrame_RelStructure)

Aggregations

StopPlacesInFrame_RelStructure (org.rutebanken.netex.model.StopPlacesInFrame_RelStructure)9 SiteFrame (org.rutebanken.netex.model.SiteFrame)7 StopPlace (org.rutebanken.netex.model.StopPlace)7 ArrayList (java.util.ArrayList)6 JAXBElement (javax.xml.bind.JAXBElement)6 Test (org.junit.Test)6 MultilingualString (org.rutebanken.netex.model.MultilingualString)6 ObjectFactory (org.rutebanken.netex.model.ObjectFactory)6 PublicationDeliveryStructure (org.rutebanken.netex.model.PublicationDeliveryStructure)6 TariffZoneRef (org.rutebanken.netex.model.TariffZoneRef)6 TariffZoneRefs_RelStructure (org.rutebanken.netex.model.TariffZoneRefs_RelStructure)6 TariffZonesInFrame_RelStructure (org.rutebanken.netex.model.TariffZonesInFrame_RelStructure)6 Zone_VersionStructure (org.rutebanken.netex.model.Zone_VersionStructure)6 TiamatIntegrationTest (org.rutebanken.tiamat.TiamatIntegrationTest)6 ImportParams (org.rutebanken.tiamat.importer.ImportParams)6 BigDecimal (java.math.BigDecimal)4 LocationStructure (org.rutebanken.netex.model.LocationStructure)4 SimplePoint_VersionStructure (org.rutebanken.netex.model.SimplePoint_VersionStructure)4 FareZone (org.rutebanken.netex.model.FareZone)3 TariffZone (org.rutebanken.netex.model.TariffZone)3