Skip to content
Snippets Groups Projects
Commit 64f05652 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

feat:Add push subscription admin link to messages [VIPSUTV-342]

parent ced35bcb
Branches
No related tags found
1 merge request!33Feat/add user subscription link vipsutv 342
Showing
with 104 additions and 6 deletions
...@@ -20,7 +20,10 @@ ...@@ -20,7 +20,10 @@
package no.nibio.vips.logic.messaging; package no.nibio.vips.logic.messaging;
/** /**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a> * Represents a localized message in the VIPS push notification system. Used by
* the UniversalMessage class
*
* @copyright 2016-2022 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no> * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/ */
public class MessageLocalVersion { public class MessageLocalVersion {
......
...@@ -79,6 +79,7 @@ public class MessagingBean { ...@@ -79,6 +79,7 @@ public class MessagingBean {
public void sendUniversalMessage(Message message) public void sendUniversalMessage(Message message)
{ {
// TODO: Make URL relative
String msgDownloadUrlTpl = "https://www.vips-landbruk.no/messages/" + message.getMessageId() + "/"; String msgDownloadUrlTpl = "https://www.vips-landbruk.no/messages/" + message.getMessageId() + "/";
// Create a universal message from the message // Create a universal message from the message
// TODO: When UniversalMessage has changed, pick // TODO: When UniversalMessage has changed, pick
......
...@@ -29,6 +29,7 @@ import java.io.Serializable; ...@@ -29,6 +29,7 @@ import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.ResourceBundle;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.persistence.Basic; import javax.persistence.Basic;
...@@ -44,6 +45,8 @@ import javax.persistence.Temporal; ...@@ -44,6 +45,8 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.Transient; import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import com.ibm.icu.util.ULocale;
import no.nibio.vips.logic.util.StringJsonUserType; import no.nibio.vips.logic.util.StringJsonUserType;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef; import org.hibernate.annotations.TypeDef;
...@@ -84,6 +87,10 @@ public class UniversalMessage implements Serializable { ...@@ -84,6 +87,10 @@ public class UniversalMessage implements Serializable {
@Transient @Transient
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
// Include by default. If not needed, use constructor that makes it configurable
@Transient
private Boolean includeNotificationSettingsLink = Boolean.TRUE;
public UniversalMessage() { public UniversalMessage() {
...@@ -99,6 +106,19 @@ public class UniversalMessage implements Serializable { ...@@ -99,6 +106,19 @@ public class UniversalMessage implements Serializable {
{ {
this.addMessageLocalVersion(locale, msgSubject, msgLeadParagraph, msgBody, msgDownloadUrl); this.addMessageLocalVersion(locale, msgSubject, msgLeadParagraph, msgBody, msgDownloadUrl);
} }
public UniversalMessage(
String locale,
String msgSubject,
String msgLeadParagraph,
String msgBody,
String msgDownloadUrl,
Boolean includeNotificationSettingsLink
)
{
this(locale, msgSubject, msgLeadParagraph, msgBody, msgDownloadUrl);
this.setIncludeNotificationSettingsLink(includeNotificationSettingsLink);
}
public final void addMessageLocalVersion( public final void addMessageLocalVersion(
String locale, String locale,
...@@ -235,6 +255,18 @@ public class UniversalMessage implements Serializable { ...@@ -235,6 +255,18 @@ public class UniversalMessage implements Serializable {
} }
} }
/**
* @param locale two-letter language string
* @return The localized string **template** for generating a link to a user's page for
* managing notification subscription settings
*/
@Transient
public String getNotificationSettingsLinkTpl(String locale)
{
ULocale theLocale = new ULocale(locale);
ResourceBundle rb = ResourceBundle.getBundle("no.nibio.vips.logic.i18n.vipslogictexts",theLocale.toLocale());
return rb.getString("universalMessageSettingsLink_tpl");
}
private ObjectMapper getObjectMapper() private ObjectMapper getObjectMapper()
{ {
...@@ -244,4 +276,19 @@ public class UniversalMessage implements Serializable { ...@@ -244,4 +276,19 @@ public class UniversalMessage implements Serializable {
} }
return this.objectMapper; return this.objectMapper;
} }
/**
* If true, the SMS and mail messages will have this type of link appended at the end:
* "To edit your notification subscriptions, please use this link: https://logic.vips.nibio.no/user/notificationsubscription?userId=1"
* The server name can be configured with the system properties no.nibio.vips.logic.VIPSLOGIC_PROTOCOL and no.nibio.vips.logic.SERVER_NAME
* @return
*/
@Transient
public Boolean getIncludeNotificationSettingsLink() {
return includeNotificationSettingsLink;
}
public void setIncludeNotificationSettingsLink(Boolean includeNotificationSettingsLink) {
this.includeNotificationSettingsLink = includeNotificationSettingsLink;
}
} }
...@@ -18,7 +18,12 @@ ...@@ -18,7 +18,12 @@
*/ */
package no.nibio.vips.logic.messaging.distribution.entity; package no.nibio.vips.logic.messaging.distribution.entity;
import com.ibm.icu.util.ULocale;
import no.nibio.vips.logic.util.Globals;
import java.net.URL; import java.net.URL;
import java.text.MessageFormat;
import java.util.ResourceBundle;
/** /**
...@@ -46,6 +51,10 @@ public class MsgToSend { ...@@ -46,6 +51,10 @@ public class MsgToSend {
// The lead paragraph (AKA "Ingress") // The lead paragraph (AKA "Ingress")
public String msgLeadParagraph; public String msgLeadParagraph;
// Include by default. If not needed, use constructor that makes it configurable
private Boolean includeNotificationSettingsLink = Boolean.TRUE;
/* (non-Javadoc) /* (non-Javadoc)
* @see no.nibio.vips_msg_dist.dao.Test#getMsgSubject() * @see no.nibio.vips_msg_dist.dao.Test#getMsgSubject()
*/ */
...@@ -116,5 +125,29 @@ public class MsgToSend { ...@@ -116,5 +125,29 @@ public class MsgToSend {
this.locale = locale; this.locale = locale;
} }
/**
* @return The localized string **template** for generating a link to a user's page for
* managing notification subscription settings
*/
public String getNotificationSettingsLinkTpl()
{
ULocale theLocale = new ULocale(this.getLocale());
ResourceBundle rb = ResourceBundle.getBundle("no.nibio.vips.logic.i18n.vipslogictexts",theLocale.toLocale());
return MessageFormat.format(rb.getString("universalMessageSettingsLink_tpl"), Globals.PROTOCOL + "://" + Globals.SERVER_NAME + "/user/notificationsubscription?userId={0}");
}
/**
* If true, the SMS and mail messages will have this type of link appended at the end:
* "To edit your notification subscriptions, please use this link: https://logic.vips.nibio.no/user/notificationsubscription?userId=1"
* The server name can be configured with the system properties no.nibio.vips.logic.VIPSLOGIC_PROTOCOL and no.nibio.vips.logic.SERVER_NAME
* @return
*/
public Boolean getIncludeNotificationSettingsLink() {
return includeNotificationSettingsLink;
}
public void setIncludeNotificationSettingsLink(Boolean includeNotificationSettingsLink) {
this.includeNotificationSettingsLink = includeNotificationSettingsLink;
}
} }
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package no.nibio.vips.logic.messaging.distribution.send; package no.nibio.vips.logic.messaging.distribution.send;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
import java.util.Date; import java.util.Date;
import java.util.Properties; import java.util.Properties;
...@@ -148,7 +149,8 @@ public class MailMsgDeliveryHandler implements IDeliveryMsgHandler { ...@@ -148,7 +149,8 @@ public class MailMsgDeliveryHandler implements IDeliveryMsgHandler {
+ " using server " + mailserver); + " using server " + mailserver);
} else { } else {
sendMessage(msgToSend.getMsgSubject(), msgToSend.getMsgLeadParagraph(), new StringBuffer(msgToSend.getMsgBody()).append("\n\n") sendMessage(msgToSend.getMsgSubject(), msgToSend.getMsgLeadParagraph(), new StringBuffer(msgToSend.getMsgBody()).append("\n\n")
.append(msgToSend.getMsgDownloadUrl() != null ? msgToSend.getMsgDownloadUrl():""), .append(msgToSend.getMsgDownloadUrl() != null ? msgToSend.getMsgDownloadUrl():"")
.append(msgToSend.getIncludeNotificationSettingsLink() ? "\n\n" + MessageFormat.format(msgToSend.getNotificationSettingsLinkTpl(),msgReceiver.recipientId): "\n"),
msgReceiver.msgDeliveryAddress); msgReceiver.msgDeliveryAddress);
} }
return SingleMsgSentStateEnum.Ok; return SingleMsgSentStateEnum.Ok;
......
...@@ -26,6 +26,7 @@ import java.net.MalformedURLException; ...@@ -26,6 +26,7 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.text.MessageFormat;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import no.nibio.vips.logic.messaging.distribution.entity.MsgReceiver; import no.nibio.vips.logic.messaging.distribution.entity.MsgReceiver;
...@@ -134,7 +135,8 @@ public class SmsMsgDeliveryHandler implements IDeliveryMsgHandler { ...@@ -134,7 +135,8 @@ public class SmsMsgDeliveryHandler implements IDeliveryMsgHandler {
String smsText = msgToSend.getMsgSubject() + "\n" String smsText = msgToSend.getMsgSubject() + "\n"
+ msgToSend.getMsgLeadParagraph() + "\n" + msgToSend.getMsgLeadParagraph() + "\n"
+ msgToSend.getMsgBody() + msgToSend.getMsgBody()
+ (msgToSend.getMsgDownloadUrl() != null ? "\n" + msgToSend.getMsgDownloadUrl().toString(): ""); + (msgToSend.getMsgDownloadUrl() != null ? "\n" + msgToSend.getMsgDownloadUrl().toString(): "\n")
+ (msgToSend.getIncludeNotificationSettingsLink() ? "\n\n" + MessageFormat.format(msgToSend.getNotificationSettingsLinkTpl(), msgReceiver.recipientId): "\n");
LOGGER.debug(smsText); LOGGER.debug(smsText);
LOGGER.debug("Teksten er på " + smsText.length() + " tegn."); LOGGER.debug("Teksten er på " + smsText.length() + " tegn.");
......
...@@ -842,11 +842,13 @@ public class BarkbeetleBean { ...@@ -842,11 +842,13 @@ public class BarkbeetleBean {
* @param users * @param users
* @param heading * @param heading
* @param message * @param message
* @param url
*/ */
public void sendReminder(List<VipsLogicUser> users, String heading, String message) { public void sendReminder(List<VipsLogicUser> users, String heading, String message) {
UniversalMessage uMessage = new UniversalMessage(); UniversalMessage uMessage = new UniversalMessage();
// The notificationSettingsLink is relevant to regular VIPS notifications, not
// these barkbeetle reminders, so omitting this here.
uMessage.setIncludeNotificationSettingsLink(false);
Calendar cal = Calendar.getInstance(BarkbeetleBean.NORGE_MITT_NORGE); Calendar cal = Calendar.getInstance(BarkbeetleBean.NORGE_MITT_NORGE);
cal.setTime(new Date()); cal.setTime(new Date());
cal.add(Calendar.DATE, 2); cal.add(Calendar.DATE, 2);
......
...@@ -70,6 +70,8 @@ public class Globals { ...@@ -70,6 +70,8 @@ public class Globals {
public static int DEFAULT_UUID_VALIDITY_DURATION_DAYS = 30; public static int DEFAULT_UUID_VALIDITY_DURATION_DAYS = 30;
public static String PROTOCOL = System.getProperty("no.nibio.vips.logic.VIPSLOGIC_PROTOCOL"); public static String PROTOCOL = System.getProperty("no.nibio.vips.logic.VIPSLOGIC_PROTOCOL") != null ? System.getProperty("no.nibio.vips.logic.VIPSLOGIC_PROTOCOL") : "http";
public static String SERVER_NAME = System.getProperty("no.nibio.vips.logic.SERVER_NAME") != null ? System.getProperty("no.nibio.vips.logic.SERVER_NAME") : "logic.vips.nibio.no";
} }
...@@ -1041,3 +1041,4 @@ addIllustration=Add illustration ...@@ -1041,3 +1041,4 @@ addIllustration=Add illustration
allRoles=All roles allRoles=All roles
allStatuses=All statuses allStatuses=All statuses
LEAFBLOTCH=Leaf blotch model LEAFBLOTCH=Leaf blotch model
universalMessageSettingsLink_tpl=To edit your notification subscriptions, please use this link: {0}
...@@ -1034,3 +1034,4 @@ addIllustration=Add illustration ...@@ -1034,3 +1034,4 @@ addIllustration=Add illustration
allRoles=All roles allRoles=All roles
allStatuses=All statuses allStatuses=All statuses
LEAFBLOTCH=Leaf blotch model LEAFBLOTCH=Leaf blotch model
universalMessageSettingsLink_tpl=To edit your VIPS notification subscriptions, please use this link: {0}
...@@ -1033,3 +1033,4 @@ addIllustration=Add illustration ...@@ -1033,3 +1033,4 @@ addIllustration=Add illustration
allRoles=All roles allRoles=All roles
allStatuses=All statuses allStatuses=All statuses
LEAFBLOTCH=Leaf blotch model LEAFBLOTCH=Leaf blotch model
universalMessageSettingsLink_tpl=To edit your notification subscriptions, please use this link: {0}
...@@ -1042,3 +1042,4 @@ addIllustration=Legg til illustrasjon ...@@ -1042,3 +1042,4 @@ addIllustration=Legg til illustrasjon
allRoles=Alle roller allRoles=Alle roller
allStatuses=Alle statuser allStatuses=Alle statuser
LEAFBLOTCH=Bladflekksjukdomsmodell LEAFBLOTCH=Bladflekksjukdomsmodell
universalMessageSettingsLink_tpl=For endre dine abonnement p push-varsler fra VIPS, bruk denne lenken: {0}
...@@ -1035,3 +1035,4 @@ addIllustration=Add illustration ...@@ -1035,3 +1035,4 @@ addIllustration=Add illustration
allRoles=All roles allRoles=All roles
allStatuses=All statuses allStatuses=All statuses
LEAFBLOTCH=Leaf blotch model LEAFBLOTCH=Leaf blotch model
universalMessageSettingsLink_tpl=To edit your notification subscriptions, please use this link: {0}
...@@ -1028,3 +1028,4 @@ addIllustration=Add illustration ...@@ -1028,3 +1028,4 @@ addIllustration=Add illustration
allRoles=All roles allRoles=All roles
allStatuses=All statuses allStatuses=All statuses
LEAFBLOTCH=Leaf blotch model LEAFBLOTCH=Leaf blotch model
universalMessageSettingsLink_tpl=To edit your notification subscriptions, please use this link: {0}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment