diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/AslNewsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/AslNewsManager.java index 11cdc56..066f8fb 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/AslNewsManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/AslNewsManager.java @@ -1,23 +1,14 @@ package org.gcube.applicationsupportlayer.social; import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.UUID; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.common.core.contexts.GHNContext; -import org.gcube.common.core.informationsystem.ISException; -import org.gcube.common.core.informationsystem.client.AtomicCondition; import org.gcube.common.core.informationsystem.client.ISClient; import org.gcube.common.core.informationsystem.client.XMLResult; -import org.gcube.common.core.informationsystem.client.ISClient.ISMalformedQueryException; -import org.gcube.common.core.informationsystem.client.ISClient.ISUnsupportedQueryException; import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery; -import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericResourceQuery; -import org.gcube.common.core.resources.GCUBEGenericResource; -import org.gcube.common.core.scope.GCUBEScope; -import org.gcube.common.core.utils.logging.GCUBEClientLog; import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl; import org.gcube.portal.databook.server.DatabookStore; import org.gcube.portal.databook.shared.Application; @@ -35,17 +26,14 @@ import org.gcube.portlets.user.homelibrary.home.data.application.ApplicationData */ public class AslNewsManager extends SocialPortalBridge implements NewsManager { - GCUBEClientLog log = new GCUBEClientLog(AslNewsManager.class); - - private ASLSession session; private Application application; /** * - * @param session the ASLSession instance + * @param aslSession the ASLSession instance * @param applicationClass your servlet class name will be used ad unique identifier for your application */ public AslNewsManager(ASLSession session, Class applicationClass) { - this.session = session; + super(session); this.application = getProfileFromInfrastrucure(applicationClass); } /** @@ -65,7 +53,7 @@ public class AslNewsManager extends SocialPortalBridge implements NewsManager { " eq '" + applicationClass.getName() + "'" + "return $profile"); - List appProfile = client.execute(query, session.getScope().getInfrastructure()); + List appProfile = client.execute(query, aslSession.getScope().getInfrastructure()); if (appProfile == null || appProfile.size() == 0) throw new ApplicationDataNotFoundException("Your application is not registered in the infrastructure"); else { @@ -81,7 +69,7 @@ public class AslNewsManager extends SocialPortalBridge implements NewsManager { if (currValue != null && currValue.size() > 0) { toReturn.setDescription(currValue.get(0)); } - else log.warn("No Description exists for " + toReturn.getName()); + else _log.warn("No Description exists for " + toReturn.getName()); currValue = node.evaluate("/Resource/Profile/Body/AppId/text()"); if (currValue != null && currValue.size() > 0) { @@ -98,7 +86,7 @@ public class AslNewsManager extends SocialPortalBridge implements NewsManager { } } catch (Exception e) { - log.error("Error while trying to fetch application profile from the infrastructure"); + _log.error("Error while trying to fetch application profile from the infrastructure"); e.printStackTrace(); return null; } @@ -116,7 +104,7 @@ public class AslNewsManager extends SocialPortalBridge implements NewsManager { FeedType.PUBLISH, application.getName(), new Date(), - getScopeByOrganizationId(""+session.getGroupId()), + getScopeByOrganizationId(""+aslSession.getGroupId()), "", "", descToAdd, @@ -128,7 +116,7 @@ public class AslNewsManager extends SocialPortalBridge implements NewsManager { "linkDescription", "linkHost"); - return store.saveAppFeed(toShare); + return getStoreInstance().saveAppFeed(toShare); } /** * {@inheritDoc} diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/AslNotificationManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/AslNotificationManager.java index 60e3cd4..f12ff49 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/AslNotificationManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/AslNotificationManager.java @@ -1,9 +1,6 @@ package org.gcube.applicationsupportlayer.social; import org.gcube.application.framework.core.session.ASLSession; -import org.gcube.common.core.utils.logging.GCUBEClientLog; -import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl; -import org.gcube.portal.databook.server.DatabookStore; import org.gcube.portal.databook.shared.Comment; import org.gcube.portal.databook.shared.Feed; import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceFolder; @@ -17,12 +14,9 @@ import org.gcube.portlets.user.homelibrary.home.workspace.sharing.WorkspaceMessa * use to notify users from within your application */ public class AslNotificationManager extends SocialPortalBridge implements NotificationManager { - GCUBEClientLog log = new GCUBEClientLog(AslNotificationManager.class); - private ASLSession session; - public AslNotificationManager(ASLSession session) { - this.session = session; + super(session); } /** * {@inheritDoc} diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java b/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java index 6f95049..84a17ee 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java @@ -1,5 +1,6 @@ package org.gcube.applicationsupportlayer.social; +import org.gcube.application.framework.core.session.ASLSession; import org.gcube.common.core.utils.logging.GCUBEClientLog; import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl; import org.gcube.portal.databook.server.DatabookStore; @@ -13,14 +14,23 @@ import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager; * use to notify users from within your application */ public abstract class SocialPortalBridge { - - private GCUBEClientLog _log = new GCUBEClientLog(SocialPortalBridge.class); - protected DatabookStore store; - - public SocialPortalBridge() { - store = new DBCassandraAstyanaxImpl(); + + protected static GCUBEClientLog _log = new GCUBEClientLog(SocialPortalBridge.class); + protected ASLSession aslSession; + //unique instance + private static DatabookStore store; + + public SocialPortalBridge(ASLSession session) { + this.aslSession = session; } - + + public static synchronized DatabookStore getStoreInstance() { + if (store == null) { + store = new DBCassandraAstyanaxImpl(); + } + return store; + } + String getScopeByOrganizationId(String vreid) { GroupManager gm = new LiferayGroupManager(); try {