This is an automated email from the ASF dual-hosted git repository. nmalin 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 0c24cb12bd Improved: Convert PeriodServices.xml mini lang to groovy (OFBIZ-12962) 0c24cb12bd is described below commit 0c24cb12bd973bc52d45206d210f34e6fe208da6 Author: Nicolas Malin <nicolas.ma...@nereide.fr> AuthorDate: Mon Mar 25 20:38:50 2024 +0100 Improved: Convert PeriodServices.xml mini lang to groovy (OFBIZ-12962) Finish to convert PeriodServices.xml with migrate service : * findCustomTimePeriods * getPreviousTimePeriod --- .../accounting/minilang/period/PeriodServices.xml | 93 ---------------------- .../accounting/servicedef/services_ledger.xml | 10 +-- .../ofbiz/accounting/period/PeriodServices.groovy | 90 +++++++++++++++++++++ 3 files changed, 95 insertions(+), 98 deletions(-) diff --git a/applications/accounting/minilang/period/PeriodServices.xml b/applications/accounting/minilang/period/PeriodServices.xml deleted file mode 100644 index 984d10a982..0000000000 --- a/applications/accounting/minilang/period/PeriodServices.xml +++ /dev/null @@ -1,93 +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="findCustomTimePeriods" short-description="Find a CustomTimePeriod"> - <if-not-empty field="parameters.organizationPartyId"> - <!-- walk up the tree and find all party groups that this is a member of, and include the periods for all of them --> - <set from-field="parameters.organizationPartyId" field="getParentOrganizationsCallMap.organizationPartyId"/> - <call-service service-name="getParentOrganizations" in-map-name="getParentOrganizationsCallMap"> - <result-to-field result-name="parentOrganizationPartyIdList"/> - </call-service> - - <iterate list="parentOrganizationPartyIdList" entry="curOrganizationPartyId"> - <clear-field field="orgTimePeriodList"/> - <entity-condition entity-name="CustomTimePeriod" list="orgTimePeriodList" use-cache="true"> - <condition-list combine="and"> - <condition-list combine="or"> - <condition-expr field-name="organizationPartyId" operator="equals" from-field="curOrganizationPartyId"/> - </condition-list> - <condition-expr field-name="fromDate" operator="less-equals" from-field="parameters.findDate"/> - <condition-list combine="or"> - <condition-expr field-name="thruDate" operator="greater-equals" from-field="parameters.findDate"/> - <condition-expr field-name="thruDate" operator="equals" from-field="nullField"/> - </condition-list> - <condition-expr field-name="periodTypeId" operator="in" from-field="parameters.onlyIncludePeriodTypeIdList" ignore-if-empty="true"/> - </condition-list> - </entity-condition> - <list-to-list list="orgTimePeriodList" to-list="listSoFar"/> - </iterate> - </if-not-empty> - - <if-compare field="parameters.excludeNoOrganizationPeriods" operator="not-equals" value="Y"> - <entity-condition entity-name="CustomTimePeriod" list="generalCustomTimePeriodList" use-cache="true"> - <condition-list combine="and"> - <condition-list combine="or"> - <condition-expr field-name="organizationPartyId" operator="equals" from-field="nullField"/> - <condition-expr field-name="organizationPartyId" operator="equals" value="_NA_"/> - </condition-list> - <condition-expr field-name="fromDate" operator="less-equals" from-field="parameters.findDate"/> - <condition-list combine="or"> - <condition-expr field-name="thruDate" operator="greater" from-field="parameters.findDate"/> - <condition-expr field-name="thruDate" operator="equals" from-field="nullField"/> - </condition-list> - <condition-expr field-name="periodTypeId" operator="in" from-field="parameters.onlyIncludePeriodTypeIdList" ignore-if-empty="true"/> - </condition-list> - </entity-condition> - <list-to-list list="generalCustomTimePeriodList" to-list="listSoFar"/> - </if-compare> - - <!-- - * We might want to implement this sometime in the future, but for now is not needed - * go through the list and check each one to see if it has a child in the list, if so don't copy it - <if-compare field="parameters.excludeParentPeriods" operator="equals" value="Y"></if-compare> - --> - - <field-to-result field="listSoFar" result-name="customTimePeriodList"/> - </simple-method> - - <!-- Return previous year with respect to the given year and if none found then return current year as previous. --> - <simple-method method-name="getPreviousTimePeriod" short-description="Return previous time period"> - - <entity-one entity-name="CustomTimePeriod" value-field="currentTimePeriod"/> - - <set field="periodNum" value="${currentTimePeriod.periodNum - 1}" type="Integer"/> - <if-compare field="periodNum" operator="greater" value="-1"> - <entity-and entity-name="CustomTimePeriod" list="customTimePeriodList" filter-by-date="false" use-cache="true"> - <field-map field-name="organizationPartyId" from-field="currentTimePeriod.organizationPartyId"/> - <field-map field-name="periodTypeId" from-field="currentTimePeriod.periodTypeId"/> - <field-map field-name="periodNum"/> - </entity-and> - <first-from-list list="customTimePeriodList" entry="previousTimePeriod"/> - <field-to-result field="previousTimePeriod"/> - </if-compare> - </simple-method> -</simple-methods> diff --git a/applications/accounting/servicedef/services_ledger.xml b/applications/accounting/servicedef/services_ledger.xml index d62d10dc09..4dd45d0c05 100644 --- a/applications/accounting/servicedef/services_ledger.xml +++ b/applications/accounting/servicedef/services_ledger.xml @@ -535,10 +535,10 @@ under the License. </service> <!-- CustomTimePeriod Services --> - <service name="findCustomTimePeriods" engine="simple" - location="component://accounting/minilang/period/PeriodServices.xml" invoke="findCustomTimePeriods" auth="true"> + <service name="findCustomTimePeriods" engine="groovy" invoke="findCustomTimePeriods" auth="true" + location="component://accounting/src/main/groovy/org/apache/ofbiz/accounting/period/PeriodServices.groovy"> <description>Find CustomTimePeriod records, returns both general ones and those for the organizationPartyId passed</description> - <attribute name="findDate" type="Timestamp" mode="IN" optional="false"/> + <attribute name="findDate" type="Timestamp" mode="IN"/> <attribute name="organizationPartyId" type="String" mode="IN" optional="true"/> <attribute name="excludeNoOrganizationPeriods" type="String" mode="IN" optional="true"/> <attribute name="onlyIncludePeriodTypeIdList" type="List" mode="IN" optional="true"/> @@ -557,8 +557,8 @@ under the License. <attribute name="lastClosedDate" type="Timestamp" mode="OUT" optional="true"/> <attribute name="lastClosedTimePeriod" type="org.apache.ofbiz.entity.GenericValue" mode="OUT" optional="true"/> </service> - <service name="getPreviousTimePeriod" engine="simple" invoke="getPreviousTimePeriod" - location="component://accounting/minilang/period/PeriodServices.xml" auth="true"> + <service name="getPreviousTimePeriod" engine="groovy" invoke="getPreviousTimePeriod" auth="true" + location="component://accounting/src/main/groovy/org/apache/ofbiz/accounting/period/PeriodServices.groovy"> <description>Return previous year with respect to the given year and if none found then return null.</description> <attribute name="customTimePeriodId" mode="IN" type="String"/> <attribute name="previousTimePeriod" mode="OUT" type="Map" optional="true"/> diff --git a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/period/PeriodServices.groovy b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/period/PeriodServices.groovy new file mode 100644 index 0000000000..1c08c0e9ee --- /dev/null +++ b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/period/PeriodServices.groovy @@ -0,0 +1,90 @@ +/* + * 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.period + +import org.apache.ofbiz.entity.GenericValue +import org.apache.ofbiz.entity.condition.EntityCondition +import org.apache.ofbiz.entity.condition.EntityConditionBuilder + +/** + * Find a CustomTimePeriod + */ +Map findCustomTimePeriods() { + List customTimePeriodList = [] + if (parameters.organizationPartyId) { + // walk up the tree and find all party groups that this is a member of, and include the periods for all of them + Map serviceResult = run service: 'getParentOrganizations', with: parameters + List parentOrganizationPartyIdList = serviceResult.parentOrganizationPartyIdList + EntityCondition condition = new EntityConditionBuilder().AND { + IN(organizationPartyId: parentOrganizationPartyIdList) + LESS_THAN(fromDate: parameters.findDate) + OR { + GREATER_THAN_EQUAL_TO(thruDate: parameters.findDate) + EQUALS(thruDate: null) + } + if (parameters.onlyIncludePeriodTypeIdList) { + IN(periodTypeId: parameters.onlyIncludePeriodTypeIdList) + } + } + customTimePeriodList.addAll(from('CustomTimePeriod') + .where(condition) + .cache() + .queryList()) + } + if (parameters.excludeNoOrganizationPeriods) { + EntityCondition condition = new EntityConditionBuilder().AND { + OR { + EQUALS(organizationPartyId: null) + EQUALS(organizationPartyId: '_NA_') + + } + LESS_THAN(fromDate: parameters.findDate) + OR { + GREATER_THAN_EQUAL_TO(thruDate: parameters.findDate) + EQUALS(thruDate: null) + } + if (parameters.onlyIncludePeriodTypeIdList) { + IN(periodTypeId: parameters.onlyIncludePeriodTypeIdList) + } + } + customTimePeriodList.addAll(from('CustomTimePeriod') + .where(condition) + .cache() + .queryList()) + } + return success([customTimePeriodList: customTimePeriodList]) +} + +/** + * Return previous year with respect to the given year and if none found then return current year as previous. + */ +Map getPreviousTimePeriod() { + GenericValue customTimePeriod = from('CustomTimePeriod').where(parameters).cache().queryOne() + int periodNum = (customTimePeriod.periodNum ?: 0) - 1 + if (periodNum > -1) { + GenericValue previousTimePeriod = from('CustomTimePeriod') + .where(organizationPartyId: customTimePeriod.organizationPartyId, + periodTypeId: customTimePeriod.periodTypeId, + periodNum: periodNum) + .cache() + .queryFirst() + return success([previousTimePeriod: previousTimePeriod]) + } + return success() +} \ No newline at end of file