Skip to content

Commit

Permalink
[SELC-4077] Feat: added clients for core API (#348)
Browse files Browse the repository at this point in the history
* add clients for core API

* refactor clientConfig class
  • Loading branch information
flaminiaScarciofolo authored Feb 16, 2024
1 parent 18f252b commit 18ddba3
Show file tree
Hide file tree
Showing 13 changed files with 3,003 additions and 1,042 deletions.
3,927 changes: 2,929 additions & 998 deletions connector/rest/docs/openapi/api-selfcare-core-docs.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import it.pagopa.selfcare.dashboard.connector.model.institution.UpdateInstitutionResource;
import it.pagopa.selfcare.dashboard.connector.model.product.PartyProduct;
import it.pagopa.selfcare.dashboard.connector.model.user.UserInfo;
import it.pagopa.selfcare.dashboard.connector.rest.client.MsCoreDelegationApiRestClient;
import it.pagopa.selfcare.dashboard.connector.rest.client.CoreDelegationApiRestClient;
import it.pagopa.selfcare.dashboard.connector.rest.client.CoreUserApiRestClient;
import it.pagopa.selfcare.dashboard.connector.rest.client.MsCoreRestClient;
import it.pagopa.selfcare.dashboard.connector.rest.client.MsCoreUserApiRestClient;
import it.pagopa.selfcare.dashboard.connector.rest.model.ProductState;
import it.pagopa.selfcare.dashboard.connector.rest.model.RelationshipInfo;
import it.pagopa.selfcare.dashboard.connector.rest.model.RelationshipsResponse;
Expand Down Expand Up @@ -47,17 +47,17 @@ class MsCoreConnectorImpl implements MsCoreConnector {
static final String REQUIRED_UPDATE_RESOURCE_MESSAGE = "An Institution description is required";

private final MsCoreRestClient msCoreRestClient;
private final MsCoreUserApiRestClient msCoreUserApiRestClient;
private final CoreUserApiRestClient msCoreUserApiRestClient;
private final BrokerMapper brokerMapper;
private final InstitutionMapper institutionMapper;

private final MsCoreDelegationApiRestClient msCoreDelegationApiRestClient;
private final CoreDelegationApiRestClient msCoreDelegationApiRestClient;

private final DelegationRestClientMapper delegationMapper;


@Autowired
public MsCoreConnectorImpl(MsCoreRestClient msCoreRestClient, MsCoreUserApiRestClient msCoreUserApiRestClient, InstitutionMapper institutionMapper, BrokerMapper brokerMapper, MsCoreDelegationApiRestClient msCoreInstitutionApiRestClient, DelegationRestClientMapper delegationMapper) {
public MsCoreConnectorImpl(MsCoreRestClient msCoreRestClient, CoreUserApiRestClient msCoreUserApiRestClient, InstitutionMapper institutionMapper, BrokerMapper brokerMapper, CoreDelegationApiRestClient msCoreInstitutionApiRestClient, DelegationRestClientMapper delegationMapper) {
this.msCoreRestClient = msCoreRestClient;
this.msCoreUserApiRestClient = msCoreUserApiRestClient;
this.institutionMapper = institutionMapper;
Expand All @@ -81,7 +81,7 @@ public Collection<InstitutionInfo> getOnBoardedInstitutions() {
public List<InstitutionInfo> getUserProducts(String userId) {
log.trace("getUserProducts start");
UserProductsResponse productsInfoUsingGET = msCoreUserApiRestClient._getUserProductsInfoUsingGET(userId, null,
String.join(",", ACTIVE.name(), PENDING.name(), TOBEVALIDATED.name())).getBody();
List.of(ACTIVE.name(), PENDING.name(), TOBEVALIDATED.name())).getBody();

if(Objects.isNull(productsInfoUsingGET) ||
Objects.isNull(productsInfoUsingGET.getBindings())) return List.of();
Expand Down Expand Up @@ -227,7 +227,7 @@ public List<BrokerInfo> findInstitutionsByProductAndType(String productId, Strin
public List<Delegation> getDelegations(String from, String to, String productId) {
log.trace("getDelegations start");
log.debug("getDelegations productId = {}, type = {}", from, productId);
List<DelegationResponse> delegationsResponse = msCoreDelegationApiRestClient._getDelegationsUsingGET(from, to, productId).getBody();
List<DelegationResponse> delegationsResponse = msCoreDelegationApiRestClient._getDelegationsUsingGET(from, to, productId, null).getBody();

if(Objects.isNull(delegationsResponse))
return List.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

import org.springframework.cloud.openfeign.FeignClient;
@FeignClient(name = "${rest-client.ms-core-delegation-api.serviceCode}", url = "${rest-client.ms-core.base-url}")
public interface MsCoreDelegationApiRestClient extends it.pagopa.selfcare.core.generated.openapi.v1.api.DelegationApi{
public interface CoreDelegationApiRestClient extends it.pagopa.selfcare.core.generated.openapi.v1.api.DelegationApi{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package it.pagopa.selfcare.dashboard.connector.rest.client;

import it.pagopa.selfcare.core.generated.openapi.v1.api.InstitutionApi;
import org.springframework.cloud.openfeign.FeignClient;

@FeignClient(name = "${rest-client.ms-core-institution-api.serviceCode}", url = "${rest-client.ms-core.base-url}")
public interface CoreInstitutionApiRestClient extends InstitutionApi {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package it.pagopa.selfcare.dashboard.connector.rest.client;

import it.pagopa.selfcare.core.generated.openapi.v1.api.ManagementApi;
import org.springframework.cloud.openfeign.FeignClient;

@FeignClient(name = "${rest-client.ms-core-management-api.serviceCode}", url = "${rest-client.ms-core.base-url}")

public interface CoreManagementApiRestClient extends ManagementApi {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package it.pagopa.selfcare.dashboard.connector.rest.client;

import it.pagopa.selfcare.core.generated.openapi.v1.api.OnboardingApi;
import org.springframework.cloud.openfeign.FeignClient;

@FeignClient(name = "${rest-client.ms-core-onboarding-api.serviceCode}", url = "${rest-client.ms-core.base-url}")
public interface CoreOnboardingApiRestClient extends OnboardingApi {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import org.springframework.cloud.openfeign.FeignClient;

@FeignClient(name = "${rest-client.ms-core-user-api.serviceCode}", url = "${rest-client.ms-core.base-url}")
public interface MsCoreUserApiRestClient extends it.pagopa.selfcare.core.generated.openapi.v1.api.PersonsApi {
public interface CoreUserApiRestClient extends it.pagopa.selfcare.core.generated.openapi.v1.api.PersonsApi {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package it.pagopa.selfcare.dashboard.connector.rest.config;

import it.pagopa.selfcare.commons.connector.rest.config.RestClientBaseConfig;
import it.pagopa.selfcare.dashboard.connector.rest.client.MsCoreRestClient;
import it.pagopa.selfcare.dashboard.connector.rest.client.MsCoreUserApiRestClient;
import it.pagopa.selfcare.dashboard.connector.rest.client.*;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;

@Configuration
@Import(RestClientBaseConfig.class)
@EnableFeignClients(clients = {MsCoreRestClient.class, MsCoreUserApiRestClient.class})
@EnableFeignClients(clients = {MsCoreRestClient.class, CoreUserApiRestClient.class, CoreDelegationApiRestClient.class,
CoreInstitutionApiRestClient.class, CoreOnboardingApiRestClient.class, CoreManagementApiRestClient.class})
@PropertySource("classpath:config/ms-core-rest-client.properties")
class MsCoreRestClientConfig {
public class MsCoreRestClientConfig {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Configuration
@Import(RestClientBaseConfig.class)
@EnableFeignClients(clients = PartyManagementRestClient.class)
@EnableFeignClients(clients = {PartyManagementRestClient.class})
@PropertySource("classpath:config/party-management-rest-client.properties")
class PartyManagementRestClientConfig {
public class PartyManagementRestClientConfig {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Configuration
@Import(RestClientBaseConfig.class)
@EnableFeignClients(clients = PartyProcessRestClient.class)
@EnableFeignClients(clients = {PartyProcessRestClient.class})
@PropertySource("classpath:config/party-process-rest-client.properties")
class PartyProcessRestClientConfig {
public class PartyProcessRestClientConfig {
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ feign.client.config.ms-core.readTimeout=${USERVICE_MS_CORE_REST_CLIENT_READ_TIME
feign.client.config.ms-core.loggerLevel=${USERVICE_MS_CORE_REST_CLIENT_LOGGER_LEVEL:${REST_CLIENT_LOGGER_LEVEL:FULL}}


rest-client.ms-core-institution-api.serviceCode=ms-core-institution-api
feign.client.config.ms-core-institution-api.requestInterceptors[0]=it.pagopa.selfcare.commons.connector.rest.interceptor.AuthorizationHeaderInterceptor
feign.client.config.ms-core-institution-api.connectTimeout=${USERVICE_MS_CORE_REST_CLIENT_CONNECT_TIMEOUT:${REST_CLIENT_CONNECT_TIMEOUT:5000}}
feign.client.config.ms-core-institution-api.readTimeout=${USERVICE_MS_CORE_REST_CLIENT_READ_TIMEOUT:${REST_CLIENT_READ_TIMEOUT:5000}}
feign.client.config.ms-core-institution-api.loggerLevel=${USERVICE_MS_CORE_REST_CLIENT_LOGGER_LEVEL:${REST_CLIENT_LOGGER_LEVEL:FULL}}


rest-client.ms-core-user-api.serviceCode=ms-core-user-api
feign.client.config.ms-core-user-api.connectTimeout=${USERVICE_MS_CORE_REST_CLIENT_CONNECT_TIMEOUT:${REST_CLIENT_CONNECT_TIMEOUT:5000}}
feign.client.config.ms-core-user-api.requestInterceptors[0]=it.pagopa.selfcare.commons.connector.rest.interceptor.AuthorizationHeaderInterceptor
Expand All @@ -38,4 +45,18 @@ feign.client.config.ms-core-delegation-api.connectTimeout=${USERVICE_MS_CORE_RES
feign.client.config.ms-core-delegation-api.requestInterceptors[0]=it.pagopa.selfcare.commons.connector.rest.interceptor.AuthorizationHeaderInterceptor
feign.client.config.ms-core-delegation-api.errorDecoder=it.pagopa.selfcare.dashboard.connector.rest.decoder.FeignErrorDecoder
feign.client.config.ms-core-delegation-api.readTimeout=${USERVICE_MS_CORE_REST_CLIENT_READ_TIMEOUT:${REST_CLIENT_READ_TIMEOUT:5000}}
feign.client.config.ms-core-delegation-api.loggerLevel=${USERVICE_MS_CORE_REST_CLIENT_LOGGER_LEVEL:${REST_CLIENT_LOGGER_LEVEL:FULL}}
feign.client.config.ms-core-delegation-api.loggerLevel=${USERVICE_MS_CORE_REST_CLIENT_LOGGER_LEVEL:${REST_CLIENT_LOGGER_LEVEL:FULL}}


rest-client.ms-core-management-api.serviceCode=ms-core-management-api
feign.client.config.ms-core-management-api.requestInterceptors[0]=it.pagopa.selfcare.commons.connector.rest.interceptor.AuthorizationHeaderInterceptor
feign.client.config.ms-core-management-api.connectTimeout=${USERVICE_MS_CORE_REST_CLIENT_CONNECT_TIMEOUT:${REST_CLIENT_CONNECT_TIMEOUT:5000}}
feign.client.config.ms-core-management-api.readTimeout=${USERVICE_MS_CORE_REST_CLIENT_READ_TIMEOUT:${REST_CLIENT_READ_TIMEOUT:5000}}
feign.client.config.ms-core-management-api.loggerLevel=${USERVICE_MS_CORE_REST_CLIENT_LOGGER_LEVEL:${REST_CLIENT_LOGGER_LEVEL:FULL}}


rest-client.ms-core-onboarding-api.serviceCode=ms-core-onboarding-api
feign.client.config.ms-core-onboarding-api.requestInterceptors[0]=it.pagopa.selfcare.commons.connector.rest.interceptor.AuthorizationHeaderInterceptor
feign.client.config.ms-core-onboarding-api.connectTimeout=${USERVICE_MS_CORE_REST_CLIENT_CONNECT_TIMEOUT:${REST_CLIENT_CONNECT_TIMEOUT:5000}}
feign.client.config.ms-core-onboarding-api.readTimeout=${USERVICE_MS_CORE_REST_CLIENT_READ_TIMEOUT:${REST_CLIENT_READ_TIMEOUT:5000}}
feign.client.config.ms-core-onboarding-api.loggerLevel=${USERVICE_MS_CORE_REST_CLIENT_LOGGER_LEVEL:${REST_CLIENT_LOGGER_LEVEL:FULL}}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import it.pagopa.selfcare.dashboard.connector.model.user.ProductInfo;
import it.pagopa.selfcare.dashboard.connector.model.user.RoleInfo;
import it.pagopa.selfcare.dashboard.connector.model.user.UserInfo;
import it.pagopa.selfcare.dashboard.connector.rest.client.MsCoreDelegationApiRestClient;
import it.pagopa.selfcare.dashboard.connector.rest.client.CoreDelegationApiRestClient;
import it.pagopa.selfcare.dashboard.connector.rest.client.CoreUserApiRestClient;
import it.pagopa.selfcare.dashboard.connector.rest.client.MsCoreRestClient;
import it.pagopa.selfcare.dashboard.connector.rest.client.MsCoreUserApiRestClient;
import it.pagopa.selfcare.dashboard.connector.rest.model.InstitutionUpdate;
import it.pagopa.selfcare.dashboard.connector.rest.model.ProductState;
import it.pagopa.selfcare.dashboard.connector.rest.model.RelationshipInfo;
Expand All @@ -39,7 +39,6 @@
import it.pagopa.selfcare.dashboard.connector.rest.model.onboarding.OnboardingUsersRequest;
import it.pagopa.selfcare.dashboard.connector.rest.model.product.Product;
import it.pagopa.selfcare.dashboard.connector.rest.model.product.Products;
import it.pagopa.selfcare.dashboard.connector.rest.model.relationship.Relationship;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -86,10 +85,10 @@ class MsCoreConnectorImplTest {
private MsCoreRestClient msCoreRestClientMock;

@MockBean
private MsCoreUserApiRestClient msCoreUserApiRestClientMock;
private CoreUserApiRestClient msCoreUserApiRestClientMock;

@MockBean
private MsCoreDelegationApiRestClient msCoreInstitutionApiRestClient;
private CoreDelegationApiRestClient msCoreInstitutionApiRestClient;

@MockBean
private BrokerMapper brokerMapper;
Expand Down Expand Up @@ -145,7 +144,7 @@ void getUserProducts_shouldGetEmptyData() {
assertEquals(0, institutions.size());

verify(msCoreUserApiRestClientMock, times(1))
._getUserProductsInfoUsingGET(eq(userId), isNull(), eq(String.join(",", ACTIVE.name(), PENDING.name(), TOBEVALIDATED.name())));
._getUserProductsInfoUsingGET(eq(userId), isNull(), eq(List.of(ACTIVE.name(), PENDING.name(), TOBEVALIDATED.name())));
verifyNoMoreInteractions(msCoreUserApiRestClientMock);
}

Expand Down Expand Up @@ -179,7 +178,7 @@ void getUserProducts_shouldGetData() {
assertEquals(userProductsResponse.getBindings().get(0).getInstitutionId(), institutions.get(0).getId());

verify(msCoreUserApiRestClientMock, times(1))
._getUserProductsInfoUsingGET(eq(userId), isNull(), eq(String.join(",", ACTIVE.name(), PENDING.name(), TOBEVALIDATED.name())));
._getUserProductsInfoUsingGET(eq(userId), isNull(), eq(List.of(ACTIVE.name(), PENDING.name(), TOBEVALIDATED.name())));
verifyNoMoreInteractions(msCoreUserApiRestClientMock);
}

Expand Down Expand Up @@ -929,7 +928,7 @@ void getDelegationUsingFrom_shouldGetData() {
ResponseEntity<List<DelegationResponse>> delegationResponseEntity = new ResponseEntity<>(delegationResponseList, null, HttpStatus.OK);
Delegation delegation = dummyDelegation();

when(msCoreInstitutionApiRestClient._getDelegationsUsingGET(any(), any(), any()))
when(msCoreInstitutionApiRestClient._getDelegationsUsingGET(any(), any(), any(), any()))
.thenReturn(delegationResponseEntity);


Expand All @@ -948,7 +947,7 @@ void getDelegationUsingFrom_shouldGetData() {
assertEquals(delegationResponseList.get(0).getBrokerName(), delegationList.get(0).getBrokerName());

verify(msCoreInstitutionApiRestClient, times(1))
._getDelegationsUsingGET(delegation.getInstitutionId(), delegation.getBrokerId(), delegation.getProductId());
._getDelegationsUsingGET(delegation.getInstitutionId(), delegation.getBrokerId(), delegation.getProductId(), null);
verifyNoMoreInteractions(msCoreInstitutionApiRestClient);
}

Expand All @@ -961,7 +960,7 @@ void getDelegationUsingFrom_shouldGetEmptyData() {

when(delegationResponseEntity.getBody()).thenReturn(null);

when(msCoreInstitutionApiRestClient._getDelegationsUsingGET(any(), any(), any()))
when(msCoreInstitutionApiRestClient._getDelegationsUsingGET(any(), any(), any(), any()))
.thenReturn(delegationResponseEntity);


Expand All @@ -972,7 +971,7 @@ void getDelegationUsingFrom_shouldGetEmptyData() {
assertEquals(0, delegationList.size());

verify(msCoreInstitutionApiRestClient, times(1))
._getDelegationsUsingGET(delegation.getInstitutionId(), delegation.getBrokerId(), delegation.getProductId());
._getDelegationsUsingGET(delegation.getInstitutionId(), delegation.getBrokerId(), delegation.getProductId(), null);
verifyNoMoreInteractions(msCoreInstitutionApiRestClient);
}

Expand Down

0 comments on commit 18ddba3

Please sign in to comment.