From 7d63f420c8d7639015443321784c00954a4eef87 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Fri, 6 May 2022 17:13:39 +0200 Subject: [PATCH] support for catalogue notifications first test ok --- .../ApplicationNotificationsManager.java | 35 ++++++++++++--- .../social/NotificationsManager.java | 44 +++++++------------ .../ex/UnsupportedNotificationException.java | 8 ++++ .../social/mailing/SocialMailingUtil.java | 14 ++++++ 4 files changed, 69 insertions(+), 32 deletions(-) create mode 100644 src/main/java/org/gcube/applicationsupportlayer/social/ex/UnsupportedNotificationException.java diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java index db11bd2..3ad0f7e 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java @@ -1,11 +1,13 @@ package org.gcube.applicationsupportlayer.social; +import java.net.URL; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Set; import java.util.UUID; +import org.gcube.applicationsupportlayer.social.ex.UnsupportedNotificationException; import org.gcube.applicationsupportlayer.social.mailing.EmailPlugin; import org.gcube.applicationsupportlayer.social.shared.SocialFileItem; import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite; @@ -829,7 +831,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen /** * {@inheritDoc} */ - @Override + @Deprecated public boolean notifyNewCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate) { SimpleDateFormat spf = new SimpleDateFormat("EEE dd MMMMM, yyyy"); @@ -863,7 +865,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen /** * {@inheritDoc} */ - @Override + @Deprecated public boolean notifyEditedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate) { SimpleDateFormat spf = new SimpleDateFormat("EEE dd MMMMM, yyyy"); @@ -896,7 +898,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen /** * {@inheritDoc} */ - @Override + @Deprecated public boolean notifyDeletedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate) { SimpleDateFormat spf = new SimpleDateFormat("EEE dd MMMMM, yyyy"); @@ -929,7 +931,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen /** * {@inheritDoc} */ - @Override + @Deprecated public boolean notifyTDMTabularResourceSharing(String userIdToNotify, String tabularResourceName, String encodedTabularResourceParams) throws Exception { Notification not = new Notification( UUID.randomUUID().toString(), @@ -949,7 +951,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen /** * {@inheritDoc} */ - @Override + @Deprecated public boolean notifyTDMObjectSharing(String userIdToNotify, NotificationType type, String tdmObjectName, String encodedTabularResourceParams) throws Exception { if (! (type == NotificationType.TDM_RULE_SHARE || type == NotificationType.TDM_TEMPLATE_SHARE)) throw new IllegalArgumentException("Type must be either TDM_RULE_SHARE or TDM_TEMPLATE_SHARE"); @@ -977,4 +979,27 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen return saveNotification(not); } + + @Override + public boolean notifyCatalogueEvent(NotificationType type, String userIdToNotify, String itemId, String notifyText, URL url) throws Exception { + final String prefix = "CAT_"; + if (! type.toString().startsWith(prefix)) { + throw new UnsupportedNotificationException("The type of notification is not belonging to the catalogue ones, must start with " + prefix); + } + + Notification not = new Notification( + UUID.randomUUID().toString(), + type, + userIdToNotify, //user no notify + itemId, //the + new Date(), + url.toString(), + notifyText, + false, + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); + + return saveNotification(not); + } } diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java index 026c553..8dea3aa 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java @@ -1,5 +1,6 @@ package org.gcube.applicationsupportlayer.social; +import java.net.URL; import java.util.Date; import java.util.List; import java.util.Set; @@ -148,33 +149,26 @@ public interface NotificationsManager { */ boolean notifyMessageReceived(String userIdToNotify, String messageUniqueIdentifier, String subject, String messageText, String ... otherRecipientsFullNames); /** - * + * use to notify a catalogue moderators someone submitted an item for consideration + * @param type the notification type * @param userIdToNotify the user you want to notify - * @param eventTitle the title of the event - * @param eventType the type of the event - * @param startDate staring date - * @param endingDate ending date + * @param itemId the item unique identifier + * @param notifyText the text of the notification + * @param the resolver URL pointing to the item * @return true if the notification is correctly delivered, false otherwise */ + boolean notifyCatalogueEvent(NotificationType type, String userIdToNotify, String itemId, String notifyText, URL url) throws Exception; + + /** + * @deprecated no longer supported + */ boolean notifyNewCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate); /** - * - * @param userIdToNotify the user you want to notify - * @param eventTitle the title of the event - * @param eventType the type of the event - * @param startDate staring date - * @param endingDate ending date - * @return true if the notification is correctly delivered, false otherwise + * @deprecated no longer supported */ boolean notifyEditedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate); /** - * - * @param userIdToNotify the user you want to notify - * @param eventTitle the title of the event - * @param eventType the type of the event - * @param startDate staring date - * @param endingDate ending date - * @return true if the notification is correctly delivered, false otherwise + * @deprecated no longer supported */ boolean notifyDeletedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate); @@ -280,16 +274,12 @@ public interface NotificationsManager { * @return true if the notification is correctly delivered, false otherwise */ boolean notifyJobStatus(String userIdToNotify, RunningJob job); - + /** + * @deprecated no longer supported + */ boolean notifyTDMTabularResourceSharing(String userIdToNotify, String tabularResourceName, String encodedTabularResourceParams) throws Exception; /** - * use to notify a user he got a Tabular Data Resource shared - * - * @param userIdToNotify the user you want to notify - * @param type type of the shared tdm object (TDM Rule or TDM Template at the moment) - * @param tdmObjectName the name - * @param encodedTabularResourceParams the parameters to be placed in the HTTP GET Request (must be encoded) - * @return true if the notification is correctly delivered, false otherwise + * @deprecated no longer supported */ boolean notifyTDMObjectSharing(String userIdToNotify, NotificationType type, String tdmObjectName, String encodedTabularResourceParams) throws Exception; diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/ex/UnsupportedNotificationException.java b/src/main/java/org/gcube/applicationsupportlayer/social/ex/UnsupportedNotificationException.java new file mode 100644 index 0000000..82d237c --- /dev/null +++ b/src/main/java/org/gcube/applicationsupportlayer/social/ex/UnsupportedNotificationException.java @@ -0,0 +1,8 @@ +package org.gcube.applicationsupportlayer.social.ex; + +@SuppressWarnings("serial") +public class UnsupportedNotificationException extends Exception { + public UnsupportedNotificationException(String message) { + super(message); + } +} diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java index 8c902dd..27267f8 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java @@ -249,6 +249,12 @@ public class SocialMailingUtil { toReturn += " " + hashtag; } return toReturn; + case CAT_ITEM_DELETE: + case CAT_ITEM_PUBLISHED: + case CAT_ITEM_REJECTED: + case CAT_ITEM_SUBMITTED: + case CAT_ITEM_UPDATED: + return "[D4Science Catalogue] " + notification2Save.getSubjectid(); case REQUEST_CONNECTION: return "Connection request"; case JOB_COMPLETED_NOK: @@ -306,6 +312,14 @@ public class SocialMailingUtil { case POST_ALERT: actionLink.append("\">").append("See this Post").append(""); break; + case CAT_ITEM_DELETE: + case CAT_ITEM_PUBLISHED: + case CAT_ITEM_REJECTED: + case CAT_ITEM_SUBMITTED: + case CAT_ITEM_UPDATED: + StringBuilder myLink = new StringBuilder("

").append(" See this on Catalogue").append(""); + return myLink.toString(); case REQUEST_CONNECTION: actionLink.append("\">").append(" Go to Contacts Center").append(""); break;