1
|
package eu.dnetlib.uoaadmintools.controllers;
|
2
|
|
3
|
import eu.dnetlib.uoaadmintools.entities.Layout;
|
4
|
import eu.dnetlib.uoaadmintools.services.LayoutService;
|
5
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
6
|
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*;
|
7
|
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
8
|
import org.apache.log4j.Logger;
|
9
|
import org.springframework.web.bind.annotation.*;
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
|
12
|
import java.util.*;
|
13
|
|
14
|
@RestController
|
15
|
@RequestMapping("/connect")
|
16
|
@CrossOrigin(origins = "*")
|
17
|
public class ConnectController {
|
18
|
private final Logger log = Logger.getLogger(this.getClass());
|
19
|
|
20
|
@Autowired
|
21
|
private LayoutService layoutService;
|
22
|
|
23
|
@Autowired
|
24
|
private PortalService portalService;
|
25
|
|
26
|
// @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
|
27
|
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
28
|
public PortalResponse updateCommunity(@RequestBody Portal portal) {
|
29
|
PortalResponse portalResponse = portalService.updatePortal(portal);
|
30
|
|
31
|
String old_pid = portalResponse.getPid();
|
32
|
String new_pid = portal.getPid();
|
33
|
if(!old_pid.equals(new_pid)) {
|
34
|
layoutService.updatePid(old_pid, new_pid);
|
35
|
}
|
36
|
|
37
|
return portalResponse;
|
38
|
}
|
39
|
|
40
|
// @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
|
41
|
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
42
|
public PortalResponse insertCommunity(@RequestBody Portal portal) {
|
43
|
PortalResponse portalResponse = portalService.insertPortal(portal);
|
44
|
return portalResponse;
|
45
|
}
|
46
|
|
47
|
// cannot handle MismatchingContent
|
48
|
// @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
|
49
|
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
50
|
public Boolean deleteCommunities(@RequestBody List<String> portals) {
|
51
|
for (String id: portals) {
|
52
|
String pid = portalService.deletePortal(id);
|
53
|
layoutService.deleteByPid(pid);
|
54
|
}
|
55
|
|
56
|
return true;
|
57
|
}
|
58
|
|
59
|
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
|
60
|
public Layout getLayoutForCommunity(@PathVariable(value = "pid") String pid) {
|
61
|
return layoutService.findByPid(pid);
|
62
|
}
|
63
|
|
64
|
// @PreAuthorize("hasAnyAuthority(" +
|
65
|
// "@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
66
|
// "@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))")
|
67
|
@RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
|
68
|
public Layout updateLayoutForCommunity(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
|
69
|
return layoutService.save(layout);
|
70
|
}
|
71
|
}
|
72
|
|