Added recording of persons to the backend.

This commit is contained in:
neviyn 2018-10-19 10:33:58 +01:00
parent 77a0077be1
commit bee72b152c
5 changed files with 45 additions and 34 deletions

View File

@ -22,13 +22,15 @@ data class NewObservation(
val observed: String,
val whom: String,
val entries: List<Entry>,
val tutors: List<Long>
val tutors: List<Long>,
val persons: List<String>
)
data class ObservationsRequest(
val site: Long?,
val tutor: Long?,
val whom: String?,
val person: String?,
val startDate: LocalDate,
val endDate: LocalDate
)

View File

@ -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 {

View File

@ -92,7 +92,9 @@ data class Observation(
val entries: List<Entry>,
@JsonIgnore
@ManyToMany(mappedBy = "observations")
val tutors: Set<Tutor>
val tutors: Set<Tutor>,
@ElementCollection
val persons: Set<Person>
)
/**
@ -113,3 +115,9 @@ data class Entry(
@JsonProperty
val improvements: String
)
@Embeddable
data class Person(
@JsonProperty
val name: String
)

View File

@ -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())

View File

@ -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)