Integrated with ExportAsPDF config

This commit is contained in:
Francesco Mangiacrapa 2024-05-07 11:11:15 +02:00
parent e3fff1b505
commit 8382f74dcf
2 changed files with 49 additions and 6 deletions

View File

@ -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) {

View File

@ -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<String, String> {
@ -29,7 +28,7 @@ public class SubstitutorPlaceholdersMap extends HashMap<String, String> {
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<String, String> {
public String putUserCaller(String username) {
return put(USER_CALLER, username);
}
/**
* Put item creator.
*
@ -78,6 +77,16 @@ public class SubstitutorPlaceholdersMap extends HashMap<String, String> {
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.
*