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