Skip to content

Commit

Permalink
[SELC-6087] Updated api updateUserRegistryAndSendNotification to allo…
Browse files Browse the repository at this point in the history
…w updating the phone number in addition to the email.
  • Loading branch information
flaminiaScarciofolo committed Nov 27, 2024
1 parent 8cda843 commit c132fef
Show file tree
Hide file tree
Showing 16 changed files with 384 additions and 185 deletions.
11 changes: 5 additions & 6 deletions apps/user-ms/src/main/docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1387,14 +1387,10 @@
"type" : "string"
},
"certified" : {
"$ref" : "#/components/schemas/CertificationEnum"
"type" : "string"
}
}
},
"CertificationEnum" : {
"enum" : [ "NONE", "SPID" ],
"type" : "string"
},
"CreateUserDto" : {
"required" : [ "institutionId", "user", "product" ],
"type" : "object",
Expand Down Expand Up @@ -1620,7 +1616,6 @@
}
},
"UpdateUserRequest" : {
"required" : [ "email" ],
"type" : "object",
"properties" : {
"name" : {
Expand All @@ -1631,6 +1626,10 @@
},
"email" : {
"type" : "string"
},
"mobilePhone" : {
"pattern" : "^\\+?[0-9]{9,15}$",
"type" : "string"
}
}
},
Expand Down
12 changes: 4 additions & 8 deletions apps/user-ms/src/main/docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -993,12 +993,7 @@ components:
value:
type: string
certified:
$ref: "#/components/schemas/CertificationEnum"
CertificationEnum:
enum:
- NONE
- SPID
type: string
type: string
CreateUserDto:
required:
- institutionId
Expand Down Expand Up @@ -1182,8 +1177,6 @@ components:
institutionRootName:
type: string
UpdateUserRequest:
required:
- email
type: object
properties:
name:
Expand All @@ -1192,6 +1185,9 @@ components:
type: string
email:
type: string
mobilePhone:
pattern: "^\\+?[0-9]{9,15}$"
type: string
User:
required:
- fiscalCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public class CollectionUtil {
public static final String CURRENT_ANY = ".$[].";

public static final String MAIL_ID_PREFIX = "ID_MAIL#";

public static final String CONTACTS_ID_PREFIX = "ID_CONTACTS#";
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public Multi<UserInstitutionResponse> retrievePaginatedAndFilteredUser(@QueryPar
@Produces(MediaType.APPLICATION_JSON)
public Uni<Response> updateUserRegistryAndSendNotification(@PathParam(value = "id") String userId,
@QueryParam(value = "institutionId") String institutionId,
UpdateUserRequest updateUserRequest) {
@Valid UpdateUserRequest updateUserRequest) {
return userRegistryService.updateUserRegistry(updateUserRequest, userId, institutionId)
.map(ignore -> Response
.status(HttpStatus.SC_NO_CONTENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfstring;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CertifiableFieldResponse<T> {
private T value;
private CertifiableFieldResourceOfstring.CertificationEnum certified;
private String certified;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
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.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.SaveUserDto;
import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfLocalDate;

import java.time.LocalDate;
import java.util.*;
Expand All @@ -31,15 +34,15 @@ public interface UserMapper {
UserNotificationResponse toUserNotification(UserNotificationToSend user);

@Mapping(source = "userResource.fiscalCode", target = "taxCode")
@Mapping(source = "userResource.familyName", target = "surname", qualifiedByName = "fromCertifiableString")
@Mapping(source = "userResource.name", target = "name", qualifiedByName = "fromCertifiableString")
@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 = "workContacts", expression = "java(toWorkContacts(userResource.getWorkContacts()))")
UserResponse toUserResponse(UserResource userResource, String userMailUuid);

@Mapping(target = "email", expression = "java(retrieveCertifiedMailFromWorkContacts(userResource, userMailUuid))")
@Mapping(source = "userResource.familyName", target = "familyName", qualifiedByName = "toCertifiableFieldResponse")
@Mapping(source = "userResource.name", target = "name", qualifiedByName = "toCertifiableFieldResponse")
@Mapping(source = "userResource.familyName", target = "familyName", qualifiedByName = "toFamilyNameCertifiableFieldResponse")
@Mapping(source = "userResource.name", target = "name", qualifiedByName = "toNameCertifiableFieldResponse")
@Mapping(target = "workContacts", expression = "java(toWorkContactResponse(userResource.getWorkContacts()))")
UserDetailResponse toUserDetailResponse(UserResource userResource, String userMailUuid);

Expand All @@ -55,9 +58,14 @@ default Map<String, String> toWorkContacts(Map<String, WorkContactResource> work
}


@Named("fromCertifiableString")
default String fromCertifiableString(CertifiableFieldResourceOfstring certifiableFieldResourceOfstring) {
return Optional.ofNullable(certifiableFieldResourceOfstring).map(CertifiableFieldResourceOfstring::getValue).orElse(null);
@Named("fromSurnameCertifiableString")
default String fromCertifiableString(org.openapi.quarkus.user_registry_json.model.FamilyNameCertifiableSchema certifiableFieldResourceOfstring) {
return Optional.ofNullable(certifiableFieldResourceOfstring).map(org.openapi.quarkus.user_registry_json.model.FamilyNameCertifiableSchema::getValue).orElse(null);
}

@Named("fromNameCertifiableString")
default String fromCertifiableString(NameCertifiableSchema certifiableFieldResourceOfstring) {
return Optional.ofNullable(certifiableFieldResourceOfstring).map(NameCertifiableSchema::getValue).orElse(null);
}

@Named("toWorkContactResponse")
Expand All @@ -66,7 +74,7 @@ default Map<String, WorkContactResponse> toWorkContactResponse(Map<String, WorkC
if (workContactResourceMap != null && !workContactResourceMap.isEmpty()) {
workContactResourceMap.forEach((key, value) -> {
WorkContactResponse workContact = new WorkContactResponse();
workContact.setEmail(toCertifiableFieldResponse(value.getEmail()));
workContact.setEmail(toEmailCertifiableFieldResponse(value.getEmail()));
resourceMap.put(key, workContact);
});
}
Expand All @@ -87,71 +95,142 @@ default String retrieveMailFromWorkContacts(Map<String, WorkContactResource> map
@Named("retrieveCertifiedMailFromWorkContacts")
default CertifiableFieldResponse<String> 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 new CertifiableFieldResponse<>(userResource.getWorkContacts().get(userMailUuid).getEmail().getValue(),
Optional.ofNullable(userResource.getWorkContacts().get(userMailUuid).getEmail().getCertification())
.map(EmailCertifiableSchema.CertificationEnum::value).orElse(null));
}
return null;
}

@Named("toCertifiableFieldResponse")
default CertifiableFieldResponse<String> toCertifiableFieldResponse(CertifiableFieldResourceOfstring resource){
return Optional.ofNullable(resource).map(r -> new CertifiableFieldResponse<>(r.getValue(), r.getCertification())).orElse(null);
@Named("toNameCertifiableFieldResponse")
default CertifiableFieldResponse<String> toNameCertifiableFieldResponse(NameCertifiableSchema resource){
return Optional.ofNullable(resource).map(r -> new CertifiableFieldResponse<>(r.getValue(),
Optional.ofNullable(r.getCertification()).map(NameCertifiableSchema.CertificationEnum::value).orElse(null)))
.orElse(null);
}

@Named("toFamilyNameCertifiableFieldResponse")
default CertifiableFieldResponse<String> toFamilyNameCertifiableFieldResponse(FamilyNameCertifiableSchema resource){
return Optional.ofNullable(resource).map(r -> new CertifiableFieldResponse<>(r.getValue(),
Optional.ofNullable(r.getCertification()).map(FamilyNameCertifiableSchema.CertificationEnum::value).orElse(null)))
.orElse(null);
}

@Named("toEmailCertifiableFieldResponse")
default CertifiableFieldResponse<String> toEmailCertifiableFieldResponse(EmailCertifiableSchema resource){
return Optional.ofNullable(resource).map(r -> new CertifiableFieldResponse<>(r.getValue(),
Optional.ofNullable(r.getCertification()).map(EmailCertifiableSchema.CertificationEnum::value).orElse(null)))
.orElse(null);
}
MutableUserFieldsDto toMutableUserFieldsDto(UserResource userResource);

@Mapping(target = "familyName", expression = "java(toCertifiableStringNotEquals(userResource.getFamilyName(), updateUserRequest.getFamilyName()))")
@Mapping(target = "name", expression = "java(toCertifiableStringNotEquals(userResource.getName(), updateUserRequest.getName()))")
@Mapping(target = "workContacts", expression = "java(toWorkContact(updateUserRequest.getEmail(), idMail))")
@Mapping(target = "familyName", expression = "java(toFamilyNameCertifiableStringNotEquals(userResource.getFamilyName(), updateUserRequest.getFamilyName()))")
@Mapping(target = "name", expression = "java(toNameCertifiableStringNotEquals(userResource.getName(), updateUserRequest.getName()))")
@Mapping(target = "workContacts", expression = "java(toWorkContact(updateUserRequest.getEmail(), updateUserRequest.getMobilePhone(), idContact))")
@Mapping(target = "email", ignore = true)
@Mapping(target = "birthDate", ignore = true)
MutableUserFieldsDto toMutableUserFieldsDto(UpdateUserRequest updateUserRequest, UserResource userResource, String idMail);
MutableUserFieldsDto toMutableUserFieldsDto(UpdateUserRequest updateUserRequest, UserResource userResource, String idContact);

@Mapping(source = "user.birthDate", target = "birthDate", qualifiedByName = "toCertifiableLocalDate")
@Mapping(source = "user.familyName", target = "familyName", qualifiedByName = "toCertifiableString")
@Mapping(source = "user.name", target = "name", qualifiedByName = "toCertifiableString")
@Mapping(source = "user.familyName", target = "familyName", qualifiedByName = "toFamilyNameCertifiableString")
@Mapping(source = "user.name", target = "name", qualifiedByName = "toNameCertifiableString")
@Mapping(source = "user.fiscalCode", target = "fiscalCode")
@Mapping(source = "workContactResource", target = "workContacts")
SaveUserDto toSaveUserDto(CreateUserDto.User user, Map<String, WorkContactResource> workContactResource);

@Named("toFamilyNameCertifiableStringNotEquals")
default FamilyNameCertifiableSchema toFamilyNameCertifiableStringNotEquals(FamilyNameCertifiableSchema certifiableString, String value) {
if(StringUtils.isBlank(value) ||
Objects.nonNull(certifiableString) && FamilyNameCertifiableSchema.CertificationEnum.SPID.equals(certifiableString.getCertification())){
return null;
}

if(Objects.isNull(certifiableString) || !value.equals(certifiableString.getValue())){
var certifiableFieldResourceOfstring = new FamilyNameCertifiableSchema();
certifiableFieldResourceOfstring.setValue(value);
certifiableFieldResourceOfstring.setCertification(FamilyNameCertifiableSchema.CertificationEnum.NONE);
return certifiableFieldResourceOfstring;
}
return null;
}

@Named("toNameCertifiableStringNotEquals")
default NameCertifiableSchema toNameCertifiableStringNotEquals(NameCertifiableSchema certifiableString, String value) {
if(StringUtils.isBlank(value) ||
Objects.nonNull(certifiableString) && NameCertifiableSchema.CertificationEnum.SPID.equals(certifiableString.getCertification())){
return null;
}

if(Objects.isNull(certifiableString) || !value.equals(certifiableString.getValue())){
var certifiableFieldResourceOfstring = new NameCertifiableSchema();
certifiableFieldResourceOfstring.setValue(value);
certifiableFieldResourceOfstring.setCertification(NameCertifiableSchema.CertificationEnum.NONE);
return certifiableFieldResourceOfstring;
}
return null;
}
@Named("toWorkContact")
default Map<String, WorkContactResource> toWorkContact(String email, String idMail){
if (StringUtils.isNotBlank(idMail) && StringUtils.isNotBlank(email)){
default Map<String, WorkContactResource> toWorkContact(String email, String phoneNumber, String idContact){
if (StringUtils.isNotBlank(idContact)){
WorkContactResource workContactResource = new WorkContactResource();
workContactResource.setEmail(toCertString(email));
return Map.of(idMail, workContactResource);
if(StringUtils.isNotBlank(email)){
workContactResource.setEmail(toMailCertString(email));
}
if(StringUtils.isNotBlank(phoneNumber)){
workContactResource.setMobilePhone(toPhoneCertString(phoneNumber));
}
return Map.of(idContact, workContactResource);
}
return null;
}

@Named("toCertifiableLocalDate")
default CertifiableFieldResourceOfLocalDate toLocalTime(String time) {
default BirthDateCertifiableSchema toLocalTime(String time) {
if(Objects.isNull(time)) return null;
var certifiableFieldResourceOfLocalDate = new CertifiableFieldResourceOfLocalDate();
var certifiableFieldResourceOfLocalDate = new BirthDateCertifiableSchema();
certifiableFieldResourceOfLocalDate.setValue(LocalDate.parse(time));
certifiableFieldResourceOfLocalDate.setCertification(CertifiableFieldResourceOfLocalDate.CertificationEnum.NONE);
certifiableFieldResourceOfLocalDate.setCertification(BirthDateCertifiableSchema.CertificationEnum.NONE);
return certifiableFieldResourceOfLocalDate;
}

@Named("toCertifiableString")
default CertifiableFieldResourceOfstring toCertString(String value) {

default EmailCertifiableSchema toMailCertString(String value) {
if (StringUtils.isNotBlank(value)){
var certifiableFieldResourceOfstring = new CertifiableFieldResourceOfstring();
var certifiableFieldResourceOfstring = new EmailCertifiableSchema();
certifiableFieldResourceOfstring.setValue(value);
certifiableFieldResourceOfstring.setCertification(CertifiableFieldResourceOfstring.CertificationEnum.NONE);
certifiableFieldResourceOfstring.setCertification(EmailCertifiableSchema.CertificationEnum.NONE);
return certifiableFieldResourceOfstring;
}
return null;
}

@Named("toCertifiableStringNotEquals")
default CertifiableFieldResourceOfstring toCertifiableStringNotEquals(CertifiableFieldResourceOfstring certifiableString, String value) {
if(StringUtils.isBlank(value) ||
Objects.nonNull(certifiableString) && CertifiableFieldResourceOfstring.CertificationEnum.SPID.equals(certifiableString.getCertification())){
return null;
default MobilePhoneCertifiableSchema toPhoneCertString(String value){
if (StringUtils.isNotBlank(value)){
var certifiableFieldResourceOfstring = new MobilePhoneCertifiableSchema();
certifiableFieldResourceOfstring.setValue(value);
certifiableFieldResourceOfstring.setCertification(MobilePhoneCertifiableSchema.CertificationEnum.NONE);
return certifiableFieldResourceOfstring;
}
return null;
}

if(Objects.isNull(certifiableString) || !value.equals(certifiableString.getValue())){
var certifiableFieldResourceOfstring = new CertifiableFieldResourceOfstring();
@Named("toNameCertifiableString")
default NameCertifiableSchema toNameCertString(String value) {
if (StringUtils.isNotBlank(value)){
var certifiableFieldResourceOfstring = new NameCertifiableSchema();
certifiableFieldResourceOfstring.setValue(value);
certifiableFieldResourceOfstring.setCertification(NameCertifiableSchema.CertificationEnum.NONE);
return certifiableFieldResourceOfstring;
}
return null;
}

@Named("toFamilyNameCertifiableString")
default FamilyNameCertifiableSchema toFamilyNameCertString(String value) {
if (StringUtils.isNotBlank(value)){
var certifiableFieldResourceOfstring = new FamilyNameCertifiableSchema();
certifiableFieldResourceOfstring.setValue(value);
certifiableFieldResourceOfstring.setCertification(CertifiableFieldResourceOfstring.CertificationEnum.NONE);
certifiableFieldResourceOfstring.setCertification(FamilyNameCertifiableSchema.CertificationEnum.NONE);
return certifiableFieldResourceOfstring;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package it.pagopa.selfcare.user.model;

import jakarta.validation.constraints.NotNull;
import lombok.Data;

import javax.validation.constraints.Pattern;

@Data
public class UpdateUserRequest {
private String name;
private String familyName;
@NotNull
private String email;
@Pattern(regexp = "^\\+?[0-9]{9,15}$", message = "Il numero di telefono non è valido")
private String mobilePhone;
}
Loading

0 comments on commit c132fef

Please sign in to comment.