From 4d7e51f1c2f4f4fd8dfa0df0b2c90aef99d0798f Mon Sep 17 00:00:00 2001 From: Giulia Tremolada <124147597+giulia-tremolada@users.noreply.github.com> Date: Thu, 28 Nov 2024 09:44:21 +0100 Subject: [PATCH] [SELC-6102] feat: add mobilePhone in getUserDetailsById API (#232) --- apps/user-ms/src/main/docs/openapi.json | 3 ++ apps/user-ms/src/main/docs/openapi.yaml | 2 ++ .../response/UserDetailResponse.java | 1 + .../selfcare/user/mapper/UserMapper.java | 29 ++++++++++------- .../src/main/openapi/user_registry.json | 3 ++ .../user/controller/UserControllerTest.java | 5 ++- .../selfcare/user/mapper/UserMapperTest.java | 32 +++++++++++++++---- 7 files changed, 57 insertions(+), 18 deletions(-) diff --git a/apps/user-ms/src/main/docs/openapi.json b/apps/user-ms/src/main/docs/openapi.json index a2addf06..c6ad99ed 100644 --- a/apps/user-ms/src/main/docs/openapi.json +++ b/apps/user-ms/src/main/docs/openapi.json @@ -1713,6 +1713,9 @@ "email" : { "$ref" : "#/components/schemas/CertifiableFieldResponseString" }, + "mobilePhone" : { + "$ref" : "#/components/schemas/CertifiableFieldResponseString" + }, "workContacts" : { "type" : "object", "additionalProperties" : { diff --git a/apps/user-ms/src/main/docs/openapi.yaml b/apps/user-ms/src/main/docs/openapi.yaml index 3c3a0a0c..cf983ded 100644 --- a/apps/user-ms/src/main/docs/openapi.yaml +++ b/apps/user-ms/src/main/docs/openapi.yaml @@ -1248,6 +1248,8 @@ components: $ref: "#/components/schemas/CertifiableFieldResponseString" email: $ref: "#/components/schemas/CertifiableFieldResponseString" + mobilePhone: + $ref: "#/components/schemas/CertifiableFieldResponseString" workContacts: type: object additionalProperties: diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/controller/response/UserDetailResponse.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/controller/response/UserDetailResponse.java index 5dc887bc..54d69e85 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/controller/response/UserDetailResponse.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/controller/response/UserDetailResponse.java @@ -15,5 +15,6 @@ public class UserDetailResponse { private CertifiableFieldResponse name; private CertifiableFieldResponse familyName; private CertifiableFieldResponse email; + private CertifiableFieldResponse mobilePhone; private Map workContacts; } diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/UserMapper.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/UserMapper.java index 789ea1ed..479c1971 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/UserMapper.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/UserMapper.java @@ -14,12 +14,7 @@ import org.mapstruct.Mapping; import org.mapstruct.Named; import org.mapstruct.factory.Mappers; -import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfstring; -import org.openapi.quarkus.user_registry_json.model.MutableUserFieldsDto; -import org.openapi.quarkus.user_registry_json.model.UserResource; -import org.openapi.quarkus.user_registry_json.model.WorkContactResource; -import org.openapi.quarkus.user_registry_json.model.SaveUserDto; -import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfLocalDate; +import org.openapi.quarkus.user_registry_json.model.*; import java.time.LocalDate; import java.util.*; @@ -38,6 +33,7 @@ public interface UserMapper { UserResponse toUserResponse(UserResource userResource, String userMailUuid); @Mapping(target = "email", expression = "java(retrieveCertifiedMailFromWorkContacts(userResource, userMailUuid))") + @Mapping(target = "mobilePhone", expression = "java(retrieveCertifiedMobilePhoneFromWorkContacts(userResource, userMailUuid))") @Mapping(source = "userResource.familyName", target = "familyName", qualifiedByName = "toCertifiableFieldResponse") @Mapping(source = "userResource.name", target = "name", qualifiedByName = "toCertifiableFieldResponse") @Mapping(target = "workContacts", expression = "java(toWorkContactResponse(userResource.getWorkContacts()))") @@ -85,11 +81,22 @@ default String retrieveMailFromWorkContacts(Map map @Named("retrieveCertifiedMailFromWorkContacts") - default CertifiableFieldResponse retrieveCertifiedMailFromWorkContacts(UserResource userResource, String userMailUuid){ - if(userResource.getWorkContacts()!=null && !userResource.getWorkContacts().isEmpty() && userResource.getWorkContacts().containsKey(userMailUuid)){ - return new CertifiableFieldResponse<>(userResource.getWorkContacts().get(userMailUuid).getEmail().getValue(), userResource.getWorkContacts().get(userMailUuid).getEmail().getCertification()); - } - return null; + default CertifiableFieldResponse retrieveCertifiedMailFromWorkContacts(UserResource userResource, String userMailUuid) { + return Optional.ofNullable(userResource) + .map(UserResource::getWorkContacts) + .map(workContacts -> workContacts.get(userMailUuid)) + .map(WorkContactResource::getEmail) + .map(email -> new CertifiableFieldResponse<>(email.getValue(), email.getCertification())) + .orElse(null); + } + + @Named("retrieveCertifiedMobilePhoneFromWorkContacts") + default CertifiableFieldResponse retrieveCertifiedMobilePhoneFromWorkContacts(UserResource userResource, String userMailUuid) { + return Optional.ofNullable(userResource.getWorkContacts()) + .map(workContacts -> workContacts.get(userMailUuid)) + .map(WorkContactResource::getMobilePhone) + .map(mobilePhone -> new CertifiableFieldResponse<>(mobilePhone.getValue(), mobilePhone.getCertification())) + .orElse(null); } @Named("toCertifiableFieldResponse") diff --git a/apps/user-ms/src/main/openapi/user_registry.json b/apps/user-ms/src/main/openapi/user_registry.json index c6ac022d..f711c58e 100644 --- a/apps/user-ms/src/main/openapi/user_registry.json +++ b/apps/user-ms/src/main/openapi/user_registry.json @@ -395,6 +395,9 @@ "properties" : { "email" : { "$ref" : "#/components/schemas/CertifiableFieldResourceOfstring" + }, + "mobilePhone" : { + "$ref" : "#/components/schemas/CertifiableFieldResourceOfstring" } } }, diff --git a/apps/user-ms/src/test/java/it/pagopa/selfcare/user/controller/UserControllerTest.java b/apps/user-ms/src/test/java/it/pagopa/selfcare/user/controller/UserControllerTest.java index 07e3134e..48a2fe86 100644 --- a/apps/user-ms/src/test/java/it/pagopa/selfcare/user/controller/UserControllerTest.java +++ b/apps/user-ms/src/test/java/it/pagopa/selfcare/user/controller/UserControllerTest.java @@ -51,12 +51,15 @@ class UserControllerTest { private static final UserDetailResponse userDetailResponse; static { + CertifiableFieldResourceOfstring email = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email"); + CertifiableFieldResourceOfstring phone = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "mobilePhone"); + userResource = new UserResource(); userResource.setEmail(new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email")); userResource.setName(new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "name")); userResource.setFamilyName(new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "familyName")); userResource.setFiscalCode("fiscalCode"); - userResource.setWorkContacts(Map.of("userMailUuid", new WorkContactResource(new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email")))); + userResource.setWorkContacts(Map.of("userMailUuid", new WorkContactResource(email, phone))); userDetailResponse = new UserDetailResponse(); userDetailResponse.setId(UUID.randomUUID().toString()); diff --git a/apps/user-ms/src/test/java/it/pagopa/selfcare/user/mapper/UserMapperTest.java b/apps/user-ms/src/test/java/it/pagopa/selfcare/user/mapper/UserMapperTest.java index e490bf49..93ef99f7 100644 --- a/apps/user-ms/src/test/java/it/pagopa/selfcare/user/mapper/UserMapperTest.java +++ b/apps/user-ms/src/test/java/it/pagopa/selfcare/user/mapper/UserMapperTest.java @@ -22,16 +22,33 @@ public class UserMapperTest { void retrieveCertifiedEmailFromWorkContacts(){ final UserResource userResource = new UserResource(); final CertifiableFieldResourceOfstring email = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email"); - WorkContactResource workContactResource = new WorkContactResource(email); - Map workContactResourceMap = Map.of("email", workContactResource); + final CertifiableFieldResourceOfstring phone = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "mobilePhone"); + WorkContactResource workContactResource = new WorkContactResource(email, phone); + Map workContactResourceMap = Map.of("contactsUuid", workContactResource); userResource.setWorkContacts(workContactResourceMap); - CertifiableFieldResponse certifiedMail = userMapper.retrieveCertifiedMailFromWorkContacts(userResource, "email"); + CertifiableFieldResponse certifiedMail = userMapper.retrieveCertifiedMailFromWorkContacts(userResource, "contactsUuid"); assertEquals(CertifiableFieldResourceOfstring.CertificationEnum.NONE,certifiedMail.getCertified()); assertEquals("email", certifiedMail.getValue()); } + @Test + void retrieveCertifiedMobilePhoneFromWorkContacts(){ + final UserResource userResource = new UserResource(); + final CertifiableFieldResourceOfstring email = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email"); + String mobilePhone = "mobilePhone"; + final CertifiableFieldResourceOfstring phone = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, mobilePhone); + WorkContactResource workContactResource = new WorkContactResource(email, phone); + Map workContactResourceMap = Map.of("contactsUuid", workContactResource); + userResource.setWorkContacts(workContactResourceMap); + + CertifiableFieldResponse certifiedPhone = userMapper.retrieveCertifiedMobilePhoneFromWorkContacts(userResource, "contactsUuid"); + + assertEquals(CertifiableFieldResourceOfstring.CertificationEnum.NONE,certifiedPhone.getCertified()); + assertEquals(mobilePhone, certifiedPhone.getValue()); + } + @Test void retrieveCertifiedEmailFromWorkContacts_nullWorkContacts(){ final UserResource userResource = new UserResource(); @@ -45,7 +62,8 @@ void retrieveCertifiedEmailFromWorkContacts_nullWorkContacts(){ void retrieveCertifiedEmailFromWorkContacts_notPresent(){ final UserResource userResource = new UserResource(); final CertifiableFieldResourceOfstring email = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email"); - WorkContactResource workContactResource = new WorkContactResource(email); + final CertifiableFieldResourceOfstring phone = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "mobilePhone"); + WorkContactResource workContactResource = new WorkContactResource(email, phone); Map workContactResourceMap = Map.of("email", workContactResource); userResource.setWorkContacts(workContactResourceMap); @@ -58,7 +76,8 @@ void retrieveCertifiedEmailFromWorkContacts_notPresent(){ @Test void retrieveMailFromWorkContacts(){ final CertifiableFieldResourceOfstring email = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email"); - WorkContactResource workContactResource = new WorkContactResource(email); + final CertifiableFieldResourceOfstring phone = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "mobilePhone"); + WorkContactResource workContactResource = new WorkContactResource(email, phone); Map workContactResourceMap = Map.of("email", workContactResource); String mailFromWorkContact = userMapper.retrieveMailFromWorkContacts(workContactResourceMap, "email"); @@ -87,7 +106,8 @@ void retrieveMailFromWorkContacts_nullMap(){ @Test void retrieveMailFromWorkContacts_notPresent(){ final CertifiableFieldResourceOfstring email = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email"); - WorkContactResource workContactResource = new WorkContactResource(email); + final CertifiableFieldResourceOfstring phone = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "mobilePhone"); + WorkContactResource workContactResource = new WorkContactResource(email, phone); Map workContactResourceMap = Map.of("email", workContactResource); String mailFromWorkContact = userMapper.retrieveMailFromWorkContacts(workContactResourceMap, "notPresent");