Skip to content

Commit

Permalink
feat: send no-reply email to user on unresolvable functional errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MLenterman committed May 16, 2024
1 parent 380d3a5 commit 0e76805
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 2 deletions.
64 changes: 64 additions & 0 deletions src/main/configurations/bpel/Common/xsl/CreateMail.xslt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" cdata-section-elements="message" />
<xsl:param name="fromAddress"/>
<xsl:param name="fromName"/>
<xsl:param name="messageType" select="'text/plain'" />
<xsl:param name="message"/>
<xsl:param name="mailaddresses"/>
<xsl:param name="subject" />
<xsl:variable name="to" select="tokenize($mailaddresses,',')[1]"/>
<xsl:variable name="cc" select="substring-after($mailaddresses,',')"/>

<xsl:template match="/">
<email>
<recipients>
<recipient type="to"><xsl:value-of select="$to"/></recipient>
<xsl:for-each select="tokenize($cc,',')">
<recipient type="cc"><xsl:value-of select="."/></recipient>
</xsl:for-each>
</recipients>
<from><xsl:value-of select="$fromName"/>&lt;<xsl:value-of select="$fromAddress"/>&gt;</from>
<subject><xsl:value-of select="$subject"/>
</subject>
<messageType><xsl:value-of select="$messageType"/></messageType>
<!--
CDATA will be added by cdata-section-elements="message" attribute
on xsl:output. This will prevent the MailSender from removing
whitespace at the beginning of the message.
-->
<message>
<!--
http://support.xink.io/support/solutions/articles/1000064098-why-is-outlook-stripping-line-breaks-from-plain-text-emails
https://stackoverflow.com/questions/247546/outlook-autocleaning-my-line-breaks-and-screwing-up-my-email-format
https://www.masternewmedia.org/newsletter_publishing/newsletter_formatting/remove_line_breaks_issue_Microsoft_Outlook_2003_when_publishing_text_newsletters_20051217.htm
-->
<xsl:call-template name="replace">
<xsl:with-param name="string" select="$message"/>
<xsl:with-param name="old" select="'&#10;'"/>
<xsl:with-param name="new" select="'&#10; '"/>
</xsl:call-template>
</message>
</email>
</xsl:template>

<xsl:template name="replace">
<xsl:param name="string"/>
<xsl:param name="old"/>
<xsl:param name="new"/>
<xsl:choose>
<xsl:when test="contains($string, $old)">
<xsl:value-of select="concat(substring-before($string, $old), $new)"/>
<xsl:call-template name="replace">
<xsl:with-param name="string" select="substring-after($string, $old)"/>
<xsl:with-param name="old" select="$old"/>
<xsl:with-param name="new" select="$new"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>
2 changes: 2 additions & 0 deletions src/main/configurations/bpel/Configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<!ENTITY Bpel_Documents_PostStartBatch SYSTEM "./Configuration_Bpel_Documents_PostStartBatch.xml">
<!ENTITY Handler_AddDocumentsToCaseCommand SYSTEM "./Configuration_Handler_AddDocumentsToCaseCommand.xml">
<!ENTITY Handler_AddDocumentToCaseCommand SYSTEM "./Configuration_Handler_AddDocumentToCaseCommand.xml">
<!ENTITY Handler_SendNoReplyUserEmailCommand SYSTEM "./Configuration_Handler_SendNoReplyUserEmailCommand.xml">
<!ENTITY Handler_UpdateInitiatingSubjectGegMagCommand SYSTEM "./Configuration_Handler_UpdateInitiatingSubjectGegMagCommand.xml">
<!ENTITY Bpel_GegMag_Post SYSTEM "./Configuration_Bpel_GegMag_Post.xml">
<!ENTITY Bpel_Mtom_Mock SYSTEM "./Configuration_Bpel_Mtom_Mock.xml">
Expand Down Expand Up @@ -39,6 +40,7 @@
&Bpel_Documents_PostStartBatch;
&Handler_AddDocumentsToCaseCommand;
&Handler_AddDocumentToCaseCommand;
&Handler_SendNoReplyUserEmailCommand;
&Handler_UpdateInitiatingSubjectGegMagCommand;
&Bpel_GegMag_Post;
&Bpel_Mtom_Mock;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<Module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../FrankConfig.xsd">
<Adapter
name="Handler_SendNoReplyUserEmailCommand"
active="${Handler_SendNoReplyUserEmailCommand.Active}"
description=""
>

<Receiver
name="Handler_SendNoReplyUserEmailCommand"
transactionAttribute="RequiresNew"
pollInterval="5"
maxRetries="0"
>
<MessageStoreListener
name="Handler_SendNoReplyUserEmailCommand"
slotId="${instance.name}/SendNoReplyUserEmailCommand"
peekUntransacted="true"
statusValueInProcess="I"
sessionKeys="TemplateName"
/>
</Receiver>

<Pipeline>
<Exits>
<Exit name="EXIT" state="SUCCESS" />
<Exit name="EXCEPTION" state="ERROR" />
</Exits>

<FixedResultPipe
name="SubstituteMailTemplateVariables"
filename="${openforms2bpel.noreply-smtp.mail-templates-file}"
substituteVars="true"
>
<Param name="vars.signature-from-name" value="${openforms2bpel.noreply-smtp.signature-from-name}" />
</FixedResultPipe>

<XsltPipe
name="SelectMailTemplateByTemplateName"
xpathExpression="//mailTemplates[ name = $TemplateName ]"
outputType="XML"
>
<Param name="TemplateName" sessionKey="TemplateName" />
</XsltPipe>

<XmlWellFormedCheckerPipe
name="TemplateNotFound_Condition"
>
<Forward name="success" path="CreateMailMessage" />
<Forward name="exception" path="TemplateNotFound_Exception" />
</XmlWellFormedCheckerPipe>

<ExceptionPipe name="TemplateNotFound_Exception" />

<XsltPipe
name="CreateMailMessage"
styleSheetName="Common/xsl/CreateMail.xslt"
storeResultInSessionKey="MailMessage"
>
<Param name="subject" xpathExpression="/mailTemplates/subject" />
<Param name="fromName" value="${openforms2bpel.noreply-smtp.default-from-name}" />
<Param name="fromAddress" value="${openforms2bpel.noreply-smtp.default-from-address}" />
<Param name="mailaddresses" sessionKey="originalMessage" xpathExpression="//*[starts-with(name(), 'contactgegevens')]/*[starts-with(name(), 'eMailadres')]" />
<Param name="messageType" xpathExpression="/mailTemplates/messageType" />
<Param name="message" xpathExpression="/mailTemplates/message" />
</XsltPipe>

<SenderPipe
name="NoReplySender"
>
<MailSender
name="NoReplyMailSender"
authAlias="${openforms2bpel.noreply-smtp.auth-alias}"
smtpHost="${openforms2bpel.noreply-smtp.host}"
smtpPort="${openforms2bpel.noreply-smtp.port}"
useSsl="${openforms2bpel.noreply-smtp.use-ssl}"
timeout="${openforms2bpel.noreply-smtp.timeout}"
>
</MailSender>
</SenderPipe>
</Pipeline>
</Adapter>
</Module>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Bpel_Documents_PostEndBatch.Active=true
Bpel_Documents_PostStartBatch.Active=true
Handler_AddDocumentsToCaseCommand.Active=true
Handler_AddDocumentToCaseCommand.Active=true
Handler_SendNoReplyUserEmailCommand.Active=true
Handler_UpdateInitiatingSubjectGegMagCommand.Active=true
Bpel_GegMag_Post.Active=true
Bpel_Mtom_Mock.Active=true
Expand Down
10 changes: 8 additions & 2 deletions src/main/resources/DeploymentSpecifics.properties
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,11 @@ openforms2bpel.noreply-smtp.port=587
openforms2bpel.noreply-smtp.use-ssl=false
openforms2bpel.noreply-smtp.timeout=60000
openforms2bpel.noreply-smtp.auth-alias=noreply-smtp
openforms2bpel.noreply-smtp.default-from-name: Gemeente X
openforms2bpel.noreply-smtp.default-from-address: no-reply@gemeente-x.local
openforms2bpel.noreply-smtp.default-from-name=Gemeente X
openforms2bpel.noreply-smtp.default-from-address=no-reply@gemeente-x.local
openforms2bpel.noreply-smtp.signature-from-name=${openforms2bpel.noreply-smtp.default-from-name}
openforms2bpel.noreply-smtp.mail-templates-file=MailTemplates.xml

openforms2bpel.workflows.tweewegcommunicatie.on-case-not-found.mail-template=
openforms2bpel.workflows.tweewegcommunicatie.on-subject-not-equals-case-subject.mail-template=

20 changes: 20 additions & 0 deletions src/main/resources/MailTemplates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<mailTemplates>
<name>unable-to-add-document-to-case-default</name>
<subject>Document toevoegen aan zaak niet gelukt</subject>
<messageType>text/html</messageType>
<message>
<![CDATA[
Beste,
U heeft onlangs geprobeerd om één of meerdere documenten toe te voegen aan een aanvraag die u eerder bij ons heeft gedaan. Dit is helaas niet gelukt.
Reden is dat het zaaknummer waaraan u document(en) toe wilde voegen [OF-Nummer] niet klopt. Het juiste zaaknummer vindt u in de bevestigingsmail van de originele aanvraag.
Wij vragen u de aanvraag opnieuw toe te sturen en daarin het juiste zaaknummer in te vullen.
Met vriendelijke groet,
${vars.signature-from-name}
]]>
</message>
</mailTemplates>
</root>

0 comments on commit 0e76805

Please sign in to comment.