Skip to content

Commit

Permalink
Improved: Slim down use of ${groovy: } (OFBIZ-13146) (#838)
Browse files Browse the repository at this point in the history
* Improved: Slim down use of ${groovy: } (OFBIZ-13146)

With the framework evolution, we used on many place the scriptlet ${groovy: } on screen rendering where something it's now unecessary.

This issue convert some of them on a other solution to slim down this usage
  • Loading branch information
nmalin committed Nov 5, 2024
1 parent 012f5c0 commit 9464a4f
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.
*/
package org.apache.ofbiz.accounting.invoice

String invoiceId = context.invoiceId
BigDecimal amountToApply = InvoiceWorker.getInvoiceNotApplied(delegator, invoiceId)
context.paidInvoice = amountToApply == 0
context.amountToApply = amountToApply
context.total = InvoiceWorker.getInvoiceTotal(delegator, invoiceId)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.
*/
package org.apache.ofbiz.accounting.ledger

List fieldForTooltip = delegator.getModelEntity('PartyAcctgPreference').getAllFieldNames()
String labelInherited = label('AccountingUiLabels', 'AccountingInheritedValue')
fieldForTooltip.each {
context."${it}Tooltip" = !context.partyAcctgPreference?.(it) && context.aggregatedPartyAcctgPreference?.(it) ? labelInherited : ''
}
8 changes: 1 addition & 7 deletions applications/accounting/widget/BillingAccountForms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,7 @@ under the License.
<field-map field-name="compareDate" from-field="invoiceDate"/>
<field-map field-name="lastNameFirst" value="Y"/>
</service>
<set field="paidInvoice" value="${groovy: org.apache.ofbiz.accounting.invoice.InvoiceWorker.getInvoiceNotApplied(delegator,invoiceId).compareTo(java.math.BigDecimal.ZERO)==0}" type="Boolean"/>
<set field="amountToApply" value="${groovy:
import java.text.NumberFormat;
return(NumberFormat.getNumberInstance(locale).format(org.apache.ofbiz.accounting.invoice.InvoiceWorker.getInvoiceNotApplied(delegator,invoiceId)));}"/>
<set field="total" value="${groovy:
import java.text.NumberFormat;
return(NumberFormat.getNumberInstance(locale).format(org.apache.ofbiz.accounting.invoice.InvoiceWorker.getInvoiceTotal(delegator,invoiceId)));}"/>
<script location="component://accounting/src/main/groovy/org/apache/ofbiz/accounting/invoice/DisplayInvoiceAmounts.groovy"/>
</row-actions>
<field name="billingAccountId"><hidden/></field>
<field name="invoiceId" widget-style="buttontext">
Expand Down
87 changes: 25 additions & 62 deletions applications/accounting/widget/GlSetupForms.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.
*/
package org.apache.ofbiz.commonext.ofbizsetup

