From 3c5373ebc4241176a2e218368c46a4a5852852a4 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 17 Mar 2021 11:42:53 +0100 Subject: [PATCH] Prepared for new LMS Setups --- .../gbl/model/institution/LmsSetup.java | 7 +++-- .../gui/service/ResourceService.java | 29 +++++++++---------- .../config/application-dev-gui.properties | 5 ---- src/main/resources/messages.properties | 2 ++ 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/institution/LmsSetup.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/institution/LmsSetup.java index 9c8884cb..70a775b7 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/institution/LmsSetup.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/institution/LmsSetup.java @@ -39,14 +39,15 @@ public final class LmsSetup implements GrantEntity, Activatable { public enum Features { COURSE_API, - SEB_RESTRICTION, - COURSE_STRUCTURE_API, + SEB_RESTRICTION } public enum LmsType { MOCKUP(Features.COURSE_API), OPEN_EDX(Features.COURSE_API, Features.SEB_RESTRICTION), - MOODLE(Features.COURSE_API /* , Features.SEB_RESTRICTION */); + MOODLE(Features.COURSE_API /* , Features.SEB_RESTRICTION */), + ANS_DELFT(/* Features.COURSE_API , Features.SEB_RESTRICTION */), + OPEN_OLAT(/* Features.COURSE_API , Features.SEB_RESTRICTION */); public final EnumSet features; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java index 34632e10..8098140b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java @@ -18,13 +18,14 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.function.Function; +import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTimeZone; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Lazy; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; import ch.ethz.seb.sebserver.gbl.Constants; @@ -117,6 +118,8 @@ public class ResourceService { public static final String EXAM_PROCTORING_TYPE_PREFIX = "sebserver.exam.proctoring.type.servertype."; public static final String VDI_TYPE_PREFIX = "sebserver.clientconfig.form.vditype."; + private static final String DISABLE_LMS_FLAG = "sebserver.gui.webservice.lms.disable."; + public static final EnumSet ATTRIBUTE_TYPES_NOT_DISPLAYED = EnumSet.of( AttributeType.LABEL, AttributeType.COMPOSITE_TABLE, @@ -134,30 +137,24 @@ public class ResourceService { private final I18nSupport i18nSupport; private final RestService restService; private final CurrentUser currentUser; - private final EnumSet enabledLmsTypes; + private final EnumSet disabledLmsTypes; protected ResourceService( final I18nSupport i18nSupport, final RestService restService, final CurrentUser currentUser, - @Value("${sebserver.gui.webservice.mock-lms-enabled:true}") final boolean mock_lms_enabled, - @Value("${sebserver.gui.webservice.edx-lms-enabled:true}") final boolean edx_lms_enabled, - @Value("${sebserver.gui.webservice.moodle-lms-enabled:true}") final boolean moodle_lms_enabled) { + final Environment environment) { this.i18nSupport = i18nSupport; this.restService = restService; this.currentUser = currentUser; - this.enabledLmsTypes = EnumSet.noneOf(LmsType.class); - if (mock_lms_enabled) { - this.enabledLmsTypes.add(LmsType.MOCKUP); - } - if (edx_lms_enabled) { - this.enabledLmsTypes.add(LmsType.OPEN_EDX); - } - if (moodle_lms_enabled) { - this.enabledLmsTypes.add(LmsType.MOODLE); - } + this.disabledLmsTypes = EnumSet.noneOf(LmsType.class); + final List disabled = Arrays.asList(LmsType.values()).stream() + .filter(lmsType -> lmsType.features.isEmpty() || + environment.getProperty(DISABLE_LMS_FLAG + lmsType.name(), Boolean.class, false) == true) + .collect(Collectors.toList()); + this.disabledLmsTypes.addAll(disabled); } public I18nSupport getI18nSupport() { @@ -187,7 +184,7 @@ public class ResourceService { public List> lmsTypeResources() { return Arrays.stream(LmsType.values()) - .filter(this.enabledLmsTypes::contains) + .filter(Predicate.not(this.disabledLmsTypes::contains)) .map(lmsType -> new Tuple<>( lmsType.name(), this.i18nSupport.getText(LMSSETUP_TYPE_PREFIX + lmsType.name(), lmsType.name()))) diff --git a/src/main/resources/config/application-dev-gui.properties b/src/main/resources/config/application-dev-gui.properties index 4aaab9d3..8069b264 100644 --- a/src/main/resources/config/application-dev-gui.properties +++ b/src/main/resources/config/application-dev-gui.properties @@ -10,11 +10,6 @@ sebserver.gui.webservice.apipath=/admin-api/v1 # defines the polling interval that is used to poll the webservice for client connection data on a monitored exam page sebserver.gui.webservice.poll-interval=1000 -sebserver.gui.webservice.mock-lms-enabled=true -sebserver.gui.webservice.edx-lms-enabled=true -sebserver.gui.webservice.moodle-lms-enabled=true - - sebserver.gui.theme=css/sebserver.css sebserver.gui.list.page.size=15 diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 0be7961b..277a36e6 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -283,6 +283,8 @@ sebserver.useraccount.delete.confirm.message.noDeps=The User Account ({0}) was s sebserver.lmssetup.type.MOCKUP=Testing sebserver.lmssetup.type.MOODLE=Moodle sebserver.lmssetup.type.OPEN_EDX=Open edX +sebserver.lmssetup.type.ANS_DELFT=Ans Delft +sebserver.lmssetup.type.OPEN_OLAT=Open OLAT sebserver.lmssetup.list.actions= sebserver.lmssetup.list.action.no.modify.privilege=No Access: A LMS Setup from other institution cannot be modified.