[Admin Tools | Trunk]: Add get managers by Type. Get Curators base on AAI ID

This commit is contained in:
Konstantinos Triantafyllou 2021-03-02 11:27:31 +00:00
parent ac370aa055
commit 7466b04f4f
2 changed files with 19 additions and 7 deletions

View File

@ -26,10 +26,8 @@ public class CuratorService {
public List<CuratorResponse> getCurators(String pid) {
List<CuratorResponse> curators = new ArrayList<>();
for (Manager manager : managerService.getManagers(pid)) {
log.info(manager.getEmail());
Curator curator = curatorDAO.findByEmail(manager.getEmail());
for (Manager manager : managerService.getManagers(pid, ManagerService.Type.ID)) {
Curator curator = curatorDAO.findById(parseId(manager.getId()));
if (curator != null) {
curators.add(new CuratorResponse(curator));
}
@ -46,12 +44,16 @@ public class CuratorService {
}
public void deleteCurators(String pid) {
for (Manager manager : managerService.getManagers(pid)) {
Curator curator = curatorDAO.findByEmail(manager.getEmail());
for (Manager manager : managerService.getManagers(pid, ManagerService.Type.ID)) {
Curator curator = curatorDAO.findById(parseId(manager.getId()));
if (curator != null) {
curatorDAO.delete(curator.getId());
}
}
}
private String parseId(String id) {
return id.substring(0 , id.indexOf("@"));
}
}

View File

@ -13,6 +13,11 @@ import org.springframework.web.client.RestTemplate;
@Service
public class ManagerService {
enum Type {
EMAIL,
ID
}
@Autowired
private ManagersApiConfig config;
@ -20,7 +25,12 @@ public class ManagerService {
private RestTemplate restTemplate;
public Manager[] getManagers(String pid) {
ResponseEntity<Response> responseEntity = restTemplate.getForEntity(config.getEmail().replace("{community}", pid), Response.class);
return getManagers(pid, Type.EMAIL);
}
public Manager[] getManagers(String pid, Type type) {
String url = (type == Type.EMAIL)?config.getEmail():config.getId();
ResponseEntity<Response> responseEntity = restTemplate.getForEntity(url.replace("{community}", pid), Response.class);
Response response = responseEntity.getBody();
if (response != null && responseEntity.getStatusCode() == HttpStatus.OK) {
return response.getResponse();