From d5d119fe7d8042170a44279a958aeee2b1090e33 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 18 Oct 2022 10:48:11 +0200 Subject: [PATCH] prevent empty additional attributes from being saved --- .../servicelayer/dao/impl/ExamDAOImpl.java | 20 ++++++++++++------- 1 file changed, 13 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 dd17c5ff..847490b8 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 @@ -742,14 +742,20 @@ public class ExamDAOImpl implements ExamDAO { private QuizData saveAdditionalQuizAttributes(final Long examId, final QuizData quizData) { final Map additionalAttributes = new HashMap<>(quizData.getAdditionalAttributes()); - additionalAttributes.put(QuizData.QUIZ_ATTR_DESCRIPTION, quizData.description); - additionalAttributes.put(QuizData.QUIZ_ATTR_START_URL, quizData.startURL); + if (StringUtils.isNotBlank(quizData.description)) { + additionalAttributes.put(QuizData.QUIZ_ATTR_DESCRIPTION, quizData.description); + } + if (StringUtils.isNotBlank(quizData.startURL)) { + additionalAttributes.put(QuizData.QUIZ_ATTR_START_URL, quizData.startURL); + } - this.additionalAttributesDAO.saveAdditionalAttributes( - EntityType.EXAM, - examId, - additionalAttributes) - .getOrThrow(); + if (!additionalAttributes.isEmpty()) { + this.additionalAttributesDAO.saveAdditionalAttributes( + EntityType.EXAM, + examId, + additionalAttributes) + .getOrThrow(); + } return quizData; }