1
|
package eu.dnetlib.uoaadmintools.services;
|
2
|
|
3
|
import eu.dnetlib.uoaadmintools.configuration.properties.ManagersApiConfig;
|
4
|
import eu.dnetlib.uoaadmintools.entities.Manager;
|
5
|
import eu.dnetlib.uoaadmintools.entities.curator.Response;
|
6
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
8
|
import org.springframework.http.HttpStatus;
|
9
|
import org.springframework.http.ResponseEntity;
|
10
|
import org.springframework.stereotype.Service;
|
11
|
import org.springframework.web.client.RestTemplate;
|
12
|
|
13
|
@Service
|
14
|
public class ManagerService {
|
15
|
|
16
|
@Autowired
|
17
|
private ManagersApiConfig config;
|
18
|
|
19
|
@Autowired
|
20
|
private RestTemplate restTemplate;
|
21
|
|
22
|
public Manager[] getManagers(String pid) {
|
23
|
ResponseEntity<Response> responseEntity = restTemplate.getForEntity(config.getEmail().replace("{community}", pid), Response.class);
|
24
|
Response response = responseEntity.getBody();
|
25
|
if (response != null && responseEntity.getStatusCode() == HttpStatus.OK) {
|
26
|
return response.getResponse();
|
27
|
} else {
|
28
|
throw new ContentNotFoundException("No managers has been found for community " + pid);
|
29
|
}
|
30
|
}
|
31
|
}
|