Skip to content
Snippets Groups Projects
Commit 6b5cf7a7 authored by Julian Hochstetter's avatar Julian Hochstetter
Browse files

remove sort parameter

parent 26b343e9
Branches
Tags
No related merge requests found
......@@ -92,8 +92,8 @@ public class QuestionController extends AbstractController {
method=RequestMethod.GET
)
@ResponseBody
public List<Question> getSkillQuestions(@PathVariable String sessionkey, @RequestParam(value="sort", required=false) String sort, HttpServletResponse response) {
List<Question> questions = sessionService.getSkillQuestions(sessionkey, sort);
public List<Question> getSkillQuestions(@PathVariable String sessionkey, HttpServletResponse response) {
List<Question> questions = sessionService.getSkillQuestions(sessionkey);
if(questions == null || questions.isEmpty()) {
response.setStatus(HttpStatus.NOT_FOUND.value());
return null;
......
......@@ -34,14 +34,19 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import de.thm.arsnova.entities.Feedback;
import de.thm.arsnova.entities.Question;
import de.thm.arsnova.entities.LoggedIn;
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.ARSnovaSocketIOServer;
@Controller
public class SessionController extends AbstractController {
......@@ -74,6 +79,20 @@ public class SessionController extends AbstractController {
return sessionService.joinSession(sessionkey);
}
@RequestMapping(value="/session/{sessionkey}/online", method=RequestMethod.POST)
@ResponseBody
public LoggedIn registerAsOnlineUser(@PathVariable String sessionkey, HttpServletResponse response) {
User user = userService.getCurrentUser();
LoggedIn loggedIn = sessionService.registerAsOnlineUser(user, sessionkey);
if (loggedIn != null) {
response.setStatus(HttpStatus.CREATED.value());
return loggedIn;
}
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
return null;
}
@RequestMapping(value="/session", method=RequestMethod.POST)
@ResponseBody
public Session postNewSession(@RequestBody Session session, HttpServletResponse response) {
......@@ -87,6 +106,7 @@ public class SessionController extends AbstractController {
return null;
}
@RequestMapping(value="/socketurl", method=RequestMethod.GET)
@ResponseBody
public String getSocketUrl() {
......@@ -113,4 +133,5 @@ public class SessionController extends AbstractController {
}
return sessions;
}
}
......@@ -34,11 +34,15 @@ import java.util.Set;
import net.sf.ezmorph.Morpher;
import net.sf.ezmorph.MorpherRegistry;
import net.sf.ezmorph.bean.BeanMorpher;
import net.sf.ezmorph.bean.MorphDynaBean;
import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.JSONUtils;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -57,8 +61,10 @@ import com.fourspaces.couchdb.ViewResults;
import de.thm.arsnova.entities.Feedback;
import de.thm.arsnova.entities.PossibleAnswer;
import de.thm.arsnova.entities.Question;
import de.thm.arsnova.entities.LoggedIn;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.entities.VisitedSession;
import de.thm.arsnova.exceptions.ForbiddenException;
import de.thm.arsnova.exceptions.NotFoundException;
import de.thm.arsnova.services.ISessionService;
......@@ -191,20 +197,14 @@ public class CouchDBDao implements IDatabaseDao {
}
@Override
public List<Question> getSkillQuestions(String sessionKeyword, String sort) {
public List<Question> getSkillQuestions(String sessionKeyword) {
Session session = this.getSessionFromKeyword(sessionKeyword);
if (session == null) {
return null;
}
String viewName = "";
if(sort != null && sort.equals("text")) {
viewName = "skill_question/by_session_sorted_by_subject_and_text";
} else {
viewName = "skill_question/by_session";
}
try {
View view = new View(viewName);
View view = new View("skill_question/by_session_sorted_by_subject_and_text");
view.setStartKey("[" + URLEncoder.encode("\"" + session.get_id() + "\"", "UTF-8") + "]");
view.setEndKey("[" + URLEncoder.encode("\"" + session.get_id() + "\",{}", "UTF-8") + "]");
......@@ -514,4 +514,45 @@ public class CouchDBDao implements IDatabaseDao {
}
return null;
}
@Override
public LoggedIn registerAsOnlineUser(User u, Session s) {
try {
View view = new View("logged_in/all");
view.setKey(URLEncoder.encode("\"" + u.getUsername() + "\"", "UTF-8"));
ViewResults results = this.getDatabase().view(view);
LoggedIn loggedIn = new LoggedIn();
if (results.getJSONArray("rows").optJSONObject(0) != null) {
JSONObject json = results.getJSONArray("rows").optJSONObject(0).optJSONObject("value");
loggedIn = (LoggedIn) JSONObject.toBean(json, LoggedIn.class);
Collection<VisitedSession> visitedSessions = JSONArray.toCollection(json.getJSONArray("visitedSessions"), VisitedSession.class);
loggedIn.setVisitedSessions(new ArrayList<VisitedSession>(visitedSessions));
}
loggedIn.setUser(u.getUsername());
loggedIn.setSessionId(s.get_id());
loggedIn.addVisitedSession(s);
JSONObject json = JSONObject.fromObject(loggedIn);
Document doc = new Document(json);
if (doc.getId() == "") {
// If this is a new user without a logged_in document, we have to remove the following
// pre-filled fields. Otherwise, CouchDB will take these empty fields as genuine
// identifiers, and will throw errors afterwards.
doc.remove("_id");
doc.remove("_rev");
}
this.getDatabase().saveDocument(doc);
LoggedIn l = (LoggedIn) JSONObject.toBean(doc.getJSONObject(), LoggedIn.class);
Collection<VisitedSession> visitedSessions = JSONArray.toCollection(doc.getJSONObject().getJSONArray("visitedSessions"), VisitedSession.class);
l.setVisitedSessions(new ArrayList<VisitedSession>(visitedSessions));
return l;
} catch (UnsupportedEncodingException e) {
return null;
} catch (IOException e) {
return null;
}
}
}
......@@ -23,6 +23,7 @@ import java.util.List;
import de.thm.arsnova.entities.Feedback;
import de.thm.arsnova.entities.Question;
import de.thm.arsnova.entities.LoggedIn;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
......@@ -38,6 +39,8 @@ public interface IDatabaseDao {
public boolean saveQuestion(Session session, Question question);
public Question getQuestion(String id);
List<Question> getSkillQuestions(String session, String sort);
List<Question> getSkillQuestions(String session);
public int getSkillQuestionCount(String sessionkey);
public LoggedIn registerAsOnlineUser(User u, Session s);
}
\ No newline at end of file
......@@ -25,6 +25,7 @@ import java.util.Set;
import de.thm.arsnova.entities.Feedback;
import de.thm.arsnova.entities.Question;
import de.thm.arsnova.entities.LoggedIn;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
......@@ -43,6 +44,7 @@ public interface ISessionService {
public List<Session> getMySessions(String username);
public boolean saveQuestion(Question question);
public Question getQuestion(String id);
public List<Question> getSkillQuestions(String sessionkey, String sort);
public LoggedIn registerAsOnlineUser(User user, String sessionkey);
public List<Question> getSkillQuestions(String sessionkey);
public int getSkillQuestionCount(String sessionkey);
}
\ No newline at end of file
......@@ -32,6 +32,7 @@ import de.thm.arsnova.annotation.Authenticated;
import de.thm.arsnova.dao.IDatabaseDao;
import de.thm.arsnova.entities.Feedback;
import de.thm.arsnova.entities.Question;
import de.thm.arsnova.entities.LoggedIn;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.socket.ARSnovaSocketIOServer;
......@@ -77,8 +78,8 @@ public class SessionService implements ISessionService {
}
@Override
public List<Question> getSkillQuestions(String sessionkey, String sort) {
return databaseDao.getSkillQuestions(sessionkey, sort);
public List<Question> getSkillQuestions(String sessionkey) {
return databaseDao.getSkillQuestions(sessionkey);
}
@Override
......@@ -147,4 +148,13 @@ public class SessionService implements ISessionService {
public Question getQuestion(String id) {
return databaseDao.getQuestion(id);
}
@Override
@Authenticated
public LoggedIn registerAsOnlineUser(User user, String sessionkey) {
Session session = this.joinSession(sessionkey);
if (session == null) return null;
return databaseDao.registerAsOnlineUser(user, session);
}
}
......@@ -11,6 +11,7 @@ import org.springframework.stereotype.Component;
import de.thm.arsnova.entities.Feedback;
import de.thm.arsnova.entities.Question;
import de.thm.arsnova.entities.LoggedIn;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.exceptions.ForbiddenException;
......@@ -133,7 +134,7 @@ public class StubDatabaseDao implements IDatabaseDao {
}
@Override
public List<Question> getSkillQuestions(String session, String sort) {
public List<Question> getSkillQuestions(String session) {
// TODO Auto-generated method stub
return null;
}
......@@ -150,4 +151,10 @@ public class StubDatabaseDao implements IDatabaseDao {
return null;
}
@Override
public LoggedIn registerAsOnlineUser(User u, Session s) {
// TODO Auto-generated method stub
return null;
}
}
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