refactored notifications

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerSocial@67075 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2013-01-03 15:28:36 +00:00
parent baf7de5c76
commit 1bfe6577b0
5 changed files with 126 additions and 99 deletions

View File

@ -103,9 +103,6 @@
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>

View File

@ -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<XMLResult> 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<String> 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 <AppId> element in <Body>");
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 <ThumbnailURL> element in <Body>");
currValue = node.evaluate("/Resource/Profile/Body/EndPoint/Scope/text()");
if (currValue != null && currValue.size() > 0) {
List<String> 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 <EndPoint><Scope> element in <Body>");
return toReturn;
}
} catch (Exception e) {
_log.error("Error while trying to fetch applicationProfile profile from the infrastructure");
e.printStackTrace();
return null;
}
}
/**
* {@inheritDoc}
*/

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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("&", "&amp;").replaceAll("<", "&lt;")
.replaceAll(">", "&gt;");
}
/**
* @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<XMLResult> 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<String> 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 <AppId> element in <Body>");
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 <ThumbnailURL> element in <Body>");
currValue = node.evaluate("/Resource/Profile/Body/EndPoint/Scope/text()");
if (currValue != null && currValue.size() > 0) {
List<String> 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 <EndPoint><Scope> element in <Body>");
return toReturn;
}
} catch (Exception e) {
_log.error("Error while trying to fetch applicationProfile profile from the infrastructure");
e.printStackTrace();
return null;
}
}
}