Skip to content
Snippets Groups Projects
Commit 94ef4a89 authored by Paul-Christian Volkmer's avatar Paul-Christian Volkmer
Browse files

Some code cleanups

parent 479589dd
No related merge requests found
......@@ -38,7 +38,6 @@ import de.thm.arsnova.connector.model.Course;
import de.thm.arsnova.connector.model.UserRole;
import de.thm.arsnova.exceptions.NotFoundException;
import de.thm.arsnova.exceptions.UnauthorizedException;
import de.thm.arsnova.services.ISessionService;
import de.thm.arsnova.services.IUserService;
@Controller
......@@ -53,13 +52,10 @@ public class CourseController extends AbstractController {
@Autowired
private IUserService userService;
@Autowired
private ISessionService sessionService;
@RequestMapping(value = "/mycourses", method = RequestMethod.GET)
@ResponseBody
public final List<Course> myCourses(
@RequestParam(value="sortby", defaultValue="name") final String sortby
@RequestParam(value = "sortby", defaultValue = "name") final String sortby
) {
String username = userService.getCurrentUser().getUsername();
......
......@@ -60,6 +60,7 @@ import de.thm.arsnova.services.UserSessionService;
public class LoginController extends AbstractController {
private static final int MAX_USERNAME_LENGTH = 15;
private static final int MAX_GUESTHASH_LENGTH = 10;
@Autowired
private TwitterProvider twitterProvider;
......@@ -126,7 +127,7 @@ public class LoginController extends AbstractController {
if (guestName != null && guestName.startsWith("Guest") && guestName.length() == MAX_USERNAME_LENGTH) {
username = guestName;
} else {
username = "Guest" + Sha512DigestUtils.shaHex(request.getSession().getId()).substring(0, 10);
username = "Guest" + Sha512DigestUtils.shaHex(request.getSession().getId()).substring(0, MAX_GUESTHASH_LENGTH);
}
org.springframework.security.core.userdetails.User user =
new org.springframework.security.core.userdetails.User(
......
......@@ -19,7 +19,6 @@
package de.thm.arsnova.dao;
import java.io.IOException;
import java.util.List;
import de.thm.arsnova.connector.model.Course;
......
......@@ -132,14 +132,13 @@ public class FeedbackService implements IFeedbackService {
for (String session : allAffectedSessions) {
this.server.reportUpdatedFeedbackForSession(session);
}
}
@Override
public final Integer getMyFeedback(final String keyword, final User user) {
return this.databaseDao.getMyFeedback(keyword, user);
}
private static class FeedbackStorageObject {
private int value;
private Date timestamp;
......@@ -156,7 +155,7 @@ public class FeedbackService implements IFeedbackService {
return timestamp;
}
}
private static class FeedbackStorage {
private Map<String, Map<String, FeedbackStorageObject>> data;
......@@ -169,30 +168,29 @@ public class FeedbackService implements IFeedbackService {
int b = 0;
int c = 0;
int d = 0;
if (data.get(keyword) == null) {
return new Feedback(0, 0, 0, 0);
}
for (FeedbackStorageObject fso : data.get(keyword).values()) {
switch (fso.getValue()) {
case 0:
case Feedback.FEEDBACK_FASTER:
a++;
break;
case 1:
case Feedback.FEEDBACK_OK:
b++;
break;
case 2:
case Feedback.FEEDBACK_SLOWER:
c++;
break;
case 3:
case Feedback.FEEDBACK_AWAY:
d++;
break;
default:
break;
}
}
return new Feedback(a, b, c, d);
}
......@@ -213,9 +211,9 @@ public class FeedbackService implements IFeedbackService {
private void cleanSessionFeedbackVotes(String keyword, int cleanupFeedbackDelay) {
final long timelimitInMillis = 60000 * (long) cleanupFeedbackDelay;
final long maxAllowedTimeInMillis = System.currentTimeMillis() - timelimitInMillis;
Map<String, FeedbackStorageObject> sessionFeedbacks = data.get(keyword);
for (Map.Entry<String, FeedbackStorageObject> entry : sessionFeedbacks.entrySet()) {
if (
entry.getValue().getTimestamp().getTime() < maxAllowedTimeInMillis
......
......@@ -33,18 +33,18 @@ public class FoodService implements IFoodService {
@Autowired
private IDatabaseDao databaseDao;
public final void setDatabaseDao(IDatabaseDao databaseDao) {
this.databaseDao = databaseDao;
}
@Override
@Authenticated
public void vote(String menu) {
this.databaseDao.vote(menu);
}
@Override
public List<FoodVote> getFoodVote() {
return this.databaseDao.getFoodVote();
......
......@@ -19,7 +19,6 @@
package de.thm.arsnova.services;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
......
......@@ -19,7 +19,6 @@
package de.thm.arsnova.services;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......
......@@ -15,9 +15,6 @@ public class StatisticsService implements IStatisticsService {
@Autowired
private IDatabaseDao databaseDao;
@Autowired
private IUserService userService;
@Autowired
private SessionRegistry sessionRegistry;
......
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