1
|
package eu.dnetlib.functionality.modular.ui;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.util.Collections;
|
5
|
import java.util.List;
|
6
|
import java.util.Map;
|
7
|
import java.util.Set;
|
8
|
|
9
|
import javax.annotation.Resource;
|
10
|
import javax.servlet.http.HttpServletResponse;
|
11
|
|
12
|
import org.apache.commons.logging.Log;
|
13
|
import org.apache.commons.logging.LogFactory;
|
14
|
import org.springframework.stereotype.Controller;
|
15
|
import org.springframework.web.bind.annotation.RequestBody;
|
16
|
import org.springframework.web.bind.annotation.RequestMapping;
|
17
|
import org.springframework.web.bind.annotation.RequestMethod;
|
18
|
import org.springframework.web.bind.annotation.ResponseBody;
|
19
|
|
20
|
import com.google.common.collect.Lists;
|
21
|
import com.google.common.collect.Maps;
|
22
|
|
23
|
import eu.dnetlib.functionality.modular.ui.users.AuthorizationDAO;
|
24
|
import eu.dnetlib.functionality.modular.ui.users.PermissionLevel;
|
25
|
import eu.dnetlib.functionality.modular.ui.users.User;
|
26
|
|
27
|
@Controller
|
28
|
public class UsersInternalController {
|
29
|
|
30
|
@Resource(name="modularUiAuthorizationDao")
|
31
|
private AuthorizationDAO dao;
|
32
|
|
33
|
private static final Log log = LogFactory.getLog(UsersInternalController.class);
|
34
|
|
35
|
@RequestMapping(value = "/ui/users.get")
|
36
|
public @ResponseBody List<User> listUsers(HttpServletResponse response) throws IOException {
|
37
|
final List<User> list = Lists.newArrayList();
|
38
|
for (Map.Entry<String, Set<PermissionLevel>> e : dao.getPermissionLevels().entrySet()) {
|
39
|
final User user = new User(e.getKey());
|
40
|
user.setPermissionLevels(e.getValue());
|
41
|
list.add(user);
|
42
|
}
|
43
|
Collections.sort(list);
|
44
|
|
45
|
return list;
|
46
|
}
|
47
|
|
48
|
@RequestMapping(value = "/ui/saveusers.do", method=RequestMethod.POST)
|
49
|
public @ResponseBody boolean updateUsers(@RequestBody final List<User> users) {
|
50
|
|
51
|
log.info("Saving " + users.size() + " user(s)");
|
52
|
final Map<String, Set<PermissionLevel>> map = Maps.newHashMap();
|
53
|
for (User u : users) {
|
54
|
map.put(u.getId(), u.getPermissionLevels());
|
55
|
}
|
56
|
dao.updatePermissionLevels(map);
|
57
|
return true;
|
58
|
}
|
59
|
|
60
|
}
|