Implement save email to a resource with a seca
Showing
3 changed files
with
119 additions
and
1 deletions
... | @@ -43,4 +43,8 @@ along with this software (see the LICENSE.md file). If not, see | ... | @@ -43,4 +43,8 @@ along with this software (see the LICENSE.md file). If not, see |
43 | serviceName="mjml.MjmlServices.remove#ExcessMjmlEmailResourceHistories" cronExpression="0 0 3 * * ?" paused="N" minRetryTime="1" | 43 | serviceName="mjml.MjmlServices.remove#ExcessMjmlEmailResourceHistories" cronExpression="0 0 3 * * ?" paused="N" minRetryTime="1" |
44 | transactionTimeout="3600"/> | 44 | transactionTimeout="3600"/> |
45 | 45 | ||
46 | <!-- ========= Product Store Configuration --> | ||
47 | <moqui.basic.Enumeration enumCode="mjmlSaveLocation" description="Place to save Mjml Emails (empty will not save anything)" enumId="PsstMjmlSaveLocation" enumTypeId="ProductStoreSettingType"/> | ||
48 | <moqui.basic.Enumeration enumCode="mjmlSaveOnPublish" description="Whether to save Mjml Emails only on publish (true/false) (empty will only save on publish)" enumId="PsstMjmlSaveOnPublish" enumTypeId="ProductStoreSettingType"/> | ||
49 | |||
46 | </entity-facade-xml> | 50 | </entity-facade-xml> | ... | ... |
service/Mjml.secas.xml
0 → 100644
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <!-- | ||
3 | This software is in the public domain under CC0 1.0 Universal plus a | ||
4 | Grant of Patent License. | ||
5 | |||
6 | To the extent possible under law, the author(s) have dedicated all | ||
7 | copyright and related and neighboring rights to this software to the | ||
8 | public domain worldwide. This software is distributed without any | ||
9 | warranty. | ||
10 | |||
11 | You should have received a copy of the CC0 Public Domain Dedication | ||
12 | along with this software (see the LICENSE.md file). If not, see | ||
13 | <http://creativecommons.org/publicdomain/zero/1.0/>. | ||
14 | --> | ||
15 | <secas xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/service-eca-3.xsd"> | ||
16 | <seca id="MjmlFlushEmailToOnSave" service="mjml.MjmlServices.store#GrapeJs" when="tx-commit"> | ||
17 | <actions> | ||
18 | <service-call name="mjml.MjmlServices.flush#EmailOnSave" in-map="context" out-map="context"/> | ||
19 | </actions> | ||
20 | </seca> | ||
21 | </secas> |
... | @@ -195,9 +195,10 @@ along with this software (see the LICENSE.md file). If not, see | ... | @@ -195,9 +195,10 @@ along with this software (see the LICENSE.md file). If not, see |
195 | <service verb="store" noun="GrapeJs" authenticate="anonymous-all"> | 195 | <service verb="store" noun="GrapeJs" authenticate="anonymous-all"> |
196 | <description>Store GrapesJs resource. Can be adapted to entity other than EmailTemplate, but must have data for the grapesLocation and htmlLocation to ensure safety of read and write of resources.</description> | 196 | <description>Store GrapesJs resource. Can be adapted to entity other than EmailTemplate, but must have data for the grapesLocation and htmlLocation to ensure safety of read and write of resources.</description> |
197 | <in-parameters> | 197 | <in-parameters> |
198 | <parameter name="emailTemplateId" required="true"/> | ||
199 | |||
198 | <parameter name="htmlLocation"/> | 200 | <parameter name="htmlLocation"/> |
199 | <parameter name="grapesLocation"/> | 201 | <parameter name="grapesLocation"/> |
200 | <parameter name="emailTemplateId" required="true"/> | ||
201 | <parameter name="data" required="true"/> | 202 | <parameter name="data" required="true"/> |
202 | <parameter name="moquiVars" required="true"/> | 203 | <parameter name="moquiVars" required="true"/> |
203 | <parameter name="html" allow-html="any" required="true"/> | 204 | <parameter name="html" allow-html="any" required="true"/> |
... | @@ -408,4 +409,96 @@ along with this software (see the LICENSE.md file). If not, see | ... | @@ -408,4 +409,96 @@ along with this software (see the LICENSE.md file). If not, see |
408 | </actions> | 409 | </actions> |
409 | </service> | 410 | </service> |
410 | 411 | ||
412 | <service verb="flush" noun="EmailOnSave" authenticate="anonymous-all"> | ||
413 | <description>Given a html and grapes location, save them to a configurable resource uri on the MjmlFlushEmailToOnSave seca. | ||
414 | |||
415 | Could have a generic implementation that uses a hierarchical conditional structure of basic config like an EntitySyncConfig on DbResource GRAPESJS_PROJECT to component://moqui-mjml/dbresource/grapesjs/project</description> | ||
416 | <in-parameters> | ||
417 | <parameter name="emailTemplateId" required="true"/> | ||
418 | <parameter name="publish" type="Boolean"/> | ||
419 | </in-parameters> | ||
420 | <out-parameters> | ||
421 | <parameter name="outHtmlLocation"/> | ||
422 | <parameter name="outGrapesLocation"/> | ||
423 | |||
424 | <parameter name="htmlLocation"/> | ||
425 | <parameter name="grapesLocation"/> | ||
426 | <parameter name="productStoreId"/> | ||
427 | <parameter name="saveOnlyOnPublish" type="Boolean"/> | ||
428 | </out-parameters> | ||
429 | <actions> | ||
430 | <if condition="publish == null"><set field="publish" from="false"/></if> | ||
431 | <entity-find entity-name="mantle.product.store.ProductStoreEmailDetail" list="storeEmails"> | ||
432 | <econdition field-name="emailTemplateId"/> | ||
433 | </entity-find> | ||
434 | <if condition="storeEmails.size() == 0"><return type="danger" message="No store emails found for emailTemplateId ${emailTemplateId}"/></if> | ||
435 | <set field="storeEmail" from="storeEmails.getFirst()"/> | ||
436 | <set field="htmlLocation" from="storeEmail.htmlLocation"/> | ||
437 | <set field="grapesLocation" from="storeEmail.grapesLocation"/> | ||
438 | <set field="productStoreId" from="storeEmail.productStoreId"/> | ||
439 | <if condition="!productStoreId"><return message="Defaulting to not saving email, because no productStoreId found for emailTemplateId ${emailTemplateId}"/></if> | ||
440 | |||
441 | <entity-find entity-name="mantle.product.store.ProductStoreSetting" list="locationStoreSettingList"> | ||
442 | <econdition field-name="productStoreId"/> | ||
443 | <econdition field-name="settingTypeEnumId" value="PsstMjmlSaveLocation"/> | ||
444 | <econdition field-name="settingValue" operator="is-not-null"/> | ||
445 | <econdition field-name="settingValue" operator="not-equals" value=""/> | ||
446 | <date-filter/> | ||
447 | <order-by field-name="-fromDate"/> | ||
448 | </entity-find> | ||
449 | <if condition="locationStoreSettingList.size() == 0"><return message="No location setting found for productStoreId ${productStoreId} for emailTemplateId ${emailTemplateId}"/></if> | ||
450 | <entity-find entity-name="mantle.product.store.ProductStoreSetting" list="publishStoreSettingList"> | ||
451 | <econdition field-name="productStoreId"/> | ||
452 | <econdition field-name="settingTypeEnumId" value="PsstMjmlSaveOnPublish"/> | ||
453 | <econdition field-name="settingValue" operator="is-not-null"/> | ||
454 | <econdition field-name="settingValue" operator="not-equals" value=""/> | ||
455 | <date-filter/> | ||
456 | <order-by field-name="-fromDate"/> | ||
457 | </entity-find> | ||
458 | <!-- default to only saving on publish --> | ||
459 | <set field="saveOnlyOnPublish" from="publishStoreSettingList.getFirst()?.settingValue == 'false' ? false : true"/> | ||
460 | <!-- conditions | ||
461 | saveOnlyOnPublish, publish, save | ||
462 | true, true, -> true | ||
463 | true, false, -> false | ||
464 | false, true, -> true | ||
465 | false, false, -> true --> | ||
466 | <if condition="saveOnlyOnPublish && !publish"><return type="warning" message="Not saving email on save because saveOnlyOnPublish is true and publish is false"/></if> | ||
467 | |||
468 | <set field="toSaveLocation" from="ec.resource.getLocationReference(locationStoreSettingList.getFirst().settingValue)"/> | ||
469 | <if condition="!toSaveLocation"><return message="No location found for settingValue ${locationStoreSettingList.getFirst().settingValue}"/></if> | ||
470 | |||
471 | <set field="htmlFile" from="ec.resource.getLocationReference(htmlLocation)"/> | ||
472 | <set field="htmlText" from="htmlFile?.getText()"/> | ||
473 | <set field="grapesFile" from="ec.resource.getLocationReference(grapesLocation)"/> | ||
474 | <set field="grapesText" from="grapesFile?.getText()"/> | ||
475 | |||
476 | <set field="outHtmlLocation" value=""/> | ||
477 | <if condition="htmlText && htmlText"> | ||
478 | <then> | ||
479 | <set field="outHtmlFile" from="toSaveLocation.getChild(htmlFile.getFileName())"/> | ||
480 | <if condition="!outHtmlFile"> | ||
481 | <set field="outHtmlFile" from="toSaveLocation.makeFile(htmlFile.getFileName())"/> | ||
482 | </if> | ||
483 | <set field="outHtmlLocation" from="outHtmlFile.location"/> | ||
484 | <log message="Saving html to ${outHtmlFile.location}"/> | ||
485 | <script><![CDATA[outHtmlFile.putText(htmlText)]]></script> | ||
486 | </then> | ||
487 | <else><log level="warn" message="No html file text found at ${htmlLocation}"/></else> | ||
488 | </if> | ||
489 | <set field="outGrapesLocation" value=""/> | ||
490 | <if condition="grapesText && grapesFile"> | ||
491 | <then> | ||
492 | <set field="outGrapesFile" from="toSaveLocation.getChild(grapesFile.getFileName())"/> | ||
493 | <if condition="!outGrapesFile"> | ||
494 | <set field="outGrapesFile" from="toSaveLocation.makeFile(grapesFile.getFileName())"/> | ||
495 | </if> | ||
496 | <set field="outGrapesLocation" from="outGrapesFile.location"/> | ||
497 | <log message="Saving grapes to ${outGrapesFile.location}"/> | ||
498 | <script><![CDATA[outGrapesFile.putText(grapesText)]]></script> | ||
499 | </then> | ||
500 | <else><log level="warn" message="No grapes file text found at ${grapesLocation}"/></else></if> | ||
501 | <if condition="!htmlFile || !grapesFile"><return/></if> | ||
502 | </actions> | ||
503 | </service> | ||
411 | </services> | 504 | </services> | ... | ... |
-
Please register or sign in to post a comment