diff --git a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java index 8b78b08..e3d97a6 100644 --- a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java +++ b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java @@ -1,21 +1,14 @@ package org.gcube.portal.social.networking.ws.methods.v2; import java.io.IOException; -import java.net.URL; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; import java.util.List; -import java.util.Set; -import java.util.concurrent.ExecutionException; import javax.validation.Valid; import javax.validation.ValidationException; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; @@ -29,7 +22,6 @@ import javax.ws.rs.core.Response.Status; import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager; import org.gcube.applicationsupportlayer.social.NotificationsManager; -import org.gcube.applicationsupportlayer.social.ScopeBeanExt; import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite; import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser; import org.gcube.common.authorization.control.annotations.AuthorizationControl; @@ -39,7 +31,6 @@ import org.gcube.common.authorization.library.utils.Caller; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.impl.ScopeBean; import org.gcube.portal.databook.shared.Notification; -import org.gcube.portal.databook.shared.NotificationType; import org.gcube.portal.databook.shared.RunningJob; import org.gcube.portal.notifications.bean.GenericItemBean; import org.gcube.portal.notifications.thread.JobStatusNotificationThread; @@ -49,20 +40,15 @@ import org.gcube.portal.social.networking.liferay.ws.GroupManagerWSBuilder; import org.gcube.portal.social.networking.liferay.ws.LiferayJSONWsCredentials; import org.gcube.portal.social.networking.liferay.ws.UserManagerWSBuilder; import org.gcube.portal.social.networking.ws.ex.AuthException; -import org.gcube.portal.social.networking.ws.inputs.UserSetNotificationBean; import org.gcube.portal.social.networking.ws.mappers.CatalogueEventTypeMapper; import org.gcube.portal.social.networking.ws.mappers.JobMapper; import org.gcube.portal.social.networking.ws.mappers.WorkspaceItemMapper; import org.gcube.portal.social.networking.ws.outputs.ResponseBean; import org.gcube.portal.social.networking.ws.utils.CassandraConnection; -import org.gcube.portal.social.networking.ws.utils.DistributedCacheClient; import org.gcube.portal.social.networking.ws.utils.ErrorMessages; -import org.gcube.portal.social.networking.ws.utils.SocialUtils; import org.gcube.portal.social.networking.ws.utils.TokensUtils; import org.gcube.social_networking.socialnetworking.model.beans.JobNotificationBean; - import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEvent; -import org.gcube.social_networking.socialnetworking.model.beans.workspace.WorkspaceEvent; import org.gcube.social_networking.socialnetworking.model.beans.workspace.AddedItemEvent; import org.gcube.social_networking.socialnetworking.model.beans.workspace.DeletedItemEvent; import org.gcube.social_networking.socialnetworking.model.beans.workspace.FolderAddedUserEvent; @@ -73,24 +59,20 @@ import org.gcube.social_networking.socialnetworking.model.beans.workspace.Rename import org.gcube.social_networking.socialnetworking.model.beans.workspace.SharedFolderEvent; import org.gcube.social_networking.socialnetworking.model.beans.workspace.UnsharedFolderEvent; import org.gcube.social_networking.socialnetworking.model.beans.workspace.UpdatedItemEvent; +import org.gcube.social_networking.socialnetworking.model.beans.workspace.WorkspaceEvent; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.UserManager; -import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.mortbay.log.Log; import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.annotation.JsonProperty; import com.webcohesion.enunciate.metadata.rs.RequestHeader; import com.webcohesion.enunciate.metadata.rs.RequestHeaders; import com.webcohesion.enunciate.metadata.rs.ResponseCode; import com.webcohesion.enunciate.metadata.rs.StatusCodes; -import net.spy.memcached.MemcachedClient; -import net.spy.memcached.internal.OperationFuture; - /** * REST interface for the social networking library (notifications). */ diff --git a/src/main/java/org/gcube/portal/social/networking/ws/utils/DistributedCacheClient.java b/src/main/java/org/gcube/portal/social/networking/ws/utils/DistributedCacheClient.java deleted file mode 100644 index 38fb3b2..0000000 --- a/src/main/java/org/gcube/portal/social/networking/ws/utils/DistributedCacheClient.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.gcube.portal.social.networking.ws.utils; - -import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; -import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.List; - -import org.gcube.common.resources.gcore.ServiceEndpoint; -import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; -import org.gcube.common.resources.gcore.utils.Group; -import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.resources.discovery.client.api.DiscoveryClient; -import org.gcube.resources.discovery.client.queries.api.SimpleQuery; -import org.gcube.smartgears.ContextProvider; -import org.gcube.smartgears.context.application.ApplicationContext; -import org.slf4j.LoggerFactory; - -import net.spy.memcached.KetamaConnectionFactory; -import net.spy.memcached.MemcachedClient; - -/** - * @author Massimiliano Assante at ISTI-CNR - */ -public class DistributedCacheClient { - - // Logger - private static final org.slf4j.Logger logger = LoggerFactory.getLogger(DistributedCacheClient.class); - - private static final String MEMCACHED_RESOURCE_NAME = "Memcached"; - private static final String CATEGORY = "Database"; - - private MemcachedClient mClient; - - /** - * Build the singleton instance - */ - public DistributedCacheClient(){ - List addrs = discoverHostOfServiceEndpoint(); - try { - mClient = new MemcachedClient(new KetamaConnectionFactory(), addrs); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public MemcachedClient getMemcachedClient() { - return mClient; - } - - /** - * Retrieve endpoint resoruce from IS - * @return List of InetSocketAddresses - * @throws Exception - */ - private static List discoverHostOfServiceEndpoint(){ - - String currentScope = ScopeProvider.instance.get(); - ApplicationContext ctx = ContextProvider.get(); // get this info from SmartGears - String infrastructure = "/"+ctx.container().configuration().infrastructure(); - ScopeProvider.instance.set(infrastructure); - List toReturn = new ArrayList(); - try{ - SimpleQuery query = queryFor(ServiceEndpoint.class); - query.addCondition("$resource/Profile/Name/text() eq '"+ MEMCACHED_RESOURCE_NAME +"'"); - query.addCondition("$resource/Profile/Category/text() eq '"+ CATEGORY +"'"); - DiscoveryClient client = clientFor(ServiceEndpoint.class); - List ses = client.submit(query); - if (ses.isEmpty()) { - logger.error("There is no Memcached cluster having name: " + MEMCACHED_RESOURCE_NAME + " and Category " + CATEGORY + " on root context in this infrastructure: "); - return null; - } - for (ServiceEndpoint se : ses) { - Group aps = se.profile().accessPoints(); - for (AccessPoint ap : aps.asCollection()) { - String address = ap.address(); //e.g. socialnetworking-d-d4s.d4science.org:11211 - String[] splits = address.split(":"); - String hostname = splits[0]; - int port = Integer.parseInt(splits[1]); - toReturn.add(new InetSocketAddress(hostname, port)); - } - break; - } - } catch(Exception e){ - logger.error("Error while retrieving hosts for the Memcached cluster having name: " + MEMCACHED_RESOURCE_NAME + " and Category " + CATEGORY + " on root context"); - }finally{ - ScopeProvider.instance.set(currentScope); - } - ScopeProvider.instance.set(currentScope); - return toReturn; - } - -}