Added mechanism for retrieving in-progress session data.

This commit is contained in:
neviyn 2019-05-03 13:20:38 +01:00
parent 0ec96a874d
commit 319e59354a
3 changed files with 39 additions and 4 deletions

View File

@ -64,7 +64,7 @@ object GroupSessionManager {
}
fun dataComplete(): Boolean {
if(observations.isEmpty()){
if (observations.isEmpty()) {
logger.warn("Observations is currently empty")
return false
}
@ -80,4 +80,8 @@ object GroupSessionManager {
fun updateObservationData(input: GroupObservation) {
observations[input.person] = input
}
fun participantExistsInSession(name: String): Boolean = observations.containsKey(name)
fun getObservationDataForParticipant(name: String): GroupObservation? = observations[name]
}

View File

@ -120,13 +120,23 @@ class GroupSessionController {
return committedObservation
}
/**
* Get the current observation data for a user with [name] in the current session.
*/
@GetMapping("/participant/{name}")
fun getParticipantData(@PathVariable name: String): GroupObservation{
if(GroupSessionManager.participantExistsInSession(name))
return GroupSessionManager.getObservationDataForParticipant(name)!!
throw ResponseStatusException(HttpStatus.NOT_FOUND, "No participant with the name:'$name'")
}
/**
* Submit an observation to be added to the session state and actual database
*/
@PostMapping("/submit")
fun addGroupObservation(@Valid @RequestBody observationData: GroupObservation) {
val titles = observationData.scenarios.map { it.title }
if(GroupSessionManager.scenarioTitles!!.size != titles.size || !GroupSessionManager.scenarioTitles!!.containsAll(titles)) {
if (GroupSessionManager.scenarioTitles!!.size != titles.size || !GroupSessionManager.scenarioTitles!!.containsAll(titles)) {
logger.warn("Received scenario data but titles did not match\nInput:$titles\nRequired:${GroupSessionManager.scenarioTitles}")
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Submission data contains non-matching title(s)")
}

View File

@ -12,7 +12,6 @@ import org.mockito.Mockito
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.junit.MockitoJUnitRunner
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.messaging.simp.SimpMessagingTemplate
import org.springframework.web.server.ResponseStatusException
import uk.co.neviyn.observationdatabase.GroupObservation
@ -89,7 +88,7 @@ class GroupSessionControllerTest {
}
@Test
fun testCompleteSession(){
fun testCompleteSession() {
val site = Site(1, "Test site")
val tutor = Tutor(1, "Mr X", site)
Mockito.doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
@ -150,4 +149,26 @@ class GroupSessionControllerTest {
assertEquals("A Student", GroupSessionManager.observations.keys.first())
assertEquals("A Student", GroupSessionManager.observations.values.first().person)
}
@Test(expected = ResponseStatusException::class)
fun testGetParticipantData_NoParticipant() {
controller.getParticipantData("Someone")
}
@Test(expected = ResponseStatusException::class)
fun testGetParticipantData_WrongName() {
val rc = RatingComponent(rating = 5)
val testData = GroupObservation("A Student", listOf(Scenario(0, "Sample title", rc, rc, rc, rc, rc, rc, rc, rc)))
GroupSessionManager.observations["A Student"] = testData
controller.getParticipantData("Another Student")
}
@Test
fun testGetParticipantData() {
val rc = RatingComponent(rating = 5)
val testData = GroupObservation("A Student", listOf(Scenario(0, "Sample title", rc, rc, rc, rc, rc, rc, rc, rc)))
GroupSessionManager.observations["A Student"] = testData
val output = controller.getParticipantData("A Student")
assertEquals(testData, output)
}
}