aslsocial/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsMan...

315 lines
11 KiB
Java

package org.gcube.applicationsupportlayer.social;
import java.util.Date;
import java.util.UUID;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.common.core.utils.logging.GCUBEClientLog;
import org.gcube.portal.databook.shared.ApplicationProfile;
import org.gcube.portal.databook.shared.Notification;
import org.gcube.portal.databook.shared.NotificationType;
import org.gcube.portal.databook.shared.RunningJob;
import org.gcube.portlets.user.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItem;
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;
/**
*
* @author Massimiliano Assante, ISTI-CNR
* @version 0.1 Dec 2012
*
* use to notify users from within your application
*/
public class ApplicationNotificationsManager extends SocialPortalBridge implements NotificationsManager {
static GCUBEClientLog _log = new GCUBEClientLog(ApplicationNotificationsManager.class);
/**
* Use this constructor if you do not need notifications to point back to your applications
* @param aslSession the ASLSession instance
*/
public ApplicationNotificationsManager(ASLSession session) {
super(session);
}
/**
* 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);
}
/**
* {@inheritDoc}
* @throws InternalErrorException
*/
@Override
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(),
"?oid="+sharedFolder.getId(),
"has shared a workspace folder ("+ sharedFolder.getName() +") with you",
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
aslSession.getUserAvatarId());
return getStoreInstance().saveNotification(not);
}
/**
* {@inheritDoc}
* @throws UserManagementPortalException
* @throws UserRetrievalFault
* @throws UserManagementSystemException
*/
@Override
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(),
"?oid="+sharedFolder.getId(),
"has added a new user ("+ user.getFullname() +") on your workspace shared folder ("+ sharedFolder.getName() +")",
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
aslSession.getUserAvatarId());
return getStoreInstance().saveNotification(not);
}
/**
* {@inheritDoc}
*/
@Override
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(),
"?oid="+sharedFolder.getId(),
"has removed a user ("+ user.getFullname() +") from your workspace shared folder ("+ sharedFolder.getName() +")",
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
aslSession.getUserAvatarId());
return getStoreInstance().saveNotification(not);
}
/**
* {@inheritDoc}
* @throws InternalErrorException
*/
@Override
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(),
"?oid="+item.getId()+"&parentoid="+item.getParent().getId(),
"has added a new item ("+ item.getName() +") on your workspace shared folder ("+ item.getParent().getName() +")",
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
aslSession.getUserAvatarId());
return getStoreInstance().saveNotification(not);
}
/**
* {@inheritDoc}
* @throws InternalErrorException
*/
@Override
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(),
"?oid="+item.getId()+"&parentoid="+item.getParent().getId(),
"has removed an item ("+ item.getName() +") from your workspace shared folder ("+ item.getParent().getName() +")",
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
aslSession.getUserAvatarId());
return getStoreInstance().saveNotification(not);
}
/**
* {@inheritDoc}
* @throws InternalErrorException
*/
@Override
public boolean notifyUpdatedItem(String userIdToNotify, WorkspaceItem item) throws InternalErrorException {
Notification not = new Notification(
UUID.randomUUID().toString(),
NotificationType.WP_ITEM_UPDATED,
userIdToNotify, //user no notify
"?oid="+item.getId()+"&parentoid="+item.getParent().getId(),
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());
return getStoreInstance().saveNotification(not);
}
/**
* {@inheritDoc}
*/
@Override
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(),
"",
"has sent you a message with subject: " + escapeHtml(subject),
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
aslSession.getUserAvatarId());
return getStoreInstance().saveNotification(not);
}
/**
* {@inheritDoc}
*/
@Override
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(),
"?oid="+feedid,
"commented on your post: " + escapeHtml(feedText),
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
aslSession.getUserAvatarId());
return getStoreInstance().saveNotification(not);
}
/**
* {@inheritDoc}
*/
@Override
public boolean notifyCommentReply(String userIdToNotify, String feedid, String feedText) {
//TODO: missing implementation
return false;
}
/**
* {@inheritDoc}
*/
@Override
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(),
"?oid="+feedid,
"likes your post: " + escapeHtml(feedText),
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
aslSession.getUserAvatarId());
return getStoreInstance().saveNotification(not);
}
/**
* {@inheritDoc}
*/
@Override
public boolean notifyJobStatus(String userIdToNotify, ApplicationProfile executingJobApId, RunningJob job) {
//TODO: missing implementation
return false;
}
/**
* {@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());
return getStoreInstance().saveNotification(not);
}
/**
* {@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());
return getStoreInstance().saveNotification(not);
}
@Override
public boolean notifyDocumentWorkflowTaskRequest(String userIdToNotify, String documentWorkflowId, String documentName, String assignedRoleName) {
Notification not = new Notification(
UUID.randomUUID().toString(),
NotificationType.DOCUMENT_WORKFLOW_STEP_REQUEST_TASK,
userIdToNotify, //user no notify
documentWorkflowId, //the workflowid
new Date(),
"?oid="+documentWorkflowId,
"has involved you on the document workflow with name: " + escapeHtml(documentName) + " " +
"and has assigned you the following role: " + assignedRoleName +". The VRE used was " + aslSession.getGroupName(),
false,
aslSession.getUsername(),
aslSession.getUserFullName(),
aslSession.getUserAvatarId());
return getStoreInstance().saveNotification(not);
}
}