1
|
package eu.dnetlib.uoaadmintools.controllers;
|
2
|
|
3
|
import eu.dnetlib.uoaadmintools.services.LayoutService;
|
4
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
5
|
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse;
|
6
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
7
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException;
|
8
|
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
9
|
import org.apache.log4j.Logger;
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
import org.springframework.security.access.prepost.PreAuthorize;
|
12
|
import org.springframework.web.bind.annotation.*;
|
13
|
|
14
|
import java.util.List;
|
15
|
|
16
|
@RestController
|
17
|
@RequestMapping("/connect")
|
18
|
@CrossOrigin(origins = "*")
|
19
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
20
|
public class ConnectController {
|
21
|
private final Logger log = Logger.getLogger(this.getClass());
|
22
|
|
23
|
@Autowired
|
24
|
private LayoutService layoutService;
|
25
|
|
26
|
@Autowired
|
27
|
private PortalService portalService;
|
28
|
|
29
|
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
30
|
public PortalResponse updateConnect(@RequestBody Portal portal) {
|
31
|
if (!portal.getType().equals("connect")) {
|
32
|
// EXCEPTION - MismatchingContent
|
33
|
throw new MismatchingContentException("Update Connect: Portal with id: " + portal.getId() + " has type: " + portal.getType() + " instead of connect");
|
34
|
}
|
35
|
|
36
|
PortalResponse portalResponse = portalService.updatePortal(portal);
|
37
|
|
38
|
String old_pid = portalResponse.getPid();
|
39
|
String new_pid = portal.getPid();
|
40
|
if (!old_pid.equals(new_pid)) {
|
41
|
layoutService.updatePid(old_pid, new_pid);
|
42
|
}
|
43
|
|
44
|
return portalResponse;
|
45
|
}
|
46
|
|
47
|
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
48
|
public PortalResponse insertConnect(@RequestBody Portal portal) {
|
49
|
if (!portal.getType().equals("connect")) {
|
50
|
// EXCEPTION - MismatchingContent
|
51
|
throw new MismatchingContentException("Save Connect: Portal with id: " + portal.getId() + " has type: " + portal.getType() + " instead of connect");
|
52
|
}
|
53
|
|
54
|
PortalResponse portalResponse = portalService.insertPortal(portal);
|
55
|
return portalResponse;
|
56
|
}
|
57
|
|
58
|
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
59
|
public Boolean deleteConnect(@RequestBody List<String> portals) {
|
60
|
for (String id : portals) {
|
61
|
Portal portal = portalService.getPortalById(id);
|
62
|
if (portal == null) {
|
63
|
// EXCEPTION - Entity Not Found
|
64
|
throw new ContentNotFoundException("Delete connect: Portal with id: " + id + " not found");
|
65
|
}
|
66
|
if (!portal.getType().equals("connect")) {
|
67
|
// EXCEPTION - MismatchingContent
|
68
|
throw new MismatchingContentException("Delete Connect: Portal with id: " + id + " has type: " + portal.getType() + " instead of connect");
|
69
|
}
|
70
|
|
71
|
String pid = portalService.deletePortal(id);
|
72
|
layoutService.deleteByPid(pid);
|
73
|
}
|
74
|
|
75
|
return true;
|
76
|
}
|
77
|
|
78
|
// @RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
|
79
|
// public Layout getLayoutForConnect(@PathVariable(value = "pid") String pid) {
|
80
|
// return layoutService.findByPid(pid);
|
81
|
// }
|
82
|
//
|
83
|
// @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
84
|
// @RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
|
85
|
// public Layout updateLayoutForConnect(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
|
86
|
// return layoutService.save(layout);
|
87
|
// }
|
88
|
}
|
89
|
|