use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.
the class TariffZoneTerminator method terminateTariffZone.
public TariffZone terminateTariffZone(String tariffZoneId, Instant suggestedTimeOfTermination, String versionComment) {
return mutateLock.executeInLock(() -> {
String usernameForAuthenticatedUser = usernameFetcher.getUserNameForAuthenticatedUser();
logger.warn("About to terminate tariff zone by ID {}. User: {}", tariffZoneId, usernameForAuthenticatedUser);
DataManagedObjectStructure resolved = referenceResolver.resolve(new VersionOfObjectRefStructure(tariffZoneId));
authorizationService.assertAuthorized(ROLE_EDIT_STOPS, Collections.singletonList(resolved));
Instant now = Instant.now();
Instant timeOfTermination;
if (suggestedTimeOfTermination.isBefore(now)) {
logger.warn("Termination date {} cannot be before now {}. Setting now as time of termination for {}", suggestedTimeOfTermination, now, tariffZoneId);
timeOfTermination = now;
} else {
timeOfTermination = suggestedTimeOfTermination;
}
logger.info("User {} is terminating tariff zone {} at {} with comment '{}'", usernameFetcher.getUserNameForAuthenticatedUser(), tariffZoneId, timeOfTermination, versionComment);
final TariffZone tariffZone = tariffZoneRepository.findFirstByNetexIdOrderByVersionDesc(tariffZoneId);
if (tariffZone != null) {
// or to_date after future date, this is to avoid duplicated tariff zones.
if (tariffZone.getValidBetween() != null && tariffZone.getValidBetween().getToDate() != null && tariffZone.getValidBetween().getToDate().isBefore(timeOfTermination)) {
throw new IllegalArgumentException("The tariff zone " + tariffZoneId + ", version " + tariffZone.getVersion() + " is already terminated at " + tariffZone.getValidBetween().getToDate());
}
logger.debug("End previous version {} of tariff zone {} at {} (timeOfTermination)", tariffZone.getVersion(), tariffZone.getNetexId(), timeOfTermination);
tariffZone.getValidBetween().setToDate(timeOfTermination);
final TariffZone result = tariffZoneRepository.save(tariffZone);
// Start updating stop_place tariff zone ref
backgroundJobs.triggerStopPlaceUpdate();
return result;
} else {
throw new IllegalArgumentException("Cannot find tariff zone to terminate: " + tariffZoneId + ". No changes executed.");
}
});
}
use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.
the class TariffZonesFromStopsExporterTest method avoidDuplicateTariffZones.
@Test
public void avoidDuplicateTariffZones() {
TariffZone tariffZone = new TariffZone();
tariffZone.setNetexId("VKT:TariffZone:201");
tariffZone.setVersion(1L);
tariffZoneRepository.save(tariffZone);
// Two stops with reference to the same tariffzone
StopPlace netexStopPlace = new StopPlace();
netexStopPlace.setId("NSR:StopPlace:1");
netexStopPlace.withTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withRef(tariffZone.getNetexId()).withVersion("1")));
StopPlace netexStopPlace2 = new StopPlace();
netexStopPlace2.setId("NSR:StopPlace:2");
netexStopPlace2.withTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withRef(tariffZone.getNetexId()).withVersion("1")));
SiteFrame siteFrame = new SiteFrame();
tariffZonesFromStopsExporter.resolveTariffZones(Arrays.asList(netexStopPlace, netexStopPlace2), siteFrame);
assertThat(siteFrame.getTariffZones().getTariffZone()).as("Number of tariffzones returned").hasSize(1);
}
use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.
the class TiamatSiteFrameExporterTest method exportTariffZonesInSiteFrame.
@Test
public void exportTariffZonesInSiteFrame() {
org.rutebanken.tiamat.model.SiteFrame siteFrame = new org.rutebanken.tiamat.model.SiteFrame();
TariffZone tariffZone = new TariffZone();
tariffZone.setName(new EmbeddableMultilingualString("name"));
tariffZoneRepository.save(tariffZone);
tiamatSiteFrameExporter.addAllTariffZones(siteFrame);
assertThat(siteFrame.getTariffZones()).isNotNull();
assertThat(siteFrame.getTariffZones().getTariffZone()).hasSize(1);
}
use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.
the class GenericObjectDifferTest method diffStopPlaceWithTariffZone.
@Test
public void diffStopPlaceWithTariffZone() throws IllegalAccessException {
StopPlace oldStopPlace = new StopPlace();
StopPlace newStopPlace = new StopPlace();
newStopPlace.getTariffZones().add(new TariffZoneRef(new TariffZone()));
String diffString = compareObjectsAndPrint(oldStopPlace, newStopPlace);
assertThat(diffString).contains("tariffZones");
}
use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.
the class TariffZoneSaverService method saveNewVersion.
public TariffZone saveNewVersion(TariffZone existingVersion, TariffZone newVersion) {
versionValidator.validate(existingVersion, newVersion);
TariffZone saved = defaultVersionedSaverService.saveNewVersion(existingVersion, newVersion, tariffZoneRepository);
tariffZonesLookupService.resetTariffZone();
return saved;
}
Aggregations