Skip to content
Snippets Groups Projects
Commit 57c76399 authored by Tom Käsler's avatar Tom Käsler
Browse files

#14886 couchDB Functions nearly rdy, need to parse the json from db right

parent b85f02d9
Branches
Tags
No related merge requests found
...@@ -71,6 +71,7 @@ import de.thm.arsnova.entities.SessionInfo; ...@@ -71,6 +71,7 @@ import de.thm.arsnova.entities.SessionInfo;
import de.thm.arsnova.entities.Statistics; import de.thm.arsnova.entities.Statistics;
import de.thm.arsnova.entities.User; import de.thm.arsnova.entities.User;
import de.thm.arsnova.entities.VisitedSession; import de.thm.arsnova.entities.VisitedSession;
import de.thm.arsnova.entities.SortOrder;
import de.thm.arsnova.entities.transport.AnswerQueueElement; import de.thm.arsnova.entities.transport.AnswerQueueElement;
import de.thm.arsnova.entities.transport.ImportExportSession; import de.thm.arsnova.entities.transport.ImportExportSession;
import de.thm.arsnova.entities.transport.ImportExportSession.ImportExportQuestion; import de.thm.arsnova.entities.transport.ImportExportSession.ImportExportQuestion;
...@@ -1381,22 +1382,26 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware ...@@ -1381,22 +1382,26 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
@Cacheable("lecturequestions") @Cacheable("lecturequestions")
@Override @Override
public List<Question> getLectureQuestionsForUsers(final Session session) { public List<Question> getLectureQuestionsForUsers(final Session session) {
String viewName = "question_sort/lecture_question_by_session_sorted_for_all"; SortOrder sortOrder = getSortOrder(session, "lecture");
List<Question> result = getQuestions(new NovaView(viewName), session); if (sordOrder != null) {
if(result == null) { //get Questionds via sortOrder List<Question> result =
}
else {
String viewName = "skill_question/lecture_question_by_session_for_all"; String viewName = "skill_question/lecture_question_by_session_for_all";
result = getQuestions(new NovaView(viewName), session); List<Question> result = getQuestions(new NovaView(viewName), session);
} }
return result; return result;
} }
@Override @Override
public List<Question> getLectureQuestionsForTeachers(final Session session) { public List<Question> getLectureQuestionsForTeachers(final Session session) {
String viewName = "question_sort/lecture_question_by_session_sorted"; SortOrder sortOrder = getSortOrder(session, "lecture");
List<Question> result = getQuestions(new NovaView(viewName), session); if (sordOrder != null) {
if (result == null) { //get Questionds via sortOrder
}
else {
String viewName = "skill_question/lecture_question_by_session"; String viewName = "skill_question/lecture_question_by_session";
result = getQuestions(new NovaView(viewName), session); List<Question> result = getQuestions(new NovaView(viewName), session);
} }
return result; return result;
} }
...@@ -1417,22 +1422,25 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware ...@@ -1417,22 +1422,25 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
@Cacheable("preparationquestions") @Cacheable("preparationquestions")
@Override @Override
public List<Question> getPreparationQuestionsForUsers(final Session session) { public List<Question> getPreparationQuestionsForUsers(final Session session) {
String viewName = "question_sort/preparation_question_by_session_sorted_for_all"; SortOrder sortOrder = getSortOrder(session, "preparation");
List<Question> result = getQuestions(new NovaView(viewName), session); if (sordOrder != null) {
if (result == null) { //get Questionds via sortOrder
}
else {
String viewName = "skill_question/preparation_question_by_session_for_all"; String viewName = "skill_question/preparation_question_by_session_for_all";
result = getQuestions(new NovaView(viewName), session); return getQuestions(new NovaView(viewName), session);
} }
return result;
} }
@Override @Override
public List<Question> getPreparationQuestionsForTeachers(final Session session) { public List<Question> getPreparationQuestionsForTeachers(final Session session) {
String viewName = "question_sort/preparation_question_by_session_sorted"; SortOrder sortOrder = getSortOrder(session, "preparation");
List<Question> result = getQuestions(new NovaView(viewName), session); if (sordOrder != null) {
if (result == null) { //get Questionds via sortOrder
}
else {
String viewName = "skill_question/preparation_question_by_session"; String viewName = "skill_question/preparation_question_by_session";
result = getQuestions(new NovaView(viewName), session); return getQuestions(new NovaView(viewName), session);
} }
return result; return result;
} }
...@@ -1930,22 +1938,52 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware ...@@ -1930,22 +1938,52 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
return info; return info;
} }
@OVerride @Override
String getSaveOrderId(Session session) { SortOrder getSortOrder(Session session, String questionVariant) {
String view = "question_sort/get_id"; if ("preparation".equals(questionVariant)) {
String viewString = "sort_order/preparation_question_sort_order_by_session";
}
else if ("lecture".euals(questionVariant)) {
String viewString = "sort_order/lecture_question_sort_order_by_session";
}
NovaView view = new NovaView(viewString);
view.setKey(session.get_id());
ViewResults results = this.getDatabase().view(view);
if (results.getJSONArray("rows").optJSONObject(0) == null) {
return null;
}
return (SortOrder) JSONObject.toBean(
results.getJSONArray("rows").optJSONObject(0).optJSONObject("value"),
SortOrder.class
);
} }
@Override @Override
String saveQuestionSort(Session session, final String[] sortOrder) { SortOrder createOrUpdateQuestionSortOrder(Session session, SortOrder sortOrder) {
final Document a = new Document();
a.put("type", "question_sort");
a.put("sessionId", session.getSessionId());
a.put("sortOrder", sortOrder);
try { try {
database.saveDocument(a); String id = sortOrder.get_id();
} catch (final IOException e) { String rev = sortOrder.get_rev();
return null; Document d = new Document();
if (null != id) {
d = database.getDocument(id, rev);
}
d.put("type", "sort_order");
d.put("sessionId", session.get_id());
d.put("questionVariant", sortOrder.getQuestionVariant());
d.put("sortOrder", sortOrder.getSortOrder());
database.saveDocument(d, id);
sortOrder.setId(d.getId());
sortOrder.setRev(d.getRev());
return sotOrder;
} catch (IOException e) {
LOGGER.error("Could not save user {}", user);
} }
return sortOrder; return null;
} }
} }
...@@ -31,6 +31,7 @@ import de.thm.arsnova.entities.Session; ...@@ -31,6 +31,7 @@ import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.SessionInfo; import de.thm.arsnova.entities.SessionInfo;
import de.thm.arsnova.entities.Statistics; import de.thm.arsnova.entities.Statistics;
import de.thm.arsnova.entities.User; import de.thm.arsnova.entities.User;
import de.thm.arsnova.entities.SortOrder;
import de.thm.arsnova.entities.transport.ImportExportSession; import de.thm.arsnova.entities.transport.ImportExportSession;
public interface IDatabaseDao { public interface IDatabaseDao {
...@@ -197,7 +198,7 @@ public interface IDatabaseDao { ...@@ -197,7 +198,7 @@ public interface IDatabaseDao {
Statistics getStatistics(); Statistics getStatistics();
String getSaveOrderId(Session session); String getSortOrder(Session session, String questionVariant);
String saveQuestionSort(Session session, final String[] sortOrder); String createOrUpdateQuestionSortOrder(Session session, SortOrder sortOrder);
} }
...@@ -311,13 +311,5 @@ public class Session implements Serializable { ...@@ -311,13 +311,5 @@ public class Session implements Serializable {
Session other = (Session) obj; Session other = (Session) obj;
return this.keyword.equals(other.keyword); return this.keyword.equals(other.keyword);
} }
// Sorting
public boolean getSortLectureQuestions(){
return false;
}
// Sorting
public boolean getSortPreparationQuestions(){
return false;
}
} }
...@@ -17,115 +17,43 @@ ...@@ -17,115 +17,43 @@
*/ */
package de.thm.arsnova.entities; package de.thm.arsnova.entities;
public class Statistics { public class SortOrder {
private int answers; private String sortVariant;
private int lectureQuestions; private String[] sortOrder;
private int preparationQuestions;
private int openSessions;
private int closedSessions;
private int activeUsers;
private int loggedinUsers;
private int interposedQuestions;
public int getAnswers() { private String _id;
return answers; private String _rev;
}
public void setSortVariant(final String sortVariant) {
public void setAnswers(final int answers) { this.sortVariant = sortVariant;
this.answers = answers; }
}
public String getSortVariant() {
public int getLectureQuestions() { return this.sortVariant;
return lectureQuestions; }
}
public void setSortOrder(final String[] sortOrder) {
public void setLectureQuestions(final int questions) { this.sortOrder = sortOrder;
this.lectureQuestions = questions; }
}
public String[] getSortOrder() {
public int getPreparationQuestions() { return this.sortOrder;
return preparationQuestions; }
}
public void setPreparationQuestions(final int questions) {
this.preparationQuestions = questions;
}
public int getQuestions() {
return getLectureQuestions() + getPreparationQuestions();
}
public int getOpenSessions() {
return openSessions;
}
public void setOpenSessions(final int openSessions) {
this.openSessions = openSessions;
}
public int getClosedSessions() {
return closedSessions;
}
public void setClosedSessions(final int closedSessions) {
this.closedSessions = closedSessions;
}
public int getSessions() {
return getOpenSessions() + getClosedSessions();
}
public int getActiveUsers() {
return activeUsers;
}
public void setActiveUsers(final int activeUsers) {
this.activeUsers = activeUsers;
}
public int getLoggedinUsers() {
return loggedinUsers;
}
public void setLoggedinUsers(final int loggedinUsers) {
this.loggedinUsers = loggedinUsers;
}
public int getInterposedQuestions() { public void set_id(final String id) {
return interposedQuestions; _id = id;
} }
public void setInterposedQuestions(int interposedQuestions) { public String get_id() {
this.interposedQuestions = interposedQuestions; return _id;
} }
@Override public void set_rev(final String rev) {
public int hashCode() { _rev = rev;
return (this.getClass().getName()
+ activeUsers
+ answers
+ closedSessions
+ openSessions
+ lectureQuestions
+ preparationQuestions
+ interposedQuestions
+ loggedinUsers
).hashCode();
} }
@Override public String get_rev() {
public boolean equals(final Object obj) { return _rev;
if (obj == null) { }
return false;
}
if (obj == this) {
return true;
}
if (obj instanceof Statistics) {
final Statistics other = (Statistics) obj;
return hashCode() == other.hashCode();
}
return false;
}
} }
...@@ -44,6 +44,7 @@ import de.thm.arsnova.entities.InterposedReadingCount; ...@@ -44,6 +44,7 @@ import de.thm.arsnova.entities.InterposedReadingCount;
import de.thm.arsnova.entities.Question; import de.thm.arsnova.entities.Question;
import de.thm.arsnova.entities.Session; import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User; import de.thm.arsnova.entities.User;
import de.thm.arsnova.entities.SortOrder;
import de.thm.arsnova.events.DeleteAllLectureAnswersEvent; import de.thm.arsnova.events.DeleteAllLectureAnswersEvent;
import de.thm.arsnova.events.DeleteAllPreparationAnswersEvent; import de.thm.arsnova.events.DeleteAllPreparationAnswersEvent;
import de.thm.arsnova.events.DeleteAllQuestionsAnswersEvent; import de.thm.arsnova.events.DeleteAllQuestionsAnswersEvent;
...@@ -107,19 +108,6 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis ...@@ -107,19 +108,6 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis
} else if (question.getPiRound() < 1 || question.getPiRound() > 2) { } else if (question.getPiRound() < 1 || question.getPiRound() > 2) {
question.setPiRound(1); question.setPiRound(1);
} }
// if SortIndex false, list is sorted so new question is appended to sorted list with (highest sequenceNr)++
if ("lecture".equals(question.getQuestionVariant())) {
if(session.getSortLectureQuestions()) {
//Take a look at entities/Session.java
//question.setSequenceNo();
}
} else if ("preparation".equals(question.getQuestionVariant())) {
if(session.getSortPreparationQuestions()) {
//Take a look at entities/Session.java
//question.setSequenceNo();
}
}
// convert imageurl to base64 if neccessary // convert imageurl to base64 if neccessary
if ("grid".equals(question.getQuestionType())) { if ("grid".equals(question.getQuestionType())) {
...@@ -138,6 +126,12 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis ...@@ -138,6 +126,12 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis
throw new BadRequestException(); throw new BadRequestException();
} }
} }
SortOrder sortOrder = databaseDao.getSortOrder(session, question.getQuestionVariant);
if (sortOrder != null) {
}
final Question result = databaseDao.saveQuestion(session, question); final Question result = databaseDao.saveQuestion(session, question);
final NewQuestionEvent event = new NewQuestionEvent(this, session, result); final NewQuestionEvent event = new NewQuestionEvent(this, session, result);
......
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