SEBSERV-150 fixed filtering

This commit is contained in:
anhefti 2020-12-17 18:04:28 +01:00
parent 7fcfcf1445
commit 9941d57d44
3 changed files with 21 additions and 7 deletions

View file

@ -246,7 +246,8 @@ public class QuizLookupList implements TemplateComposer {
}
private static Function<QuizData, String> quizDataLmsSetupNameFunction(final ResourceService resourceService) {
return quizData -> resourceService.getLmsSetupNameFunction()
final Function<String, String> lmsSetupNameFunction = resourceService.getLmsSetupNameFunction();
return quizData -> lmsSetupNameFunction
.apply(String.valueOf(quizData.lmsSetupId));
}

View file

@ -9,6 +9,7 @@
package ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -156,8 +157,16 @@ public class LmsAPIServiceImpl implements LmsAPIService {
// case 1. if lmsSetupId is available only get quizzes from specified LmsSetup
final Long lmsSetupId = filterMap.getLmsSetupId();
if (lmsSetupId != null) {
return getLmsAPITemplate(lmsSetupId)
.flatMap(template -> template.getQuizzes(filterMap))
final Long institutionId = filterMap.getInstitutionId();
final LmsAPITemplate template = getLmsAPITemplate(lmsSetupId)
.getOrThrow();
if (institutionId != null && template.lmsSetup().institutionId != institutionId) {
return Collections.emptyList();
}
return template
.getQuizzes(filterMap)
.getOrThrow();
}

View file

@ -10,6 +10,7 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl.moodle;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@ -33,7 +34,7 @@ public class MoodleLmsAPITemplateFactory {
private final AsyncService asyncService;
private final ClientCredentialService clientCredentialService;
private final ClientHttpRequestFactoryService clientHttpRequestFactoryService;
private final MoodleCourseDataLazyLoader moodleCourseDataLazyLoader;
private final ApplicationContext applicationContext;
private final String[] alternativeTokenRequestPaths;
protected MoodleLmsAPITemplateFactory(
@ -41,14 +42,14 @@ public class MoodleLmsAPITemplateFactory {
final AsyncService asyncService,
final ClientCredentialService clientCredentialService,
final ClientHttpRequestFactoryService clientHttpRequestFactoryService,
final MoodleCourseDataLazyLoader moodleCourseDataLazyLoader,
final ApplicationContext applicationContext,
@Value("${sebserver.webservice.lms.moodle.api.token.request.paths:}") final String alternativeTokenRequestPaths) {
this.jsonMapper = jsonMapper;
this.asyncService = asyncService;
this.clientCredentialService = clientCredentialService;
this.clientHttpRequestFactoryService = clientHttpRequestFactoryService;
this.moodleCourseDataLazyLoader = moodleCourseDataLazyLoader;
this.applicationContext = applicationContext;
this.alternativeTokenRequestPaths = (alternativeTokenRequestPaths != null)
? StringUtils.split(alternativeTokenRequestPaths, Constants.LIST_SEPARATOR)
: null;
@ -61,6 +62,9 @@ public class MoodleLmsAPITemplateFactory {
return Result.tryCatch(() -> {
final MoodleCourseDataLazyLoader lazyLoaderPrototype =
this.applicationContext.getBean(MoodleCourseDataLazyLoader.class);
final MoodleRestTemplateFactory moodleRestTemplateFactory = new MoodleRestTemplateFactory(
this.jsonMapper,
lmsSetup,
@ -74,7 +78,7 @@ public class MoodleLmsAPITemplateFactory {
this.jsonMapper,
lmsSetup,
moodleRestTemplateFactory,
this.moodleCourseDataLazyLoader,
lazyLoaderPrototype,
this.asyncService);
final MoodleCourseRestriction moodleCourseRestriction = new MoodleCourseRestriction(