Integrated with ExportAsPDF config
This commit is contained in:
parent
e3fff1b505
commit
8382f74dcf
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
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.NotificationWhen;
|
||||||
import org.gcube.application.cms.notifications.config.Notify;
|
import org.gcube.application.cms.notifications.config.Notify;
|
||||||
import org.gcube.application.cms.notifications.config.serviceaccount.GeoportalServiceAccount;
|
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.manager.SecretManagerProvider;
|
||||||
import org.gcube.common.authorization.utils.secret.Secret;
|
import org.gcube.common.authorization.utils.secret.Secret;
|
||||||
import org.gcube.portal.databook.shared.Post;
|
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.social_networking_client_library.NotificationClient;
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.PostInputBean;
|
import org.gcube.social_networking.socialnetworking.model.beans.PostInputBean;
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEvent;
|
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEvent;
|
||||||
|
@ -54,6 +56,7 @@ public class NotifyToSocial {
|
||||||
for (Notify notify : listNotifies) {
|
for (Notify notify : listNotifies) {
|
||||||
switch (notify.getType()) {
|
switch (notify.getType()) {
|
||||||
case USER_NOTIFICATION:
|
case USER_NOTIFICATION:
|
||||||
|
|
||||||
log.info("Notification type {}, send: {}", notify.getType(), notify.getSend());
|
log.info("Notification type {}, send: {}", notify.getType(), notify.getSend());
|
||||||
if (notify.getSend()) {
|
if (notify.getSend()) {
|
||||||
log.debug("Building Notification...");
|
log.debug("Building Notification...");
|
||||||
|
@ -62,6 +65,13 @@ 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());
|
||||||
|
|
||||||
|
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);
|
String optionalMessage = itemObserved.getOptionalValue(OPTIONAL_FIELD.message);
|
||||||
if (optionalMessage != null) {
|
if (optionalMessage != null) {
|
||||||
body += "\n" + optionalMessage;
|
body += "\n" + optionalMessage;
|
||||||
|
@ -75,6 +85,7 @@ public class NotifyToSocial {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case VRE_POST:
|
case VRE_POST:
|
||||||
|
|
||||||
log.info("Notification type {}, send: {}", notify.getType(), notify.getSend());
|
log.info("Notification type {}, send: {}", notify.getType(), notify.getSend());
|
||||||
if (notify.getSend()) {
|
if (notify.getSend()) {
|
||||||
PostInputBean toWrite = new PostInputBean();
|
PostInputBean toWrite = new PostInputBean();
|
||||||
|
@ -85,6 +96,13 @@ public class NotifyToSocial {
|
||||||
toWrite.setPreviewtitle(title);
|
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);
|
String optionalMessage = itemObserved.getOptionalValue(OPTIONAL_FIELD.message);
|
||||||
|
|
||||||
if (optionalMessage != null) {
|
if (optionalMessage != null) {
|
||||||
|
@ -112,6 +130,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) {
|
private void vrePost(PostInputBean toWrite, Notify notify) {
|
||||||
|
|
||||||
final SecretManager secretManager = SecretManagerProvider.instance.get();
|
final SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.gcube.application.cms.notifications.substitutor;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class SubstitutorPlaceholdersMap.
|
* The Class SubstitutorPlaceholdersMap.
|
||||||
*
|
*
|
||||||
|
@ -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 PRIVATE_DATA_VIEWER_LINK = "private_data_viewer_link";
|
||||||
public static final String PUBLIC_DATA_VIEWER_LINK = "public_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.
|
* Instantiates a new substitutor placeholders map.
|
||||||
|
@ -78,6 +77,16 @@ public class SubstitutorPlaceholdersMap extends HashMap<String, String> {
|
||||||
return put(PROJECT_ID, projectId);
|
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.
|
* Put private data entry link.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue