You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mb...@apache.org on 2021/02/01 15:51:10 UTC
[ofbiz-framework] branch trunk updated: Improved: Convert
EmailServices.xml mini lang to groovy (OFBIZ-11868)
This is an automated email from the ASF dual-hosted git repository.
mbrohl pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push:
new a33ac5c Improved: Convert EmailServices.xml mini lang to groovy (OFBIZ-11868)
a33ac5c is described below
commit a33ac5cff38aac816b5917f49897e36ae45c7396
Author: Sebastian Berg <se...@ecomify.de>
AuthorDate: Mon Jan 25 12:32:46 2021 +0100
Improved: Convert EmailServices.xml mini lang to groovy (OFBIZ-11868)
---
.../groovyScripts/email/EmailServices.groovy | 92 ++++++++++++++++++++++
framework/common/minilang/email/EmailServices.xml | 76 ------------------
framework/common/servicedef/services_email.xml | 4 +-
3 files changed, 94 insertions(+), 78 deletions(-)
diff --git a/framework/common/groovyScripts/email/EmailServices.groovy b/framework/common/groovyScripts/email/EmailServices.groovy
new file mode 100644
index 0000000..b6a1427
--- /dev/null
+++ b/framework/common/groovyScripts/email/EmailServices.groovy
@@ -0,0 +1,92 @@
+import org.apache.ofbiz.base.util.UtilProperties
+import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.service.ModelService
+import org.apache.ofbiz.service.ServiceUtil
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+ /**
+ * Send Mail from Email Template Setting
+ * @return
+ */
+def sendMailFromTemplateSetting() {
+ Map result = success()
+ // if partyIdTo provided but no emailAddress, get it from the partyContactMech
+ if (!parameters.sendTo && !parameters.partyIdTo) {
+ logError("PartyId or SendTo should be specified!")
+ return error(UtilProperties.getMessage("CommonUiLabels", "CommonEmailShouldBeSpecified", parameters.locale))
+ }
+ if (parameters.partyIdTo && !parameters.sendTo) {
+ Map getEmail = [partyId: parameters.partyIdTo]
+ Map serviceResult = run service: "getPartyEmail", with: getEmail
+ if (!ServiceUtil.isSuccess(serviceResult)) {
+ return serviceResult
+ }
+ parameters.sendTo = serviceResult.emailAddress
+ if (!parameters.sendTo) {
+ logInfo("PartyId: ${parameters.partyIdTo} has no valid email address, not sending email")
+ return result;
+ }
+ }
+ GenericValue emailTemplateSetting = from("EmailTemplateSetting").where(parameters).queryOne()
+ if (emailTemplateSetting) {
+ Map emailParams = [:]
+ emailParams.bodyScreenUri = emailTemplateSetting.bodyScreenLocation
+ emailParams.xslfoAttachScreenLocation = emailTemplateSetting.xslfoAttachScreenLocation
+ emailParams.partyId = parameters.partyIdTo
+ if (emailTemplateSetting.fromAddress) {
+ emailParams.sendFrom = emailTemplateSetting.fromAddress
+ } else {
+ emailParams.sendFrom = UtilProperties.getPropertyValue("general", "defaultFromEmailAddress", "ofbizsupport@example.com")
+ }
+ emailParams.sendCc = emailTemplateSetting.ccAddress
+ emailParams.sendBcc = emailTemplateSetting.bccAddress
+ emailParams.subject = emailTemplateSetting.subject
+ emailParams.contentType = emailTemplateSetting.contentType ?: "text/html"
+ if (parameters.custRequestId) {
+ Map bodyParameters = [custRequestId: parameters.custRequestId]
+ emailParams.bodyParameters = bodyParameters
+ }
+ // copy the incoming parameter fields AFTER setting the ones from EmailTemplateSetting so they can override things like subject, sendFrom, etc
+ emailParams << parameters
+ Map sendMailResult = run service: "sendMailFromScreen", with: emailParams
+ if (!ServiceUtil.isSuccess(sendMailResult)) {
+ return sendMailResult
+ }
+ result.messageWrapper = sendMailResult.messageWrapper
+ result.body = sendMailResult.body
+ result.communicationEventId = sendMailResult.communicationEventId
+ } else {
+ logError("sendMailFromTemplateSetting service could not find the emailTemplateSettingId: ${parameters.emailTemplateSettingId}")
+ }
+ return result
+}
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/framework/common/minilang/email/EmailServices.xml b/framework/common/minilang/email/EmailServices.xml
deleted file mode 100644
index ecf6097..0000000
--- a/framework/common/minilang/email/EmailServices.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-
-<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd">
- <simple-method method-name="sendMailFromTemplateSetting" short-description="Send Mail from Email Template Setting">
- <!-- if partyIdTo provided but no emailAddress, get it from the partyContactMech -->
- <if-empty field="parameters.sendTo">
- <if-empty field="parameters.partyIdTo">
- <log level="error" message="PartyId or SendTo should be specified!"></log>
- <add-error>
- <fail-property resource="CommonUiLabels" property="CommonEmailShouldBeSpecified"/>
- </add-error>
- <check-errors/>
- </if-empty>
- </if-empty>
- <if-not-empty field="parameters.partyIdTo">
- <if-empty field="parameters.sendTo">
- <set field="getEmail.partyId" from-field="parameters.partyIdTo"/>
- <call-service service-name="getPartyEmail" in-map-name="getEmail">
- <result-to-field result-name="emailAddress" field="parameters.sendTo"/>
- </call-service>
- <if-empty field="parameters.sendTo">
- <log level="info" message="PartyId: ${parameters.partyIdTo} has no valid email address, not sending email"></log>
- <return/>
- </if-empty>
- </if-empty>
- </if-not-empty>
- <entity-one entity-name="EmailTemplateSetting" value-field="emailTemplateSetting"/>
- <if-not-empty field="emailTemplateSetting">
- <set field="emailParams.bodyScreenUri" from-field="emailTemplateSetting.bodyScreenLocation"/>
- <set field="emailParams.xslfoAttachScreenLocation" from-field="emailTemplateSetting.xslfoAttachScreenLocation"/>
- <set field="emailParams.partyId" from-field="parameters.partyIdTo"/>
- <if-not-empty field="emailTemplateSetting.fromAddress">
- <set field="emailParams.sendFrom" from-field="emailTemplateSetting.fromAddress"/>
- <else>
- <property-to-field resource="general" property="defaultFromEmailAddress" field="emailParams.sendFrom" default="ofbizsupport@example.com"/>
- </else>
- </if-not-empty>
- <set field="emailParams.sendCc" from-field="emailTemplateSetting.ccAddress"/>
- <set field="emailParams.sendBcc" from-field="emailTemplateSetting.bccAddress"/>
- <set field="emailParams.subject" from-field="emailTemplateSetting.subject"/>
- <set field="emailParams.contentType" from-field="emailTemplateSetting.contentType" default-value="text/html"/>
- <if-not-empty field="parameters.custRequestId">
- <set field="emailParams.bodyParameters.custRequestId" from-field="parameters.custRequestId"/>
- </if-not-empty>
- <!-- copy the incoming parameter fields AFTER setting the ones from EmailTemplateSetting so they can override things like subject, sendFrom, etc -->
- <set-service-fields service-name="sendMailFromScreen" map="parameters" to-map="emailParams"/>
- <call-service service-name="sendMailFromScreen" in-map-name="emailParams">
- <result-to-result result-name="messageWrapper"/>
- <result-to-result result-name="body"/>
- <result-to-result result-name="communicationEventId"/>
- </call-service>
- <else>
- <log level="error" message="sendMailFromTemplateSetting service could not find the emailTemplateSettingId: ${parameters.emailTemplateSettingId}"></log>
- </else>
- </if-not-empty>
- </simple-method>
-</simple-methods>
diff --git a/framework/common/servicedef/services_email.xml b/framework/common/servicedef/services_email.xml
index eb18453..26370cc 100644
--- a/framework/common/servicedef/services_email.xml
+++ b/framework/common/servicedef/services_email.xml
@@ -129,8 +129,8 @@ under the License.
<description>Send E-Mail hidden in log (password, etc.) From Screen Widget Service</description>
<implements service="sendMailFromScreenInterface"/>
</service>
- <service name="sendMailFromTemplateSetting" engine="simple"
- location="component://common/minilang/email/EmailServices.xml" invoke="sendMailFromTemplateSetting">
+ <service name="sendMailFromTemplateSetting" engine="groovy"
+ location="component://common/groovyScripts/email/EmailServices.groovy" invoke="sendMailFromTemplateSetting">
<description>Send Email From Email Template Setting Service</description>
<implements service="sendMailInterface"/>
<attribute name="emailTemplateSettingId" type="String" mode="IN" optional="false"/>