From 8828b2f4e82e0b487b16417831b006d184e00e11 Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 14 Nov 2022 16:24:58 +0100 Subject: [PATCH] Fixed Exam quiz data update for additional attributes (delete null) --- .../servicelayer/dao/impl/ExamDAOImpl.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java index 847490b8..d1600902 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java @@ -749,13 +749,24 @@ public class ExamDAOImpl implements ExamDAO { additionalAttributes.put(QuizData.QUIZ_ATTR_START_URL, quizData.startURL); } - if (!additionalAttributes.isEmpty()) { - this.additionalAttributesDAO.saveAdditionalAttributes( - EntityType.EXAM, - examId, - additionalAttributes) - .getOrThrow(); - } + additionalAttributes.entrySet().forEach(entry -> { + final String value = entry.getValue(); + if (value == null) { + this.additionalAttributesDAO.delete( + EntityType.EXAM, + examId, + entry.getKey()); + } else { + this.additionalAttributesDAO.saveAdditionalAttribute( + EntityType.EXAM, + examId, + entry.getKey(), + value) + .onError(error -> log.error("Failed to save additional quiz attribute: {}", + entry.getKey(), + error)); + } + }); return quizData; }