Fixed searching for an observation by an associated individual.

This commit is contained in:
neviyn 2018-10-29 15:26:12 +00:00
parent 2834010c3b
commit 8a6e3a312a
3 changed files with 4 additions and 7 deletions

View File

@ -132,13 +132,11 @@ class Controller {
endDate = observationsRequest.endDate) endDate = observationsRequest.endDate)
} }
}.orElse(listOf()) }.orElse(listOf())
} } else if (observationsRequest.person != null && observationsRequest.person.isNotEmpty() && observationsRequest.site != null) {
else if(observationsRequest.person != null && observationsRequest.person.isNotEmpty() && observationsRequest.site != null) { val person = personRepository.findByName(observationsRequest.person.toUpperCase()) ?: return listOf()
val person = personRepository.findByName(observationsRequest.person) ?: return listOf()
val site = siteRepository.findById(observationsRequest.site).get() val site = siteRepository.findById(observationsRequest.site).get()
return observationRepository.findBySiteAndPersonsAndDateBetween(site, person, observationsRequest.startDate, observationsRequest.endDate) return observationRepository.findBySiteAndPersonsAndDateBetween(site, person, observationsRequest.startDate, observationsRequest.endDate)
} } else if (observationsRequest.site != null) {
else if (observationsRequest.site != null) {
return siteRepository.findById(observationsRequest.site).map { return siteRepository.findById(observationsRequest.site).map {
when { when {
(observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findBySiteAndDateBetween(site = it, (observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findBySiteAndDateBetween(site = it,

View File

@ -28,5 +28,4 @@ interface ObservationRepository : CrudRepository<Observation, Long> {
interface PersonRepository : CrudRepository<Person, Long> { interface PersonRepository : CrudRepository<Person, Long> {
fun findByName(name: String): Person? fun findByName(name: String): Person?
} }

View File

@ -186,7 +186,7 @@ class ControllerTest {
control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 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, entries = listOf(), tutors = setOf(tutor), persons = setOf(person))
doReturn(Optional.of(site)).`when`(siteRepository).findById(1) doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
doReturn(person).`when`(personRepository).findByName("Foo Bar") doReturn(person).`when`(personRepository).findByName("FOO BAR")
doReturn(listOf(observation)).`when`(observationRepository).findBySiteAndPersonsAndDateBetween(site, person, LocalDate.now(), LocalDate.now()) doReturn(listOf(observation)).`when`(observationRepository).findBySiteAndPersonsAndDateBetween(site, person, LocalDate.now(), LocalDate.now())
val result = controller.getObservations(request) val result = controller.getObservations(request)
assertEquals(1, result.size) assertEquals(1, result.size)