Project

General

Profile

1
package eu.dnetlib.uoaadmintoolslibrary.controllers;
2

    
3
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
4
import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse;
5
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
6
import org.apache.log4j.Logger;
7
import org.springframework.beans.factory.annotation.Autowired;
8
import org.springframework.web.bind.annotation.*;
9

    
10
import java.util.List;
11

    
12
// not used by portals
13
@RestController
14
@RequestMapping("/portal")
15
@CrossOrigin(origins = "*")
16
public class GenericPortalController {
17
    private final Logger log = Logger.getLogger(this.getClass());
18

    
19
    @Autowired
20
    private PortalService portalService;
21

    
22
    @RequestMapping(value = "/{pid}/type", method = RequestMethod.GET)
23
    public String getPortalType(@PathVariable String pid) {
24
        Portal portal = portalService.getPortal(pid);
25
        if (portal == null) {
26
            return null;
27
        } else {
28
            return portal.getType();
29
        }
30
    }
31

    
32
    @RequestMapping(value = {""}, method = RequestMethod.GET)
33
    public List<Portal> getAllPortals() {
34
        List<Portal> portals = portalService.getAllPortals();
35

    
36
        return portals;
37
    }
38

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

    
44
//    @PreAuthorize("isAuthenticated()")
45
//    @RequestMapping(value = {"/my-portals"}, method = RequestMethod.GET)
46
//    public List<Portal> getMyPortals(
47
//            //@RequestHeader("X-XSRF-TOKEN") String token
48
//
49
//            ) {
50
////        log.debug(token);
51
////        UserInfo userInfo = utils.getUserInfo(token);
52
////        log.debug(userInfo);
53
////        if(userInfo != null) {
54
////            List<String> roles = userInfo.getRoles();
55
////            for (String role : roles) {
56
////                log.debug(role);
57
////            }
58
////        }
59
//
60
//        List<GrantedAuthority> authorities = null;
61
//        Authentication authentication = (Authentication) SecurityContextHolder.getContext().getAuthentication();
62
//        if(authentication != null) {
63
//           authorities = (List<GrantedAuthority>) authentication.getAuthorities();
64
//        }
65
//        log.debug(authorities);
66
//
67
////        for(GrantedAuthority authority : authorities) {
68
////            authorizationService.
69
////        }
70
//        List<Portal> portals = portalService.getAllPortals();
71
//        for(Portal portal : portals) {
72
//            if(authorizationService..manager(portal.getType(), portal.getPid())) {
73
//
74
//            }
75
//        }
76
//
77
//        List<Portal> myPortals = new ArrayList<>();
78
//        // Get roles and for every role, find portalType and add portals
79
//        List<String> portalTypes = new ArrayList<>();
80
//        portalTypes.add("connect");
81
//        portalTypes.add("community");
82
//        portalTypes.add("explore");
83
//        for(String portalType : portalTypes) {
84
//            myPortals.addAll(portalService.getAllPortalsByType(portalType));
85
//            log.debug("Num of portals now: "+myPortals.size());
86
//        }
87
//
88
//        return myPortals;
89
//    }
90
}
(5-5/9)