|
8 | 8 |
|
9 | 9 | package ch.ethz.seb.sebserver.webservice.servicelayer.lms;
|
10 | 10 |
|
11 |
| -import java.util.List; |
12 | 11 | import java.util.Set;
|
13 |
| -import java.util.function.Function; |
14 | 12 | import java.util.function.Predicate;
|
15 |
| -import java.util.stream.Collectors; |
16 | 13 |
|
17 | 14 | import ch.ethz.seb.sebserver.gbl.util.Utils;
|
18 | 15 | import org.apache.commons.lang3.StringUtils;
|
|
22 | 19 | import ch.ethz.seb.sebserver.gbl.model.Page;
|
23 | 20 | import ch.ethz.seb.sebserver.gbl.model.exam.QuizData;
|
24 | 21 | import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup;
|
25 |
| -import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetupTestResult; |
26 | 22 | import ch.ethz.seb.sebserver.gbl.util.Result;
|
27 | 23 | import ch.ethz.seb.sebserver.webservice.servicelayer.dao.FilterMap;
|
28 | 24 | import org.slf4j.Logger;
|
@@ -100,41 +96,61 @@ static Predicate<QuizData> quizFilterPredicate(final FilterMap filterMap) {
|
100 | 96 | if (filterMap == null) {
|
101 | 97 | return q -> true;
|
102 | 98 | }
|
| 99 | + |
| 100 | + final Set<String> importedExams = filterMap.getImportedExamIds(); |
| 101 | + final DateTime now = DateTime.now(DateTimeZone.UTC); |
103 | 102 | final String name = filterMap.getQuizName();
|
104 | 103 | final DateTime from = filterMap.getQuizFromTime();
|
105 |
| - final DateTime now = DateTime.now(DateTimeZone.UTC); |
106 |
| - final Set<String> importedExams = filterMap.getImportedExamIds(); |
107 |
| - final Long dayStart = (from != null) ? from.withTime(0, 0, 0, 0).getMillis() : null; |
108 |
| - final Long dayEnd = (from != null) ? from.withTime(23, 59, 59, 0).getMillis() : null; |
109 | 104 |
|
110 |
| - |
111 |
| - log.info("***************** fromTime: " + from); |
112 |
| - log.info("***************** filter timestamps: dayStart: " + dayStart + " dayEnd: " + dayEnd); |
113 |
| - log.info("***************** filter dates UTC: dayStart: " + Utils.toDateTimeUTC( dayStart) + " dayEnd: " + Utils.toDateTimeUTC(dayEnd)); |
114 |
| - |
115 |
| - return q -> { |
116 |
| - final boolean nameFilter = StringUtils.isBlank(name) || (q.name != null && q.name.contains(name)); |
117 |
| - boolean startTimeFilter = true; |
118 |
| - if (dayStart != null) { |
| 105 | + if (from != null) { |
| 106 | + // this is the old way to search with due date |
| 107 | + return q -> { |
| 108 | + final boolean nameFilter = StringUtils.isBlank(name) || (q.name != null && q.name.contains(name)); |
| 109 | + final boolean startTimeFilter = q.startTime != null && (q.startTime.isEqual(from) || q.startTime.isAfter(from)); |
| 110 | + final DateTime endTime = now.isAfter(from) ? now : from; |
| 111 | + final boolean fromTimeFilter = q.endTime == null || endTime.isBefore(q.endTime); |
| 112 | + |
| 113 | + // SEBSERV-632 |
| 114 | + boolean imported = false; |
| 115 | + if (importedExams != null) { |
| 116 | + imported = importedExams.contains(q.id); |
| 117 | + } |
| 118 | + |
| 119 | + return nameFilter && (startTimeFilter || fromTimeFilter) && !imported; |
| 120 | + }; |
| 121 | + } else { |
| 122 | + // this is the new way with the filter date timestamp from the user input. |
| 123 | + // Unix timestamp from user selected date plus now time within the users day (users timezone) |
| 124 | + // this is tricky since we want to fins all in users day, that depends on users time-zone so we have to |
| 125 | + // convert the timestamp to a user timezone related date and then get the start and end of this user related date |
| 126 | + // and convert this back to UTC timestamp for from and to... so let's go: |
| 127 | + final Long quizFromTimeMillis = filterMap.getQuizFromTimeMillis(); |
| 128 | + final DateTimeZone userTimeZone = filterMap.getQuizFromUserTimeZone(); |
| 129 | + final DateTime dateTimeUTC = quizFromTimeMillis != null ? Utils.toDateTimeUTC(quizFromTimeMillis) : null; |
| 130 | + // this is the users date with now time within the users time zone. |
| 131 | + final DateTime userDate = (userTimeZone != null && dateTimeUTC != null) ? dateTimeUTC.withZone(userTimeZone) : dateTimeUTC; |
| 132 | + // now we use stat and end of the users date and time perspective and map it to UTC time stamps |
| 133 | + final Long dayStart = userDate != null ? userDate.withTime(0, 0, 0, 0).getMillis() : null; |
| 134 | + final Long dayEnd = userDate != null ? userDate.withTime(23, 59, 59, 0).getMillis(): null; |
| 135 | + |
| 136 | + log.info("***************** fromTime: " + from); |
| 137 | + log.info("***************** filter timestamps: dayStart: " + dayStart + " dayEnd: " + dayEnd); |
| 138 | + log.info("***************** filter dates UTC: dayStart: " + Utils.toDateTimeUTC( dayStart) + " dayEnd: " + Utils.toDateTimeUTC(dayEnd)); |
| 139 | + |
| 140 | + return q -> { |
| 141 | + final boolean nameFilter = StringUtils.isBlank(name) || (q.name != null && q.name.contains(name)); |
119 | 142 | final long quizStart = q.startTime.getMillis();
|
120 |
| - startTimeFilter = dayStart <= quizStart && dayEnd >= quizStart; |
121 |
| - } |
122 |
| - |
123 |
| - // SEBSERV-632 |
124 |
| - boolean imported = false; |
125 |
| - if (importedExams != null) { |
126 |
| - imported = importedExams.contains(q.id); |
127 |
| - } |
128 |
| - |
129 |
| - return nameFilter && startTimeFilter && !imported; |
130 |
| - |
131 |
| - // old filter wie due date |
132 |
| -// final boolean startTimeFilter = |
133 |
| -// from == null || (q.startTime != null && (q.startTime.isEqual(from) || q.startTime.isAfter(from))); |
134 |
| -// final DateTime endTime = now.isAfter(from) ? now : from; |
135 |
| -// final boolean fromTimeFilter = (endTime == null || q.endTime == null || endTime.isBefore(q.endTime)); |
136 |
| -// return nameFilter && (startTimeFilter || fromTimeFilter); |
137 |
| - }; |
| 143 | + final boolean startTimeFilter = dayStart == null || dayStart <= quizStart && dayEnd >= quizStart; |
| 144 | + |
| 145 | + // SEBSERV-632 |
| 146 | + boolean imported = false; |
| 147 | + if (importedExams != null) { |
| 148 | + imported = importedExams.contains(q.id); |
| 149 | + } |
| 150 | + |
| 151 | + return nameFilter && startTimeFilter && !imported; |
| 152 | + }; |
| 153 | + } |
138 | 154 | }
|
139 | 155 |
|
140 | 156 | }
|
0 commit comments