mirror of
https://github.com/2martens/tsw-timetable.git
synced 2026-10-17 07:57:55 +02:00
change: Remove routeId from BahnTimetable
This commit is contained in:
+1
-3
@@ -3,7 +3,6 @@ package de.twomartens.timetable.bahnApi.mapper
|
|||||||
import de.twomartens.timetable.bahnApi.model.db.BahnStationStop
|
import de.twomartens.timetable.bahnApi.model.db.BahnStationStop
|
||||||
import de.twomartens.timetable.bahnApi.model.db.BahnStopEvent
|
import de.twomartens.timetable.bahnApi.model.db.BahnStopEvent
|
||||||
import de.twomartens.timetable.bahnApi.model.db.BahnTimetable
|
import de.twomartens.timetable.bahnApi.model.db.BahnTimetable
|
||||||
import de.twomartens.timetable.model.common.RouteId
|
|
||||||
import de.twomartens.timetable.model.common.TimetableId
|
import de.twomartens.timetable.model.common.TimetableId
|
||||||
import de.twomartens.timetable.model.common.UserId
|
import de.twomartens.timetable.model.common.UserId
|
||||||
import de.twomartens.timetable.types.HourAtDay
|
import de.twomartens.timetable.types.HourAtDay
|
||||||
@@ -22,12 +21,11 @@ interface BahnTimetableMapper {
|
|||||||
@Mapping(target = "created", ignore = true)
|
@Mapping(target = "created", ignore = true)
|
||||||
@Mapping(target = "lastModified", ignore = true)
|
@Mapping(target = "lastModified", ignore = true)
|
||||||
fun mapToDB(dto: de.twomartens.timetable.bahnApi.model.dto.BahnTimetable,
|
fun mapToDB(dto: de.twomartens.timetable.bahnApi.model.dto.BahnTimetable,
|
||||||
userId: UserId, routeId: RouteId, tswTimetableId: TimetableId,
|
userId: UserId, tswTimetableId: TimetableId,
|
||||||
hourAtDay: HourAtDay,
|
hourAtDay: HourAtDay,
|
||||||
clock: Clock): BahnTimetable {
|
clock: Clock): BahnTimetable {
|
||||||
return BahnTimetable(
|
return BahnTimetable(
|
||||||
userId,
|
userId,
|
||||||
routeId,
|
|
||||||
tswTimetableId,
|
tswTimetableId,
|
||||||
dto.eva,
|
dto.eva,
|
||||||
ZonedDateTime.of(hourAtDay.dateTime, clock.zone),
|
ZonedDateTime.of(hourAtDay.dateTime, clock.zone),
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package de.twomartens.timetable.bahnApi.model
|
package de.twomartens.timetable.bahnApi.model
|
||||||
|
|
||||||
import de.twomartens.timetable.bahnApi.model.db.ScheduledFetchTask
|
import de.twomartens.timetable.bahnApi.model.db.ScheduledFetchTask
|
||||||
import de.twomartens.timetable.model.common.RouteId
|
|
||||||
import de.twomartens.timetable.model.common.TimetableId
|
import de.twomartens.timetable.model.common.TimetableId
|
||||||
import de.twomartens.timetable.model.common.UserId
|
import de.twomartens.timetable.model.common.UserId
|
||||||
import de.twomartens.timetable.types.HourAtDay
|
import de.twomartens.timetable.types.HourAtDay
|
||||||
@@ -21,12 +20,11 @@ class TaskFactory {
|
|||||||
countTasks(existingTasks)
|
countTasks(existingTasks)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createTaskAndUpdateCounter(userId: UserId, routeId: RouteId,
|
fun createTaskAndUpdateCounter(userId: UserId, tswTimetableId: TimetableId,
|
||||||
tswTimetableId: TimetableId, eva: Eva,
|
eva: Eva, hourAtDay: HourAtDay): ScheduledFetchTask {
|
||||||
hourAtDay: HourAtDay): ScheduledFetchTask {
|
|
||||||
val fetchDateTime = calculateNextAvailableFetchDateTime(hourAtDay)
|
val fetchDateTime = calculateNextAvailableFetchDateTime(hourAtDay)
|
||||||
incrementTaskCountForHourAtDay(hourAtDay)
|
incrementTaskCountForHourAtDay(hourAtDay)
|
||||||
return ScheduledFetchTask(userId, routeId, tswTimetableId, eva, hourAtDay, fetchDateTime)
|
return ScheduledFetchTask(userId, tswTimetableId, eva, hourAtDay, fetchDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateNextAvailableFetchDateTime(hourAtDay: HourAtDay): LocalDateTime {
|
private fun calculateNextAvailableFetchDateTime(hourAtDay: HourAtDay): LocalDateTime {
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,6 @@
|
|||||||
package de.twomartens.timetable.bahnApi.model.db
|
package de.twomartens.timetable.bahnApi.model.db
|
||||||
|
|
||||||
import de.twomartens.timetable.bahnApi.model.Eva
|
import de.twomartens.timetable.bahnApi.model.Eva
|
||||||
import de.twomartens.timetable.model.common.RouteId
|
|
||||||
import de.twomartens.timetable.model.common.TimetableId
|
import de.twomartens.timetable.model.common.TimetableId
|
||||||
import de.twomartens.timetable.model.common.UserId
|
import de.twomartens.timetable.model.common.UserId
|
||||||
import de.twomartens.timetable.types.NonEmptyString
|
import de.twomartens.timetable.types.NonEmptyString
|
||||||
@@ -15,11 +14,10 @@ import java.time.Instant
|
|||||||
import java.time.ZonedDateTime
|
import java.time.ZonedDateTime
|
||||||
|
|
||||||
@Document
|
@Document
|
||||||
@CompoundIndex(def = "{'userId': 1, 'routeId': 1, 'tswTimetableId': 1, 'eva': 1, 'hourAtDay': 1}",
|
@CompoundIndex(def = "{'userId': 1, 'tswTimetableId': 1, 'eva': 1, 'hourAtDay': 1}",
|
||||||
unique = true)
|
unique = true)
|
||||||
data class BahnTimetable(
|
data class BahnTimetable(
|
||||||
var userId: UserId,
|
var userId: UserId,
|
||||||
var routeId: RouteId,
|
|
||||||
var tswTimetableId: TimetableId,
|
var tswTimetableId: TimetableId,
|
||||||
var eva: Eva,
|
var eva: Eva,
|
||||||
var hourAtDay: ZonedDateTime,
|
var hourAtDay: ZonedDateTime,
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,6 @@
|
|||||||
package de.twomartens.timetable.bahnApi.model.db
|
package de.twomartens.timetable.bahnApi.model.db
|
||||||
|
|
||||||
import de.twomartens.timetable.bahnApi.model.Eva
|
import de.twomartens.timetable.bahnApi.model.Eva
|
||||||
import de.twomartens.timetable.model.common.RouteId
|
|
||||||
import de.twomartens.timetable.model.common.TimetableId
|
import de.twomartens.timetable.model.common.TimetableId
|
||||||
import de.twomartens.timetable.model.common.UserId
|
import de.twomartens.timetable.model.common.UserId
|
||||||
import de.twomartens.timetable.types.HourAtDay
|
import de.twomartens.timetable.types.HourAtDay
|
||||||
@@ -15,10 +14,9 @@ import java.time.Instant
|
|||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
@Document
|
@Document
|
||||||
@CompoundIndex(def = "{'userId': 1, 'routeId': 1, 'tswTimetableId': 1, 'eva': 1, 'fetchedDateTime': 1}")
|
@CompoundIndex(def = "{'userId': 1, 'tswTimetableId': 1, 'eva': 1, 'fetchedDateTime': 1}")
|
||||||
data class ScheduledFetchTask(
|
data class ScheduledFetchTask(
|
||||||
var userId: UserId,
|
var userId: UserId,
|
||||||
var routeId: RouteId,
|
|
||||||
var tswTimetableId: TimetableId,
|
var tswTimetableId: TimetableId,
|
||||||
var eva: Eva,
|
var eva: Eva,
|
||||||
var fetchedDateTime: HourAtDay,
|
var fetchedDateTime: HourAtDay,
|
||||||
|
|||||||
+2
-4
@@ -6,7 +6,6 @@ import de.twomartens.timetable.bahnApi.model.dto.BahnStation
|
|||||||
import de.twomartens.timetable.bahnApi.model.dto.BahnTimetable
|
import de.twomartens.timetable.bahnApi.model.dto.BahnTimetable
|
||||||
import de.twomartens.timetable.bahnApi.repository.BahnStationRepository
|
import de.twomartens.timetable.bahnApi.repository.BahnStationRepository
|
||||||
import de.twomartens.timetable.bahnApi.repository.BahnTimetableRepository
|
import de.twomartens.timetable.bahnApi.repository.BahnTimetableRepository
|
||||||
import de.twomartens.timetable.model.common.RouteId
|
|
||||||
import de.twomartens.timetable.model.common.TimetableId
|
import de.twomartens.timetable.model.common.TimetableId
|
||||||
import de.twomartens.timetable.model.common.UserId
|
import de.twomartens.timetable.model.common.UserId
|
||||||
import de.twomartens.timetable.model.db.Station
|
import de.twomartens.timetable.model.db.Station
|
||||||
@@ -93,11 +92,10 @@ open class BahnDatabaseService(
|
|||||||
.execute()
|
.execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun storeTimetable(timetable: BahnTimetable, userId: UserId, routeId: RouteId,
|
fun storeTimetable(timetable: BahnTimetable, userId: UserId, tswTimetableId: TimetableId,
|
||||||
tswTimetableId: TimetableId,
|
|
||||||
hourAtDay: HourAtDay) {
|
hourAtDay: HourAtDay) {
|
||||||
val matcher = bahnTimetableRepository.getExampleMatcher()
|
val matcher = bahnTimetableRepository.getExampleMatcher()
|
||||||
val dbTimetable = bahnTimetableMapper.mapToDB(timetable, userId, routeId,
|
val dbTimetable = bahnTimetableMapper.mapToDB(timetable, userId,
|
||||||
tswTimetableId, hourAtDay, clock)
|
tswTimetableId, hourAtDay, clock)
|
||||||
val existingTimetable = bahnTimetableRepository.findOne(Example.of(dbTimetable, matcher))
|
val existingTimetable = bahnTimetableRepository.findOne(Example.of(dbTimetable, matcher))
|
||||||
existingTimetable
|
existingTimetable
|
||||||
|
|||||||
+4
-6
@@ -6,7 +6,6 @@ import de.twomartens.timetable.bahnApi.repository.ScheduledFetchTaskRepository
|
|||||||
import de.twomartens.timetable.bahnApi.tasks.DeleteScheduledTask
|
import de.twomartens.timetable.bahnApi.tasks.DeleteScheduledTask
|
||||||
import de.twomartens.timetable.bahnApi.tasks.FetchTimetableTask
|
import de.twomartens.timetable.bahnApi.tasks.FetchTimetableTask
|
||||||
import de.twomartens.timetable.bahnApi.tasks.StoreTimetableTask
|
import de.twomartens.timetable.bahnApi.tasks.StoreTimetableTask
|
||||||
import de.twomartens.timetable.model.common.RouteId
|
|
||||||
import de.twomartens.timetable.model.common.TimetableId
|
import de.twomartens.timetable.model.common.TimetableId
|
||||||
import de.twomartens.timetable.model.common.UserId
|
import de.twomartens.timetable.model.common.UserId
|
||||||
import de.twomartens.timetable.types.HourAtDay
|
import de.twomartens.timetable.types.HourAtDay
|
||||||
@@ -27,10 +26,9 @@ class FetchTaskScheduler(
|
|||||||
private val bahnDatabaseService: BahnDatabaseService,
|
private val bahnDatabaseService: BahnDatabaseService,
|
||||||
private val scheduledFetchTaskRepository: ScheduledFetchTaskRepository
|
private val scheduledFetchTaskRepository: ScheduledFetchTaskRepository
|
||||||
) {
|
) {
|
||||||
fun scheduleStoreTask(timetable: BahnTimetable, userId: UserId, routeId: RouteId,
|
fun scheduleStoreTask(timetable: BahnTimetable, userId: UserId, tswTimetableId: TimetableId,
|
||||||
tswTimetableId: TimetableId,
|
|
||||||
hourAtDay: HourAtDay) {
|
hourAtDay: HourAtDay) {
|
||||||
val storeTask = StoreTimetableTask(timetable, userId, routeId, tswTimetableId,
|
val storeTask = StoreTimetableTask(timetable, userId, tswTimetableId,
|
||||||
hourAtDay, bahnDatabaseService)
|
hourAtDay, bahnDatabaseService)
|
||||||
threadPoolTaskExecutor.execute(storeTask)
|
threadPoolTaskExecutor.execute(storeTask)
|
||||||
}
|
}
|
||||||
@@ -76,7 +74,7 @@ class FetchTaskScheduler(
|
|||||||
scheduledFetchTask: ScheduledFetchTask,
|
scheduledFetchTask: ScheduledFetchTask,
|
||||||
zonedExecutionTime: ZonedDateTime
|
zonedExecutionTime: ZonedDateTime
|
||||||
) {
|
) {
|
||||||
val deleteTask = DeleteScheduledTask(scheduledFetchTaskRepository, scheduledFetchTask)
|
val deleteTask = DeleteScheduledTask(scheduledFetchTaskRepository, scheduledFetchTask, eventPublisher)
|
||||||
threadPoolTaskScheduler.schedule(deleteTask, zonedExecutionTime.toInstant())
|
threadPoolTaskScheduler.schedule(deleteTask, zonedExecutionTime.toInstant())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +82,7 @@ class FetchTaskScheduler(
|
|||||||
scheduledFetchTask: ScheduledFetchTask,
|
scheduledFetchTask: ScheduledFetchTask,
|
||||||
zonedExecutionTime: ZonedDateTime
|
zonedExecutionTime: ZonedDateTime
|
||||||
) {
|
) {
|
||||||
val timetableTask = FetchTimetableTask(scheduledFetchTask.userId, scheduledFetchTask.routeId,
|
val timetableTask = FetchTimetableTask(scheduledFetchTask.userId,
|
||||||
scheduledFetchTask.tswTimetableId,
|
scheduledFetchTask.tswTimetableId,
|
||||||
scheduledFetchTask.eva, scheduledFetchTask.fetchedDateTime,
|
scheduledFetchTask.eva, scheduledFetchTask.fetchedDateTime,
|
||||||
bahnApiService, this)
|
bahnApiService, this)
|
||||||
|
|||||||
+3
-3
@@ -83,18 +83,18 @@ class ScheduledTaskService(
|
|||||||
val eva = Eva.of(stationId)
|
val eva = Eva.of(stationId)
|
||||||
var hourAtDay = HourAtDay.of(Hour.of(23), fetchDates.previousDay)
|
var hourAtDay = HourAtDay.of(Hour.of(23), fetchDates.previousDay)
|
||||||
var newTask = taskFactory.createTaskAndUpdateCounter(tswRoute.userId,
|
var newTask = taskFactory.createTaskAndUpdateCounter(tswRoute.userId,
|
||||||
tswRoute.routeId, tswTimetableId, eva, hourAtDay)
|
tswTimetableId, eva, hourAtDay)
|
||||||
newTasks.add(newTask)
|
newTasks.add(newTask)
|
||||||
for (hour in 0..23) {
|
for (hour in 0..23) {
|
||||||
hourAtDay = HourAtDay.of(Hour.of(hour), fetchDates.fetchDate)
|
hourAtDay = HourAtDay.of(Hour.of(hour), fetchDates.fetchDate)
|
||||||
newTask = taskFactory.createTaskAndUpdateCounter(tswRoute.userId,
|
newTask = taskFactory.createTaskAndUpdateCounter(tswRoute.userId,
|
||||||
tswRoute.routeId, tswTimetableId, eva, hourAtDay)
|
tswTimetableId, eva, hourAtDay)
|
||||||
newTasks.add(newTask)
|
newTasks.add(newTask)
|
||||||
}
|
}
|
||||||
for (hour in 0..3) {
|
for (hour in 0..3) {
|
||||||
hourAtDay = HourAtDay.of(Hour.of(hour), fetchDates.nextDate)
|
hourAtDay = HourAtDay.of(Hour.of(hour), fetchDates.nextDate)
|
||||||
newTask = taskFactory.createTaskAndUpdateCounter(tswRoute.userId,
|
newTask = taskFactory.createTaskAndUpdateCounter(tswRoute.userId,
|
||||||
tswRoute.routeId, tswTimetableId, eva, hourAtDay)
|
tswTimetableId, eva, hourAtDay)
|
||||||
newTasks.add(newTask)
|
newTasks.add(newTask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -3,7 +3,6 @@ package de.twomartens.timetable.bahnApi.tasks
|
|||||||
import de.twomartens.timetable.bahnApi.model.Eva
|
import de.twomartens.timetable.bahnApi.model.Eva
|
||||||
import de.twomartens.timetable.bahnApi.service.BahnApiService
|
import de.twomartens.timetable.bahnApi.service.BahnApiService
|
||||||
import de.twomartens.timetable.bahnApi.service.FetchTaskScheduler
|
import de.twomartens.timetable.bahnApi.service.FetchTaskScheduler
|
||||||
import de.twomartens.timetable.model.common.RouteId
|
|
||||||
import de.twomartens.timetable.model.common.TimetableId
|
import de.twomartens.timetable.model.common.TimetableId
|
||||||
import de.twomartens.timetable.model.common.UserId
|
import de.twomartens.timetable.model.common.UserId
|
||||||
import de.twomartens.timetable.types.HourAtDay
|
import de.twomartens.timetable.types.HourAtDay
|
||||||
@@ -13,7 +12,6 @@ import org.springframework.scheduling.annotation.Async
|
|||||||
@Async
|
@Async
|
||||||
open class FetchTimetableTask(
|
open class FetchTimetableTask(
|
||||||
private val userId: UserId,
|
private val userId: UserId,
|
||||||
private val routeId: RouteId,
|
|
||||||
private val tswTimetableId: TimetableId,
|
private val tswTimetableId: TimetableId,
|
||||||
private val eva: Eva,
|
private val eva: Eva,
|
||||||
private val hourAtDay: HourAtDay,
|
private val hourAtDay: HourAtDay,
|
||||||
@@ -24,7 +22,7 @@ open class FetchTimetableTask(
|
|||||||
"Fetch timetable: [eva: $eva], [date: ${hourAtDay.date}], [hour: ${hourAtDay.hour}]"
|
"Fetch timetable: [eva: $eva], [date: ${hourAtDay.date}], [hour: ${hourAtDay.hour}]"
|
||||||
}
|
}
|
||||||
val timetable = bahnApiService.fetchTimetable(eva, hourAtDay)
|
val timetable = bahnApiService.fetchTimetable(eva, hourAtDay)
|
||||||
scheduler.scheduleStoreTask(timetable, userId, routeId, tswTimetableId, hourAtDay)
|
scheduler.scheduleStoreTask(timetable, userId, tswTimetableId, hourAtDay)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
+1
-3
@@ -2,7 +2,6 @@ package de.twomartens.timetable.bahnApi.tasks
|
|||||||
|
|
||||||
import de.twomartens.timetable.bahnApi.model.dto.BahnTimetable
|
import de.twomartens.timetable.bahnApi.model.dto.BahnTimetable
|
||||||
import de.twomartens.timetable.bahnApi.service.BahnDatabaseService
|
import de.twomartens.timetable.bahnApi.service.BahnDatabaseService
|
||||||
import de.twomartens.timetable.model.common.RouteId
|
|
||||||
import de.twomartens.timetable.model.common.TimetableId
|
import de.twomartens.timetable.model.common.TimetableId
|
||||||
import de.twomartens.timetable.model.common.UserId
|
import de.twomartens.timetable.model.common.UserId
|
||||||
import de.twomartens.timetable.types.HourAtDay
|
import de.twomartens.timetable.types.HourAtDay
|
||||||
@@ -13,14 +12,13 @@ import org.springframework.scheduling.annotation.Async
|
|||||||
open class StoreTimetableTask(
|
open class StoreTimetableTask(
|
||||||
private val timetable: BahnTimetable,
|
private val timetable: BahnTimetable,
|
||||||
private val userId: UserId,
|
private val userId: UserId,
|
||||||
private val routeId: RouteId,
|
|
||||||
private val tswTimetableId: TimetableId,
|
private val tswTimetableId: TimetableId,
|
||||||
private val hourAtDay: HourAtDay,
|
private val hourAtDay: HourAtDay,
|
||||||
private val bahnDatabaseService: BahnDatabaseService
|
private val bahnDatabaseService: BahnDatabaseService
|
||||||
) : Runnable {
|
) : Runnable {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
log.info { "Store timetable: [eva: ${timetable.eva}], [station: ${timetable.station}], [hour: ${hourAtDay}]" }
|
log.info { "Store timetable: [eva: ${timetable.eva}], [station: ${timetable.station}], [hour: ${hourAtDay}]" }
|
||||||
bahnDatabaseService.storeTimetable(timetable, userId, routeId, tswTimetableId, hourAtDay)
|
bahnDatabaseService.storeTimetable(timetable, userId, tswTimetableId, hourAtDay)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
Reference in New Issue
Block a user