implemented first version of the notification plugin
This commit is contained in:
parent
70ec76748e
commit
75a964ad09
|
@ -1,6 +1,9 @@
|
||||||
# Changelog for org.gcube.application.cms.notifications-plugins
|
# Changelog for org.gcube.application.cms.notifications-plugins
|
||||||
|
|
||||||
## [v1.0.4-SNAPSHOT] - 2023-09-06
|
## [v1.0.5-SNAPSHOT] - 2023-09-06
|
||||||
|
- Implemented the notification-plugin [#26453]
|
||||||
|
|
||||||
|
## [v1.0.4] - 2023-09-06
|
||||||
- Using parent version range [#25572]
|
- Using parent version range [#25572]
|
||||||
|
|
||||||
## [v1.0.3] - 2023-03-06
|
## [v1.0.3] - 2023-03-06
|
||||||
|
|
|
@ -38,6 +38,7 @@ This plugin requires a configuration of type:
|
||||||
{
|
{
|
||||||
"type": "NOTIFICATION_TYPE",
|
"type": "NOTIFICATION_TYPE",
|
||||||
"send": "true/false",
|
"send": "true/false",
|
||||||
|
"placeholder_title": "PLACEHOLDER_TITLE_1",
|
||||||
"placeholder_msg": "PLACEHOLDER_MESSAGE_1",
|
"placeholder_msg": "PLACEHOLDER_MESSAGE_1",
|
||||||
"export_as_pdf": {
|
"export_as_pdf": {
|
||||||
"placeholder_msg": "Export as PDF placeholder",
|
"placeholder_msg": "Export as PDF placeholder",
|
||||||
|
@ -55,6 +56,7 @@ This plugin requires a configuration of type:
|
||||||
{
|
{
|
||||||
"type": "NOTIFICATION_TYPE",
|
"type": "NOTIFICATION_TYPE",
|
||||||
"send": "true/false",
|
"send": "true/false",
|
||||||
|
"placeholder_title": "PLACEHOLDER_TITLE_2",
|
||||||
"placeholder_msg": "PLACEHOLDER_MESSAGE_2",
|
"placeholder_msg": "PLACEHOLDER_MESSAGE_2",
|
||||||
"export_as_pdf": {
|
"export_as_pdf": {
|
||||||
"placeholder_msg": "Export as PDF placeholder",
|
"placeholder_msg": "Export as PDF placeholder",
|
||||||
|
@ -80,11 +82,11 @@ Where:
|
||||||
|
|
||||||
and
|
and
|
||||||
|
|
||||||
* `EVENT_NAME` (mandatory) can be: `PROJECT_CREATED`, `PROJECT_UPDATED`, `PROJECT_DELETED`, `LIFECYCLE_STEP_PERFORMED`.
|
* `EVENT_NAME` (mandatory) can be: `PROJECT_CREATED`, `PROJECT_UPDATED`, `PROJECT_DELETED`, `LIFECYCLE_STEP_PERFORMED`;
|
||||||
* `USER_ROLE` (mandatory) can be: `Data-Manager`, `Data-Editor`, `Member"`, `Item_Creator`, `Any`;
|
* `USER_ROLE` (mandatory) can be: `Data-Manager`, `Data-Editor`, `Member`, `Item_Creator`, `Any`;
|
||||||
* `TARGET_PHASE` (mandatory) can be: `DRAFT`, `Pending Approval`, `Published`, `Any`;
|
* `TARGET_PHASE` (mandatory) can be: `DRAFT`, `Pending Approval`, `Published`, `Any`;
|
||||||
* `LAST_INVOKED_STEP` (optional) can be: `SUBMIT-FOR-REVIEW`, `APPROVE-SUBMITTED`, `REJECT-DRAFT`, `UNPUBLISH`;
|
* `LAST_INVOKED_STEP` (optional) can be: `SUBMIT-FOR-REVIEW`, `APPROVE-SUBMITTED`, `REJECT-DRAFT`, `UNPUBLISH`;
|
||||||
* `NOTIFICATION_TYPE` (mandatory) can be: `USER_POST`, `VRE_POST`, `EMAIL`;
|
* `NOTIFICATION_TYPE` (mandatory) can be: `USER_NOTIFICATION`, `VRE_POST`, `EMAIL`;
|
||||||
|
|
||||||
|
|
||||||
## Change log
|
## Change log
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>notifications-plugins</artifactId>
|
<artifactId>notifications-plugins</artifactId>
|
||||||
<version>1.0.4-SNAPSHOT</version>
|
<version>1.0.5-SNAPSHOT</version>
|
||||||
<name>gCube CMS - Notifications Plugins</name>
|
<name>gCube CMS - Notifications Plugins</name>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
|
|
@ -11,7 +11,7 @@ public class NotificationGenericConstants {
|
||||||
};
|
};
|
||||||
|
|
||||||
public static enum NOTIFICATION_TYPE {
|
public static enum NOTIFICATION_TYPE {
|
||||||
USER_POST, EMAIL, VRE_POST
|
USER_NOTIFICATION, EMAIL, VRE_POST
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,6 +163,7 @@ public class NotificationsPlugin extends AbstractPlugin implements EventListener
|
||||||
@Override
|
@Override
|
||||||
@Synchronized
|
@Synchronized
|
||||||
public InitializationReport initInContext() throws InitializationException {
|
public InitializationReport initInContext() throws InitializationException {
|
||||||
|
log.debug("Called initInContext");
|
||||||
InitializationReport report = new InitializationReport();
|
InitializationReport report = new InitializationReport();
|
||||||
try {
|
try {
|
||||||
String context = UserUtils.getCurrent().getContext();
|
String context = UserUtils.getCurrent().getContext();
|
||||||
|
|
|
@ -26,7 +26,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
public class IAMClientCredentialsReader {
|
public class IAMClientCredentialsReader {
|
||||||
|
|
||||||
private static final String SE_PROFILE_NAME = "geoportal";
|
private static final String SE_PROFILE_NAME = "geoportal";
|
||||||
private static final String SE_CATEGORY_NAME = "SystemClient";
|
private static final String SE_CATEGORY_NAME = "SystemWorkspaceClient";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the credentials.
|
* Gets the credentials.
|
||||||
|
|
|
@ -58,7 +58,14 @@ public class ManageDoActionNotification {
|
||||||
String projectName = docAsMap.size() > 0 ? docAsMap.values().stream().findFirst().get() + ""
|
String projectName = docAsMap.size() > 0 ? docAsMap.values().stream().findFirst().get() + ""
|
||||||
: itemObserved.getProjectId();
|
: itemObserved.getProjectId();
|
||||||
placeholderMapValues.putProjectName(projectName);
|
placeholderMapValues.putProjectName(projectName);
|
||||||
placeholderMapValues.putUser(itemObserved.getUserCaller().getUsername());
|
placeholderMapValues.putUserCaller(itemObserved.getUserCaller().getUsername());
|
||||||
|
|
||||||
|
try {
|
||||||
|
//Setting the user creator of the project
|
||||||
|
placeholderMapValues.putItemCreator(itemObserved.getProject().getInfo().getCreationInfo().getUser().getUsername());
|
||||||
|
}catch (Exception e) {
|
||||||
|
// TODO: handle exception
|
||||||
|
}
|
||||||
|
|
||||||
nMPlaceholdersS.setPlaceholderMapValues(placeholderMapValues);
|
nMPlaceholdersS.setPlaceholderMapValues(placeholderMapValues);
|
||||||
|
|
||||||
|
@ -106,7 +113,7 @@ public class ManageDoActionNotification {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
NotifyUsers mnu = new NotifyUsers(itemObserved, notificationsCompliantToPhase,
|
NotifyToSocial mnu = new NotifyToSocial(itemObserved, notificationsCompliantToPhase,
|
||||||
nMPlaceholdersS, notifyUsers, catalogueEventType);
|
nMPlaceholdersS, notifyUsers, catalogueEventType);
|
||||||
mnu.sendNotification();
|
mnu.sendNotification();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ import org.gcube.social_networking.socialnetworking.model.beans.catalogue.Catalo
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class NotifyUsers {
|
public class NotifyToSocial {
|
||||||
|
|
||||||
private List<User> recipientUsers;
|
private List<User> recipientUsers;
|
||||||
private NMessagesPlaceholdersSubstitutorUtil nMPlaceholdersSUtil;
|
private NMessagesPlaceholdersSubstitutorUtil nMPlaceholdersSUtil;
|
||||||
|
@ -34,7 +34,7 @@ public class NotifyUsers {
|
||||||
private CatalogueEventType catalogueEventType;
|
private CatalogueEventType catalogueEventType;
|
||||||
private ItemObserved<Project> itemObserved;
|
private ItemObserved<Project> itemObserved;
|
||||||
|
|
||||||
public NotifyUsers(ItemObserved<Project> itemObserved, List<NotificationWhen> listWhen,
|
public NotifyToSocial(ItemObserved<Project> itemObserved, List<NotificationWhen> listWhen,
|
||||||
NMessagesPlaceholdersSubstitutorUtil nMPlaceholdersSUtil, List<User> recipientUsers,
|
NMessagesPlaceholdersSubstitutorUtil nMPlaceholdersSUtil, List<User> recipientUsers,
|
||||||
CatalogueEventType catalogueEventType) {
|
CatalogueEventType catalogueEventType) {
|
||||||
this.socialClients = new SocialClients();
|
this.socialClients = new SocialClients();
|
||||||
|
@ -48,32 +48,44 @@ public class NotifyUsers {
|
||||||
public void sendNotification() throws Exception {
|
public void sendNotification() throws Exception {
|
||||||
log.info("send notification...");
|
log.info("send notification...");
|
||||||
List<Notify> listNotifies = toNotify();
|
List<Notify> listNotifies = toNotify();
|
||||||
|
log.info("listNotifies are {} ", listNotifies);
|
||||||
|
|
||||||
for (Notify notify : listNotifies) {
|
for (Notify notify : listNotifies) {
|
||||||
switch (notify.getType()) {
|
switch (notify.getType()) {
|
||||||
case USER_POST:
|
case USER_NOTIFICATION:
|
||||||
log.info("Notification type {}, send: {}", notify.getType(), notify.getSend());
|
log.info("Notification type {}, send: {}", notify.getType(), notify.getSend());
|
||||||
if (notify.getSend()) {
|
if (notify.getSend()) {
|
||||||
log.debug("Building message...");
|
log.debug("Building Notification...");
|
||||||
String subject = "Message";
|
String subject = "Notification";
|
||||||
String body = null;
|
String body = null;
|
||||||
subject = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_title());
|
subject = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_title());
|
||||||
body = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_msg());
|
body = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_msg());
|
||||||
|
|
||||||
log.debug("subject: {}", subject);
|
if (itemObserved.getOptionalMessage() != null) {
|
||||||
log.debug("body: {}", body);
|
body += "\n" + itemObserved.getOptionalMessage();
|
||||||
log.info("Sending message to users: {}", recipientUsers);
|
}
|
||||||
|
|
||||||
postMessage(subject, body, catalogueEventType);
|
log.info("Going to sent notification to users: {}", recipientUsers);
|
||||||
|
log.info("subject: {}", subject);
|
||||||
|
log.info("body: {}", body);
|
||||||
|
userNotify(subject, body, catalogueEventType);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case VRE_POST:
|
case VRE_POST:
|
||||||
if (notify.getSend()) {
|
|
||||||
log.info("Notification type {}, send: {}", notify.getType(), notify.getSend());
|
log.info("Notification type {}, send: {}", notify.getType(), notify.getSend());
|
||||||
PostInputBean toWrite = null;
|
if (notify.getSend()) {
|
||||||
Post thePost = socialClients.writeUserPost(toWrite);
|
PostInputBean toWrite = new PostInputBean();
|
||||||
log.info("{} post created: {} ", notify.getType(), thePost);
|
String title = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_title());
|
||||||
|
String body = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_msg());
|
||||||
|
if (itemObserved.getOptionalMessage() != null) {
|
||||||
|
body += "\n" + itemObserved.getOptionalMessage();
|
||||||
|
}
|
||||||
|
toWrite.setText(body);
|
||||||
|
if (title != null)
|
||||||
|
toWrite.setPreviewtitle(title);
|
||||||
|
|
||||||
|
vrePost(toWrite, notify);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EMAIL:
|
case EMAIL:
|
||||||
|
@ -86,6 +98,63 @@ public class NotifyUsers {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void vrePost(PostInputBean toWrite, Notify notify) {
|
||||||
|
|
||||||
|
final SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||||
|
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);
|
||||||
|
|
||||||
|
// String bodyWithTag = toWrite.getText() + "\n #" + geoportalSecret.getUser().getUsername();
|
||||||
|
// log.debug("body with tag: {}", bodyWithTag);
|
||||||
|
// toWrite.setText(bodyWithTag);
|
||||||
|
toWrite.setEnablenotification(true);
|
||||||
|
|
||||||
|
log.info("Going to write user post: {}", toWrite);
|
||||||
|
Post thePost = socialClients.writeUserPost(toWrite);
|
||||||
|
log.info("{} post created: {} ", notify.getType(), thePost);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error while sending vrePost", e);
|
||||||
|
} finally {
|
||||||
|
if (secretManager != null) {
|
||||||
|
try {
|
||||||
|
secretManager.endSession();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void userNotify(String subject, String bodyMessage, CatalogueEventType catalogueEventType)
|
||||||
|
throws Exception {
|
||||||
|
CatalogueEvent catalogueEvent = getCatalogueEvent(subject, bodyMessage);
|
||||||
|
SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||||
|
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();
|
||||||
|
nc.sendCatalogueEvent(catalogueEvent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error while sending notification", e);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
if (secretManager != null) {
|
||||||
|
try {
|
||||||
|
secretManager.endSession();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<Notify> toNotify() {
|
private List<Notify> toNotify() {
|
||||||
List<Notify> listNotifies = new ArrayList<Notify>();
|
List<Notify> listNotifies = new ArrayList<Notify>();
|
||||||
for (NotificationWhen notificationWhen : listNotificationWhen) {
|
for (NotificationWhen notificationWhen : listNotificationWhen) {
|
||||||
|
@ -95,51 +164,6 @@ public class NotifyUsers {
|
||||||
return listNotifies;
|
return listNotifies;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void postMessage(String subject, String bodyMessage, CatalogueEventType catalogueEventType)
|
|
||||||
throws Exception {
|
|
||||||
CatalogueEvent catalogueEvent = getCatalogueEvent(subject, bodyMessage);
|
|
||||||
SecretManager secretManager = SecretManagerProvider.instance.get();
|
|
||||||
try {
|
|
||||||
Secret geoportalSecret = GeoportalServiceAccount.getGeoportalSecret();
|
|
||||||
secretManager.startSession(geoportalSecret);
|
|
||||||
sendNotification(catalogueEvent);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Error while sending notification", e);
|
|
||||||
} finally {
|
|
||||||
if (secretManager != null) {
|
|
||||||
secretManager.endSession();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void sendNotification(CatalogueEvent catalogueEvent) throws Exception {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread thread = new Thread() {
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
log.debug("{} is going to send the following notification {}",
|
|
||||||
SecretManagerProvider.instance.get().getUser().getUsername(), catalogueEvent);
|
|
||||||
NotificationClient nc = socialClients.getNotificationClient();
|
|
||||||
nc.sendCatalogueEvent(catalogueEvent);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Error while sending notification from thread", e);
|
|
||||||
} finally {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// thread.run();
|
|
||||||
thread.start();
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Error while sending notification", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// log.debug("{} is going to send the following notification {}", SecretManagerProvider.instance.get().getUser().getUsername(), catalogueEvent);
|
|
||||||
// NotificationClient nc = socialClients.getNotificationClient();
|
|
||||||
// nc.sendCatalogueEvent(catalogueEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CatalogueEvent getCatalogueEvent(String subject, String bodyMessage) throws Exception {
|
protected CatalogueEvent getCatalogueEvent(String subject, String bodyMessage) throws Exception {
|
||||||
CatalogueEvent catalogueEvent = new CatalogueEvent();
|
CatalogueEvent catalogueEvent = new CatalogueEvent();
|
||||||
catalogueEvent.setType(catalogueEventType);
|
catalogueEvent.setType(catalogueEventType);
|
||||||
|
|
|
@ -52,14 +52,15 @@ public class NMessagesPlaceholdersSubstitutorUtil {
|
||||||
if (notificationPlaceholder == null || notificationPlaceholder.isEmpty())
|
if (notificationPlaceholder == null || notificationPlaceholder.isEmpty())
|
||||||
return notificationPlaceholder;
|
return notificationPlaceholder;
|
||||||
|
|
||||||
this.placeholderMapValues = ResolveProjectLinkFromPlaceholder.resolveLink(itemObserved, placeholderMapValues, notificationPlaceholder);
|
|
||||||
|
|
||||||
log.trace("stringSub is {}",stringSub);
|
log.trace("stringSub is {}",stringSub);
|
||||||
|
|
||||||
if (stringSub != null) {
|
if (stringSub != null) {
|
||||||
|
|
||||||
log.debug("notificationPlaceholder: {}", notificationPlaceholder);
|
log.debug("notificationPlaceholder: {}", notificationPlaceholder);
|
||||||
String templateString = notificationMessagesProperties.getProperty(notificationPlaceholder);
|
String templateString = notificationMessagesProperties.getProperty(notificationPlaceholder);
|
||||||
|
|
||||||
|
this.placeholderMapValues = ResolveProjectLinkFromPlaceholder.resolveLink(itemObserved, placeholderMapValues, templateString);
|
||||||
|
|
||||||
log.debug("templateString: {}", templateString);
|
log.debug("templateString: {}", templateString);
|
||||||
// Replace
|
// Replace
|
||||||
String resolvedString = stringSub.replace(templateString);
|
String resolvedString = stringSub.replace(templateString);
|
||||||
|
|
|
@ -11,24 +11,25 @@ public class SubstitutorPlaceholdersMap extends HashMap<String, String> {
|
||||||
|
|
||||||
public static final String PROJECT_ID = "project_id";
|
public static final String PROJECT_ID = "project_id";
|
||||||
public static final String PROJECT_NAME = "project_name";
|
public static final String PROJECT_NAME = "project_name";
|
||||||
public static final String USER = "user";
|
public static final String USER_CALLER = "user_caller";
|
||||||
|
private static final String ITEM_CREATOR = "item_creator";
|
||||||
|
|
||||||
public static final String PRIVATE_DATA_ENTRY_LINK = "private_data_entry_link";
|
public static final String PRIVATE_DATA_ENTRY_LINK = "private_data_entry_link";
|
||||||
public static final String PUBLIC_DATA_ENTRY_LINK = "public_data_entry_link";
|
public static final String PUBLIC_DATA_ENTRY_LINK = "public_data_entry_link";
|
||||||
public static final String PRIVATE_DATA_VIEWER_LINK = "private_data_viewer_link";
|
public static final String PRIVATE_DATA_VIEWER_LINK = "private_data_viewer_link";
|
||||||
public static final String PUBLIC_DATA_VIEWER_LINK = "public_data_viewer_link";
|
public static final String PUBLIC_DATA_VIEWER_LINK = "public_data_viewer_link";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public SubstitutorPlaceholdersMap() {
|
public SubstitutorPlaceholdersMap() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public String putUserCaller(String username) {
|
||||||
public String put(String key, String value) {
|
return put(USER_CALLER, username);
|
||||||
return put(key, value);
|
|
||||||
}
|
}
|
||||||
|
public String putItemCreator(String username) {
|
||||||
public String putUser(String username) {
|
return put(ITEM_CREATOR, username);
|
||||||
return put(USER, username);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String putProjectName(String projectName) {
|
public String putProjectName(String projectName) {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.gcube.application.cms.tests.plugins.BasicPluginTest;
|
||||||
import org.gcube.application.geoportal.common.model.document.Project;
|
import org.gcube.application.geoportal.common.model.document.Project;
|
||||||
import org.gcube.application.geoportal.common.model.document.accounting.AccountingInfo;
|
import org.gcube.application.geoportal.common.model.document.accounting.AccountingInfo;
|
||||||
import org.gcube.application.geoportal.common.model.document.accounting.PublicationInfo;
|
import org.gcube.application.geoportal.common.model.document.accounting.PublicationInfo;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||||
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||||
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
||||||
|
@ -33,30 +34,44 @@ import org.junit.Test;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class CatalogueBindingPluginTest.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Apr 10, 2024
|
||||||
|
*/
|
||||||
public class CatalogueBindingPluginTest extends BasicPluginTest {
|
public class CatalogueBindingPluginTest extends BasicPluginTest {
|
||||||
|
|
||||||
NotificationsPlugin plugin;
|
NotificationsPlugin plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check plugin.
|
||||||
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void checkPlugin() {
|
public void checkPlugin() {
|
||||||
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
plugin = (NotificationsPlugin) plugins.get(NotificationsPlugin.DESCRIPTOR.getId());
|
plugin = (NotificationsPlugin) plugins.get(NotificationsPlugin.DESCRIPTOR.getId());
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
plugin.init();
|
// plugin.init();
|
||||||
} catch (InitializationException e1) {
|
// } catch (InitializationException e1) {
|
||||||
e1.printStackTrace();
|
// e1.printStackTrace();
|
||||||
}
|
// }
|
||||||
try {
|
//
|
||||||
plugin.initInContext();
|
// try {
|
||||||
} catch (InitializationException e1) {
|
// plugin.initInContext();
|
||||||
e1.printStackTrace();
|
// } catch (InitializationException e1) {
|
||||||
}
|
// e1.printStackTrace();
|
||||||
|
// }
|
||||||
|
|
||||||
System.out.println("Plugin check: " + plugin);
|
System.out.println("Plugin check: " + plugin);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check plugin config.
|
||||||
|
*/
|
||||||
//@Test
|
//@Test
|
||||||
public void checkPluginConfig() {
|
public void checkPluginConfig() {
|
||||||
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
|
@ -75,8 +90,11 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check notifications SUBMIT_FOR_REVIEW to USERS
|
||||||
|
*/
|
||||||
//@Test
|
//@Test
|
||||||
public void checkNotifications_LIFECYCLE_STEP_PERFORMED() {
|
public void checkNotifications_LIFECYCLE_STEP_PERFORMED_TO_SUBMIT_FOR_REVIEW() {
|
||||||
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
UseCaseDescriptor descriptor = TestProfiles.profiles.get("profiledConcessioni");
|
UseCaseDescriptor descriptor = TestProfiles.profiles.get("profiledConcessioni");
|
||||||
|
|
||||||
|
@ -94,22 +112,109 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
|
||||||
|
|
||||||
ItemObserved<Project> item = mockItemObserverd();
|
ItemObserved<Project> item = mockItemObserverd();
|
||||||
|
|
||||||
|
//Setting creator
|
||||||
|
User creator = new User();
|
||||||
|
creator.setUsername("gianluca.vannini");
|
||||||
|
item.getProject().getInfo().getCreationInfo().setUser(creator);
|
||||||
|
|
||||||
EventManager.Event event = Event.LIFECYCLE_STEP_PERFORMED;
|
EventManager.Event event = Event.LIFECYCLE_STEP_PERFORMED;
|
||||||
item.setEvent(event);
|
item.setEvent(event);
|
||||||
|
|
||||||
LifecycleInformation lifecycleInfo = item.getProject().getLifecycleInformation();
|
LifecycleInformation lifecycleInfo = item.getProject().getLifecycleInformation();
|
||||||
//(Pending Approval, "SUBMIT-FOR-REVIEW")
|
|
||||||
// lifecycleInfo.setPhase("Pending Approval");
|
//Test Stage (Pending Approval, "SUBMIT-FOR-REVIEW")
|
||||||
// lifecycleInfo.setLastInvokedStep("SUBMIT-FOR-REVIEW");
|
lifecycleInfo.setPhase("Pending Approval");
|
||||||
//(DRAFT, REJECT-DRAFT)
|
lifecycleInfo.setLastInvokedStep("SUBMIT-FOR-REVIEW");
|
||||||
lifecycleInfo.setPhase("DRAFT");
|
|
||||||
lifecycleInfo.setLastInvokedStep("REJECT-DRAFT");
|
|
||||||
|
|
||||||
System.out.println("By notifying event " + event + " project " + item.getProjectId());
|
System.out.println("By notifying event " + event + " project " + item.getProjectId());
|
||||||
EventManager.getInstance().notify(event, item);
|
EventManager.getInstance().notify(event, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sysOut(SubscribeNotificationEvent subscribeNotificationEvent) {
|
/**
|
||||||
|
* Check notifications REJECT_DRAFT to USERS
|
||||||
|
*/
|
||||||
|
//@Test
|
||||||
|
public void checkNotifications_LIFECYCLE_STEP_PERFORMED_TO_REJECT_DRAFT() {
|
||||||
|
//org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
|
UseCaseDescriptor descriptor = TestProfiles.profiles.get("profiledConcessioni");
|
||||||
|
|
||||||
|
NotificationEventsSubscribedConfig notificationEventsSubs;
|
||||||
|
try {
|
||||||
|
System.out.println(NotificationEventsSubscribedConfig.class.getSimpleName() + ": ");
|
||||||
|
notificationEventsSubs = plugin.readNotificationsSubscribedFromConfigurationInTheUCD(descriptor);
|
||||||
|
List<SubscribeNotificationEvent> events = notificationEventsSubs.getListNotificationEventSubscribed();
|
||||||
|
for (SubscribeNotificationEvent subscribeNotificationEvent : events) {
|
||||||
|
sysOut(subscribeNotificationEvent);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemObserved<Project> item = mockItemObserverd();
|
||||||
|
|
||||||
|
//Setting creator
|
||||||
|
User creator = new User();
|
||||||
|
creator.setUsername("gianluca.vannini");
|
||||||
|
item.getProject().getInfo().getCreationInfo().setUser(creator);
|
||||||
|
|
||||||
|
EventManager.Event event = Event.LIFECYCLE_STEP_PERFORMED;
|
||||||
|
item.setEvent(event);
|
||||||
|
|
||||||
|
LifecycleInformation lifecycleInfo = item.getProject().getLifecycleInformation();
|
||||||
|
//Test Stage (DRAFT, REJECT-DRAFT)
|
||||||
|
lifecycleInfo.setPhase("DRAFT");
|
||||||
|
lifecycleInfo.setLastInvokedStep("REJECT-DRAFT");
|
||||||
|
System.out.println("By notifying event " + event + " project " + item.getProjectId());
|
||||||
|
EventManager.getInstance().notify(event, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the VRE POST
|
||||||
|
*/
|
||||||
|
//@Test
|
||||||
|
public void checkNotifications_LIFECYCLE_STEP_PERFORMED_TO_APPROVE_SUBMITTED() {
|
||||||
|
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
|
UseCaseDescriptor descriptor = TestProfiles.profiles.get("profiledConcessioni");
|
||||||
|
|
||||||
|
NotificationEventsSubscribedConfig notificationEventsSubs;
|
||||||
|
try {
|
||||||
|
System.out.println(NotificationEventsSubscribedConfig.class.getSimpleName() + ": ");
|
||||||
|
notificationEventsSubs = plugin.readNotificationsSubscribedFromConfigurationInTheUCD(descriptor);
|
||||||
|
List<SubscribeNotificationEvent> events = notificationEventsSubs.getListNotificationEventSubscribed();
|
||||||
|
for (SubscribeNotificationEvent subscribeNotificationEvent : events) {
|
||||||
|
sysOut(subscribeNotificationEvent);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemObserved<Project> item = mockItemObserverd();
|
||||||
|
|
||||||
|
//Setting creator
|
||||||
|
User creator = new User();
|
||||||
|
creator.setUsername("gianluca.vannini");
|
||||||
|
item.getProject().getInfo().getCreationInfo().setUser(creator);
|
||||||
|
|
||||||
|
EventManager.Event event = Event.LIFECYCLE_STEP_PERFORMED;
|
||||||
|
item.setEvent(event);
|
||||||
|
|
||||||
|
LifecycleInformation lifecycleInfo = item.getProject().getLifecycleInformation();
|
||||||
|
|
||||||
|
//Test Stage (Published, null)
|
||||||
|
lifecycleInfo.setPhase("Published");
|
||||||
|
lifecycleInfo.setLastInvokedStep("APPROVE-SUBMITTED");
|
||||||
|
|
||||||
|
System.out.println("By notifying event " + event + " project " + item.getProjectId());
|
||||||
|
EventManager.getInstance().notify(event, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sys out.
|
||||||
|
*
|
||||||
|
* @param subscribeNotificationEvent the subscribe notification event
|
||||||
|
*/
|
||||||
|
private static void sysOut(SubscribeNotificationEvent subscribeNotificationEvent) {
|
||||||
System.out.println("\n#SubscribeNotificationEvent - Event: " + subscribeNotificationEvent.getEvent());
|
System.out.println("\n#SubscribeNotificationEvent - Event: " + subscribeNotificationEvent.getEvent());
|
||||||
List<NotificationFor> listNotificationFor = subscribeNotificationEvent.getNotificationFor();
|
List<NotificationFor> listNotificationFor = subscribeNotificationEvent.getNotificationFor();
|
||||||
for (NotificationFor notificationFor : listNotificationFor) {
|
for (NotificationFor notificationFor : listNotificationFor) {
|
||||||
|
@ -129,6 +234,11 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock item observerd.
|
||||||
|
*
|
||||||
|
* @return the item observed
|
||||||
|
*/
|
||||||
private static ItemObserved<Project> mockItemObserverd() {
|
private static ItemObserved<Project> mockItemObserverd() {
|
||||||
|
|
||||||
UseCaseDescriptor descriptor = TestProfiles.profiles.get("profiledConcessioni");
|
UseCaseDescriptor descriptor = TestProfiles.profiles.get("profiledConcessioni");
|
||||||
|
@ -148,7 +258,7 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
|
||||||
|
|
||||||
// MOCK PROJECT
|
// MOCK PROJECT
|
||||||
Project testProject = new Project();
|
Project testProject = new Project();
|
||||||
testProject.setId("63bda06581b811167f6a0769");
|
testProject.setId("655489965bdd5478cca320ea");
|
||||||
testProject.setProfileID(descriptor.getId());
|
testProject.setProfileID(descriptor.getId());
|
||||||
PublicationInfo info = new PublicationInfo(descriptor.getCreationInfo(), null, null);
|
PublicationInfo info = new PublicationInfo(descriptor.getCreationInfo(), null, null);
|
||||||
testProject.setInfo(info);
|
testProject.setInfo(info);
|
||||||
|
@ -168,9 +278,15 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
|
||||||
testProject.setLifecycleInformation(lifecycleInfo);
|
testProject.setLifecycleInformation(lifecycleInfo);
|
||||||
item.setProject(testProject);
|
item.setProject(testProject);
|
||||||
|
|
||||||
|
|
||||||
|
item.setOptionalMessage("My great message");
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Matching notification test.
|
||||||
|
*/
|
||||||
//@Test
|
//@Test
|
||||||
public void matchingNotificationTest() {
|
public void matchingNotificationTest() {
|
||||||
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
|
@ -205,6 +321,9 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
|
||||||
System.out.println("Filtered notifications: "+listWhen);
|
System.out.println("Filtered notifications: "+listWhen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check serialize deserialize.
|
||||||
|
*/
|
||||||
// @Test
|
// @Test
|
||||||
public void checkSerializeDeserialize() {
|
public void checkSerializeDeserialize() {
|
||||||
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
|
@ -230,6 +349,11 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock subscribe notification event.
|
||||||
|
*
|
||||||
|
* @return the subscribe notification event
|
||||||
|
*/
|
||||||
public static SubscribeNotificationEvent mockSubscribeNotificationEvent() {
|
public static SubscribeNotificationEvent mockSubscribeNotificationEvent() {
|
||||||
SubscribeNotificationEvent sne = new SubscribeNotificationEvent();
|
SubscribeNotificationEvent sne = new SubscribeNotificationEvent();
|
||||||
sne.setEvent(Event.LIFECYCLE_STEP_PERFORMED);
|
sne.setEvent(Event.LIFECYCLE_STEP_PERFORMED);
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class StringReplacerTest {
|
||||||
// valuesMap.put(SubstitutorPlaceholdersMap.PROJECT_ID, PROJECT_ID);
|
// valuesMap.put(SubstitutorPlaceholdersMap.PROJECT_ID, PROJECT_ID);
|
||||||
|
|
||||||
SubstitutorPlaceholdersMap smp = new SubstitutorPlaceholdersMap();
|
SubstitutorPlaceholdersMap smp = new SubstitutorPlaceholdersMap();
|
||||||
smp.putUser(USERNAME);
|
smp.putUserCaller(USERNAME);
|
||||||
smp.putPublicDataEntryLink(APPLICATION_LINK);
|
smp.putPublicDataEntryLink(APPLICATION_LINK);
|
||||||
smp.putProjectId(PROJECT_ID);
|
smp.putProjectId(PROJECT_ID);
|
||||||
smp.putProjectName(PROJECT_NAME);
|
smp.putProjectName(PROJECT_NAME);
|
||||||
|
|
Loading…
Reference in New Issue