Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
update src/main/java/org/isf/menu/rest/UserController.java
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudFonzam committed Nov 14, 2023
1 parent ea38ded commit 9c84c40
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/main/java/org/isf/menu/rest/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public ResponseEntity<UserDTO> getUserByName(@PathVariable("username") String us
}

/**
* Create a new {@link User}.
* Creates a new {@link User}.
* @param userDTO - the {@link User} to insert
* @return {@code true} if the user has been inserted, {@code false} otherwise.
* @throws OHServiceException
Expand All @@ -171,7 +171,7 @@ public ResponseEntity<Boolean> newUser(@Valid @RequestBody UserDTO userDTO) thro
}

/**
* Update an existing {@link User}.
* Updates an existing {@link User}.
* @param userDTO - the {@link User} to update
* @param updatePassword - indicates if it is the password that need to be updated
* @return {@code true} if the user has been updated, {@code false} otherwise.
Expand Down Expand Up @@ -199,7 +199,7 @@ public ResponseEntity<Boolean> updateUser(
}

/**
* Delete an existing {@link User}.
* Deletes an existing {@link User}.
* @param username - the name of the {@link User} to delete
* @return {@code true} if the user has been deleted, {@code false} otherwise.
*/
Expand Down Expand Up @@ -236,7 +236,7 @@ public ResponseEntity<List<UserGroupDTO>> getUserGroup() throws OHServiceExcepti
}

/**
* Replace the {@link UserGroup} rights.
* Replaces the {@link UserGroup} rights.
* @param code - the {@link UserGroup}'s code
* @param menusDTO - the list of {@link UserMenuItem}s
* @return {@code true} if the menu has been replaced, {@code false} otherwise.
Expand All @@ -256,7 +256,7 @@ public ResponseEntity<Boolean> setGroupMenu(
}

/**
* Delete a {@link UserGroup}.
* Deletes a {@link UserGroup}.
* @param code - the code of the {@link UserGroup} to delete
* @return {@code true} if the group has been deleted, {@code false} otherwise.
*/
Expand All @@ -272,7 +272,7 @@ public ResponseEntity<Boolean> deleteGroup(@PathVariable("group_code") String co
}

/**
* Create a new {@link UserGroup} with a minimum set of rights.
* Creates a new {@link UserGroup} with a minimum set of rights.
* @param aGroup - the {@link UserGroup} to insert
* @return {@code true} if the group has been inserted, {@code false} otherwise.
*/
Expand All @@ -287,7 +287,7 @@ public ResponseEntity<Boolean> newUserGroup(@Valid @RequestBody UserGroupDTO aGr
}

/**
* Update an existing {@link UserGroup}.
* Updates an existing {@link UserGroup}.
* @param aGroup - the {@link UserGroup} to update
* @return {@code true} if the group has been updated, {@code false} otherwise.
*/
Expand All @@ -314,7 +314,7 @@ private UserGroup loadUserGroup(String code) throws OHServiceException {
}

