[Admin Tools | Trunk]: Add get managers by Type. Get Curators base on AAI ID
This commit is contained in:
parent
ac370aa055
commit
7466b04f4f
|
@ -26,10 +26,8 @@ public class CuratorService {
|
||||||
|
|
||||||
public List<CuratorResponse> getCurators(String pid) {
|
public List<CuratorResponse> getCurators(String pid) {
|
||||||
List<CuratorResponse> curators = new ArrayList<>();
|
List<CuratorResponse> curators = new ArrayList<>();
|
||||||
|
for (Manager manager : managerService.getManagers(pid, ManagerService.Type.ID)) {
|
||||||
for (Manager manager : managerService.getManagers(pid)) {
|
Curator curator = curatorDAO.findById(parseId(manager.getId()));
|
||||||
log.info(manager.getEmail());
|
|
||||||
Curator curator = curatorDAO.findByEmail(manager.getEmail());
|
|
||||||
if (curator != null) {
|
if (curator != null) {
|
||||||
curators.add(new CuratorResponse(curator));
|
curators.add(new CuratorResponse(curator));
|
||||||
}
|
}
|
||||||
|
@ -46,12 +44,16 @@ public class CuratorService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteCurators(String pid) {
|
public void deleteCurators(String pid) {
|
||||||
for (Manager manager : managerService.getManagers(pid)) {
|
for (Manager manager : managerService.getManagers(pid, ManagerService.Type.ID)) {
|
||||||
Curator curator = curatorDAO.findByEmail(manager.getEmail());
|
Curator curator = curatorDAO.findById(parseId(manager.getId()));
|
||||||
if (curator != null) {
|
if (curator != null) {
|
||||||
curatorDAO.delete(curator.getId());
|
curatorDAO.delete(curator.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String parseId(String id) {
|
||||||
|
return id.substring(0 , id.indexOf("@"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -13,6 +13,11 @@ import org.springframework.web.client.RestTemplate;
|
||||||
@Service
|
@Service
|
||||||
public class ManagerService {
|
public class ManagerService {
|
||||||
|
|
||||||
|
enum Type {
|
||||||
|
EMAIL,
|
||||||
|
ID
|
||||||
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ManagersApiConfig config;
|
private ManagersApiConfig config;
|
||||||
|
|
||||||
|
@ -20,7 +25,12 @@ public class ManagerService {
|
||||||
private RestTemplate restTemplate;
|
private RestTemplate restTemplate;
|
||||||
|
|
||||||
public Manager[] getManagers(String pid) {
|
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();
|
Response response = responseEntity.getBody();
|
||||||
if (response != null && responseEntity.getStatusCode() == HttpStatus.OK) {
|
if (response != null && responseEntity.getStatusCode() == HttpStatus.OK) {
|
||||||
return response.getResponse();
|
return response.getResponse();
|
||||||
|
|
Loading…
Reference in New Issue