in progress notification plugin

This commit is contained in:
Francesco Mangiacrapa 2024-03-26 10:28:21 +01:00
parent b422fc8b56
commit b502ad0c2d
12 changed files with 484 additions and 197 deletions

View File

@ -16,6 +16,76 @@ This module is expected to contain plugin definitions for the generations of not
## Documentation
[gCube CMS Suite](../) parent module containing references, documentation, guides ad utilities.
This plugin requires a configuration of type:
```json
{
"subscribeNotifications": [
{
"event": "EVENT_NAME",
"notificationFor": [
{
"roles": [
"USER_ROLE"
],
"when": [
{
"target_phase": [
"TARGET_PHASE"
],
"last_invoked_step": LAST_INVOKED_STEP_1,
"notify": [
{
"type": "NOTIFICATION_TYPE",
"send": "true/false",
"placeholder_msg": "PLACEHOLDER_MESSAGE_1",
"export_as_pdf": {
"placeholder_msg": "Export as PDF placeholder",
"export": true
}
}
]
},
{
"target_phase": [
"TARGET_PHASE"
],
"last_invoked_step": LAST_INVOKED_STEP_2,
"notify": [
{
"type": "NOTIFICATION_TYPE",
"send": "true/false",
"placeholder_msg": "PLACEHOLDER_MESSAGE_2",
"export_as_pdf": {
"placeholder_msg": "Export as PDF placeholder",
"export": true
}
}
]
}
]
}
]
}
],
"enabled":true/false,
"link_to_notifications_messages" (mandatory): "link to file containg the messages as properties like PLACEHOLDER_MESSAGE_{N} = value"
}
```
Where:
* `enabled`: (optional) can be true/false. Default is true. It enables or not the plugin.
* `link_to_notifications_messages`: it is the URL to Notifications Messages file with placeholder values. A property file like PLACEHOLDER_MESSAGE_{N} = value
and
* `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`;
* `TARGET_PHASE` (mandatory) can be: `DRAFT`, `Pending Approval`, `Published`, `Any`;
* `LAST_INVOKED_STEP` (optional) can be: `SUBMIT-FOR-REVIEW`, `APPROVE-SUBMITTED`, `REJECT-DRAFT`, `UNPUBLISH`;
* `NOTIFICATION_TYPE` (mandatory) can be: `USER_POST`, `VRE_POST`, `EMAIL`;
## Change log

View File

@ -14,4 +14,5 @@ public class NotificationEventsSubscribedConfig {
UseCaseDescriptor ucd;
List<SubscribeNotificationEvent> listNotificationEventSubscribed;
String linkToNotificationsMessages;
boolean enabled = true;
}

View File

