Search in sources :

Example 16 with ValidBetween

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

the class StopPlaceRepositoryTest method doNotFindHistoricStopPlaceWithoutParentForCurrentAndFutureVersion.

@Test
public void doNotFindHistoricStopPlaceWithoutParentForCurrentAndFutureVersion() {
    StopPlace historicVersion = new StopPlace();
    historicVersion.setVersion(1L);
    historicVersion.setValidBetween(new ValidBetween(now.minus(3, DAYS), now.minus(2, DAYS)));
    stopPlaceRepository.save(historicVersion);
    StopPlaceSearch stopPlaceSearch = StopPlaceSearch.newStopPlaceSearchBuilder().setVersionValidity(ExportParams.VersionValidity.CURRENT_FUTURE).build();
    Page<StopPlace> results = stopPlaceRepository.findStopPlace(ExportParams.newExportParamsBuilder().setStopPlaceSearch(stopPlaceSearch).build());
    assertThat(results).isEmpty();
}
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)

Example 17 with ValidBetween

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

the class StopPlaceRepositoryTest method findFutureStopPlaceVersion.

@Test
public void findFutureStopPlaceVersion() {
    StopPlace futureVersion = new StopPlace();
    futureVersion.setVersion(1L);
    futureVersion.setValidBetween(new ValidBetween(now.plus(1, DAYS), now.plus(2, DAYS)));
    stopPlaceRepository.save(futureVersion);
    StopPlaceSearch stopPlaceSearch = StopPlaceSearch.newStopPlaceSearchBuilder().setVersionValidity(ExportParams.VersionValidity.CURRENT_FUTURE).build();
    Page<StopPlace> results = stopPlaceRepository.findStopPlace(ExportParams.newExportParamsBuilder().setStopPlaceSearch(stopPlaceSearch).build());
    assertThat(results).hasSize(1).contains(futureVersion);
}
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)

Example 18 with ValidBetween

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

the class MultiModalStopPlaceEditorTest method testCreateMultiModalParentStopPlaceWithFutureValidBetween.

@Test
public void testCreateMultiModalParentStopPlaceWithFutureValidBetween() {
    StopPlace child = stopPlaceRepository.save(createStopPlace("StopPlace - 1"));
    Instant futureTime = now.plusSeconds(600);
    String parentStopPlaceName = "Super Duper StopPlace";
    String versionComment = "version comment";
    StopPlace result = multiModalStopPlaceEditor.createMultiModalParentStopPlace(Arrays.asList(child.getNetexId()), new EmbeddableMultilingualString(parentStopPlaceName), new ValidBetween(futureTime), versionComment, null);
    assertThat(result.getValidBetween().getFromDate()).isEqualTo(futureTime);
    assertThatChildsAreReferencingParent(Arrays.asList(child.getNetexId()), result);
    verifyChildValidBetween(result);
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) Instant(java.time.Instant) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 19 with ValidBetween

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

the class MultiModalStopPlaceEditorTest method testAddToMultiModalParentStopPlaceWithFutureValidBetween.

@Test
public void testAddToMultiModalParentStopPlaceWithFutureValidBetween() {
    StopPlace child = stopPlaceRepository.save(createStopPlace("StopPlace - 1"));
    Instant futureTime = now.plusSeconds(600);
    String parentStopPlaceName = "Super Duper StopPlace +1";
    StopPlace parent = new StopPlace(new EmbeddableMultilingualString(parentStopPlaceName));
    parent.setParentStopPlace(true);
    parent = stopPlaceRepository.save(parent);
    StopPlace result = multiModalStopPlaceEditor.addToMultiModalParentStopPlace(parent.getNetexId(), Arrays.asList(child.getNetexId()), new ValidBetween(futureTime), null);
    assertThatChildsAreReferencingParent(Arrays.asList(child.getNetexId()), result);
    verifyChildValidBetween(result);
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) Instant(java.time.Instant) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 20 with ValidBetween

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

