Search in sources :

Example 16 with LocationStructure

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

the class ImportResourceTest method publicationDeliveryWithImportedIdUpdates.

/**
 * When sending a stop place multiple times with separate 'imported ids' - all 'imported ids' should be kept
 */
@Test
public void publicationDeliveryWithImportedIdUpdates() throws Exception {
    StopPlace stopPlace = new StopPlace().withId("RUT:StopPlace:123").withVersion("1").withStopPlaceType(StopTypeEnumeration.BUS_STATION).withName(new MultilingualString().withValue("Test")).withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("10")).withLongitude(new BigDecimal("72"))));
    StopPlace stopPlace2 = new StopPlace().withId("RUT:StopPlace:1234").withVersion("2").withStopPlaceType(StopTypeEnumeration.BUS_STATION).withName(new MultilingualString().withValue("Test")).withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("10")).withLongitude(new BigDecimal("72"))));
    StopPlace stopPlace3 = new StopPlace().withId("RUT:StopPlace:12345").withVersion("3").withStopPlaceType(StopTypeEnumeration.BUS_STATION).withName(new MultilingualString().withValue("Test")).withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("10")).withLongitude(new BigDecimal("72"))));
    PublicationDeliveryStructure publicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(stopPlace);
    PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery);
    PublicationDeliveryStructure publicationDelivery2 = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(stopPlace2);
    PublicationDeliveryStructure response2 = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery2);
    PublicationDeliveryStructure publicationDelivery3 = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(stopPlace3);
    PublicationDeliveryStructure response3 = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery3);
    List<StopPlace> result = publicationDeliveryTestHelper.extractStopPlaces(response);
    List<StopPlace> result2 = publicationDeliveryTestHelper.extractStopPlaces(response2);
    List<StopPlace> result3 = publicationDeliveryTestHelper.extractStopPlaces(response3);
    assertThat(result).as("Expecting one stop place in return, as there is no need to return duplicates").hasSize(1);
    assertThat(result2).as("Expecting one stop place in return, as there is no need to return duplicates").hasSize(1);
    assertThat(result3).as("Expecting one stop place in return, as there is no need to return duplicates").hasSize(1);
    assertThat(result3.get(0).getVersion()).isEqualTo("3");
}
Also used : StopPlace(org.rutebanken.netex.model.StopPlace) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) MultilingualString(org.rutebanken.netex.model.MultilingualString) LocationStructure(org.rutebanken.netex.model.LocationStructure) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 17 with LocationStructure

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

the class StopPlaceMatchingTest method matchNearByStopPlaceIfIDMatchIsTooFarAway.

/**
 * See https://rutebanken.atlassian.net/browse/NRP-1601
 *
 * IDs might match incorrectly because of bad data.
 * Make sure if we got a ID match, the distance should be checked.
 * If the existing stop place and the incoming stop place is too far away from each other,
 * fall back to look for nearby stops.
 */
@Test
public void matchNearByStopPlaceIfIDMatchIsTooFarAway() throws Exception {
    StopPlace tooFarAwayStopPlace = new StopPlace().withId("RUT:StopPlace:187187666").withStopPlaceType(StopTypeEnumeration.BUS_STATION).withVersion("1").withName(new MultilingualString().withValue("Too far away")).withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("74")).withLongitude(new BigDecimal("10"))));
    StopPlace nearbyStopPlace = new StopPlace().withId("CBS:StopPlace:321").withStopPlaceType(StopTypeEnumeration.BUS_STATION).withVersion("1").withName(new MultilingualString().withValue("Some stop place")).withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("74.2")).withLongitude(new BigDecimal("10.2"))));
    ImportParams importParams = new ImportParams();
    importParams.importType = ImportType.INITIAL;
    PublicationDeliveryStructure publicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(tooFarAwayStopPlace, nearbyStopPlace);
    publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery, importParams);
    StopPlace stopPlaceToBeMerged = new StopPlace().withId(// Same as the ID of the stop place which is too far away
    "RUT:StopPlace:187187666").withStopPlaceType(StopTypeEnumeration.BUS_STATION).withVersion("1").withName(new MultilingualString().withValue("Some stop place")).withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("74.2002")).withLongitude(new BigDecimal("10.20001"))));
    PublicationDeliveryStructure publicationDelivery2 = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(stopPlaceToBeMerged);
    importParams.importType = ImportType.MERGE;
    PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery2, importParams);
    List<StopPlace> result = publicationDeliveryTestHelper.extractStopPlaces(response);
    assertThat(result).hasSize(1);
    StopPlace actualStopPlace = result.get(0);
    publicationDeliveryTestHelper.hasOriginalId(nearbyStopPlace.getId(), actualStopPlace);
    publicationDeliveryTestHelper.hasOriginalId(stopPlaceToBeMerged.getId(), actualStopPlace);
    assertThat(actualStopPlace.getName().getValue()).isNotEqualTo(tooFarAwayStopPlace.getName().getValue());
    assertThat(actualStopPlace.getName().getValue()).isEqualTo(nearbyStopPlace.getName().getValue());
}
Also used : StopPlace(org.rutebanken.netex.model.StopPlace) ImportParams(org.rutebanken.tiamat.importer.ImportParams) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) MultilingualString(org.rutebanken.netex.model.MultilingualString) LocationStructure(org.rutebanken.netex.model.LocationStructure) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 18 with LocationStructure

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

