Search in sources :

Example 11 with ValidBetween

use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.

the class StopPlaceRepositoryImplTest method findStopsWithEffectiveChangesInPeriodWithParent.

@Test
public void findStopsWithEffectiveChangesInPeriodWithParent() {
    String importedIdPosix = "321";
    String importedId = "XXX:StopPlace:" + importedIdPosix;
    StopPlace childStop = new StopPlace();
    childStop.setVersion(1L);
    Quay quay = new Quay();
    quay.getOrCreateValues(ORIGINAL_ID_KEY).add(importedId);
    quayRepository.save(quay);
    childStop.getQuays().add(quay);
    StopPlace parentStop = new StopPlace();
    parentStop.setParentStopPlace(true);
    parentStop.setVersion(2L);
    // Valid between only set on parent
    parentStop.setValidBetween(new ValidBetween(now.minusSeconds(10)));
    parentStop.getChildren().add(childStop);
    stopPlaceRepository.save(parentStop);
    childStop.setParentSiteRef(new SiteRefStructure(parentStop.getNetexId(), String.valueOf(parentStop.getVersion())));
    stopPlaceRepository.save(childStop);
    ChangedStopPlaceSearch changedStopPlaceSearch = new ChangedStopPlaceSearch(now.minusSeconds(20), now.plusSeconds(20), PageRequest.of(0, 10));
    Page<StopPlace> result = stopPlaceRepository.findStopPlacesWithEffectiveChangeInPeriod(changedStopPlaceSearch);
    assertThat(result.getContent()).extracting(StopPlace::getNetexId).contains(parentStop.getNetexId());
    assertThat(result.getContent()).extracting(StopPlace::getNetexId).doesNotContain(childStop.getNetexId());
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) SiteRefStructure(org.rutebanken.tiamat.model.SiteRefStructure) Quay(org.rutebanken.tiamat.model.Quay) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) ChangedStopPlaceSearch(org.rutebanken.tiamat.repository.search.ChangedStopPlaceSearch) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 12 with ValidBetween

use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.

the class StopPlaceRepositoryImplTest method findStopPlacesDefaultsToVersionValidityCurrent.

@Test
public void findStopPlacesDefaultsToVersionValidityCurrent() {
    Instant yesterday = now.minus(1, ChronoUnit.DAYS);
    StopPlace v1 = new StopPlace(new EmbeddableMultilingualString("stop"));
    v1.setStopPlaceType(StopTypeEnumeration.BUS_STATION);
    v1.setVersion(1L);
    v1.setValidBetween(new ValidBetween(Instant.EPOCH, yesterday));
    stopPlaceRepository.save(v1);
    StopPlace v2 = new StopPlace(new EmbeddableMultilingualString("v2"));
    v2.setVersion(2L);
    v2.setNetexId(v1.getNetexId());
    v2.setStopPlaceType(StopTypeEnumeration.BUS_STATION);
    v2.setValidBetween(new ValidBetween(yesterday));
    stopPlaceRepository.save(v2);
    stopPlaceRepository.flush();
    ExportParams exportParams = newExportParamsBuilder().setStopPlaceSearch(newStopPlaceSearchBuilder().setQuery(v2.getNetexId()).setStopTypeEnumerations(Arrays.asList(StopTypeEnumeration.BUS_STATION)).build()).build();
    List<StopPlace> content = stopPlaceRepository.findStopPlace(exportParams).getContent();
    assertThat(content).isNotEmpty();
    assertThat(content).hasSize(1);
    assertThat(content.get(0).getVersion()).isEqualTo(2L);
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) ExportParams(org.rutebanken.tiamat.exporter.params.ExportParams) Instant(java.time.Instant) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 13 with ValidBetween

use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.

the class StopPlaceRepositoryImplTest method findStopPlacesWithinMaxVersion.

