Skip to content
Snippets Groups Projects
Commit f2a273e1 authored by ThanKarab's avatar ThanKarab
Browse files

Small beautifications.

parent 12cbb8c2
No related branches found
No related tags found
1 merge request!19Feat/186 experiment refactor
package eu.hbp.mip.controllers;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.hbp.mip.models.DAOs.UserDAO;
import eu.hbp.mip.services.ActiveUserService;
import eu.hbp.mip.utils.Logging;
......@@ -9,19 +7,19 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
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 javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@RestController
@RequestMapping(value = "/activeUser", produces = {APPLICATION_JSON_VALUE})
@Api(value = "/activeUser")
public class UsersApi {
public class ActiveUserAPI {
@Autowired
private ActiveUserService activeUserService;
......@@ -32,22 +30,6 @@ public class UsersApi {
Logging.LogUserAction(activeUserService.getActiveUser().getUsername(), "(GET) /activeUser",
"Loading the details of the activeUser");
UserDAO activeUser = activeUserService.getActiveUser();
// Add the active user object to a cookie
try {
// TODO needed? Ask Manuel
ObjectMapper mapper = new ObjectMapper();
String userJSON = mapper.writeValueAsString(activeUser);
Cookie cookie = new Cookie("user", URLEncoder.encode(userJSON, "UTF-8"));
cookie.setSecure(true);
cookie.setPath("/");
response.addCookie(cookie);
} catch (JsonProcessingException | UnsupportedEncodingException e) {
Logging.LogUserAction(activeUser.getUsername(),
"(GET) /activeUser", "Failed to add Cookie. Exception: " + e.getMessage());
}
return ResponseEntity.ok(activeUserService.getActiveUser());
}
......
......@@ -37,7 +37,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@RestController
@RequestMapping(value = "/algorithms", produces = {APPLICATION_JSON_VALUE})
@Api(value = "/algorithms")
public class AlgorithmsApi {
public class AlgorithmsAPI {
private static final Gson gson = new Gson();
......
......@@ -25,7 +25,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@RestController
@RequestMapping(value = "/experiments", produces = {APPLICATION_JSON_VALUE})
@Api(value = "/experiments")
public class ExperimentApi {
public class ExperimentAPI {
@Autowired
private ActiveUserService activeUserService;
......
......@@ -27,7 +27,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@RestController
@RequestMapping(value = "/pathologies", produces = {APPLICATION_JSON_VALUE})
@Api(value = "/pathologies")
public class PathologiesApi {
public class PathologiesAPI {
private static final Gson gson = new Gson();
......
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