diff --git a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/model/institutions/Subscription.java b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/model/institutions/Subscription.java index 2aeac6767..cc05ce422 100644 --- a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/model/institutions/Subscription.java +++ b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/model/institutions/Subscription.java @@ -24,7 +24,7 @@ public enum Subscription { BIZ("/products/bizevents", "BIZ - Recupero ricevute Ente Creditore", "biz-", CI, null, false), FDR_ORG("/products/fdr-org", "FdR - Flussi di Rendicontazione (EC)", "fdrorg-", CI, "fdr", true), FDR_PSP("/products/fdr-psp", "FdR - Flussi di Rendicontazione (PSP)", "fdrpsp-", PSP, "fdr", true), - QI_FDR_KPI("/products/qi-fdr-kpi", "FdR - Quality Improvement KPI API", "qifdrkpiservice-", PSP, "qi", false), + QI_FDR_KPI("/products/qi-fdr-kpi", "FdR - Quality Improvement KPI API", "qifdrkpiservice-", PSP, "qi", true), BO_EXT_EC("/apis/%s-backoffice-external-ec-api-v1", "Backoffice External (EC)", "selfcareboexternalec-", CI, "backoffice_external", false), BO_EXT_PSP("/apis/%s-backoffice-external-psp-api-v1", "Backoffice External (PSP)", "selfcareboexternalpsp-", PSP, "backoffice_external", false), PRINT_NOTICE("/products/pagopa_notices_service_external", "Stampa Avvisi", "printnotice-", CI, null, false), diff --git a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementService.java b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementService.java index a7a86cee0..5631b2d42 100644 --- a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementService.java +++ b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementService.java @@ -459,7 +459,7 @@ private AuthorizationEntity getAuthorizationEntity( String taxCode ) { String value = taxCode; - if (subscription.equals(Subscription.FDR_PSP)) { + if (subscription.equals(Subscription.FDR_PSP) || subscription.equals(Subscription.QI_FDR_KPI)) { try { value = this.legacyPspCodeUtil.retrievePspCode(taxCode, false); } catch (Exception e) { @@ -603,6 +603,7 @@ private record AuthorizationConfig(List authorizationEntiti } private boolean isPSPCodeRequiredForProvidedSubscriptionAnInstitution(Subscription subscriptionCode, InstitutionResponse institution) { - return subscriptionCode.equals(Subscription.FDR_PSP) && !InstitutionType.PT.equals(institution.getInstitutionType()); + return (subscriptionCode.equals(Subscription.FDR_PSP) || subscriptionCode.equals(Subscription.QI_FDR_KPI)) + && !InstitutionType.PT.equals(institution.getInstitutionType()); } } diff --git a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementServiceTest.java b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementServiceTest.java index 006090e0f..5ff9a8ac1 100644 --- a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementServiceTest.java +++ b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementServiceTest.java @@ -443,15 +443,16 @@ void createSubscriptionKeysForGPDSuccess(Subscription sub) { assertEquals(AUTHORIZER_SEGREGATION_CODES_METADATA_SHORT_KEY, captorValue.getOtherMetadata().get(0).getShortKey()); } - @Test - void createSubscriptionKeysForSubscriptionThatRequirePSPCodeFailNoPSPCodeFound() { + @ParameterizedTest + @EnumSource(value = Subscription.class, names = {"FDR_PSP", "QI_FDR_KPI"}) + void createSubscriptionKeysForSubscriptionThatRequirePSPCodeFailNoPSPCodeFound(Subscription sub) { it.pagopa.selfcare.pagopa.backoffice.model.institutions.client.Institution institutionResponse = buildInstitutionResponse(InstitutionType.PSP); when(externalApiClient.getInstitution(any())).thenReturn(institutionResponse); when(legacyPspCodeUtil.retrievePspCode(INSTITUTION_TAX_CODE, false)).thenThrow(AppException.class); AppException e = assertThrows(AppException.class, () -> - service.createSubscriptionKeys(INSTITUTION_ID, Subscription.FDR_PSP)); + service.createSubscriptionKeys(INSTITUTION_ID, sub)); assertNotNull(e); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, e.getHttpStatus()); @@ -561,10 +562,11 @@ void regeneratePrimaryKeyForGPDSuccess(Subscription sub) { assertEquals(AUTHORIZER_SEGREGATION_CODES_METADATA_SHORT_KEY, captorValue.getOtherMetadata().get(0).getShortKey()); } - @Test - void regeneratePrimaryKeyForSubscriptionThatRequirePSPCodeFailNoPSPCodeFound() { + @ParameterizedTest + @EnumSource(value = Subscription.class, names = {"FDR_PSP", "QI_FDR_KPI"}) + void regeneratePrimaryKeyForSubscriptionThatRequirePSPCodeFailNoPSPCodeFound(Subscription sub) { it.pagopa.selfcare.pagopa.backoffice.model.institutions.client.Institution institutionResponse = buildInstitutionResponse(InstitutionType.PSP); - String subscriptionId = String.format("%s%s", Subscription.FDR_PSP.getPrefixId(), institutionResponse.getTaxCode()); + String subscriptionId = String.format("%s%s", sub.getPrefixId(), institutionResponse.getTaxCode()); when(externalApiClient.getInstitution(any())).thenReturn(institutionResponse); when(legacyPspCodeUtil.retrievePspCode(INSTITUTION_TAX_CODE, false)).thenThrow(AppException.class); @@ -582,10 +584,11 @@ void regeneratePrimaryKeyForSubscriptionThatRequirePSPCodeFailNoPSPCodeFound() { verify(authorizerConfigClient, never()).createAuthorization(any()); } - @Test - void regeneratePrimaryKeyForFDRPSPSuccess() { + @ParameterizedTest + @EnumSource(value = Subscription.class, names = {"FDR_PSP", "QI_FDR_KPI"}) + void regeneratePrimaryKeyForFDRPSPSuccess(Subscription sub) { it.pagopa.selfcare.pagopa.backoffice.model.institutions.client.Institution institutionResponse = buildInstitutionResponse(InstitutionType.PSP); - String subscriptionId = String.format("%s%s", Subscription.FDR_PSP.getPrefixId(), institutionResponse.getTaxCode()); + String subscriptionId = String.format("%s%s", sub.getPrefixId(), institutionResponse.getTaxCode()); InstitutionApiKeys institutionApiKeys = buildInstitutionApiKeys(subscriptionId); when(apimClient.getApiSubscriptions(anyString())).thenReturn(Collections.singletonList(institutionApiKeys)); @@ -711,10 +714,11 @@ void regenerateSecondaryKeyForGPDSuccess(Subscription sub) { assertEquals(AUTHORIZER_SEGREGATION_CODES_METADATA_SHORT_KEY, captorValue.getOtherMetadata().get(0).getShortKey()); } - @Test - void regenerateSecondaryKeyForSubscriptionThatRequirePSPCodeFailNoPSPCodeFound() { + @ParameterizedTest + @EnumSource(value = Subscription.class, names = {"FDR_PSP", "QI_FDR_KPI"}) + void regenerateSecondaryKeyForSubscriptionThatRequirePSPCodeFailNoPSPCodeFound(Subscription sub) { it.pagopa.selfcare.pagopa.backoffice.model.institutions.client.Institution institutionResponse = buildInstitutionResponse(InstitutionType.PSP); - String subscriptionId = String.format("%s%s", Subscription.FDR_PSP.getPrefixId(), institutionResponse.getTaxCode()); + String subscriptionId = String.format("%s%s", sub.getPrefixId(), institutionResponse.getTaxCode()); when(externalApiClient.getInstitution(any())).thenReturn(institutionResponse); when(legacyPspCodeUtil.retrievePspCode(INSTITUTION_TAX_CODE, false)).thenThrow(AppException.class); @@ -732,10 +736,11 @@ void regenerateSecondaryKeyForSubscriptionThatRequirePSPCodeFailNoPSPCodeFound() verify(authorizerConfigClient, never()).createAuthorization(any()); } - @Test - void regenerateSecondaryKeyForSubscriptionThatRequirePSPCodeSuccess() { + @ParameterizedTest + @EnumSource(value = Subscription.class, names = {"FDR_PSP", "QI_FDR_KPI"}) + void regenerateSecondaryKeyForSubscriptionThatRequirePSPCodeSuccess(Subscription sub) { it.pagopa.selfcare.pagopa.backoffice.model.institutions.client.Institution institutionResponse = buildInstitutionResponse(InstitutionType.PSP); - String subscriptionId = String.format("%s%s", Subscription.FDR_PSP.getPrefixId(), institutionResponse.getTaxCode()); + String subscriptionId = String.format("%s%s", sub.getPrefixId(), institutionResponse.getTaxCode()); InstitutionApiKeys institutionApiKeys = buildInstitutionApiKeys(subscriptionId); when(apimClient.getApiSubscriptions(anyString())).thenReturn(Collections.singletonList(institutionApiKeys));