the class StopPlaceMatchingTest method matchImportedStopOnId.

@Test
public void matchImportedStopOnId() throws Exception {
    StopPlace stopPlaceToBeMatched = new StopPlace().withId("RUT:StopPlace:187187666").withStopPlaceType(StopTypeEnumeration.BUS_STATION).withVersion("1").withName(new MultilingualString().withValue("I don't care")).withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("10")).withLongitude(new BigDecimal("74"))));
    ImportParams importParams = new ImportParams();
    importParams.importType = ImportType.INITIAL;
    PublicationDeliveryStructure publicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(stopPlaceToBeMatched);
    publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery, importParams);
    PublicationDeliveryStructure publicationDelivery2 = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(stopPlaceToBeMatched);
    importParams.importType = ImportType.ID_MATCH;
    PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery2, importParams);
    System.out.println("Got response: \n" + response);
    List<StopPlace> result = publicationDeliveryTestHelper.extractStopPlaces(response);
    assertThat(result).hasSize(1);
    publicationDeliveryTestHelper.hasOriginalId(stopPlaceToBeMatched.getId(), result.get(0));
}
Also used : StopPlace(org.rutebanken.netex.model.StopPlace) ImportParams(org.rutebanken.tiamat.importer.ImportParams) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) MultilingualString(org.rutebanken.netex.model.MultilingualString) LocationStructure(org.rutebanken.netex.model.LocationStructure) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 19 with LocationStructure

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

the class StopPlaceMatchingTest method matchMultipleStopsBasedOnQuayOriginalId.

/**
 * Incoming stop matches two stops.
 * Incoming stop has two quays, where each quay matches in separate stop place.
 * Both stop places should be returned.
 *
 * https://rutebanken.atlassian.net/browse/NRP-1718
 */