@Test
public void findStopPlacesWithinMaxVersion() throws Exception {
    double southEastLatitude = 59.875649;
    double southEastLongitude = 10.500340;
    double northWestLatitude = 59.875924;
    double northWestLongitude = 10.500699;
    StopPlace version1 = createStopPlace(59.875679, 10.500430);
    version1.setVersion(1L);
    version1.setNetexId("NSR:StopPlace:977777");
    version1.setValidBetween(new ValidBetween(Instant.EPOCH, now.minusMillis(1000000)));
    StopPlace version2 = createStopPlace(59.875679, 10.500430);
    version2.setVersion(2L);
    version2.setNetexId(version1.getNetexId());
    version2.setValidBetween(new ValidBetween(now.minusMillis(1000001), now.plusMillis(1000000)));
    stopPlaceRepository.save(version1);
    stopPlaceRepository.save(version2);
    Pageable pageable = PageRequest.of(0, 10);
    Page<StopPlace> result = stopPlaceRepository.findStopPlacesWithin(southEastLongitude, southEastLatitude, northWestLongitude, northWestLatitude, null, pageable);
    assertThat(result).hasSize(1);
    assertThat(result.getContent().get(0).getVersion()).isEqualTo(version2.getVersion());
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) Pageable(org.springframework.data.domain.Pageable) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 14 with ValidBetween

use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.

the class StopPlaceRepositoryImplTest method findByTagParam.

@Test
public void findByTagParam() {
    StopPlace stopPlace = new StopPlace();
    stopPlace.setVersion(2L);
    stopPlace.setValidBetween(new ValidBetween(now.minusSeconds(10)));
    stopPlaceRepository.save(stopPlace);
    Tag tag = new Tag();
    tag.setName("tagname");
    tag.setIdreference(stopPlace.getNetexId());
    tag = tagRepository.save(tag);
    StopPlaceSearch stopPlaceSearch = StopPlaceSearch.newStopPlaceSearchBuilder().setQuery("#" + tag.getName()).build();
    Page<StopPlace> searchResult = stopPlaceRepository.findStopPlace(ExportParams.newExportParamsBuilder().setStopPlaceSearch(stopPlaceSearch).build());
    assertThat(searchResult.getContent()).extracting(s -> s.getNetexId()).contains(stopPlace.getNetexId());
}
Also used : SiteRefStructure(org.rutebanken.tiamat.model.SiteRefStructure) Arrays(java.util.Arrays) ORIGINAL_ID_KEY(org.rutebanken.tiamat.netex.mapping.mapper.NetexIdMapper.ORIGINAL_ID_KEY) Quay(org.rutebanken.tiamat.model.Quay) TopographicPlace(org.rutebanken.tiamat.model.TopographicPlace) Coordinate(org.locationtech.jts.geom.Coordinate) Autowired(org.springframework.beans.factory.annotation.Autowired) StopPlaceSearch(org.rutebanken.tiamat.exporter.params.StopPlaceSearch) IdentifiedEntity(org.rutebanken.tiamat.model.identification.IdentifiedEntity) StopPlace(org.rutebanken.tiamat.model.StopPlace) ExportParams.newExportParamsBuilder(org.rutebanken.tiamat.exporter.params.ExportParams.newExportParamsBuilder) ArrayList(java.util.ArrayList) Map(java.util.Map) AssertionsForInterfaceTypes.assertThat(org.assertj.core.api.AssertionsForInterfaceTypes.assertThat) Assertions(org.assertj.core.api.Assertions) Pageable(org.springframework.data.domain.Pageable) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) Tag(org.rutebanken.tiamat.model.tag.Tag) ChangedStopPlaceSearch(org.rutebanken.tiamat.repository.search.ChangedStopPlaceSearch) Iterator(java.util.Iterator) StopPlaceSearch.newStopPlaceSearchBuilder(org.rutebanken.tiamat.exporter.params.StopPlaceSearch.newStopPlaceSearchBuilder) Collection(java.util.Collection) Value(org.rutebanken.tiamat.model.Value) PageRequest(org.springframework.data.domain.PageRequest) Set(java.util.Set) MERGED_ID_KEY(org.rutebanken.tiamat.netex.mapping.mapper.NetexIdMapper.MERGED_ID_KEY) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest) Page(org.springframework.data.domain.Page) Instant(java.time.Instant) StopTypeEnumeration(org.rutebanken.tiamat.model.StopTypeEnumeration) Sets(com.google.common.collect.Sets) ExportParams(org.rutebanken.tiamat.exporter.params.ExportParams) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) TopographicPlaceRefStructure(org.rutebanken.tiamat.model.TopographicPlaceRefStructure) CollectionUtils(org.springframework.util.CollectionUtils) IdMappingDto(org.rutebanken.tiamat.dtoassembling.dto.IdMappingDto) MultiModalStopPlaceEditor(org.rutebanken.tiamat.service.stopplace.MultiModalStopPlaceEditor) H2Functions(org.rutebanken.tiamat.config.H2Functions) EntityStructure(org.rutebanken.tiamat.model.EntityStructure) Assert(org.junit.Assert) Envelope(org.locationtech.jts.geom.Envelope) Transactional(org.springframework.transaction.annotation.Transactional) StopPlace(org.rutebanken.tiamat.model.StopPlace) StopPlaceSearch(org.rutebanken.tiamat.exporter.params.StopPlaceSearch) ChangedStopPlaceSearch(org.rutebanken.tiamat.repository.search.ChangedStopPlaceSearch) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) Tag(org.rutebanken.tiamat.model.tag.Tag) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 15 with ValidBetween

