support for catalogue notifications first test ok

This commit is contained in:
Massimiliano Assante 2022-05-06 17:13:39 +02:00
parent cf37f90b4d
commit 7d63f420c8
4 changed files with 69 additions and 32 deletions

View File

@ -1,11 +1,13 @@
package org.gcube.applicationsupportlayer.social; package org.gcube.applicationsupportlayer.social;
import java.net.URL;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.gcube.applicationsupportlayer.social.ex.UnsupportedNotificationException;
import org.gcube.applicationsupportlayer.social.mailing.EmailPlugin; import org.gcube.applicationsupportlayer.social.mailing.EmailPlugin;
import org.gcube.applicationsupportlayer.social.shared.SocialFileItem; import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite; import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
@ -829,7 +831,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Deprecated
public boolean notifyNewCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate) { public boolean notifyNewCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate) {
SimpleDateFormat spf = new SimpleDateFormat("EEE dd MMMMM, yyyy"); SimpleDateFormat spf = new SimpleDateFormat("EEE dd MMMMM, yyyy");
@ -863,7 +865,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Deprecated
public boolean notifyEditedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate) { public boolean notifyEditedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate) {
SimpleDateFormat spf = new SimpleDateFormat("EEE dd MMMMM, yyyy"); SimpleDateFormat spf = new SimpleDateFormat("EEE dd MMMMM, yyyy");
@ -896,7 +898,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Deprecated
public boolean notifyDeletedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate) { public boolean notifyDeletedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate) {
SimpleDateFormat spf = new SimpleDateFormat("EEE dd MMMMM, yyyy"); SimpleDateFormat spf = new SimpleDateFormat("EEE dd MMMMM, yyyy");
@ -929,7 +931,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Deprecated
public boolean notifyTDMTabularResourceSharing(String userIdToNotify, String tabularResourceName, String encodedTabularResourceParams) throws Exception { public boolean notifyTDMTabularResourceSharing(String userIdToNotify, String tabularResourceName, String encodedTabularResourceParams) throws Exception {
Notification not = new Notification( Notification not = new Notification(
UUID.randomUUID().toString(), UUID.randomUUID().toString(),
@ -949,7 +951,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Deprecated
public boolean notifyTDMObjectSharing(String userIdToNotify, NotificationType type, String tdmObjectName, String encodedTabularResourceParams) throws Exception { public boolean notifyTDMObjectSharing(String userIdToNotify, NotificationType type, String tdmObjectName, String encodedTabularResourceParams) throws Exception {
if (! (type == NotificationType.TDM_RULE_SHARE || type == NotificationType.TDM_TEMPLATE_SHARE)) 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"); 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); 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);
}
} }

View File

@ -1,5 +1,6 @@
package org.gcube.applicationsupportlayer.social; package org.gcube.applicationsupportlayer.social;
import java.net.URL;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -148,33 +149,26 @@ public interface NotificationsManager {
*/ */
boolean notifyMessageReceived(String userIdToNotify, String messageUniqueIdentifier, String subject, String messageText, String ... otherRecipientsFullNames); 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 userIdToNotify the user you want to notify
* @param eventTitle the title of the event * @param itemId the item unique identifier
* @param eventType the type of the event * @param notifyText the text of the notification
* @param startDate staring date * @param the resolver URL pointing to the item
* @param endingDate ending date
* @return true if the notification is correctly delivered, false otherwise * @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); boolean notifyNewCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate);
/** /**
* * @deprecated no longer supported
* @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
*/ */
boolean notifyEditedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate); boolean notifyEditedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate);
/** /**
* * @deprecated no longer supported
* @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
*/ */
boolean notifyDeletedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate); 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 * @return true if the notification is correctly delivered, false otherwise
*/ */
boolean notifyJobStatus(String userIdToNotify, RunningJob job); boolean notifyJobStatus(String userIdToNotify, RunningJob job);
/**
* @deprecated no longer supported
*/
boolean notifyTDMTabularResourceSharing(String userIdToNotify, String tabularResourceName, String encodedTabularResourceParams) throws Exception; boolean notifyTDMTabularResourceSharing(String userIdToNotify, String tabularResourceName, String encodedTabularResourceParams) throws Exception;
/** /**
* use to notify a user he got a Tabular Data Resource shared * @deprecated no longer supported
*
* @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
*/ */
boolean notifyTDMObjectSharing(String userIdToNotify, NotificationType type, String tdmObjectName, String encodedTabularResourceParams) throws Exception; boolean notifyTDMObjectSharing(String userIdToNotify, NotificationType type, String tdmObjectName, String encodedTabularResourceParams) throws Exception;

View File

@ -0,0 +1,8 @@
package org.gcube.applicationsupportlayer.social.ex;
@SuppressWarnings("serial")
public class UnsupportedNotificationException extends Exception {
public UnsupportedNotificationException(String message) {
super(message);
}
}

View File

@ -249,6 +249,12 @@ public class SocialMailingUtil {
toReturn += " " + hashtag; toReturn += " " + hashtag;
} }
return toReturn; 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: case REQUEST_CONNECTION:
return "Connection request"; return "Connection request";
case JOB_COMPLETED_NOK: case JOB_COMPLETED_NOK:
@ -306,6 +312,14 @@ public class SocialMailingUtil {
case POST_ALERT: case POST_ALERT:
actionLink.append("\">").append("See this Post").append("</a>"); actionLink.append("\">").append("See this Post").append("</a>");
break; 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("<br/><br/><a style=\"color:#3B5998; text-decoration:none\" target=\"_blank\" href=\"");
myLink.append(notification2Save.getUri()).append("\">").append(" See this on Catalogue").append("</a>");
return myLink.toString();
case REQUEST_CONNECTION: case REQUEST_CONNECTION:
actionLink.append("\">").append(" Go to Contacts Center").append("</a>"); actionLink.append("\">").append(" Go to Contacts Center").append("</a>");
break; break;