the class MultiModalStopPlaceEditor method addToMultiModalParentStopPlace.

public StopPlace addToMultiModalParentStopPlace(String parentStopPlaceId, List<String> childStopPlaceIds, ValidBetween validBetween, String versionComment) {
    return mutateLock.executeInLock(() -> {
        logger.info("Add childs: {} to parent stop place {}", childStopPlaceIds, parentStopPlaceId);
        verifyChildrenIdsNotNullOrEmpty(childStopPlaceIds);
        Instant fromDate = resolveFromDateOrNow(validBetween);
        StopPlace parentStopPlace = stopPlaceRepository.findFirstByNetexIdOrderByVersionDesc(parentStopPlaceId);
        if (parentStopPlace == null) {
            throw new IllegalArgumentException("Cannot fetch parent stop place from ID: " + parentStopPlaceId);
        }
        authorizationService.assertAuthorized(ROLE_EDIT_STOPS, Arrays.asList(parentStopPlace));
        List<String> alreadyAdded = childStopPlaceIds.stream().filter(child -> parentStopPlace.getChildren() != null && parentStopPlace.getChildren().stream().anyMatch(existingChild -> child.equals(existingChild.getNetexId()))).collect(toList());
        if (!alreadyAdded.isEmpty()) {
            throw new IllegalArgumentException("Child stop place(s) " + alreadyAdded + " is already added to " + parentStopPlace);
        }
        StopPlace parentStopPlaceCopy = versionCreator.createCopy(parentStopPlace, StopPlace.class);
        parentStopPlaceCopy.setValidBetween(validBetween);
        parentStopPlaceCopy.setVersionComment(versionComment);
        List<StopPlace> futureChildStopPlaces = childStopPlaceIds.stream().map(id -> stopPlaceRepository.findFirstByNetexIdOrderByVersionDesc(id)).collect(toList());
        authorizationService.assertAuthorized(ROLE_EDIT_STOPS, futureChildStopPlaces);
        Set<StopPlace> childCopies = validateAndCopyPotentionalChildren(futureChildStopPlaces, parentStopPlace, fromDate);
        Instant terminationDate = fromDate.minusMillis(MILLIS_BETWEEN_VERSIONS);
        terminatePreviousVersionsOfChildren(futureChildStopPlaces, terminationDate);
        stopPlaceRepository.saveAll(futureChildStopPlaces);
        parentStopPlaceCopy.getChildren().addAll(childCopies);
        return stopPlaceVersionedSaverService.saveNewVersion(parentStopPlace, parentStopPlaceCopy, fromDate);
    });
}
Also used : EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) Arrays(java.util.Arrays) MILLIS_BETWEEN_VERSIONS(org.rutebanken.tiamat.versioning.save.DefaultVersionedSaverService.MILLIS_BETWEEN_VERSIONS) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) Point(org.locationtech.jts.geom.Point) ReflectionAuthorizationService(org.rutebanken.helper.organisation.ReflectionAuthorizationService) StopPlace(org.rutebanken.tiamat.model.StopPlace) VersionCreator(org.rutebanken.tiamat.versioning.VersionCreator) Instant(java.time.Instant) StopPlaceRepository(org.rutebanken.tiamat.repository.StopPlaceRepository) Component(org.springframework.stereotype.Component) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) MutateLock(org.rutebanken.tiamat.lock.MutateLock) StopPlaceVersionedSaverService(org.rutebanken.tiamat.versioning.save.StopPlaceVersionedSaverService) ROLE_EDIT_STOPS(org.rutebanken.helper.organisation.AuthorizationConstants.ROLE_EDIT_STOPS) Collectors.toSet(java.util.stream.Collectors.toSet) Transactional(org.springframework.transaction.annotation.Transactional) StopPlace(org.rutebanken.tiamat.model.StopPlace) Instant(java.time.Instant) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString)

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