GitLab wurde aktualisiert. Dank regelmäßiger Updates bleibt das THM GitLab sicher und Sie profitieren von den neuesten Funktionen. Vielen Dank für Ihre Geduld.

Commit 87fb504f authored by Christoph Thelen's avatar Christoph Thelen
Browse files

Task #3918: Receive and store a question object

parent 4ad3216e
......@@ -53,6 +53,7 @@ import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.services.ISessionService;
import de.thm.arsnova.services.IUserService;
import de.thm.arsnova.socket.message.Question;
@Component
public class CouchDBDao implements IDatabaseDao {
......@@ -145,17 +146,7 @@ public class CouchDBDao implements IDatabaseDao {
@Override
public Session getSession(String keyword) {
View view = new View("session/by_keyword");
view.setKey(URLEncoder.encode("\"" + keyword + "\""));
ViewResults results = this.getDatabase().view(view);
if (results.getJSONArray("rows").optJSONObject(0) == null)
return null;
Session result = (Session) JSONObject.toBean(
results.getJSONArray("rows").optJSONObject(0)
.optJSONObject("value"), Session.class);
Session result = this.getSessionFromKeyword(keyword);
if (result.isActive() || result.getCreator().equals(this.actualUserName())) {
sessionService.addUserToSessionMap(this.actualUserName(), keyword);
return result;
......@@ -164,6 +155,23 @@ public class CouchDBDao implements IDatabaseDao {
return null;
}
@Override
public Session getSessionFromKeyword(String keyword) {
try {
View view = new View("session/by_keyword");
view.setKey(URLEncoder.encode("\"" + keyword + "\"", "UTF-8"));
ViewResults results = this.getDatabase().view(view);
if (results.getJSONArray("rows").optJSONObject(0) == null)
return null;
return (Session) JSONObject.toBean(
results.getJSONArray("rows").optJSONObject(0).optJSONObject("value"), Session.class);
} catch (UnsupportedEncodingException e) {
return null;
}
}
@Override
public Session saveSession(Session session) {
......@@ -373,4 +381,25 @@ public class CouchDBDao implements IDatabaseDao {
return database;
}
@Override
public boolean saveQuestion(Session session, Question question) {
Document q = new Document();
q.put("type", "skill_question");
q.put("questionType", question.getQuestionType());
q.put("sessionId", session.get_id());
q.put("subject", question.getSubject());
q.put("text", question.getText());
q.put("active", question.isActive());
q.put("number", 0); // TODO: This number has to get incremented automatically
q.put("releasedFor", question.getReleasedFor());
q.put("possibleAnswers", question.getPossibleAnswers());
q.put("noCorrect", question.isNoCorrect());
try {
database.saveDocument(q);
} catch (IOException e) {
logger.error("Could not save question {}", question);
}
return false;
}
}
......@@ -22,12 +22,16 @@ package de.thm.arsnova.dao;
import de.thm.arsnova.entities.Feedback;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.socket.message.Question;
public interface IDatabaseDao {
public void cleanFeedbackVotes(int cleanupFeedbackDelay);
public Session getSessionFromKeyword(String keyword);
public Session getSession(String keyword);
public Session saveSession(Session session);
public Feedback getFeedback(String keyword);
public boolean saveFeedback(String keyword, int value, User user);
public boolean sessionKeyAvailable(String keyword);
public boolean saveQuestion(Session session, Question question);
}
\ No newline at end of file
......@@ -67,7 +67,12 @@ public class Session {
this.active = active;
}
public void set_id(String id) {}
public void set_rev(String rev) {}
public void set_id(String id) {
_id = id;
}
public String get_id() {
return _id;
}
public void set_rev(String rev) {}
}
......@@ -27,6 +27,8 @@ import de.thm.arsnova.entities.Feedback;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.socket.message.Question;
public interface ISessionService {
......@@ -41,4 +43,6 @@ public interface ISessionService {
public boolean isUserInSession(User user, String keyword);
public List<String> getUsersInSession(String keyword);
public void broadcastFeedbackChanges(Map<String, Set<String>> affectedUsers, Set<String> allAffectedSessions);
public boolean saveQuestion(Question question);
}
\ No newline at end of file
......@@ -38,6 +38,7 @@ import de.thm.arsnova.entities.Feedback;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.socket.ARSnovaSocketIOServer;
import de.thm.arsnova.socket.message.Question;
@Service
public class SessionService implements ISessionService {
......@@ -141,4 +142,10 @@ public class SessionService implements ISessionService {
if (this.sessionKeyAvailable(keyword)) return keyword;
return generateKeyword();
}
@Override
public boolean saveQuestion(Question question) {
Session session = this.databaseDao.getSessionFromKeyword(question.getSession());
return this.databaseDao.saveQuestion(session, question);
}
}
......@@ -25,6 +25,7 @@ import com.corundumstudio.socketio.listener.DisconnectListener;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.services.ISessionService;
import de.thm.arsnova.socket.message.Feedback;
import de.thm.arsnova.socket.message.Question;
public class ARSnovaSocketIOServer {
......@@ -95,9 +96,13 @@ public class ARSnovaSocketIOServer {
}
}
});
server.addEventListener("arsnova/question/create", Question.class, new DataListener<Question>(){
@Override
public void onData(SocketIOClient client, Question question) {
sessionService.saveQuestion(question);
}
});
server.addConnectListener(new ConnectListener() {
@Override
......
/*
* Copyright (C) 2012 THM webMedia
*
* This file is part of ARSnova.
*
* ARSnova is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.socket.message;
public class PossibleAnswer {
private String text;
private boolean correct;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public boolean isCorrect() {
return correct;
}
public void setCorrect(boolean correct) {
this.correct = correct;
}
@Override
public String toString() {
return "PossibleAnswer [text=" + text + ", correct=" + correct + "]";
}
}
/*
* Copyright (C) 2012 THM webMedia
*
* This file is part of ARSnova.
*
* ARSnova is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.socket.message;
import java.util.List;
public class Question {
private String questionType;
private String subject;
private String text;
private boolean active;
private String releasedFor;
private List<PossibleAnswer> possibleAnswers;
private boolean noCorrect;
private String session;
public String getQuestionType() {
return questionType;
}
public void setQuestionType(String questionType) {
this.questionType = questionType;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public String getReleasedFor() {
return releasedFor;
}
public void setReleasedFor(String releasedFor) {
this.releasedFor = releasedFor;
}
public List<PossibleAnswer> getPossibleAnswers() {
return possibleAnswers;
}
public void setPossibleAnswers(List<PossibleAnswer> possibleAnswers) {
this.possibleAnswers = possibleAnswers;
}
public boolean isNoCorrect() {
return noCorrect;
}
public void setNoCorrect(boolean noCorrect) {
this.noCorrect = noCorrect;
}
public String getSession() {
return session;
}
public void setSession(String session) {
this.session = session;
}
@Override
public String toString() {
return "Question type '" + this.questionType + "': " + this.subject + ";\n" + this.text;
}
}
Markdown is supported
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