Skip to content

Commit a0dd8ca

Browse files
committed
SEBSERV-651 new request with timestamp old with date still in place
1 parent db00bbb commit a0dd8ca

File tree

6 files changed

+91
-35
lines changed

6 files changed

+91
-35
lines changed

src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/QuizData.java

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public final class QuizData implements GrantEntity {
3434

3535
public static final String FILTER_ATTR_QUIZ_NAME = "quiz_name";
3636
public static final String FILTER_ATTR_START_TIME = "start_timestamp";
37+
public static final String FILTER_ATTR_START_TIME_MILLIS = "start_timestamp_millis";
38+
public static final String FILTER_ATTR_START_TIME_USER_TIME_ZONE = "start_timestamp_uz";
3739
public static final String FILTER_ATTR_IMPORTED_EXAMS = "imported_exam_ids";
3840

3941
public static final String QUIZ_ATTR_ID = "quiz_id";

src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/FilterMap.java

+19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import org.apache.commons.lang3.StringUtils;
1414
import org.joda.time.DateTime;
15+
import org.joda.time.DateTimeZone;
1516
import org.springframework.util.LinkedMultiValueMap;
1617
import org.springframework.util.MultiValueMap;
1718

@@ -114,6 +115,24 @@ public String getLmsSetupType() {
114115
public DateTime getQuizFromTime() {
115116
return Utils.toDateTime(getString(QuizData.FILTER_ATTR_START_TIME));
116117
}
118+
119+
public Long getQuizFromTimeMillis() {
120+
final Long millis = getLong(QuizData.FILTER_ATTR_START_TIME_MILLIS);
121+
if (millis != null) {
122+
return millis;
123+
}
124+
125+
final DateTime quizFromTime = getQuizFromTime();
126+
if (quizFromTime != null) {
127+
return quizFromTime.getMillis();
128+
}
129+
130+
return null;
131+
}
132+
133+
public DateTimeZone getQuizFromUserTimeZone() {
134+
return getDateTimeZone(QuizData.FILTER_ATTR_START_TIME_USER_TIME_ZONE);
135+
}
117136

118137
public Set<String> getImportedExamIds() {
119138
final String uuids = getString(QuizData.FILTER_ATTR_IMPORTED_EXAMS);

src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/LmsAPIService.java

+51-35
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88

99
package ch.ethz.seb.sebserver.webservice.servicelayer.lms;
1010

11-
import java.util.List;
1211
import java.util.Set;
13-
import java.util.function.Function;
1412
import java.util.function.Predicate;
15-
import java.util.stream.Collectors;
1613

1714
import ch.ethz.seb.sebserver.gbl.util.Utils;
1815
import org.apache.commons.lang3.StringUtils;
@@ -22,7 +19,6 @@
2219
import ch.ethz.seb.sebserver.gbl.model.Page;
2320
import ch.ethz.seb.sebserver.gbl.model.exam.QuizData;
2421
import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup;
25-
import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetupTestResult;
2622
import ch.ethz.seb.sebserver.gbl.util.Result;
2723
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.FilterMap;
2824
import org.slf4j.Logger;
@@ -100,41 +96,61 @@ static Predicate<QuizData> quizFilterPredicate(final FilterMap filterMap) {
10096
if (filterMap == null) {
10197
return q -> true;
10298
}
99+
100+
final Set<String> importedExams = filterMap.getImportedExamIds();
101+
final DateTime now = DateTime.now(DateTimeZone.UTC);
103102
final String name = filterMap.getQuizName();
104103
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;
109104

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));
119142
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+
}
138154
}
139155

140156
}

src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/QuizController.java

+5
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ public Page<QuizData> getQuizPage(
102102
filterMap.putIfAbsent(API.PARAM_INSTITUTION_ID, String.valueOf(institutionId));
103103
}
104104

