diff --git a/src/main/java/org/bytedream/untis4j/Session.java b/src/main/java/org/bytedream/untis4j/Session.java index 320e150..a45885a 100755 --- a/src/main/java/org/bytedream/untis4j/Session.java +++ b/src/main/java/org/bytedream/untis4j/Session.java @@ -137,8 +137,8 @@ private T requestSender(UntisUtils.Method method, Respo /** * Checks if the same request is still in the {@link com.github.benmanes.caffeine.cache.LoadingCache} and if not, the request is sent to the server. - * - * + * + * * @param method the POST method * @param params params you want to send with the request * @param action lambda expression that gets called if the {@code method} is not in the cache manager @@ -711,10 +711,26 @@ public SchoolYears.SchoolYearObject getCurrentSchoolYear() throws IOException { * @since 1.0 */ public Timetable getTimetable(LocalDate start, LocalDate end, UntisUtils.ElementType elementType, int id) throws IOException { - HashMap params = UntisUtils.localDateToParams(start, end); - - params.put("type", String.valueOf(elementType.getElementType())); - params.put("id", String.valueOf(id)); + if (end.isBefore(start)) { + throw new DateTimeException("The end date must end after or on the same day as the start date"); + } + Map element = new HashMap<>(){{ + put("type", elementType.getElementType()); + put("id", id); + }}; + Map options = new HashMap<>() {{ + put("startDate", start.format(DateTimeFormatter.ofPattern("yyyyMMdd"))); + put("endDate", end.format(DateTimeFormatter.ofPattern("yyyyMMdd"))); + put("element", element); + put("onlyBaseTimetable", "False"); + put("showInfo","True"); + put("showSubstText", "True"); + put("showLsText", "True"); + put("showLsNumber", "True"); + put("showStudentgroup", "True"); + }}; + Map> params = new HashMap<>(); + params.put("options", options); return requestSender(UntisUtils.Method.GETTIMETABLE, params, response -> { JSONObject jsonResponse = response.getResponse(); @@ -841,7 +857,23 @@ public Timetable getTimetable(LocalDate start, LocalDate end, UntisUtils.Element String activityType = null; if (timetableInfos.has("activityType")) activityType = timetableInfos.getString("activityType"); - timetable.add(new Timetable.Lesson(LocalDate.parse(String.valueOf(timetableInfos.getInt("date")), DateTimeFormatter.ofPattern("yyyyMMdd")), + String info = null; + if (timetableInfos.has("info")) info = timetableInfos.getString("info"); + + String substText = null; + if (timetableInfos.has("substText")) substText = timetableInfos.getString("substText"); + + String lsText = null; + if (timetableInfos.has("lstext")) lsText = timetableInfos.getString("lstext"); + + Integer lsNumber = null; + if (timetableInfos.has("lsnumber")) lsNumber = timetableInfos.getInt("lsnumber"); + + String studentGroup = null; + if (timetableInfos.has("sg")) studentGroup = timetableInfos.getString("sg"); + + timetable.add(new Timetable.Lesson( + LocalDate.parse(String.valueOf(timetableInfos.getInt("date")), DateTimeFormatter.ofPattern("yyyyMMdd")), startTime, endTime, timeUnits.findByStartTime(startTime), @@ -854,7 +886,13 @@ public Timetable getTimetable(LocalDate start, LocalDate end, UntisUtils.Element subjects, originalSubjects, code, - activityType)); + activityType, + info, + substText, + lsText, + lsNumber, + studentGroup + )); } return timetable; diff --git a/src/main/java/org/bytedream/untis4j/responseObjects/Timetable.java b/src/main/java/org/bytedream/untis4j/responseObjects/Timetable.java index 429fee5..c32d045 100755 --- a/src/main/java/org/bytedream/untis4j/responseObjects/Timetable.java +++ b/src/main/java/org/bytedream/untis4j/responseObjects/Timetable.java @@ -719,6 +719,45 @@ public ArrayList getActivityTypes() { return activityTypes; } + public ArrayList getInfos() { + ArrayList infos = new ArrayList<>(); + + this.stream().map(Lesson::getInfo).forEach(infos::add); + + return infos; + } + + public ArrayList getSubstTexts() { + ArrayList substText = new ArrayList<>(); + + this.stream().map(Lesson::getSubstText).forEach(substText::add); + + return substText; + } + + public ArrayList getLsTexts() { + ArrayList lsTexts = new ArrayList<>(); + + this.stream().map(Lesson::getLsText).forEach(lsTexts::add); + + return lsTexts; + } + + public ArrayList getLsNumbers() { + ArrayList lsNumbers = new ArrayList<>(); + + this.stream().map(Lesson::getLsNumber).forEach(lsNumbers::add); + + return lsNumbers; + } + public ArrayList getStudentGroups() { + ArrayList studentGroups = new ArrayList<>(); + + this.stream().map(Lesson::getStudentGroup).forEach(studentGroups::add); + + return studentGroups; + } + /** * Class to get information about a lesson * @@ -741,6 +780,11 @@ public static class Lesson extends ResponseObject { private final Subjects originalSubjects; private final UntisUtils.LessonCode code; private final String activityType; + private final String info; + private final String substText; + private final String lsText; + private final Integer lsNumber; + private final String studentGroup; /** * Initialize the {@link Lesson} class @@ -759,6 +803,11 @@ public static class Lesson extends ResponseObject { * @param originalSubjects the original subjects if the subject has changed * @param code code of the lesson (normally null, {@link UntisUtils.LessonCode#CANCELLED} if the lesson is cancelled, {@code UntisUtils.LessonCode.IRREGULAR} if e.g. a lesson has been moved * @param activityType type of the lesson + * @param info info text of the lesson + * @param substText substitution text + * @param lsText ls text of the lesson + * @param lsNumber ls Number of the lesson + * @param studentGroup name of the studentGroup * @since 1.0 */ public Lesson(LocalDate date, @@ -774,7 +823,12 @@ public Lesson(LocalDate date, Subjects subjects, Subjects originalSubjects, UntisUtils.LessonCode code, - String activityType) { + String activityType, + String info, + String substText, + String lsText, + Integer lsNumber, + String studentGroup) { this.date = date; this.startTime = startTime; this.endTime = endTime; @@ -789,6 +843,11 @@ public Lesson(LocalDate date, this.originalSubjects = originalSubjects; this.code = code; this.activityType = activityType; + this.info = info; + this.substText = substText; + this.lsText = lsText; + this.lsNumber = lsNumber; + this.studentGroup = studentGroup; } /** @@ -931,6 +990,21 @@ public String getActivityType() { return activityType; } + public String getInfo() { + return info; + } + public String getSubstText() { + return substText; + } + public String getLsText() { + return lsText; + } + public Integer getLsNumber() { + return lsNumber; + } + public String getStudentGroup() { + return studentGroup; + } /** * Returns a json parsed string with all information * @@ -954,6 +1028,11 @@ public String toString() { classAsMap.put("startTime", startTime.format(DateTimeFormatter.ofPattern("HHmm"))); classAsMap.put("endTime", endTime.format(DateTimeFormatter.ofPattern("HHmm"))); classAsMap.put("activityType", activityType); + classAsMap.put("info", info); + classAsMap.put("substText", substText); + classAsMap.put("lsText", lsText); + classAsMap.put("lsNumber", lsNumber); + classAsMap.put("studentGroup", studentGroup); return new JSONObject(classAsMap).toString(); } }