diff --git a/notifications-plugins/README.md b/notifications-plugins/README.md index 85cc986..b3eca94 100644 --- a/notifications-plugins/README.md +++ b/notifications-plugins/README.md @@ -88,6 +88,17 @@ and * `LAST_INVOKED_STEP` (optional) can be: `SUBMIT-FOR-REVIEW​`, `APPROVE-SUBMITTED`, `REJECT-DRAFT​`, `UNPUBLISH`; * `NOTIFICATION_TYPE` (mandatory) can be: `USER_NOTIFICATION`, `VRE_POST`, `EMAIL`; +***Notifications_Messages.properties*** managed/known placeholders: + +* `${project_name}` +* `${project_id}` +* `${private_data_entry_link}` +* `${public_data_entry_link}` +* `${private_data_viewer_link}` +* `${public_data_viewer_link}` +* `${project_as_pdf_link}` +* `${user_caller}` + ## Change log diff --git a/notifications-plugins/pom.xml b/notifications-plugins/pom.xml index f30f8df..f6b712e 100644 --- a/notifications-plugins/pom.xml +++ b/notifications-plugins/pom.xml @@ -58,7 +58,7 @@ org.gcube.social-networking social-service-client - [1.0.0, 2.0.0-SNAPSHOT) + [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) org.gcube.portlets.user diff --git a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/NotificationsPlugin.java b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/NotificationsPlugin.java index 6303bde..f77a2b6 100644 --- a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/NotificationsPlugin.java +++ b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/NotificationsPlugin.java @@ -19,6 +19,7 @@ import org.gcube.application.cms.plugins.events.EventManager; import org.gcube.application.cms.plugins.events.EventManager.Event; import org.gcube.application.cms.plugins.events.ItemObserved; import org.gcube.application.cms.plugins.faults.InitializationException; +import org.gcube.application.cms.plugins.faults.InvalidProfileException; import org.gcube.application.cms.plugins.faults.MaterializationException; import org.gcube.application.cms.plugins.faults.ShutDownException; import org.gcube.application.cms.plugins.implementations.AbstractPlugin; @@ -49,6 +50,9 @@ public class NotificationsPlugin extends AbstractPlugin implements EventListener public static final String PLUGIN_ID = "Notifications-Plugin"; public static final String PLUGIN_TYPE = "EventListener"; + private static final String CONFIG_ENABLED = "enabled"; + private static final String CONFIG_LINK_TO_NOTIFICATIONS_MESSAGES = "link_to_notifications_messages"; + public static final PluginDescriptor DESCRIPTOR = new PluginDescriptor(PLUGIN_ID, PLUGIN_TYPE); static { @@ -316,8 +320,9 @@ public class NotificationsPlugin extends AbstractPlugin implements EventListener notificationMapPerContext.setUcd(useCaseDescriptor); notificationMapPerContext .setListNotificationEventSubscribed(listNotificationEventsSubscribedPerUCD); - String linkToMessages = profileConfiguration.get("link_to_notifications_messages", String.class); - Boolean enabledNotifications = profileConfiguration.get("enabled", Boolean.class); + String linkToMessages = profileConfiguration.get(CONFIG_LINK_TO_NOTIFICATIONS_MESSAGES, + String.class); + Boolean enabledNotifications = profileConfiguration.get(CONFIG_ENABLED, Boolean.class); notificationMapPerContext.setLinkToNotificationsMessages(linkToMessages); notificationMapPerContext.setEnabled(enabledNotifications); } @@ -326,7 +331,9 @@ public class NotificationsPlugin extends AbstractPlugin implements EventListener log.info("Events subscribed read from config {} ", notificationMapPerContext); } - + } catch (InvalidProfileException e) { + log.warn("Unable to read configuration for {} in the UCD {}" + NotificationsPlugin.PLUGIN_ID, + useCaseDescriptor.getId()); } catch (Exception e) { log.error("Unable to read configuration for " + NotificationsPlugin.PLUGIN_ID, e); } catch (Throwable t) { diff --git a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/NotifyToSocial.java b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/NotifyToSocial.java index c68780a..b5576a4 100644 --- a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/NotifyToSocial.java +++ b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/NotifyToSocial.java @@ -65,7 +65,7 @@ public class NotifyToSocial { body += "\n" + itemObserved.getOptionalMessage(); } - log.info("Going to sent notification to users: {}", recipientUsers); + log.info("Going to send notification to users: {}", recipientUsers); log.info("subject: {}", subject); log.info("body: {}", body); userNotify(subject, body, catalogueEventType); @@ -104,7 +104,6 @@ public class NotifyToSocial { try { final Secret geoportalSecret = GeoportalServiceAccount.getGeoportalSecret(); secretManager.startSession(geoportalSecret); - // secretManager.startSession(geoportalSecret); log.debug("{} is going to send vrePost {}", SecretManagerProvider.instance.get().getUser().getUsername(), toWrite); @@ -112,8 +111,8 @@ public class NotifyToSocial { // log.debug("body with tag: {}", bodyWithTag); // toWrite.setText(bodyWithTag); toWrite.setEnablenotification(true); - - log.info("Going to write user post: {}", toWrite); + + log.info("Calling social - going to write user post: {}", toWrite); Post thePost = socialClients.writeUserPost(toWrite); log.info("{} post created: {} ", notify.getType(), thePost); @@ -137,9 +136,9 @@ public class NotifyToSocial { try { Secret secret = GeoportalServiceAccount.getGeoportalSecret(); secretManager.startSession(secret); - log.debug("{} is going to send the following notification {}", - SecretManagerProvider.instance.get().getUser().getUsername(), catalogueEvent); NotificationClient nc = socialClients.getNotificationClient(); + log.info("Calling social - {} is going to send the notification {}", + SecretManagerProvider.instance.get().getUser().getUsername(), catalogueEvent); nc.sendCatalogueEvent(catalogueEvent); } catch (Exception e) { log.error("Error while sending notification", e); diff --git a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/substitutor/SubstitutorPlaceholdersMap.java b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/substitutor/SubstitutorPlaceholdersMap.java index 8af17f0..9045451 100644 --- a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/substitutor/SubstitutorPlaceholdersMap.java +++ b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/substitutor/SubstitutorPlaceholdersMap.java @@ -2,6 +2,16 @@ package org.gcube.application.cms.notifications.substitutor; import java.util.HashMap; + +/** + * The Class SubstitutorPlaceholdersMap. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Apr 15, 2024 + * + * This class contains the placeholder known + */ public class SubstitutorPlaceholdersMap extends HashMap { /** @@ -21,37 +31,89 @@ public class SubstitutorPlaceholdersMap extends HashMap { + /** + * Instantiates a new substitutor placeholders map. + */ public SubstitutorPlaceholdersMap() { super(); } + /** + * Put user caller. + * + * @param username the username + * @return the string + */ public String putUserCaller(String username) { return put(USER_CALLER, username); } + + /** + * Put item creator. + * + * @param username the username + * @return the string + */ public String putItemCreator(String username) { return put(ITEM_CREATOR, username); } + /** + * Put project name. + * + * @param projectName the project name + * @return the string + */ public String putProjectName(String projectName) { return put(PROJECT_NAME, projectName); } + /** + * Put project id. + * + * @param projectId the project id + * @return the string + */ public String putProjectId(String projectId) { return put(PROJECT_ID, projectId); } + /** + * Put private data entry link. + * + * @param link the link + * @return the string + */ public String putPrivateDataEntryLink(String link) { return put(PRIVATE_DATA_ENTRY_LINK, link); } + /** + * Put public data entry link. + * + * @param link the link + * @return the string + */ public String putPublicDataEntryLink(String link) { return put(PUBLIC_DATA_ENTRY_LINK, link); } + /** + * Put private data viewer link. + * + * @param link the link + * @return the string + */ public String putPrivateDataViewerLink(String link) { return put(PRIVATE_DATA_VIEWER_LINK, link); } + /** + * Put public data viewer link. + * + * @param link the link + * @return the string + */ public String putPublicDataViewerLink(String link) { return put(PUBLIC_DATA_VIEWER_LINK, link); } diff --git a/notifications-plugins/src/test/java/CatalogueBindingPluginTest.java b/notifications-plugins/src/test/java/CatalogueBindingPluginTest.java index 6236bf3..daa947d 100644 --- a/notifications-plugins/src/test/java/CatalogueBindingPluginTest.java +++ b/notifications-plugins/src/test/java/CatalogueBindingPluginTest.java @@ -114,7 +114,7 @@ public class CatalogueBindingPluginTest extends BasicPluginTest { //Setting creator User creator = new User(); - creator.setUsername("gianluca.vannini"); + creator.setUsername("giancarlo.panichi"); item.getProject().getInfo().getCreationInfo().setUser(creator); EventManager.Event event = Event.LIFECYCLE_STEP_PERFORMED;