Map serviceResult = run service: 'getLastSystemInfoNote', with: parameters
context.layoutSettings.middleTopHeader = "---------- ${uiLabelMap.CommonLastSytemNotes} ----------"
['1', '2', '3'].each {
Map infoNote = serviceResult."lastSystemInfoNote$it"
context.layoutSettings."middleTopMessage$it" = infoNote ? "${infoNote.noteDateTime.toString().substring(0, 16)} ${infoNote.noteInfo}" : ''
context.layoutSettings."middleTopLink$it" = infoNote && infoNote.moreInfoUrl && infoNote.moreInfoItemName && infoNote.moreInfoItemId
? "${infoNote.moreInfoUrl}?${infoNote.moreInfoItemName}=${infoNote.moreInfoItemId}&amp;id=${infoNote.moreInfoItemId}"
: ''
}
12 changes: 1 addition & 11 deletions applications/commonext/widget/CommonScreens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,7 @@ under the License.
<set field="layoutSettings.topLines[]" from-field="line" global="true"/>
<script location="component://commonext/src/main/groovy/org/apache/ofbiz/commonext/ofbizsetup/ChangeOrgPartyId.groovy"/><!-- to see ofbizsetup needs to be displayed -->
<!-- system info notes -->
<service service-name="getLastSystemInfoNote" result-map="resultNote"/>
<set field="lastSystemInfoNote1" from-field="resultNote.lastSystemInfoNote1"/>
<set field="lastSystemInfoNote2" from-field="resultNote.lastSystemInfoNote2"/>
<set field="lastSystemInfoNote3" from-field="resultNote.lastSystemInfoNote3"/>
<set field="layoutSettings.middleTopHeader" value="---------- ${uiLabelMap.CommonLastSytemNotes} ----------"/>
<set field="layoutSettings.middleTopMessage1" value="${groovy:lastSystemInfoNote1!=null?lastSystemInfoNote1.noteDateTime.toString().substring(0,16) + &quot; &quot; + lastSystemInfoNote1.noteInfo:&quot;&quot;}"/>
<set field="layoutSettings.middleTopMessage2" value="${groovy:lastSystemInfoNote2!=null?lastSystemInfoNote2.noteDateTime.toString().substring(0,16) + &quot; &quot; + lastSystemInfoNote2.noteInfo:&quot;&quot;}"/>
<set field="layoutSettings.middleTopMessage3" value="${groovy:lastSystemInfoNote3!=null?lastSystemInfoNote3.noteDateTime.toString().substring(0,16) + &quot; &quot; + lastSystemInfoNote3.noteInfo:&quot;&quot;}"/>
<set field="layoutSettings.middleTopLink1" value="${lastSystemInfoNote1.moreInfoUrl}${groovy: if (lastSystemInfoNote1&amp;&amp;lastSystemInfoNote1.moreInfoItemName&amp;&amp;lastSystemInfoNote1.moreInfoItemId)&quot;?&quot; + lastSystemInfoNote1.moreInfoItemName + &quot;=&quot; + lastSystemInfoNote1.moreInfoItemId + &quot;&amp;id=&quot; + lastSystemInfoNote1.moreInfoItemId;}"/>
<set field="layoutSettings.middleTopLink2" value="${lastSystemInfoNote2.moreInfoUrl}${groovy: if (lastSystemInfoNote2&amp;&amp;lastSystemInfoNote2.moreInfoItemName&amp;&amp;lastSystemInfoNote2.moreInfoItemId)&quot;?&quot; + lastSystemInfoNote2.moreInfoItemName + &quot;=&quot; + lastSystemInfoNote2.moreInfoItemId + &quot;&amp;id=&quot; + lastSystemInfoNote2.moreInfoItemId;}"/>
<set field="layoutSettings.middleTopLink3" value="${lastSystemInfoNote3.moreInfoUrl}${groovy: if (lastSystemInfoNote3&amp;&amp;lastSystemInfoNote3.moreInfoItemName&amp;&amp;lastSystemInfoNote3.moreInfoItemId)&quot;?&quot; + lastSystemInfoNote3.moreInfoItemName + &quot;=&quot; + lastSystemInfoNote3.moreInfoItemId + &quot;&amp;id=&quot; + lastSystemInfoNote3.moreInfoItemId;}"/>
<script location="component://commonext/src/main/groovy/org/apache/ofbiz/commonext/ofbizsetup/SystemInfoNote.groovy"/>
<!-- Help link actions -->
<set field="helpTopic" value="${groovy: webappName.toUpperCase() + '_' + requestAttributes._CURRENT_VIEW_}"/>
<entity-and entity-name="ContentAssoc" list="pageAvail">
Expand Down
2 changes: 1 addition & 1 deletion applications/content/widget/website/WebSiteForms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ under the License.
<form name="CreateWebSiteContactList" type="single" target="createWebSiteContactList"
default-map-name="webSite" title="" header-row-style="header-row" default-table-style="basic-table">
<actions>
<set field="fromDate" value="${groovy: import org.apache.ofbiz.base.util.UtilDateTime; return UtilDateTime.nowTimestamp();}" type="Timestamp"/>
<set field="fromDate" value="${date:nowTimestamp()}" type="Timestamp"/>
</actions>
<field name="webSiteId"><display/></field>
<field name="siteName"><display/></field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,13 +552,13 @@ under the License.
<field name="drObjectInfo" title="${uiLabelMap.CommonContent}">
<display description="default ${drObjectInfo}"/>
</field>
<field name="drObjectInfo" title="${uiLabelMap.CommonContent}" use-when="${groovy: drDataResourceTypeId != null &amp;&amp; (drDataResourceTypeId.contains(&quot;FILE&quot;) || drDataResourceTypeId.equals(&quot;IMAGE_OBJECT&quot;))}">
<field name="drObjectInfo" title="${uiLabelMap.CommonContent}" use-when="${drDataResourceTypeId?.contains('FILE') || drDataResourceTypeId == 'IMAGE_OBJECT'}">
<hyperlink description="${drObjectInfo}" target="/content/control/ViewBinaryDataResource" target-type="content" target-window="productionRunContentWindow">
<parameter param-name="dataResourceId" from-field="drDataResourceId"/>
</hyperlink>
</field>
<field name="drObjectInfo" title="${uiLabelMap.CommonContent}" entry-name="drDataResourceId" encode-output="true" use-when="${groovy: drDataResourceTypeId != null &amp;&amp; drDataResourceTypeId.equals(&quot;ELECTRONIC_TEXT&quot;)}">
<display-entity entity-name="ElectronicText" key-field-name="dataResourceId" description="${textData}"></display-entity>
<field name="drObjectInfo" title="${uiLabelMap.CommonContent}" entry-name="drDataResourceId" encode-output="true" use-when="${drDataResourceTypeId == 'ELECTRONIC_TEXT'}">
<display-entity entity-name="ElectronicText" key-field-name="dataResourceId" description="${textData}"/>
</field>
<field name="deleteLink" title=" " widget-style="smallSubmit">
<hyperlink description="${uiLabelMap.CommonDelete}" target="deleteProductionRunContent" also-hidden="false">
Expand Down
2 changes: 1 addition & 1 deletion applications/marketing/widget/ContactListForms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ under the License.
<form name="CreateWebSiteContactList" type="single" target="createWebSiteContactList"
default-map-name="contactList" title="" header-row-style="header-row" default-table-style="basic-table">
<actions>
<set field="fromDate" value="${groovy: import org.apache.ofbiz.base.util.UtilDateTime; return UtilDateTime.nowTimestamp();}" type="Timestamp"/>
<set field="fromDate" value="${date:nowTimestamp()}" type="Timestamp"/>
</actions>
<field name="contactListId"><display/></field>
<field name="contactListName"><display/></field>
Expand Down
2 changes: 1 addition & 1 deletion applications/order/widget/ordermgr/OrderEntryForms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ under the License.
<row-actions>
<entity-one entity-name="Product" value-field="product" auto-field-map="true"/>
<set field=""/>
<set field="hasAmount" value="${groovy:product.getString('requireAmount')?:'N'}"/>
<set field="hasAmount" from-field="product.requireAmount" default-value="N"/>
</row-actions>
<field name="productId" title="${uiLabelMap.ProductProductId}" widget-style="buttontext">
<hyperlink description="${productId}" target="/catalog/control/EditProductInventoryItems" target-type="inter-app">
Expand Down
13 changes: 7 additions & 6 deletions applications/party/widget/partymgr/PartyForms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,17 @@ under the License.
<entity-and entity-name="UserLogin" list="logins" use-cache="true">
<field-map field-name="partyId" from-field="partyId"/>
</entity-and>
<set field="userLoginSize" value="${groovy:logins.size()}" type="Integer"/>
<set field="userLoginSize" value="${util:size(logins)}" type="Integer"/>
<service service-name="getPartyMainRole" result-map="mainRole">
<field-map field-name="partyId" from-field="partyId"/>
<field-map field-name="userLogin" from-field="userLogin"/>
</service>
<entity-and entity-name="PartyClassification" list="partyClassifications" use-cache="true">
<field-map field-name="partyId" from-field="partyId"/>
</entity-and>
<set field="fieldId" value="partyClassificationGroupId"/>
<set field="partyClassificationGroupIds" value="${groovy:org.apache.ofbiz.entity.util.EntityUtil.getFieldListFromEntityList(partyClassifications, fieldId, true);}"/>
<entity-condition entity-name="PartyClassification" list="partyClassifications" use-cache="true" distinct="true">
<condition-expr field-name="partyId" from-field="partyId"/>
<select-field field-name="partyClassificationGroupId"/>
</entity-condition>
<set field="partyClassificationGroupIds" value="${groovy: partyClassifications*.partyClassificationGroupId}"/>
<service service-name="getPartyNameForDate" result-map="partyName"/>
</row-actions>
<field name="partyId" sort-field="true" widget-style="buttontext">
<hyperlink description="${partyId}" target="viewprofile">
Expand Down
3 changes: 2 additions & 1 deletion applications/product/widget/catalog/ImageManagementForms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,8 @@ under the License.

