Added field for who was observed.

This commit is contained in:
neviyn 2018-09-25 11:08:18 +01:00
parent 40ad371748
commit 20599d48fd
9 changed files with 15 additions and 8 deletions

View File

@ -22,7 +22,7 @@ public class NewObservation {
@NonNull @NonNull
@JsonProperty @JsonProperty
private String observed, type; private String observed, type, whom;
@NonNull @NonNull
@JsonProperty @JsonProperty

View File

@ -39,6 +39,10 @@ public class Observation implements Serializable {
@JsonProperty @JsonProperty
private String observed; private String observed;
@NonNull
@JsonProperty
private String whom;
@NonNull @NonNull
@JsonProperty @JsonProperty
private TrainingType type; private TrainingType type;

View File

@ -48,7 +48,7 @@ public class ObservationResource {
.type(TrainingType.valueOf(newObservation.getType())).monitoring(newObservation.getMonitoring()) .type(TrainingType.valueOf(newObservation.getType())).monitoring(newObservation.getMonitoring())
.control(newObservation.getControl()).conservatism(newObservation.getConservatism()) .control(newObservation.getControl()).conservatism(newObservation.getConservatism())
.teamwork(newObservation.getTeamwork()).knowledge(newObservation.getKnowledge()) .teamwork(newObservation.getTeamwork()).knowledge(newObservation.getKnowledge())
.observations(newObservation.getRawData()).date(submissionDate).build(); .observations(newObservation.getRawData()).date(submissionDate).whom(newObservation.getWhom()).build();
for (Tutor t : tutors) { for (Tutor t : tutors) {
t.getObservations().add(observation); t.getObservations().add(observation);
} }

View File

@ -9,14 +9,15 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import static io.dropwizard.testing.FixtureHelpers.fixture; import static io.dropwizard.testing.FixtureHelpers.fixture;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
public class NewObservationTest { public class NewObservationTest {
private static final ObjectMapper mapper = Jackson.newObjectMapper(); private static final ObjectMapper mapper = Jackson.newObjectMapper();
private final NewObservation newObservation = new NewObservation(1, Arrays.asList(1L, 2L, 3L), "A random thing made for testing.", private final NewObservation newObservation = NewObservation.builder().siteId(1).tutorIds(Arrays.asList(1L, 2L, 3L))
"INITIAL", 1, 2, 3, 4, 5, Collections.singletonList(new ObservationEntry("MONITORING", 5, "some", "another sum"))); .observed("A random thing made for testing.").whom("Group A").type("INITIAL").monitoring(1).control(2).conservatism(3)
.teamwork(4).knowledge(5).rawData(Collections.singletonList(new ObservationEntry("MONITORING", 5, "some", "another sum"))).build();
@Test @Test
public void serializesToJson() throws Exception { public void serializesToJson() throws Exception {

View File

@ -16,7 +16,7 @@ public class ObservationTest {
private static final ObjectMapper mapper = Jackson.newObjectMapper(); private static final ObjectMapper mapper = Jackson.newObjectMapper();
private final Observation observation = Observation.builder().observed("Just a test observation").type(TrainingType.INITIAL) private final Observation observation = Observation.builder().observed("Just a test observation").type(TrainingType.INITIAL)
.monitoring(1).control(2).conservatism(3).teamwork(4).knowledge(5) .monitoring(1).control(2).conservatism(3).teamwork(4).knowledge(5).whom("Group A")
.observations(Collections.singletonList(new ObservationEntry("MONITORING", 5, "some", "another sum"))) .observations(Collections.singletonList(new ObservationEntry("MONITORING", 5, "some", "another sum")))
.date(DateTime.parse("2018-09-18T00:00:00.000Z")).build(); .date(DateTime.parse("2018-09-18T00:00:00.000Z")).build();

View File

@ -23,7 +23,7 @@ public class ObservationDaoTest extends DaoTestBase {
private final Site site = Site.builder().name("Test site").build(); private final Site site = Site.builder().name("Test site").build();
private final Observation observation = Observation.builder().observed("Just a test observation").type(TrainingType.INITIAL) private final Observation observation = Observation.builder().observed("Just a test observation").type(TrainingType.INITIAL)
.site(site).monitoring(1).control(2).conservatism(3).teamwork(4).knowledge(5) .site(site).monitoring(1).control(2).conservatism(3).teamwork(4).knowledge(5).whom("Group A")
.observations(Collections.singletonList(new ObservationEntry("MONITORING", 5, "some", "another sum"))) .observations(Collections.singletonList(new ObservationEntry("MONITORING", 5, "some", "another sum")))
.date(DateTime.parse("2018-09-18T00:00:00.000Z")).build(); .date(DateTime.parse("2018-09-18T00:00:00.000Z")).build();

View File

@ -47,7 +47,7 @@ public class ObservationResourceTest {
when(tutorDao.get(2)).thenReturn(tutors.get(1)); when(tutorDao.get(2)).thenReturn(tutors.get(1));
resources.target("/observation").request().post(Entity.json(NewObservation.builder().type("INITIAL") resources.target("/observation").request().post(Entity.json(NewObservation.builder().type("INITIAL")
.conservatism(1).control(2).knowledge(3).monitoring(4).teamwork(5).siteId(1).tutorIds(Arrays.asList(1L, 2L)) .conservatism(1).control(2).knowledge(3).monitoring(4).teamwork(5).siteId(1).tutorIds(Arrays.asList(1L, 2L))
.observed("").rawData(new ArrayList<>()).build())); .observed("").whom("Group A").rawData(new ArrayList<>()).build()));
verify(dao, times(1)).persist(any(Observation.class)); verify(dao, times(1)).persist(any(Observation.class));
} }

View File

@ -2,6 +2,7 @@
"siteId":1, "siteId":1,
"tutorIds":[1,2,3], "tutorIds":[1,2,3],
"observed":"A random thing made for testing.", "observed":"A random thing made for testing.",
"whom": "Group A",
"type":"INITIAL", "type":"INITIAL",
"monitoring":1, "monitoring":1,
"control":2, "control":2,

View File

@ -1,6 +1,7 @@
{ {
"id":0, "id":0,
"observed":"Just a test observation", "observed":"Just a test observation",
"whom": "Group A",
"type":"INITIAL", "type":"INITIAL",
"monitoring":1, "monitoring":1,
"control":2, "control":2,