2020-03-31 14:02:29 +02:00
|
|
|
package eu.dnetlib.uoaadmintools.controllers;
|
|
|
|
|
2020-09-24 14:02:39 +02:00
|
|
|
import eu.dnetlib.uoaadmintools.entities.curator.Curator;
|
|
|
|
import eu.dnetlib.uoaadmintools.entities.curator.CuratorResponse;
|
2021-02-25 20:00:05 +01:00
|
|
|
import eu.dnetlib.uoaadmintools.services.CuratorService;
|
|
|
|
import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService;
|
2020-03-31 14:02:29 +02:00
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2021-02-25 12:57:22 +01:00
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
2020-03-31 14:02:29 +02:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin(origins = "*")
|
|
|
|
public class CuratorController {
|
|
|
|
private final Logger log = Logger.getLogger(this.getClass());
|
|
|
|
|
|
|
|
@Autowired
|
2021-02-25 20:00:05 +01:00
|
|
|
private CuratorService curatorService;
|
2020-03-31 14:02:29 +02:00
|
|
|
|
2021-02-25 12:57:22 +01:00
|
|
|
@Autowired
|
2021-02-25 20:00:05 +01:00
|
|
|
private AuthorizationService authorizationService;
|
2020-03-31 14:02:29 +02:00
|
|
|
|
|
|
|
/**
|
2021-02-25 20:00:05 +01:00
|
|
|
* Return a list with curator for a specific community
|
2020-03-31 14:02:29 +02:00
|
|
|
*
|
2021-02-25 20:00:05 +01:00
|
|
|
* @param pid
|
2020-03-31 14:02:29 +02:00
|
|
|
* @return
|
|
|
|
*/
|
2021-02-25 20:00:05 +01:00
|
|
|
@RequestMapping(value = "/{pid}/curator", method = RequestMethod.GET)
|
|
|
|
public List<CuratorResponse> getCurators(@PathVariable String pid) {
|
|
|
|
return curatorService.getCurators(pid);
|
2020-03-31 14:02:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a Curator with the given id.
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @return
|
|
|
|
*/
|
2021-02-25 12:57:22 +01:00
|
|
|
@PreAuthorize("isAuthenticated()")
|
2020-03-31 14:02:29 +02:00
|
|
|
@RequestMapping(value = "/curator/{id}", method = RequestMethod.GET)
|
|
|
|
public Curator getCuratorById(@PathVariable String id) {
|
2021-02-25 20:00:05 +01:00
|
|
|
return curatorService.findById(id);
|
2020-03-31 14:02:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create or update a curator, base on Curator object given on Request Body.
|
|
|
|
*
|
|
|
|
* @param curator
|
|
|
|
* @return
|
|
|
|
*/
|
2021-02-25 12:57:22 +01:00
|
|
|
@PreAuthorize("isAuthenticated()")
|
2020-03-31 14:02:29 +02:00
|
|
|
@RequestMapping(value = "/curator", method = RequestMethod.POST)
|
|
|
|
public Curator insertCurator(@RequestBody Curator curator) {
|
2021-02-25 20:00:05 +01:00
|
|
|
String aaiId = authorizationService.getAaiId();
|
|
|
|
curator.setId(aaiId.substring(0, aaiId.indexOf("@")));
|
|
|
|
return curatorService.save(curator);
|
2020-03-31 14:02:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-25 20:00:05 +01:00
|
|
|
* Delete all curators for a spedific community.
|
2020-03-31 14:02:29 +02:00
|
|
|
*
|
2021-02-25 20:00:05 +01:00
|
|
|
* @param pid
|
2020-03-31 14:02:29 +02:00
|
|
|
*/
|
2021-02-25 12:57:22 +01:00
|
|
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
2021-02-25 20:00:05 +01:00
|
|
|
@RequestMapping(value = "/{pid}/curator", method = RequestMethod.DELETE)
|
|
|
|
public void deleteCurators(@PathVariable String pid) {
|
|
|
|
curatorService.deleteCurators(pid);
|
2020-03-31 14:02:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|