SEBSERV-417 improved error and waning handling and logging

This commit is contained in:
anhefti 2024-06-06 13:50:07 +02:00
parent 05d6cdaf21
commit 07391430c4
4 changed files with 58 additions and 21 deletions

View file

@ -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(

View file

@ -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<Warning> warnings;
@JsonCreator
public FullConnectionApplyResponse(
@JsonProperty("success") final int success,
@JsonProperty("warnings") final Collection<Warning> warnings) {
this.success = success;
this.warnings = warnings;
}
}
}

View file

@ -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;
});

View file

@ -445,21 +445,6 @@ class ExamUpdateHandler implements ExamUpdateTask {
}
}
// if (quizData.additionalAttributes != null && !quizData.additionalAttributes.isEmpty()) {
// for (final Map.Entry<String, String> 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;
}