Added TrainingType.

This commit is contained in:
neviyn 2018-09-17 10:12:14 +01:00
parent 32d601a78c
commit cca23fa995
4 changed files with 30 additions and 7 deletions

View File

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

View File

@ -14,7 +14,6 @@ import org.joda.time.DateTime;
@Data
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class Observation {
@NonNull
@ -29,6 +28,10 @@ public class Observation {
@JsonProperty
private String observed;
@NonNull
@JsonProperty
private TrainingType type;
@NonNull
@JsonProperty
private int monitoring, control, conservatism, teamwork, knowledge;
@ -53,10 +56,25 @@ public class Observation {
this.rawData = rawData;
}
private Observation(int id, int siteId, String observed, String type, int monitoring, int control, int conservatism,
int teamwork, int knowledge, String rawData, DateTime date) {
this.id = id;
this.siteId = siteId;
this.observed = observed;
this.type = TrainingType.valueOf(type.toUpperCase());
this.monitoring = monitoring;
this.control = control;
this.conservatism = conservatism;
this.teamwork = teamwork;
this.knowledge = knowledge;
this.rawData = rawData;
this.date = date;
}
public static class Mapper implements RowMapper<Observation>{
public Observation map(ResultSet rs, StatementContext ctx) throws SQLException {
return new Observation(rs.getInt("id"), rs.getInt("siteId"), rs.getString("observed"),
return new Observation(rs.getInt("id"), rs.getInt("siteId"), rs.getString("observed"), rs.getString("type"),
rs.getInt("monitoring"), rs.getInt("control"), rs.getInt("conservatism"), rs.getInt("teamwork"),
rs.getInt("knowledge"), rs.getString("rawData"), new DateTime(rs.getDate("date")));
}

View File

@ -0,0 +1,5 @@
package uk.co.neviyn.Observations.core;
public enum TrainingType {
INITIAL, CONTINUING
}

View File

@ -16,16 +16,16 @@ import uk.co.neviyn.Observations.core.Observation;
public interface ObservationDao {
@SqlUpdate("CREATE TABLE IF NOT EXISTS observations (id INTEGER PRIMARY KEY, siteId INTEGER, " +
"observed TEXT, monitoring INTEGER, control INTEGER, conservatism INTEGER, teamwork INTEGER, knowledge INTEGER, " +
"rawData TEXT, date DATE)")
"observed TEXT, type TEXT, monitoring INTEGER, control INTEGER, conservatism INTEGER, teamwork INTEGER, " +
"knowledge INTEGER, rawData TEXT, date DATE)")
void createObservationTable();
@SqlUpdate("CREATE TABLE IF NOT EXISTS observation_tutor (tutorId INT NOT NULL, observationId INT NOT NULL, " +
"FOREIGN KEY (tutorID) REFERENCES tutor(id), FOREIGN KEY (observationId) REFERENCES observations(id))")
void createObservationTutorTable();
@SqlUpdate("INSERT INTO observations (siteId, observed, monitoring, control, conservatism, teamwork, knowledge, " +
"rawData, date) VALUES (:siteId, :observed, :monitoring, :control, :conservatism, :teamwork, :knowledge, " +
@SqlUpdate("INSERT INTO observations (siteId, observed, type, monitoring, control, conservatism, teamwork, knowledge, " +
"rawData, date) VALUES (:siteId, :observed, :type, :monitoring, :control, :conservatism, :teamwork, :knowledge, " +
":rawData, :date)")
@GetGeneratedKeys
int addObservation(@BindBean NewObservation observation, @Bind("date") DateTime date);