From c4a7f4cc585b3ee06d98aacbc3171c0e5f24a295 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Thu, 20 Feb 2020 13:46:25 +0000 Subject: [PATCH] Changed some data types in Observation and Scenario data classes. Had issues with data submission failing because the data entered was too long. --- .../co/neviyn/observationdatabase/Entity.kt | 45 ++++++++++++++----- .../observationdatabase/RepositoryTest.kt | 14 ++++++ pom.xml | 2 +- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Entity.kt b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Entity.kt index 30757d9..a167c7e 100644 --- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Entity.kt +++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Entity.kt @@ -1,6 +1,7 @@ package uk.co.neviyn.observationdatabase import com.fasterxml.jackson.annotation.JsonIgnore +import org.hibernate.annotations.Type import org.joda.time.LocalDate import javax.persistence.CascadeType import javax.persistence.Column @@ -74,7 +75,7 @@ data class Observation( val date: LocalDate = LocalDate.now(), @Column(nullable = false) val type: TrainingType = TrainingType.INVALID, - @Column(nullable = false) + @Column(nullable = false, length = 500) val observed: String = "UNKNOWN", val monitoring: Double? = null, val controlProcedural: Double? = null, @@ -133,33 +134,57 @@ data class Scenario( @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long = 0, val title: String = "UNKNOWN", - val monitoringRating: Int = -1, + @Type(type = "byte") + val monitoringRating: Byte = -1, + @Type(type = "text") val monitoringStrengths: String = "", + @Type(type = "text") val monitoringImprovements: String = "", - val controlProceduralRating: Int = -1, + @Type(type = "byte") + val controlProceduralRating: Byte = -1, + @Type(type = "text") val controlProceduralStrengths: String = "", + @Type(type = "text") val controlProceduralImprovements: String = "", - val controlRating: Int = -1, + @Type(type = "byte") + val controlRating: Byte = -1, + @Type(type = "text") val controlStrengths: String = "", + @Type(type = "text") val controlImprovements: String = "", - val conservatismRating: Int = -1, + @Type(type = "byte") + val conservatismRating: Byte = -1, + @Type(type = "text") val conservatismStrengths: String = "", + @Type(type = "text") val conservatismImprovements: String = "", - val teamworkCommunicationsRating: Int = -1, + @Type(type = "byte") + val teamworkCommunicationsRating: Byte = -1, + @Type(type = "text") val teamworkCommunicationsStrengths: String = "", + @Type(type = "text") val teamworkCommunicationsImprovements: String = "", - val teamworkLeadershipRating: Int = -1, + @Type(type = "byte") + val teamworkLeadershipRating: Byte = -1, + @Type(type = "text") val teamworkLeadershipStrengths: String = "", + @Type(type = "text") val teamworkLeadershipImprovements: String = "", - val teamworkWorkloadRating: Int = -1, + @Type(type = "byte") + val teamworkWorkloadRating: Byte = -1, + @Type(type = "text") val teamworkWorkloadStrengths: String = "", + @Type(type = "text") val teamworkWorkloadImprovements: String = "", - val knowledgeRating: Int = -1, + @Type(type = "byte") + val knowledgeRating: Byte = -1, + @Type(type = "text") val knowledgeStrengths: String = "", + @Type(type = "text") val knowledgeImprovements: String = "" ) { - private fun ratingValid(rating: Int): Boolean { + private fun ratingValid(rating: Byte): Boolean { return rating in 1..5 } fun ratingsAllValid(): Boolean { diff --git a/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/RepositoryTest.kt b/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/RepositoryTest.kt index 81cdd42..8b60795 100644 --- a/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/RepositoryTest.kt +++ b/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/RepositoryTest.kt @@ -326,4 +326,18 @@ class RepositoryTest { assertEquals(1, result.size) assertEquals(justRight, result.first()) } + + @Test + fun testInsertEntryWithVeryLongText() { + val site = entityManager.persist(Site(name = "X")) + val tutor = entityManager.persist(Tutor(name = "Foo Bar", site = site)) + val person = "Mr X" + val testString = "teststring".repeat(100) + val scenario = entityManager.persist(Scenario(0, "Something", 5, testString, "", 5, "", "", 5, "", "", 5, "", "", 5, "", "", 5, "", "", 5, "", "", 5, "", "")) + val scenarios = listOf(scenario) + val observation = Observation(0, site, LocalDate.now(), TrainingType.INITIAL, "An Observation", 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, scenarios, setOf(tutor), person) + val result = entityManager.persist(observation) + assertEquals(1, result.id) + assertEquals(testString, observation.scenarios.first().monitoringStrengths) + } } diff --git a/pom.xml b/pom.xml index dc4d957..f41a1b5 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ ${project.basedir} - BETA-4 + 2020_02_20