use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.

the class StopPlaceRepositoryTest method findCurrentlyValidStopPlaceWithoutEndDate.

@Test
public void findCurrentlyValidStopPlaceWithoutEndDate() {
    StopPlace currentlyValid = new StopPlace();
    currentlyValid.setVersion(1L);
    currentlyValid.setValidBetween(new ValidBetween(now.minus(1, DAYS)));
    stopPlaceRepository.save(currentlyValid);
    StopPlaceSearch stopPlaceSearch = StopPlaceSearch.newStopPlaceSearchBuilder().setVersionValidity(ExportParams.VersionValidity.ALL).build();
    Page<StopPlace> results = stopPlaceRepository.findStopPlace(ExportParams.newExportParamsBuilder().setStopPlaceSearch(stopPlaceSearch).build());
    assertThat(results).hasSize(1);
    assertThat(results).contains(currentlyValid);
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) StopPlaceSearch(org.rutebanken.tiamat.exporter.params.StopPlaceSearch) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Aggregations

ValidBetween (org.rutebanken.tiamat.model.ValidBetween)66 StopPlace (org.rutebanken.tiamat.model.StopPlace)57 Test (org.junit.Test)56 TiamatIntegrationTest (org.rutebanken.tiamat.TiamatIntegrationTest)56 EmbeddableMultilingualString (org.rutebanken.tiamat.model.EmbeddableMultilingualString)38 Instant (java.time.Instant)33 StopPlaceSearch (org.rutebanken.tiamat.exporter.params.StopPlaceSearch)17 SiteRefStructure (org.rutebanken.tiamat.model.SiteRefStructure)14 ChangedStopPlaceSearch (org.rutebanken.tiamat.repository.search.ChangedStopPlaceSearch)12 ExportParams (org.rutebanken.tiamat.exporter.params.ExportParams)11 Quay (org.rutebanken.tiamat.model.Quay)11 List (java.util.List)9 Coordinate (org.locationtech.jts.geom.Coordinate)9 TopographicPlace (org.rutebanken.tiamat.model.TopographicPlace)9 Pageable (org.springframework.data.domain.Pageable)9 Autowired (org.springframework.beans.factory.annotation.Autowired)8 Arrays (java.util.Arrays)7 Set (java.util.Set)7 IdMappingDto (org.rutebanken.tiamat.dtoassembling.dto.IdMappingDto)7 Value (org.rutebanken.tiamat.model.Value)7