Project

General

Profile

1
package eu.dnetlib.uoaadmintoolslibrary.controllers;
2

    
3
import eu.dnetlib.uoaadmintoolslibrary.entities.Page;
4
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalPage;
5
import eu.dnetlib.uoaadmintoolslibrary.services.PageService;
6

    
7
import org.apache.log4j.Logger;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.web.bind.annotation.*;
10
import org.springframework.security.access.prepost.PreAuthorize;
11

    
12
import java.util.*;
13

    
14
@RestController
15
@CrossOrigin(origins = "*")
16
public class PageController {
17
    private final Logger log = Logger.getLogger(this.getClass());
18

    
19
    @Autowired
20
    private PageService pageService;
21

    
22
    // used by portals WITHOUT ANY PARAMS
23
    @RequestMapping(value = "/page/full", method = RequestMethod.GET)
24
    public List<PortalPage> getPagesFull(@RequestParam(value="pid", required=false) String pid,
25
                                         @RequestParam(value="page_route", required=false) String page_route) {
26
        return pageService.getPagesFull(pid, page_route);
27
    }
28

    
29
    // used by portals WITHOUT ANY PARAMS
30
    @RequestMapping(value = "/page", method = RequestMethod.GET)
31
    public List<Page> getAllPages(@RequestParam(value="pid", required=false) String pid,
32
                                  @RequestParam(value="page_route", required=false) String page_route,
33
                                  @RequestParam(value="with_positions", required=false) String with_positions) {
34
        return pageService.getAllPages(pid, page_route, with_positions);
35
    }
36

    
37
//    // not used by portals
38
//    @RequestMapping(value = "/page", method = RequestMethod.DELETE)
39
//    public void deleteAllPages() {
40
//        pageService.deleteAllPages();
41
//    }
42

    
43
    // used
44
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
45
    @RequestMapping(value = "/page/update", method = RequestMethod.POST)
46
    public PortalPage updatePage(@RequestBody PortalPage portalPage) {
47
        return pageService.updatePage(portalPage);
48
    }
49

    
50
    // used
51
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
52
    @RequestMapping(value = "/page/save", method = RequestMethod.POST)
53
    public PortalPage insertPage(@RequestBody PortalPage portalPage) {
54
        return pageService.insertPage(portalPage);
55
    }
56

    
57
    // used
58
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
59
    @RequestMapping(value = "/page/delete", method = RequestMethod.POST)
60
    public Boolean deletePages(@RequestBody List<String> pages) throws Exception {
61
        return pageService.deletePages(pages);
62
    }
63

    
64
//    // not used by portals
65
//    @RequestMapping(value = "/page/{id}", method = RequestMethod.GET)
66
//    public Page getPage(@PathVariable(value = "id") String id) {
67
//        return pageService.getPage(id);
68
//    }
69
//
70
//    // not used by portals
71
//    @RequestMapping(value = "/page/{id}", method = RequestMethod.DELETE)
72
//    public void deletePage(@PathVariable(value = "id") String id) {
73
//        pageService.deletePage(id);
74
//    }
75
//
76
//    // not used by portals
77
//    @RequestMapping(value = "/page/{id}/entity", method = RequestMethod.GET)
78
//    public List<String> getPageEntities(@PathVariable(value = "id") String id) {
79
//        return pageService.getPageEntities(id);
80
//    }
81
//
82
//    // not used by portals
83
//    @RequestMapping(value = "page/{id}/entity/toggle", method = RequestMethod.POST)
84
//    public Page togglePageEntity(@PathVariable(value = "id") String id, @RequestParam String entityId, @RequestParam String status) throws Exception {
85
//        return pageService.togglePageEntity(id, entityId, status);
86
//    }
87
}
(6-6/9)