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 2268c9027e316eef96be66bd632f394c8be25390..b6e872864e644b741c49827eebf3714a463e8a47 100644 --- a/appointment-import/src/main/java/smash/appointment/parse/AppointmentEntry.java +++ b/appointment-import/src/main/java/smash/appointment/parse/AppointmentEntry.java @@ -4,12 +4,12 @@ import java.util.ArrayList; import java.util.List; public class AppointmentEntry { - private String day; - private String time; - private String duration; - private Subject subject; - private AppointmentType type; - private String source; + private String day; + private String time; + private String duration; + private Subject subject; + private List<AppointmentType> types = new ArrayList<>(); + private String source; /** * @return the time @@ -49,8 +49,8 @@ public class AppointmentEntry { * @return the type * @see #type */ - public AppointmentType getType() { - return type; + public List<AppointmentType> getTypes() { + return types; } /** @@ -58,8 +58,8 @@ public class AppointmentEntry { * the type to set * @see #type */ - public void setType(AppointmentType type) { - this.type = type; + public void addType(AppointmentType type) { + this.types.add(type); } /** @@ -98,7 +98,7 @@ public class AppointmentEntry { @Override public String toString() { - return day + " " + time + " " + subject + " " + type + "\t\t[source: " + source + "]"; + return day + " " + time + " " + subject + " " + types + "\t\t[source: " + source + "]"; } /** @@ -117,4 +117,11 @@ public class AppointmentEntry { public void setDuration(String duration) { this.duration = duration; } + + public void addTypes(AppointmentType[] typesToAdd) { + for (AppointmentType appointmentType : typesToAdd) { + addType(appointmentType); + } + + } } 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 9660b8e6ab7a6d3f76052214b329eb66336cf842..5f232b0af3d9219642a84b8ba9161abe6e2b54c6 100644 --- a/appointment-import/src/main/java/smash/appointment/parse/AppointmentType.java +++ b/appointment-import/src/main/java/smash/appointment/parse/AppointmentType.java @@ -1,36 +1,15 @@ package smash.appointment.parse; public enum AppointmentType { - - //most complex should be first - LEVEL_BV_BG_SB_MPOWER(new String[] {"evel BV + BG + SB + mPower", "BV + BG + SB + mPower"}), // - LEVEL_BV_BG_SB(new String[] { "evel BV + BG + SB","BV + BG + SB" }), // - LEVEL_BV_SB(new String[] { "evel BV + SB","BV + SB" }), // - LEVEL_BV_BG(new String[] { "evel BV + BG","BV + BG" }), // - LEVEL_BG_SB(new String[] { "evel BG + SB","BG + SB" }), // - LEVEL_BV(new String[] { "evel BV", "BV" }), // - LEVEL_BG(new String[] { "evel BG","BG" }), // - LEVEL_SB(new String[] { "evel SB", "SB" }), // - - LEVEL_A_TQ(new String[] { "TQ" }), // - LEVEL_A(new String[] { "level A" }), // - LEVEL_B(new String[] { "evel B" }), // - LEVEL_B_M_POWER(new String[] { "mPower" }), // - OTHER(new String[] {}), // + LEVEL_BV(), // + LEVEL_BG(), // + LEVEL_SB(), // + + LEVEL_A_TQ(), // + LEVEL_A(), // + LEVEL_B(), // + LEVEL_B_M_POWER(), // + OTHER(), // ; - private String[] queryStrings; - - private AppointmentType(String[] queryStrings) { - this.queryStrings = queryStrings; - - } - - /** - * @return the queryStrings - * @see #queryStrings - */ - public String[] getQueryStrings() { - return queryStrings; - } } diff --git a/appointment-import/src/main/java/smash/appointment/parse/CellParser.java b/appointment-import/src/main/java/smash/appointment/parse/CellParser.java index 3093c7d706f3a4f615111a59560e1e40e0fd4348..01be5b86147e5f25e2984577cca99624aa5c0f98 100644 --- a/appointment-import/src/main/java/smash/appointment/parse/CellParser.java +++ b/appointment-import/src/main/java/smash/appointment/parse/CellParser.java @@ -43,23 +43,24 @@ public class CellParser { Subject subject = extractSubject(query); result.setSubject(subject); - AppointmentType type = extractType(query); + AppointmentTypeCollection type = extractType(query); if (type == null) { - type = AppointmentType.OTHER; + result.addType(AppointmentType.OTHER); + } else { + result.addTypes(type.getTypes()); } - result.setType(type); result.setSource(query); return result; } - private AppointmentType extractType(String query) { + private AppointmentTypeCollection extractType(String query) { String simplifiedQuery = Utils.simplifyString(query); - AppointmentType result = null; + AppointmentTypeCollection result = null; String usedString = null; - for (AppointmentType type : AppointmentType.values()) { + for (AppointmentTypeCollection type : AppointmentTypeCollection.values()) { boolean matchFound = false; for (String string : type.getQueryStrings()) { if (!matchFound) { @@ -77,7 +78,7 @@ public class CellParser { } else if (usedString.contains(string)) { // new one is a substring of old } else { // if there is no substring then we might have a problem - AppointmentType newType = result; + AppointmentTypeCollection newType = result; if (usedString.length() < string.length()) { usedString = string; newType = type; diff --git a/appointment-import/src/main/java/smash/appointment/parse/RedcapParser.java b/appointment-import/src/main/java/smash/appointment/parse/RedcapParser.java index 2e8cbc2f21d092a02e425759879f4a58b692b613..89eb6edd870b0e98c54e4680d8bed3092e0e78ff 100644 --- a/appointment-import/src/main/java/smash/appointment/parse/RedcapParser.java +++ b/appointment-import/src/main/java/smash/appointment/parse/RedcapParser.java @@ -86,7 +86,7 @@ public class RedcapParser { entry.setDay(date); entry.setSubject(subject); entry.setSource("Imported from RedCap"); - entry.setType(AppointmentType.LEVEL_B_M_POWER); + entry.addType(AppointmentType.LEVEL_B_M_POWER); return entry; } @@ -96,7 +96,7 @@ public class RedcapParser { entry.setDay(date); entry.setSubject(subject); entry.setSource("Imported from RedCap"); - entry.setType(AppointmentType.LEVEL_SB); + entry.addType(AppointmentType.LEVEL_SB); return entry; } @@ -110,7 +110,7 @@ public class RedcapParser { entry.setDay(date); entry.setSubject(subject); entry.setSource("Imported from RedCap"); - entry.setType(AppointmentType.LEVEL_BV); + entry.addType(AppointmentType.LEVEL_BV); return entry; } @@ -124,7 +124,7 @@ public class RedcapParser { entry.setDay(date); entry.setSubject(subject); entry.setSource("Imported from RedCap"); - entry.setType(AppointmentType.LEVEL_BG); + entry.addType(AppointmentType.LEVEL_BG); return entry; } @@ -138,7 +138,7 @@ public class RedcapParser { entry.setDay(date); entry.setSubject(subject); entry.setSource("Imported from RedCap"); - entry.setType(AppointmentType.LEVEL_B); + entry.addType(AppointmentType.LEVEL_B); return entry; } @@ -156,7 +156,7 @@ public class RedcapParser { entry.setSubject(subject); entry.setSource("Imported from RedCap"); entry.setTime(time); - entry.setType(AppointmentType.LEVEL_A); + entry.addType(AppointmentType.LEVEL_A); return entry; } diff --git a/appointment-import/src/test/java/smash/appointment/parse/AllTests.java b/appointment-import/src/test/java/smash/appointment/parse/AllTests.java index 80dc2e923c352fd7f99c0a18378f0ac8cec14ba2..be53066bf67243f20b17db09c78442986f2a6e74 100644 --- a/appointment-import/src/test/java/smash/appointment/parse/AllTests.java +++ b/appointment-import/src/test/java/smash/appointment/parse/AllTests.java @@ -6,6 +6,8 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) @SuiteClasses({ CellParserTest.class, // + RedcapParserTest.class, // + SubjectDaoTest.class, // XlsxCalendarProcessorTest.class, // }) diff --git a/appointment-import/src/test/java/smash/appointment/parse/CellParseTestCase.java b/appointment-import/src/test/java/smash/appointment/parse/CellParseTestCase.java index 5bc5156649eb06657b40d4b7f4210e7ea593c924..a43dcbc578952867a0cd36fcbd74d1284fbc3466 100644 --- a/appointment-import/src/test/java/smash/appointment/parse/CellParseTestCase.java +++ b/appointment-import/src/test/java/smash/appointment/parse/CellParseTestCase.java @@ -1,15 +1,15 @@ package smash.appointment.parse; class CellParseTestCase { - String query; - Subject subject; - String time; - AppointmentType type; + String query; + Subject subject; + String time; + AppointmentType[] types; - public CellParseTestCase(String query, Subject subject, String time, AppointmentType type) { + public CellParseTestCase(String query, Subject subject, String time, AppointmentType[] types) { this.query = query; this.subject = subject; this.time = time; - this.type = type; + this.types = types; } }; 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 9178b38a6ab18fd1209f3ef52c9a5ffae535254d..c4cb6ce91b0a29874eb889fb18a0fa58b8ddb97e 100644 --- a/appointment-import/src/test/java/smash/appointment/parse/CellParserTest.java +++ b/appointment-import/src/test/java/smash/appointment/parse/CellParserTest.java @@ -2,9 +2,12 @@ package smash.appointment.parse; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Map; import org.apache.log4j.Logger; import org.junit.Before; @@ -25,17 +28,25 @@ public class CellParserTest extends TestBase { testCases = new ArrayList<CellParseTestCase>(); - testCases.add(new CellParseTestCase("Piotr Gawron level A FU V3", piotrGawron, null, AppointmentType.LEVEL_A)); - testCases.add(new CellParseTestCase("09:00 Jan Kowalski-Nowak level A", janKowalskiNowak, "09:00", AppointmentType.LEVEL_A)); - testCases.add(new CellParseTestCase("ND0002 l664574645 (sms)evel BV © + SB ©", janKowalskiNowak, null, AppointmentType.LEVEL_BV_SB)); - testCases.add(new CellParseTestCase("ND0001 654654631 level B ©", piotrGawron, null, AppointmentType.LEVEL_B)); - testCases.add(new CellParseTestCase("John Doe BV + BG + SB", johnDoe, null, AppointmentType.LEVEL_BV_BG_SB)); - testCases.add(new CellParseTestCase("Kowalski-Nowak m-Power", janKowalskiNowak, null, AppointmentType.LEVEL_B_M_POWER)); - testCases.add(new CellParseTestCase("ND0004 Name BV ©", cateKowalsky, null, AppointmentType.LEVEL_BV)); - testCases.add(new CellParseTestCase("ND0004 level BV (c) + SB ©", cateKowalsky, null, AppointmentType.LEVEL_BV_SB)); - testCases.add(new CellParseTestCase("Cate Kowalsky level BV + BG + SB + m-Power", cateKowalsky, null, AppointmentType.LEVEL_BV_BG_SB_MPOWER)); - testCases.add(new CellParseTestCase("sb name level A", null, null, AppointmentType.LEVEL_A)); - testCases.add(new CellParseTestCase("Andrew Dude level A FU V3", andrewDude, null, AppointmentType.LEVEL_A)); + testCases.add(new CellParseTestCase("Piotr Gawron level A FU V3", piotrGawron, null, new AppointmentType[] { AppointmentType.LEVEL_A })); + testCases.add(new CellParseTestCase("09:00 Jan Kowalski-Nowak level A", janKowalskiNowak, "09:00", new AppointmentType[] { AppointmentType.LEVEL_A })); + testCases.add( + new CellParseTestCase( + "ND0002 l664574645 (sms)evel BV © + SB ©", janKowalskiNowak, null, new AppointmentType[] { AppointmentType.LEVEL_BV, AppointmentType.LEVEL_SB })); + testCases.add(new CellParseTestCase("ND0001 654654631 level B ©", piotrGawron, null, new AppointmentType[] { AppointmentType.LEVEL_B })); + testCases.add( + new CellParseTestCase( + "John Doe BV + BG + SB", johnDoe, null, new AppointmentType[] { AppointmentType.LEVEL_BV, AppointmentType.LEVEL_BG, AppointmentType.LEVEL_SB })); + testCases.add(new CellParseTestCase("Kowalski-Nowak m-Power", janKowalskiNowak, null, new AppointmentType[] { AppointmentType.LEVEL_B_M_POWER })); + testCases.add(new CellParseTestCase("ND0004 Name BV ©", cateKowalsky, null, new AppointmentType[] { AppointmentType.LEVEL_BV })); + testCases.add( + new CellParseTestCase("ND0004 level BV (c) + SB ©", cateKowalsky, null, new AppointmentType[] { AppointmentType.LEVEL_BV, AppointmentType.LEVEL_SB })); + testCases.add( + new CellParseTestCase( + "Cate Kowalsky level BV + BG + SB + m-Power", cateKowalsky, null, + new AppointmentType[] { AppointmentType.LEVEL_BV, AppointmentType.LEVEL_BG, AppointmentType.LEVEL_SB, AppointmentType.LEVEL_B_M_POWER })); + testCases.add(new CellParseTestCase("sb name level A", null, null, new AppointmentType[] { AppointmentType.LEVEL_A })); + testCases.add(new CellParseTestCase("Andrew Dude level A FU V3", andrewDude, null, new AppointmentType[] { AppointmentType.LEVEL_A })); } @Test @@ -75,8 +86,23 @@ public class CellParserTest extends TestBase { assertEquals("Invalid time parsed from query (default value expected): " + testCase.query, defaultTime, appointment.getTime()); } assertEquals("Invalid subject parsed from query: " + testCase.query, testCase.subject, appointment.getSubject()); - assertEquals("Invalid type parsed from query: " + testCase.query, testCase.type, appointment.getType()); + assertTrue("Invalid type parsed from query: " + testCase.query, equalTypes(Arrays.asList(testCase.types), appointment.getTypes())); } } + private boolean equalTypes(List<AppointmentType> types, List<AppointmentType> types2) { + for (AppointmentType type: types) { + if (!types2.contains(type)) { + return false; + } + } + for (AppointmentType type: types2) { + if (!types.contains(type)) { + return false; + } + } + + return true; + } + } diff --git a/appointment-import/src/test/java/smash/appointment/parse/RedcapParserTest.java b/appointment-import/src/test/java/smash/appointment/parse/RedcapParserTest.java index 33a72db1558fb0ab3b5e2798917738572bc44432..e912829f7d1345aeedb3b5aa079e1d35c0eff59b 100644 --- a/appointment-import/src/test/java/smash/appointment/parse/RedcapParserTest.java +++ b/appointment-import/src/test/java/smash/appointment/parse/RedcapParserTest.java @@ -43,23 +43,22 @@ public class RedcapParserTest extends TestBase{ int levelSBCount = 0; int levelMPowerCount = 0; for (AppointmentEntry appointmentEntry : entries) { - logger.debug(appointmentEntry); - if (appointmentEntry.getType().equals(AppointmentType.LEVEL_A)) { + if (appointmentEntry.getTypes().contains(AppointmentType.LEVEL_A)) { levelACount++; } - if (appointmentEntry.getType().equals(AppointmentType.LEVEL_B)) { + if (appointmentEntry.getTypes().contains(AppointmentType.LEVEL_B)) { levelBCount++; } - if (appointmentEntry.getType().equals(AppointmentType.LEVEL_BG)) { + if (appointmentEntry.getTypes().contains(AppointmentType.LEVEL_BG)) { levelBGCount++; } - if (appointmentEntry.getType().equals(AppointmentType.LEVEL_BV)) { + if (appointmentEntry.getTypes().contains(AppointmentType.LEVEL_BV)) { levelBVCount++; } - if (appointmentEntry.getType().equals(AppointmentType.LEVEL_SB)) { + if (appointmentEntry.getTypes().contains(AppointmentType.LEVEL_SB)) { levelSBCount++; } - if (appointmentEntry.getType().equals(AppointmentType.LEVEL_B_M_POWER)) { + if (appointmentEntry.getTypes().contains(AppointmentType.LEVEL_B_M_POWER)) { levelMPowerCount++; } }