diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java index 9912cb34..6320a305 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java @@ -69,8 +69,7 @@ public enum AppErrorCodeEnum { PROFILE_NOT_FOUND("ATMLM_4000058", "Non esiste un profilo con l'id indicato", CONSTRAINT_VIOLATION), PROFILE_OR_USER_NOT_FOUND("ATMLM_4000059","Utente o profilo non trovato", CONSTRAINT_VIOLATION), NO_ASSOCIATION_FOUND("ATMLM_4000060","Nessuna associazione trovata", CONSTRAINT_VIOLATION), - ALL_FIELDS_ARE_BLANK("ATMLM_4000061", "Tutti i campi sono vuoti", BLANK_FIELDS), - USERS_ALREADY_ACCESSED("ATMLM_4000062", "Impossibile registrare l'utente come primo accesso: almeno un utente è già presente nel database", NOT_FIRST_ACCESS); + ALL_FIELDS_ARE_BLANK("ATMLM_4000061", "Tutti i campi sono vuoti", BLANK_FIELDS); private final String errorCode; private final String errorMessage; private final AppErrorType type; diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorType.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorType.java index f5428faa..61a5776f 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorType.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorType.java @@ -26,6 +26,5 @@ public enum AppErrorType { CANNOT_ASSOCIATE, NOT_EXISTING_USER_ID, NOT_EXISTING_USER_PROFILE, CANNOT_REPLACE_ASSOCIATION, - BLANK_FIELDS, - NOT_FIRST_ACCESS + BLANK_FIELDS } \ No newline at end of file diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/UserServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/UserServiceImpl.java index 518269e4..836804d9 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/UserServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/UserServiceImpl.java @@ -134,17 +134,19 @@ public Uni checkFirstAccess(String userId) { return countUsers() .onItem() .transformToUni(count -> { - if (count != 0){ - throw new AtmLayerException("Sono già presenti degli utenti nel sistema", Response.Status.BAD_REQUEST, AppErrorCodeEnum.USERS_ALREADY_ACCESSED); - } - UserInsertionWithProfilesDTO userInsertionWithProfilesDTO = new UserInsertionWithProfilesDTO(); - List profile = new ArrayList<>(); - profile.add(5); - userInsertionWithProfilesDTO.setUserId(userId); - userInsertionWithProfilesDTO.setProfileIds(profile); - return insertUserWithProfiles(userInsertionWithProfilesDTO) - .onItem() - .transformToUni(list -> Uni.createFrom().voidItem()); + if (count == 0) { + UserInsertionWithProfilesDTO userInsertionWithProfilesDTO = new UserInsertionWithProfilesDTO(); + List profile = new ArrayList<>(); + profile.add(5); + userInsertionWithProfilesDTO.setUserId(userId); + userInsertionWithProfilesDTO.setProfileIds(profile); + userInsertionWithProfilesDTO.setName(""); + userInsertionWithProfilesDTO.setSurname(""); + return insertUserWithProfiles(userInsertionWithProfilesDTO) + .onItem() + .transformToUni(list -> Uni.createFrom().voidItem()); + } + return Uni.createFrom().voidItem(); }); } } diff --git a/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/UserServiceImplTest.java b/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/UserServiceImplTest.java index ad61311f..8d33ff29 100644 --- a/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/UserServiceImplTest.java +++ b/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/UserServiceImplTest.java @@ -342,7 +342,8 @@ void testCheckFirstAccessWhenUsersExist() { userServiceImpl.checkFirstAccess(userId) .subscribe() .withSubscriber(UniAssertSubscriber.create()) - .assertFailedWith(AtmLayerException.class); + .assertCompleted() + .assertItem(null); verify(userRepository, times(1)).count(); verify(userProfilesService, never()).insertUserProfiles(any(UserProfilesInsertionDTO.class));