diff --git a/src/main/java/eu/dnetlib/irishmonitorservice/controllers/StakeholderExtendedController.java b/src/main/java/eu/dnetlib/irishmonitorservice/controllers/StakeholderExtendedController.java index 766284f..035b683 100644 --- a/src/main/java/eu/dnetlib/irishmonitorservice/controllers/StakeholderExtendedController.java +++ b/src/main/java/eu/dnetlib/irishmonitorservice/controllers/StakeholderExtendedController.java @@ -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 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 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); } } diff --git a/src/main/java/eu/dnetlib/irishmonitorservice/services/StakeholderExtendedService.java b/src/main/java/eu/dnetlib/irishmonitorservice/services/StakeholderExtendedService.java index e0cea2e..8719f1a 100644 --- a/src/main/java/eu/dnetlib/irishmonitorservice/services/StakeholderExtendedService.java +++ b/src/main/java/eu/dnetlib/irishmonitorservice/services/StakeholderExtendedService.java @@ -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 getStakeholdersExtended(String type) throws UnsupportedEncodingException { + public StakeholderExtended getStakeholderExtended(String stakeholderId) throws UnsupportedEncodingException { + Stakeholder stakeholder = this.service.findByPath(stakeholderId); + List>> 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 getVisibleStakeholdersExtended(String type) throws UnsupportedEncodingException { List stakeholders = this.service.getVisibleStakeholders(type, null); List>> results = this.cacheService.getResponse(type); if(results != null) {