updated ItemObserverd. Completed the Notification-Plugin
This commit is contained in:
parent
6202bb71fe
commit
93576e5b19
|
@ -14,7 +14,6 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
@ -22,9 +21,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ToString
|
|
||||||
public class ItemObserved<T extends Project> implements ItemObservable {
|
public class ItemObserved<T extends Project> implements ItemObservable {
|
||||||
|
|
||||||
private User userCaller;
|
private User userCaller;
|
||||||
private Context context;
|
private Context context;
|
||||||
private UseCaseDescriptor useCaseDescriptor;
|
private UseCaseDescriptor useCaseDescriptor;
|
||||||
|
@ -32,6 +30,10 @@ public class ItemObserved<T extends Project> implements ItemObservable {
|
||||||
private EventManager.Event event;
|
private EventManager.Event event;
|
||||||
private Document optional;
|
private Document optional;
|
||||||
|
|
||||||
|
public static enum OPTIONAL_FIELD {
|
||||||
|
message, preview_url
|
||||||
|
}
|
||||||
|
|
||||||
public String getProjectId() {
|
public String getProjectId() {
|
||||||
log.debug("Called getProjectId");
|
log.debug("Called getProjectId");
|
||||||
if (project == null)
|
if (project == null)
|
||||||
|
@ -70,15 +72,18 @@ public class ItemObserved<T extends Project> implements ItemObservable {
|
||||||
|
|
||||||
return documentAsMap;
|
return documentAsMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOptionalMessage(String message){
|
public void setOptional(OPTIONAL_FIELD optionalField, String value) {
|
||||||
this.optional = new Document();
|
this.optional = new Document();
|
||||||
this.optional.put("message", message);
|
if (optional == null)
|
||||||
|
this.optional = new Document();
|
||||||
|
|
||||||
|
this.optional.put(optionalField.name(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOptionalMessage(){
|
public String getOptionalValue(OPTIONAL_FIELD optionalField) {
|
||||||
if(this.optional!=null) {
|
if (this.optional != null) {
|
||||||
return (String) this.optional.getOrDefault("message", null);
|
return this.optional.getString(optionalField.name());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -91,9 +96,9 @@ public class ItemObserved<T extends Project> implements ItemObservable {
|
||||||
builder.append(", context=");
|
builder.append(", context=");
|
||||||
builder.append(context);
|
builder.append(context);
|
||||||
builder.append(", useCaseDescriptor id=");
|
builder.append(", useCaseDescriptor id=");
|
||||||
builder.append(useCaseDescriptor!=null?useCaseDescriptor.getId():null);
|
builder.append(useCaseDescriptor != null ? useCaseDescriptor.getId() : null);
|
||||||
builder.append(", project id=");
|
builder.append(", project id=");
|
||||||
builder.append(project!=null?project.getId():null);
|
builder.append(project != null ? project.getId() : null);
|
||||||
builder.append(", event=");
|
builder.append(", event=");
|
||||||
builder.append(event);
|
builder.append(event);
|
||||||
builder.append(", optional=");
|
builder.append(", optional=");
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class SimpleLifecycleTests {
|
||||||
// public void testFullCycle(){
|
// public void testFullCycle(){
|
||||||
// SimpleLifeCycleManager manager = plugins.get(SimpleLifeCycleManager.PLUGIN_ID);
|
// SimpleLifeCycleManager manager = plugins.get(SimpleLifeCycleManager.PLUGIN_ID);
|
||||||
//
|
//
|
||||||
// StepExecutionRequest request = new StepExecutionRequest();
|
// PerformStepRequest request = new PerformStepRequest();
|
||||||
//
|
//
|
||||||
// Project p = null;
|
// Project p = null;
|
||||||
//
|
//
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.gcube.application.cms.implementations.utils.UserUtils;
|
||||||
import org.gcube.application.cms.plugins.events.EventManager;
|
import org.gcube.application.cms.plugins.events.EventManager;
|
||||||
import org.gcube.application.cms.plugins.events.EventManager.Event;
|
import org.gcube.application.cms.plugins.events.EventManager.Event;
|
||||||
import org.gcube.application.cms.plugins.events.ItemObserved;
|
import org.gcube.application.cms.plugins.events.ItemObserved;
|
||||||
|
import org.gcube.application.cms.plugins.events.ItemObserved.OPTIONAL_FIELD;
|
||||||
import org.gcube.application.cms.serialization.Serialization;
|
import org.gcube.application.cms.serialization.Serialization;
|
||||||
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
||||||
import org.gcube.application.geoportal.common.model.document.Project;
|
import org.gcube.application.geoportal.common.model.document.Project;
|
||||||
|
@ -131,7 +132,7 @@ public class ProfiledDocuments {
|
||||||
AccountingInfo user = UserUtils.getCurrent().asInfo();
|
AccountingInfo user = UserUtils.getCurrent().asInfo();
|
||||||
item.setUserCaller(user.getUser());
|
item.setUserCaller(user.getUser());
|
||||||
item.setContext(user.getContext());
|
item.setContext(user.getContext());
|
||||||
item.setOptionalMessage(null);
|
item.setOptional(null);
|
||||||
item.setEvent(event);
|
item.setEvent(event);
|
||||||
item.setProject(theNewProject);
|
item.setProject(theNewProject);
|
||||||
item.setUseCaseDescriptor(manager.getUseCaseDescriptor());
|
item.setUseCaseDescriptor(manager.getUseCaseDescriptor());
|
||||||
|
@ -171,7 +172,7 @@ public class ProfiledDocuments {
|
||||||
AccountingInfo user = UserUtils.getCurrent().asInfo();
|
AccountingInfo user = UserUtils.getCurrent().asInfo();
|
||||||
item.setUserCaller(user.getUser());
|
item.setUserCaller(user.getUser());
|
||||||
item.setContext(user.getContext());
|
item.setContext(user.getContext());
|
||||||
item.setOptionalMessage(null);
|
item.setOptional(null);
|
||||||
item.setEvent(event);
|
item.setEvent(event);
|
||||||
item.setProject(theUpdatedProject);
|
item.setProject(theUpdatedProject);
|
||||||
item.setUseCaseDescriptor(manager.getUseCaseDescriptor());
|
item.setUseCaseDescriptor(manager.getUseCaseDescriptor());
|
||||||
|
@ -332,7 +333,7 @@ public class ProfiledDocuments {
|
||||||
item.setUserCaller(user.getUser());
|
item.setUserCaller(user.getUser());
|
||||||
item.setContext(user.getContext());
|
item.setContext(user.getContext());
|
||||||
item.setEvent(event);
|
item.setEvent(event);
|
||||||
item.setOptionalMessage(performStepRequest.getMessage());
|
item.setOptional(OPTIONAL_FIELD.message, performStepRequest.getMessage());
|
||||||
item.setUseCaseDescriptor(manager.getUseCaseDescriptor());
|
item.setUseCaseDescriptor(manager.getUseCaseDescriptor());
|
||||||
item.setProject(theProject);
|
item.setProject(theProject);
|
||||||
log.info("By notifying event ({}, ID {})", event, item.getProjectId());
|
log.info("By notifying event ({}, ID {})", event, item.getProjectId());
|
||||||
|
|
|
@ -70,6 +70,19 @@
|
||||||
<artifactId>commons-text</artifactId>
|
<artifactId>commons-text</artifactId>
|
||||||
<version>1.11.0</version>
|
<version>1.11.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- Fix the issue with JUnit tests: java.lang.NoClassDefFoundError : javax/xml/soap/SOAPException -->
|
||||||
|
<!-- <dependency> -->
|
||||||
|
<!-- <groupId>javax.xml.soap</groupId> -->
|
||||||
|
<!-- <artifactId>javax.xml.soap-api</artifactId> -->
|
||||||
|
<!-- <version>1.4.0</version> -->
|
||||||
|
<!-- </dependency> -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.xml.ws</groupId>
|
||||||
|
<artifactId>jaxws-api</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.application.cms</groupId>
|
<groupId>org.gcube.application.cms</groupId>
|
||||||
<artifactId>cms-test-commons</artifactId>
|
<artifactId>cms-test-commons</artifactId>
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.gcube.application.cms.notifications.config.serviceaccount.GeoportalSe
|
||||||
import org.gcube.application.cms.notifications.social.SocialClients;
|
import org.gcube.application.cms.notifications.social.SocialClients;
|
||||||
import org.gcube.application.cms.notifications.substitutor.NMessagesPlaceholdersSubstitutorUtil;
|
import org.gcube.application.cms.notifications.substitutor.NMessagesPlaceholdersSubstitutorUtil;
|
||||||
import org.gcube.application.cms.plugins.events.ItemObserved;
|
import org.gcube.application.cms.plugins.events.ItemObserved;
|
||||||
|
import org.gcube.application.cms.plugins.events.ItemObserved.OPTIONAL_FIELD;
|
||||||
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.User;
|
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.SecretManager;
|
||||||
|
@ -61,8 +62,9 @@ public class NotifyToSocial {
|
||||||
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());
|
||||||
|
|
||||||
if (itemObserved.getOptionalMessage() != null) {
|
String optionalMessage = itemObserved.getOptionalValue(OPTIONAL_FIELD.message);
|
||||||
body += "\n" + itemObserved.getOptionalMessage();
|
if (optionalMessage != null) {
|
||||||
|
body += "\n" + optionalMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("Going to send notification to users: {}", recipientUsers);
|
log.info("Going to send notification to users: {}", recipientUsers);
|
||||||
|
@ -78,12 +80,24 @@ public class NotifyToSocial {
|
||||||
PostInputBean toWrite = new PostInputBean();
|
PostInputBean toWrite = new PostInputBean();
|
||||||
String title = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_title());
|
String title = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_title());
|
||||||
String body = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_msg());
|
String body = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_msg());
|
||||||
if (itemObserved.getOptionalMessage() != null) {
|
|
||||||
body += "\n" + itemObserved.getOptionalMessage();
|
if (title != null) {
|
||||||
}
|
|
||||||
toWrite.setText(body);
|
|
||||||
if (title != null)
|
|
||||||
toWrite.setPreviewtitle(title);
|
toWrite.setPreviewtitle(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
String optionalMessage = itemObserved.getOptionalValue(OPTIONAL_FIELD.message);
|
||||||
|
|
||||||
|
if (optionalMessage != null) {
|
||||||
|
body += "\n" + optionalMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
toWrite.setText(body);
|
||||||
|
|
||||||
|
String previewURL = itemObserved.getOptionalValue(OPTIONAL_FIELD.preview_url);
|
||||||
|
System.out.println("previewURL: "+previewURL);
|
||||||
|
if (previewURL != null) {
|
||||||
|
toWrite.setPreviewurl(previewURL);
|
||||||
|
}
|
||||||
|
|
||||||
vrePost(toWrite, notify);
|
vrePost(toWrite, notify);
|
||||||
}
|
}
|
||||||
|
@ -106,14 +120,14 @@ public class NotifyToSocial {
|
||||||
secretManager.startSession(geoportalSecret);
|
secretManager.startSession(geoportalSecret);
|
||||||
log.debug("{} is going to send vrePost {}", SecretManagerProvider.instance.get().getUser().getUsername(),
|
log.debug("{} is going to send vrePost {}", SecretManagerProvider.instance.get().getUser().getUsername(),
|
||||||
toWrite);
|
toWrite);
|
||||||
|
|
||||||
// String bodyWithTag = toWrite.getText() + "\n #" + geoportalSecret.getUser().getUsername();
|
String bodyWithTag = toWrite.getText() + "\n#" + geoportalSecret.getUser().getUsername();
|
||||||
// log.debug("body with tag: {}", bodyWithTag);
|
log.debug("body with tag: {}", bodyWithTag);
|
||||||
// toWrite.setText(bodyWithTag);
|
toWrite.setText(bodyWithTag);
|
||||||
toWrite.setEnablenotification(true);
|
toWrite.setEnablenotification(true);
|
||||||
|
|
||||||
log.info("Calling social - going to write user post: {}", toWrite);
|
log.info("Calling social - going to write application post: {}", toWrite);
|
||||||
Post thePost = socialClients.writeUserPost(toWrite);
|
Post thePost = socialClients.writeApplication(toWrite);
|
||||||
log.info("{} post created: {} ", notify.getType(), thePost);
|
log.info("{} post created: {} ", notify.getType(), thePost);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class SocialClients {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error on instacing {}: ", UserClient.class.getSimpleName(), e);
|
log.error("Error on instacing {}: ", UserClient.class.getSimpleName(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.notificationClient = new NotificationClient();
|
this.notificationClient = new NotificationClient();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -99,22 +99,48 @@ public class SocialClients {
|
||||||
return postClient.writeUserPost(toWrite);
|
return postClient.writeUserPost(toWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static org.slf4j.Logger getLog() {
|
/**
|
||||||
return log;
|
* Write application.
|
||||||
|
*
|
||||||
|
* @param toWrite the to write
|
||||||
|
* @return the post
|
||||||
|
*/
|
||||||
|
public Post writeApplication(PostInputBean toWrite) {
|
||||||
|
return postClient.writeApplicationPost(toWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the post client.
|
||||||
|
*
|
||||||
|
* @return the post client
|
||||||
|
*/
|
||||||
public PostClient getPostClient() {
|
public PostClient getPostClient() {
|
||||||
return postClient;
|
return postClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the messages client.
|
||||||
|
*
|
||||||
|
* @return the messages client
|
||||||
|
*/
|
||||||
public MessageClient getMessagesClient() {
|
public MessageClient getMessagesClient() {
|
||||||
return messagesClient;
|
return messagesClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the user client.
|
||||||
|
*
|
||||||
|
* @return the user client
|
||||||
|
*/
|
||||||
public UserClient getUserClient() {
|
public UserClient getUserClient() {
|
||||||
return userClient;
|
return userClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the notification client.
|
||||||
|
*
|
||||||
|
* @return the notification client
|
||||||
|
*/
|
||||||
public NotificationClient getNotificationClient() {
|
public NotificationClient getNotificationClient() {
|
||||||
return notificationClient;
|
return notificationClient;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.gcube.application.cms.notifications.manage.ManageDoActionNotification
|
||||||
import org.gcube.application.cms.plugins.events.EventManager;
|
import org.gcube.application.cms.plugins.events.EventManager;
|
||||||
import org.gcube.application.cms.plugins.events.EventManager.Event;
|
import org.gcube.application.cms.plugins.events.EventManager.Event;
|
||||||
import org.gcube.application.cms.plugins.events.ItemObserved;
|
import org.gcube.application.cms.plugins.events.ItemObserved;
|
||||||
|
import org.gcube.application.cms.plugins.events.ItemObserved.OPTIONAL_FIELD;
|
||||||
import org.gcube.application.cms.plugins.faults.InitializationException;
|
import org.gcube.application.cms.plugins.faults.InitializationException;
|
||||||
import org.gcube.application.cms.serialization.Serialization;
|
import org.gcube.application.cms.serialization.Serialization;
|
||||||
import org.gcube.application.cms.tests.TestProfiles;
|
import org.gcube.application.cms.tests.TestProfiles;
|
||||||
|
@ -48,7 +49,7 @@ public class NotificationsPluginTest extends BasicPluginTest {
|
||||||
/**
|
/**
|
||||||
* Check 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());
|
||||||
|
@ -171,7 +172,7 @@ public class NotificationsPluginTest extends BasicPluginTest {
|
||||||
/**
|
/**
|
||||||
* Check the VRE POST
|
* Check the VRE POST
|
||||||
*/
|
*/
|
||||||
@Test
|
//@Test
|
||||||
public void checkNotifications_LIFECYCLE_STEP_PERFORMED_TO_APPROVE_SUBMITTED() {
|
public void checkNotifications_LIFECYCLE_STEP_PERFORMED_TO_APPROVE_SUBMITTED() {
|
||||||
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
UseCaseDescriptor descriptor = TestProfiles.profiles.get("profiledConcessioni");
|
UseCaseDescriptor descriptor = TestProfiles.profiles.get("profiledConcessioni");
|
||||||
|
@ -192,7 +193,7 @@ public class NotificationsPluginTest extends BasicPluginTest {
|
||||||
|
|
||||||
//Setting creator
|
//Setting creator
|
||||||
User creator = new User();
|
User creator = new User();
|
||||||
creator.setUsername("massimiliano.assante");
|
creator.setUsername("francesco.mangiacrapa");
|
||||||
item.getProject().getInfo().getCreationInfo().setUser(creator);
|
item.getProject().getInfo().getCreationInfo().setUser(creator);
|
||||||
|
|
||||||
EventManager.Event event = Event.LIFECYCLE_STEP_PERFORMED;
|
EventManager.Event event = Event.LIFECYCLE_STEP_PERFORMED;
|
||||||
|
@ -279,7 +280,7 @@ public class NotificationsPluginTest extends BasicPluginTest {
|
||||||
item.setProject(testProject);
|
item.setProject(testProject);
|
||||||
|
|
||||||
|
|
||||||
item.setOptionalMessage("My great message");
|
item.setOptional(OPTIONAL_FIELD.message, "Il mio grande progetto");
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue