1 |
41837
|
michele.ar
|
package eu.dnetlib.functionality.modular.ui;
|
2 |
|
|
|
3 |
|
|
import java.net.URLEncoder;
|
4 |
|
|
import javax.annotation.Resource;
|
5 |
|
|
import javax.servlet.http.HttpServletRequest;
|
6 |
|
|
import javax.servlet.http.HttpServletResponse;
|
7 |
|
|
|
8 |
42621
|
sandro.lab
|
import eu.dnetlib.functionality.modular.ui.users.AuthorizationManager;
|
9 |
|
|
import eu.dnetlib.functionality.modular.ui.users.User;
|
10 |
|
|
import eu.dnetlib.functionality.modular.ui.utils.ShutdownUtils;
|
11 |
41838
|
michele.ar
|
import org.apache.commons.lang3.StringUtils;
|
12 |
41837
|
michele.ar
|
import org.springframework.beans.factory.BeanNameAware;
|
13 |
42621
|
sandro.lab
|
import org.springframework.beans.factory.annotation.Autowired;
|
14 |
41837
|
michele.ar
|
import org.springframework.beans.factory.annotation.Required;
|
15 |
|
|
import org.springframework.beans.factory.annotation.Value;
|
16 |
|
|
import org.springframework.ui.ModelMap;
|
17 |
|
|
import org.springframework.web.servlet.ModelAndView;
|
18 |
|
|
import org.springframework.web.servlet.mvc.Controller;
|
19 |
|
|
import org.springframework.web.servlet.view.RedirectView;
|
20 |
|
|
|
21 |
|
|
public abstract class ModuleEntryPoint extends MenuEntry implements Controller, BeanNameAware {
|
22 |
|
|
|
23 |
42621
|
sandro.lab
|
@Autowired
|
24 |
|
|
protected EntryPointsAggregator aggregator;
|
25 |
|
|
@Resource(name = "modularUiAuthorizationManager")
|
26 |
|
|
protected AuthorizationManager authorizationManager;
|
27 |
41837
|
michele.ar
|
private String beanName;
|
28 |
|
|
private boolean validMenuEntry = true;
|
29 |
|
|
private String group;
|
30 |
|
|
private int groupOrder = 50;
|
31 |
|
|
@Value("${dnet.modular.ui.authentication.url}")
|
32 |
|
|
private String authenticationUrl;
|
33 |
|
|
@Value("${dnet.modular.ui.logout.url}")
|
34 |
|
|
private String logoutUrl;
|
35 |
|
|
@Value("${dnet.modular.ui.ribbon.environment}")
|
36 |
|
|
private String environment;
|
37 |
|
|
@Value("${dnet.modular.ui.ribbon.accent}")
|
38 |
|
|
private String ribbonAccent;
|
39 |
42621
|
sandro.lab
|
@Autowired
|
40 |
41837
|
michele.ar
|
private ShutdownUtils shutdownUtils;
|
41 |
|
|
|
42 |
|
|
@Override
|
43 |
|
|
public ModelAndView handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
|
44 |
|
|
|
45 |
41838
|
michele.ar
|
final User user = this.authorizationManager.obtainUserDetails(request);
|
46 |
41837
|
michele.ar
|
if (user != null) {
|
47 |
|
|
final ModelAndView mv = new ModelAndView();
|
48 |
|
|
final ModelMap map = mv.getModelMap();
|
49 |
|
|
map.addAttribute("ui_menu", getMenu());
|
50 |
|
|
map.addAttribute("ui_title", getTitle());
|
51 |
|
|
map.addAttribute("ui_description", getDescription());
|
52 |
|
|
map.addAttribute("ui_group", getGroup());
|
53 |
41838
|
michele.ar
|
map.addAttribute("ui_modules", this.aggregator.getMenus(user));
|
54 |
|
|
map.addAttribute("environment", this.environment);
|
55 |
|
|
map.addAttribute("ribbonAccent", this.ribbonAccent);
|
56 |
41837
|
michele.ar
|
|
57 |
41838
|
michele.ar
|
switch (this.shutdownUtils.currentStatus()) {
|
58 |
41837
|
michele.ar
|
case STOPPING:
|
59 |
|
|
map.addAttribute("ui_navbar_class", "navbar-system-stopping");
|
60 |
|
|
map.addAttribute("ui_message", "stopping system");
|
61 |
|
|
break;
|
62 |
|
|
case STOPPED:
|
63 |
|
|
map.addAttribute("ui_navbar_class", "navbar-system-stopped");
|
64 |
|
|
map.addAttribute("ui_message", "system stopped");
|
65 |
|
|
break;
|
66 |
|
|
default:
|
67 |
|
|
map.addAttribute("ui_navbar_class", "navbar-inverse");
|
68 |
|
|
break;
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
String baseUrl = "";
|
72 |
41838
|
michele.ar
|
for (int i = 1; i < StringUtils.countMatches(this.beanName, "/"); i++) {
|
73 |
41837
|
michele.ar
|
baseUrl += "/..";
|
74 |
|
|
}
|
75 |
|
|
if (baseUrl.length() > 0) {
|
76 |
|
|
baseUrl = baseUrl.substring(1);
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
map.addAttribute("ui_baseUrl", baseUrl);
|
80 |
|
|
|
81 |
41838
|
michele.ar
|
if ((this.logoutUrl != null) && !this.logoutUrl.isEmpty()) {
|
82 |
|
|
map.addAttribute("ui_logoutUrl", this.logoutUrl);
|
83 |
41837
|
michele.ar
|
}
|
84 |
|
|
|
85 |
|
|
map.addAttribute("ui_user", user);
|
86 |
|
|
|
87 |
|
|
initialize(map, request, response);
|
88 |
|
|
return mv;
|
89 |
|
|
} else {
|
90 |
|
|
final StringBuffer url = request.getRequestURL();
|
91 |
|
|
final String queryString = request.getQueryString();
|
92 |
|
|
if (queryString != null) {
|
93 |
|
|
url.append('?');
|
94 |
|
|
url.append(queryString);
|
95 |
|
|
}
|
96 |
41838
|
michele.ar
|
return new ModelAndView(new RedirectView(this.authenticationUrl + "?url=" + URLEncoder.encode(url.toString(), "UTF-8")));
|
97 |
41837
|
michele.ar
|
}
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
abstract protected void initialize(ModelMap map, HttpServletRequest request, HttpServletResponse response) throws Exception;
|
101 |
|
|
|
102 |
|
|
public String getBeanName() {
|
103 |
41838
|
michele.ar
|
return this.beanName;
|
104 |
41837
|
michele.ar
|
}
|
105 |
|
|
|
106 |
|
|
@Override
|
107 |
|
|
public void setBeanName(final String beanName) {
|
108 |
|
|
this.beanName = beanName;
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
public String getGroup() {
|
112 |
41838
|
michele.ar
|
return this.group;
|
113 |
41837
|
michele.ar
|
}
|
114 |
|
|
|
115 |
|
|
@Required
|
116 |
|
|
public void setGroup(final String group) {
|
117 |
|
|
this.group = group;
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
@Override
|
121 |
|
|
public String getRelativeUrl() {
|
122 |
41838
|
michele.ar
|
return this.beanName;
|
123 |
41837
|
michele.ar
|
}
|
124 |
|
|
|
125 |
|
|
public boolean isValidMenuEntry() {
|
126 |
41838
|
michele.ar
|
return this.validMenuEntry;
|
127 |
41837
|
michele.ar
|
}
|
128 |
|
|
|
129 |
|
|
public void setValidMenuEntry(final boolean validMenuEntry) {
|
130 |
|
|
this.validMenuEntry = validMenuEntry;
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
public int getGroupOrder() {
|
134 |
41838
|
michele.ar
|
return this.groupOrder;
|
135 |
41837
|
michele.ar
|
}
|
136 |
|
|
|
137 |
|
|
public void setGroupOrder(final int groupOrder) {
|
138 |
|
|
this.groupOrder = groupOrder;
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
}
|