From 344ec8f630250de03004f12540e0f6ee4e610044 Mon Sep 17 00:00:00 2001 From: Giampiero Ferrara Date: Wed, 6 Nov 2024 16:04:42 +0100 Subject: [PATCH] [SELC-5924] feat: Fixed contract template and version into ProductsMapper --- .../external_api/mapper/ProductsMapper.java | 90 +++++----- .../model/product/ProductResource.java | 89 +++++----- src/main/resources/swagger/api-docs.json | 5 - .../InstitutionControllerV2Test.java | 6 + .../InstitutionResourceV2_2elements.json | 159 +++++++++--------- src/test/resources/expectations/Product.json | 22 ++- .../expectations/ProductResource.json | 1 - .../expectations/ProductResources.json | 2 - 8 files changed, 190 insertions(+), 184 deletions(-) diff --git a/src/main/java/it/pagopa/selfcare/external_api/mapper/ProductsMapper.java b/src/main/java/it/pagopa/selfcare/external_api/mapper/ProductsMapper.java index c8b913f5..d67d386f 100644 --- a/src/main/java/it/pagopa/selfcare/external_api/mapper/ProductsMapper.java +++ b/src/main/java/it/pagopa/selfcare/external_api/mapper/ProductsMapper.java @@ -2,58 +2,60 @@ import it.pagopa.selfcare.external_api.model.product.ProductResource; import it.pagopa.selfcare.onboarding.common.PartyRole; -import it.pagopa.selfcare.product.entity.ContractTemplate; import it.pagopa.selfcare.product.entity.Product; import it.pagopa.selfcare.product.entity.ProductRoleInfo; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.Named; - import java.util.EnumMap; import java.util.Map; -import java.util.Objects; import java.util.Optional; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; @Mapper(componentModel = "spring") public interface ProductsMapper { - @Mapping(target = "roleMappings", expression = "java(toRoleMappings(model.getRoleMappings(institutionType)))") - @Mapping(target = "contractTemplatePath", expression = "java(toContractTemplatePath(model,institutionType))") - @Mapping(target = "contractTemplateVersion", expression = "java(toContractTemplateVersion(model,institutionType))") - ProductResource toResource(Product model, String institutionType); - - @Named("toRoleMappings") - default EnumMap toRoleMappings(Map roleMappings){ - EnumMap result; - if(roleMappings != null){ - result = new EnumMap<>(PartyRole.class); - - roleMappings.forEach((key, value) -> { - ProductRoleInfo productRoleInfo = new ProductRoleInfo(); - productRoleInfo.setRoles(roleMappings.get(key).getRoles()); - productRoleInfo.setMultiroleAllowed(roleMappings.get(key).isMultiroleAllowed()); - result.put(key, productRoleInfo); - }); - } - else{ - result = null; - } - return result; - } - - @Named("toContractTemplatePath") - default String toContractTemplatePath(Product model, String institutionType){ - if(Objects.isNull(institutionType)) return null; - return Optional.ofNullable(model.getInstitutionContractTemplate(institutionType)) - .map(ContractTemplate::getContractTemplatePath) - .orElse(null); - } - - @Named("toContractTemplateVersion") - default String toContractTemplateVersion(Product model, String institutionType){ - if(Objects.isNull(institutionType)) return null; - return Optional.ofNullable(model.getInstitutionContractTemplate(institutionType)) - .map(ContractTemplate::getContractTemplateVersion) - .orElse(null); + @Mapping( + target = "roleMappings", + expression = "java(toRoleMappings(model.getRoleMappings(institutionType)))") + @Mapping( + target = "contractTemplatePath", + expression = "java(toContractTemplatePath(model,institutionType))") + @Mapping( + target = "contractTemplateVersion", + expression = "java(toContractTemplateVersion(model,institutionType))") + ProductResource toResource(Product model, String institutionType); + + @Named("toRoleMappings") + default EnumMap toRoleMappings( + Map roleMappings) { + EnumMap result; + if (roleMappings != null) { + result = new EnumMap<>(PartyRole.class); + + roleMappings.forEach( + (key, value) -> { + ProductRoleInfo productRoleInfo = new ProductRoleInfo(); + productRoleInfo.setRoles(roleMappings.get(key).getRoles()); + productRoleInfo.setMultiroleAllowed(roleMappings.get(key).isMultiroleAllowed()); + result.put(key, productRoleInfo); + }); + } else { + result = null; } + return result; + } + + @Named("toContractTemplatePath") + default String toContractTemplatePath(Product model, String institutionType) { + return Optional.ofNullable( + model.getInstitutionContractTemplate(institutionType).getContractTemplatePath()) + .orElse(null); + } + + @Named("toContractTemplateVersion") + default String toContractTemplateVersion(Product model, String institutionType) { + return Optional.ofNullable( + model.getInstitutionContractTemplate(institutionType).getContractTemplateVersion()) + .orElse(null); + } } diff --git a/src/main/java/it/pagopa/selfcare/external_api/model/product/ProductResource.java b/src/main/java/it/pagopa/selfcare/external_api/model/product/ProductResource.java index 6196befe..fd5f27d5 100644 --- a/src/main/java/it/pagopa/selfcare/external_api/model/product/ProductResource.java +++ b/src/main/java/it/pagopa/selfcare/external_api/model/product/ProductResource.java @@ -2,68 +2,67 @@ import io.swagger.annotations.ApiModelProperty; import it.pagopa.selfcare.onboarding.common.PartyRole; -import lombok.Data; - -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; import java.time.Instant; import java.util.EnumMap; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import lombok.Data; @Data public class ProductResource { - @ApiModelProperty(value = "${swagger.external_api.products.model.id}", required = true) - @NotBlank - private String id; - - @ApiModelProperty(value = "${swagger.external_api.products.model.title}", required = true) - @NotBlank - private String title; - - @ApiModelProperty(value = "${swagger.external_api.products.model.contractTemplatePath}", required = true) - @NotBlank - private String contractTemplatePath; + @ApiModelProperty(value = "${swagger.external_api.products.model.id}", required = true) + @NotBlank + private String id; - @ApiModelProperty(value = "${swagger.external_api.products.model.contractTemplateUpdatedAt}") - private Instant contractTemplateUpdatedAt; + @ApiModelProperty(value = "${swagger.external_api.products.model.title}", required = true) + @NotBlank + private String title; - @ApiModelProperty(value = "${swagger.external_api.products.model.contractTemplateVersion}", required = true) - @NotBlank - private String contractTemplateVersion; + @ApiModelProperty( + value = "${swagger.external_api.products.model.contractTemplatePath}", + required = true) + @NotBlank + private String contractTemplatePath; - @ApiModelProperty(value = "${swagger.external_api.products.model.createdAt}") - private Instant createdAt; + @ApiModelProperty( + value = "${swagger.external_api.products.model.contractTemplateVersion}", + required = true) + @NotBlank + private String contractTemplateVersion; - @ApiModelProperty(value = "${swagger.external_api.products.model.description}", required = true) - @NotBlank - private String description; + @ApiModelProperty(value = "${swagger.external_api.products.model.createdAt}") + private Instant createdAt; - @ApiModelProperty("${swagger.external_api.products.model.urlPublic}") - private String urlPublic; + @ApiModelProperty(value = "${swagger.external_api.products.model.description}", required = true) + @NotBlank + private String description; - @ApiModelProperty(value = "${swagger.external_api.products.model.urlBO}", required = true) - @NotBlank - private String urlBO; + @ApiModelProperty("${swagger.external_api.products.model.urlPublic}") + private String urlPublic; - @ApiModelProperty(value = "${swagger.external_api.products.model.depictImageUrl}") - private String depictImageUrl; + @ApiModelProperty(value = "${swagger.external_api.products.model.urlBO}", required = true) + @NotBlank + private String urlBO; - @ApiModelProperty(value = "${swagger.external_api.products.model.identityTokenAudience}") - private String identityTokenAudience; + @ApiModelProperty(value = "${swagger.external_api.products.model.depictImageUrl}") + private String depictImageUrl; - @ApiModelProperty(value = "${swagger.external_api.products.model.logo}") - private String logo; + @ApiModelProperty(value = "${swagger.external_api.products.model.identityTokenAudience}") + private String identityTokenAudience; - @ApiModelProperty(value = "${swagger.external_api.products.model.logoBgColor}") - private String logoBgColor; + @ApiModelProperty(value = "${swagger.external_api.products.model.logo}") + private String logo; - @ApiModelProperty(value = "${swagger.external_api.products.model.parentId}") - private String parentId; + @ApiModelProperty(value = "${swagger.external_api.products.model.logoBgColor}") + private String logoBgColor; - @ApiModelProperty(value = "${swagger.external_api.products.model.roleMappings}", required = true) - @NotEmpty - private EnumMap roleMappings; + @ApiModelProperty(value = "${swagger.external_api.products.model.parentId}") + private String parentId; - @ApiModelProperty(value = "${swagger.external_api.products.model.roleManagementURL}") - private String roleManagementURL; + @ApiModelProperty(value = "${swagger.external_api.products.model.roleMappings}", required = true) + @NotEmpty + private EnumMap roleMappings; + @ApiModelProperty(value = "${swagger.external_api.products.model.roleManagementURL}") + private String roleManagementURL; } diff --git a/src/main/resources/swagger/api-docs.json b/src/main/resources/swagger/api-docs.json index fa14ee9b..630b8ca1 100644 --- a/src/main/resources/swagger/api-docs.json +++ b/src/main/resources/swagger/api-docs.json @@ -2248,11 +2248,6 @@ "type" : "string", "description" : "The path of contract" }, - "contractTemplateUpdatedAt" : { - "type" : "string", - "description" : "Date the contract was postponed", - "format" : "date-time" - }, "contractTemplateVersion" : { "type" : "string", "description" : "Version of the contract" diff --git a/src/test/java/it/pagopa/selfcare/external_api/controller/InstitutionControllerV2Test.java b/src/test/java/it/pagopa/selfcare/external_api/controller/InstitutionControllerV2Test.java index bc728fff..76d2155d 100644 --- a/src/test/java/it/pagopa/selfcare/external_api/controller/InstitutionControllerV2Test.java +++ b/src/test/java/it/pagopa/selfcare/external_api/controller/InstitutionControllerV2Test.java @@ -211,6 +211,12 @@ void getInstitutionUserProductsWith2Elements() throws Exception { byte[] productStream = Files.readAllBytes(inputResource.getFile().toPath()); List products = objectMapper.readValue(productStream, new TypeReference<>() {}); + products.forEach( + productResource -> { + productResource.setContractTemplatePath("contractTemplatePath"); + productResource.setContractTemplateVersion("1.0.0"); + }); + ClassPathResource outputResource = new ClassPathResource("expectations/ProductResources.json"); String expectedResource = StringUtils.deleteWhitespace(new String(Files.readAllBytes(outputResource.getFile().toPath()))); diff --git a/src/test/resources/expectations/InstitutionResourceV2_2elements.json b/src/test/resources/expectations/InstitutionResourceV2_2elements.json index 5ecd93c6..fe1eb193 100644 --- a/src/test/resources/expectations/InstitutionResourceV2_2elements.json +++ b/src/test/resources/expectations/InstitutionResourceV2_2elements.json @@ -1,100 +1,101 @@ [ { - "id":"07532a3f-1cf9-4d60-8b15-e2c146b7273a", - "description":"example_description", - "externalId":"example_external_id", - "originId":"example_origin_id", - "institutionType":"PA", - "digitalAddress":"example_digital_address", - "status":"ACTIVE", - "address":"example_address", - "zipCode":"example_zip_code", - "taxCode":"example_tax_code", + "id": "07532a3f-1cf9-4d60-8b15-e2c146b7273a", + "description": "example_description", + "externalId": "example_external_id", + "originId": "example_origin_id", + "institutionType": "PA", + "digitalAddress": "example_digital_address", + "status": "ACTIVE", + "address": "example_address", + "zipCode": "example_zip_code", + "taxCode": "example_tax_code", "taxCodeInvoicing": "example_tax_code_invoicing", - "origin":"example_origin", - "userProductRoles":[ - "admin","manager" + "origin": "example_origin", + "userProductRoles": [ + "admin", + "manager" ], - "recipientCode":"example_recipient_code", - "companyInformations":{ - "rea":"example_business_type", - "shareCapital":"example_share_capital", - "businessRegisterPlace":"example_business_register_place" + "recipientCode": "example_recipient_code", + "companyInformations": { + "rea": "example_business_type", + "shareCapital": "example_share_capital", + "businessRegisterPlace": "example_business_register_place" }, - "assistanceContacts":{ - "supportEmail":"example_support_email", - "supportPhone":"example_support_phone" + "assistanceContacts": { + "supportEmail": "example_support_email", + "supportPhone": "example_support_phone" }, - "pspData":{ - "businessRegisterNumber":"example_business_register_number", - "legalRegisterName":"example_legal_register_name", - "legalRegisterNumber":"example_legal_register_number", - "abiCode":"example_abi_code", - "vatNumberGroup":false + "pspData": { + "businessRegisterNumber": "example_business_register_number", + "legalRegisterName": "example_legal_register_name", + "legalRegisterNumber": "example_legal_register_number", + "abiCode": "example_abi_code", + "vatNumberGroup": false }, - "dpoData":{ - "address":"example_dpo_address", - "pec":"example_dpo_pec", - "email":"example_dpo_email" + "dpoData": { + "address": "example_dpo_address", + "pec": "example_dpo_pec", + "email": "example_dpo_email" }, - "subunitCode":"example_subunit_code", - "subunitType":"example_subunit_type", - "rootParent":{ - "id":"example_parent_id", - "description":"example_parent_description" + "subunitCode": "example_subunit_code", + "subunitType": "example_subunit_type", + "rootParent": { + "id": "example_parent_id", + "description": "example_parent_description" }, - "aooParentCode":"example_aoo_parent_code", - "country":"example_country", - "county":"example_county", - "city":"example_city" + "aooParentCode": "example_aoo_parent_code", + "country": "example_country", + "county": "example_county", + "city": "example_city" }, { - "id":"07532a3f-1cf9-4d60-8b15-e2c146b7273b", - "description":"example_description", - "externalId":"example_external_id", - "originId":"example_origin_id", - "institutionType":"PA", - "digitalAddress":"example_digital_address", - "status":"ACTIVE", - "address":"example_address", - "zipCode":"example_zip_code", - "taxCode":"example_tax_code", + "id": "07532a3f-1cf9-4d60-8b15-e2c146b7273b", + "description": "example_description", + "externalId": "example_external_id", + "originId": "example_origin_id", + "institutionType": "PA", + "digitalAddress": "example_digital_address", + "status": "ACTIVE", + "address": "example_address", + "zipCode": "example_zip_code", + "taxCode": "example_tax_code", "taxCodeInvoicing": "example_tax_code_invoicing", - "origin":"example_origin", - "userProductRoles":[ + "origin": "example_origin", + "userProductRoles": [ "admin" ], - "recipientCode":"example_recipient_code", - "companyInformations":{ - "rea":"example_business_type", - "shareCapital":"example_share_capital", - "businessRegisterPlace":"example_business_register_place" + "recipientCode": "example_recipient_code", + "companyInformations": { + "rea": "example_business_type", + "shareCapital": "example_share_capital", + "businessRegisterPlace": "example_business_register_place" }, - "assistanceContacts":{ - "supportEmail":"example_support_email", - "supportPhone":"example_support_phone" + "assistanceContacts": { + "supportEmail": "example_support_email", + "supportPhone": "example_support_phone" }, - "pspData":{ - "businessRegisterNumber":"example_business_register_number", - "legalRegisterName":"example_legal_register_name", - "legalRegisterNumber":"example_legal_register_number", - "abiCode":"example_abi_code", - "vatNumberGroup":false + "pspData": { + "businessRegisterNumber": "example_business_register_number", + "legalRegisterName": "example_legal_register_name", + "legalRegisterNumber": "example_legal_register_number", + "abiCode": "example_abi_code", + "vatNumberGroup": false }, - "dpoData":{ - "address":"example_dpo_address", - "pec":"example_dpo_pec", - "email":"example_dpo_email" + "dpoData": { + "address": "example_dpo_address", + "pec": "example_dpo_pec", + "email": "example_dpo_email" }, - "subunitCode":"example_subunit_code", - "subunitType":"example_subunit_type", - "rootParent":{ - "id":"example_parent_id", - "description":"example_parent_description" + "subunitCode": "example_subunit_code", + "subunitType": "example_subunit_type", + "rootParent": { + "id": "example_parent_id", + "description": "example_parent_description" }, - "aooParentCode":"example_aoo_parent_code", - "country":"example_country", - "county":"example_county", - "city":"example_city" + "aooParentCode": "example_aoo_parent_code", + "country": "example_country", + "county": "example_county", + "city": "example_city" } ] \ No newline at end of file diff --git a/src/test/resources/expectations/Product.json b/src/test/resources/expectations/Product.json index b51aa41f..9d08e4cf 100644 --- a/src/test/resources/expectations/Product.json +++ b/src/test/resources/expectations/Product.json @@ -34,10 +34,13 @@ } }, "parentId": "parentProduct", - "contractTemplatePath": "contractTemplatePath", - "contractTemplateVersion": "1.0.0", - "contractTemplateUpdatedAt": "2024-04-17T01:00:00Z", - "roleManagementURL": "roleManagementUrl" + "roleManagementURL": "roleManagementUrl", + "institutionContractMappings": { + "default": { + "contractTemplatePath": "path_template", + "contractTemplateVersion": "1.0.0" + } + } }, { "id": "456", @@ -72,10 +75,13 @@ } }, "parentId": "parentProduct", - "contractTemplatePath": "contractTemplatePath", - "contractTemplateVersion": "1.0.0", - "contractTemplateUpdatedAt": "2024-04-17T01:00:00Z", "createdAt": "2024-04-17T01:00:00Z", - "roleManagementURL": "roleManagementUrl" + "roleManagementURL": "roleManagementUrl", + "institutionContractMappings": { + "default": { + "contractTemplatePath": "path_template", + "contractTemplateVersion": "1.0.0" + } + } } ] \ No newline at end of file diff --git a/src/test/resources/expectations/ProductResource.json b/src/test/resources/expectations/ProductResource.json index 371a0f53..bae45010 100644 --- a/src/test/resources/expectations/ProductResource.json +++ b/src/test/resources/expectations/ProductResource.json @@ -2,7 +2,6 @@ "id":"123", "title":"Title", "contractTemplatePath":"contractTemplatePath", - "contractTemplateUpdatedAt":"2024-04-17T01:00:00Z", "contractTemplateVersion":"1.0.0", "createdAt":"2024-04-17T01:00:00Z", "description":"ProductDescription", diff --git a/src/test/resources/expectations/ProductResources.json b/src/test/resources/expectations/ProductResources.json index 96ac0102..501df148 100644 --- a/src/test/resources/expectations/ProductResources.json +++ b/src/test/resources/expectations/ProductResources.json @@ -3,7 +3,6 @@ "id":"123", "title":"Title", "contractTemplatePath":"contractTemplatePath", - "contractTemplateUpdatedAt":"2024-04-17T01:00:00Z", "contractTemplateVersion":"1.0.0", "createdAt":"2024-04-17T01:00:00Z", "description":"ProductDescription", @@ -38,7 +37,6 @@ "id":"456", "title":"Title", "contractTemplatePath":"contractTemplatePath", - "contractTemplateUpdatedAt":"2024-04-17T01:00:00Z", "contractTemplateVersion":"1.0.0", "createdAt":"2024-04-17T01:00:00Z", "description":"ProductDescription",