@Test
public void matchMultipleStopsBasedOnQuayOriginalId() throws Exception {
    StopPlace firstStopPlace = new StopPlace().withId("NTR:StopPlace:10").withStopPlaceType(StopTypeEnumeration.BUS_STATION).withVersion("1").withName(new MultilingualString().withValue("Vennesla")).withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("10")).withLongitude(new BigDecimal("74")))).withQuays(new Quays_RelStructure().withQuayRefOrQuay(new Quay().withId("NTR:Quay:11").withVersion("1")));
    ImportParams importParams = new ImportParams();
    importParams.importType = ImportType.INITIAL;
    PublicationDeliveryStructure initialPublicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(firstStopPlace);
    publicationDeliveryTestHelper.postAndReturnPublicationDelivery(initialPublicationDelivery, importParams);
    StopPlace secondStopPlace = new StopPlace().withId("NTR:StopPlace:10").withStopPlaceType(StopTypeEnumeration.BUS_STATION).withVersion("1").withName(new MultilingualString().withValue("Vennesla")).withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("10")).withLongitude(new BigDecimal("74")))).withQuays(new Quays_RelStructure().withQuayRefOrQuay(new Quay().withId("NTR:Quay:12").withVersion("1")));
    PublicationDeliveryStructure secondInitialPublicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(secondStopPlace);
    publicationDeliveryTestHelper.postAndReturnPublicationDelivery(secondInitialPublicationDelivery, importParams);
    StopPlace incomingStopPlace = new StopPlace().withId("NTR:StopPlace:10").withStopPlaceType(StopTypeEnumeration.BUS_STATION).withVersion("1").withName(new MultilingualString().withValue("Vennesla")).withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("10")).withLongitude(new BigDecimal("74")))).withQuays(new Quays_RelStructure().withQuayRefOrQuay(new Quay().withId("NTR:Quay:12").withVersion("1")).withQuayRefOrQuay(new Quay().withId("NTR:Quay:11").withVersion("1")));
    importParams.importType = ImportType.MATCH;
    PublicationDeliveryStructure matchingPublicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(incomingStopPlace);
    PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(matchingPublicationDelivery, importParams);
    List<StopPlace> result = publicationDeliveryTestHelper.extractStopPlaces(response);
    assertThat(result).as("two stop places matches one incoming stop place with two quays").hasSize(2);
}
Also used : Quays_RelStructure(org.rutebanken.netex.model.Quays_RelStructure) StopPlace(org.rutebanken.netex.model.StopPlace) ImportParams(org.rutebanken.tiamat.importer.ImportParams) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) Quay(org.rutebanken.netex.model.Quay) MultilingualString(org.rutebanken.netex.model.MultilingualString) LocationStructure(org.rutebanken.netex.model.LocationStructure) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 20 with LocationStructure

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

the class StopPlaceMatchingTest method doNotmatchStopOnSimilarOriginalId.

@Test
public void doNotmatchStopOnSimilarOriginalId() throws Exception {
    StopPlace stopPlaceNotToBeMatched = new StopPlace().withName(new MultilingualString().withValue("Hest")).withId("RUT:StopPlace:212345678910").withStopPlaceType(StopTypeEnumeration.BUS_STATION).withVersion("1").withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("15")).withLongitude(new BigDecimal("76"))));
    ImportParams importParams = new ImportParams();
    importParams.importType = ImportType.INITIAL;
    PublicationDeliveryStructure publicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(stopPlaceNotToBeMatched);
    publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery, importParams);
    // ID is similar, but does not start with 2
    stopPlaceNotToBeMatched.setId("RUT:StopPlace:12345678910");
    PublicationDeliveryStructure publicationDelivery2 = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(stopPlaceNotToBeMatched);
    importParams.importType = ImportType.ID_MATCH;
    PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery2, importParams);
    System.out.println("Got response: \n" + response);
    List<StopPlace> result = publicationDeliveryTestHelper.extractStopPlaces(response, false);
    assertThat(result).as("no match as stop has different ID").hasSize(0);
}
Also used : StopPlace(org.rutebanken.netex.model.StopPlace) ImportParams(org.rutebanken.tiamat.importer.ImportParams) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) MultilingualString(org.rutebanken.netex.model.MultilingualString) LocationStructure(org.rutebanken.netex.model.LocationStructure) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Aggregations

LocationStructure (org.rutebanken.netex.model.LocationStructure)47 SimplePoint_VersionStructure (org.rutebanken.netex.model.SimplePoint_VersionStructure)47 Test (org.junit.Test)44 BigDecimal (java.math.BigDecimal)37 PublicationDeliveryStructure (org.rutebanken.netex.model.PublicationDeliveryStructure)36 StopPlace (org.rutebanken.netex.model.StopPlace)36 TiamatIntegrationTest (org.rutebanken.tiamat.TiamatIntegrationTest)35 MultilingualString (org.rutebanken.netex.model.MultilingualString)31 ImportParams (org.rutebanken.tiamat.importer.ImportParams)21 Quay (org.rutebanken.netex.model.Quay)16 Quays_RelStructure (org.rutebanken.netex.model.Quays_RelStructure)16 ArrayList (java.util.ArrayList)11 LocalDateTime (java.time.LocalDateTime)9 ValidBetween (org.rutebanken.netex.model.ValidBetween)8 Response (javax.ws.rs.core.Response)7 KeyValueStructure (org.rutebanken.netex.model.KeyValueStructure)7 Sets (com.google.common.collect.Sets)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IOException (java.io.IOException)6