Add method to get a stakeholder extended information.

This commit is contained in:
Konstantinos Triantafyllou 2024-06-13 15:39:05 +03:00
parent eef35e3047
commit 86fc8bba6a
2 changed files with 24 additions and 7 deletions

View File

@ -11,7 +11,7 @@ import java.util.List;
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("stakeholder/extended")
@RequestMapping("extended")
public class StakeholderExtendedController {
private final StakeholderExtendedService service;
@ -20,8 +20,13 @@ public class StakeholderExtendedController {
this.service = service;
}
@RequestMapping(value = "/{type}", method = RequestMethod.GET)
public List<StakeholderExtended> getStakeholders(@PathVariable String type, @RequestParam(value = "sort", required = false) SortBy sort) throws UnsupportedEncodingException {
return this.service.sortBy(this.service.getStakeholdersExtended(type), sort);
@RequestMapping(value = "", method = RequestMethod.GET)
public List<StakeholderExtended> getStakeholders(@RequestParam("type") String type, @RequestParam(value = "sort", required = false) SortBy sort) throws UnsupportedEncodingException {
return this.service.sortBy(this.service.getVisibleStakeholdersExtended(type), sort);
}
@RequestMapping(value = "/{stakeholderId}", method = RequestMethod.GET)
public StakeholderExtended getStakeholder(@PathVariable String stakeholderId) throws UnsupportedEncodingException {
return this.service.getStakeholderExtended(stakeholderId);
}
}

View File

@ -1,6 +1,5 @@
package eu.dnetlib.irishmonitorservice.services;
import eu.dnetlib.irishmonitorservice.entities.Data;
import eu.dnetlib.irishmonitorservice.entities.SortBy;
import eu.dnetlib.irishmonitorservice.entities.StakeholderExtended;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
@ -9,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@ -26,7 +24,21 @@ public class StakeholderExtendedService {
this.cacheService = cacheService;
}
public List<StakeholderExtended> getStakeholdersExtended(String type) throws UnsupportedEncodingException {
public StakeholderExtended getStakeholderExtended(String stakeholderId) throws UnsupportedEncodingException {
Stakeholder stakeholder = this.service.findByPath(stakeholderId);
List<List<List<String>>> results = this.cacheService.getResponse(stakeholder.getType());
if(results != null) {
return new StakeholderExtended(stakeholder,
getNumber(results, 0, stakeholder.getIndex_id()),
getNumber(results, 1, stakeholder.getIndex_id()),
getNumber(results, 2, stakeholder.getIndex_id()));
}
else {
return new StakeholderExtended(stakeholder, "0", "0", "0");
}
}
public List<StakeholderExtended> getVisibleStakeholdersExtended(String type) throws UnsupportedEncodingException {
List<Stakeholder> stakeholders = this.service.getVisibleStakeholders(type, null);
List<List<List<String>>> results = this.cacheService.getResponse(type);
if(results != null) {