updated notify to social. Using social client 2.0

This commit is contained in:
Francesco Mangiacrapa 2024-04-15 16:39:35 +02:00
parent 15ad448778
commit a8b931d9ed
6 changed files with 90 additions and 11 deletions

View File

@ -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

View File

@ -58,7 +58,7 @@
<dependency>
<groupId>org.gcube.social-networking</groupId>
<artifactId>social-service-client</artifactId>
<version>[1.0.0, 2.0.0-SNAPSHOT)</version>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>

View File

@ -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) {

View File

@ -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);

View File

@ -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<String, String> {
/**
@ -21,37 +31,89 @@ public class SubstitutorPlaceholdersMap extends HashMap<String, String> {
/**
* 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);
}

View File

@ -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;