From 2176c312df67e632f9cf576d3c59ffbf6c3125d2 Mon Sep 17 00:00:00 2001
From: agrt56 <andreas.gaertner@mni.thm.de>
Date: Tue, 28 Jul 2015 18:03:13 +0200
Subject: [PATCH] Add possibility to request question list with image data.

---
 .../controller/LecturerQuestionController.java       |  3 +++
 src/main/java/de/thm/arsnova/dao/CouchDBDao.java     |  4 ----
 .../de/thm/arsnova/services/IQuestionService.java    |  2 ++
 .../de/thm/arsnova/services/QuestionService.java     | 12 ++++++++++++
 4 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/main/java/de/thm/arsnova/controller/LecturerQuestionController.java b/src/main/java/de/thm/arsnova/controller/LecturerQuestionController.java
index fb6a306bd..9a63ae717 100644
--- a/src/main/java/de/thm/arsnova/controller/LecturerQuestionController.java
+++ b/src/main/java/de/thm/arsnova/controller/LecturerQuestionController.java
@@ -236,6 +236,7 @@ public class LecturerQuestionController extends PaginationController {
 			@RequestParam(value = "lecturequestionsonly", defaultValue = "false") final boolean lectureQuestionsOnly,
 			@RequestParam(value = "flashcardsonly", defaultValue = "false") final boolean flashcardsOnly,
 			@RequestParam(value = "preparationquestionsonly", defaultValue = "false") final boolean preparationQuestionsOnly,
+			@RequestParam(value = "requestImageData", defaultValue = "false") final boolean requestImageData,
 			final HttpServletResponse response
 			) {
 		List<Question> questions;
@@ -251,6 +252,8 @@ public class LecturerQuestionController extends PaginationController {
 		if (questions == null || questions.isEmpty()) {
 			response.setStatus(HttpStatus.NO_CONTENT.value());
 			return null;
+		} else if (!requestImageData) {
+			questions = questionService.replaceImageData(questions);
 		}
 
 		return new PaginationListDecorator<Question>(questions, offset, limit);
diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
index 769ee7457..a9385e8ee 100644
--- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
+++ b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
@@ -1641,10 +1641,6 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
 				question.setPiRound(1);
 			}
 
-			if (question.getImage() != null) {
-				question.setImage("true");
-			}
-
 			questions.add(question);
 		}
 		return questions;
diff --git a/src/main/java/de/thm/arsnova/services/IQuestionService.java b/src/main/java/de/thm/arsnova/services/IQuestionService.java
index 92df798ca..b44a2f267 100644
--- a/src/main/java/de/thm/arsnova/services/IQuestionService.java
+++ b/src/main/java/de/thm/arsnova/services/IQuestionService.java
@@ -171,4 +171,6 @@ public interface IQuestionService {
 
 	String getQuestionFcImage(String questionId);
 
+	List<Question> replaceImageData(List<Question> questions);
+
 }
diff --git a/src/main/java/de/thm/arsnova/services/QuestionService.java b/src/main/java/de/thm/arsnova/services/QuestionService.java
index 2ec056efd..c993f4ab9 100644
--- a/src/main/java/de/thm/arsnova/services/QuestionService.java
+++ b/src/main/java/de/thm/arsnova/services/QuestionService.java
@@ -847,6 +847,18 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis
 		}
 	}
 
+	@Override
+	@PreAuthorize("isAuthenticated()")
+	public List<Question> replaceImageData(final List<Question> questions) {
+		for (Question q : questions) {
+			if (q.getImage() != null) {
+				q.setImage("true");
+			}
+		}
+
+		return questions;
+	}
+
 	private Session getSession(final String sessionkey) {
 		final Session session = databaseDao.getSessionFromKeyword(sessionkey);
 		if (session == null) {
-- 
GitLab