diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleAPIRestTemplate.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleAPIRestTemplate.java index 6dfb31d1..96329d68 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleAPIRestTemplate.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleAPIRestTemplate.java @@ -60,11 +60,11 @@ public interface MoodleAPIRestTemplate { /** This maps a Moodle warning JSON object */ @JsonIgnoreProperties(ignoreUnknown = true) - static final class Warning { - final String item; - final String itemid; - final String warningcode; - final String message; + final class Warning { + public final String item; + public final String itemid; + public final String warningcode; + public final String message; @JsonCreator public Warning( diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleUtils.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleUtils.java index bfb08287..9fe1ed57 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleUtils.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleUtils.java @@ -560,4 +560,21 @@ public abstract class MoodleUtils { } } + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class FullConnectionApplyResponse { + @JsonProperty("success") + public final int success; + @JsonProperty("warnings") + public final Collection warnings; + + @JsonCreator + public FullConnectionApplyResponse( + @JsonProperty("success") final int success, + @JsonProperty("warnings") final Collection warnings) { + + this.success = success; + this.warnings = warnings; + } + } + } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginFullIntegration.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginFullIntegration.java index 602b2ed5..e56542f3 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginFullIntegration.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginFullIntegration.java @@ -11,6 +11,7 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl.moodle.plugin; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Objects; import ch.ethz.seb.sebserver.gbl.api.APIMessage; import ch.ethz.seb.sebserver.gbl.api.JSONMapper; @@ -131,6 +132,28 @@ public class MoodlePluginFullIntegration implements FullLmsIntegrationAPI { throw new MoodleResponseException("Failed to apply SEB Server connection: " + lmsSetup, response); } + try { + final MoodleUtils.FullConnectionApplyResponse fullConnectionApplyResponse = jsonMapper.readValue( + response, + MoodleUtils.FullConnectionApplyResponse.class); + + if (fullConnectionApplyResponse.success == 0 && !fullConnectionApplyResponse.warnings.isEmpty()) { + fullConnectionApplyResponse.warnings.stream() + .filter(w -> Objects.equals(w.warningcode, "connectiondoesntmatch")) + .findFirst() + .ifPresent( w -> { + + throw new MoodleResponseException("Failed to apply SEB Server connection due to connection mismatch", response); + }); + } + + if (log.isDebugEnabled()) { + log.debug("Got warnings from Moodle: {}", response); + } + } catch (final Exception e) { + log.warn("Failed to parse Moodle warnings. Error: {}", e.getMessage()); + } + if (log.isDebugEnabled()) { log.debug("Successfully applied SEB Server connection for Moodle. Connection data: {} LMS Setup: {}", data, lmsSetup); } @@ -184,6 +207,10 @@ public class MoodlePluginFullIntegration implements FullLmsIntegrationAPI { log.warn("Failed to apply Exam data to moodle: {}", examData); } + if (response != null && (response.startsWith("{\"warnings\":"))) { + log.info("Moodle warnings in response: {}", response); + } + return examData; }); } @@ -216,6 +243,10 @@ public class MoodlePluginFullIntegration implements FullLmsIntegrationAPI { log.warn("Failed to apply Connection Configuration to LMS for Exam: {}", exam.externalId); } + if (response != null && (response.startsWith("{\"warnings\":"))) { + log.info("Moodle warnings in response: {}", response); + } + return exam; }); } @@ -243,10 +274,14 @@ public class MoodlePluginFullIntegration implements FullLmsIntegrationAPI { null, queryAttributes); - if (response.startsWith("{\"exception\":")) { + if (response != null && response.startsWith("{\"exception\":")) { throw new MoodleResponseException("Failed to delete SEB Server connection: " + lmsSetup, response); } + if (response != null && (response.startsWith("{\"warnings\":"))) { + log.info("Moodle warnings in response: {}", response); + } + log.info("Successfully deleted SEB Server connection for Moodle. LMS Setup: {}", lmsSetup); return response; }); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java index b4aa5b18..a4a0e8c2 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java @@ -445,21 +445,6 @@ class ExamUpdateHandler implements ExamUpdateTask { } } -// if (quizData.additionalAttributes != null && !quizData.additionalAttributes.isEmpty()) { -// for (final Map.Entry attr : quizData.additionalAttributes.entrySet()) { -// final String currentAttrValue = exam.getAdditionalAttribute(attr.getKey()); -// if (!Utils.isEqualsWithEmptyCheck(currentAttrValue, attr.getValue())) { -// if (log.isDebugEnabled()) { -// log.debug("Update difference from LMS: attribute{}, currentValue: {}, lmsValue: {}", -// attr.getKey(), -// currentAttrValue, -// attr.getValue()); -// } -// return true; -// } -// } -// } - return false; }