<grid name="ListImageUpload" title="" list-name="productContent" odd-row-style="alternate-row" default-table-style="basic-table" use-row-submit="true" separate-columns="true">
<actions>
<set field="dateNow" type="Timestamp" value="${groovy:import org.apache.ofbiz.base.util.UtilDateTime;UtilDateTime.nowTimestamp().getTime() - 18000;}"/>
<set field="dateNow" type="Timestamp" value="${date:nowTimestamp()}"/>
<set field="dateNow" type="Timestamp" value="${groovy: dateNow.getTime() - 18000}"/>
<entity-condition entity-name="ProductContentAndInfo">
<condition-list combine="and">
<condition-expr field-name="productId" from-field="parameters.productId"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.
*/
package org.apache.ofbiz.common

context.requiredLabels = new groovy.json.JsonSlurper().parseText(parameters.requiredLabels)
2 changes: 1 addition & 1 deletion themes/common-theme/widget/CommonScreens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ under the License.
<section>
<actions>
<property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/>
<set field="requiredLabels" value="${groovy: new groovy.json.JsonSlurper().parseText(parameters.requiredLabels)}"/>
<script location="component://common/src/main/groovy/org/apache/ofbiz/common/GetUiLabels.groovy"/>
</actions>
<widgets>
<platform-specific><text><html-template location="component://common-theme/template/GetUiLabels.ftl"/></text></platform-specific>
Expand Down

0 comments on commit 9464a4f

Please sign in to comment.