in progess on defining the config

This commit is contained in:
Francesco Mangiacrapa 2024-02-01 12:22:34 +01:00
parent 49f7b248fb
commit a2c3f44dcd
5 changed files with 167 additions and 78 deletions

View File

@ -228,7 +228,7 @@ public class NotificationsPlugin extends AbstractPlugin implements EventListener
log.debug("Reading subscribed events from UCD");
NotificationEventsSubscribedConfig eventsSubscrInTheUCD = new NotificationEventsSubscribedConfig();
NotificationEventsSubscribedConfig notificationMapPerContext = new NotificationEventsSubscribedConfig();
if (useCaseDescriptor == null)
throw new Exception("Error reading UCD null found");
@ -237,11 +237,12 @@ public class NotificationsPlugin extends AbstractPlugin implements EventListener
String context = UserUtils.getCurrent().getContext();
eventsSubscrInTheUCD = getNotificationBindingMapPerContext();
List<SubscribeNotificationEvent> listNotificationEventsSubscribedPerUCD = new ArrayList<SubscribeNotificationEvent>();
if (eventsSubscrInTheUCD == null || listNotificationEventsSubscribedPerUCD.isEmpty()) {
notificationMapPerContext = getNotificationBindingMapPerContext();
List<SubscribeNotificationEvent> listNotificationEventsSubscribedPerUCD = notificationMapPerContext.getListNotificationEventSubscribed();
if (listNotificationEventsSubscribedPerUCD==null) {
listNotificationEventsSubscribedPerUCD = new ArrayList<SubscribeNotificationEvent>();
Document profileConfiguration = getConfigurationFromProfile(useCaseDescriptor).getConfiguration();
log.debug("UseCaseDescriptor Configuration is {} ", profileConfiguration);
// JSONPathWrapper schemaNavigator = new
@ -249,26 +250,31 @@ public class NotificationsPlugin extends AbstractPlugin implements EventListener
for (Object fsConfigObj : profileConfiguration.get(SUBSCRIBE_NOTIFICATIONS_CONFIG, List.class)) {
log.debug("Managing {} ", fsConfigObj);
SubscribeNotificationEvent fsConfig = Serialization.read(fsConfigObj.toString(),
SubscribeNotificationEvent fsConfig = Serialization.convert(fsConfigObj,
SubscribeNotificationEvent.class);
log.debug("Converted config {}", fsConfig);
String theEventSubsribed = fsConfig.getEvent();
if (theEventSubsribed == null || theEventSubsribed.isEmpty())
throw new MaterializationException(
"Invalid Field Definition path in configuration [NO MATCH] : " + fsConfig.getEvent());
SubscribeNotificationEvent event = Serialization.convert(theEventSubsribed,
SubscribeNotificationEvent.class);
log.debug("Added event {} to list ", event);
listNotificationEventsSubscribedPerUCD.add(event);
"Invalid Field Definition path in configuration null or empty event : " + theEventSubsribed);
try {
Event event = Serialization.convert(theEventSubsribed, Event.class);
log.debug("Added event {} to list ", event);
listNotificationEventsSubscribedPerUCD.add(fsConfig);
}catch (Exception e) {
log.error("MaterializationException: ", e);
throw new MaterializationException(
"Invalid Event Definition path in configuration [NO MATCH] : " + fsConfig.getEvent());
}
}
eventsSubscrInTheUCD = new NotificationEventsSubscribedConfig();
eventsSubscrInTheUCD.setContext(context);
eventsSubscrInTheUCD.setListNotificationEventSubscribed(listNotificationEventsSubscribedPerUCD);
notificationEventsBindingMap.put(context, eventsSubscrInTheUCD);
notificationMapPerContext = new NotificationEventsSubscribedConfig();
notificationMapPerContext.setContext(context);
notificationMapPerContext.setListNotificationEventSubscribed(listNotificationEventsSubscribedPerUCD);
notificationEventsBindingMap.put(context, notificationMapPerContext);
log.info("Events subscribed read from config {} ", eventsSubscrInTheUCD);
log.info("Events subscribed read from config {} ", notificationMapPerContext);
}
@ -278,7 +284,7 @@ public class NotificationsPlugin extends AbstractPlugin implements EventListener
log.error("Exception, Unable to read configuration ", t);
}
return eventsSubscrInTheUCD;
return notificationMapPerContext;
}
/**

View File

@ -14,6 +14,6 @@ import lombok.Data;
public class NotificationWhen {
List<String> target_phase;
Notify notify;
List<Notify> notify;
}

View File

@ -9,11 +9,10 @@ import lombok.Data;
*
*
{
"send_personal_nofitication": false,
"send_email": true,
"send_pdf_document": false,
"post_on_vre": false,
"message": "ID_MESSAGE_1"
"type": "NOTIFICATION_TYPE",
"send": "true/false",
"attach_pdf_document": "true/false",
"message": "PLACEHOLDER_MESSAGE_1"
}
*
*/
@ -21,9 +20,9 @@ import lombok.Data;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Notify {
Boolean send_personal_nofitication;
Boolean send_email;
Boolean send_pdf_document;
Boolean post_on_vre;
public static enum NOTIFICATION_TYPE {PERSONAL_POST, EMAIL, VRE_POST, ANY}
NOTIFICATION_TYPE type;
Boolean send;
Boolean attach_pdf_document;
String message;
}

