1
|
package eu.dnetlib.uoaadmintools.controllers;
|
2
|
|
3
|
import eu.dnetlib.uoaadmintools.entities.curator.Curator;
|
4
|
import eu.dnetlib.uoaadmintools.entities.curator.CuratorResponse;
|
5
|
import eu.dnetlib.uoaadmintools.services.CuratorService;
|
6
|
import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService;
|
7
|
import org.apache.log4j.Logger;
|
8
|
import org.springframework.beans.factory.annotation.Autowired;
|
9
|
import org.springframework.security.access.prepost.PreAuthorize;
|
10
|
import org.springframework.web.bind.annotation.*;
|
11
|
|
12
|
import java.util.List;
|
13
|
|
14
|
@RestController
|
15
|
@CrossOrigin(origins = "*")
|
16
|
public class CuratorController {
|
17
|
private final Logger log = Logger.getLogger(this.getClass());
|
18
|
|
19
|
@Autowired
|
20
|
private CuratorService curatorService;
|
21
|
|
22
|
@Autowired
|
23
|
private AuthorizationService authorizationService;
|
24
|
|
25
|
/**
|
26
|
* Return a list with curator for a specific community
|
27
|
*
|
28
|
* @param pid
|
29
|
* @return
|
30
|
*/
|
31
|
@RequestMapping(value = "/{pid}/curator", method = RequestMethod.GET)
|
32
|
public List<CuratorResponse> getCurators(@PathVariable String pid) {
|
33
|
return curatorService.getCurators(pid);
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* Return a Curator with the given id.
|
38
|
*
|
39
|
* @param id
|
40
|
* @return
|
41
|
*/
|
42
|
@PreAuthorize("isAuthenticated()")
|
43
|
@RequestMapping(value = "/curator/{id}", method = RequestMethod.GET)
|
44
|
public Curator getCuratorById(@PathVariable String id) {
|
45
|
return curatorService.findById(id);
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* Create or update a curator, base on Curator object given on Request Body.
|
50
|
*
|
51
|
* @param curator
|
52
|
* @return
|
53
|
*/
|
54
|
@PreAuthorize("isAuthenticated()")
|
55
|
@RequestMapping(value = "/curator", method = RequestMethod.POST)
|
56
|
public Curator insertCurator(@RequestBody Curator curator) {
|
57
|
String aaiId = authorizationService.getAaiId();
|
58
|
curator.setId(aaiId.substring(0, aaiId.indexOf("@")));
|
59
|
return curatorService.save(curator);
|
60
|
}
|
61
|
|
62
|
|
63
|
/**
|
64
|
* Delete all curators for a spedific community.
|
65
|
*
|
66
|
* @param pid
|
67
|
*/
|
68
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
69
|
@RequestMapping(value = "/{pid}/curator", method = RequestMethod.DELETE)
|
70
|
public void deleteCurators(@PathVariable String pid) {
|
71
|
curatorService.deleteCurators(pid);
|
72
|
}
|
73
|
|
74
|
}
|