diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/events/ItemObserved.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/events/ItemObserved.java index 87d0e67..d7d9f8c 100644 --- a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/events/ItemObserved.java +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/events/ItemObserved.java @@ -14,7 +14,6 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import lombok.ToString; import lombok.extern.slf4j.Slf4j; @Getter @@ -22,9 +21,8 @@ import lombok.extern.slf4j.Slf4j; @NoArgsConstructor @AllArgsConstructor @Slf4j -@ToString public class ItemObserved implements ItemObservable { - + private User userCaller; private Context context; private UseCaseDescriptor useCaseDescriptor; @@ -32,6 +30,10 @@ public class ItemObserved implements ItemObservable { private EventManager.Event event; private Document optional; + public static enum OPTIONAL_FIELD { + message, preview_url + } + public String getProjectId() { log.debug("Called getProjectId"); if (project == null) @@ -70,15 +72,18 @@ public class ItemObserved implements ItemObservable { return documentAsMap; } - - public void setOptionalMessage(String message){ + + public void setOptional(OPTIONAL_FIELD optionalField, String value) { 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(){ - if(this.optional!=null) { - return (String) this.optional.getOrDefault("message", null); + + public String getOptionalValue(OPTIONAL_FIELD optionalField) { + if (this.optional != null) { + return this.optional.getString(optionalField.name()); } return null; } @@ -91,9 +96,9 @@ public class ItemObserved implements ItemObservable { builder.append(", context="); builder.append(context); 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!=null?project.getId():null); + builder.append(project != null ? project.getId() : null); builder.append(", event="); builder.append(event); builder.append(", optional="); diff --git a/default-lc-managers/src/test/java/org/gcube/application/cms/plugins/SimpleLifecycleTests.java b/default-lc-managers/src/test/java/org/gcube/application/cms/plugins/SimpleLifecycleTests.java index 9db753a..d78291a 100644 --- a/default-lc-managers/src/test/java/org/gcube/application/cms/plugins/SimpleLifecycleTests.java +++ b/default-lc-managers/src/test/java/org/gcube/application/cms/plugins/SimpleLifecycleTests.java @@ -14,7 +14,7 @@ public class SimpleLifecycleTests { // public void testFullCycle(){ // SimpleLifeCycleManager manager = plugins.get(SimpleLifeCycleManager.PLUGIN_ID); // -// StepExecutionRequest request = new StepExecutionRequest(); +// PerformStepRequest request = new PerformStepRequest(); // // Project p = null; // diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java index f47b07d..ecbf0c9 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java @@ -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.Event; 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.geoportal.common.model.configuration.Configuration; import org.gcube.application.geoportal.common.model.document.Project; @@ -131,7 +132,7 @@ public class ProfiledDocuments { AccountingInfo user = UserUtils.getCurrent().asInfo(); item.setUserCaller(user.getUser()); item.setContext(user.getContext()); - item.setOptionalMessage(null); + item.setOptional(null); item.setEvent(event); item.setProject(theNewProject); item.setUseCaseDescriptor(manager.getUseCaseDescriptor()); @@ -171,7 +172,7 @@ public class ProfiledDocuments { AccountingInfo user = UserUtils.getCurrent().asInfo(); item.setUserCaller(user.getUser()); item.setContext(user.getContext()); - item.setOptionalMessage(null); + item.setOptional(null); item.setEvent(event); item.setProject(theUpdatedProject); item.setUseCaseDescriptor(manager.getUseCaseDescriptor()); @@ -332,7 +333,7 @@ public class ProfiledDocuments { item.setUserCaller(user.getUser()); item.setContext(user.getContext()); item.setEvent(event); - item.setOptionalMessage(performStepRequest.getMessage()); + item.setOptional(OPTIONAL_FIELD.message, performStepRequest.getMessage()); item.setUseCaseDescriptor(manager.getUseCaseDescriptor()); item.setProject(theProject); log.info("By notifying event ({}, ID {})", event, item.getProjectId()); diff --git a/notifications-plugins/pom.xml b/notifications-plugins/pom.xml index f6b712e..efa7f64 100644 --- a/notifications-plugins/pom.xml +++ b/notifications-plugins/pom.xml @@ -70,6 +70,19 @@ commons-text 1.11.0 + + + + + + + + + javax.xml.ws + jaxws-api + test + + org.gcube.application.cms cms-test-commons diff --git a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/NotifyToSocial.java b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/NotifyToSocial.java index b5576a4..325bd90 100644 --- a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/NotifyToSocial.java +++ b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/manage/NotifyToSocial.java @@ -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.substitutor.NMessagesPlaceholdersSubstitutorUtil; 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.accounting.User; import org.gcube.common.authorization.utils.manager.SecretManager; @@ -61,8 +62,9 @@ public class NotifyToSocial { subject = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_title()); body = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_msg()); - if (itemObserved.getOptionalMessage() != null) { - body += "\n" + itemObserved.getOptionalMessage(); + String optionalMessage = itemObserved.getOptionalValue(OPTIONAL_FIELD.message); + if (optionalMessage != null) { + body += "\n" + optionalMessage; } log.info("Going to send notification to users: {}", recipientUsers); @@ -78,12 +80,24 @@ public class NotifyToSocial { PostInputBean toWrite = new PostInputBean(); 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) + + if (title != null) { 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); } @@ -106,14 +120,14 @@ public class NotifyToSocial { 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); + + String bodyWithTag = toWrite.getText() + "\n#" + geoportalSecret.getUser().getUsername(); + log.debug("body with tag: {}", bodyWithTag); + toWrite.setText(bodyWithTag); toWrite.setEnablenotification(true); - - log.info("Calling social - going to write user post: {}", toWrite); - Post thePost = socialClients.writeUserPost(toWrite); + + log.info("Calling social - going to write application post: {}", toWrite); + Post thePost = socialClients.writeApplication(toWrite); log.info("{} post created: {} ", notify.getType(), thePost); } catch (Exception e) { diff --git a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/social/SocialClients.java b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/social/SocialClients.java index 207188a..697295a 100644 --- a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/social/SocialClients.java +++ b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/social/SocialClients.java @@ -49,7 +49,7 @@ public class SocialClients { } catch (Exception e) { log.error("Error on instacing {}: ", UserClient.class.getSimpleName(), e); } - + try { this.notificationClient = new NotificationClient(); } catch (Exception e) { @@ -99,22 +99,48 @@ public class SocialClients { 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() { return postClient; } + /** + * Gets the messages client. + * + * @return the messages client + */ public MessageClient getMessagesClient() { return messagesClient; } + /** + * Gets the user client. + * + * @return the user client + */ public UserClient getUserClient() { return userClient; } - + + /** + * Gets the notification client. + * + * @return the notification client + */ public NotificationClient getNotificationClient() { return notificationClient; } diff --git a/notifications-plugins/src/test/java/NotificationsPluginTest.java b/notifications-plugins/src/test/java/NotificationsPluginTest.java index 97ca4c7..9c6b73d 100644 --- a/notifications-plugins/src/test/java/NotificationsPluginTest.java +++ b/notifications-plugins/src/test/java/NotificationsPluginTest.java @@ -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.Event; 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.serialization.Serialization; import org.gcube.application.cms.tests.TestProfiles; @@ -48,7 +49,7 @@ public class NotificationsPluginTest extends BasicPluginTest { /** * Check plugin. */ - @Before + //@Before public void checkPlugin() { org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled()); plugin = (NotificationsPlugin) plugins.get(NotificationsPlugin.DESCRIPTOR.getId()); @@ -171,7 +172,7 @@ public class NotificationsPluginTest extends BasicPluginTest { /** * Check the VRE POST */ - @Test + //@Test public void checkNotifications_LIFECYCLE_STEP_PERFORMED_TO_APPROVE_SUBMITTED() { org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled()); UseCaseDescriptor descriptor = TestProfiles.profiles.get("profiledConcessioni"); @@ -192,7 +193,7 @@ public class NotificationsPluginTest extends BasicPluginTest { //Setting creator User creator = new User(); - creator.setUsername("massimiliano.assante"); + creator.setUsername("francesco.mangiacrapa"); item.getProject().getInfo().getCreationInfo().setUser(creator); EventManager.Event event = Event.LIFECYCLE_STEP_PERFORMED; @@ -279,7 +280,7 @@ public class NotificationsPluginTest extends BasicPluginTest { item.setProject(testProject); - item.setOptionalMessage("My great message"); + item.setOptional(OPTIONAL_FIELD.message, "Il mio grande progetto"); return item; }