@ -316,7 +316,9 @@ public class NotificationsPlugin extends AbstractPlugin implements EventListener
notificationMapPerContext
.setListNotificationEventSubscribed(listNotificationEventsSubscribedPerUCD);
String linkToMessages = profileConfiguration.get("link_to_notifications_messages", String.class);
Boolean enabledNotifications = profileConfiguration.get("enabled", Boolean.class);
notificationMapPerContext.setLinkToNotificationsMessages(linkToMessages);
notificationMapPerContext.setEnabled(enabledNotifications);
}
setNotificationBindingMapPerContext(context, useCaseDescriptor, notificationMapPerContext);
@ -366,35 +368,34 @@ public class NotificationsPlugin extends AbstractPlugin implements EventListener
NotificationEventsSubscribedConfig subscribedConfig = notificationMapPerContext
.get(itemObserved.getUCD_Id());
String linkToFileWithMessages = subscribedConfig.getLinkToNotificationsMessages();
List<SubscribeNotificationEvent> list = subscribedConfig.getListNotificationEventSubscribed();
boolean subscribeNotificationsEnabled = subscribedConfig.isEnabled();
//Filtering list of SubscribeNotificationEvent for itemObserved Event
List<SubscribeNotificationEvent> filterList = list.stream()
.filter(sne -> sne.getEvent().equals(itemObserved.getEvent())).collect(Collectors.toList());
log.info("subscribeNotifications enabled: {}", subscribeNotificationsEnabled);
if (subscribeNotificationsEnabled) {
String linkToFileWithMessages = subscribedConfig.getLinkToNotificationsMessages();
List<SubscribeNotificationEvent> list = subscribedConfig.getListNotificationEventSubscribed();
// Filtering list of SubscribeNotificationEvent for itemObserved Event
List<SubscribeNotificationEvent> filterList = list.stream()
.filter(sne -> sne.getEvent().equals(itemObserved.getEvent())).collect(Collectors.toList());
log.debug(linkToFileWithMessages);
NMessagesPlaceholdersSubstitutorUtil nMPlaceholdersSUtil = null;
try {
nMPlaceholdersSUtil = new NMessagesPlaceholdersSubstitutorUtil(linkToFileWithMessages);
} catch (IOException e) {
log.error("Error instancing the {}. Please check the URL {}. Returning!!",
NMessagesPlaceholdersSubstitutorUtil.class.getSimpleName(), linkToFileWithMessages);
return;
}
ManageDoActionNotification mdoact = new ManageDoActionNotification(itemObserved, nMPlaceholdersSUtil,
filterList);
mdoact.manage();
log.debug(linkToFileWithMessages);
NMessagesPlaceholdersSubstitutorUtil nMPlaceholdersSUtil = null;
try {
nMPlaceholdersSUtil = new NMessagesPlaceholdersSubstitutorUtil(linkToFileWithMessages);
} catch (IOException e) {
log.error("Error instancing the {}. Please check the URL {}. Returning!!", NMessagesPlaceholdersSubstitutorUtil.class.getSimpleName(), linkToFileWithMessages);
return;
}
ManageDoActionNotification mdoact = new ManageDoActionNotification(itemObserved, nMPlaceholdersSUtil, filterList);
mdoact.manage();
// for (SubscribeNotificationEvent subscribeNotificationEvent : filterList) {
// List<NotificationFor> listNotificationFor = subscribeNotificationEvent.getNotificationFor();
//
// UserUtils.getCurrent().getRoles();
//
// for (NotificationFor notificationFor : listNotificationFor) {
// notificationFor.getRoles();
// }
// }
}
}

View File

