1
|
package eu.dnetlib.administration.uis;
|
2
|
|
3
|
import java.net.URLEncoder;
|
4
|
|
5
|
import javax.servlet.http.HttpServletRequest;
|
6
|
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
8
|
import org.springframework.http.HttpStatus;
|
9
|
import org.springframework.stereotype.Controller;
|
10
|
import org.springframework.ui.ModelMap;
|
11
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
12
|
import org.springframework.web.bind.annotation.PathVariable;
|
13
|
import org.springframework.web.bind.annotation.RequestMapping;
|
14
|
import org.springframework.web.bind.annotation.ResponseBody;
|
15
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
16
|
|
17
|
import eu.dnetlib.administration.uis.auth.AuthorizationManager;
|
18
|
import eu.dnetlib.administration.uis.auth.User;
|
19
|
import eu.dnetlib.administration.uis.modules.ErrorMessage;
|
20
|
import eu.dnetlib.administration.uis.modules.UIModule;
|
21
|
import eu.dnetlib.administration.uis.modules.UIModuleGrouper;
|
22
|
|
23
|
@Controller
|
24
|
@RequestMapping("/ui")
|
25
|
public class UIController {
|
26
|
|
27
|
@Autowired
|
28
|
private UIModuleGrouper grouper;
|
29
|
|
30
|
@Autowired
|
31
|
private AuthorizationManager authorizationManager;
|
32
|
|
33
|
@Autowired
|
34
|
private UIProperties properties;
|
35
|
|
36
|
@RequestMapping("{section}")
|
37
|
public String section(final ModelMap map,
|
38
|
final HttpServletRequest request,
|
39
|
@PathVariable("section") final String section) throws Exception {
|
40
|
final User user = authorizationManager.obtainUserDetails(request);
|
41
|
|
42
|
final UIModule module = grouper.getModuleByUrlSection(section);
|
43
|
|
44
|
if (module == null) {
|
45
|
return "redirect:home";
|
46
|
} else if (user == null) {
|
47
|
final StringBuffer url = request.getRequestURL();
|
48
|
final String queryString = request.getQueryString();
|
49
|
if (queryString != null) {
|
50
|
url.append('?');
|
51
|
url.append(queryString);
|
52
|
}
|
53
|
return "redirect:" + properties.getAuthenticationUrl() + "?url=" + URLEncoder.encode(url.toString(), "UTF-8");
|
54
|
} else {
|
55
|
|
56
|
map.addAttribute("section", section);
|
57
|
map.addAttribute("uiTitle", module.getTitle());
|
58
|
map.addAttribute("uiGroup", module.getGroup());
|
59
|
map.addAttribute("uiMenus", grouper.getMenus(user));
|
60
|
map.addAttribute("environment", properties.getRibbonEnv());
|
61
|
map.addAttribute("ribbonAccent", properties.getRibbonAccent());
|
62
|
|
63
|
module.populateModelMap(map);
|
64
|
|
65
|
return "master";
|
66
|
}
|
67
|
}
|
68
|
|
69
|
@RequestMapping("logout")
|
70
|
public String logout() {
|
71
|
// TODO
|
72
|
return "";
|
73
|
}
|
74
|
|
75
|
@ExceptionHandler(Throwable.class)
|
76
|
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
77
|
public @ResponseBody ErrorMessage handleException(final Exception e) {
|
78
|
return ErrorMessage.newInstance(e);
|
79
|
}
|
80
|
}
|