Skip to content

Commit

Permalink
add check on null workcontact
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminiaScarciofolo committed Apr 18, 2024
1 parent a2b0461 commit 43ed990
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.openapi.quarkus.user_registry_json.model.UserResource;
import org.openapi.quarkus.user_registry_json.model.WorkContactResource;
import software.amazon.awssdk.utils.CollectionUtils;

import java.io.StringWriter;
import java.util.HashMap;
Expand Down Expand Up @@ -159,7 +160,10 @@ private StringWriter getContent(String templateName, Map<String, String> dataMod
}

private static String retrieveMail(UserResource user, UserInstitution institution) {
WorkContactResource certEmail = user.getWorkContacts().getOrDefault(institution.getUserMailUuid(), null);
WorkContactResource certEmail = null;
if(!CollectionUtils.isNullOrEmpty(user.getWorkContacts())){
certEmail = user.getWorkContacts().getOrDefault(institution.getUserMailUuid(), null);
}
String email;
if (certEmail == null || certEmail.getEmail() == null || StringUtils.isBlank(certEmail.getEmail().getValue())) {
throw new InvalidRequestException("Missing mail for userId: " + user.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
import lombok.extern.slf4j.Slf4j;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.gradle.internal.impldep.org.apache.commons.lang.StringUtils;
import org.openapi.quarkus.user_registry_json.model.MutableUserFieldsDto;
import org.openapi.quarkus.user_registry_json.api.UserApi;
import org.openapi.quarkus.user_registry_json.model.UserResource;
import software.amazon.awssdk.utils.CollectionUtils;

import java.util.List;
import java.util.UUID;
import java.util.concurrent.Flow;

import org.openapi.quarkus.user_registry_json.api.UserApi;
import org.openapi.quarkus.user_registry_json.model.UserResource;


@ApplicationScoped
Expand Down Expand Up @@ -74,6 +72,13 @@ private Multi<UserNotificationToSend> sendKafkaNotification(UserResource userRes
}

private Uni<String> checkEmail(UserResource userResource, UpdateUserRequest userDto) {

if(CollectionUtils.isNullOrEmpty(userResource.getWorkContacts())) {
log.debug("WorkContacts is empty");
String idMail = "ID_MAIL#" + UUID.randomUUID();
return userRegistryApi.updateUsingPATCH(userResource.getId().toString(), userMapper.toMutableUserFieldsDto(userDto, idMail)).replaceWith(idMail);
}

return userResource.getWorkContacts().entrySet().stream()
.filter(entry -> entry.getValue() != null && entry.getValue().getEmail() != null && StringUtils.isNotBlank(entry.getValue().getEmail().getValue())
&& entry.getValue().getEmail().getValue().equalsIgnoreCase(userDto.getEmail()) && entry.getKey().startsWith("ID_MAIL#"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,23 @@ public Uni<String> createOrUpdateUserByFiscalCode(CreateUserDto userDto, LoggedU
*/
private Uni<PrepareNotificationData> updateUserOnUserRegistryAndUserInstitutionByFiscalCode(UserResource userResource, CreateUserDto userDto) {
log.info("Updating user on userRegistry and userInstitution");
String mailUuid = userUtils.getMailUuidFromMail(userResource.getWorkContacts(), userDto.getUser().getInstitutionEmail())
.orElse(randomMailId.get());
String mailUuid;
if(!CollectionUtils.isNullOrEmpty(userResource.getWorkContacts())) {
mailUuid = userUtils.getMailUuidFromMail(userResource.getWorkContacts(), userDto.getUser().getInstitutionEmail())
.orElse(randomMailId.get());
}else {
mailUuid = randomMailId.get();
}

var workContact = UserUtils.buildWorkContact(userDto.getUser().getInstitutionEmail());
userResource.getWorkContacts().put(mailUuid, workContact);
if(CollectionUtils.isNullOrEmpty(userResource.getWorkContacts())){
Map<String, WorkContactResource> workContactResourceMap = new HashMap<>();
workContactResourceMap.put(mailUuid, workContact);
userResource.setWorkContacts(workContactResourceMap);
}else{
userResource.getWorkContacts().put(mailUuid, workContact);
}


return userRegistryApi.updateUsingPATCH(userResource.getId().toString(), userMapper.toMutableUserFieldsDto(userResource))
.onFailure().invoke(exception -> log.error("Error during update user on userRegistry: {} ", exception.getMessage(), exception))
Expand Down

0 comments on commit 43ed990

Please sign in to comment.