Project

General

Profile

1 50222 konstantin
package eu.dnetlib.uoaadmintools.controllers;
2
3 59470 konstantin
import eu.dnetlib.uoaadmintools.entities.Layout;
4
import eu.dnetlib.uoaadmintools.services.LayoutService;
5 60034 konstantin
import eu.dnetlib.uoaadmintools.services.NotificationsService;
6 59470 konstantin
import eu.dnetlib.uoaadmintools.services.StatisticsService;
7
import eu.dnetlib.uoaadmintools.services.SubscriberService;
8
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
9
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.*;
10
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
11 50222 konstantin
import org.apache.log4j.Logger;
12
import org.springframework.web.bind.annotation.*;
13
import org.springframework.beans.factory.annotation.Autowired;
14
15
import java.util.*;
16
17
@RestController
18 59470 konstantin
@RequestMapping("/community")
19 50222 konstantin
@CrossOrigin(origins = "*")
20
public class CommunityController {
21
    private final Logger log = Logger.getLogger(this.getClass());
22
23
    @Autowired
24 59470 konstantin
    private LayoutService layoutService;
25 50222 konstantin
26
    @Autowired
27 60034 konstantin
    private NotificationsService notificationsService;
28
29
    @Autowired
30 59470 konstantin
    private StatisticsService statisticsService;
31 55027 k.triantaf
32
    @Autowired
33 59470 konstantin
    private SubscriberService subscriberService;
34 50222 konstantin
35
    @Autowired
36 59470 konstantin
    private PortalService portalService;
37 50222 konstantin
38 59482 konstantin
    @RequestMapping(value = {""}, method = RequestMethod.GET)
39 59470 konstantin
    public List<Portal> getAllCommunities() {
40
        return portalService.getAllPortalsByType("community");
41 50222 konstantin
    }
42
43 59470 konstantin
    @RequestMapping(value = {"/full"}, method = RequestMethod.GET)
44
    public List<PortalResponse> getAllCommunitiesFull() {
45
        return portalService.getAllPortalsFullByType("community");
46 50222 konstantin
    }
47
48 59470 konstantin
//    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
49
    @RequestMapping(value = "/update", method = RequestMethod.POST)
50
    public PortalResponse updateCommunity(@RequestBody Portal portal) {
51 60034 konstantin
        String old_pid = portalService.getPortalById(portal.getId()).getPid();
52
        String new_pid = portal.getPid();
53
54 59470 konstantin
        PortalResponse portalResponse = portalService.updatePortal(portal);
55 50222 konstantin
56 59470 konstantin
        if(!old_pid.equals(new_pid)) {
57 60034 konstantin
            log.debug("update portal pid - old: "+old_pid + " - new: "+new_pid);
58 59470 konstantin
            statisticsService.updatePid(old_pid, new_pid);
59
            subscriberService.updatePid(old_pid, new_pid);
60
            layoutService.updatePid(old_pid, new_pid);
61 60034 konstantin
            notificationsService.updatePid(old_pid, new_pid);
62 50222 konstantin
        }
63
64 59470 konstantin
        return portalResponse;
65 50222 konstantin
    }
66
67 59470 konstantin
//    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
68
    @RequestMapping(value = "/save", method = RequestMethod.POST)
69
    public PortalResponse insertCommunity(@RequestBody Portal portal) {
70
        PortalResponse portalResponse = portalService.insertPortal(portal);
71 50222 konstantin
72 59470 konstantin
        statisticsService.createPortalStatistics(portal.getPid());
73
        subscriberService.createPortalSubscribers(portal.getPid());
74 50222 konstantin
75 59470 konstantin
        return portalResponse;
76 50222 konstantin
    }
77
78 59470 konstantin
    // cannot handle MismatchingContent
79
//    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
80
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
81
    public Boolean deleteCommunities(@RequestBody List<String> portals) {
82
        for (String id: portals) {
83
            String pid = portalService.deletePortal(id);
84 57497 konstantin
85 59470 konstantin
            statisticsService.deleteByPid(pid);
86
            subscriberService.deletePortalSubscribers(pid);
87
            layoutService.deleteByPid(pid);
88 60034 konstantin
            notificationsService.deleteByPid(pid);
89 50222 konstantin
        }
90 51340 konstantin
91 50222 konstantin
        return true;
92
    }
93
94 59470 konstantin
    @RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
95 55027 k.triantaf
    public Layout getLayoutForCommunity(@PathVariable(value = "pid") String pid) {
96 59470 konstantin
        return layoutService.findByPid(pid);
97 55027 k.triantaf
    }
98
99 59470 konstantin
//    @PreAuthorize("hasAnyAuthority(" +
100
//            "@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
101
//            "@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))")
102
    @RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
103 57319 k.triantaf
    public Layout updateLayoutForCommunity(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
104 59470 konstantin
        return layoutService.save(layout);
105 55027 k.triantaf
    }
106 50222 konstantin
}