Skip to content

Commit

Permalink
Metadata publication notifications / allow to configure the mail form…
Browse files Browse the repository at this point in the history
…at: html / text
  • Loading branch information
josegar74 committed Nov 13, 2024
1 parent 6dbaa47 commit 8fe0368
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2001-2023 Food and Agriculture Organization of the
* Copyright (C) 2001-2024 Food and Agriculture Organization of the
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
* and United Nations Environment Programme (UNEP)
*
Expand Down Expand Up @@ -34,6 +34,7 @@
import org.fao.geonet.repository.GroupRepository;
import org.fao.geonet.utils.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.*;
Expand All @@ -48,6 +49,9 @@

@Component
public class MetadataPublicationMailNotifier {
@Value("${metadata.publicationmail.format.html:true}")
private boolean sendHtmlMail;

@Autowired
SettingManager settingManager;

Expand Down Expand Up @@ -136,7 +140,6 @@ private void sendMailPublicationNotification(Locale[] feedbackLocales,
LocalizedEmailComponent emailMessageComponent = new LocalizedEmailComponent(MESSAGE, "metadata_published_text", KeyType.MESSAGE_KEY, POSITIONAL_FORMAT);

for (Locale feedbackLocale : feedbackLocales) {

emailSubjectComponent.addParameters(
feedbackLocale,
new LocalizedEmailParameter(ParameterType.RAW_VALUE, 1, settingManager.getSiteName())
Expand Down Expand Up @@ -175,15 +178,19 @@ private void sendMailPublicationNotification(Locale[] feedbackLocales,
);
}

LocalizedEmail localizedEmail = new LocalizedEmail(true);
LocalizedEmail localizedEmail = new LocalizedEmail(sendHtmlMail);
localizedEmail.addComponents(emailSubjectComponent, emailMessageComponent);

String subject = localizedEmail.getParsedSubject(feedbackLocales);
String htmlMessage = localizedEmail.getParsedMessage(feedbackLocales);
String message = localizedEmail.getParsedMessage(feedbackLocales);

// Send mail to notify about metadata publication / un-publication
try {
MailUtil.sendHtmlMail(toAddress, subject, htmlMessage, settingManager);
if (sendHtmlMail) {
MailUtil.sendHtmlMail(toAddress, subject, message, settingManager);
} else {
MailUtil.sendMail(toAddress, subject, message, settingManager);
}
} catch (IllegalArgumentException ex) {
Log.warning(API.LOG_MODULE_NAME, ex.getMessage(), ex);
}
Expand Down
3 changes: 2 additions & 1 deletion web/src/main/webResources/WEB-INF/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ analytics.web.jscode=
#analytics.web.service=matomo
#analytics.web.jscode=var _paq = _paq || [];_paq.push(['trackPageView']);_paq.push(['enableLinkTracking']);(function() {var u="//localhost/";_paq.push(['setTrackerUrl', u+'piwik.php']);_paq.push(['setSiteId', '1']);var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);})();var currentUrl = location.href; window.addEventListener('hashchange', function() {_paq.push(['setReferrerUrl', currentUrl]);currentUrl = window.location.href;_paq.push(['setCustomUrl', currentUrl]);_paq.push(['setDocumentTitle', currentUrl]);_paq.push(['deleteCustomVariables', 'page']);_paq.push(['trackPageView']);var content = document.getElementsByTagName('body')[0];_paq.push(['MediaAnalytics::scanForMedia', content]);_paq.push(['FormAnalytics::scanForForms', content]);_paq.push(['trackContentImpressionsWithinNode', content]);_paq.push(['enableLinkTracking']);});


# Configure the metadata publication notification mails to be sent as HTML (true) or TEXT (false)
metadata.publicationmail.format.html=true

0 comments on commit 8fe0368

Please sign in to comment.