From 2cf262130efb4f55d26550b7d61a4a7d9f3868d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Sun, 13 May 2018 16:02:51 +0200 Subject: [PATCH] [API] Get rid of NULL in timetable lesson descriptions (#106) --- .circleci/config.yml | 4 +- .../wulkanowy/api/timetable/Timetable.java | 20 +++++--- .../api/timetable/TimetableTest.java | 1 + .../api/timetable/PlanLekcji-full.html | 46 ++++++++++++++++++- 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6f91f6b3..822ae06c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -228,6 +228,6 @@ workflows: - instrumented filters: branches: - only: master + ignore: /.*/ tags: - only: /.*/ + only: /^\d+\.\d+\.\d+$/ diff --git a/api/src/main/java/io/github/wulkanowy/api/timetable/Timetable.java b/api/src/main/java/io/github/wulkanowy/api/timetable/Timetable.java index b5c7efc2..4e9cc18e 100644 --- a/api/src/main/java/io/github/wulkanowy/api/timetable/Timetable.java +++ b/api/src/main/java/io/github/wulkanowy/api/timetable/Timetable.java @@ -94,14 +94,18 @@ public class Timetable { moveWarningToLessonNode(e); switch (e.size()) { + case 1: + addLessonInfoFromElement(lesson, e.first()); + break; case 2: Element span = e.last().select("span").first(); if (span.hasClass(LessonTypes.CLASS_MOVED_OR_CANCELED)) { lesson.setNewMovedInOrChanged(true); lesson.setDescription("poprzednio: " + getLessonAndGroupInfoFromSpan(span)[0]); + addLessonInfoFromElement(lesson, e.first()); + } else { + addLessonInfoFromElement(lesson, e.last()); } - case 1: - addLessonInfoFromElement(lesson, e.first()); break; case 3: addLessonInfoFromElement(lesson, e.get(1)); @@ -167,7 +171,8 @@ public class Timetable { lesson.setRoom(spans.get(5).text()); lesson.setMovedOrCanceled(false); lesson.setNewMovedInOrChanged(true); - lesson.setDescription(StringUtils.substringBetween(spans.last().text(), "(", ")") + lesson.setDescription(StringUtils.defaultString(StringUtils.substringBetween( + spans.last().text(), "(", ")"), spans.last().text()) + " (poprzednio: " + spans.get(0).text() + ")"); } else if (9 == spans.size()) { String[] subjectAndGroupInfo = getLessonAndGroupInfoFromSpan(spans.get(4)); @@ -178,13 +183,15 @@ public class Timetable { lesson.setMovedOrCanceled(false); lesson.setNewMovedInOrChanged(true); lesson.setDivisionIntoGroups(true); - lesson.setDescription(StringUtils.substringBetween(spans.last().text(), "(", ")") + lesson.setDescription(StringUtils.defaultString(StringUtils.substringBetween( + spans.last().text(), "(", ")"), spans.last().text()) + " (poprzednio: " + getLessonAndGroupInfoFromSpan(spans.get(0))[0] + ")"); } else if (4 <= spans.size()) { lesson.setSubject(spans.get(0).text()); lesson.setTeacher(spans.get(1).text()); lesson.setRoom(spans.get(2).text()); - lesson.setDescription(StringUtils.substringBetween(spans.last().text(), "(", ")")); + lesson.setDescription(StringUtils.defaultString(StringUtils.substringBetween( + spans.last().text(), "(", ")"), spans.last().text())); } } @@ -212,7 +219,8 @@ public class Timetable { return new String[]{ span.text().replace(" " + groupName, ""), - StringUtils.substringBetween(groupName, "[", "]") + StringUtils.defaultString(StringUtils.substringBetween( + groupName, "[", "]"), groupName) }; } } diff --git a/api/src/test/java/io/github/wulkanowy/api/timetable/TimetableTest.java b/api/src/test/java/io/github/wulkanowy/api/timetable/TimetableTest.java index d7df9411..818745f7 100644 --- a/api/src/test/java/io/github/wulkanowy/api/timetable/TimetableTest.java +++ b/api/src/test/java/io/github/wulkanowy/api/timetable/TimetableTest.java @@ -151,6 +151,7 @@ public class TimetableTest extends StudentAndParentTestCase { Assert.assertEquals("zastępstwo (poprzednio: Wychowanie fizyczne)", full.getWeekTable().getDay(3).getLesson(1).getDescription()); Assert.assertEquals("", full.getWeekTable().getDay(4).getLesson(0).getDescription()); Assert.assertEquals("", full.getWeekTable().getDay(4).getLesson(1).getDescription()); + Assert.assertEquals("bez nawiasów (poprzednio: Religia)", full.getWeekTable().getDay(4).getLesson(3).getDescription()); Assert.assertEquals("poprzednio: Wychowanie fizyczne", full.getWeekTable().getDay(4).getLesson(2).getDescription()); Assert.assertEquals("egzamin", full.getWeekTable().getDay(3).getLesson(0).getDescription()); Assert.assertEquals("", full.getWeekTable().getDay(4).getLesson(1).getDescription()); diff --git a/api/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-full.html b/api/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-full.html index c7dcef2e..4bce6c93 100644 --- a/api/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-full.html +++ b/api/src/test/resources/io/github/wulkanowy/api/timetable/PlanLekcji-full.html @@ -3,6 +3,40 @@ Witryna ucznia i rodzica – Plan lekcji +
@@ -238,7 +272,17 @@ - + +
+ Religia + Cyranka Krystian + 3 + Wychowanie do życia w rodzinie + Nowak Jadwiga + 3 + bez nawiasów +
+ 4