View File

@ -16,42 +16,49 @@ import lombok.Data;
/**
* Instantiates a new subscribe notification config.
*
* {
* "event": "EVENT_NAME",
* "for": [
* {
* "roles": [
* "USER_ROLE"
* ],
* "when": [
* {
* "target_phase": [
* "TARGET_PHASE"
* ],
* "notify": {
* "send_personal_nofitication": "true/false",
* "send_email": "true/false",
* "send_pdf_document": "true/false",
* "post_on_vre": "true/false",
* "message": "ID_MESSAGE_1"
* }
* },
* {
* "target_phase": [
* "TARGET_PHASE"
* ],
* "notify": {
* "send_personal_nofitication": "true/false",
* "send_email": "true/false",
* "send_pdf_document": "true/false",
* "post_on_vre": "true/false",
* "message": "ID_MESSAGE_2"
* }
* }
* ]
* }
* ]
* }
{
"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"
}
*
*/

View File

@ -9,6 +9,7 @@ import org.gcube.application.cms.notifications.NotificationsPlugin;
import org.gcube.application.cms.notifications.config.NotificationFor;
import org.gcube.application.cms.notifications.config.NotificationWhen;
import org.gcube.application.cms.notifications.config.Notify;
import org.gcube.application.cms.notifications.config.Notify.NOTIFICATION_TYPE;
import org.gcube.application.cms.notifications.config.SubscribeNotificationEvent;
import org.gcube.application.cms.plugins.faults.InitializationException;
import org.gcube.application.cms.serialization.Serialization;
@ -42,7 +43,7 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
}
//@Test
@Test
public void checkPluginConfig() {
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
NotificationsPlugin plugin = (NotificationsPlugin) plugins.get(NotificationsPlugin.DESCRIPTOR.getId());
@ -71,7 +72,7 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
}
//@Test
public void checkDeserialize() {
public void checkSerializeDeserialize() {
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
SubscribeNotificationEvent sne = new SubscribeNotificationEvent();
@ -87,12 +88,11 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
notificationWhen.setTarget_phase(Arrays.asList("Pending Approval"));
Notify notify = new Notify();
notify.setSend_personal_nofitication(false);
notify.setPost_on_vre(false);
notify.setSend_email(false);
notify.setSend_personal_nofitication(false);
notify.setType(NOTIFICATION_TYPE.EMAIL);
notify.setSend(true);
notify.setAttach_pdf_document(true);
notify.setMessage("message");
notificationWhen.setNotify(notify);
notificationWhen.setNotify(Arrays.asList(notify));
listWhen.add(notificationWhen);
notificatioFor.setWhen(listWhen);
@ -111,13 +111,12 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
//Test Notify
/*
String testNotify = " {\n"
+ " \"send_personal_nofitication\": false,\n"
+ " \"send_email\": true,\n"
+ " \"send_pdf_document\": false,\n"
+ " \"post_on_vre\": false,\n"
+ " \"message\": \"ID_MESSAGE_1\"\n"
+ " }";
String testNotify = "{\n"
+ " \"type\": \"EMAIL\",\n"
+ " \"send\": true,\n"
+ " \"attach_pdf_document\": false,\n"
+ " \"message\": \"The project ${project_name} has just been rejected by ${user}\"\n"
+ "}";
System.out.println("String :"+testNotify);
Notify serialize = Serialization.read(testNotify, Notify.class);
@ -158,6 +157,84 @@ public class CatalogueBindingPluginTest extends BasicPluginTest {
System.out.println("Ser from JSON :"+serializeNotificationWhen);
*/
String testSubribeNotifications = "{\n"
+ " \"event\": \"LIFECYCLE_STEP_PERFORMED\",\n"
+ " \"notificationFor\": [\n"
+ " {\n"
+ " \"roles\": [\n"
+ " \"Data-Manager\"\n"
+ " ],\n"
+ " \"when\": [\n"
+ " {\n"
+ " \"target_phase\": [\n"
+ " \"Pending Approval\"\n"
+ " ],\n"
+ " \"notify\": [\n"
+ " {\n"
+ " \"type\": \"EMAIL\",\n"
+ " \"send\": true,\n"
+ " \"attach_pdf_document\": false,\n"
+ " \"message\": \"${user} created the project ${project_name}. You are kindly requested to review it and decide either to APPROVE or REJECT it. See it at @link\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " {\n"
+ " \"target_phase\": [\n"
+ " \"Rejected\"\n"
+ " ],\n"
+ " \"notify\": [\n"
+ " {\n"
+ " \"type\": \"EMAIL\",\n"
+ " \"send\": true,\n"
+ " \"attach_pdf_document\": false,\n"
+ " \"message\": \"The project ${project_name} has just been rejected by ${user}\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " {\n"
+ " \"roles\": [\n"
+ " \"Item_Creator\"\n"
+ " ],\n"
+ " \"when\": [\n"
+ " {\n"
+ " \"target_phase\": [\n"
+ " \"Rejected\"\n"
+ " ],\n"
+ " \"notify\": [\n"
+ " {\n"
+ " \"type\": \"EMAIL\",\n"
+ " \"send\": true,\n"
+ " \"attach_pdf_document\": false,\n"
+ " \"message\": \"The project ${project_name} has just been rejected. You are kindly requested to review it\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " {\n"
+ " \"target_phase\": [\n"
+ " \"Published\"\n"
+ " ],\n"
+ " \"notify\": [\n"
+ " {\n"
+ " \"type\": \"EMAIL\",\n"
+ " \"send\": true,\n"
+ " \"attach_pdf_document\": false,\n"
+ " \"message\": \"The project ${project_name} has just been published. See it at @link\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " ]\n"
+ "}";
testSubribeNotifications = "{event=LIFECYCLE_STEP_PERFORMED, notificationFor=[{roles=[Data-Manager], when=[{target_phase=[Pending Approval], notify=[{type=EMAIL, send=true, attach_pdf_document=false, message=${user} created the project ${project_name}. You are kindly requested to review it and decide either to APPROVE or REJECT it. See it at @link}]}, {target_phase=[Rejected], notify=[{type=EMAIL, send=true, attach_pdf_document=false, message=The project ${project_name} has just been rejected by ${user}}]}]}, {roles=[Item_Creator], when=[{target_phase=[Rejected], notify=[{type=EMAIL, send=true, attach_pdf_document=false, message=The project ${project_name} has just been rejected. You are kindly requested to review it}]}, {target_phase=[Published], notify=[{type=EMAIL, send=true, attach_pdf_document=false, message=The project ${project_name} has just been published. See it at @link}]}]}]}";
System.out.println("String :"+testSubribeNotifications);
SubscribeNotificationEvent serializeSubscribeNotificationEvent = Serialization.convert(testSubribeNotifications, SubscribeNotificationEvent.class);
System.out.println("Ser from JSON :"+serializeSubscribeNotificationEvent);
} catch (JsonProcessingException e) {