Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GET API for fetching combine target frame #22

Merged
merged 6 commits into from
Dec 14, 2023
Merged

Conversation

Leitsi
Copy link
Contributor

@Leitsi Leitsi commented Dec 4, 2023

This change is Reviewable

@Leitsi Leitsi marked this pull request as ready for review December 13, 2023 08:26
Copy link
Contributor

@jarkkoka jarkkoka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 30 of 30 files at r1, all commit messages.
Reviewable status: all files reviewed, 9 unresolved discussions (waiting on @Leitsi)


src/main/kotlin/fi/hsl/jore4/timetables/api/TimetablesController.kt line 134 at r1 (raw file):

        val targetPriorityEnumResult = runCatching { TimetablesPriority.fromInt(targetPriority) }
        if (targetPriorityEnumResult.isFailure) {

This snippet of code does not look like idiomatic Kotlin.

I really would like to change the implementation of TimetablesPriority.fromInt into this form:

fun fromInt(value: Int): TimetablesPriority? = values().firstOrNull { it.value == value }

Then, you could implement this in a much more elegant way:

val targetPriorityEnum =  
    TimetablesPriority.fromInt(targetPriority)  
        ?: throw TargetPriorityParsingException("Failed to parse target priority", targetPriority)  
  
val targetVehicleScheduleFrame = combineTimetablesService.fetchTargetVehicleScheduleFrame(  
    stagingVehicleScheduleFrameId,  
    targetPriorityEnum  
)

src/main/kotlin/fi/hsl/jore4/timetables/api/util/HasuraErrorExtensions.kt line 19 at r1 (raw file):

    // Not required by Hasura, but we want to always pass one.
    val type: HasuraErrorType

See my comments related to this in another PR.


src/main/kotlin/fi/hsl/jore4/timetables/api/util/HasuraErrorType.kt line 3 at r1 (raw file):

package fi.hsl.jore4.timetables.api.util

enum class HasuraErrorType {

See my comments related to the name of this enum class in another PR.


src/test/kotlin/fi/hsl/jore4/timetables/api/TimetablesToCombineApiTest.kt line 41 at r1 (raw file):

    )
    private val defaultToCombineTargetId = defaultTargetFrame.vehicleScheduleFrameId
    private fun executeToCombineTimetablesRequest(

Please add line break before a function definition.


src/test/kotlin/fi/hsl/jore4/timetables/api/TimetablesToCombineApiTest.kt line 61 at r1 (raw file):

            combineTimetablesService.fetchTargetVehicleScheduleFrame(
                stagingVehicleScheduleFrameId,
                TimetablesPriority.fromInt(targetPriority)

Be explicit here:

TimetablesPriority.TEMPORARY

src/test/kotlin/fi/hsl/jore4/timetables/api/TimetablesToCombineApiTest.kt line 65 at r1 (raw file):

        } answers { defaultTargetFrame }

        executeToCombineTimetablesRequest(stagingVehicleScheduleFrameId, targetPriority)

You could add this line to the beginning of the method:

val targetPriority = TimetablesPriority.TEMPORARY

Then you reference the int value here by:

targetPriority.value

It really is unnecessary to test parsing done in TimetablesPriority.fromInt here.


src/test/kotlin/fi/hsl/jore4/timetables/api/TimetablesToCombineApiTest.kt line 82 at r1 (raw file):

            combineTimetablesService.fetchTargetVehicleScheduleFrame(
                stagingVehicleScheduleFrameId,
                TimetablesPriority.fromInt(targetPriority)

Be explicit here:

TimetablesPriority.TEMPORARY

src/test/kotlin/fi/hsl/jore4/timetables/api/util/TransactionSystemExtensionsTest.kt line 10 at r1 (raw file):

    private fun createTransactionSystemExceptionWithCause(message: String): TransactionSystemException {
        return TransactionSystemException("test exception", Exception(message))

The method body could be simplified to expression form:

private fun createTransactionSystemExceptionWithCause(message: String) =  
    TransactionSystemException("test exception", Exception(message))

No need to duplicate the return type.


src/test/kotlin/fi/hsl/jore4/timetables/service/CombineTimetablesServiceTest.kt line 366 at r1 (raw file):

            val causeMessage = exception?.cause?.message
            assertNotNull(causeMessage)
            assertContains(causeMessage, "ERROR: conflicting schedules detected: vehicle schedule frame")

My current favourite to write this is:

assertFailsWith<TransactionSystemException> {  
    combineTimetablesService.combineTimetables(  
        listOf(stagingFrameId),  
        TimetablesPriority.STANDARD  
    )  
}.also { exception ->  
    // Check that the error messages are somewhat in the format we expect. TransactionSystemExtensions depends on these.  
    assertEquals(exception.message, "JDBC commit failed")  
  
    val causeMessage = exception.cause?.message  
    assertNotNull(causeMessage)  
    assertContains(causeMessage, "ERROR: conflicting schedules detected: vehicle schedule frame")  
    assertContains(causeMessage, "Where: PL/pgSQL function vehicle_schedule.validate_queued_schedules_uniqueness()")  
    assertContains(causeMessage, "SQL statement \"SELECT vehicle_schedule.validate_queued_schedules_uniqueness()")  
}

We won't be preventing these after all.
Current plan is to instead show a warning to the user in the UI.

See HSLdevcom/jore4#1566
Similar to the /to-replace API (from which this is largely copypasted)
that already existed for /replace.
These were accidentally left out from a previous PR,
where the relevant commit was.
Copy link
Contributor Author

@Leitsi Leitsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 9 unresolved discussions (waiting on @jarkkoka)


src/main/kotlin/fi/hsl/jore4/timetables/api/TimetablesController.kt line 134 at r1 (raw file):

Previously, jarkkoka (Jarkko Kaura) wrote…

This snippet of code does not look like idiomatic Kotlin.

I really would like to change the implementation of TimetablesPriority.fromInt into this form:

fun fromInt(value: Int): TimetablesPriority? = values().firstOrNull { it.value == value }

Then, you could implement this in a much more elegant way:

val targetPriorityEnum =  
    TimetablesPriority.fromInt(targetPriority)  
        ?: throw TargetPriorityParsingException("Failed to parse target priority", targetPriority)  
  
val targetVehicleScheduleFrame = combineTimetablesService.fetchTargetVehicleScheduleFrame(  
    stagingVehicleScheduleFrameId,  
    targetPriorityEnum  
)

Done.


src/test/kotlin/fi/hsl/jore4/timetables/api/TimetablesToCombineApiTest.kt line 65 at r1 (raw file):

Previously, jarkkoka (Jarkko Kaura) wrote…

You could add this line to the beginning of the method:

val targetPriority = TimetablesPriority.TEMPORARY

Then you reference the int value here by:

targetPriority.value

It really is unnecessary to test parsing done in TimetablesPriority.fromInt here.

Done.


src/test/kotlin/fi/hsl/jore4/timetables/service/CombineTimetablesServiceTest.kt line 366 at r1 (raw file):

Previously, jarkkoka (Jarkko Kaura) wrote…

My current favourite to write this is:

assertFailsWith<TransactionSystemException> {  
    combineTimetablesService.combineTimetables(  
        listOf(stagingFrameId),  
        TimetablesPriority.STANDARD  
    )  
}.also { exception ->  
    // Check that the error messages are somewhat in the format we expect. TransactionSystemExtensions depends on these.  
    assertEquals(exception.message, "JDBC commit failed")  
  
    val causeMessage = exception.cause?.message  
    assertNotNull(causeMessage)  
    assertContains(causeMessage, "ERROR: conflicting schedules detected: vehicle schedule frame")  
    assertContains(causeMessage, "Where: PL/pgSQL function vehicle_schedule.validate_queued_schedules_uniqueness()")  
    assertContains(causeMessage, "SQL statement \"SELECT vehicle_schedule.validate_queued_schedules_uniqueness()")  
}

Done.

@Leitsi Leitsi force-pushed the combine-target-api branch from 570735f to fab81b4 Compare December 14, 2023 10:42
Copy link
Contributor

@jarkkoka jarkkoka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 27 of 27 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Leitsi)


src/main/kotlin/fi/hsl/jore4/timetables/api/TimetablesController.kt line 55 at r2 (raw file):

    )

    private fun parseTargetPriority(targetPriority: Int) = TimetablesPriority.fromInt(targetPriority)

Since this method is essentially stateless (static) it should be located in a companion object.

@Leitsi Leitsi force-pushed the combine-target-api branch from fab81b4 to a454026 Compare December 14, 2023 11:53
Copy link
Contributor Author

@Leitsi Leitsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 30 of 31 files reviewed, 1 unresolved discussion (waiting on @jarkkoka)


src/main/kotlin/fi/hsl/jore4/timetables/api/TimetablesController.kt line 55 at r2 (raw file):

Previously, jarkkoka (Jarkko Kaura) wrote…

Since this method is essentially stateless (static) it should be located in a companion object.

Done.

Copy link
Contributor

@jarkkoka jarkkoka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Leitsi)

@Leitsi Leitsi merged commit daee5f9 into main Dec 14, 2023
8 checks passed
@Leitsi Leitsi deleted the combine-target-api branch December 14, 2023 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants