diff --git a/service/src/main/inse/dashboard/service.py b/service/src/main/inse/dashboard/service.py index dde3ba29..384e0755 100644 --- a/service/src/main/inse/dashboard/service.py +++ b/service/src/main/inse/dashboard/service.py @@ -27,8 +27,9 @@ from .model import ( TopicWordCloud, TopicWordCloudWord, ) +from inse.projects.model import ProjectType, ProjectsFilteringProperties from inse.projects.projects_search_client import ( - get_eu_organization_contributions, + get_eu_organization_project_contributions, ) TOP_AUTHOR_LIMIT = 10 @@ -842,11 +843,16 @@ async def _top_patent_authors(institution_id: str) -> list[TopAuthor]: async def _top_eu_project_publication_authors( organization_names: list[str], ) -> list[TopAuthor]: - contributions = await get_eu_organization_contributions( + project_page = await get_eu_organization_project_contributions( organization_names=organization_names, + projects_filtering_properties=ProjectsFilteringProperties( + project_type=ProjectType.EU, + page=0, + size=10000, + ), ) - project_ids = list(contributions.keys()) + project_ids = [project.project_id for project in project_page.elements] if not project_ids: return [] diff --git a/service/src/main/inse/dashboard/test_service.py b/service/src/main/inse/dashboard/test_service.py index 0a03a574..93302fc2 100644 --- a/service/src/main/inse/dashboard/test_service.py +++ b/service/src/main/inse/dashboard/test_service.py @@ -1,5 +1,6 @@ from unittest.mock import AsyncMock, patch from datetime import datetime +from types import SimpleNamespace import pytest from fastapi import HTTPException @@ -244,12 +245,15 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects(): "inse.dashboard.service.InstitutionsSearchClient.get_institution_aliases_by_oa_institution_id", new=AsyncMock(return_value=["Example University"]), ), patch( - "inse.dashboard.service.get_eu_organization_contributions", + "inse.dashboard.service.get_eu_organization_project_contributions", new=AsyncMock( - return_value={ - "P1": object(), - "P2": object(), - } + return_value=SimpleNamespace( + elements=[ + SimpleNamespace(project_id="P1"), + SimpleNamespace(project_id="P2"), + SimpleNamespace(project_id="P3"), + ], + ) ), ), patch( "inse.dashboard.service.OrgPatentsSearchClient.top_authors_by_institution", @@ -306,6 +310,7 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects(): assert set(eu_body["query"]["terms"]["projectID"]) == { "P1", "P2", + "P3", } assert eu_body["_source"] == ["projectID", "doi", "qaProcessedDoi"] assert "aggs" not in eu_body @@ -429,12 +434,14 @@ async def test_top_eu_project_authors_count_filtered_projects_by_stable_author_i "inse.dashboard.service.InstitutionsSearchClient.get_institution_aliases_by_oa_institution_id", new=AsyncMock(return_value=["Example University"]), ), patch( - "inse.dashboard.service.get_eu_organization_contributions", + "inse.dashboard.service.get_eu_organization_project_contributions", new=AsyncMock( - return_value={ - "P1": object(), - "P2": object(), - } + return_value=SimpleNamespace( + elements=[ + SimpleNamespace(project_id="P1"), + SimpleNamespace(project_id="P2"), + ], + ) ), ), patch( "inse.dashboard.service.OrgPatentsSearchClient.top_authors_by_institution", @@ -479,8 +486,14 @@ async def test_top_authors_returns_partial_response_when_one_source_fails(): "inse.dashboard.service.InstitutionsSearchClient.get_institution_aliases_by_oa_institution_id", new=AsyncMock(return_value=["Example University"]), ), patch( - "inse.dashboard.service.get_eu_organization_contributions", - new=AsyncMock(return_value={"P1": object()}), + "inse.dashboard.service.get_eu_organization_project_contributions", + new=AsyncMock( + return_value=SimpleNamespace( + elements=[ + SimpleNamespace(project_id="P1"), + ], + ) + ), ), patch( "inse.dashboard.service.OrgPatentsSearchClient.top_authors_by_institution", new=AsyncMock(return_value=[]), @@ -539,8 +552,8 @@ async def test_top_authors_can_rank_works_by_last_five_years(): "inse.dashboard.service.InstitutionsSearchClient.get_institution_aliases_by_oa_institution_id", new=AsyncMock(return_value=["Example University"]), ), patch( - "inse.dashboard.service.get_eu_organization_contributions", - new=AsyncMock(return_value={}), + "inse.dashboard.service.get_eu_organization_project_contributions", + new=AsyncMock(return_value=SimpleNamespace(elements=[])), ), patch( "inse.dashboard.service.OrgPatentsSearchClient.top_authors_by_institution", new=AsyncMock(return_value=[]),