Project

General

Profile

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.*;
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
@RequestMapping("/community")
18
@CrossOrigin(origins = "*")
19
public class CommunityController {
20
    private final Logger log = Logger.getLogger(this.getClass());
21

    
22
    @Autowired
23
    private LayoutService layoutService;
24

    
25
    @Autowired
26
    private StatisticsService statisticsService;
27

    
28
    @Autowired
29
    private SubscriberService subscriberService;
30

    
31
    @Autowired
32
    private PortalService portalService;
33

    
34
    @RequestMapping(value = {"/"}, method = RequestMethod.GET)
35
    public List<Portal> getAllCommunities() {
36
        return portalService.getAllPortalsByType("community");
37
    }
38

    
39
    @RequestMapping(value = {"/full"}, method = RequestMethod.GET)
40
    public List<PortalResponse> getAllCommunitiesFull() {
41
        return portalService.getAllPortalsFullByType("community");
42
    }
43

    
44
//    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
45
    @RequestMapping(value = "/update", method = RequestMethod.POST)
46
    public PortalResponse updateCommunity(@RequestBody Portal portal) {
47
        PortalResponse portalResponse = portalService.updatePortal(portal);
48

    
49
        String old_pid = portalResponse.getPid();
50
        String new_pid = portal.getPid();
51
        if(!old_pid.equals(new_pid)) {
52
            statisticsService.updatePid(old_pid, new_pid);
53
            subscriberService.updatePid(old_pid, new_pid);
54
            layoutService.updatePid(old_pid, new_pid);
55
        }
56

    
57
        return portalResponse;
58
    }
59

    
60
//    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
61
    @RequestMapping(value = "/save", method = RequestMethod.POST)
62
    public PortalResponse insertCommunity(@RequestBody Portal portal) {
63
        PortalResponse portalResponse = portalService.insertPortal(portal);
64

    
65
        statisticsService.createPortalStatistics(portal.getPid());
66
        subscriberService.createPortalSubscribers(portal.getPid());
67

    
68
        return portalResponse;
69
    }
70

    
71
    // cannot handle MismatchingContent
72
//    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
73
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
74
    public Boolean deleteCommunities(@RequestBody List<String> portals) {
75
        for (String id: portals) {
76
            String pid = portalService.deletePortal(id);
77

    
78
            statisticsService.deleteByPid(pid);
79
            subscriberService.deletePortalSubscribers(pid);
80
            layoutService.deleteByPid(pid);
81
        }
82

    
83
        return true;
84
    }
85

    
86
    @RequestMapping(value = "/{pid}/layout", method = RequestMethod.GET)
87
    public Layout getLayoutForCommunity(@PathVariable(value = "pid") String pid) {
88
        return layoutService.findByPid(pid);
89
    }
90

    
91
//    @PreAuthorize("hasAnyAuthority(" +
92
//            "@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
93
//            "@AuthorizationService.curator(#portalType), @AuthorizationService.manager(#portalType, #pid))")
94
    @RequestMapping(value = "/{pid}/layout", method = RequestMethod.POST)
95
    public Layout updateLayoutForCommunity(@PathVariable(value = "pid") String pid, @RequestBody Layout layout) {
96
        return layoutService.save(layout);
97
    }
98
}
99

    
(1-1/11)