diff --git a/apps/user-ms/src/main/docs/openapi.json b/apps/user-ms/src/main/docs/openapi.json index d8cb32ca..ca69cf80 100644 --- a/apps/user-ms/src/main/docs/openapi.json +++ b/apps/user-ms/src/main/docs/openapi.json @@ -1894,6 +1894,9 @@ "email" : { "type" : "string" }, + "mobilePhone" : { + "type" : "string" + }, "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 dcc412e6..822e1c46 100644 --- a/apps/user-ms/src/main/docs/openapi.yaml +++ b/apps/user-ms/src/main/docs/openapi.yaml @@ -1371,6 +1371,8 @@ components: type: string email: type: string + mobilePhone: + type: string workContacts: type: object additionalProperties: diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/controller/response/UserResponse.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/controller/response/UserResponse.java index e595d6ea..88a15e3f 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/controller/response/UserResponse.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/controller/response/UserResponse.java @@ -25,5 +25,6 @@ public class UserResponse { @NotBlank private String surname; private String email; + private String 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 558ba03f..15f08a0e 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 @@ -39,6 +39,7 @@ public interface UserMapper { @Mapping(source = "userResource.familyName", target = "surname", qualifiedByName = "fromSurnameCertifiableString") @Mapping(source = "userResource.name", target = "name", qualifiedByName = "fromNameCertifiableString") @Mapping(target = "email", expression = "java(retrieveMailFromWorkContacts(userResource.getWorkContacts(), userMailUuid))") + @Mapping(target = "mobilePhone", expression = "java(retrieveMobilePhoneFromWorkContacts(userResource.getWorkContacts(), userMailUuid))") @Mapping(target = "workContacts", expression = "java(toWorkContacts(userResource.getWorkContacts()))") UserResponse toUserResponse(UserResource userResource, String userMailUuid); @@ -94,6 +95,16 @@ default String retrieveMailFromWorkContacts(Map map .orElse(null); } + @Named("retrieveMobilePhoneFromWorkContacts") + default String retrieveMobilePhoneFromWorkContacts(Map map, String userMailUuid){ + return Optional.ofNullable(map) + .filter(item -> item.containsKey(userMailUuid)) + .map(item -> map.get(userMailUuid)) + .filter(workContactResource -> Objects.nonNull(workContactResource.getMobilePhone())) + .map(workContactResource -> workContactResource.getMobilePhone().getValue()) + .orElse(null); + } + @Named("retrieveCertifiedMailFromWorkContacts") default CertifiableFieldResponse retrieveCertifiedMailFromWorkContacts(UserResource userResource, String userMailUuid) { 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 c24e8dac..d7a78262 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 @@ -8,13 +8,7 @@ import it.pagopa.selfcare.user.model.OnboardedProduct; import it.pagopa.selfcare.user.model.constants.OnboardedProductState; import org.junit.jupiter.api.Test; -import org.openapi.quarkus.user_registry_json.model.BirthDateCertifiableSchema; -import org.openapi.quarkus.user_registry_json.model.EmailCertifiableSchema; -import org.openapi.quarkus.user_registry_json.model.FamilyNameCertifiableSchema; -import org.openapi.quarkus.user_registry_json.model.MobilePhoneCertifiableSchema; -import org.openapi.quarkus.user_registry_json.model.NameCertifiableSchema; -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.*; import java.time.LocalDate; import java.util.ArrayList; @@ -27,34 +21,37 @@ @QuarkusTest public class UserMapperTest { + public static final String CONTACTS_UUID = "contactsUuid"; + public static final String EMAIL = "email"; + public static final String MOBILE_PHONE = "mobilePhone"; private final UserMapper userMapper = new UserMapperImpl(); @Test void retrieveCertifiedEmailFromWorkContacts(){ final UserResource userResource = new UserResource(); - final EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, "email"); - final MobilePhoneCertifiableSchema phone = new MobilePhoneCertifiableSchema(MobilePhoneCertifiableSchema.CertificationEnum.NONE, "mobilePhone"); + final EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, EMAIL); + final MobilePhoneCertifiableSchema phone = new MobilePhoneCertifiableSchema(MobilePhoneCertifiableSchema.CertificationEnum.NONE, MOBILE_PHONE); WorkContactResource workContactResource = new WorkContactResource(email, phone, null); - Map workContactResourceMap = Map.of("contactsUuid", workContactResource); + Map workContactResourceMap = Map.of(CONTACTS_UUID, workContactResource); userResource.setWorkContacts(workContactResourceMap); - CertifiableFieldResponse certifiedMail = userMapper.retrieveCertifiedMailFromWorkContacts(userResource, "contactsUuid"); + CertifiableFieldResponse certifiedMail = userMapper.retrieveCertifiedMailFromWorkContacts(userResource, CONTACTS_UUID); assertEquals(CertificationEnum.NONE,certifiedMail.getCertified()); - assertEquals("email", certifiedMail.getValue()); + assertEquals(EMAIL, certifiedMail.getValue()); } @Test void retrieveCertifiedMobilePhoneFromWorkContacts(){ final UserResource userResource = new UserResource(); - final EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, "email"); - String mobilePhone = "mobilePhone"; + final EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, EMAIL); + String mobilePhone = MOBILE_PHONE; final MobilePhoneCertifiableSchema phone = new MobilePhoneCertifiableSchema(MobilePhoneCertifiableSchema.CertificationEnum.NONE, mobilePhone); WorkContactResource workContactResource = new WorkContactResource(email, phone, null); - Map workContactResourceMap = Map.of("contactsUuid", workContactResource); + Map workContactResourceMap = Map.of(CONTACTS_UUID, workContactResource); userResource.setWorkContacts(workContactResourceMap); - CertifiableFieldResponse certifiedPhone = userMapper.retrieveCertifiedMobilePhoneFromWorkContacts(userResource, "contactsUuid"); + CertifiableFieldResponse certifiedPhone = userMapper.retrieveCertifiedMobilePhoneFromWorkContacts(userResource, CONTACTS_UUID); assertEquals(CertificationEnum.NONE,certifiedPhone.getCertified()); assertEquals(mobilePhone, certifiedPhone.getValue()); @@ -64,7 +61,7 @@ void retrieveCertifiedMobilePhoneFromWorkContacts(){ void retrieveCertifiedEmailFromWorkContacts_nullWorkContacts(){ final UserResource userResource = new UserResource(); - CertifiableFieldResponse certifiedMail = userMapper.retrieveCertifiedMailFromWorkContacts(userResource, "email"); + CertifiableFieldResponse certifiedMail = userMapper.retrieveCertifiedMailFromWorkContacts(userResource, CONTACTS_UUID); assertNull(certifiedMail); } @@ -72,11 +69,11 @@ void retrieveCertifiedEmailFromWorkContacts_nullWorkContacts(){ @Test void retrieveCertifiedEmailFromWorkContacts_notPresent(){ final UserResource userResource = new UserResource(); - final EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, "email"); - final MobilePhoneCertifiableSchema phone = new MobilePhoneCertifiableSchema(MobilePhoneCertifiableSchema.CertificationEnum.NONE, "mobilePhone"); + final EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, EMAIL); + final MobilePhoneCertifiableSchema phone = new MobilePhoneCertifiableSchema(MobilePhoneCertifiableSchema.CertificationEnum.NONE, MOBILE_PHONE); WorkContactResource workContactResource = new WorkContactResource(email, phone, null); - Map workContactResourceMap = Map.of("email", workContactResource); + Map workContactResourceMap = Map.of(CONTACTS_UUID, workContactResource); userResource.setWorkContacts(workContactResourceMap); CertifiableFieldResponse certifiedMail = userMapper.retrieveCertifiedMailFromWorkContacts(userResource, "notPresent"); @@ -87,40 +84,69 @@ void retrieveCertifiedEmailFromWorkContacts_notPresent(){ @Test void retrieveMailFromWorkContacts(){ - final EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, "email"); - final MobilePhoneCertifiableSchema phone = new MobilePhoneCertifiableSchema(MobilePhoneCertifiableSchema.CertificationEnum.NONE, "mobilePhone"); + final EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, EMAIL); + final MobilePhoneCertifiableSchema phone = new MobilePhoneCertifiableSchema(MobilePhoneCertifiableSchema.CertificationEnum.NONE, MOBILE_PHONE); WorkContactResource workContactResource = new WorkContactResource(email, phone, null); - Map workContactResourceMap = Map.of("email", workContactResource); + Map workContactResourceMap = Map.of(CONTACTS_UUID, workContactResource); - String mailFromWorkContact = userMapper.retrieveMailFromWorkContacts(workContactResourceMap, "email"); + String mailFromWorkContact = userMapper.retrieveMailFromWorkContacts(workContactResourceMap, CONTACTS_UUID); - assertEquals("email", mailFromWorkContact); + assertEquals(EMAIL, mailFromWorkContact); + } + + @Test + void retrieveMobilePhoneFromWorkContacts(){ + final EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, EMAIL); + final MobilePhoneCertifiableSchema phone = new MobilePhoneCertifiableSchema(MobilePhoneCertifiableSchema.CertificationEnum.NONE, MOBILE_PHONE); + WorkContactResource workContactResource = new WorkContactResource(email, phone, null); + Map workContactResourceMap = Map.of(CONTACTS_UUID, workContactResource); + + String phoneFromWorkContacts = userMapper.retrieveMobilePhoneFromWorkContacts(workContactResourceMap, CONTACTS_UUID); + + assertEquals(MOBILE_PHONE, phoneFromWorkContacts); } @Test void retrieveMailFromWorkContacts_emptyMap(){ Map workContactResourceMap = new HashMap<>(); - String mailFromWorkContact = userMapper.retrieveMailFromWorkContacts(workContactResourceMap, "email"); + String mailFromWorkContact = userMapper.retrieveMailFromWorkContacts(workContactResourceMap, CONTACTS_UUID); assertNull(mailFromWorkContact); } + @Test + void retrieveMobilePhoneFromWorkContacts_emptyMap(){ + Map workContactResourceMap = new HashMap<>(); + + String phoneFromWorkContact = userMapper.retrieveMobilePhoneFromWorkContacts(workContactResourceMap, CONTACTS_UUID); + + assertNull(phoneFromWorkContact); + } + @Test void retrieveMailFromWorkContacts_nullMap(){ - String mailFromWorkContact = userMapper.retrieveMailFromWorkContacts(null, "email"); + String mailFromWorkContact = userMapper.retrieveMailFromWorkContacts(null, CONTACTS_UUID); assertNull(mailFromWorkContact); } + @Test + void retrievePhoneFromWorkContacts_nullMap(){ + + String phoneFromWorkContact = userMapper.retrieveMailFromWorkContacts(null, CONTACTS_UUID); + + assertNull(phoneFromWorkContact); + } + @Test void retrieveMailFromWorkContacts_notPresent(){ - final EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, "email"); - final MobilePhoneCertifiableSchema phone = new MobilePhoneCertifiableSchema(MobilePhoneCertifiableSchema.CertificationEnum.NONE, "mobilePhone"); + final EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, EMAIL); + final MobilePhoneCertifiableSchema phone = new MobilePhoneCertifiableSchema(MobilePhoneCertifiableSchema.CertificationEnum.NONE, MOBILE_PHONE); WorkContactResource workContactResource = new WorkContactResource(email, phone, null); - Map workContactResourceMap = Map.of("email", workContactResource); + Map workContactResourceMap = Map.of(CONTACTS_UUID, workContactResource); String mailFromWorkContact = userMapper.retrieveMailFromWorkContacts(workContactResourceMap, "notPresent"); @@ -131,12 +157,12 @@ void retrieveMailFromWorkContacts_notPresent(){ void toWorkContactResponseMap(){ final Map workContactResourceMap = new HashMap<>(); final WorkContactResource workContactResource = new WorkContactResource(); - final EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, "email"); + final EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, EMAIL); workContactResource.setEmail(email); - workContactResourceMap.put("email", workContactResource); + workContactResourceMap.put(CONTACTS_UUID, workContactResource); Map responseMap = userMapper.toWorkContactResponse(workContactResourceMap); - assertEquals(email.getValue(), responseMap.get("email").getEmail().getValue()); + assertEquals(email.getValue(), responseMap.get(CONTACTS_UUID).getEmail().getValue()); } @Test @@ -157,14 +183,14 @@ void toWorkContactResponseMap_empty(){ @Test void toWorkContactsValidWorkContactResourceMap() { Map workContactResourceMap = new HashMap<>(); - EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, "email@example.com"); + EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, EMAIL); WorkContactResource workContactResource = new WorkContactResource(email, null, null); - workContactResourceMap.put("contact1", workContactResource); + workContactResourceMap.put(CONTACTS_UUID, workContactResource); Map result = userMapper.toWorkContacts(workContactResourceMap); assertEquals(1, result.size()); - assertEquals("email@example.com", result.get("contact1")); + assertEquals(EMAIL, result.get(CONTACTS_UUID)); } @Test @@ -328,28 +354,28 @@ void toNameCertifiableStringNotEqualsWithDifferentValue() { @Test void toWorkContact() { - Map result = userMapper.toWorkContact("email@example.com", "1234567890", "contact1"); + Map result = userMapper.toWorkContact(EMAIL, MOBILE_PHONE, CONTACTS_UUID); assertNotNull(result); assertEquals(1, result.size()); - assertEquals("email@example.com", result.get("contact1").getEmail().getValue()); - assertEquals("1234567890", result.get("contact1").getMobilePhone().getValue()); + assertEquals(EMAIL, result.get(CONTACTS_UUID).getEmail().getValue()); + assertEquals(MOBILE_PHONE, result.get(CONTACTS_UUID).getMobilePhone().getValue()); } @Test void toWorkContactWithBlankIdContact() { - Map result = userMapper.toWorkContact("email@example.com", "1234567890", " "); + Map result = userMapper.toWorkContact(EMAIL, MOBILE_PHONE, " "); assertNull(result); } @Test void toWorkContactWithNullEmailAndPhoneNumber() { - Map result = userMapper.toWorkContact(null, null, "contact1"); + Map result = userMapper.toWorkContact(null, null, CONTACTS_UUID); assertNotNull(result); assertEquals(1, result.size()); - assertNull(result.get("contact1").getEmail()); - assertNull(result.get("contact1").getMobilePhone()); + assertNull(result.get(CONTACTS_UUID).getEmail()); + assertNull(result.get(CONTACTS_UUID).getMobilePhone()); } @Test @@ -369,10 +395,10 @@ void toCertifiableLocalDateWithNullTime() { @Test void toMailCertString() { - EmailCertifiableSchema result = userMapper.toMailCertString("email@example.com"); + EmailCertifiableSchema result = userMapper.toMailCertString(EMAIL); assertNotNull(result); - assertEquals("email@example.com", result.getValue()); + assertEquals(EMAIL, result.getValue()); assertEquals(EmailCertifiableSchema.CertificationEnum.NONE, result.getCertification()); } @@ -385,10 +411,10 @@ void toMailCertStringWithBlankValue() { @Test void toPhoneCertString() { - MobilePhoneCertifiableSchema result = userMapper.toPhoneCertString("1234567890"); + MobilePhoneCertifiableSchema result = userMapper.toPhoneCertString(MOBILE_PHONE); assertNotNull(result); - assertEquals("1234567890", result.getValue()); + assertEquals(MOBILE_PHONE, result.getValue()); assertEquals(MobilePhoneCertifiableSchema.CertificationEnum.NONE, result.getCertification()); }