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();
}
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);
}
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);
}
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);
}
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);
});
}
Aggregations