2012-12-07 15:06:26 +01:00
|
|
|
package org.gcube.applicationsupportlayer.social;
|
|
|
|
|
2013-01-09 17:47:22 +01:00
|
|
|
import java.util.Date;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2012-12-07 15:06:26 +01:00
|
|
|
import org.gcube.application.framework.core.session.ASLSession;
|
2013-01-09 17:47:22 +01:00
|
|
|
import org.gcube.common.core.utils.logging.GCUBEClientLog;
|
2013-01-03 16:28:36 +01:00
|
|
|
import org.gcube.portal.databook.shared.ApplicationProfile;
|
2013-01-09 17:47:22 +01:00
|
|
|
import org.gcube.portal.databook.shared.Notification;
|
|
|
|
import org.gcube.portal.databook.shared.NotificationType;
|
2013-01-03 16:28:36 +01:00
|
|
|
import org.gcube.portal.databook.shared.RunningJob;
|
2013-01-11 12:36:44 +01:00
|
|
|
import org.gcube.portlets.user.homelibrary.home.exceptions.InternalErrorException;
|
2012-12-07 15:06:26 +01:00
|
|
|
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceFolder;
|
|
|
|
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItem;
|
2013-01-11 12:36:44 +01:00
|
|
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException;
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.UserModel;
|
|
|
|
|
2012-12-07 15:06:26 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Massimiliano Assante, ISTI-CNR
|
|
|
|
* @version 0.1 Dec 2012
|
|
|
|
*
|
2012-12-07 18:06:40 +01:00
|
|
|
* use to notify users from within your application
|
2012-12-07 15:06:26 +01:00
|
|
|
*/
|
2013-01-03 16:28:36 +01:00
|
|
|
public class ApplicationNotificationsManager extends SocialPortalBridge implements NotificationsManager {
|
2013-01-09 17:47:22 +01:00
|
|
|
static GCUBEClientLog _log = new GCUBEClientLog(ApplicationNotificationsManager.class);
|
2013-01-03 16:28:36 +01:00
|
|
|
/**
|
2013-01-11 12:36:44 +01:00
|
|
|
* Use this constructor if you do not need notifications to point back to your applications
|
2013-01-03 16:28:36 +01:00
|
|
|
* @param aslSession the ASLSession instance
|
|
|
|
*/
|
2013-01-09 17:47:22 +01:00
|
|
|
public ApplicationNotificationsManager(ASLSession session) {
|
|
|
|
super(session);
|
2012-12-07 15:06:26 +01:00
|
|
|
}
|
2013-01-11 12:36:44 +01:00
|
|
|
/**
|
|
|
|
* Use this constructor if you do need notifications to point back to your applications,
|
|
|
|
* make sure you create your application profile on the infrastructure.
|
|
|
|
*
|
|
|
|
* @see http://gcube.wiki.gcube-system.org/gcube/index.php/Social_Networking_Library#Create_Your_Application_Profile
|
|
|
|
*
|
|
|
|
* @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);
|
|
|
|
}
|
2013-01-28 23:30:54 +01:00
|
|
|
/**
|
|
|
|
* actually save the notification to the store
|
|
|
|
* @param notification2Save the notification instance to save
|
|
|
|
* @return true if the notification was sent ok
|
|
|
|
*/
|
|
|
|
private boolean saveNotification(Notification notification2Save) {
|
|
|
|
_log.trace("Trying to send notification to: " + notification2Save.getUserid() + " Type: " + notification2Save.getType());
|
|
|
|
boolean result = getStoreInstance().saveNotification(notification2Save);
|
|
|
|
if (result)
|
|
|
|
_log.trace("Notification Saved Successfully! ");
|
|
|
|
else
|
|
|
|
_log.error("While trying to save Notification");
|
|
|
|
return result;
|
|
|
|
}
|
2012-12-07 18:02:20 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
2013-01-11 12:36:44 +01:00
|
|
|
* @throws InternalErrorException
|
2012-12-07 18:02:20 +01:00
|
|
|
*/
|
2012-12-07 15:06:26 +01:00
|
|
|
@Override
|
2013-01-11 12:36:44 +01:00
|
|
|
public boolean notifyFolderSharing(String userIdToNotify, WorkspaceFolder sharedFolder) throws InternalErrorException {
|
|
|
|
Notification not = new Notification(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
NotificationType.WP_FOLDER_SHARE,
|
|
|
|
userIdToNotify, //user no notify
|
|
|
|
sharedFolder.getId(), //the
|
|
|
|
new Date(),
|
2013-01-11 14:29:14 +01:00
|
|
|
"?oid="+sharedFolder.getId(),
|
2013-01-11 12:36:44 +01:00
|
|
|
"has shared a workspace folder ("+ sharedFolder.getName() +") with you",
|
|
|
|
false,
|
|
|
|
aslSession.getUsername(),
|
|
|
|
aslSession.getUserFullName(),
|
|
|
|
aslSession.getUserAvatarId());
|
|
|
|
|
2013-01-28 23:30:54 +01:00
|
|
|
return saveNotification(not);
|
2012-12-07 15:06:26 +01:00
|
|
|
}
|
2012-12-07 18:02:20 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
2013-01-11 12:36:44 +01:00
|
|
|
* @throws UserManagementPortalException
|
|
|
|
* @throws UserRetrievalFault
|
|
|
|
* @throws UserManagementSystemException
|
2012-12-07 18:02:20 +01:00
|
|
|
*/
|
2012-12-07 15:06:26 +01:00
|
|
|
@Override
|
2013-01-11 12:36:44 +01:00
|
|
|
public boolean notifyFolderAddedUser(String userIdToNotify, WorkspaceFolder sharedFolder, String newAddedUserId) throws InternalErrorException, UserManagementSystemException, UserRetrievalFault, UserManagementPortalException {
|
|
|
|
UserManager um = new LiferayUserManager();
|
|
|
|
UserModel user = um.getUserByScreenName(newAddedUserId);
|
|
|
|
Notification not = new Notification(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
NotificationType.WP_FOLDER_ADDEDUSER,
|
|
|
|
userIdToNotify, //user no notify
|
|
|
|
sharedFolder.getId(), //the
|
|
|
|
new Date(),
|
2013-01-11 14:29:14 +01:00
|
|
|
"?oid="+sharedFolder.getId(),
|
2013-01-11 12:36:44 +01:00
|
|
|
"has added a new user ("+ user.getFullname() +") on your workspace shared folder ("+ sharedFolder.getName() +")",
|
|
|
|
false,
|
|
|
|
aslSession.getUsername(),
|
|
|
|
aslSession.getUserFullName(),
|
|
|
|
aslSession.getUserAvatarId());
|
|
|
|
|
2013-01-28 23:30:54 +01:00
|
|
|
return saveNotification(not);
|
2012-12-07 15:06:26 +01:00
|
|
|
}
|
2012-12-07 18:02:20 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2012-12-07 15:06:26 +01:00
|
|
|
@Override
|
2013-01-11 12:36:44 +01:00
|
|
|
public boolean notifyFolderRemovedUser(String userIdToNotify, WorkspaceFolder sharedFolder, String removedUserId) throws InternalErrorException, UserManagementSystemException, UserRetrievalFault, UserManagementPortalException {
|
|
|
|
UserManager um = new LiferayUserManager();
|
|
|
|
UserModel user = um.getUserByScreenName(removedUserId);
|
|
|
|
Notification not = new Notification(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
NotificationType.WP_FOLDER_REMOVEDUSER,
|
|
|
|
userIdToNotify, //user no notify
|
|
|
|
sharedFolder.getId(), //the
|
|
|
|
new Date(),
|
2013-01-11 14:29:14 +01:00
|
|
|
"?oid="+sharedFolder.getId(),
|
2013-01-11 12:36:44 +01:00
|
|
|
"has removed a user ("+ user.getFullname() +") from your workspace shared folder ("+ sharedFolder.getName() +")",
|
|
|
|
false,
|
|
|
|
aslSession.getUsername(),
|
|
|
|
aslSession.getUserFullName(),
|
|
|
|
aslSession.getUserAvatarId());
|
|
|
|
|
2013-01-28 23:30:54 +01:00
|
|
|
return saveNotification(not);
|
2012-12-07 15:06:26 +01:00
|
|
|
}
|
2012-12-07 18:02:20 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
2013-01-11 12:36:44 +01:00
|
|
|
* @throws InternalErrorException
|
2012-12-07 18:02:20 +01:00
|
|
|
*/
|
2012-12-07 15:06:26 +01:00
|
|
|
@Override
|
2013-01-11 12:36:44 +01:00
|
|
|
public boolean notifyAddedItem(String userIdToNotify, WorkspaceItem item) throws InternalErrorException {
|
|
|
|
Notification not = new Notification(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
NotificationType.WP_ITEM_NEW,
|
|
|
|
userIdToNotify, //user no notify
|
|
|
|
item.getId(), //the
|
|
|
|
new Date(),
|
2013-01-11 14:29:14 +01:00
|
|
|
"?oid="+item.getId()+"&parentoid="+item.getParent().getId(),
|
2013-01-11 12:36:44 +01:00
|
|
|
"has added a new item ("+ item.getName() +") on your workspace shared folder ("+ item.getParent().getName() +")",
|
|
|
|
false,
|
|
|
|
aslSession.getUsername(),
|
|
|
|
aslSession.getUserFullName(),
|
|
|
|
aslSession.getUserAvatarId());
|
|
|
|
|
2013-01-28 23:30:54 +01:00
|
|
|
return saveNotification(not);
|
2012-12-07 15:06:26 +01:00
|
|
|
}
|
2012-12-07 18:02:20 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
2013-01-11 12:36:44 +01:00
|
|
|
* @throws InternalErrorException
|
2012-12-07 18:02:20 +01:00
|
|
|
*/
|
2012-12-07 15:06:26 +01:00
|
|
|
@Override
|
2013-01-11 12:36:44 +01:00
|
|
|
public boolean notifyRemovedItem(String userIdToNotify, WorkspaceItem item) throws InternalErrorException {
|
|
|
|
Notification not = new Notification(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
NotificationType.WP_ITEM_DELETE,
|
|
|
|
userIdToNotify, //user no notify
|
|
|
|
item.getId(), //the
|
|
|
|
new Date(),
|
2013-01-11 14:29:14 +01:00
|
|
|
"?oid="+item.getId()+"&parentoid="+item.getParent().getId(),
|
2013-01-11 12:36:44 +01:00
|
|
|
"has removed an item ("+ item.getName() +") from your workspace shared folder ("+ item.getParent().getName() +")",
|
|
|
|
false,
|
|
|
|
aslSession.getUsername(),
|
|
|
|
aslSession.getUserFullName(),
|
|
|
|
aslSession.getUserAvatarId());
|
|
|
|
|
2013-01-28 23:30:54 +01:00
|
|
|
return saveNotification(not);
|
2012-12-07 15:06:26 +01:00
|
|
|
}
|
2012-12-07 18:02:20 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
2013-01-11 12:36:44 +01:00
|
|
|
* @throws InternalErrorException
|
2012-12-07 18:02:20 +01:00
|
|
|
*/
|
2012-12-07 15:06:26 +01:00
|
|
|
@Override
|
2013-01-11 12:36:44 +01:00
|
|
|
public boolean notifyUpdatedItem(String userIdToNotify, WorkspaceItem item) throws InternalErrorException {
|
|
|
|
Notification not = new Notification(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
NotificationType.WP_ITEM_UPDATED,
|
|
|
|
userIdToNotify, //user no notify
|
2013-01-11 14:29:14 +01:00
|
|
|
"?oid="+item.getId()+"&parentoid="+item.getParent().getId(),
|
2013-01-11 12:36:44 +01:00
|
|
|
new Date(),
|
|
|
|
"?folder="+item.getParent().getId()+"&item="+item.getId(),
|
|
|
|
"has updated an item ("+ item.getName() +") on your workspace shared folder ("+ item.getParent().getName() +")",
|
|
|
|
false,
|
|
|
|
aslSession.getUsername(),
|
|
|
|
aslSession.getUserFullName(),
|
|
|
|
aslSession.getUserAvatarId());
|
|
|
|
|
2013-01-28 23:30:54 +01:00
|
|
|
return saveNotification(not);
|
2012-12-07 15:06:26 +01:00
|
|
|
}
|
2012-12-07 18:02:20 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2012-12-07 16:29:09 +01:00
|
|
|
@Override
|
2013-01-09 17:47:22 +01:00
|
|
|
public boolean notifyMessageReceived(String userIdToNotify, String subject) {
|
|
|
|
Notification not = new Notification(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
NotificationType.MESSAGE,
|
|
|
|
userIdToNotify, //user no notify
|
|
|
|
"messageid_not_provided", //the
|
|
|
|
new Date(),
|
|
|
|
"",
|
2013-01-11 12:41:13 +01:00
|
|
|
"has sent you a message with subject: " + escapeHtml(subject),
|
2013-01-09 17:47:22 +01:00
|
|
|
false,
|
|
|
|
aslSession.getUsername(),
|
|
|
|
aslSession.getUserFullName(),
|
|
|
|
aslSession.getUserAvatarId());
|
2013-01-11 12:36:44 +01:00
|
|
|
|
2013-01-28 23:30:54 +01:00
|
|
|
return saveNotification(not);
|
2012-12-07 16:29:09 +01:00
|
|
|
}
|
2012-12-07 18:02:20 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2012-12-07 16:29:09 +01:00
|
|
|
@Override
|
2013-01-11 12:36:44 +01:00
|
|
|
public boolean notifyOwnCommentReply(String userIdToNotify, String feedid, String feedText) {
|
|
|
|
Notification not = new Notification(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
NotificationType.OWN_COMMENT,
|
|
|
|
userIdToNotify, //user no notify
|
|
|
|
feedid, //the post
|
|
|
|
new Date(),
|
2013-01-11 14:29:14 +01:00
|
|
|
"?oid="+feedid,
|
2013-01-11 12:41:13 +01:00
|
|
|
"commented on your post: " + escapeHtml(feedText),
|
2013-01-11 12:36:44 +01:00
|
|
|
false,
|
|
|
|
aslSession.getUsername(),
|
|
|
|
aslSession.getUserFullName(),
|
|
|
|
aslSession.getUserAvatarId());
|
2013-01-28 23:30:54 +01:00
|
|
|
return saveNotification(not);
|
2012-12-07 16:29:09 +01:00
|
|
|
}
|
2012-12-07 18:02:20 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2012-12-07 16:29:09 +01:00
|
|
|
@Override
|
2013-01-11 12:36:44 +01:00
|
|
|
public boolean notifyCommentReply(String userIdToNotify, String feedid, String feedText) {
|
|
|
|
//TODO: missing implementation
|
|
|
|
return false;
|
2012-12-07 16:29:09 +01:00
|
|
|
}
|
2012-12-07 18:02:20 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2012-12-07 16:29:09 +01:00
|
|
|
@Override
|
2013-01-11 12:36:44 +01:00
|
|
|
public boolean notifyLikedFeed(String userIdToNotify, String feedid, String feedText) {
|
|
|
|
Notification not = new Notification(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
NotificationType.LIKE,
|
|
|
|
userIdToNotify, //user no notify
|
|
|
|
feedid, //the post
|
|
|
|
new Date(),
|
2013-01-11 14:29:14 +01:00
|
|
|
"?oid="+feedid,
|
2013-01-11 12:41:13 +01:00
|
|
|
"likes your post: " + escapeHtml(feedText),
|
2013-01-11 12:36:44 +01:00
|
|
|
false,
|
|
|
|
aslSession.getUsername(),
|
|
|
|
aslSession.getUserFullName(),
|
|
|
|
aslSession.getUserAvatarId());
|
2013-01-28 23:30:54 +01:00
|
|
|
return saveNotification(not);
|
2012-12-07 16:29:09 +01:00
|
|
|
}
|
2013-01-28 01:12:51 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2013-01-03 16:28:36 +01:00
|
|
|
@Override
|
2013-01-11 12:36:44 +01:00
|
|
|
public boolean notifyJobStatus(String userIdToNotify, ApplicationProfile executingJobApId, RunningJob job) {
|
|
|
|
//TODO: missing implementation
|
2013-01-03 16:28:36 +01:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-28 01:12:51 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean notifyDocumentWorkflowView(String userIdToNotify, String documentWorkflowId, String documentName) {
|
|
|
|
Notification not = new Notification(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
NotificationType.DOCUMENT_WORKFLOW_VIEW,
|
|
|
|
userIdToNotify, //user no notify
|
|
|
|
documentWorkflowId, //the workflowid
|
|
|
|
new Date(),
|
|
|
|
"?oid="+documentWorkflowId,
|
|
|
|
"has viewed the document workflow with name: " + escapeHtml(documentName),
|
|
|
|
false,
|
|
|
|
aslSession.getUsername(),
|
|
|
|
aslSession.getUserFullName(),
|
|
|
|
aslSession.getUserAvatarId());
|
2013-01-28 23:30:54 +01:00
|
|
|
return saveNotification(not);
|
2013-01-28 01:12:51 +01:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean notifyDocumentWorkflowUpdate(String userIdToNotify, String documentWorkflowId, String documentName) {
|
|
|
|
Notification not = new Notification(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
NotificationType.DOCUMENT_WORKFLOW_EDIT,
|
|
|
|
userIdToNotify, //user no notify
|
|
|
|
documentWorkflowId, //the workflowid
|
|
|
|
new Date(),
|
|
|
|
"?oid="+documentWorkflowId,
|
|
|
|
"has edited the document workflow with name: " + escapeHtml(documentName),
|
|
|
|
false,
|
|
|
|
aslSession.getUsername(),
|
|
|
|
aslSession.getUserFullName(),
|
|
|
|
aslSession.getUserAvatarId());
|
2013-01-28 23:30:54 +01:00
|
|
|
return saveNotification(not);
|
2013-01-28 01:12:51 +01:00
|
|
|
}
|
2013-01-28 23:30:54 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2013-01-28 18:38:43 +01:00
|
|
|
@Override
|
2013-01-28 19:11:47 +01:00
|
|
|
public boolean notifyDocumentWorkflowTaskRequest(String userIdToNotify, String documentWorkflowId, String documentName, String assignedRoleName) {
|
2013-01-28 18:38:43 +01:00
|
|
|
Notification not = new Notification(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
NotificationType.DOCUMENT_WORKFLOW_STEP_REQUEST_TASK,
|
|
|
|
userIdToNotify, //user no notify
|
|
|
|
documentWorkflowId, //the workflowid
|
|
|
|
new Date(),
|
|
|
|
"?oid="+documentWorkflowId,
|
2013-01-28 23:30:54 +01:00
|
|
|
"has involved you in a Document Workflow (" + escapeHtml(documentName) + ") " +
|
|
|
|
"and has assigned you the role: " + assignedRoleName +". The VRE used was " + aslSession.getGroupName(),
|
2013-01-28 18:38:43 +01:00
|
|
|
false,
|
|
|
|
aslSession.getUsername(),
|
|
|
|
aslSession.getUserFullName(),
|
|
|
|
aslSession.getUserAvatarId());
|
2013-01-28 23:30:54 +01:00
|
|
|
|
|
|
|
return saveNotification(not);
|
|
|
|
|
2013-01-28 18:38:43 +01:00
|
|
|
}
|
2013-01-28 01:12:51 +01:00
|
|
|
|
2013-01-28 23:30:54 +01:00
|
|
|
|
2013-01-09 17:47:22 +01:00
|
|
|
|
2012-12-07 16:29:09 +01:00
|
|
|
|
2012-12-07 15:06:26 +01:00
|
|
|
}
|