minor fix

This commit is contained in:
Massimiliano Assante 2022-09-16 11:46:41 +02:00
parent cfcbec3bf8
commit 195d8f1f65
1 changed files with 11 additions and 13 deletions

View File

@ -149,10 +149,8 @@ public class Notifications {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
/** /**
* Return whether the notifications for this user are enabled or not * Return whether the notifications for this user are enabled or not
* @param from must be greater or equal to 1, range[0, infinity] * @param username the username you want to check
* @param quantity quantity must be greater or equal to 0 * @return true if the notification for the user are disabled (Catalogue and Workspace ones)
* @return notifications up to quantity
* @throws ValidationException
*/ */
@StatusCodes ({ @StatusCodes ({
@ResponseCode ( code = 200, condition = "Users with silenced notifications are reported in the 'result' field of the returned object"), @ResponseCode ( code = 200, condition = "Users with silenced notifications are reported in the 'result' field of the returned object"),
@ -160,15 +158,15 @@ public class Notifications {
}) })
@AuthorizationControl(allowedRoles={INFRASTRUCTURE_MANAGER_ROLE}, exception=AuthException.class) @AuthorizationControl(allowedRoles={INFRASTRUCTURE_MANAGER_ROLE}, exception=AuthException.class)
public Response isUserDisabled( public Response isUserDisabled(
@QueryParam("usernameToCheck") @NotNull(message="username cannot be null") @Size(min=2, message="username cannot be empty") @QueryParam("username") @NotNull(message="username cannot be null") @Size(min=2, message="username cannot be empty")
String usernameToCheck) throws ValidationException{ String username) throws ValidationException{
ResponseBean responseBean = new ResponseBean(); ResponseBean responseBean = new ResponseBean();
Status status = Status.OK; Status status = Status.OK;
try{ try{
Boolean userDisabled= !isNotificationEnabled(usernameToCheck); Boolean userDisabled= !isNotificationEnabled(username);
responseBean.setResult(userDisabled); responseBean.setResult(userDisabled);
responseBean.setSuccess(true); responseBean.setSuccess(true);
logger.debug("are User " + usernameToCheck + " Notifications Disabled?"+userDisabled); logger.debug("are User " + username + " Notifications Disabled?"+userDisabled);
}catch(Exception e){ }catch(Exception e){
logger.error("Unable to read whether the notifications for this user are enabled or not.", e); logger.error("Unable to read whether the notifications for this user are enabled or not.", e);
responseBean.setMessage(e.getMessage()); responseBean.setMessage(e.getMessage());
@ -209,10 +207,10 @@ public class Notifications {
try{ try{
String opExecutor = caller.getClient().getId(); String opExecutor = caller.getClient().getId();
Boolean result = setUserNotificationsOnOff(username, disable, opExecutor); Boolean result = setUserNotificationsOnOff(username, disable, opExecutor);
String toReturn = "Notifications have been set "; String toReturn = "Notifications have been set";
if (result) { if (result) {
toReturn += disable ? " Off ": " On "; toReturn += disable ? " OFF ": " ON ";
toReturn += "for " + username; toReturn += "for username=" + username;
} }
responseBean.setSuccess(true); responseBean.setSuccess(true);
responseBean.setResult(toReturn); responseBean.setResult(toReturn);
@ -258,8 +256,8 @@ public class Notifications {
result = entries.delete(username); result = entries.delete(username);
} }
try { try {
return result.get(); return result.getStatus().isSuccess();
} catch (InterruptedException | ExecutionException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;