Commit b3ce3309 authored by Paul-Christian Volkmer's avatar Paul-Christian Volkmer

Merge private repository in upstream master

parents 77fc8107 8229832d
......@@ -91,8 +91,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 = questionService.getSkillQuestions(sessionkey, sort);
public List<Question> getSkillQuestions(@PathVariable String sessionkey, HttpServletResponse response) {
List<Question> questions = questionService.getSkillQuestions(sessionkey);
if(questions == null || questions.isEmpty()) {
response.setStatus(HttpStatus.NOT_FOUND.value());
return null;
......
......@@ -36,6 +36,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
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;
......@@ -43,7 +45,6 @@ import de.thm.arsnova.services.ISessionService;
import de.thm.arsnova.services.IUserService;
import de.thm.arsnova.socket.ARSnovaSocketIOServer;
@Controller
public class SessionController extends AbstractController {
......@@ -103,7 +104,6 @@ public class SessionController extends AbstractController {
return null;
}
@RequestMapping(value="/socketurl", method=RequestMethod.GET)
@ResponseBody
public String getSocketUrl() {
......@@ -130,5 +130,4 @@ public class SessionController extends AbstractController {
}
return sessions;
}
}
......@@ -195,20 +195,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") + "]");
......
......@@ -39,7 +39,7 @@ 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);
......
package de.thm.arsnova.entities;
import java.io.Serializable;
import org.jasig.cas.client.authentication.AttributePrincipal;
import org.scribe.up.profile.facebook.FacebookProfile;
import org.scribe.up.profile.google.Google2Profile;
......@@ -7,8 +9,8 @@ import org.scribe.up.profile.twitter.TwitterProfile;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
public class User {
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private String username;
public User(Google2Profile profile) {
......@@ -46,5 +48,16 @@ public class User {
public String toString() {
return "User, username: " + this.username;
}
@Override
public int hashCode() {
return username.hashCode();
}
@Override
public boolean equals(Object obj) {
User other = (User) obj;
return this.username.equals(other.username);
}
}
......@@ -27,6 +27,6 @@ import de.thm.arsnova.entities.Question;
public interface IQuestionService {
public boolean saveQuestion(Question question);
public Question getQuestion(String id);
public List<Question> getSkillQuestions(String sessionkey, String sort);
public List<Question> getSkillQuestions(String sessionkey);
public int getSkillQuestionCount(String sessionkey);
}
\ No newline at end of file
......@@ -47,8 +47,8 @@ public class QuestionService implements IQuestionService {
}
@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
......
......@@ -60,7 +60,7 @@ public class SessionService implements ISessionService {
public List<Session> getMySessions(String username) {
return databaseDao.getMySessions(username);
}
@Override
@Authenticated
public Session saveSession(Session session) {
......
package de.thm.arsnova.services;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import org.scribe.up.profile.facebook.FacebookProfile;
import org.scribe.up.profile.google.Google2Profile;
import org.scribe.up.profile.twitter.TwitterProfile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.cas.authentication.CasAuthenticationToken;
......@@ -24,11 +36,13 @@ import com.github.leleuj.ss.oauth.client.authentication.OAuthAuthenticationToken
import de.thm.arsnova.entities.User;
import de.thm.arsnova.exceptions.UnauthorizedException;
public class UserService implements IUserService {
public class UserService implements IUserService, InitializingBean, DisposableBean {
public static final Logger logger = LoggerFactory.getLogger(UserService.class);
private static final ConcurrentHashMap<UUID, User> socketid2user = new ConcurrentHashMap<UUID, User>();
private static final ConcurrentHashMap<String, String> user2session = new ConcurrentHashMap<String, String>();
@Override
public User getCurrentUser() {
......@@ -118,4 +132,53 @@ public class UserService implements IUserService {
public String getSessionForUser(String username) {
return user2session.get(username);
}
@Override
public void afterPropertiesSet() {
try {
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
File store = new File(tmpDir, "arsnova.bin");
if(!store.exists()) {
return;
}
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(store));
Hashtable<String, Map<?, ?>> map = (Hashtable<String, Map<?, ?>>) ois.readObject();
ois.close();
Map<UUID, User> s2u = (Map<UUID, User>) map.get("socketid2user");
Map<String, String> u2s = (Map<String, String>) map.get("user2session");
logger.info("load from store: {}", map);
socketid2user.putAll(s2u);
user2session.putAll(u2s);
} catch (IOException e) {
logger.error("IOException during restoring UserService", e);
} catch (ClassNotFoundException e) {
logger.error("ClassNotFoundException during restoring UserService", e);
}
}
@Override
public void destroy() {
Hashtable<String, Map<?, ?>> map = new Hashtable<String, Map<?, ?>>();
map.put("socketid2user", socketid2user);
map.put("user2session", user2session);
try {
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
File store = new File(tmpDir, "arsnova.bin");
if(!store.exists()) {
store.createNewFile();
}
OutputStream file = new FileOutputStream (store);
ObjectOutputStream objOut = new ObjectOutputStream(file);
objOut.writeObject(map);
objOut.close();
file.close();
logger.info("saved to store: {}", map);
} catch (IOException e) {
logger.error("IOException while saving UserService", e);
}
}
}
......@@ -134,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;
}
......
package de.thm.arsnova.services;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import de.thm.arsnova.entities.User;
public class StubUserService implements IUserService {
public class StubUserService extends UserService {
private User stubUser = null;
......@@ -29,52 +24,4 @@ public class StubUserService implements IUserService {
public User getCurrentUser() {
return stubUser;
}
@Override
public User getUser2SessionID(UUID sessionID) {
// TODO Auto-generated method stub
return null;
}
@Override
public void putUser2SessionID(UUID sessionID, User user) {
// TODO Auto-generated method stub
}
@Override
public void removeUser2SessionID(UUID sessionID) {
// TODO Auto-generated method stub
}
@Override
public Set<Entry<UUID, User>> users2Session() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isUserInSession(User user, String keyword) {
// TODO Auto-generated method stub
return false;
}
@Override
public List<String> getUsersInSession(String keyword) {
// TODO Auto-generated method stub
return null;
}
@Override
public String getSessionForUser(String username) {
// TODO Auto-generated method stub
return null;
}
@Override
public void addCurrentUserToSessionMap(String keyword) {
// TODO Auto-generated method stub
}
}
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