-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SELC-5244] Feat: Refactor API /v2/institutions (#286)
- Loading branch information
1 parent
eb7eee3
commit 83df2a5
Showing
19 changed files
with
341 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...n/java/it/pagopa/selfcare/external_api/model/onboarding/OnboardedInstitutionResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package it.pagopa.selfcare.external_api.model.onboarding; | ||
|
||
import it.pagopa.selfcare.commons.base.utils.InstitutionType; | ||
import it.pagopa.selfcare.external_api.model.institutions.RootParent; | ||
import lombok.Data; | ||
|
||
import java.util.Collection; | ||
import java.util.UUID; | ||
|
||
@Data | ||
public class OnboardedInstitutionResource { | ||
|
||
private UUID id; | ||
private String description; | ||
private String externalId; | ||
private String originId; | ||
private InstitutionType institutionType; | ||
private String digitalAddress; | ||
private String status; | ||
private String address; | ||
private String zipCode; | ||
private String taxCode; | ||
private String taxCodeInvoicing; | ||
private String origin; | ||
private Collection<String> userProductRoles; | ||
private String recipientCode; | ||
private String rea; | ||
private String shareCapital; | ||
private String businessRegisterPlace; | ||
private String supportEmail; | ||
private String supportPhone; | ||
private PaymentServiceProvider paymentServiceProvider; | ||
private DataProtectionOfficer dataProtectionOfficer; | ||
private String subunitCode; | ||
private String subunitType; | ||
private RootParent rootParent; | ||
private String aooParentCode; | ||
private String country; | ||
private String county; | ||
private String city; | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
.../it/pagopa/selfcare/external_api/model/onboarding/mapper/OnboardingInstitutionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,51 @@ | ||
package it.pagopa.selfcare.external_api.model.onboarding.mapper; | ||
|
||
import it.pagopa.selfcare.external_api.model.institutions.Institution; | ||
import it.pagopa.selfcare.external_api.model.institutions.Onboarding; | ||
import it.pagopa.selfcare.external_api.model.onboarding.OnboardedInstitutionInfo; | ||
import it.pagopa.selfcare.external_api.model.onboarding.OnboardedInstitutionResource; | ||
import it.pagopa.selfcare.external_api.model.onboarding.OnboardedInstitutionResponse; | ||
import it.pagopa.selfcare.external_api.model.user.OnboardedProductResponse; | ||
import it.pagopa.selfcare.external_api.model.user.RelationshipState; | ||
import it.pagopa.selfcare.external_api.model.user.UserInstitution; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.Named; | ||
import org.springframework.util.CollectionUtils; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Mapper(componentModel = "spring") | ||
|
||
public interface OnboardingInstitutionMapper { | ||
OnboardedInstitutionResponse toOnboardedInstitutionResponse(OnboardedInstitutionInfo onboardedInstitutionInfo); | ||
|
||
@Mapping(target = "userProductRoles", expression = "java(retrieveUserProductRole(userInstitution, productId))") | ||
@Mapping(target = "status", expression = "java(retrieveStatus(institution, productId))") | ||
@Mapping(target = "id", source = "institution.id") | ||
OnboardedInstitutionResource toOnboardedInstitutionResource(Institution institution, UserInstitution userInstitution, String productId); | ||
|
||
|
||
@Named("retrieveStatus") | ||
default String retrieveStatus(Institution institution, String productId) { | ||
List<RelationshipState> statusList = institution.getOnboarding().stream() | ||
.filter(onboarding -> productId.equalsIgnoreCase(onboarding.getProductId())) | ||
.map(Onboarding::getStatus) | ||
.toList(); | ||
|
||
if(CollectionUtils.isEmpty(statusList)) | ||
return null; | ||
|
||
return Collections.min(statusList).name(); | ||
} | ||
|
||
@Named("retrieveUserProductRole") | ||
default Collection<String> retrieveUserProductRole(UserInstitution userInstitution, String productId) { | ||
return userInstitution.getProducts().stream() | ||
.collect(Collectors.groupingBy(OnboardedProductResponse::getProductId, Collectors.mapping(OnboardedProductResponse::getProductRole, Collectors.toList()))) | ||
.get(productId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...t/src/test/java/it/pagopa/selfcare/external_api/connector/rest/InstitutionMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package it.pagopa.selfcare.external_api.connector.rest; | ||
|
||
import it.pagopa.selfcare.core.generated.openapi.v1.dto.InstitutionResponse; | ||
import it.pagopa.selfcare.core.generated.openapi.v1.dto.OnboardedProductResponse; | ||
import it.pagopa.selfcare.external_api.connector.rest.mapper.InstitutionMapperImpl; | ||
import it.pagopa.selfcare.external_api.model.institutions.Institution; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class InstitutionMapperTest { | ||
|
||
@InjectMocks | ||
InstitutionMapperImpl institutionMapperImpl; | ||
|
||
@Test | ||
void toOnboardingWithDate(){ | ||
InstitutionResponse institutionResponse = new InstitutionResponse(); | ||
OnboardedProductResponse onboardedProductResponse = new OnboardedProductResponse(); | ||
onboardedProductResponse.setProductId("productId"); | ||
onboardedProductResponse.setStatus(OnboardedProductResponse.StatusEnum.ACTIVE); | ||
onboardedProductResponse.setCreatedAt(LocalDateTime.now()); | ||
institutionResponse.setOnboarding(List.of(onboardedProductResponse)); | ||
Institution institution = institutionMapperImpl.toInstitution(institutionResponse); | ||
Assertions.assertNotNull(institution); | ||
Assertions.assertNotNull(institution.getOnboarding()); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.