Skip to content
Snippets Groups Projects
Commit bab0627f authored by Christoph Thelen's avatar Christoph Thelen
Browse files

Fixed #6620: Server API to open/close all questions of a session

parent 83df11ab
Branches
Tags
No related merge requests found
......@@ -99,6 +99,20 @@ public class LecturerQuestionController extends AbstractController {
}
this.questionService.update(question);
}
@RequestMapping(value = "/publish", method = RequestMethod.POST)
@ResponseBody
public final void publishAllQuestions(
@RequestParam final String sessionkey,
@RequestParam(required = false) final Boolean publish,
final HttpServletResponse response
) {
boolean p = true;
if (publish != null) {
p = publish;
}
this.questionService.publishAll(sessionkey, p);
}
@RequestMapping(value = "/{questionId}/publishstatistics", method = RequestMethod.POST)
@ResponseBody
......
......@@ -259,6 +259,19 @@ public class CouchDBDao implements IDatabaseDao {
@Override
public final Question saveQuestion(final Session session, final Question question) {
Document q = toQuestionDocument(session, question);
try {
database.saveDocument(q);
question.set_id(q.getId());
question.set_rev(q.getRev());
return question;
} catch (IOException e) {
LOGGER.error("Could not save question {}", question);
}
return null;
}
private Document toQuestionDocument(final Session session, final Question question) {
Document q = new Document();
q.put("type", "skill_question");
q.put("questionType", question.getQuestionType());
......@@ -275,15 +288,7 @@ public class CouchDBDao implements IDatabaseDao {
q.put("showStatistic", question.isShowStatistic());
q.put("showAnswer", question.isShowAnswer());
q.put("abstention", question.isAbstention());
try {
database.saveDocument(q);
question.set_id(q.getId());
question.set_rev(q.getRev());
return question;
} catch (IOException e) {
LOGGER.error("Could not save question {}", question);
}
return null;
return q;
}
@Override
......@@ -1305,4 +1310,24 @@ public class CouchDBDao implements IDatabaseDao {
}
}
}
@Override
public void publishAllQuestions(Session session, boolean publish) {
List<Question> questions = this.getQuestions(new NovaView("skill_question/by_session"), session);
for (Question q : questions) {
q.setActive(publish);
}
List<Document> documents = new ArrayList<Document>();
for (Question q : questions) {
Document d = toQuestionDocument(session, q);
d.setId(q.get_id());
d.setRev(q.get_rev());
documents.add(d);
}
try {
this.database.bulkSaveDocuments(documents.toArray(new Document[documents.size()]));
} catch (IOException e) {
LOGGER.error("Could not bulk publish all questions: {}", e.getMessage());
}
}
}
......@@ -157,4 +157,6 @@ public interface IDatabaseDao {
List<String> getUnAnsweredPreparationQuestionIds(Session session, User user);
void deleteAllInterposedQuestions(Session session);
void publishAllQuestions(Session session, boolean publish);
}
......@@ -107,4 +107,6 @@ public interface IQuestionService {
void deleteAllInterposedQuestions(String sessionKeyword);
void publishAll(String sessionkey, boolean publish);
}
......@@ -487,6 +487,7 @@ public class QuestionService implements IQuestionService {
}
@Override
@Authenticated
public List<String> getUnAnsweredLectureQuestionIds(String sessionkey) {
User user = getCurrentUser();
Session session = getSession(sessionkey);
......@@ -494,9 +495,21 @@ public class QuestionService implements IQuestionService {
}
@Override
@Authenticated
public List<String> getUnAnsweredPreparationQuestionIds(String sessionkey) {
User user = getCurrentUser();
Session session = getSession(sessionkey);
return databaseDao.getUnAnsweredPreparationQuestionIds(session, user);
}
@Override
@Authenticated
public void publishAll(String sessionkey, boolean publish) {
User user = getCurrentUser();
Session session = getSession(sessionkey);
if (!session.isCreator(user)) {
throw new ForbiddenException();
}
databaseDao.publishAllQuestions(session, publish);
}
}
......@@ -485,4 +485,10 @@ public class StubDatabaseDao implements IDatabaseDao {
public void deleteAllInterposedQuestions(Session session) {
// TODO Auto-generated method stub
}
@Override
public void publishAllQuestions(Session session, boolean publish) {
// TODO Auto-generated method stub
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment