Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
moqui
/
moqui-mjml
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
a1c1b3c8
authored
2024-05-23 18:06:58 -0500
by
acetousk
1
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Create service job and necessary data for it
1 parent
945aff82
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
0 deletions
data/MjmlSetupData.xml
service/mjml/MjmlServices.xml
data/MjmlSetupData.xml
View file @
a1c1b3c
This diff is collapsed.
Click to expand it.
service/mjml/MjmlServices.xml
View file @
a1c1b3c
...
...
@@ -323,4 +323,75 @@ along with this software (see the LICENSE.md file). If not, see
</actions>
</service>
<service
verb=
"remove"
noun=
"ExcessMjmlEmailResourceHistories"
>
<in-parameters>
<parameter
name=
"runDate"
default=
"ec.user.nowTimestamp"
required=
"true"
type=
"Timestamp"
/>
</in-parameters>
<out-parameters>
<parameter
name=
"removedHistoryList"
/>
</out-parameters>
<actions>
<entity-find
entity-name=
"moqui.basic.email.EmailTemplate"
list=
"emailTemplateList"
>
<econdition
field-name=
"grapesLocation"
operator=
"is-not-null"
/>
<econdition
field-name=
"htmlLocation"
operator=
"is-not-null"
/>
<select-field
field-name=
"emailTemplateId,grapesLocation,htmlLocation,grapesPublishedVersionName,htmlPublishedVersionName"
/>
<order-by
field-name=
"-lastUpdatedStamp"
/>
</entity-find>
<set
field=
"resourceList"
from=
"[]"
/>
<iterate
list=
"emailTemplateList"
entry=
"emailTemplate"
>
<set
field=
"grapesFile"
from=
"ec.resource.getLocationReference(emailTemplate.grapesLocation)"
/>
<if
condition=
"grapesFile"
>
<script>
<![CDATA[
def versionWhitelist = []
if (grapesFile?.getCurrentVersion()?.getVersionName()) versionWhitelist.add(grapesFile.getCurrentVersion().getVersionName())
if (emailTemplate?.grapesPublishedVersionName) versionWhitelist.add(emailTemplate.grapesPublishedVersionName)
resourceList.add([location:grapesFile.location,resourceId:grapesFile.dbResourceId,versionWhitelist:versionWhitelist.size()>
0?versionWhitelist:null])]]>
</script>
</if>
<set
field=
"htmlFile"
from=
"ec.resource.getLocationReference(emailTemplate.htmlLocation)"
/>
<if
condition=
"htmlFile"
>
<script>
<![CDATA[
def versionWhitelist = []
if (htmlFile?.getCurrentVersion()?.getVersionName()) versionWhitelist.add(htmlFile.getCurrentVersion().getVersionName())
if (emailTemplate?.htmlPublishedVersionName) versionWhitelist.add(emailTemplate.htmlPublishedVersionName)
resourceList.add([location:htmlFile.location,resourceId:htmlFile.dbResourceId,versionWhitelist:versionWhitelist.size()>
0?versionWhitelist:null])]]>
</script>
</if>
</iterate>
<set
field=
"oneHourAgo"
from=
"Timestamp.from(runDate.toInstant().minus(1, java.time.temporal.ChronoUnit.HOURS))"
/>
<set
field=
"removedHistoryList"
from=
"[]"
/>
<iterate
list=
"resourceList"
entry=
"resource"
>
<entity-find
entity-name=
"moqui.resource.DbResourceFileHistory"
list=
"resourceHistoryPreList"
>
<econdition
field-name=
"resourceId"
from=
"resource.resourceId"
/>
<econdition
field-name=
"versionDate"
operator=
"greater"
from=
"oneHourAgo"
/>
<econdition
field-name=
"versionDate"
operator=
"less-equals"
from=
"runDate"
/>
<select-field
field-name=
"resourceId,versionName,versionDate,previousVersionName,userId"
/>
<order-by
field-name=
"-versionDate"
/>
</entity-find>
<set
field=
"skippedUserIds"
from=
"[]"
/>
<set
field=
"resourceHistoryList"
from=
"[]"
/>
<iterate
list=
"resourceHistoryPreList"
entry=
"resourceHistory"
>
<!-- Add all but the single latest history per userId to resourceHistoryList -->
<if
condition=
"resource.versionWhitelist.contains(resourceHistory.versionName) || !skippedUserIds.contains(resourceHistory.userId)"
>
<!-- <log level="warn" message="${resource.resourceId} ${resourceHistory.versionName} userId ${resourceHistory.userId}"/>-->
<set
field=
"skippedUserIds"
from=
"skippedUserIds + [resourceHistory.userId]"
/><continue/></if>
<set
field=
"resourceHistoryList"
from=
"resourceHistoryList + [resourceHistory]"
/>
</iterate>
<iterate
list=
"resourceHistoryList"
entry=
"resourceHistory"
>
<entity-find-one
entity-name=
"moqui.resource.DbResourceFileHistory"
value-field=
"usedResourceHistory"
auto-field-map=
"[resourceId:resource.resourceId,previousVersionName:resourceHistory.versionName]"
for-update=
"true"
>
<select-field
field-name=
"resourceId,versionName,versionDate,previousVersionName,userId"
/></entity-find-one>
<!-- <log level="warn" message="set versionName ${usedResourceHistory.versionName} of previousVersionName ${usedResourceHistory.previousVersionName} to ${resourceHistory.previousVersionName}"/>-->
<set
field=
"usedResourceHistory.previousVersionName"
from=
"resourceHistory.previousVersionName"
/>
<log
level=
"info"
message=
"Removed resource history ${resourceHistory.resourceId} version ${resourceHistory.versionName}"
/>
<set
field=
"removedHistoryList"
from=
"removedHistoryList + [resourceId:resource.resourceId, versionName:resourceHistory.versionName,versionDate:resourceHistory.versionDate,userId:resourceHistory.userId]"
/>
<entity-update
value-field=
"usedResourceHistory"
/>
<entity-delete
value-field=
"resourceHistory"
/>
</iterate>
</iterate>
</actions>
</service>
</services>
...
...
Please
register
or
sign in
to post a comment