Search in sources :

Example 26 with LocationStructure

use of org.rutebanken.netex.model.LocationStructure in project OpenTripPlanner by opentripplanner.

the class WgsCoordinateMapperTest method handleCoordinatesWithValuesSet.

@Test
public void handleCoordinatesWithValuesSet() {
    // Given a valid point
    final SimplePoint_VersionStructure point = new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLongitude(LONGITUDE).withLatitude(LATITUDE));
    // When map coordinates
    WgsCoordinate c = WgsCoordinateMapper.mapToDomain(point);
    // Then verify coordinate
    assertEquals(LONGITUDE_VALUE, c.longitude(), DELTA);
    assertEquals(LATITUDE_VALUE, c.latitude(), DELTA);
}
Also used : WgsCoordinate(org.opentripplanner.model.WgsCoordinate) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) LocationStructure(org.rutebanken.netex.model.LocationStructure) Test(org.junit.Test)

Example 27 with LocationStructure

use of org.rutebanken.netex.model.LocationStructure in project OpenTripPlanner by opentripplanner.

the class WgsCoordinateMapperTest method handleCoordinatesWithMissingLongitude.

@Test(expected = IllegalArgumentException.class)
public void handleCoordinatesWithMissingLongitude() {
    SimplePoint_VersionStructure p;
    p = new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(LATITUDE));
    WgsCoordinateMapper.mapToDomain(p);
}
Also used : SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) LocationStructure(org.rutebanken.netex.model.LocationStructure) Test(org.junit.Test)

Example 28 with LocationStructure

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

the class QuayMapper method mapBtoA.

@Override
public void mapBtoA(org.rutebanken.tiamat.model.Quay quay, Quay quay2, MappingContext context) {
    super.mapBtoA(quay, quay2, context);
    if (quay.getPlaceEquipments() != null && quay.getPlaceEquipments().getInstalledEquipment() != null && quay.getPlaceEquipments().getInstalledEquipment().isEmpty()) {
        quay.setPlaceEquipments(null);
        quay2.setPlaceEquipments(null);
    }
    if (quay.getAlternativeNames() != null && !quay.getAlternativeNames().isEmpty()) {
        List<AlternativeName> alternativeNames = quay.getAlternativeNames();
        List<org.rutebanken.netex.model.AlternativeName> netexAlternativeNames = new ArrayList<>();
        for (org.rutebanken.tiamat.model.AlternativeName alternativeName : alternativeNames) {
            if (alternativeName != null && alternativeName.getName() != null && alternativeName.getName().getValue() != null && !alternativeName.getName().getValue().isEmpty()) {
                // Only include non-empty alternative names
                org.rutebanken.netex.model.AlternativeName netexAltName = new org.rutebanken.netex.model.AlternativeName();
                mapperFacade.map(alternativeName, netexAltName);
                netexAltName.setId(alternativeName.getNetexId());
                netexAlternativeNames.add(netexAltName);
            }
        }
        if (!netexAlternativeNames.isEmpty()) {
            AlternativeNames_RelStructure altName = new AlternativeNames_RelStructure();
            altName.getAlternativeName().addAll(netexAlternativeNames);
            quay2.setAlternativeNames(altName);
        }
    } else {
        quay2.setAlternativeNames(null);
    }
    if (quay.getBoardingPositions() != null && !quay.getBoardingPositions().isEmpty()) {
        final List<BoardingPosition> boardingPositions = quay.getBoardingPositions();
        List<org.rutebanken.netex.model.BoardingPosition> netexBoardingPositions = new ArrayList<>();
        for (BoardingPosition boardingPosition : boardingPositions) {
            if (boardingPosition != null && boardingPosition.getPublicCode() != null && !boardingPosition.getPublicCode().isEmpty()) {
                // Only Include non-empty boarding-positions
                final org.rutebanken.netex.model.BoardingPosition netexBoardingPosition = new org.rutebanken.netex.model.BoardingPosition();
                mapperFacade.map(boardingPosition, netexBoardingPosition);
                netexBoardingPosition.setId(boardingPosition.getNetexId());
                netexBoardingPosition.setPublicCode(boardingPosition.getPublicCode());
                if (boardingPosition.getCentroid() != null) {
                    SimplePoint_VersionStructure simplePoint = new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(BigDecimal.valueOf(boardingPosition.getCentroid().getY())).withLongitude(BigDecimal.valueOf(boardingPosition.getCentroid().getX())));
                    netexBoardingPosition.setCentroid(simplePoint);
                }
                netexBoardingPositions.add(netexBoardingPosition);
            }
        }
        if (!netexBoardingPositions.isEmpty()) {
            final BoardingPositions_RelStructure boardingPositionsRelStructure = new BoardingPositions_RelStructure();
            boardingPositionsRelStructure.getBoardingPositionRefOrBoardingPosition().addAll(netexBoardingPositions);
            quay2.setBoardingPositions(boardingPositionsRelStructure);
        }
    }
}
Also used : AlternativeNames_RelStructure(org.rutebanken.netex.model.AlternativeNames_RelStructure) ArrayList(java.util.ArrayList) AlternativeName(org.rutebanken.tiamat.model.AlternativeName) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) LocationStructure(org.rutebanken.netex.model.LocationStructure) AlternativeName(org.rutebanken.tiamat.model.AlternativeName) BoardingPosition(org.rutebanken.tiamat.model.BoardingPosition) BoardingPositions_RelStructure(org.rutebanken.netex.model.BoardingPositions_RelStructure)

Example 29 with LocationStructure

use of org.rutebanken.netex.model.LocationStructure 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)

Example 30 with LocationStructure

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

the class ImportResourceTest method maxNumberOfDigitsInCoordinatesShouldBeSix.

@Test
public void maxNumberOfDigitsInCoordinatesShouldBeSix() throws Exception {
    final int maxdigits = 6;
    StopPlace stopPlace = new StopPlace().withId("XYZ:StopPlace:91").withVersion("1").withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("10.123456789123456789123456789")).withLongitude(new BigDecimal("20.123456789123456789123456789")))).withQuays(new Quays_RelStructure().withQuayRefOrQuay(new Quay().withId("XYZ:Quay:91").withVersion("1").withName(new MultilingualString().withValue("quay number one")).withCentroid(new SimplePoint_VersionStructure().withVersion("1").withLocation(new LocationStructure().withLatitude(new BigDecimal("10.123456789123456789123456789")).withLongitude(new BigDecimal("20.123456789123456789123456789"))))));
    PublicationDeliveryStructure publicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(stopPlace);
    PublicationDeliveryStructure firstResponse = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery);
    StopPlace actualStopPlace = publicationDeliveryTestHelper.findFirstStopPlace(firstResponse);
    BigDecimal longitude = actualStopPlace.getCentroid().getLocation().getLongitude();
    BigDecimal latitude = actualStopPlace.getCentroid().getLocation().getLatitude();
    assertThat(String.valueOf(longitude).split("\\.")[1].length()).as("longitude decimals length").isLessThanOrEqualTo(maxdigits);
    assertThat(String.valueOf(latitude).split("\\.")[1].length()).as("latitude decimals length").isLessThanOrEqualTo(maxdigits);
}
Also used : Quays_RelStructure(org.rutebanken.netex.model.Quays_RelStructure) StopPlace(org.rutebanken.netex.model.StopPlace) 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)

Aggregations

LocationStructure (org.rutebanken.netex.model.LocationStructure)50 SimplePoint_VersionStructure (org.rutebanken.netex.model.SimplePoint_VersionStructure)50 Test (org.junit.Test)47 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