Skip to content

Commit

Permalink
feat: Add retry when find users on User Registry (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuraf authored Sep 26, 2024
1 parent 70d46c7 commit 9aa3fde
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
import org.jboss.resteasy.reactive.ResponseStatus;
import org.openapi.quarkus.user_registry_json.model.Problem;
import org.owasp.encoder.Encode;

import java.util.List;

Expand Down Expand Up @@ -303,8 +302,6 @@ public Uni<Void> updateUserProductStatus(@PathParam("id") String userId,
public Uni<Response> createOrUpdateByUserId(@PathParam("userId") String userId,
@Valid AddUserRoleDto userDto,
@Context SecurityContext ctx) {

log.info("[createOrUpdateByFiscalCode] Received body: {}", Encode.forJava(userDto.toString()));
return readUserIdFromToken(ctx)
.onItem().transformToUni(loggedUser -> userService.createOrUpdateUserByUserId(userDto, userId, loggedUser))
.onItem().ifNotNull().transform(ignore -> Response.status(HttpStatus.SC_CREATED).build())
Expand All @@ -331,7 +328,6 @@ public Uni<Response> createOrUpdateByUserId(@PathParam("userId") String userId,
@Produces(MediaType.APPLICATION_JSON)
public Uni<Response> createOrUpdateByFiscalCode(@Valid CreateUserDto userDto,
@Context SecurityContext ctx) {
log.info("[createOrUpdateByFiscalCode] Received body: {}", Encode.forJava(userDto.toString()));
return readUserIdFromToken(ctx)
.onItem().transformToUni(loggedUser -> userService.createOrUpdateUserByFiscalCode(userDto, loggedUser))
.map(response -> Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ public Uni<UserInfo> retrieveBindings(String institutionId, String userId, Strin
@Override
public Uni<CreateOrUpdateUserByFiscalCodeResponse> createOrUpdateUserByFiscalCode(CreateUserDto userDto, LoggedUser loggedUser) {
return userRegistryService.searchUsingPOST(USERS_WORKS_FIELD_LIST, new UserSearchDto(userDto.getUser().getFiscalCode().trim()))
.onFailure(UserUtils::isUserNotFoundExceptionOnUserRegistry).retry().atMost(2)
.onFailure(UserUtils::isUserNotFoundExceptionOnUserRegistry).recoverWithUni(throwable -> Uni.createFrom().failure(new ResourceNotFoundException(throwable.getMessage())))
.onItem().transformToUni(userResource -> updateUserOnUserRegistryAndUserInstitutionByFiscalCode(userResource, userDto,loggedUser))
.onFailure(ResourceNotFoundException.class).recoverWithUni(throwable -> createUserOnUserRegistryAndUserInstitution(userDto,loggedUser))
Expand Down Expand Up @@ -444,6 +445,7 @@ private Uni<CreateOrUpdateUserByFiscalCodeResponse> createUserOnUserRegistryAndU
@Override
public Uni<String> createOrUpdateUserByUserId(AddUserRoleDto userDto, String userId, LoggedUser loggedUser) {
return userRegistryService.findByIdUsingGET(USERS_FIELD_LIST_WITHOUT_FISCAL_CODE, userId)
.onFailure(UserUtils::isUserNotFoundExceptionOnUserRegistry).retry().atMost(2)
.onFailure(UserUtils::isUserNotFoundExceptionOnUserRegistry).recoverWithUni(throwable -> Uni.createFrom().failure(new ResourceNotFoundException(throwable.getMessage())))
.onItem().transformToUni(userResource -> updateUserInstitutionByUserId(userResource, userDto, loggedUser))
.onFailure().invoke(exception -> log.error("Error during retrieve user from userRegistry: {} ", exception.getMessage(), exception));
Expand Down

0 comments on commit 9aa3fde

Please sign in to comment.