removed memcached
This commit is contained in:
parent
0c4c8d61d1
commit
522e04d50e
5
pom.xml
5
pom.xml
|
@ -79,11 +79,6 @@
|
||||||
<artifactId>ehcache</artifactId>
|
<artifactId>ehcache</artifactId>
|
||||||
<version>2.10.0</version>
|
<version>2.10.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>net.spy</groupId>
|
|
||||||
<artifactId>spymemcached</artifactId>
|
|
||||||
<version>2.12.3</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>authorization-control-library</artifactId>
|
<artifactId>authorization-control-library</artifactId>
|
||||||
|
|
|
@ -188,97 +188,98 @@ public class Notifications {
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Set user notification enabled or disabled
|
// * Set user notification enabled or disabled
|
||||||
* @param disable true if you want to disable the notifications for this user, false if you want to enable them
|
// * @param disable true if you want to disable the notifications for this user, false if you want to enable them
|
||||||
* @return the result of the operation
|
// * @return the result of the operation
|
||||||
* @throws ValidationException
|
// * @throws ValidationException
|
||||||
*/
|
// */
|
||||||
@POST
|
// @POST
|
||||||
@Path("set-user-notifications/")
|
// @Path("set-user-notifications/")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
// @Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
// @Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
// @StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Notification set Off or On correctly executed"),
|
// @ResponseCode ( code = 200, condition = "Notification set Off or On correctly executed"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
// @ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
// })
|
||||||
@AuthorizationControl(allowedRoles={INFRASTRUCTURE_MANAGER_ROLE}, exception=AuthException.class)
|
// @AuthorizationControl(allowedRoles={INFRASTRUCTURE_MANAGER_ROLE}, exception=AuthException.class)
|
||||||
public Response setUserNotifications(
|
// public Response setUserNotifications(
|
||||||
@NotNull(message="input is missing")
|
// @NotNull(message="input is missing")
|
||||||
@Valid
|
// @Valid
|
||||||
UserSetNotificationBean setting) throws ValidationException{
|
// UserSetNotificationBean setting) throws ValidationException{
|
||||||
|
//
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
// Caller caller = AuthorizationProvider.instance.get();
|
||||||
String context = ScopeProvider.instance.get();
|
// String context = ScopeProvider.instance.get();
|
||||||
ResponseBean responseBean = new ResponseBean();
|
// ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
// Status status = Status.OK;
|
||||||
|
//
|
||||||
|
//
|
||||||
try{
|
// try{
|
||||||
String opExecutor = caller.getClient().getId();
|
// String opExecutor = caller.getClient().getId();
|
||||||
Boolean result = setUserNotificationsOnOff(setting.getUsername(), setting.isDisableNotification(), opExecutor);
|
// Boolean result = setUserNotificationsOnOff(setting.getUsername(), setting.isDisableNotification(), opExecutor);
|
||||||
String toReturn = "Could not set notifications";
|
// String toReturn = "Could not set notifications";
|
||||||
if (result) {
|
// if (result) {
|
||||||
toReturn = "Notifications have been set";
|
// toReturn = "Notifications have been set";
|
||||||
toReturn += setting.isDisableNotification() ? " OFF (for 29 days unless re-enabled manually) ": " ON ";
|
// toReturn += setting.isDisableNotification() ? " OFF (for 29 days unless re-enabled manually) ": " ON ";
|
||||||
toReturn += "for username=" + setting.getUsername();
|
// toReturn += "for username=" + setting.getUsername();
|
||||||
}
|
// }
|
||||||
responseBean.setSuccess(true);
|
// responseBean.setSuccess(true);
|
||||||
responseBean.setResult(toReturn);
|
// responseBean.setResult(toReturn);
|
||||||
|
//
|
||||||
} catch(Exception e){
|
// } catch(Exception e){
|
||||||
logger.error("Unable to set user notification", e);
|
// logger.error("Unable to set user notification", e);
|
||||||
responseBean.setSuccess(false);
|
// responseBean.setSuccess(false);
|
||||||
responseBean.setMessage(e.getMessage());
|
// responseBean.setMessage(e.getMessage());
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
// status = Status.INTERNAL_SERVER_ERROR;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
return Response.status(status).entity(responseBean).build();
|
// return Response.status(status).entity(responseBean).build();
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @deprecated
|
||||||
* @param usernameToCheck
|
* @param usernameToCheck
|
||||||
* @return true if notification are enabled for this user
|
* @return true if notification are enabled for this user
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private boolean isNotificationEnabled(String usernameToCheck) throws IOException {
|
private boolean isNotificationEnabled(String usernameToCheck) throws IOException {
|
||||||
MemcachedClient entries = new DistributedCacheClient().getMemcachedClient();
|
// MemcachedClient entries = new DistributedCacheClient().getMemcachedClient();
|
||||||
String key = SocialUtils.DISABLED_USERS_NOTIFICATIONS_NAMESPACE+usernameToCheck;
|
// String key = SocialUtils.DISABLED_USERS_NOTIFICATIONS_NAMESPACE+usernameToCheck;
|
||||||
Boolean userEnabled = false;
|
// Boolean userEnabled = false;
|
||||||
if(entries.get(key) == null)
|
// if(entries.get(key) == null)
|
||||||
userEnabled = true;
|
// userEnabled = true;
|
||||||
entries.getConnection().shutdown();
|
// entries.getConnection().shutdown();
|
||||||
return userEnabled;
|
// return userEnabled;
|
||||||
}
|
return true;
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param username the user you want to disable or enable notifications (max 29 days)
|
|
||||||
* @param callerId the username or clientid of the operation executor
|
|
||||||
* @param disable true if you want to disable the notifications for this user
|
|
||||||
* @return true if the operation was performed
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
private Boolean setUserNotificationsOnOff(String username, boolean disable, String callerId) throws IOException {
|
|
||||||
MemcachedClient entries = new DistributedCacheClient().getMemcachedClient();
|
|
||||||
String key = SocialUtils.DISABLED_USERS_NOTIFICATIONS_NAMESPACE+username;
|
|
||||||
OperationFuture<Boolean> result = null;
|
|
||||||
if (disable) {
|
|
||||||
result = entries.set(key, SocialUtils.CACHING_TIME_TO_EXPIRATION, "op.ex:" + callerId); //operator executor is who silenced the user
|
|
||||||
} else {
|
|
||||||
result = entries.delete(key);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
boolean res = result.getStatus().isSuccess();
|
|
||||||
entries.getConnection().shutdown();
|
|
||||||
return res;
|
|
||||||
} catch (Exception e) {
|
|
||||||
entries.getConnection().shutdown();
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
// /**
|
||||||
|
// *
|
||||||
|
// * @param username the user you want to disable or enable notifications (max 29 days)
|
||||||
|
// * @param callerId the username or clientid of the operation executor
|
||||||
|
// * @param disable true if you want to disable the notifications for this user
|
||||||
|
// * @return true if the operation was performed
|
||||||
|
// * @throws IOException
|
||||||
|
// */
|
||||||
|
// private Boolean setUserNotificationsOnOff(String username, boolean disable, String callerId) throws IOException {
|
||||||
|
// MemcachedClient entries = new DistributedCacheClient().getMemcachedClient();
|
||||||
|
// String key = SocialUtils.DISABLED_USERS_NOTIFICATIONS_NAMESPACE+username;
|
||||||
|
// OperationFuture<Boolean> result = null;
|
||||||
|
// if (disable) {
|
||||||
|
// result = entries.set(key, SocialUtils.CACHING_TIME_TO_EXPIRATION, "op.ex:" + callerId); //operator executor is who silenced the user
|
||||||
|
// } else {
|
||||||
|
// result = entries.delete(key);
|
||||||
|
// }
|
||||||
|
// try {
|
||||||
|
// boolean res = result.getStatus().isSuccess();
|
||||||
|
// entries.getConnection().shutdown();
|
||||||
|
// return res;
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// entries.getConnection().shutdown();
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a JOB notification to a given recipient
|
* Send a JOB notification to a given recipient
|
||||||
|
|
Loading…
Reference in New Issue