/**
* Retrieve all permissions of the current logged-in user. If user not found,
* Retrieves all permissions of the current logged-in user. If user not found,
* an empty list of permissions is returned.
*
* @return list of permissions {@link Permission}
Expand All @@ -338,7 +338,7 @@ public ResponseEntity<List<LitePermissionDTO>> retrievePermissionsByCurrentLogge
}

/**
* Retrieve profile of the current logged in user. If user not found,
* Retrieves profile of the current logged in user. If user not found,
* an empty list of permissions is returned
*
* @return list of permissions {@link Permission}
Expand All @@ -364,7 +364,7 @@ public ResponseEntity<UserProfileDTO> retrieveProfileByCurrentLoggedInUser() thr


/**
* Retrieve all permissions of the username passed as path variable. If user not
* Retrieves all permissions of the username passed as path variable. If user not
* found, an empty list of permissions is returned.
*
* @return list of permissions {@link Permission}
Expand All @@ -383,7 +383,7 @@ public ResponseEntity<List<LitePermissionDTO>> retrievePermissionsByUsername(@Pa
}

/**
* Retrieve all userSetting of the current user.
* Retrieves all userSetting of the current user.
*
* @return list of userSetting {@link UserSettingDTO}.
* @throws OHServiceException
Expand All @@ -394,8 +394,8 @@ public ResponseEntity<List<UserSettingDTO>> getUserSettings() throws OHServiceEx
String userName = SecurityContextHolder.getContext().getAuthentication().getName();
List<UserSetting> userSettings = userSettingManager.getUserSettingByUserName(userName);
if (userSettings == null || userSettings.isEmpty()) {
LOGGER.info("No settings for the current user {}", userName);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null);
LOGGER.info("No settings for the current user {}", userName);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null);
}
List<UserSettingDTO> userSettingsDTO = userSettingMapper.map2DTOList(userSettings);
LOGGER.info("Found {} user settings", userSettingsDTO);
Expand Down Expand Up @@ -423,15 +423,15 @@ public ResponseEntity<UserSettingDTO> newUserSettings(@Valid @RequestBody UserSe
userSetting.setUser(userName);
UserSetting created = userSettingManager.newUserSetting(userSetting);
if (created == null) {
LOGGER.info("UserSetting is not created!");
throw new OHAPIException(new OHExceptionMessage("UserSetting not created."));
LOGGER.info("UserSetting is not created!");
throw new OHAPIException(new OHExceptionMessage("UserSetting not created."));
}
LOGGER.info("UserSetting successfully created!");
return ResponseEntity.status(HttpStatus.CREATED).body(userSettingMapper.map2DTO(created));
}

/**
* Update an existing {@link UserSettingDTO}.
* Updates an existing {@link UserSettingDTO}.
*
* @param userSettingDTO - the {@link UserSettingDTO} to update.
* @param id - id of {@link UserSetting} .
Expand All @@ -445,7 +445,7 @@ public ResponseEntity<UserSettingDTO> updateUserSettings(@PathVariable(name = "i
String userName = userSettingDTO.getUser();
final String ADMIN = "admin";
if (userSettingDTO.getId() != 0 && userSettingDTO.getId() != id) {
throw new OHAPIException(new OHExceptionMessage("UserSetting not found."));
throw new OHAPIException(new OHExceptionMessage("UserSetting not found."));
}
if (!userName.equals(SecurityContextHolder.getContext().getAuthentication().getName())
&& !SecurityContextHolder.getContext().getAuthentication().getName().equals(ADMIN)) {
Expand All @@ -454,22 +454,22 @@ public ResponseEntity<UserSettingDTO> updateUserSettings(@PathVariable(name = "i
UserSetting userSetting = userSettingManager.getUserSettingById(id);
UserSetting updated;
if (userSetting == null) {
LOGGER.info("No user settings with id {}", id);
throw new OHAPIException(new OHExceptionMessage("UserSetting doesn't exist."));
LOGGER.info("No user settings with id {}", id);
throw new OHAPIException(new OHExceptionMessage("UserSetting doesn't exist."));
}

UserSetting uSetting = userSettingMapper.map2Model(userSettingDTO);
updated = userSettingManager.updateUserSetting(uSetting);
if (updated == null) {
LOGGER.info("UserSetting is not updated!");
throw new OHAPIException(new OHExceptionMessage("UserSetting not updated."));
LOGGER.info("UserSetting is not updated!");
throw new OHAPIException(new OHExceptionMessage("UserSetting not updated."));
}
LOGGER.info("UserSetting successfully updated!");
return ResponseEntity.ok(userSettingMapper.map2DTO(updated));
}

/**
* Retrieve an existing {@link UserSettingDTO} by id.
* Retrieves an existing {@link UserSettingDTO} by id.
*
* @param id - id of userSetting {@link UserSetting} .
* @return {@link UserSettingDTO} if the UserSetting exist , null otherwise.
Expand All @@ -480,14 +480,14 @@ public ResponseEntity<UserSettingDTO> getUserSettingById(@PathVariable(name = "i
LOGGER.info("Retrieve the userSetting By id {}:", id);
UserSetting userSetting = userSettingManager.getUserSettingById(id);
if (userSetting == null) {
LOGGER.info("No user settings with id {}", id);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null);
LOGGER.info("No user settings with id {}", id);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null);
}
return ResponseEntity.ok(userSettingMapper.map2DTO(userSetting));
}

/**
* Retrieve an existing {@link UserSettingDTO} by user.
* Retrieves an existing {@link UserSettingDTO} by user.
*
* @param userName - the name of user.
* @param configName - the name of the userSetting {@link UserSetting} .
Expand All @@ -500,19 +500,19 @@ public ResponseEntity<UserSettingDTO> getUserSettingByUser(@PathVariable(name =
LOGGER.info("Retrieve the userSetting By user {} and configName {}:", userName, configName);
List<UserSetting> userSettings = userSettingManager.getUserSettingByUserName(userName);
if (userSettings == null || userSettings.isEmpty()) {
LOGGER.info("UserSetting not found!");
throw new OHAPIException(new OHExceptionMessage("UserSetting not found."));
LOGGER.info("UserSetting not found!");
throw new OHAPIException(new OHExceptionMessage("UserSetting not found."));
}
UserSetting userSetting = userSettingManager.getUserSettingByUserNameConfigName(userName, configName);
if (userSetting == null) {
LOGGER.info("No user settings for the user {}", userName);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null);
LOGGER.info("No user settings for the user {}", userName);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null);
}
return ResponseEntity.ok(userSettingMapper.map2DTO(userSetting));
}

/**
* Delete a {@link UserSetting}.
* Deletes a {@link UserSetting}.
*
* @param id - the id of the userSetting {@link UserSetting} to delete.
* @return {@code true} if the userSetting has been deleted, {@code false} otherwise.
Expand All @@ -521,8 +521,8 @@ public ResponseEntity<UserSettingDTO> getUserSettingByUser(@PathVariable(name =
public ResponseEntity<Boolean> deleteUserSetting(@PathVariable(name = "id") int id) throws OHServiceException {
UserSetting userSetting = userSettingManager.getUserSettingById(id);
if (userSetting == null) {
LOGGER.info("No user settings with id {}", id);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null);
LOGGER.info("No user settings with id {}", id);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null);
}
return ResponseEntity.ok(userSettingManager.deleteUserSetting(userSetting));
}
Expand Down

0 comments on commit 9c84c40

Please sign in to comment.