Skip to content

Commit

Permalink
[SELC-5976] feat: modify persistUser API to allow adding users even i…
Browse files Browse the repository at this point in the history
…f they already exist (#602)
  • Loading branch information
giulia-tremolada authored Nov 13, 2024
1 parent 90e9458 commit 3000bf0
Show file tree
Hide file tree
Showing 9 changed files with 1,660 additions and 1,553 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.openapi.quarkus.user_json.model.PartyRole;

import java.util.List;
import java.util.Objects;
Expand All @@ -20,9 +19,9 @@ public interface ProductMapper {
org.openapi.quarkus.user_json.model.Product toProduct(Onboarding onboarding, User user);

@Named("setRole")
default PartyRole setRole(User user) {
default String setRole(User user) {
if(Objects.nonNull(user.getRole())) {
return PartyRole.valueOf(user.getRole().name());
return user.getRole().name();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void persistUsers(Onboarding onboarding) {
The second parameter (header param) of the following method is used to build a bearer token with which invoke the API
{@link it.pagopa.selfcare.onboarding.client.auth.AuthenticationPropagationHeadersFactory}
*/
try (Response response = userApi.usersUserIdPost(user.getId(), onboarding.getUserRequestUid(), userRoleDto)) {
try (Response response = userApi.createUserByUserId(user.getId(), userRoleDto)) {
if (!SUCCESSFUL.equals(response.getStatusInfo().getFamily())) {
throw new GenericOnboardingException("Impossible to create or update role for user with ID: " + user.getId());
}
Expand Down Expand Up @@ -423,7 +423,7 @@ public List<DelegationResponse> retrieveAggregates(Onboarding onboarding) {
}

private List<String> retrieveActiveManagersOnInstitution(String institutionId, String productId) {
List<UserInstitutionResponse> activeManagers = userInstitutionApi.institutionsInstitutionIdUserInstitutionsGet(
List<UserInstitutionResponse> activeManagers = userInstitutionApi.retrieveUserInstitutions(
institutionId,
null,
List.of(productId),
Expand Down Expand Up @@ -485,7 +485,7 @@ private boolean isActiveManagerOnAdeRegistry(String userTaxCode, String institut
}

private void deleteManagerFromProduct(String uid, String institutionId, String productId) {
try (Response response = userApi.usersUserIdInstitutionsInstitutionIdProductsProductIdDelete(institutionId, productId, uid)) {
try (Response response = userApi.deleteProducts(institutionId, productId, uid)) {
if (!SUCCESSFUL.equals(response.getStatusInfo().getFamily())) {
throw new GenericOnboardingException(String.format("Failed to delete user %s from product %s in institution %s", uid, productId, institutionId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.openapi.quarkus.user_json.model.OnboardedProductResponse;
import org.openapi.quarkus.user_json.model.UserDataResponse;

import java.time.format.DateTimeFormatter;
import java.util.*;

import static it.pagopa.selfcare.onboarding.utils.CustomMetricsConst.EVENT_ONBOARDING_FN_NAME;
Expand Down Expand Up @@ -58,6 +59,7 @@ public class NotificationEventServiceDefault implements NotificationEventService
private final TokenRepository tokenRepository;
private final ObjectMapper mapper;
private final QueueEventExaminer queueEventExaminer;
private static final String NOTIFICATION_EVENT_STRING = "notificationEventTraceId";

public NotificationEventServiceDefault(ProductService productService,
NotificationConfig notificationConfig,
Expand Down Expand Up @@ -162,8 +164,8 @@ public static NotificationUserToSend getNotificationUserToSend(NotificationsReso
notificationsResources.getOnboarding(),
notificationsResources.getToken(),
notificationsResources.getInstitution(),
onboardedProductResponse.getCreatedAt(),
onboardedProductResponse.getUpdatedAt(),
onboardedProductResponse.getCreatedAt() != null ? onboardedProductResponse.getCreatedAt().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) : null,
onboardedProductResponse.getUpdatedAt() != null ? onboardedProductResponse.getUpdatedAt().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) : null,
onboardedProductResponse.getStatus().toString(),
userDataResponse.getUserId(),
onboardedProductResponse.getRole(),
Expand Down Expand Up @@ -224,15 +226,15 @@ public static Map<String, String> onboardingEventFailureMap(Onboarding onboardin

public static Map<String, String> onboardingEventFailureMap(Onboarding onboarding, Exception e, String notificationEventTraceId) {
Map<String, String> propertiesMap = onboardingEventMap(onboarding);
Optional.ofNullable(notificationEventTraceId).ifPresent(value -> propertiesMap.put("notificationEventTraceId", value));
Optional.ofNullable(notificationEventTraceId).ifPresent(value -> propertiesMap.put(NOTIFICATION_EVENT_STRING, value));
Optional.ofNullable(e).ifPresent(value -> propertiesMap.put("error", Arrays.toString(e.getStackTrace())));
return propertiesMap;
}

public static Map<String, String> notificationEventMap(NotificationToSend notificationToSend, String topic, String notificationEventTraceId) {
Map<String, String> propertiesMap = new HashMap<>();
Optional.ofNullable(topic).ifPresent(value -> propertiesMap.put("topic", value));
Optional.ofNullable(notificationEventTraceId).ifPresent(value -> propertiesMap.put("notificationEventTraceId", value));
Optional.ofNullable(notificationEventTraceId).ifPresent(value -> propertiesMap.put(NOTIFICATION_EVENT_STRING, value));
Optional.ofNullable(notificationToSend.getId()).ifPresent(value -> propertiesMap.put("id", value));
Optional.ofNullable(notificationToSend.getInternalIstitutionID()).ifPresent(value -> propertiesMap.put("internalIstitutionID", value));
Optional.ofNullable(notificationToSend.getInstitutionId()).ifPresent(value -> propertiesMap.put("institutionId", value));
Expand Down Expand Up @@ -279,7 +281,7 @@ public static Map<String, String> notificationEventMap(NotificationToSend notifi
public static Map<String, String> notificationUserEventMap(NotificationUserToSend notificationUserToSend, String topic, String notificationEventTraceId) {
Map<String, String> propertiesMap = new HashMap<>();
Optional.ofNullable(topic).ifPresent(value -> propertiesMap.put("topic", value));
Optional.ofNullable(notificationEventTraceId).ifPresent(value -> propertiesMap.put("notificationEventTraceId", value));
Optional.ofNullable(notificationEventTraceId).ifPresent(value -> propertiesMap.put(NOTIFICATION_EVENT_STRING, value));
Optional.ofNullable(notificationUserToSend.getId()).ifPresent(value -> propertiesMap.put("id", value));
Optional.ofNullable(notificationUserToSend.getInstitutionId()).ifPresent(value -> propertiesMap.put("institutionId", value));
Optional.ofNullable(notificationUserToSend.getProduct()).ifPresent(value -> propertiesMap.put("product", value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public NotificationUserToSend buildUserNotificationToSend(
notificationUserToSend.setProduct(notification.getProduct());
notificationUserToSend.setOnboardingTokenId(notification.getOnboardingTokenId());
notificationUserToSend.setCreatedAt(createdAt.endsWith("Z") ? createdAt : createdAt + "Z");
notificationUserToSend.setUpdatedAt(updatedAt.endsWith("Z") ? createdAt : createdAt + "Z");
notificationUserToSend.setUpdatedAt(updatedAt.endsWith("Z") ? updatedAt : updatedAt + "Z");
QueueUserEvent queueUserEvent =
switch (status) {
case "DELETE" -> QueueUserEvent.DELETE_USER;
Expand Down
Loading

0 comments on commit 3000bf0

Please sign in to comment.