32 lines
1.2 KiB
Java
32 lines
1.2 KiB
Java
package eu.dnetlib.uoaadmintools.services;
|
|
|
|
import eu.dnetlib.uoaadmintools.configuration.properties.ManagersApiConfig;
|
|
import eu.dnetlib.uoaadmintools.entities.Manager;
|
|
import eu.dnetlib.uoaadmintools.entities.curator.Response;
|
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
@Service
|
|
public class ManagerService {
|
|
|
|
@Autowired
|
|
private ManagersApiConfig config;
|
|
|
|
@Autowired
|
|
private RestTemplate restTemplate;
|
|
|
|
public Manager[] getManagers(String pid) {
|
|
ResponseEntity<Response> responseEntity = restTemplate.getForEntity(config.getEmail().replace("{community}", pid), Response.class);
|
|
Response response = responseEntity.getBody();
|
|
if (response != null && responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
return response.getResponse();
|
|
} else {
|
|
throw new ContentNotFoundException("No managers has been found for community " + pid);
|
|
}
|
|
}
|
|
}
|