Skip to content

Commit

Permalink
Improved: Convert PeriodServices.xml mini lang to groovy (OFBIZ-12962)
Browse files Browse the repository at this point in the history
Finish to convert PeriodServices.xml with migrate service :
 * findCustomTimePeriods
 * getPreviousTimePeriod
  • Loading branch information
nmalin committed Mar 25, 2024
1 parent 61f5831 commit 0c24cb1
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 98 deletions.
93 changes: 0 additions & 93 deletions applications/accounting/minilang/period/PeriodServices.xml

This file was deleted.

10 changes: 5 additions & 5 deletions applications/accounting/servicedef/services_ledger.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand All @@ -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"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -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_')

This comment has been minimized.

Copy link
@PierreSmits

PierreSmits Mar 26, 2024

Member

This blank line is unnecessary

}
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()
}

0 comments on commit 0c24cb1

Please sign in to comment.