diff --git a/pom.xml b/pom.xml index 160981c..02ed4a7 100644 --- a/pom.xml +++ b/pom.xml @@ -103,9 +103,6 @@ fully.qualified.MainClass - - jar-with-dependencies - diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNewsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNewsManager.java index 2aa7eca..04904be 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNewsManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNewsManager.java @@ -4,24 +4,19 @@ import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Date; -import java.util.List; import java.util.UUID; import org.apache.commons.io.IOUtils; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.gcube.application.framework.core.session.ASLSession; -import org.gcube.applicationsupportlayer.social.ex.ApplicationProfileNotFoundException; import org.gcube.common.core.contexts.GHNContext; 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.queries.GCUBEGenericQuery; import org.gcube.common.core.informationsystem.client.queries.GCUBERuntimeResourceQuery; import org.gcube.common.core.resources.GCUBERuntimeResource; import org.gcube.common.core.scope.GCUBEScope; import org.gcube.common.core.utils.logging.GCUBEClientLog; -import org.gcube.portal.databook.shared.ApplicationProfile; import org.gcube.portal.databook.shared.Feed; import org.gcube.portal.databook.shared.FeedType; import org.gcube.portal.databook.shared.ImageType; @@ -36,102 +31,22 @@ import org.gcube.portal.databook.shared.PrivacyLevel; * use to share updates from within your applicationProfile, the update will be published in the Users News Feed belonging to the VRE your applicationProfile runs into */ public class ApplicationNewsManager extends SocialPortalBridge implements NewsManager { + static GCUBEClientLog _log = new GCUBEClientLog(ApplicationNewsManager.class); - private ApplicationProfile applicationProfile; /** * the FTP Server RuntimeResource coordinates */ private static String RUNTIME_RESOURCE_NAME = "SocialPortalStorage"; private static String CATEGORY_NAME = "FTPServer"; - /** * * @param aslSession the ASLSession instance - * @param portletClassName your servlet class name will be used ad unique identifier for your applicationProfile + * @param portletClassName your portlet class name will be used ad unique identifier for your applicationProfile */ public ApplicationNewsManager(ASLSession session, String portletClassName) { - super(session); - this.applicationProfile = getProfileFromInfrastrucure(portletClassName); + super(session, portletClassName); } - - public ApplicationProfile getApplicationProfile() { - return applicationProfile; - } - /** - * this method looks up the applicationProfile profile among the ones available in the infrastructure - * @param portletClassName your servlet class name will be used ad unique identifier for your applicationProfile - * @return the applicationProfile profile - */ - private ApplicationProfile getProfileFromInfrastrucure(String portletClassName) { - try { - ApplicationProfile toReturn = new ApplicationProfile(); - ISClient client = GHNContext.getImplementation(ISClient.class); - GCUBEGenericQuery query = client.getQuery(GCUBEGenericQuery.class); - - - query.setExpression("for $profile in collection('/db/Profiles/GenericResource')//Resource " + - "where $profile/Profile/SecondaryType/string() eq 'ApplicationProfile' and $profile/Profile/Body/AppId/string() " + - " eq '" + portletClassName + "'" + - "return $profile"); - - GCUBEScope scope = aslSession.getScope(); - - List appProfile = client.execute(query, scope.getInfrastructure()); - if (appProfile == null || appProfile.size() == 0) - throw new ApplicationProfileNotFoundException("Your applicationProfile is not registered in the infrastructure"); - else { - XMLResult node = appProfile.get(0); - List currValue = null; - currValue = node.evaluate("/Resource/Profile/Name/text()"); - if (currValue != null && currValue.size() > 0) { - toReturn.setName(currValue.get(0)); - } - else throw new ApplicationProfileNotFoundException("Your applicationProfile NAME was not found in the profile"); - - currValue = node.evaluate("/Resource/Profile/Description/text()"); - if (currValue != null && currValue.size() > 0) { - toReturn.setDescription(currValue.get(0)); - } - else _log.warn("No Description exists for " + toReturn.getName()); - - currValue = node.evaluate("/Resource/Profile/Body/AppId/text()"); - if (currValue != null && currValue.size() > 0) { - toReturn.setKey(currValue.get(0)); - } - else throw new ApplicationProfileNotFoundException("Your applicationProfile ID n was not found in the profile, consider adding element in "); - - currValue = node.evaluate("/Resource/Profile/Body/ThumbnailURL/text()"); - if (currValue != null && currValue.size() > 0) { - toReturn.setImageUrl(currValue.get(0)); - } - else throw new ApplicationProfileNotFoundException("Your applicationProfile Image Url was not found in the profile, consider adding element in "); - currValue = node.evaluate("/Resource/Profile/Body/EndPoint/Scope/text()"); - if (currValue != null && currValue.size() > 0) { - List scopes = currValue; - boolean foundUrl = false; - for (int i = 0; i < scopes.size(); i++) { - if (currValue.get(i).trim().compareTo(scope.toString()) == 0) { - toReturn.setUrl(node.evaluate("/Resource/Profile/Body/EndPoint/URL/text()").get(i)); - toReturn.setScope(scope.toString()); - foundUrl = true; - break; - } - } - if (! foundUrl) - throw new ApplicationProfileNotFoundException("Your applicationProfile URL was not found in the profile for Scope: " + scope.toString()); - } - else throw new ApplicationProfileNotFoundException("Your applicationProfile EndPoint was not found in the profile, consider adding element in "); - return toReturn; - } - - } catch (Exception e) { - _log.error("Error while trying to fetch applicationProfile profile from the infrastructure"); - e.printStackTrace(); - return null; - } - - } /** * {@inheritDoc} */ diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/AslNotificationManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java similarity index 74% rename from src/main/java/org/gcube/applicationsupportlayer/social/AslNotificationManager.java rename to src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java index f12ff49..34be3d3 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/AslNotificationManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java @@ -1,8 +1,10 @@ package org.gcube.applicationsupportlayer.social; import org.gcube.application.framework.core.session.ASLSession; +import org.gcube.portal.databook.shared.ApplicationProfile; import org.gcube.portal.databook.shared.Comment; import org.gcube.portal.databook.shared.Feed; +import org.gcube.portal.databook.shared.RunningJob; import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceFolder; import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItem; import org.gcube.portlets.user.homelibrary.home.workspace.sharing.WorkspaceMessage; @@ -13,10 +15,14 @@ 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 { - - public AslNotificationManager(ASLSession session) { - super(session); +public class ApplicationNotificationsManager extends SocialPortalBridge implements NotificationsManager { + /** + * + * @param aslSession the ASLSession instance + * @param portletClassName your portlet class name will be used ad unique identifier for your applicationProfile + */ + public ApplicationNotificationsManager(ASLSession session, String portletClassName) { + super(session, portletClassName); } /** * {@inheritDoc} @@ -88,6 +94,12 @@ public class AslNotificationManager extends SocialPortalBridge implements Notifi public boolean notifyLikedFeed(String userIdToNotify, Feed likedFeed) { return true; } + @Override + public boolean notifyJobStatus(String userIdToNotify, + ApplicationProfile executingJobApId, RunningJob job) { + // TODO Auto-generated method stub + return false; + } diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/NotificationManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java similarity index 87% rename from src/main/java/org/gcube/applicationsupportlayer/social/NotificationManager.java rename to src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java index 9de7c33..3e59aab 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/NotificationManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java @@ -1,7 +1,9 @@ package org.gcube.applicationsupportlayer.social; +import org.gcube.portal.databook.shared.ApplicationProfile; import org.gcube.portal.databook.shared.Comment; import org.gcube.portal.databook.shared.Feed; +import org.gcube.portal.databook.shared.RunningJob; import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceFolder; import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItem; import org.gcube.portlets.user.homelibrary.home.workspace.sharing.WorkspaceMessage; @@ -11,7 +13,7 @@ import org.gcube.portlets.user.homelibrary.home.workspace.sharing.WorkspaceMessa * @version 0.1 Dec 2012 * */ -public interface NotificationManager { +public interface NotificationsManager { /** * use to notify a user he got a workspace folder shared * @@ -89,5 +91,13 @@ public interface NotificationManager { * @return true if the notification is correctly delivered, false otherwise */ boolean notifyLikedFeed(String userIdToNotify, Feed likedFeed); + /** + * use to notify a user he got one of his feed liked + * + * @param userIdToNotify the user you want to notify + * @param executingApp the {@link ApplicationProfile} of the application from which the job was executed/lauched + * @return true if the notification is correctly delivered, false otherwise + */ + boolean notifyJobStatus(String userIdToNotify, ApplicationProfile executingJobApId, RunningJob job); } diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java b/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java index 5a2fc8b..3d6d95a 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java @@ -1,9 +1,18 @@ package org.gcube.applicationsupportlayer.social; +import java.util.List; + import org.gcube.application.framework.core.session.ASLSession; +import org.gcube.applicationsupportlayer.social.ex.ApplicationProfileNotFoundException; +import org.gcube.common.core.contexts.GHNContext; +import org.gcube.common.core.informationsystem.client.ISClient; +import org.gcube.common.core.informationsystem.client.XMLResult; +import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery; +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.ApplicationProfile; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager; /** @@ -11,20 +20,24 @@ import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager; * @author Massimiliano Assante, ISTI-CNR * @version 0.1 Dec 2012 * - * superclass for social portal bridge + * superclass for notifications, posting news and so on */ -public abstract class SocialPortalBridge { +public class SocialPortalBridge { protected static GCUBEClientLog _log = new GCUBEClientLog(SocialPortalBridge.class); protected ASLSession aslSession; + protected ApplicationProfile applicationProfile; //unique instance private static DatabookStore store; + + /** * * @param session */ - public SocialPortalBridge(ASLSession session) { + public SocialPortalBridge(ASLSession session, String portletClassName) { this.aslSession = session; + this.applicationProfile = getProfileFromInfrastrucure(portletClassName); } /** * @@ -60,4 +73,84 @@ public abstract class SocialPortalBridge { return html.replaceAll("&", "&").replaceAll("<", "<") .replaceAll(">", ">"); } + /** + * @return the applicationProfile profile among the ones available in the infrastructure + */ + public ApplicationProfile getApplicationProfile() { + return applicationProfile; + } + /** + * this method looks up the applicationProfile profile among the ones available in the infrastructure + * @param portletClassName your servlet class name will be used ad unique identifier for your applicationProfile + * @return the applicationProfile profile + */ + private ApplicationProfile getProfileFromInfrastrucure(String portletClassName) { + try { + ApplicationProfile toReturn = new ApplicationProfile(); + ISClient client = GHNContext.getImplementation(ISClient.class); + GCUBEGenericQuery query = client.getQuery(GCUBEGenericQuery.class); + + + query.setExpression("for $profile in collection('/db/Profiles/GenericResource')//Resource " + + "where $profile/Profile/SecondaryType/string() eq 'ApplicationProfile' and $profile/Profile/Body/AppId/string() " + + " eq '" + portletClassName + "'" + + "return $profile"); + + GCUBEScope scope = aslSession.getScope(); + + List appProfile = client.execute(query, scope.getInfrastructure()); + if (appProfile == null || appProfile.size() == 0) + throw new ApplicationProfileNotFoundException("Your applicationProfile is not registered in the infrastructure"); + else { + XMLResult node = appProfile.get(0); + List currValue = null; + currValue = node.evaluate("/Resource/Profile/Name/text()"); + if (currValue != null && currValue.size() > 0) { + toReturn.setName(currValue.get(0)); + } + else throw new ApplicationProfileNotFoundException("Your applicationProfile NAME was not found in the profile"); + + currValue = node.evaluate("/Resource/Profile/Description/text()"); + if (currValue != null && currValue.size() > 0) { + toReturn.setDescription(currValue.get(0)); + } + else _log.warn("No Description exists for " + toReturn.getName()); + + currValue = node.evaluate("/Resource/Profile/Body/AppId/text()"); + if (currValue != null && currValue.size() > 0) { + toReturn.setKey(currValue.get(0)); + } + else throw new ApplicationProfileNotFoundException("Your applicationProfile ID n was not found in the profile, consider adding element in "); + + currValue = node.evaluate("/Resource/Profile/Body/ThumbnailURL/text()"); + if (currValue != null && currValue.size() > 0) { + toReturn.setImageUrl(currValue.get(0)); + } + else throw new ApplicationProfileNotFoundException("Your applicationProfile Image Url was not found in the profile, consider adding element in "); + currValue = node.evaluate("/Resource/Profile/Body/EndPoint/Scope/text()"); + if (currValue != null && currValue.size() > 0) { + List scopes = currValue; + boolean foundUrl = false; + for (int i = 0; i < scopes.size(); i++) { + if (currValue.get(i).trim().compareTo(scope.toString()) == 0) { + toReturn.setUrl(node.evaluate("/Resource/Profile/Body/EndPoint/URL/text()").get(i)); + toReturn.setScope(scope.toString()); + foundUrl = true; + break; + } + } + if (! foundUrl) + throw new ApplicationProfileNotFoundException("Your applicationProfile URL was not found in the profile for Scope: " + scope.toString()); + } + else throw new ApplicationProfileNotFoundException("Your applicationProfile EndPoint was not found in the profile, consider adding element in "); + return toReturn; + } + + } catch (Exception e) { + _log.error("Error while trying to fetch applicationProfile profile from the infrastructure"); + e.printStackTrace(); + return null; + } + + } }