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 325bd90..a698552 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 @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import org.gcube.application.cms.notifications.config.ExportAsPDF; 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; @@ -18,6 +19,7 @@ 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.portlets.user.uriresolvermanager.geoportal.GeoportalExporterAPI; import org.gcube.social_networking.social_networking_client_library.NotificationClient; import org.gcube.social_networking.socialnetworking.model.beans.PostInputBean; import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEvent; @@ -54,6 +56,7 @@ public class NotifyToSocial { for (Notify notify : listNotifies) { switch (notify.getType()) { case USER_NOTIFICATION: + log.info("Notification type {}, send: {}", notify.getType(), notify.getSend()); if (notify.getSend()) { log.debug("Building Notification..."); @@ -61,12 +64,19 @@ public class NotifyToSocial { String body = null; subject = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_title()); body = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_msg()); + + ExportAsPDF exportAsPDF = notify.getExport_as_pdf(); + String pdfRequest = getPDFLinkRequest(exportAsPDF); + if(pdfRequest!=null) { + String pdfReportMsg = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, exportAsPDF.getPlaceholder_msg()); + body += "\n" + pdfReportMsg; + } String optionalMessage = itemObserved.getOptionalValue(OPTIONAL_FIELD.message); if (optionalMessage != null) { body += "\n" + optionalMessage; } - + log.info("Going to send notification to users: {}", recipientUsers); log.info("subject: {}", subject); log.info("body: {}", body); @@ -75,6 +85,7 @@ public class NotifyToSocial { } break; case VRE_POST: + log.info("Notification type {}, send: {}", notify.getType(), notify.getSend()); if (notify.getSend()) { PostInputBean toWrite = new PostInputBean(); @@ -84,6 +95,13 @@ public class NotifyToSocial { if (title != null) { toWrite.setPreviewtitle(title); } + + ExportAsPDF exportAsPDF = notify.getExport_as_pdf(); + String pdfRequest = getPDFLinkRequest(exportAsPDF); + if(pdfRequest!=null) { + String pdfReportMsg = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, exportAsPDF.getPlaceholder_msg()); + body += "\n" + pdfReportMsg; + } String optionalMessage = itemObserved.getOptionalValue(OPTIONAL_FIELD.message); @@ -111,6 +129,22 @@ public class NotifyToSocial { } } + + private String getPDFLinkRequest(ExportAsPDF exportAsPDF) { + try { + if(exportAsPDF!=null && exportAsPDF.getExport()) { + GeoportalExporterAPI geoportalExporterAPI = new GeoportalExporterAPI(); + String thePDFShortLink = geoportalExporterAPI.exportProject("pdf", itemObserved.getUCD_Id(), itemObserved.getProjectId(), false, true); + nMPlaceholdersSUtil.getPlaceholderMapValues().putProjectAsPDFLink(thePDFShortLink); + return thePDFShortLink; + } + } catch (Exception e) { + log.error("Error while getting PDFLinkRequest", e); + return null; + } + + return null; + } private void vrePost(PostInputBean toWrite, Notify notify) { diff --git a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/substitutor/SubstitutorPlaceholdersMap.java b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/substitutor/SubstitutorPlaceholdersMap.java index 9045451..fd0198f 100644 --- a/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/substitutor/SubstitutorPlaceholdersMap.java +++ b/notifications-plugins/src/main/java/org/gcube/application/cms/notifications/substitutor/SubstitutorPlaceholdersMap.java @@ -2,15 +2,14 @@ package org.gcube.application.cms.notifications.substitutor; import java.util.HashMap; - /** * The Class SubstitutorPlaceholdersMap. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Apr 15, 2024 + * Apr 15, 2024 * - * This class contains the placeholder known + * This class contains the placeholder known */ public class SubstitutorPlaceholdersMap extends HashMap { @@ -29,7 +28,7 @@ public class SubstitutorPlaceholdersMap extends HashMap { 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 PROJECT_AS_PDF_LINK = "project_as_pdf_link"; /** * Instantiates a new substitutor placeholders map. @@ -47,7 +46,7 @@ public class SubstitutorPlaceholdersMap extends HashMap { public String putUserCaller(String username) { return put(USER_CALLER, username); } - + /** * Put item creator. * @@ -78,6 +77,16 @@ public class SubstitutorPlaceholdersMap extends HashMap { return put(PROJECT_ID, projectId); } + /** + * Put project as PDF link. + * + * @param pdfLink the pdf link + * @return the string + */ + public String putProjectAsPDFLink(String pdfLink) { + return put(PROJECT_AS_PDF_LINK, pdfLink); + } + /** * Put private data entry link. *