Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SELC-6085] feat: add mobilePhone field in retrieveUsers API response #234

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/user-ms/src/main/docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,9 @@
"email" : {
"type" : "string"
},
"mobilePhone" : {
"type" : "string"
},
"workContacts" : {
"type" : "object",
"additionalProperties" : {
Expand Down
2 changes: 2 additions & 0 deletions apps/user-ms/src/main/docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,8 @@ components:
type: string
email:
type: string
mobilePhone:
type: string
workContacts:
type: object
additionalProperties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ public class UserResponse {
@NotBlank
private String surname;
private String email;
private String mobilePhone;
private Map<String, String> workContacts;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
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.MutableUserFieldsDto;
import org.openapi.quarkus.user_registry_json.model.NameCertifiableSchema;
import org.openapi.quarkus.user_registry_json.model.SaveUserDto;
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.*;
Expand All @@ -39,6 +31,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);

Expand Down Expand Up @@ -94,6 +87,16 @@ default String retrieveMailFromWorkContacts(Map<String, WorkContactResource> map
.orElse(null);
}

@Named("retrieveMobilePhoneFromWorkContacts")
default String retrieveMobilePhoneFromWorkContacts(Map<String, WorkContactResource> 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<String> retrieveCertifiedMailFromWorkContacts(UserResource userResource, String userMailUuid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, WorkContactResource> workContactResourceMap = Map.of("contactsUuid", workContactResource);
Map<String, WorkContactResource> workContactResourceMap = Map.of(CONTACTS_UUID, workContactResource);
userResource.setWorkContacts(workContactResourceMap);

CertifiableFieldResponse<String> certifiedMail = userMapper.retrieveCertifiedMailFromWorkContacts(userResource, "contactsUuid");
CertifiableFieldResponse<String> 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<String, WorkContactResource> workContactResourceMap = Map.of("contactsUuid", workContactResource);
Map<String, WorkContactResource> workContactResourceMap = Map.of(CONTACTS_UUID, workContactResource);
userResource.setWorkContacts(workContactResourceMap);

CertifiableFieldResponse<String> certifiedPhone = userMapper.retrieveCertifiedMobilePhoneFromWorkContacts(userResource, "contactsUuid");
CertifiableFieldResponse<String> certifiedPhone = userMapper.retrieveCertifiedMobilePhoneFromWorkContacts(userResource, CONTACTS_UUID);

assertEquals(CertificationEnum.NONE,certifiedPhone.getCertified());
assertEquals(mobilePhone, certifiedPhone.getValue());
Expand All @@ -64,19 +61,19 @@ void retrieveCertifiedMobilePhoneFromWorkContacts(){
void retrieveCertifiedEmailFromWorkContacts_nullWorkContacts(){
final UserResource userResource = new UserResource();

CertifiableFieldResponse<String> certifiedMail = userMapper.retrieveCertifiedMailFromWorkContacts(userResource, "email");
CertifiableFieldResponse<String> certifiedMail = userMapper.retrieveCertifiedMailFromWorkContacts(userResource, CONTACTS_UUID);

assertNull(certifiedMail);
}

@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<String, WorkContactResource> workContactResourceMap = Map.of("email", workContactResource);
Map<String, WorkContactResource> workContactResourceMap = Map.of(CONTACTS_UUID, workContactResource);
userResource.setWorkContacts(workContactResourceMap);

CertifiableFieldResponse<String> certifiedMail = userMapper.retrieveCertifiedMailFromWorkContacts(userResource, "notPresent");
Expand All @@ -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<String, WorkContactResource> workContactResourceMap = Map.of("email", workContactResource);
Map<String, WorkContactResource> 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<String, WorkContactResource> workContactResourceMap = Map.of(CONTACTS_UUID, workContactResource);

String phoneFromWorkContacts = userMapper.retrieveMobilePhoneFromWorkContacts(workContactResourceMap, CONTACTS_UUID);

assertEquals(MOBILE_PHONE, phoneFromWorkContacts);
}

@Test
void retrieveMailFromWorkContacts_emptyMap(){
Map<String, WorkContactResource> workContactResourceMap = new HashMap<>();

String mailFromWorkContact = userMapper.retrieveMailFromWorkContacts(workContactResourceMap, "email");
String mailFromWorkContact = userMapper.retrieveMailFromWorkContacts(workContactResourceMap, CONTACTS_UUID);

assertNull(mailFromWorkContact);
}

@Test
void retrieveMobilePhoneFromWorkContacts_emptyMap(){
Map<String, WorkContactResource> 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<String, WorkContactResource> workContactResourceMap = Map.of("email", workContactResource);
Map<String, WorkContactResource> workContactResourceMap = Map.of(CONTACTS_UUID, workContactResource);

String mailFromWorkContact = userMapper.retrieveMailFromWorkContacts(workContactResourceMap, "notPresent");

Expand All @@ -131,12 +157,12 @@ void retrieveMailFromWorkContacts_notPresent(){
void toWorkContactResponseMap(){
final Map<String, WorkContactResource> 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<String, WorkContactResponse> responseMap = userMapper.toWorkContactResponse(workContactResourceMap);

assertEquals(email.getValue(), responseMap.get("email").getEmail().getValue());
assertEquals(email.getValue(), responseMap.get(CONTACTS_UUID).getEmail().getValue());
}

@Test
Expand All @@ -157,14 +183,14 @@ void toWorkContactResponseMap_empty(){
@Test
void toWorkContactsValidWorkContactResourceMap() {
Map<String, WorkContactResource> workContactResourceMap = new HashMap<>();
EmailCertifiableSchema email = new EmailCertifiableSchema(EmailCertifiableSchema.CertificationEnum.NONE, "[email protected]");
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<String, String> result = userMapper.toWorkContacts(workContactResourceMap);

assertEquals(1, result.size());
assertEquals("[email protected]", result.get("contact1"));
assertEquals(EMAIL, result.get(CONTACTS_UUID));
}

@Test
Expand Down Expand Up @@ -328,28 +354,28 @@ void toNameCertifiableStringNotEqualsWithDifferentValue() {

@Test
void toWorkContact() {
Map<String, WorkContactResource> result = userMapper.toWorkContact("[email protected]", "1234567890", "contact1");
Map<String, WorkContactResource> result = userMapper.toWorkContact(EMAIL, MOBILE_PHONE, CONTACTS_UUID);

assertNotNull(result);
assertEquals(1, result.size());
assertEquals("[email protected]", 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<String, WorkContactResource> result = userMapper.toWorkContact("[email protected]", "1234567890", " ");
Map<String, WorkContactResource> result = userMapper.toWorkContact(EMAIL, MOBILE_PHONE, " ");
assertNull(result);
}

@Test
void toWorkContactWithNullEmailAndPhoneNumber() {
Map<String, WorkContactResource> result = userMapper.toWorkContact(null, null, "contact1");
Map<String, WorkContactResource> 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
Expand All @@ -369,10 +395,10 @@ void toCertifiableLocalDateWithNullTime() {

@Test
void toMailCertString() {
EmailCertifiableSchema result = userMapper.toMailCertString("[email protected]");
EmailCertifiableSchema result = userMapper.toMailCertString(EMAIL);

assertNotNull(result);
assertEquals("[email protected]", result.getValue());
assertEquals(EMAIL, result.getValue());
assertEquals(EmailCertifiableSchema.CertificationEnum.NONE, result.getCertification());
}

Expand All @@ -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());
}

Expand Down
Loading