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.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
7
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
|
8
|
import org.apache.log4j.Logger;
|
9
|
import org.springframework.beans.factory.annotation.Autowired;
|
10
|
import org.springframework.security.access.prepost.PreAuthorize;
|
11
|
import org.springframework.web.bind.annotation.*;
|
12
|
|
13
|
import java.util.List;
|
14
|
|
15
|
@RestController
|
16
|
@CrossOrigin(origins = "*")
|
17
|
public class CuratorController {
|
18
|
private final Logger log = Logger.getLogger(this.getClass());
|
19
|
|
20
|
@Autowired
|
21
|
private CuratorService curatorService;
|
22
|
|
23
|
@Autowired
|
24
|
private RolesUtils rolesUtils;
|
25
|
|
26
|
/**
|
27
|
* Return a list with curator for a specific community
|
28
|
*
|
29
|
* @param pid
|
30
|
* @return
|
31
|
*/
|
32
|
@RequestMapping(value = "/{pid}/curator", method = RequestMethod.GET)
|
33
|
public List<CuratorResponse> getCurators(@PathVariable String pid) {
|
34
|
return curatorService.getCurators(pid);
|
35
|
}
|
36
|
|
37
|
/**
|
38
|
* Return Curator info of logged in user.
|
39
|
*
|
40
|
* @return
|
41
|
*/
|
42
|
@PreAuthorize("isAuthenticated()")
|
43
|
@RequestMapping(value = "/curator", method = RequestMethod.GET)
|
44
|
public Curator getCuratorById() {
|
45
|
Curator curator = curatorService.findById(getId());
|
46
|
if(curator != null) {
|
47
|
return curator;
|
48
|
}
|
49
|
throw new ContentNotFoundException("No curator found");
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* Create or update a curator, base on Curator object given on Request Body.
|
54
|
*
|
55
|
* @param curator
|
56
|
* @return
|
57
|
*/
|
58
|
@PreAuthorize("isAuthenticated()")
|
59
|
@RequestMapping(value = "/curator", method = RequestMethod.POST)
|
60
|
public Curator insertCurator(@RequestBody Curator curator) {
|
61
|
curator.setId(getId());
|
62
|
return curatorService.save(curator);
|
63
|
}
|
64
|
|
65
|
|
66
|
/**
|
67
|
* Delete all curators for a spedific community.
|
68
|
*
|
69
|
* @param pid
|
70
|
*/
|
71
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
72
|
@RequestMapping(value = "/{pid}/curator", method = RequestMethod.DELETE)
|
73
|
public void deleteCurators(@PathVariable String pid) {
|
74
|
curatorService.deleteCurators(pid);
|
75
|
}
|
76
|
|
77
|
private String getId() {
|
78
|
String aaiId = rolesUtils.getAaiId();
|
79
|
return aaiId.substring(0, aaiId.indexOf("@"));
|
80
|
}
|
81
|
}
|