@ -6,18 +6,6 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* Instantiates a new notify.
*
*
{
"type": "NOTIFICATION_TYPE",
"send": "true/false",
"placeholder_msg": "PLACEHOLDER_MESSAGE_1",
"export_as_pdf": "ExportAsPDF"
}
*
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class Notify {

View File

@ -7,62 +7,6 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
/**
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jan 30, 2024
*/
/**
* Instantiates a new subscribe notification config.
*
{
"subscribeNotifications": [
{
"event": "EVENT_NAME",
"notificationFor": [
{
"roles": [
"USER_ROLE"
],
"when": [
{
"target_phase": [
"TARGET_PHASE"
],
"notify": [
{
"type": "NOTIFICATION_TYPE",
"send": "true/false",
"attach_pdf_document": "true/false",
"message": "PLACEHOLDER_MESSAGE_1"
}
]
},
{
"target_phase": [
"TARGET_PHASE"
],
"notify": [
{
"type": "NOTIFICATION_TYPE",
"send": "true/false",
"attach_pdf_document": "true/false",
"message": "PLACEHOLDER_MESSAGE_2"
}
]
}
]
}
]
}
],
"link_to_messages": "link to file containing the messages as properties like ID_MESSAGE_{N} = value"
}
*
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class SubscribeNotificationEvent {

View File

@ -0,0 +1,51 @@
package org.gcube.application.cms.notifications.config.serviceaccount;
import java.util.AbstractMap.SimpleEntry;
import java.util.Map.Entry;
import javax.ws.rs.InternalServerErrorException;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.JWTSecret;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.common.keycloak.KeycloakClientFactory;
import org.gcube.common.keycloak.model.TokenResponse;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GeoportalServiceAccount {
//geoportal service account config property file
protected static final String CLIENT_ID_PROPERTY_NAME = "clientId";
private static String clientId = "geoportal";
private static Entry<String, String> getClientIdAndClientSecret(String context) {
try {
IAMClientCredentials credentials = IAMClientCredentialsReader.getCredentials();
clientId = credentials.getClientId()==null?clientId:credentials.getClientId();
String clientSecret = credentials.getClientSecret();
SimpleEntry<String, String> entry = new SimpleEntry<String, String>(clientId, clientSecret);
return entry;
} catch(Exception e) {
throw new InternalServerErrorException(
"Unable to retrieve Application Token for context " + SecretManagerProvider.instance.get().getContext(), e);
}
}
private static TokenResponse getJWTAccessToken() throws Exception {
String context = SecretManagerProvider.instance.get().getContext();
Entry<String,String> entry = getClientIdAndClientSecret(context);
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(context, entry.getKey(), entry.getValue(), context, null);
return tr;
}
public static Secret getGeoportalSecret() throws Exception {
TokenResponse tr = getJWTAccessToken();
Secret secret = new JWTSecret(tr.getAccessToken());
return secret;
}
}

View File

@ -0,0 +1,90 @@
package org.gcube.application.cms.notifications.config.serviceaccount;
import java.io.Serializable;
/**
* The Class IAMClientCredentials.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Sep 23, 2021
*/
public class IAMClientCredentials implements Serializable {
/**
*
*/
private static final long serialVersionUID = 7242909633989611318L;
private String clientId;
private String clientSecret;
/**
* Instantiates a new IAM client credentials.
*/
public IAMClientCredentials() {
}
/**
* Instantiates a new IAM client credentials.
*
* @param clientId the client id
* @param clientSecret the client secret
*/
public IAMClientCredentials(String clientId, String clientSecret) {
this.clientId = clientId;
this.clientSecret = clientSecret;
}
/**
* Gets the client id.
*
* @return the client id
*/
public String getClientId() {
return clientId;
}
/**
* Gets the client secret.
*
* @return the client secret
*/
public String getClientSecret() {
return clientSecret;
}
/**
* Sets the client id.
*
* @param clientId the new client id
*/
public void setClientId(String clientId) {
this.clientId = clientId;
}
/**
* Sets the client secret.
*
* @param clientSecret the new client secret
*/
public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("IAMClientCredentials [clientId=");
builder.append(clientId);
builder.append(", clientSecret=");
builder.append(clientSecret != null ? clientSecret.subSequence(0, 5) + "_MASKED_SECRET" : null);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,82 @@
package org.gcube.application.cms.notifications.config.serviceaccount;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.util.Collection;
import java.util.List;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.encryption.StringEncrypter;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import lombok.extern.slf4j.Slf4j;
/**
* The Class GNABaseMapsResourceReader.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Sep 23, 2021
*/
@Slf4j
public class IAMClientCredentialsReader {
private static final String SE_PROFILE_NAME = "geoportal";
private static final String SE_CATEGORY_NAME = "SystemClient";
/**
* Gets the credentials.
*
* @return the credentials
* @throws Exception the exception
*/
public static IAMClientCredentials getCredentials() throws Exception {
String currentContext = SecretManagerProvider.instance.get().getContext();
log.info("Searching SE in the scope: " + currentContext + " with profile name: " + SE_PROFILE_NAME
+ " and category name: " + SE_CATEGORY_NAME);
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Name/text() eq '" + SE_PROFILE_NAME + "'");
query.addCondition("$resource/Profile/Category/text() eq '" + SE_CATEGORY_NAME + "'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> resources = client.submit(query);
if (resources.size() > 0)
log.info("The query returned " + resources.size() + " ServiceEndpoint/s");
else
throw new RuntimeException("ServiceEndpoint not found. Searching for profile name '" + SE_PROFILE_NAME
+ "' and category name '" + SE_CATEGORY_NAME + "' in the scope: " + currentContext);
ServiceEndpoint se = resources.get(0);
Collection<AccessPoint> theAccessPoints = se.profile().accessPoints().asCollection();
String clientId = null;
String secredPwd = null;
for (AccessPoint accessPoint : theAccessPoints) {
clientId = accessPoint.username();
secredPwd = accessPoint.password();
log.debug("Found clientId: " + clientId + " and encrypted secret: " + secredPwd);
// decrypting the pwd
try {
if (secredPwd != null) {
secredPwd = StringEncrypter.getEncrypter().decrypt(secredPwd);
log.debug("Secret decrypted is: " + secredPwd.substring(0, secredPwd.length() / 2)
+ "_MASKED_TOKEN_");
}
} catch (Exception e) {
throw new RuntimeException("Error on decrypting the pwd: ", e);
}
}
log.info("Returning keycloack credentials for SE {} read from SE", SE_PROFILE_NAME);
return new IAMClientCredentials(clientId, secredPwd);
}
}

View File

@ -87,7 +87,7 @@ public class ManageDoActionNotification {
String lastInvokedStep = lInfo.getLastInvokedStep();
log.debug("ItemObserved phase is: {}, lastInvokedStep is: {}", itemPhase, lastInvokedStep);
//final SecretManager cm = SecretManagerProvider.instance.get();
// final SecretManager cm = SecretManagerProvider.instance.get();
for (final NotificationFor notificationFor : listNotificationFor) {
// Filtering notifications on 'phase' and 'lastInvokedStep' according to item
@ -100,9 +100,10 @@ public class ManageDoActionNotification {
if (notificationsCompliantToPhase != null && notificationsCompliantToPhase.size() > 0) {
// GET LIST USER COMPLIANT TO ROLES
List<User> notifyUsers = getListUserCompliantToRoles(notificationFor, itemObserved, true);
List<User> notifyUsers = getListUserCompliantToRoles(notificationFor, itemObserved, false);
final SocialClients socialClients = new SocialClients();
CatalogueEventType catalogueEventType = MappingToCatalogue.toCatalogueEventType(itemPhase, lastInvokedStep);
CatalogueEventType catalogueEventType = MappingToCatalogue.toCatalogueEventType(itemPhase,
lastInvokedStep);
if (notifyUsers.size() > 0) {
log.info("Users compliant to role are: {}", notifyUsers.size());
@ -125,8 +126,9 @@ public class ManageDoActionNotification {
}
public static List<NotificationWhen> matchNotificationsAccordingItemStatus(NotificationFor notificationFor,
String itemPhase, String lastInvokedStep) {
log.info("Filtering notifications according to phase: {}, lastInvokedStep: {}", itemPhase, lastInvokedStep);
final String itemPhase, final String lastInvokedStep) {
log.info("Filtering notifications according to item status [phase: {}, lastInvokedStep: {}]", itemPhase,
lastInvokedStep);
List<NotificationWhen> filteredList = new ArrayList<NotificationWhen>();
@ -136,20 +138,29 @@ public class ManageDoActionNotification {
notificationWhen.getTarget_phase(), notificationWhen.getLast_invoked_step());
if (notificationWhen.getTarget_phase().contains(itemPhase) || notificationWhen.getTarget_phase()
.contains(NotificationGenericConstants.CUSTOM_TARGET_PHASE.Any.name())) {
if (notificationWhen.getLast_invoked_step() == null) {
log.debug("target phase: {} - matched", itemPhase);
String lastInvokedStepConfig = notificationWhen.getLast_invoked_step().trim();
log.debug("last_invoked_step read in config is {}", lastInvokedStepConfig);
if (lastInvokedStepConfig == null) {
log.debug("last_invoked_step is null or empty - {} matched", lastInvokedStep);
// no filtering on lastInvokedStep
filteredList.add(notificationWhen);
} else if (notificationWhen.getLast_invoked_step().compareToIgnoreCase(lastInvokedStep) == 0) {
}else if (lastInvokedStepConfig.contentEquals(lastInvokedStep)) {
log.debug("last_invoked_step: {} - matched", lastInvokedStep);
// matching the lastInvokedStep
filteredList.add(notificationWhen);
} else {
log.debug("last_invoked_step {} - NOT matched", lastInvokedStep);
}
} else {
log.debug("target phase: {} - NOT matched", itemPhase);
}
}
log.info("returning filtered list with {} object {}. If 0 returned no notifications is sent", filteredList.size(),
NotificationWhen.class.getSimpleName());
log.info("returning filtered list with {} object {} (if 0 returned no notifications is sent)",
filteredList.size(), NotificationWhen.class.getSimpleName());
return filteredList;
}

View File

@ -7,11 +7,13 @@ import java.util.stream.Collectors;
import org.gcube.application.cms.notifications.config.NotificationWhen;
import org.gcube.application.cms.notifications.config.Notify;
import org.gcube.application.cms.notifications.config.serviceaccount.GeoportalServiceAccount;
import org.gcube.application.cms.notifications.social.SocialClients;
import org.gcube.application.cms.notifications.substitutor.NMessagesPlaceholdersSubstitutorUtil;
import org.gcube.application.geoportal.common.model.document.accounting.User;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.portal.databook.shared.Post;
import org.gcube.social_networking.social_networking_client_library.NotificationClient;
import org.gcube.social_networking.socialnetworking.model.beans.PostInputBean;
@ -30,7 +32,8 @@ public class NotifyUsers {
private CatalogueEventType catalogueEventType;
public NotifyUsers(SocialClients socialClients, List<NotificationWhen> listWhen,
NMessagesPlaceholdersSubstitutorUtil nMPlaceholdersSUtil, List<User> recipientUsers, CatalogueEventType catalogueEventType) {
NMessagesPlaceholdersSubstitutorUtil nMPlaceholdersSUtil, List<User> recipientUsers,
CatalogueEventType catalogueEventType) {
this.socialClients = socialClients;
this.listNotificationWhen = listWhen;
this.recipientUsers = recipientUsers;
@ -38,7 +41,6 @@ public class NotifyUsers {
this.catalogueEventType = catalogueEventType;
}
public void sendNotification() throws Exception {
log.info("send notification...");
List<Notify> listNotifies = toNotify();
@ -90,25 +92,49 @@ public class NotifyUsers {
return listNotifies;
}
protected void postMessage(String subject, String bodyMessage, CatalogueEventType catalogueEventType) throws Exception {
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();
}
}
}
//GET geoportal SECRET
protected void sendNotification(CatalogueEvent catalogueEvent) throws Exception {
// Secret secret = Constants.getCatalogueSecret();
// if(notificationSentByGCat) {
// secretManager.startSession(secret);
// }
// try {
// sendNotification(catalogueEvent);
// }finally {
// if(notificationSentByGCat) {
// secretManager.endSession();
// }
// }
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 {
//sendNotification(catalogueEvent);
}
}
};
// 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 {
@ -117,7 +143,7 @@ public class NotifyUsers {
catalogueEvent.setNotifyText(bodyMessage);
catalogueEvent.setItemId(subject);
String itemURL = nMPlaceholdersSUtil.getPlaceholderMapValues().getGisLink();
if(itemURL!=null) {
if (itemURL != null) {
catalogueEvent.setItemURL(new URL(itemURL));
}
@ -129,29 +155,13 @@ public class NotifyUsers {
return catalogueEvent;
}
protected void sendNotification(CatalogueEvent catalogueEvent) throws Exception {
Thread thread = new Thread() {
public void run() {
try {
log.trace("{} 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);
}
}
};
// thread.run();
thread.start();
}
protected CatalogueEvent toCatalogueEvent(CatalogueEventType catalogueEventType, String messageString, String subject, String itemURL, List<String> users) throws Exception {
protected CatalogueEvent toCatalogueEvent(CatalogueEventType catalogueEventType, String messageString,
String subject, String itemURL, List<String> users) throws Exception {
CatalogueEvent catalogueEvent = new CatalogueEvent();
catalogueEvent.setType(catalogueEventType);
catalogueEvent.setNotifyText(messageString);
catalogueEvent.setItemId(subject);
if(itemURL!=null) {
if (itemURL != null) {
catalogueEvent.setItemURL(new URL(itemURL));
}
catalogueEvent.setIdsToNotify(users.toArray(new String[users.size()]));
@ -160,6 +170,4 @@ public class NotifyUsers {
return catalogueEvent;
}
}

View File

@ -75,11 +75,9 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
}
@Test
public void checkNotifications() {
//@Test
public void checkNotifications_LIFECYCLE_STEP_PERFORMED() {
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
// NotificationsPlugin plugin = (NotificationsPlugin)
// plugins.get(NotificationsPlugin.DESCRIPTOR.getId());
UseCaseDescriptor descriptor = TestProfiles.profiles.get("profiledConcessioni");
NotificationEventsSubscribedConfig notificationEventsSubs;
@ -94,6 +92,47 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
e.printStackTrace();
}
ItemObserved<Project> item = mockItemObserverd();
EventManager.Event event = Event.LIFECYCLE_STEP_PERFORMED;
item.setEvent(event);
LifecycleInformation lifecycleInfo = item.getProject().getLifecycleInformation();
//(Pending Approval, "SUBMIT-FOR-REVIEW")
// lifecycleInfo.setPhase("Pending Approval");
// lifecycleInfo.setLastInvokedStep("SUBMIT-FOR-REVIEW");
//(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);
}
private void sysOut(SubscribeNotificationEvent subscribeNotificationEvent) {
System.out.println("\n#SubscribeNotificationEvent - Event: " + subscribeNotificationEvent.getEvent());
List<NotificationFor> listNotificationFor = subscribeNotificationEvent.getNotificationFor();
for (NotificationFor notificationFor : listNotificationFor) {
System.out.println("\tNotificationFor - roles: " + notificationFor.getRoles());
for (NotificationWhen notificationWhen : notificationFor.getWhen()) {
System.out.println("\t\tNotificationWhen - Target_phase: " + notificationWhen.getTarget_phase()
+ ", Last_invoked_step: " + notificationWhen.getLast_invoked_step());
for (Notify notify : notificationWhen.getNotify()) {
System.out.println("\t\t\tNotify type : " + notify.getType());
System.out.println("\t\t\tNotify send : " + notify.getSend());
System.out.println("\t\t\tNotify placeholder_message : " + notify.getPlaceholder_msg());
if (notify.getExport_as_pdf() != null) {
System.out.println("\t\t\t\tExport as PDF : " + notify.getExport_as_pdf());
}
}
}
}
}
private static ItemObserved<Project> mockItemObserverd() {
UseCaseDescriptor descriptor = TestProfiles.profiles.get("profiledConcessioni");
// notifying the Event.PROJECT_CREATED;
ItemObserved<Project> item = new ItemObserved<Project>();
EventManager.Event event = Event.LIFECYCLE_STEP_PERFORMED;
@ -119,52 +158,51 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
testProject.setTheDocument(theDocument);
LifecycleInformation lifecycleInfo = new LifecycleInformation();
lifecycleInfo.setPhase("Pending Approval");
lifecycleInfo.setLastInvokedStep("SUBMIT-FOR-REVIEW");
//Pending Approval, "SUBMIT-FOR-REVIEW"
// lifecycleInfo.setPhase("Pending Approval");
// lifecycleInfo.setLastInvokedStep("SUBMIT-FOR-REVIEW");
lifecycleInfo.setPhase("DRAFT");
lifecycleInfo.setLastInvokedStep("REJECT-DRAFT");
testProject.setLifecycleInformation(lifecycleInfo);
item.setProject(testProject);
System.out.println("By notifying event " + event + " project " + item.getProjectId());
EventManager.getInstance().notify(event, item);
}
private void sysOut(SubscribeNotificationEvent subscribeNotificationEvent) {
System.out.println("\n#SubscribeNotificationEvent - Event: " + subscribeNotificationEvent.getEvent());
List<NotificationFor> listNotificationFor = subscribeNotificationEvent.getNotificationFor();
for (NotificationFor notificationFor : listNotificationFor) {
System.out.println("\tNotificationFor - roles: " + notificationFor.getRoles());
for (NotificationWhen notificationWhen : notificationFor.getWhen()) {
System.out.println("\t\tNotificationWhen - Target_phase: " + notificationWhen.getTarget_phase()
+ ", Last_invoked_step: " + notificationWhen.getLast_invoked_step());
for (Notify notify : notificationWhen.getNotify()) {
System.out.println("\t\t\tNotify type : " + notify.getType());
System.out.println("\t\t\tNotify send : " + notify.getSend());
System.out.println("\t\t\tNotify placeholder_message : " + notify.getPlaceholder_msg());
if (notify.getExport_as_pdf() != null) {
System.out.println("\t\t\t\tExport as PDF : " + notify.getExport_as_pdf());
}
}
}
}
return item;
}
//@Test
public void matchingNotificationTest() {
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
String itemPhase = "Pending Approval";
String lastInvokedStep = "SUBMIT-FOR-REVIEW";
// String itemPhase = "Pending Approval";
// String lastInvokedStep = "SUBMIT-FOR-REVIEW";
String itemPhase = "DRAFT";
String lastInvokedStep = "REJECT-DRAFT";
UseCaseDescriptor descriptor = TestProfiles.profiles.get("profiledConcessioni");
NotificationEventsSubscribedConfig notificationEventsSubs;
List<NotificationWhen> listWhen = new ArrayList<NotificationWhen>();
try {
System.out.println(NotificationEventsSubscribedConfig.class.getSimpleName() + ": ");
notificationEventsSubs = plugin.readNotificationsSubscribedFromConfigurationInTheUCD(descriptor);
List<SubscribeNotificationEvent> events = notificationEventsSubs.getListNotificationEventSubscribed();
for (SubscribeNotificationEvent subscribeNotificationEvent : events) {
for (NotificationFor notificationFor : subscribeNotificationEvent.getNotificationFor()) {
listWhen.addAll(ManageDoActionNotification.matchNotificationsAccordingItemStatus(notificationFor, itemPhase, lastInvokedStep));
}
}
} catch (Exception e) {
e.printStackTrace();
}
/*
SubscribeNotificationEvent sne = mockSubscribeNotificationEvent();
for (NotificationFor notificationFor : sne.getNotificationFor()) {
listWhen.addAll(ManageDoActionNotification.matchNotificationsAccordingItemStatus(notificationFor, itemPhase, lastInvokedStep));
}
*/
System.out.println("Filtered notifications: "+listWhen);
}
// @Test
@ -201,11 +239,16 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
NotificationFor notificatioFor = new NotificationFor();
notificatioFor.setRoles(Arrays.asList("Data-Manager"));
//Pending Approval, "SUBMIT-FOR-REVIEW"
List<NotificationWhen> listWhen = new ArrayList<NotificationWhen>();
NotificationWhen notificationWhen = new NotificationWhen();
notificationWhen.setTarget_phase(Arrays.asList("Pending Approval"));
notificationWhen.setLast_invoked_step("SUBMIT-FOR-REVIEW");
// notificationWhen.setTarget_phase(Arrays.asList("DRAFT"));
// notificationWhen.setLast_invoked_step("REJECT-DRAFT");
Notify notify = new Notify();
notify.setType(NOTIFICATION_TYPE.EMAIL);
notify.setSend(true);

View File

@ -2,9 +2,7 @@ import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.text.StringSubstitutor;
@ -31,7 +29,7 @@ public class StringReplacerTest {
public static String FILE_URL = "https://code-repo.d4science.org/gCubeSystem/gcube-cms-suite/raw/branch/event_manager/D4S_UCDs/DEV/devVRE/notifications/Notifications_Messages.properties";
@Test
//@Test
public void checkReplace() {
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());