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.uoaadmintools.services.StatisticsService;
|
6
|
import eu.dnetlib.uoaadmintools.services.SubscriberService;
|
7
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
8
|
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse;
|
9
|
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
10
|
import org.apache.log4j.Logger;
|
11
|
import org.springframework.web.bind.annotation.*;
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
13
|
|
14
|
import java.util.*;
|
15
|
|
16
|
@RestController
|
17
|
@CrossOrigin(origins = "*")
|
18
|
public class CommunityController {
|
19
|
private final Logger log = Logger.getLogger(this.getClass());
|
20
|
|
21
|
@Autowired
|
22
|
private LayoutService layoutService;
|
23
|
|
24
|
@Autowired
|
25
|
private StatisticsService statisticsService;
|
26
|
|
27
|
@Autowired
|
28
|
private SubscriberService subscriberService;
|
29
|
|
30
|
@Autowired
|
31
|
private PortalService portalService;
|
32
|
|
33
|
@RequestMapping(value = "/community/update", method = RequestMethod.POST)
|
34
|
public PortalResponse updateCommunity(@RequestBody Portal portal) {
|
35
|
PortalResponse portalResponse = portalService.updatePortal(portal);
|
36
|
|
37
|
String old_pid = portalResponse.getPid();
|
38
|
String new_pid = portal.getPid();
|
39
|
if(!old_pid.equals(new_pid)) {
|
40
|
statisticsService.updatePid(old_pid, new_pid);
|
41
|
subscriberService.updatePid(old_pid, new_pid);
|
42
|
layoutService.updatePid(old_pid, new_pid);
|
43
|
}
|
44
|
|
45
|
return portalResponse;
|
46
|
}
|
47
|
|
48
|
@RequestMapping(value = "/community/save", method = RequestMethod.POST)
|
49
|
public PortalResponse insertCommunity(@RequestBody Portal portal) {
|
50
|
PortalResponse portalResponse = portalService.insertPortal(portal);
|
51
|
|
52
|
statisticsService.createPortalStatistics(portal.getPid());
|
53
|
subscriberService.createPortalSubscribers(portal.getPid());
|
54
|
|
55
|
return portalResponse;
|
56
|
}
|
57
|
|
58
|
@RequestMapping(value = "/community/delete", method = RequestMethod.POST)
|
59
|
public Boolean deleteCommunities(@RequestBody List<String> portals) {
|
60
|
for (String id: portals) {
|
61
|
String pid = portalService.deletePortal(id);
|
62
|
|
63
|
statisticsService.deleteByPid(pid);
|
64
|
subscriberService.deletePortalSubscribers(pid);
|
65
|
layoutService.deleteByPid(pid);
|
66
|
}
|
67
|
|
68
|
return true;
|
69
|
}
|
70
|
|
71
|
@RequestMapping(value = "/community/{pid}/layout", method = RequestMethod.GET)
|
72
|
public Layout getLayoutForCommunity(@PathVariable(value = "pid") String pid) {
|
73
|
return layoutService.findByPid(pid);
|
74
|
}
|
75
|
|
76
|
@RequestMapping(value = "/community/{pid}/layout", method = RequestMethod.POST)
|
77
|
public Layout updateLayoutForCommunity(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
|
78
|
return layoutService.save(layout);
|
79
|
}
|
80
|
}
|
81
|
|