Skip to content
Snippets Groups Projects
Commit 2ad2f158 authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Merge branch 'legacy-code-removal'

parents b4dece4c 910c933a
Branches
Tags
No related merge requests found
Showing
with 10 additions and 378 deletions
/*
* 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.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;
import de.thm.arsnova.entities.FoodVote;
import de.thm.arsnova.services.IFoodService;
@RestController
@RequestMapping("/canteen/menu/vote")
public class FoodVoteController extends AbstractController {
public static final Logger LOGGER = LoggerFactory.getLogger(FoodVoteController.class);
@Autowired
private IFoodService foodService;
@RequestMapping(value = "/", method = RequestMethod.POST)
public final void setFoodVote(
@RequestBody final Object menu,
final HttpServletResponse response
) {
final String menustring = JSONObject.fromObject(menu).getString("menu");
foodService.vote(menustring);
}
@RequestMapping(value = "/", method = RequestMethod.GET)
public final List<FoodVote> getFoodVote() {
return foodService.getFoodVote();
}
@RequestMapping(value = "/count", method = RequestMethod.GET, produces = "text/plain")
public final String getFoodVoteCount() {
return Integer.toString(foodService.getFoodVoteCount());
}
}
......@@ -42,7 +42,6 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import de.thm.arsnova.connector.model.Course;
import de.thm.arsnova.entities.LoggedIn;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.exceptions.UnauthorizedException;
import de.thm.arsnova.services.ISessionService;
......@@ -65,7 +64,7 @@ public class SessionController extends AbstractController {
@RequestMapping(value = "/{sessionkey}", method = RequestMethod.GET)
public final Session joinSession(@PathVariable final String sessionkey) {
final Session session = sessionService.joinSession(sessionkey);
final Session session = sessionService.getSession(sessionkey);
if (! session.getCreator().equals(userService.getCurrentUser().getUsername())) {
session.setCreator("NOT VISIBLE TO YOU");
} else {
......@@ -79,13 +78,6 @@ public class SessionController extends AbstractController {
sessionService.deleteSession(sessionkey);
}
@DeprecatedApi
@RequestMapping(value = "/{sessionkey}/online", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public final LoggedIn registerAsOnlineUser(@PathVariable final String sessionkey) {
return sessionService.registerAsOnlineUser(sessionkey);
}
@DeprecatedApi
@RequestMapping(value = "/{sessionkey}/activeusercount", method = RequestMethod.GET)
public final int countActiveUsers(@PathVariable final String sessionkey) {
......
......@@ -53,7 +53,6 @@ import com.fourspaces.couchdb.ViewResults;
import de.thm.arsnova.connector.model.Course;
import de.thm.arsnova.entities.Answer;
import de.thm.arsnova.entities.DbUser;
import de.thm.arsnova.entities.FoodVote;
import de.thm.arsnova.entities.InterposedQuestion;
import de.thm.arsnova.entities.InterposedReadingCount;
import de.thm.arsnova.entities.LoggedIn;
......@@ -772,39 +771,6 @@ public class CouchDBDao implements IDatabaseDao {
}
}
@Override
public List<FoodVote> getFoodVote() {
final List<FoodVote> foodVotes = new ArrayList<FoodVote>();
final String date = new SimpleDateFormat("dd-mm-yyyyy").format(new Date());
final NovaView view = new NovaView("food_vote/count_by_day");
view.setStartKeyArray(date);
view.setEndKeyArray(date, "{}");
view.setGroup(true);
final ViewResults results = getDatabase().view(view);
for (final Document d : results.getResults()) {
final FoodVote vote = new FoodVote();
vote.setCount(d.getJSONObject().optInt("value"));
vote.setDay(date);
vote.setName(d.getJSONObject().getJSONArray("key").getString(1));
foodVotes.add(vote);
}
return foodVotes;
}
@Override
public int getFoodVoteCount() {
final String date = new SimpleDateFormat("dd-mm-yyyyy").format(new Date());
final NovaView view = new NovaView("food_vote/count_by_day");
view.setStartKeyArray(date);
view.setEndKeyArray(date, "{}");
view.setGroup(false);
final ViewResults results = getDatabase().view(view);
if (results.size() == 0 || results.getResults().size() == 0) {
return 0;
}
return results.getJSONArray("rows").optJSONObject(0).optInt("value");
}
@Override
public int countSessions() {
return sessionsCountValue("openSessions")
......
......@@ -25,7 +25,6 @@ import java.util.List;
import de.thm.arsnova.connector.model.Course;
import de.thm.arsnova.entities.Answer;
import de.thm.arsnova.entities.DbUser;
import de.thm.arsnova.entities.FoodVote;
import de.thm.arsnova.entities.InterposedQuestion;
import de.thm.arsnova.entities.InterposedReadingCount;
import de.thm.arsnova.entities.LoggedIn;
......@@ -88,10 +87,6 @@ public interface IDatabaseDao {
void vote(User me, String menu);
int getFoodVoteCount();
List<FoodVote> getFoodVote();
int countSessions();
int countOpenSessions();
......
package de.thm.arsnova.entities;
public class FoodVote {
private String _id;
private String _rev;
private String type;
private String name;
private int count;
private String day;
public FoodVote() {
this.type = "food_vote";
}
public String get_id() {
return _id;
}
public void set_id(String _id) {
this._id = _id;
}
public String get_rev() {
return _rev;
}
public void set_rev(String _rev) {
this._rev = _rev;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public String getDay() {
return day;
}
public void setDay(String day) {
this.day = day;
}
}
/*
* 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.services;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import de.thm.arsnova.dao.IDatabaseDao;
import de.thm.arsnova.entities.FoodVote;
@Service
public class FoodService implements IFoodService {
@Autowired
private IDatabaseDao databaseDao;
@Autowired
private IUserService userService;
public final void setDatabaseDao(IDatabaseDao databaseDao) {
this.databaseDao = databaseDao;
}
@Override
@PreAuthorize("isAuthenticated()")
public void vote(String menu) {
this.databaseDao.vote(userService.getCurrentUser(), menu);
}
@Override
public List<FoodVote> getFoodVote() {
return this.databaseDao.getFoodVote();
}
@Override
public int getFoodVoteCount() {
return this.databaseDao.getFoodVoteCount();
}
}
/*
* 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.services;
import java.util.List;
import de.thm.arsnova.entities.FoodVote;
public interface IFoodService {
void vote(String menu);
int getFoodVoteCount();
List<FoodVote> getFoodVote();
}
......@@ -28,7 +28,7 @@ import de.thm.arsnova.entities.LoggedIn;
import de.thm.arsnova.entities.Session;
public interface ISessionService {
Session joinSession(String keyword);
Session getSession(String keyword);
Session saveSession(Session session);
......@@ -40,8 +40,6 @@ public interface ISessionService {
List<Session> getMyVisitedSessions();
LoggedIn registerAsOnlineUser(String sessionkey);
int countSessions(List<Course> courses);
int activeUsers(String sessionkey);
......
......@@ -45,8 +45,6 @@ public interface IUserService {
Set<User> getUsersInSession(String keyword);
void addCurrentUserToSessionMap(String keyword);
String getSessionForUser(String username);
void addUserToSessionBySocketId(UUID socketId, String keyword);
......
......@@ -35,7 +35,6 @@ import org.springframework.stereotype.Service;
import de.thm.arsnova.connector.client.ConnectorClient;
import de.thm.arsnova.connector.model.Course;
import de.thm.arsnova.dao.IDatabaseDao;
import de.thm.arsnova.entities.LoggedIn;
import de.thm.arsnova.entities.Question;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
......@@ -116,9 +115,7 @@ public class SessionService implements ISessionService {
@Override
@PreAuthorize("isAuthenticated()")
public final Session joinSession(final String keyword) {
/* HTTP polling solution (legacy) */
public final Session getSession(final String keyword) {
final User user = userService.getCurrentUser();
final Session session = databaseDao.getSessionFromKeyword(keyword);
if (session == null) {
......@@ -132,10 +129,6 @@ public class SessionService implements ISessionService {
}
}
userService.addCurrentUserToSessionMap(keyword);
socketIoServer.reportActiveUserCountForSession(keyword);
socketIoServer.reportFeedbackForUserInSession(session, userService.getCurrentUser());
if (connectorClient != null && session.isCourseSession()) {
final String courseid = session.getCourseId();
if (!connectorClient.getMembership(userService.getCurrentUser().getUsername(), courseid).isMember()) {
......@@ -206,21 +199,6 @@ public class SessionService implements ISessionService {
return generateKeyword();
}
@Override
public final LoggedIn registerAsOnlineUser(final String sessionkey) {
/* HTTP polling solution (legacy) */
final Session session = this.joinSession(sessionkey);
if (session == null) {
throw new NotFoundException();
}
if (session.getCreator().equals(userService.getCurrentUser().getUsername())) {
databaseDao.updateSessionOwnerActivity(session);
}
return databaseDao.registerAsOnlineUser(userService.getCurrentUser(), session);
}
@Override
public int countSessions(final List<Course> courses) {
final List<Session> sessions = databaseDao.getCourseSessions(courses);
......
......@@ -58,14 +58,10 @@ import de.thm.arsnova.socket.ARSnovaSocketIOServer;
@Service
public class UserService implements IUserService {
private static final int DEFAULT_SCHEDULER_DELAY_MS = 60000;
private static final int LOGIN_TRY_RESET_DELAY_MS = 30 * 1000;
private static final int LOGIN_BAN_RESET_DELAY_MS = 2 * 60 * 1000;
private static final int MAX_USER_INACTIVE_SECONDS = 120;
private static final int REPEATED_PASSWORD_RESET_DELAY_MS = 3 * 60 * 1000;
private static final int PASSWORD_RESET_KEY_DURABILITY_MS = 2 * 60 * 60 * 1000;
......@@ -77,9 +73,6 @@ public class UserService implements IUserService {
/* used for Socket.IO online check solution (new) */
private static final ConcurrentHashMap<User, String> user2session = new ConcurrentHashMap<User, String>();
/* used for HTTP polling online check solution (legacy) */
private static final ConcurrentHashMap<User, String> user2sessionLegacy = new ConcurrentHashMap<User, String>();
@Autowired
private IDatabaseDao databaseDao;
......@@ -152,28 +145,6 @@ public class UserService implements IUserService {
}
}
@Scheduled(fixedDelay = DEFAULT_SCHEDULER_DELAY_MS)
public final void removeInactiveUsersFromLegacyMap() {
final List<String> usernames = databaseDao.getActiveUsers(MAX_USER_INACTIVE_SECONDS);
final Set<String> affectedSessions = new HashSet<String>();
for (final Entry<User, String> e : user2sessionLegacy.entrySet()) {
final User key = e.getKey();
if (usernames != null && !usernames.contains(key.getUsername())) {
if (null != e.getValue()) {
affectedSessions.add(e.getValue());
} else {
LOGGER.warn("Session for user {} is null", key);
}
user2sessionLegacy.remove(e.getKey());
}
}
for (final String sessionKeyword : affectedSessions) {
socketIoServer.reportActiveUserCountForSession(sessionKeyword);
}
}
@Override
public User getCurrentUser() {
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
......@@ -267,12 +238,9 @@ public class UserService implements IUserService {
if (keyword == null) {
return false;
}
String session = user2sessionLegacy.get(user);
String session = user2session.get(user);
if (session == null) {
session = user2session.get(user);
if (session == null) {
return false;
}
return false;
}
return keyword.equals(session);
......@@ -286,25 +254,10 @@ public class UserService implements IUserService {
result.add(e.getKey());
}
}
for (final Entry<User, String> e : user2sessionLegacy.entrySet()) {
if (e.getValue().equals(keyword)) {
result.add(e.getKey());
}
}
return result;
}
@Override
@Transactional(isolation = Isolation.READ_COMMITTED)
public void addCurrentUserToSessionMap(final String keyword) {
final User user = getCurrentUser();
if (user == null) {
throw new UnauthorizedException();
}
user2sessionLegacy.put(user, keyword);
}
@Override
@Transactional(isolation = Isolation.READ_COMMITTED)
public void addUserToSessionBySocketId(final UUID socketId, final String keyword) {
......@@ -331,11 +284,6 @@ public class UserService implements IUserService {
return entry.getValue();
}
}
for (final Entry<User, String> entry : user2sessionLegacy.entrySet()) {
if (entry.getKey().getUsername().equals(username)) {
return entry.getValue();
}
}
return null;
}
......@@ -349,13 +297,12 @@ public class UserService implements IUserService {
public void removeUserFromMaps(final User user) {
if (user != null) {
user2session.remove(user);
user2sessionLegacy.remove(user);
}
}
@Override
public int loggedInUsers() {
return user2sessionLegacy.size();
return user2session.size();
}
@Override
......
......@@ -147,14 +147,6 @@ public class SessionControllerTest {
.andExpect(header().string(AbstractController.X_DEPRECATED_API, "1"));
}
@Test
public void testShouldEndInUnauthorizedResult() throws Exception {
setAuthenticated(false, "ptsr00");
mockMvc.perform(post("/session/12345678/online").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isUnauthorized());
}
@Test
public void testShouldEndInForbidden() throws Exception {
setAuthenticated(true, "ptsr00");
......
......@@ -28,7 +28,6 @@ import de.thm.arsnova.connector.model.Course;
import de.thm.arsnova.entities.Answer;
import de.thm.arsnova.entities.DbUser;
import de.thm.arsnova.entities.Feedback;
import de.thm.arsnova.entities.FoodVote;
import de.thm.arsnova.entities.InterposedQuestion;
import de.thm.arsnova.entities.InterposedReadingCount;
import de.thm.arsnova.entities.LoggedIn;
......@@ -264,18 +263,6 @@ public class StubDatabaseDao implements IDatabaseDao {
}
@Override
public int getFoodVoteCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public List<FoodVote> getFoodVote() {
// TODO Auto-generated method stub
return null;
}
@Override
public int countAnswers() {
// TODO Auto-generated method stub
......
......@@ -103,13 +103,13 @@ public class SessionServiceTest {
@Test(expected = NotFoundException.class)
public void testShouldNotFindNonExistantSession() {
setAuthenticated(true, "ptsr00");
sessionService.joinSession("00000000");
sessionService.getSession("00000000");
}
@Test(expected = AuthenticationCredentialsNotFoundException.class)
public void testShouldNotReturnSessionIfUnauthorized() {
setAuthenticated(false, null);
sessionService.joinSession("12345678");
sessionService.getSession("12345678");
}
@Test(expected = AuthenticationCredentialsNotFoundException.class)
......@@ -126,7 +126,7 @@ public class SessionServiceTest {
setAuthenticated(true, "ptsr00");
assertNull(sessionService.joinSession("11111111"));
assertNull(sessionService.getSession("11111111"));
}
@Test
......@@ -140,7 +140,7 @@ public class SessionServiceTest {
session.setName("TestSessionX");
session.setShortName("TSX");
sessionService.saveSession(session);
assertNotNull(sessionService.joinSession("11111111"));
assertNotNull(sessionService.getSession("11111111"));
}
@Test(expected = AccessDeniedException.class)
......
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