From bee72b152c9ad66b3629bdd4930c1392d6b37a87 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Fri, 19 Oct 2018 10:33:58 +0100 Subject: [PATCH] Added recording of persons to the backend. --- .../uk/co/neviyn/observationdatabase/Api.kt | 4 +- .../neviyn/observationdatabase/Controller.kt | 3 +- .../co/neviyn/observationdatabase/Entity.kt | 10 ++++- .../observationdatabase/ControllerTest.kt | 22 +++++----- .../observationdatabase/RepositoryTest.kt | 40 +++++++++---------- 5 files changed, 45 insertions(+), 34 deletions(-) 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 b7fe4fc..2396d09 100644 --- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Api.kt +++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Api.kt @@ -22,13 +22,15 @@ data class NewObservation( val observed: String, val whom: String, val entries: List, - val tutors: List + val tutors: List, + val persons: List ) data class ObservationsRequest( val site: Long?, val tutor: Long?, val whom: String?, + val person: String?, val startDate: LocalDate, val endDate: LocalDate ) 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 edb13e8..c388fdc 100644 --- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt +++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Controller.kt @@ -99,7 +99,8 @@ class Controller { teamworkWorkload = overallScores[RatingCategory.TEAMWORK_WORKLOAD], knowledge = overallScores[RatingCategory.KNOWLEDGE], entries = newObservation.entries, - tutors = tutors + tutors = tutors, + persons = newObservation.persons.asSequence().map { Person(it.toUpperCase()) }.toSet() ) observation = observationRepository.save(observation) tutors.forEach { 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 19a76ae..5fe2370 100644 --- a/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Entity.kt +++ b/backend/src/main/kotlin/uk/co/neviyn/observationdatabase/Entity.kt @@ -92,7 +92,9 @@ data class Observation( val entries: List, @JsonIgnore @ManyToMany(mappedBy = "observations") - val tutors: Set + val tutors: Set, + @ElementCollection + val persons: Set ) /** @@ -112,4 +114,10 @@ data class Entry( @Column(nullable = false, columnDefinition = "TEXT") @JsonProperty val improvements: String +) + +@Embeddable +data class Person( + @JsonProperty + val name: String ) \ No newline at end of file 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 63686a3..0dedfce 100644 --- a/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/ControllerTest.kt +++ b/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/ControllerTest.kt @@ -93,8 +93,8 @@ class ControllerTest { val tutor = Tutor(1, "Foo Bar", site) 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)) - 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)) + 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(observation).`when`(observationRepository).save(ArgumentMatchers.any()) val result = controller.addObservation(newData) assertEquals(1L, result) @@ -102,19 +102,19 @@ class ControllerTest { @Test fun testGetObservations_SiteAndTutorNull() { - val request = ObservationsRequest(null, null, "", LocalDate.now(), LocalDate.now()) + val request = ObservationsRequest(null, null, "", "", LocalDate.now(), LocalDate.now()) val result = controller.getObservations(request) assertTrue(result.isEmpty()) } @Test fun testGetObservations_WithSite_TutorNull_NoWhom() { - val request = ObservationsRequest(1, null, "", LocalDate.now(), LocalDate.now()) + 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, control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0, - teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf()) + 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).findBySiteAndDateBetween(site, LocalDate.now(), LocalDate.now()) @@ -125,12 +125,12 @@ class ControllerTest { @Test fun testGetObservations_WithSite_TutorNull_WithWhom() { - val request = ObservationsRequest(1, null, "Group A", LocalDate.now(), LocalDate.now()) + 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()) + 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).findBySiteAndWhomAndDateBetween(site, "Group A", LocalDate.now(), LocalDate.now()) @@ -141,13 +141,13 @@ class ControllerTest { @Test fun testGetObservations_WithSite_WithTutor_NoWhom() { - val request = ObservationsRequest(null, 1, "", LocalDate.now(), LocalDate.now()) + 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, control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0, - teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor)) + 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).findByTutorsAndDateBetween(tutor, LocalDate.now(), LocalDate.now()) @@ -158,13 +158,13 @@ class ControllerTest { @Test fun testGetObservations_WithSite_WithTutor_WithWhom() { - val request = ObservationsRequest(null, 1, "Group A", LocalDate.now(), LocalDate.now()) + 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)) + 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).findByTutorsAndWhomAndDateBetween(tutor, "Group A", LocalDate.now(), LocalDate.now()) 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 9f69d32..62acc82 100644 --- a/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/RepositoryTest.kt +++ b/backend/src/test/kotlin/uk/co/neviyn/observationdatabase/RepositoryTest.kt @@ -52,19 +52,19 @@ class RepositoryTest { 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor2), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor), persons = setOf(Person("Foo Bar"))) entityManager.persist(tooEarly) entityManager.persist(tooLate) entityManager.persist(wrongSite) @@ -83,23 +83,23 @@ class RepositoryTest { 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor2), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor), persons = setOf(Person("Foo Bar"))) entityManager.persist(tooEarly) entityManager.persist(tooLate) entityManager.persist(wrongSite) @@ -118,23 +118,23 @@ class RepositoryTest { 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(correctTutor), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(correctTutor), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(incorrectTutor), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(correctTutor), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(correctTutor, incorrectTutor), persons = setOf(Person("Foo Bar"))) entityManager.persist(tooEarly) entityManager.persist(tooLate) entityManager.persist(wrongTutor) @@ -159,27 +159,27 @@ class RepositoryTest { 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(correctTutor), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(correctTutor), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(incorrectTutor), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(correctTutor), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(correctTutor), persons = setOf(Person("Foo Bar"))) 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)) + teamworkWorkload = 1.0, knowledge = 1.0, entries = listOf(), tutors = setOf(correctTutor, incorrectTutor), persons = setOf(Person("Foo Bar"))) entityManager.persist(tooEarly) entityManager.persist(tooLate) entityManager.persist(wrongTutor)