fixed exam update additional quiz attributes

This commit is contained in:
anhefti 2024-06-06 12:09:22 +02:00
parent 0dd70f3ff4
commit 05d6cdaf21

View file

@ -16,6 +16,7 @@ import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import ch.ethz.seb.sebserver.gbl.api.JSONMapper;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -62,6 +63,7 @@ class ExamUpdateHandler implements ExamUpdateTask {
private final SEBRestrictionService sebRestrictionService; private final SEBRestrictionService sebRestrictionService;
private final LmsAPIService lmsAPIService; private final LmsAPIService lmsAPIService;
private final ScreenProctoringService screenProctoringService; private final ScreenProctoringService screenProctoringService;
private final JSONMapper jsonMapper;
private final String updatePrefix; private final String updatePrefix;
private final Long examTimePrefix; private final Long examTimePrefix;
private final Long examTimeSuffix; private final Long examTimeSuffix;
@ -74,6 +76,7 @@ class ExamUpdateHandler implements ExamUpdateTask {
final ApplicationEventPublisher applicationEventPublisher, final ApplicationEventPublisher applicationEventPublisher,
final SEBRestrictionService sebRestrictionService, final SEBRestrictionService sebRestrictionService,
final LmsAPIService lmsAPIService, final LmsAPIService lmsAPIService,
final JSONMapper jsonMapper,
final WebserviceInfo webserviceInfo, final WebserviceInfo webserviceInfo,
final ScreenProctoringService screenProctoringService, final ScreenProctoringService screenProctoringService,
@Value("${sebserver.webservice.api.exam.time-prefix:3600000}") final Long examTimePrefix, @Value("${sebserver.webservice.api.exam.time-prefix:3600000}") final Long examTimePrefix,
@ -86,6 +89,7 @@ class ExamUpdateHandler implements ExamUpdateTask {
this.applicationEventPublisher = applicationEventPublisher; this.applicationEventPublisher = applicationEventPublisher;
this.sebRestrictionService = sebRestrictionService; this.sebRestrictionService = sebRestrictionService;
this.lmsAPIService = lmsAPIService; this.lmsAPIService = lmsAPIService;
this.jsonMapper = jsonMapper;
this.screenProctoringService = screenProctoringService; this.screenProctoringService = screenProctoringService;
this.updatePrefix = webserviceInfo.getLocalHostAddress() this.updatePrefix = webserviceInfo.getLocalHostAddress()
+ "_" + webserviceInfo.getServerPort() + "_"; + "_" + webserviceInfo.getServerPort() + "_";
@ -428,20 +432,34 @@ class ExamUpdateHandler implements ExamUpdateTask {
} }
if (quizData.additionalAttributes != null && !quizData.additionalAttributes.isEmpty()) { if (quizData.additionalAttributes != null && !quizData.additionalAttributes.isEmpty()) {
for (final Map.Entry<String, String> attr : quizData.additionalAttributes.entrySet()) { String additionalQuizData = null;
final String currentAttrValue = exam.getAdditionalAttribute(attr.getKey()); try {
if (!Utils.isEqualsWithEmptyCheck(currentAttrValue, attr.getValue())) { additionalQuizData = jsonMapper.writeValueAsString(quizData.getAdditionalAttributes());
if (log.isDebugEnabled()) { } catch (final Exception ignored) {}
log.debug("Update difference from LMS: attribute{}, currentValue: {}, lmsValue: {}",
attr.getKey(), if (additionalQuizData != null) {
currentAttrValue, final String _quizData = exam.getAdditionalAttribute(Exam.ADDITIONAL_ATTR_QUIZ_ATTRIBUTES);
attr.getValue()); if (!additionalQuizData.equals(_quizData)) {
}
return true; return true;
} }
} }
} }
// 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; return false;
} }