105+
// add users time zone for quiz start time search
106+
filterMap.putIfAbsent(
107+
QuizData.FILTER_ATTR_START_TIME_USER_TIME_ZONE,
108+
authorization.getUserService().getCurrentUser().getUserInfo(). getTimeZone().getID());
109+
105110
// add UUIDs of already imported quizzes to filter SEBSERV-632
106111
filterMap.putIfAbsent(
107112
QuizData.FILTER_ATTR_IMPORTED_EXAMS,

src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ public void testUsecase05_CreateLMSSetupMockup() {
709709
// check quizzes are available now
710710
quizPageCall = restService
711711
.getBuilder(GetQuizPage.class)
712+
//.withQueryParam(QuizData.FILTER_ATTR_START_TIME, Utils.toDateTimeUTC(0).toString(Constants.DEFAULT_DATE_TIME_FORMAT))
712713
.call();
713714
assertNotNull(quizPageCall);
714715
assertFalse(quizPageCall.hasError());
@@ -717,6 +718,7 @@ public void testUsecase05_CreateLMSSetupMockup() {
717718
// get again to complete
718719
quizPageCall = restService
719720
.getBuilder(GetQuizPage.class)
721+
//.withQueryParam(QuizData.FILTER_ATTR_START_TIME, Utils.toDateTimeUTC(0).toString(Constants.DEFAULT_DATE_TIME_FORMAT))
720722
.call();
721723
assertNotNull(quizPageCall);
722724
assertFalse(quizPageCall.hasError());
@@ -754,6 +756,7 @@ public void testUsecase05_CreateLMSSetupMockup() {
754756
// check quizzes are still available
755757
quizPageCall = restService
756758
.getBuilder(GetQuizPage.class)
759+
.withQueryParam(QuizData.FILTER_ATTR_START_TIME, Utils.toDateTimeUTC(0).toString(Constants.DEFAULT_DATE_TIME_FORMAT))
757760
.call();
758761
assertNotNull(quizPageCall);
759762
assertFalse(quizPageCall.hasError());
@@ -784,6 +787,7 @@ public void testUsecase05_CreateLMSSetupMockup() {
784787
// check quizzes are not available anymore
785788
quizPageCall = restService
786789
.getBuilder(GetQuizPage.class)
790+
.withQueryParam(QuizData.FILTER_ATTR_START_TIME, Utils.toDateTimeUTC(0).toString(Constants.DEFAULT_DATE_TIME_FORMAT))
787791
.call();
788792
assertNotNull(quizPageCall);
789793
assertFalse(quizPageCall.hasError());
@@ -850,6 +854,7 @@ public void testUsecase06_ImportExam() {
850854
// check quizzes are defines
851855
final Result<Page<QuizData>> quizPageCall = restService
852856
.getBuilder(GetQuizPage.class)
857+
.withQueryParam(QuizData.FILTER_ATTR_START_TIME, Utils.toDateTimeUTC(0).toString(Constants.DEFAULT_DATE_TIME_FORMAT))
853858
.call();
854859

855860
assertNotNull(quizPageCall);

src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/QuizDataTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
import static org.junit.Assert.*;
1212

13+
import ch.ethz.seb.sebserver.gbl.Constants;
14+
import ch.ethz.seb.sebserver.gbl.util.Utils;
15+
import org.joda.time.DateTime;
1316
import org.junit.Test;
1417
import org.springframework.http.HttpMethod;
1518
import org.springframework.http.HttpStatus;
@@ -54,6 +57,7 @@ public void testGetInstitutionalQuizPage() throws Exception {
5457
Page<QuizData> quizzes = new RestAPITestHelper()
5558
.withAccessToken(getSebAdminAccess())
5659
.withPath(API.QUIZ_DISCOVERY_ENDPOINT)
60+
.withAttribute(QuizData.FILTER_ATTR_START_TIME, Utils.toDateTimeUTC(0).toString(Constants.DEFAULT_DATE_TIME_FORMAT))
5761
.withExpectedStatus(HttpStatus.OK)
5862
.getAsObject(new TypeReference<Page<QuizData>>() {
5963
});
@@ -65,6 +69,7 @@ public void testGetInstitutionalQuizPage() throws Exception {
6569
quizzes = new RestAPITestHelper()
6670
.withAccessToken(getAdminInstitution2Access())
6771
.withPath(API.QUIZ_DISCOVERY_ENDPOINT)
72+
.withAttribute(QuizData.FILTER_ATTR_START_TIME, Utils.toDateTimeUTC(0).toString(Constants.DEFAULT_DATE_TIME_FORMAT))
6873
.withExpectedStatus(HttpStatus.OK)
6974
.getAsObject(new TypeReference<Page<QuizData>>() {
7075
});
@@ -85,6 +90,7 @@ public void testGetInstitutionalQuizPage() throws Exception {
8590
quizzes = new RestAPITestHelper()
8691
.withAccessToken(getSebAdminAccess())
8792
.withPath(API.QUIZ_DISCOVERY_ENDPOINT)
93+
.withAttribute(QuizData.FILTER_ATTR_START_TIME, Utils.toDateTimeUTC(0).toString(Constants.DEFAULT_DATE_TIME_FORMAT))
8894
.withExpectedStatus(HttpStatus.OK)
8995
.getAsObject(new TypeReference<Page<QuizData>>() {
9096
});
@@ -104,6 +110,7 @@ public void testGetInstitutionalQuizPage() throws Exception {
104110
quizzes = new RestAPITestHelper()
105111
.withAccessToken(getSebAdminAccess())
106112
.withPath(API.QUIZ_DISCOVERY_ENDPOINT)
113+
.withAttribute(QuizData.FILTER_ATTR_START_TIME, Utils.toDateTimeUTC(0).toString(Constants.DEFAULT_DATE_TIME_FORMAT))
107114
.withExpectedStatus(HttpStatus.OK)
108115
.getAsObject(new TypeReference<Page<QuizData>>() {
109116
});
@@ -115,6 +122,7 @@ public void testGetInstitutionalQuizPage() throws Exception {
115122
quizzes = new RestAPITestHelper()
116123
.withAccessToken(getAdminInstitution2Access())
117124
.withPath(API.QUIZ_DISCOVERY_ENDPOINT)
125+
.withAttribute(QuizData.FILTER_ATTR_START_TIME, Utils.toDateTimeUTC(0).toString(Constants.DEFAULT_DATE_TIME_FORMAT))
118126
.withExpectedStatus(HttpStatus.OK)
119127
.getAsObject(new TypeReference<Page<QuizData>>() {
120128
});
@@ -137,6 +145,7 @@ public void testGetQuiz() throws Exception {
137145
.withPath(API.QUIZ_DISCOVERY_ENDPOINT)
138146
.withPath("quiz1")
139147
.withAttribute(QuizData.QUIZ_ATTR_LMS_SETUP_ID, lmsSetup.getModelId())
148+
.withAttribute(QuizData.FILTER_ATTR_START_TIME, Utils.toDateTimeUTC(0).toString(Constants.DEFAULT_DATE_TIME_FORMAT))
140149
.withMethod(HttpMethod.GET)
141150
.withExpectedStatus(HttpStatus.OK)
142151
.getAsObject(new TypeReference<QuizData>() {

0 commit comments

Comments
 (0)