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.PortalResponse;
|
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
|
@CrossOrigin(origins = "*")
|
16
|
public class ConnectController {
|
17
|
private final Logger log = Logger.getLogger(this.getClass());
|
18
|
|
19
|
@Autowired
|
20
|
private LayoutService layoutService;
|
21
|
|
22
|
@Autowired
|
23
|
private PortalService portalService;
|
24
|
|
25
|
@RequestMapping(value = "/connect/update", method = RequestMethod.POST)
|
26
|
public PortalResponse updateCommunity(@RequestBody Portal portal) {
|
27
|
PortalResponse portalResponse = portalService.updatePortal(portal);
|
28
|
|
29
|
String old_pid = portalResponse.getPid();
|
30
|
String new_pid = portal.getPid();
|
31
|
if(!old_pid.equals(new_pid)) {
|
32
|
layoutService.updatePid(old_pid, new_pid);
|
33
|
}
|
34
|
|
35
|
return portalResponse;
|
36
|
}
|
37
|
|
38
|
@RequestMapping(value = "/connect/save", method = RequestMethod.POST)
|
39
|
public PortalResponse insertCommunity(@RequestBody Portal portal) {
|
40
|
PortalResponse portalResponse = portalService.insertPortal(portal);
|
41
|
return portalResponse;
|
42
|
}
|
43
|
|
44
|
@RequestMapping(value = "/connect/delete", method = RequestMethod.POST)
|
45
|
public Boolean deleteCommunities(@RequestBody List<String> portals) {
|
46
|
for (String id: portals) {
|
47
|
String pid = portalService.deletePortal(id);
|
48
|
layoutService.deleteByPid(pid);
|
49
|
}
|
50
|
|
51
|
return true;
|
52
|
}
|
53
|
|
54
|
@RequestMapping(value = "/connect/{pid}/layout", method = RequestMethod.GET)
|
55
|
public Layout getLayoutForCommunity(@PathVariable(value = "pid") String pid) {
|
56
|
return layoutService.findByPid(pid);
|
57
|
}
|
58
|
|
59
|
@RequestMapping(value = "/connect/{pid}/layout", method = RequestMethod.POST)
|
60
|
public Layout updateLayoutForCommunity(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
|
61
|
return layoutService.save(layout);
|
62
|
}
|
63
|
}
|
64
|
|