diff --git a/appointment-import/src/main/java/smash/appointment/parse/AppointmentEntry.java b/appointment-import/src/main/java/smash/appointment/parse/AppointmentEntry.java index 2014454211fd50042c0a3483af0afd41cdc080f8..b4faf7c678c40b3daa3f6429d2314ce8d11e87ce 100644 --- a/appointment-import/src/main/java/smash/appointment/parse/AppointmentEntry.java +++ b/appointment-import/src/main/java/smash/appointment/parse/AppointmentEntry.java @@ -1,15 +1,16 @@ package smash.appointment.parse; -import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class AppointmentEntry { private String day; private String time; private String duration; private Subject subject; - private List<AppointmentType> types = new ArrayList<>(); + private Set<AppointmentType> types = new HashSet<>(); private String source; /** @@ -54,7 +55,7 @@ public class AppointmentEntry { * @return the type * @see #type */ - public List<AppointmentType> getTypes() { + public Set<AppointmentType> getTypes() { return types; } diff --git a/appointment-import/src/main/java/smash/appointment/parse/AppointmentSqlExporter.java b/appointment-import/src/main/java/smash/appointment/parse/AppointmentSqlExporter.java index 54eb1628dfa42483510329e239574a03b76f620d..ef3b865bb5969dddcdcf1d300805e6fae2a3d315 100644 --- a/appointment-import/src/main/java/smash/appointment/parse/AppointmentSqlExporter.java +++ b/appointment-import/src/main/java/smash/appointment/parse/AppointmentSqlExporter.java @@ -1,6 +1,6 @@ package smash.appointment.parse; -public class AppointmentSqlExporter extends SqlExporter{ +public class AppointmentSqlExporter extends SqlExporter { public String toSql(AppointmentEntry appointment, boolean isFinished) { StringBuilder result = new StringBuilder(""); @@ -12,12 +12,22 @@ public class AppointmentSqlExporter extends SqlExporter{ result.append("visit_id) "); result.append("values ("); - result.append(getStringVal(appointment.getDay()+" "+appointment.getTime()) + ","); + result.append(getStringVal(appointment.getDay() + " " + appointment.getTime()) + ","); result.append(getStringVal(appointment.getDuration()) + ","); - result.append(isFinished+ ","); + result.append(isFinished + ","); result.append("(select max(id) from web_visit)"); result.append(");"); + for (AppointmentType type : appointment.getTypes()) { + result.append("insert into web_appointment_appointment_types ("); + result.append("appointment_id, "); + result.append("appointmenttype_id) "); + result.append("values ("); + result.append("(select max(id) from web_appointment),"); + result.append("(select id from web_appointmenttype where code=" + getStringVal(type.getAbbreviation()) + ") "); + result.append(");"); + } + return result.toString(); } diff --git a/appointment-import/src/main/java/smash/appointment/parse/AppointmentType.java b/appointment-import/src/main/java/smash/appointment/parse/AppointmentType.java index d3727f176c260a567ecec2d2db88269246f145a5..bceb087694fe573ae698e4251a7364557624f402 100644 --- a/appointment-import/src/main/java/smash/appointment/parse/AppointmentType.java +++ b/appointment-import/src/main/java/smash/appointment/parse/AppointmentType.java @@ -1,24 +1,29 @@ package smash.appointment.parse; public enum AppointmentType { - LEVEL_BV(90), // - LEVEL_BG(30), // - LEVEL_SB(30), // + LEVEL_BV(90,"BV"), // + LEVEL_BG(30,"BG"), // + LEVEL_SB(30,"SB"), // - LEVEL_A_TQ(120), // - LEVEL_A(120), // - LEVEL_B(90), // - LEVEL_B_M_POWER(70), // - OTHER(60), // + LEVEL_A_TQ(120,"A_TQ"), // + LEVEL_A(120,"A"), // + LEVEL_B(90,"B"), // + LEVEL_B_M_POWER(70,"mPower"), // + OTHER(60,"OTHER"), // ; private int time; + private String abbreviation; - private AppointmentType(int defaultTime) { + private AppointmentType(int defaultTime, String abbreviation) { this.time=defaultTime; + this.abbreviation=abbreviation; } public int getTime() { return time; } + public String getAbbreviation() { + return abbreviation; + } } diff --git a/appointment-import/src/main/java/smash/appointment/parse/Main.java b/appointment-import/src/main/java/smash/appointment/parse/Main.java index 6fda1d02c6551a3064e21697c6fb9cc7e4f0186d..59a12ffb85d8be2c62b77c3c7db03416eae1dea6 100644 --- a/appointment-import/src/main/java/smash/appointment/parse/Main.java +++ b/appointment-import/src/main/java/smash/appointment/parse/Main.java @@ -78,9 +78,9 @@ public class Main { appointmentDao.addAppointments(processPrcAppointments(agendaFile, today)); String redCapFile = line.getOptionValue("red-cap"); - appointmentDao.addAppointments(processRedCapAppointments(agendaFile)); - + appointmentDao.addAppointments(processRedCapAppointments(redCapFile)); + System.out.println("delete from web_appointment_appointment_types;"); System.out.println("delete from web_subject_languages;"); System.out.println("delete from web_appointment;"); System.out.println("delete from web_visit;"); diff --git a/appointment-import/src/test/java/smash/appointment/parse/CellParserTest.java b/appointment-import/src/test/java/smash/appointment/parse/CellParserTest.java index 757161d3814d0c249bc8391b2ad1e5ccfab30e02..56ae493787677dad7bf08861061720b5302a161e 100644 --- a/appointment-import/src/test/java/smash/appointment/parse/CellParserTest.java +++ b/appointment-import/src/test/java/smash/appointment/parse/CellParserTest.java @@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import org.apache.log4j.Logger; @@ -128,7 +129,7 @@ public class CellParserTest extends TestBase { } } - private boolean equalTypes(List<AppointmentType> types, List<AppointmentType> types2) { + private boolean equalTypes(List<AppointmentType> types, Collection<AppointmentType> types2) { for (AppointmentType type : types) { if (!types2.contains(type)) { return false;