adapt Moodle course filtering again

This commit is contained in:
anhefti 2020-12-15 19:38:32 +01:00
parent d3a794c5b1
commit 1c28aad328
5 changed files with 23 additions and 15 deletions

View file

@ -23,7 +23,6 @@
<revision>${sebserver-version}</revision> <revision>${sebserver-version}</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<file.encoding>UTF-8</file.encoding>
</properties> </properties>
<!-- NOTE: There currently are two profiles, a default one to build on <!-- NOTE: There currently are two profiles, a default one to build on
@ -80,7 +79,7 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration> <configuration>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
</configuration> </configuration>
</plugin> </plugin>

View file

@ -44,6 +44,7 @@ import ch.ethz.seb.sebserver.gbl.model.exam.QuizData;
import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup;
import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetupTestResult; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetupTestResult;
import ch.ethz.seb.sebserver.gbl.model.user.ExamineeAccountDetails; import ch.ethz.seb.sebserver.gbl.model.user.ExamineeAccountDetails;
import ch.ethz.seb.sebserver.gbl.util.Pair;
import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.gbl.util.Result;
import ch.ethz.seb.sebserver.gbl.util.Utils; import ch.ethz.seb.sebserver.gbl.util.Utils;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.FilterMap; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.FilterMap;
@ -220,22 +221,28 @@ public class MoodleCourseAccess extends CourseAccess {
final List<CourseData> result = new ArrayList<>(); final List<CourseData> result = new ArrayList<>();
int page = 0; int page = 0;
List<CourseData> quizzesBatch = getQuizzesBatch(restTemplate, filterMap, page); Pair<List<CourseData>, Integer> quizzesBatch = getQuizzesBatch(restTemplate, filterMap, page);
result.addAll(quizzesBatch); result.addAll(quizzesBatch.a);
log.info("Got quiz page batch for page {} with {} items", page, quizzesBatch.size()); log.info("Got quiz page batch for page {} of size {} with {} items",
page,
quizzesBatch.b,
quizzesBatch.a.size());
while (!quizzesBatch.isEmpty()) { while (quizzesBatch.b == null || quizzesBatch.b == 0) {
page++; page++;
quizzesBatch = getQuizzesBatch(restTemplate, filterMap, page); quizzesBatch = getQuizzesBatch(restTemplate, filterMap, page);
result.addAll(quizzesBatch); result.addAll(quizzesBatch.a);
log.info("Got quiz page batch for page {} with {} items", page, quizzesBatch.size()); log.info("Got quiz page batch for page {} of size {} with {} items",
page,
quizzesBatch.b,
quizzesBatch.a.size());
} }
return result; return result;
} }
private List<CourseData> getQuizzesBatch( private Pair<List<CourseData>, Integer> getQuizzesBatch(
final MoodleAPIRestTemplate restTemplate, final MoodleAPIRestTemplate restTemplate,
final FilterMap filterMap, final FilterMap filterMap,
final int page) { final int page) {
@ -246,14 +253,12 @@ public class MoodleCourseAccess extends CourseAccess {
? Utils.toUnixTimeInSeconds(filterMap.getQuizFromTime()) ? Utils.toUnixTimeInSeconds(filterMap.getQuizFromTime())
: Utils.toUnixTimeInSeconds(DateTime.now(DateTimeZone.UTC).minusYears(DEFAULT_FROM_YEARS)); : Utils.toUnixTimeInSeconds(DateTime.now(DateTimeZone.UTC).minusYears(DEFAULT_FROM_YEARS));
System.out.println("******************** fromTime=" + fromTime);
// first get courses from Moodle for page // first get courses from Moodle for page
final Map<String, CourseData> courseData = new HashMap<>(); final Map<String, CourseData> courseData = new HashMap<>();
final Collection<CourseData> coursesPage = getCoursesPage(restTemplate, fromTime, page, 100); final Collection<CourseData> coursesPage = getCoursesPage(restTemplate, fromTime, page, 100);
if (coursesPage.isEmpty()) { if (coursesPage.isEmpty()) {
return Collections.emptyList(); return new Pair<>(Collections.emptyList(), 0);
} }
courseData.putAll(coursesPage courseData.putAll(coursesPage
@ -283,13 +288,14 @@ public class MoodleCourseAccess extends CourseAccess {
}); });
} }
return courseData.values() return new Pair<>(courseData.values()
.stream() .stream()
.filter(c -> !c.quizzes.isEmpty()) .filter(c -> !c.quizzes.isEmpty())
.collect(Collectors.toList()); .collect(Collectors.toList()),
coursesPage.size());
} catch (final Exception e) { } catch (final Exception e) {
log.error("Unexpected exception while trying to get course data: ", e); log.error("Unexpected exception while trying to get course data: ", e);
return Collections.emptyList(); return new Pair<>(Collections.emptyList(), 0);
} }
} }

View file

@ -39,6 +39,7 @@ import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.WebserviceURISer
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest( @SpringBootTest(
properties = "file.encoding=UTF-8",
classes = SEBServer.class, classes = SEBServer.class,
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@ActiveProfiles("test") @ActiveProfiles("test")

View file

@ -48,6 +48,7 @@ import ch.ethz.seb.sebserver.gbl.model.Entity;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest( @SpringBootTest(
properties = "file.encoding=UTF-8",
classes = SEBServer.class, classes = SEBServer.class,
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@ActiveProfiles("test") @ActiveProfiles("test")

View file

@ -60,6 +60,7 @@ import ch.ethz.seb.sebserver.webservice.weblayer.oauth.WebserviceResourceConfigu
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest( @SpringBootTest(
properties = "file.encoding=UTF-8",
classes = { SEBServer.class }, classes = { SEBServer.class },
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test") @ActiveProfiles("test")