diff --git a/.opex/api-selfcare-external-api-pnpg/env/prod/config.yaml b/.opex/api-selfcare-external-api-pnpg/env/prod/config.yaml index 84d34f1b..52e53ca6 100644 --- a/.opex/api-selfcare-external-api-pnpg/env/prod/config.yaml +++ b/.opex/api-selfcare-external-api-pnpg/env/prod/config.yaml @@ -20,11 +20,6 @@ overrides: response_time_evaluation_frequency: 10 # Default: 10 response_time_evaluation_time_window: 30 # Default: 20 response_time_event_occurrences: 30 # Default: - /institutions/{institutionId}/geographicTaxonomy: - response_time_threshold: 1 # Default: 1 - response_time_evaluation_frequency: 10 # Default: 10 - response_time_evaluation_time_window: 30 # Default: 20 - response_time_event_occurrences: 30 # Default: /institutions/{institutionId}/products: response_time_threshold: 2 # Default: 1 response_time_evaluation_frequency: 10 # Default: 10 @@ -35,11 +30,6 @@ overrides: response_time_evaluation_frequency: 10 # Default: 10 response_time_evaluation_time_window: 30 # Default: 20 response_time_event_occurrences: 30 # Default: - /institutions/byGeoTaxonomies: - response_time_threshold: 1 # Default: 1 - response_time_evaluation_frequency: 10 # Default: 10 - response_time_evaluation_time_window: 30 # Default: 20 - response_time_event_occurrences: 30 # Default: /onboarding: response_time_threshold: 3 # Default: 1 response_time_evaluation_frequency: 10 # Default: 10 diff --git a/.opex/api-selfcare-external-api/env/prod/config.yaml b/.opex/api-selfcare-external-api/env/prod/config.yaml index 5e56225f..f9f73ea5 100644 --- a/.opex/api-selfcare-external-api/env/prod/config.yaml +++ b/.opex/api-selfcare-external-api/env/prod/config.yaml @@ -20,11 +20,6 @@ overrides: response_time_evaluation_frequency: 10 # Default: 10 response_time_evaluation_time_window: 30 # Default: 20 response_time_event_occurrences: 30 # Default: - /institutions/{institutionId}/geographicTaxonomy: - response_time_threshold: 1 # Default: 1 - response_time_evaluation_frequency: 10 # Default: 10 - response_time_evaluation_time_window: 30 # Default: 20 - response_time_event_occurrences: 30 # Default: /institutions/{institutionId}/products: response_time_threshold: 2 # Default: 1 response_time_evaluation_frequency: 10 # Default: 10 @@ -35,11 +30,6 @@ overrides: response_time_evaluation_frequency: 10 # Default: 10 response_time_evaluation_time_window: 30 # Default: 20 response_time_event_occurrences: 30 # Default: - /institutions/byGeoTaxonomies: - response_time_threshold: 1 # Default: 1 - response_time_evaluation_frequency: 10 # Default: 10 - response_time_evaluation_time_window: 30 # Default: 20 - response_time_event_occurrences: 30 # Default: /onboarding: response_time_threshold: 3 # Default: 1 response_time_evaluation_frequency: 10 # Default: 10 diff --git a/app/src/main/java/it/pagopa/selfcare/external_api/controller/InstitutionController.java b/app/src/main/java/it/pagopa/selfcare/external_api/controller/InstitutionController.java deleted file mode 100644 index 147c8817..00000000 --- a/app/src/main/java/it/pagopa/selfcare/external_api/controller/InstitutionController.java +++ /dev/null @@ -1,78 +0,0 @@ -package it.pagopa.selfcare.external_api.controller; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.v3.oas.annotations.tags.Tag; -import it.pagopa.selfcare.external_api.mapper.GeographicTaxonomyMapper; -import it.pagopa.selfcare.external_api.model.institution.GeographicTaxonomyResource; -import it.pagopa.selfcare.external_api.model.institution.Institution; -import it.pagopa.selfcare.external_api.model.institution.InstitutionDetailResource; -import it.pagopa.selfcare.external_api.model.institution.SearchMode; -import it.pagopa.selfcare.external_api.mapper.InstitutionResourceMapper; -import it.pagopa.selfcare.external_api.service.InstitutionService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; - -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; - -@Slf4j -@RestController -@RequestMapping(value = "/v1/institutions", produces = APPLICATION_JSON_VALUE) -@Api(tags = "Institution") -public class InstitutionController { - - private final InstitutionService institutionService; - - - private final InstitutionResourceMapper institutionResourceMapper; - - - @Autowired - public InstitutionController(InstitutionService institutionService, InstitutionResourceMapper institutionResourceMapper) { - this.institutionService = institutionService; - this.institutionResourceMapper = institutionResourceMapper; - } - - @Tag(name = "Institution") - @GetMapping(value = "/{institutionId}/geographicTaxonomy") - @ResponseStatus(HttpStatus.OK) - @ApiOperation(value = "", notes = "${swagger.external-api.institutions.api.getInstitutionGeographicTaxonomy}") - public List getInstitutionGeographicTaxonomies(@ApiParam("${swagger.external-api.institutions.model.id}") - @PathVariable("institutionId") - String institutionId) { - log.trace("getInstitutionGeographicTaxonomy start"); - log.debug("getInstitutionGeographicTaxonomy institutionId = {}", institutionId); - List geographicTaxonomies = institutionService.getGeographicTaxonomyList(institutionId) - .stream() - .map(GeographicTaxonomyMapper::toResource) - .toList(); - log.debug("getInstitutionGeographicTaxonomy result = {}", geographicTaxonomies); - log.trace("getInstitutionGeographicTaxonomy end"); - return geographicTaxonomies; - } - - @Tag(name = "Institution") - @GetMapping(value = "/byGeoTaxonomies") - @ResponseStatus(HttpStatus.OK) - @ApiOperation(value = "", notes = "${swagger.external-api.institutions.api.getInstitutionByGeoTaxonomies}") - public List getInstitutionsByGeoTaxonomies(@ApiParam("${swagger.external-api.geographicTaxonomy.model.id}") - @RequestParam("geoTaxonomies") Set geoTaxonomies, - @ApiParam("${swagger.external-api.geographicTaxonomy.searchMode}") - @RequestParam(value = "searchMode", required = false) Optional searchMode) { - log.trace("getInstitutionByGeoTaxonomies start"); - log.debug("getInstitutionByGeoTaxonomies geoTaxonomies = {}, searchMode = {}", geoTaxonomies, searchMode); - Collection institutions = institutionService.getInstitutionsByGeoTaxonomies(geoTaxonomies, searchMode.orElse(null)); - List result = institutions.stream().map(institutionResourceMapper::toResource).toList(); - log.debug("getInstitutionByGeoTaxonomies result = {}", result); - log.trace("getInstitutionByGeoTaxonomies end"); - return result; - } -} diff --git a/app/src/main/resources/swagger/api-docs.json b/app/src/main/resources/swagger/api-docs.json index 6c7e8f0c..9646ae33 100644 --- a/app/src/main/resources/swagger/api-docs.json +++ b/app/src/main/resources/swagger/api-docs.json @@ -42,169 +42,6 @@ "description" : "Pn Pg Controller" } ], "paths" : { - "/v1/institutions/byGeoTaxonomies" : { - "get" : { - "tags" : [ "Institution" ], - "summary" : "getInstitutionsByGeoTaxonomies", - "description" : "The service retrieves all the institutions based on given a list of geotax ids and a searchMode", - "operationId" : "getInstitutionsByGeoTaxonomiesUsingGET", - "parameters" : [ { - "name" : "geoTaxonomies", - "in" : "query", - "description" : "Geotaxonomy's internal Id", - "required" : true, - "style" : "form", - "explode" : true, - "schema" : { - "type" : "string" - } - }, { - "name" : "searchMode", - "in" : "query", - "description" : "Searching mode to find institutions based on geotax", - "required" : false, - "style" : "form", - "schema" : { - "type" : "string", - "enum" : [ "all", "any", "exact" ] - } - } ], - "responses" : { - "200" : { - "description" : "OK", - "content" : { - "application/json" : { - "schema" : { - "type" : "array", - "items" : { - "$ref" : "#/components/schemas/InstitutionDetailResource" - } - } - } - } - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "401" : { - "description" : "Unauthorized", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "404" : { - "description" : "Not Found", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "500" : { - "description" : "Internal Server Error", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - } - }, - "/v1/institutions/{institutionId}/geographicTaxonomy" : { - "get" : { - "tags" : [ "Institution" ], - "summary" : "getInstitutionGeographicTaxonomies", - "description" : "The service retrieve the institution's geographic taxonomy", - "operationId" : "getInstitutionGeographicTaxonomiesUsingGET", - "parameters" : [ { - "name" : "institutionId", - "in" : "path", - "description" : "Institution's unique internal Id", - "required" : true, - "style" : "simple", - "schema" : { - "type" : "string" - } - } ], - "responses" : { - "200" : { - "description" : "OK", - "content" : { - "application/json" : { - "schema" : { - "type" : "array", - "items" : { - "$ref" : "#/components/schemas/GeographicTaxonomyResource" - } - } - } - } - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "401" : { - "description" : "Unauthorized", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "404" : { - "description" : "Not Found", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "500" : { - "description" : "Internal Server Error", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - } - }, "/v2/institutions" : { "get" : { "tags" : [ "Institution", "external-pnpg" ], @@ -1672,20 +1509,6 @@ } } }, - "GeographicTaxonomyResource" : { - "title" : "GeographicTaxonomyResource", - "type" : "object", - "properties" : { - "code" : { - "type" : "string", - "description" : "Institution's geographic taxonomy ISTAT code" - }, - "desc" : { - "type" : "string", - "description" : "Institution's geographic taxonomy extended name" - } - } - }, "ImportContractDto" : { "title" : "ImportContractDto", "required" : [ "contractType", "fileName", "filePath", "onboardingDate" ], @@ -1710,114 +1533,6 @@ } } }, - "InstitutionDetailResource" : { - "title" : "InstitutionDetailResource", - "type" : "object", - "properties" : { - "address" : { - "type" : "string", - "description" : "Institution's physical address" - }, - "aooParentCode" : { - "type" : "string", - "description" : "AOO unit parent institution Code" - }, - "businessRegisterPlace" : { - "type" : "string", - "description" : "Institution's business register place" - }, - "city" : { - "type" : "string", - "description" : "Institution's physical address city" - }, - "country" : { - "type" : "string", - "description" : "Institution's physical address country" - }, - "county" : { - "type" : "string", - "description" : "Institution's physical address county" - }, - "description" : { - "type" : "string", - "description" : "Institution's legal name" - }, - "digitalAddress" : { - "type" : "string", - "description" : "Institution's digitalAddress" - }, - "externalId" : { - "type" : "string", - "description" : "Institution's unique external identifier" - }, - "geographicTaxonomies" : { - "type" : "array", - "description" : "Institution's geographic taxonomy", - "items" : { - "$ref" : "#/components/schemas/GeographicTaxonomyResource" - } - }, - "id" : { - "type" : "string", - "description" : "Institution's unique internal Id", - "format" : "uuid" - }, - "imported" : { - "type" : "boolean", - "description" : "True if institution is stored from batch api", - "example" : false - }, - "institutionType" : { - "type" : "string", - "description" : "Institution's type", - "enum" : [ "AS", "CON", "GSP", "PA", "PG", "PRV", "PSP", "PT", "REC", "SA", "SCP" ] - }, - "origin" : { - "type" : "string", - "description" : "Institution data origin" - }, - "originId" : { - "type" : "string", - "description" : "Institution's details origin Id" - }, - "parentDescription" : { - "type" : "string", - "description" : "Institutions AOO/UO unit parent's description" - }, - "rea" : { - "type" : "string", - "description" : "Institution's REA" - }, - "shareCapital" : { - "type" : "string", - "description" : "Institution's share capital value" - }, - "subunitCode" : { - "type" : "string", - "description" : "Institutions AOO/UO unit Code" - }, - "subunitType" : { - "type" : "string", - "description" : "Institutions AOO/UO unit type" - }, - "supportEmail" : { - "type" : "string", - "description" : "Institution's support email contact" - }, - "supportPhone" : { - "type" : "string", - "description" : "Institution's support phone contact" - }, - "taxCode" : { - "type" : "string", - "description" : "Institution's taxCode" - }, - "zipCode" : { - "type" : "string", - "description" : "Institution's zipCode" - } - } - }, "InstitutionLocationDataDto" : { "title" : "InstitutionLocationDataDto", "type" : "object", diff --git a/app/src/test/java/it/pagopa/selfcare/external_api/controller/InstitutionControllerTest.java b/app/src/test/java/it/pagopa/selfcare/external_api/controller/InstitutionControllerTest.java deleted file mode 100644 index 45c33a54..00000000 --- a/app/src/test/java/it/pagopa/selfcare/external_api/controller/InstitutionControllerTest.java +++ /dev/null @@ -1,136 +0,0 @@ -package it.pagopa.selfcare.external_api.controller; - -import com.fasterxml.jackson.core.type.TypeReference; -import it.pagopa.selfcare.external_api.mapper.InstitutionResourceMapperImpl; -import it.pagopa.selfcare.external_api.model.institution.GeographicTaxonomy; -import it.pagopa.selfcare.external_api.model.institution.Institution; -import it.pagopa.selfcare.external_api.service.InstitutionService; -import org.apache.commons.lang3.StringUtils; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Spy; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.core.io.ClassPathResource; - -import java.nio.file.Files; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import static org.hamcrest.Matchers.hasSize; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.when; -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -@ExtendWith(MockitoExtension.class) -public class InstitutionControllerTest extends BaseControllerTest { - - @InjectMocks - private InstitutionController institutionController; - - @Spy - private InstitutionResourceMapperImpl institutionResourceMapper; - - @Mock - private InstitutionService institutionService; - - @BeforeEach - void setUp(){ - super.setUp(institutionController); - } - - - - @Test - void getInstitutionGeographicTaxonomiesWith2Elements() throws Exception { - - GeographicTaxonomy geographicTaxonomy = new GeographicTaxonomy(); - geographicTaxonomy.setCode("testCode1"); - geographicTaxonomy.setDesc("testDesc1"); - - GeographicTaxonomy geographicTaxonomy2 = new GeographicTaxonomy(); - geographicTaxonomy2.setCode("testCode2"); - geographicTaxonomy2.setDesc("testDesc2"); - - when(institutionService.getGeographicTaxonomyList(anyString())).thenReturn(List.of(geographicTaxonomy, geographicTaxonomy2)); - - mockMvc.perform(get("/v1/institutions/{institutionId}/geographicTaxonomy", "testInstitutionId") - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$", hasSize(2))) - .andExpect(content().string("[{\"code\":\"testCode1\",\"desc\":\"testDesc1\"},{\"code\":\"testCode2\",\"desc\":\"testDesc2\"}]")) - .andReturn(); - } - - @Test - void getInstitutionGeographicTaxonomiesWithEmptyList() throws Exception { - - when(institutionService.getGeographicTaxonomyList(anyString())).thenReturn(Collections.emptyList()); - - mockMvc.perform(get("/v1/institutions/{institutionId}/geographicTaxonomy", "testInstitutionId") - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$", hasSize(0))) - .andReturn(); - } - - - @Test - void getInstitutionsByGeoTaxonomiesWith2ReturnedElements() throws Exception { - - ClassPathResource productResponse = new ClassPathResource("expectations/Institution.json"); - byte[] institutionStream = Files.readAllBytes(productResponse.getFile().toPath()); - List institution = objectMapper.readValue(institutionStream, new TypeReference<>() { - }); - - ClassPathResource outputResource = new ClassPathResource("expectations/InstitutionDetailResource.json"); - String expectedResource = StringUtils.deleteWhitespace(new String(Files.readAllBytes(outputResource.getFile().toPath()))); - - when(institutionService.getInstitutionsByGeoTaxonomies(Set.of("testGeoTaxonomies"), null)).thenReturn(institution); - - mockMvc.perform(get("/v1/institutions/byGeoTaxonomies") - .param("geoTaxonomies", "testGeoTaxonomies") - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(content().string(expectedResource)) - .andExpect(jsonPath("$", hasSize(2))) - .andExpect(status().isOk()) - .andExpect(content().contentType(APPLICATION_JSON_VALUE)) - .andReturn(); - } - - - @Test - void getInstitutionsByGeoTaxonomiesWithEmptyList() throws Exception { - - when(institutionService.getInstitutionsByGeoTaxonomies(Set.of("testGeoTaxonomies"), null)) - .thenReturn(Collections.emptyList()); - - mockMvc.perform(get("/v1/institutions/byGeoTaxonomies") - .param("geoTaxonomies", "testGeoTaxonomies") - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$", hasSize(0))) - .andExpect(status().isOk()) - .andExpect(content().contentType(APPLICATION_JSON_VALUE)) - .andReturn(); - } - - - @Test - void getInstitutionsByGeoTaxonomiesWithoutGeoTaxonomyParam() throws Exception { - - mockMvc.perform(get("/v1/institutions/byGeoTaxonomies") - .contentType(APPLICATION_JSON_VALUE) - .accept(APPLICATION_JSON_VALUE)) - .andExpect(status().isBadRequest()) - .andReturn(); - } -}