diff --git a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Api.kt b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Api.kt index 2396d09..f919c1c 100644 --- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Api.kt +++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Api.kt @@ -20,10 +20,9 @@ data class NewObservation( val site: Long, val type: TrainingType, val observed: String, - val whom: String, - val entries: List, + val scenarios: List, val tutors: List, - val persons: List + val person: String ) data class ObservationsRequest( diff --git a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt index a51f41a..8936894 100644 --- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt +++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt @@ -82,29 +82,22 @@ class Controller { val tutors = tutorRepository.findAllById(newObservation.tutors).toSet() if (!site.isPresent) return null if (tutors.isEmpty() || tutors.size != newObservation.tutors.size) return null - val overallScores = newObservation.entries.asSequence().groupBy { it.type } - .map { entry -> entry.key to entry.value.asSequence().mapNotNull { it.rating }.average() } - .map { it.first to if (it.second > 0) it.second else null }.toList() - .toMap() var observation = Observation( site = site.get(), date = LocalDate.now(), type = newObservation.type, - observed = newObservation.observed, - whom = newObservation.whom, - monitoring = overallScores[RatingCategory.MONITORING], - conservatism = overallScores[RatingCategory.CONSERVATISM], - controlProcedural = overallScores[RatingCategory.CONTROL_PROCEDURAL], - control = overallScores[RatingCategory.CONTROL], - teamworkCommunications = overallScores[RatingCategory.TEAMWORK_COMMUNICATIONS], - teamworkLeadership = overallScores[RatingCategory.TEAMWORK_LEADERSHIP], - teamworkWorkload = overallScores[RatingCategory.TEAMWORK_WORKLOAD], - knowledge = overallScores[RatingCategory.KNOWLEDGE], - entries = newObservation.entries, + observed = newObservation.scenarios.joinToString { it.title }, + monitoring = newObservation.scenarios.map { it.monitoring.rating }.average(), + conservatism = newObservation.scenarios.map { it.conservatism.rating }.average(), + controlProcedural = newObservation.scenarios.map { it.controlProcedural.rating }.average(), + control = newObservation.scenarios.map { it.control.rating }.average(), + teamworkCommunications = newObservation.scenarios.map { it.teamworkCommunications.rating }.average(), + teamworkLeadership = newObservation.scenarios.map { it.teamworkLeadership.rating }.average(), + teamworkWorkload = newObservation.scenarios.map { it.teamworkWorkload.rating }.average(), + knowledge = newObservation.scenarios.map { it.knowledge.rating }.average(), + scenarios = newObservation.scenarios, tutors = tutors, - persons = newObservation.persons.asSequence().map { - personRepository.findFirstByNameLike(it.toUpperCase()) ?: personRepository.save(Person(name = it.toUpperCase())) - }.toSet() + person = personRepository.findFirstByNameLike(newObservation.person.toUpperCase()) ?: personRepository.save(Person(name = newObservation.person.toUpperCase())) ) observation = observationRepository.save(observation) tutors.forEach { @@ -122,34 +115,19 @@ class Controller { fun getObservations(@Valid @RequestBody observationsRequest: ObservationsRequest): List { if (observationsRequest.tutor != null) { return tutorRepository.findById(observationsRequest.tutor).map { - when { - (observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findByTutorsAndDateBetweenOrderByDateAsc(tutor = it, + observationRepository.findByTutorsAndDateBetweenOrderByDateAsc(tutor = it, startDate = observationsRequest.startDate, endDate = observationsRequest.endDate) - else -> observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(tutor = it, - whom = observationsRequest.whom, - startDate = observationsRequest.startDate, - endDate = observationsRequest.endDate) - } }.orElse(listOf()) } else if (observationsRequest.person != null && observationsRequest.person.isNotEmpty() && observationsRequest.site != null) { val person = personRepository.findFirstByNameLike(observationsRequest.person.toUpperCase()) ?: return listOf() val site = siteRepository.findById(observationsRequest.site).get() - return if (observationsRequest.whom == null || observationsRequest.whom.isEmpty()) - observationRepository.findBySiteAndPersonsAndDateBetweenOrderByDateAsc(site, person, observationsRequest.startDate, observationsRequest.endDate) - else - observationRepository.findBySiteAndWhomIgnoreCaseAndPersonsAndDateBetweenOrderByDateAsc(site, observationsRequest.whom, person, observationsRequest.startDate, observationsRequest.endDate) + return observationRepository.findBySiteAndPersonAndDateBetweenOrderByDateAsc(site, person, observationsRequest.startDate, observationsRequest.endDate) } else if (observationsRequest.site != null) { return siteRepository.findById(observationsRequest.site).map { - when { - (observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findBySiteAndDateBetweenOrderByDateAsc(site = it, + observationRepository.findBySiteAndDateBetweenOrderByDateAsc(site = it, startDate = observationsRequest.startDate, endDate = observationsRequest.endDate) - else -> observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(site = it, - whom = observationsRequest.whom, - startDate = observationsRequest.startDate, - endDate = observationsRequest.endDate) - } }.orElse(listOf()) } return listOf() 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 bffe1fc..cb34340 100644 --- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Entity.kt +++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Entity.kt @@ -3,9 +3,8 @@ package uk.co.neviyn.observationdatabase import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonProperty import org.joda.time.LocalDate +import javax.persistence.CascadeType import javax.persistence.Column -import javax.persistence.ElementCollection -import javax.persistence.Embeddable import javax.persistence.Entity import javax.persistence.FetchType import javax.persistence.GeneratedValue @@ -17,6 +16,7 @@ import javax.persistence.JoinTable import javax.persistence.ManyToMany import javax.persistence.ManyToOne import javax.persistence.OneToMany +import javax.persistence.OneToOne import javax.persistence.Table import kotlin.math.round @@ -59,10 +59,6 @@ enum class TrainingType { INITIAL, CONTINUING } -enum class RatingCategory { - MONITORING, CONTROL_PROCEDURAL, CONTROL, CONSERVATISM, TEAMWORK_COMMUNICATIONS, TEAMWORK_LEADERSHIP, TEAMWORK_WORKLOAD, KNOWLEDGE -} - /** * Data record for a training observation. */ @@ -81,8 +77,6 @@ data class Observation( val type: TrainingType, @Column(nullable = false) val observed: String, - @Column(nullable = false) - val whom: String, val monitoring: Double?, val controlProcedural: Double?, val control: Double?, @@ -91,33 +85,25 @@ data class Observation( val teamworkLeadership: Double?, val teamworkWorkload: Double?, val knowledge: Double?, - @ElementCollection - val entries: List, + @OneToMany(cascade = [CascadeType.ALL]) + val scenarios: List, @ManyToMany(mappedBy = "observations") val tutors: Set, - @ManyToMany - val persons: Set + @ManyToOne + val person: Person ) { fun toCsvFormat(): String { - return ",,\"${tutors.joinToString { it.name }}\",$date,\"$observed\",\"Training\",\"Performance Improvement - Training\",\"${site.name}\",\"N/A\"," + + return ",,\"${tutors.joinToString { it.name }}\",$date,\"${scenarios.joinToString { it.title }}\",\"Training\",\"Performance Improvement - Training\",\"${site.name}\",\"N/A\"," + "${roundScore(monitoring)},${roundScore(controlProcedural)},${roundScore(control)}," + "${roundScore(conservatism)},${roundScore(teamworkCommunications)},${roundScore(teamworkLeadership)}," + - "${roundScore(teamworkWorkload)},${roundScore(knowledge)},\"${getStrengths(RatingCategory.MONITORING)}\"," + - "\"${getStrengths(RatingCategory.CONTROL_PROCEDURAL)}\",\"${getStrengths(RatingCategory.CONTROL)}\",\"${getStrengths(RatingCategory.CONSERVATISM)}\"," + - "\"${getStrengths(RatingCategory.TEAMWORK_COMMUNICATIONS)}\",\"${getStrengths(RatingCategory.TEAMWORK_LEADERSHIP)}\"," + - "\"${getStrengths(RatingCategory.TEAMWORK_WORKLOAD)}\",\"${getStrengths(RatingCategory.KNOWLEDGE)}\"," + - "\"${getImprovements(RatingCategory.MONITORING)}\",\"${getImprovements(RatingCategory.CONTROL_PROCEDURAL)}\"," + - "\"${getImprovements(RatingCategory.CONTROL)}\",\"${getImprovements(RatingCategory.CONSERVATISM)}\"," + - "\"${getImprovements(RatingCategory.TEAMWORK_COMMUNICATIONS)}\",\"${getImprovements(RatingCategory.TEAMWORK_LEADERSHIP)}\"," + - "\"${getImprovements(RatingCategory.TEAMWORK_WORKLOAD)}\",\"${getImprovements(RatingCategory.KNOWLEDGE)}\"" - } - - private fun getStrengths(category: RatingCategory): String { - return entries.asSequence().filter { it.type == category && it.strengths.isNotBlank() }.map { it.strengths }.joinToString() - } - - private fun getImprovements(category: RatingCategory): String { - return entries.asSequence().filter { it.type == category && it.improvements.isNotBlank() }.map { it.improvements }.joinToString() + "${roundScore(teamworkWorkload)},${roundScore(knowledge)},\"${scenarios.joinToString { it.monitoring.strengths }}\"," + + "\"${scenarios.joinToString { it.controlProcedural.strengths }}\",\"${scenarios.joinToString { it.control.strengths }}\",\"${scenarios.joinToString { it.conservatism.strengths }}\"," + + "\"${scenarios.joinToString { it.teamworkCommunications.strengths }}\",\"${scenarios.joinToString { it.teamworkLeadership.strengths }}\"," + + "\"${scenarios.joinToString { it.teamworkWorkload.strengths }}\",\"${scenarios.joinToString { it.knowledge.strengths }}\"," + + "\"${scenarios.joinToString { it.monitoring.improvements }}\",\"${scenarios.joinToString { it.controlProcedural.improvements }}\"," + + "\"${scenarios.joinToString { it.control.improvements }}\",\"${scenarios.joinToString { it.conservatism.improvements }}\"," + + "\"${scenarios.joinToString { it.teamworkCommunications.improvements }}\",\"${scenarios.joinToString { it.teamworkLeadership.improvements }}\"," + + "\"${scenarios.joinToString { it.teamworkWorkload.improvements }}\",\"${scenarios.joinToString { it.knowledge.improvements }}\"" } private fun roundScore(input: Double?): String { @@ -128,25 +114,41 @@ data class Observation( } } -/** - * Entry giving specific details on observation performance for a tutor defined constraint. - */ -@Embeddable -data class Entry( - @Column(nullable = false) - @JsonProperty - val type: RatingCategory, - @Column(nullable = false) - @JsonProperty +@Entity +data class RatingComponent( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long = 0, val rating: Int, - @Column(nullable = false, columnDefinition = "TEXT") - @JsonProperty val strengths: String, - @Column(nullable = false, columnDefinition = "TEXT") - @JsonProperty val improvements: String ) +@Entity +data class Scenario( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long = 0, + val title: String, + @OneToOne(cascade = [CascadeType.ALL]) + val monitoring: RatingComponent, + @OneToOne(cascade = [CascadeType.ALL]) + val controlProcedural: RatingComponent, + @OneToOne(cascade = [CascadeType.ALL]) + val control: RatingComponent, + @OneToOne(cascade = [CascadeType.ALL]) + val conservatism: RatingComponent, + @OneToOne(cascade = [CascadeType.ALL]) + val teamworkCommunications: RatingComponent, + @OneToOne(cascade = [CascadeType.ALL]) + val teamworkLeadership: RatingComponent, + @OneToOne(cascade = [CascadeType.ALL]) + val teamworkWorkload: RatingComponent, + @OneToOne(cascade = [CascadeType.ALL]) + val knowledge: RatingComponent + +) + @Entity data class Person( @Id diff --git a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Repository.kt b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Repository.kt index b1fc041..0d27186 100644 --- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Repository.kt +++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Repository.kt @@ -17,13 +17,7 @@ interface ObservationRepository : CrudRepository { fun findByTutorsAndDateBetweenOrderByDateAsc(tutor: Tutor, startDate: LocalDate, endDate: LocalDate): List - fun findBySiteAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(site: Site, whom: String, startDate: LocalDate, endDate: LocalDate): List - - fun findByTutorsAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(tutor: Tutor, whom: String, startDate: LocalDate, endDate: LocalDate): List - - fun findBySiteAndPersonsAndDateBetweenOrderByDateAsc(site: Site, person: Person, startDate: LocalDate, endDate: LocalDate): List - - fun findBySiteAndWhomIgnoreCaseAndPersonsAndDateBetweenOrderByDateAsc(site: Site, whom: String, person: Person, startDate: LocalDate, endDate: LocalDate): List + fun findBySiteAndPersonAndDateBetweenOrderByDateAsc(site: Site, person: Person, startDate: LocalDate, endDate: LocalDate): List } @Repository diff --git a/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/ControllerTest.kt b/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/ControllerTest.kt index 00c7cd0..d20a4a5 100644 --- a/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/ControllerTest.kt +++ b/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/ControllerTest.kt @@ -93,10 +93,13 @@ class ControllerTest { fun testAddObservation() { val site = Site(1, "X") val tutor = Tutor(1, "Foo Bar", site) + val person = Person(name = "Mr X") doReturn(Optional.of(site)).`when`(siteRepository).findById(1) doReturn(listOf(tutor)).`when`(tutorRepository).findAllById(listOf(1)) - val newData = NewObservation(1, TrainingType.INITIAL, "An Observation", "Group A", listOf(Entry(RatingCategory.MONITORING, 5, "", "")), listOf(1), listOf()) - val observation = Observation(1, site, LocalDate.now(), TrainingType.INITIAL, "An Observation", "Group A", 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, newData.entries, setOf(tutor), setOf()) + doReturn(person).`when`(personRepository).findFirstByNameLike("MR X") + val defaultComponent = RatingComponent(rating = 5, strengths = "", improvements = "") + val newData = NewObservation(1, TrainingType.INITIAL, "An Observation", listOf(Scenario(title = "Something", monitoring = defaultComponent, controlProcedural = defaultComponent, control = defaultComponent, conservatism = defaultComponent, teamworkCommunications = defaultComponent, teamworkLeadership = defaultComponent, teamworkWorkload = defaultComponent, knowledge = defaultComponent)), listOf(1), "Mr X") + val observation = Observation(1, site, LocalDate.now(), TrainingType.INITIAL, "An Observation", 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, newData.scenarios, setOf(tutor), person) doReturn(observation).`when`(observationRepository).save(ArgumentMatchers.any()) val result = controller.addObservation(newData) assertEquals(1L, result) @@ -110,13 +113,13 @@ class ControllerTest { } @Test - fun testGetObservations_WithSite_TutorNull_NoWhom() { + fun testGetObservations_WithSite_TutorNull() { val request = ObservationsRequest(1, null, "", "", LocalDate.now(), LocalDate.now()) val site = Site(1, "Area 51") val observation = Observation(site = site, date = LocalDate.now(), - type = TrainingType.INITIAL, observed = "1", whom = "G1", monitoring = 5.0, controlProcedural = 3.0, + type = TrainingType.INITIAL, observed = "1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0, - teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(), persons = setOf()) + teamworkWorkload = 1.0, knowledge = 1.0, scenarios = listOf(), tutors = setOf(), person = Person(name = "noone")) doReturn(Optional.of(site)).`when`(siteRepository).findById(1) doReturn(listOf(observation)) .`when`(observationRepository).findBySiteAndDateBetweenOrderByDateAsc(site, LocalDate.now(), LocalDate.now()) @@ -126,30 +129,14 @@ class ControllerTest { } @Test - fun testGetObservations_WithSite_TutorNull_WithWhom() { - val request = ObservationsRequest(1, null, "Group A", "", LocalDate.now(), LocalDate.now()) - val site = Site(1, "Area 51") - val observation = Observation(site = site, date = LocalDate.now(), - type = TrainingType.INITIAL, observed = "1", whom = "Group A", monitoring = 5.0, controlProcedural = 3.0, - control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0, - teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(), persons = setOf()) - doReturn(Optional.of(site)).`when`(siteRepository).findById(1) - doReturn(listOf(observation)) - .`when`(observationRepository).findBySiteAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(site, "Group A", LocalDate.now(), LocalDate.now()) - val result = controller.getObservations(request) - assertEquals(1, result.size) - assertEquals(observation, result[0]) - } - - @Test - fun testGetObservations_WithSite_WithTutor_NoWhom() { + fun testGetObservations_WithSite_WithTutor() { val request = ObservationsRequest(null, 1, "", "", LocalDate.now(), LocalDate.now()) val site = Site(1, "Area 51") val tutor = Tutor(1, "Mr Unknown", site) val observation = Observation(site = site, date = LocalDate.now(), - type = TrainingType.INITIAL, observed = "1", whom = "G1", monitoring = 5.0, controlProcedural = 3.0, + type = TrainingType.INITIAL, observed = "1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0, - teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor), persons = setOf()) + teamworkWorkload = 1.0, knowledge = 1.0, scenarios = listOf(), tutors = setOf(tutor), person = Person(name = "noone")) doReturn(Optional.of(tutor)).`when`(tutorRepository).findById(1) doReturn(listOf(observation)) .`when`(observationRepository).findByTutorsAndDateBetweenOrderByDateAsc(tutor, LocalDate.now(), LocalDate.now()) @@ -158,23 +145,6 @@ class ControllerTest { assertEquals(observation, result[0]) } - @Test - fun testGetObservations_WithSite_WithTutor_WithWhom() { - val request = ObservationsRequest(null, 1, "Group A", "", LocalDate.now(), LocalDate.now()) - val site = Site(1, "Area 51") - val tutor = Tutor(1, "Mr Unknown", site) - val observation = Observation(site = site, date = LocalDate.now(), - type = TrainingType.INITIAL, observed = "1", whom = "Group A", monitoring = 5.0, controlProcedural = 3.0, - control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0, - teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor), persons = setOf()) - doReturn(Optional.of(tutor)).`when`(tutorRepository).findById(1) - doReturn(listOf(observation)) - .`when`(observationRepository).findByTutorsAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(tutor, "Group A", LocalDate.now(), LocalDate.now()) - val result = controller.getObservations(request) - assertEquals(1, result.size) - assertEquals(observation, result[0]) - } - @Test fun testGetObservations_WithPerson() { val request = ObservationsRequest(1, null, null, "Foo Bar", LocalDate.now(), LocalDate.now()) @@ -182,12 +152,12 @@ class ControllerTest { val tutor = Tutor(1, "Mr Unknown", site) val person = Person(1, "Foo Bar") val observation = Observation(site = site, date = LocalDate.now(), - type = TrainingType.INITIAL, observed = "1", whom = "Group A", monitoring = 5.0, controlProcedural = 3.0, + type = TrainingType.INITIAL, observed = "1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0, - teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor), persons = setOf(person)) + teamworkWorkload = 1.0, knowledge = 1.0, scenarios = listOf(), tutors = setOf(tutor), person = person) doReturn(Optional.of(site)).`when`(siteRepository).findById(1) doReturn(person).`when`(personRepository).findFirstByNameLike("FOO BAR") - doReturn(listOf(observation)).`when`(observationRepository).findBySiteAndPersonsAndDateBetweenOrderByDateAsc(site, person, LocalDate.now(), LocalDate.now()) + doReturn(listOf(observation)).`when`(observationRepository).findBySiteAndPersonAndDateBetweenOrderByDateAsc(site, person, LocalDate.now(), LocalDate.now()) val result = controller.getObservations(request) assertEquals(1, result.size) assertEquals(observation, result[0]) 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 9d2d85e..cd236db 100644 --- a/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/RepositoryTest.kt +++ b/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/RepositoryTest.kt @@ -31,15 +31,6 @@ class RepositoryTest { assertTrue(result.isEmpty()) } - @Test - fun testFindBySiteAndWhomIgnoreCaseAndDateBetween_EmptyRepository() { - val result = observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(Site( - id = 1, - name = "x" - ), "none", LocalDate.now(), LocalDate.now()) - assertTrue(result.isEmpty()) - } - @Test fun testFindByTutorsAndDateBetween_EmptyRepository() { val result = observationRepository.findByTutorsAndDateBetweenOrderByDateAsc(Tutor( @@ -50,16 +41,6 @@ class RepositoryTest { assertTrue(result.isEmpty()) } - @Test - fun testFindByTutorsAndWhomIgnoreCaseAndDateBetween_EmptyRepository() { - val result = observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(Tutor( - id = 1, - name = "x", - site = Site(1, "x") - ), "none", LocalDate.now(), LocalDate.now()) - assertTrue(result.isEmpty()) - } - @Test fun testFindBySiteAndDateBetween() { val correctSite = entityManager.persist(Site(name = "Correct")) @@ -72,7 +53,6 @@ class RepositoryTest { date = LocalDate.now().minusDays(5), type = TrainingType.INITIAL, observed = "1", - whom = "G1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, @@ -81,16 +61,15 @@ class RepositoryTest { teamworkLeadership = 3.0, teamworkWorkload = 1.0, knowledge = 1.0, - entries = listOf(), + scenarios = listOf(), tutors = setOf(tutor), - persons = setOf(person) + person = person ) val tooLate = Observation( site = correctSite, date = LocalDate.now().plusDays(5), type = TrainingType.INITIAL, observed = "1", - whom = "G1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, @@ -99,16 +78,15 @@ class RepositoryTest { teamworkLeadership = 3.0, teamworkWorkload = 1.0, knowledge = 1.0, - entries = listOf(), + scenarios = listOf(), tutors = setOf(tutor), - persons = setOf(person) + person = person ) val wrongSite = Observation( site = incorrectSite, date = LocalDate.now(), type = TrainingType.INITIAL, observed = "1", - whom = "G1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, @@ -117,16 +95,15 @@ class RepositoryTest { teamworkLeadership = 3.0, teamworkWorkload = 1.0, knowledge = 1.0, - entries = listOf(), + scenarios = listOf(), tutors = setOf(tutor2), - persons = setOf(person) + person = person ) val justRight = Observation( site = correctSite, date = LocalDate.now(), type = TrainingType.INITIAL, observed = "1", - whom = "G1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, @@ -135,9 +112,9 @@ class RepositoryTest { teamworkLeadership = 3.0, teamworkWorkload = 1.0, knowledge = 1.0, - entries = listOf(), + scenarios = listOf(), tutors = setOf(tutor), - persons = setOf(person) + person = person ) entityManager.persist(tooEarly) entityManager.persist(tooLate) @@ -152,118 +129,6 @@ class RepositoryTest { assertEquals(justRight, result.first()) } - @Test - fun testFindBySiteAndWhomIgnoreCaseAndDateBetween() { - val correctSite = entityManager.persist(Site(name = "Correct")) - val incorrectSite = entityManager.persist(Site(name = "Incorrect")) - val person = entityManager.persist(Person(name = "Foo Bar")) - val tutor = entityManager.persist(Tutor(name = "X", site = correctSite)) - val tutor2 = entityManager.persist(Tutor(name = "N", site = incorrectSite)) - val tooEarly = Observation( - site = correctSite, - date = LocalDate.now().minusDays(5), - type = TrainingType.INITIAL, - observed = "1", - whom = "G1", - monitoring = 5.0, - controlProcedural = 3.0, - control = 4.0, - conservatism = 3.0, - teamworkCommunications = 2.0, - teamworkLeadership = 3.0, - teamworkWorkload = 1.0, - knowledge = 1.0, - entries = listOf(), - tutors = setOf(tutor), - persons = setOf(person) - ) - val tooLate = Observation( - site = correctSite, - date = LocalDate.now().plusDays(5), - type = TrainingType.INITIAL, - observed = "1", - whom = "G1", - monitoring = 5.0, - controlProcedural = 3.0, - control = 4.0, - conservatism = 3.0, - teamworkCommunications = 2.0, - teamworkLeadership = 3.0, - teamworkWorkload = 1.0, - knowledge = 1.0, - entries = listOf(), - tutors = setOf(tutor), - persons = setOf(person) - ) - val wrongSite = Observation( - site = incorrectSite, - date = LocalDate.now(), - type = TrainingType.INITIAL, - observed = "1", - whom = "G1", - monitoring = 5.0, - controlProcedural = 3.0, - control = 4.0, - conservatism = 3.0, - teamworkCommunications = 2.0, - teamworkLeadership = 3.0, - teamworkWorkload = 1.0, - knowledge = 1.0, - entries = listOf(), - tutors = setOf(tutor2), - persons = setOf(person) - ) - val justRight = Observation( - site = correctSite, - date = LocalDate.now(), - type = TrainingType.INITIAL, - observed = "1", - whom = "G1", - monitoring = 5.0, - controlProcedural = 3.0, - control = 4.0, - conservatism = 3.0, - teamworkCommunications = 2.0, - teamworkLeadership = 3.0, - teamworkWorkload = 1.0, - knowledge = 1.0, - entries = listOf(), - tutors = setOf(tutor), - persons = setOf(person) - ) - val wrongWhom = Observation( - site = correctSite, - date = LocalDate.now(), - type = TrainingType.INITIAL, - observed = "1", - whom = "G2", - monitoring = 5.0, - controlProcedural = 3.0, - control = 4.0, - conservatism = 3.0, - teamworkCommunications = 2.0, - teamworkLeadership = 3.0, - teamworkWorkload = 1.0, - knowledge = 1.0, - entries = listOf(), - tutors = setOf(tutor), - persons = setOf(person) - ) - entityManager.persist(tooEarly) - entityManager.persist(tooLate) - entityManager.persist(wrongSite) - entityManager.persist(justRight) - entityManager.persist(wrongWhom) - val result = observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc( - site = correctSite, - startDate = LocalDate.now().minusDays(1), - endDate = LocalDate.now().plusDays(1), - whom = "G1" - ) - assertEquals(1, result.size) - assertEquals(justRight, result.first()) - } - @Test fun testFindByTutorsAndDateBetween() { val site = entityManager.persist(Site(name = "Correct")) @@ -275,7 +140,6 @@ class RepositoryTest { date = LocalDate.now().minusDays(5), type = TrainingType.INITIAL, observed = "1", - whom = "G1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, @@ -284,16 +148,15 @@ class RepositoryTest { teamworkLeadership = 3.0, teamworkWorkload = 1.0, knowledge = 1.0, - entries = listOf(), + scenarios = listOf(), tutors = setOf(correctTutor), - persons = setOf(person) + person = person ) val tooLate = Observation( site = site, date = LocalDate.now().plusDays(5), type = TrainingType.INITIAL, observed = "1", - whom = "G1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, @@ -302,16 +165,15 @@ class RepositoryTest { teamworkLeadership = 3.0, teamworkWorkload = 1.0, knowledge = 1.0, - entries = listOf(), + scenarios = listOf(), tutors = setOf(correctTutor), - persons = setOf(person) + person = person ) val wrongTutor = Observation( site = site, date = LocalDate.now(), type = TrainingType.INITIAL, observed = "1", - whom = "G1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, @@ -320,16 +182,15 @@ class RepositoryTest { teamworkLeadership = 3.0, teamworkWorkload = 1.0, knowledge = 1.0, - entries = listOf(), + scenarios = listOf(), tutors = setOf(incorrectTutor), - persons = setOf(person) + person = person ) val justRight = Observation( site = site, date = LocalDate.now(), type = TrainingType.INITIAL, observed = "1", - whom = "G1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, @@ -338,16 +199,15 @@ class RepositoryTest { teamworkLeadership = 3.0, teamworkWorkload = 1.0, knowledge = 1.0, - entries = listOf(), + scenarios = listOf(), tutors = setOf(correctTutor), - persons = setOf(person) + person = person ) val justRightMultipleTutors = Observation( site = site, date = LocalDate.now(), type = TrainingType.INITIAL, observed = "1", - whom = "G1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, @@ -356,9 +216,9 @@ class RepositoryTest { teamworkLeadership = 3.0, teamworkWorkload = 1.0, knowledge = 1.0, - entries = listOf(), + scenarios = listOf(), tutors = setOf(correctTutor, incorrectTutor), - persons = setOf(person) + person = person ) entityManager.persist(tooEarly) entityManager.persist(tooLate) @@ -380,143 +240,6 @@ class RepositoryTest { assertFalse(result.contains(wrongTutor)) } - @Test - fun testFindByTutorsAndWhomIgnoreCaseAndDateBetween() { - val site = entityManager.persist(Site(name = "Correct")) - val person = entityManager.persist(Person(name = "Foo Bar")) - val correctTutor = entityManager.persist(Tutor(name = "X", site = site)) - val incorrectTutor = entityManager.persist(Tutor(name = "N", site = site)) - val tooEarly = Observation( - site = site, - date = LocalDate.now().minusDays(5), - type = TrainingType.INITIAL, - observed = "1", - whom = "G1", - monitoring = 5.0, - controlProcedural = 3.0, - control = 4.0, - conservatism = 3.0, - teamworkCommunications = 2.0, - teamworkLeadership = 3.0, - teamworkWorkload = 1.0, - knowledge = 1.0, - entries = listOf(), - tutors = setOf(correctTutor), - persons = setOf(person) - ) - val tooLate = Observation( - site = site, - date = LocalDate.now().plusDays(5), - type = TrainingType.INITIAL, - observed = "1", - whom = "G1", - monitoring = 5.0, - controlProcedural = 3.0, - control = 4.0, - conservatism = 3.0, - teamworkCommunications = 2.0, - teamworkLeadership = 3.0, - teamworkWorkload = 1.0, - knowledge = 1.0, - entries = listOf(), - tutors = setOf(correctTutor), - persons = setOf(person) - ) - val wrongTutor = Observation( - site = site, - date = LocalDate.now(), - type = TrainingType.INITIAL, - observed = "1", - whom = "G1", - monitoring = 5.0, - controlProcedural = 3.0, - control = 4.0, - conservatism = 3.0, - teamworkCommunications = 2.0, - teamworkLeadership = 3.0, - teamworkWorkload = 1.0, - knowledge = 1.0, - entries = listOf(), - tutors = setOf(incorrectTutor), - persons = setOf(person) - ) - val justRight = Observation( - site = site, - date = LocalDate.now(), - type = TrainingType.INITIAL, - observed = "1", - whom = "G1", - monitoring = 5.0, - controlProcedural = 3.0, - control = 4.0, - conservatism = 3.0, - teamworkCommunications = 2.0, - teamworkLeadership = 3.0, - teamworkWorkload = 1.0, - knowledge = 1.0, - entries = listOf(), - tutors = setOf(correctTutor), - persons = setOf(person) - ) - val wrongGroup = Observation( - site = site, - date = LocalDate.now(), - type = TrainingType.INITIAL, - observed = "1", - whom = "G2", - monitoring = 5.0, - controlProcedural = 3.0, - control = 4.0, - conservatism = 3.0, - teamworkCommunications = 2.0, - teamworkLeadership = 3.0, - teamworkWorkload = 1.0, - knowledge = 1.0, - entries = listOf(), - tutors = setOf(correctTutor), - persons = setOf(person) - ) - val justRightMultipleTutors = Observation( - site = site, - date = LocalDate.now(), - type = TrainingType.INITIAL, - observed = "1", - whom = "G1", - monitoring = 5.0, - controlProcedural = 3.0, - control = 4.0, - conservatism = 3.0, - teamworkCommunications = 2.0, - teamworkLeadership = 3.0, - teamworkWorkload = 1.0, - knowledge = 1.0, - entries = listOf(), - tutors = setOf(correctTutor, incorrectTutor), - persons = setOf(person) - ) - entityManager.persist(tooEarly) - entityManager.persist(tooLate) - entityManager.persist(wrongTutor) - entityManager.persist(justRight) - entityManager.persist(wrongGroup) - entityManager.persist(justRightMultipleTutors) - correctTutor.observations.addAll(listOf(tooEarly, tooLate, justRight, justRightMultipleTutors, wrongGroup)) - entityManager.persist(correctTutor) - incorrectTutor.observations.addAll(listOf(wrongTutor, justRightMultipleTutors)) - entityManager.persist(incorrectTutor) - val result = observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc( - tutor = correctTutor, - startDate = LocalDate.now().minusDays(1), - endDate = LocalDate.now().plusDays(1), - whom = "G1" - ) - assertEquals(2, result.size) - assertTrue(result.contains(justRight)) - assertTrue(result.contains(justRightMultipleTutors)) - assertFalse(result.contains(wrongTutor)) - assertFalse(result.contains(wrongGroup)) - } - @Test fun testFindBySiteAndPersonsAndDateBetween() { val person = entityManager.persist(Person(name = "Foo Bar")) @@ -528,7 +251,6 @@ class RepositoryTest { date = LocalDate.now().minusDays(5), type = TrainingType.INITIAL, observed = "1", - whom = "G1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, @@ -537,16 +259,15 @@ class RepositoryTest { teamworkLeadership = 3.0, teamworkWorkload = 1.0, knowledge = 1.0, - entries = listOf(), + scenarios = listOf(), tutors = setOf(tutor), - persons = setOf(person) + person = person ) val tooLate = Observation( site = site, date = LocalDate.now().plusDays(5), type = TrainingType.INITIAL, observed = "1", - whom = "G1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, @@ -555,16 +276,15 @@ class RepositoryTest { teamworkLeadership = 3.0, teamworkWorkload = 1.0, knowledge = 1.0, - entries = listOf(), + scenarios = listOf(), tutors = setOf(tutor), - persons = setOf(person) + person = person ) val wrongPerson = Observation( site = site, date = LocalDate.now(), type = TrainingType.INITIAL, observed = "1", - whom = "G1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, @@ -573,16 +293,15 @@ class RepositoryTest { teamworkLeadership = 3.0, teamworkWorkload = 1.0, knowledge = 1.0, - entries = listOf(), + scenarios = listOf(), tutors = setOf(tutor), - persons = setOf(otherPerson) + person = otherPerson ) val justRight = Observation( site = site, date = LocalDate.now(), type = TrainingType.INITIAL, observed = "1", - whom = "G1", monitoring = 5.0, controlProcedural = 3.0, control = 4.0, @@ -591,15 +310,15 @@ class RepositoryTest { teamworkLeadership = 3.0, teamworkWorkload = 1.0, knowledge = 1.0, - entries = listOf(), + scenarios = listOf(), tutors = setOf(tutor), - persons = setOf(person) + person = person ) entityManager.persist(tooEarly) entityManager.persist(tooLate) entityManager.persist(wrongPerson) entityManager.persist(justRight) - val result = observationRepository.findBySiteAndPersonsAndDateBetweenOrderByDateAsc( + val result = observationRepository.findBySiteAndPersonAndDateBetweenOrderByDateAsc( site = site, person = person, startDate = LocalDate.now().minusDays(1), diff --git a/frontend/src/components/ObservationEntry.vue b/frontend/src/components/ObservationEntry.vue new file mode 100644 index 0000000..c786e92 --- /dev/null +++ b/frontend/src/components/ObservationEntry.vue @@ -0,0 +1,48 @@ + + + + + diff --git a/frontend/src/views/Observation.vue b/frontend/src/views/Observation.vue index a262098..12c6381 100644 --- a/frontend/src/views/Observation.vue +++ b/frontend/src/views/Observation.vue @@ -1,117 +1,221 @@