You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by nm...@apache.org on 2021/09/10 15:34:41 UTC
[ofbiz-framework] branch trunk updated: Improved: Convert
RoutingServices.xml mini-lang to groovy (OFBIZ-11855)
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 7d40e07 Improved: Convert RoutingServices.xml mini-lang to groovy (OFBIZ-11855)
7d40e07 is described below
commit 7d40e0703a61ff146bf3b5a54a7044a6ba980508
Author: Sebastian Berg <se...@ecomify.de>
AuthorDate: Fri Jul 2 10:31:34 2021 +0200
Improved: Convert RoutingServices.xml mini-lang to groovy (OFBIZ-11855)
---
.../groovyScripts/routing/RoutingServices.groovy | 128 ++++++++++++++++++++
.../minilang/routing/RoutingServices.xml | 131 ---------------------
.../manufacturing/servicedef/services_routing.xml | 8 +-
3 files changed, 132 insertions(+), 135 deletions(-)
diff --git a/applications/manufacturing/groovyScripts/routing/RoutingServices.groovy b/applications/manufacturing/groovyScripts/routing/RoutingServices.groovy
new file mode 100644
index 0000000..46b63f2
--- /dev/null
+++ b/applications/manufacturing/groovyScripts/routing/RoutingServices.groovy
@@ -0,0 +1,128 @@
+/*
+ * 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.
+ */
+
+import java.sql.Timestamp
+
+import org.apache.ofbiz.base.util.UtilDateTime
+import org.apache.ofbiz.entity.GenericValue
+
+/**
+ * "Get the product's routing and routing tasks
+ * @return
+ */
+def getProductRouting() {
+ Map result = success()
+
+ // If applicableDate has been passed use the value with all filter-by-date calls
+ Timestamp filterDate = parameters.applicableDate ?: UtilDateTime.nowTimestamp()
+
+ GenericValue routingGS = null
+ GenericValue routing = null
+ List tasks = null
+ Map lookupRouting = [productId: parameters.productId, workEffortGoodStdTypeId: "ROU_PROD_TEMPLATE"]
+
+ // If a workEffortId has been passed, use it to look up the desired routing
+ if (parameters.workEffortId) {
+ lookupRouting.workEffortId = parameters.workEffortId
+ routingGS = from("WorkEffortGoodStandard")
+ .where(lookupRouting)
+ .filterByDate(filterDate)
+ .queryFirst()
+
+ // If the routing is not associated with our product and it's a variant, then check to see if it's virtual product has the routing
+ if (!routingGS) {
+ GenericValue virtualProductAssoc = from("ProductAssoc")
+ .where(productIdTo: parameters.productId,
+ productAssocTypeId: "PRODUCT_VARIANT")
+ .filterByDate(filterDate)
+ .queryFirst()
+ if (virtualProductAssoc) {
+ lookupRouting.productId = virtualProductAssoc.productId
+ // Consider the validity against a date passed as (optional) parameter
+ routingGS = from("WorkEffortGoodStandard")
+ .where(lookupRouting)
+ .filterByDate(filterDate)
+ .queryFirst()
+ }
+ }
+ }
+
+ // No workEffortId has been passed, so retrieve the first routing found for this product
+ else {
+ // Consider the validity against a date passed as (optional) parameter
+ // TODO: we should consider the quantity to select the best routing
+ routingGS = from("WorkEffortGoodStandard")
+ .where(lookupRouting)
+ .filterByDate(filterDate)
+ .queryFirst()
+
+ // If there are no routings associated with our product and it's a variant, then check to see if it's virtual product has a routing
+ if (!routingGS) {
+ GenericValue virtualProductAssoc = from("ProductAssoc")
+ .where(productIdTo: parameters.productId,
+ productAssocTypeId: "PRODUCT_VARIANT")
+ .filterByDate(filterDate)
+ .queryFirst()
+ if (virtualProductAssoc) {
+ lookupRouting.productId = virtualProductAssoc.productId
+ lookupRouting.workEffortGoodStdTypeId = "ROU_PROD_TEMPLATE"
+ // Consider the validity against a date passed as (optional) parameter
+ // TODO: we should consider the quantity to select the best routing
+ routingGS = from("WorkEffortGoodStandard")
+ .where(lookupRouting)
+ .filterByDate(filterDate)
+ .queryFirst()
+ }
+ }
+ }
+ if (routingGS) {
+ routing = from("WorkEffort").where(workEffortId: routingGS.workEffortId).queryOne()
+ } else {
+ // The default routing is used when no explicit routing is associated to the product and the ignoreDefaultRouting is not equals to Y
+ if (!parameters.ignoreDefaultRouting || parameters.ignoreDefaultRouting == "N") {
+ routing = from("WorkEffort").where(workEffortId: "DEFAULT_ROUTING").queryOne()
+ }
+ }
+ if (routing) {
+ tasks = from("WorkEffortAssoc")
+ .where(workEffortIdFrom: routing.workEffortId,
+ workEffortAssocTypeId: "ROUTING_COMPONENT")
+ .orderBy("sequenceNum")
+ .filterByDate()
+ .queryList()
+ }
+ result.routing = routing
+ result.tasks = tasks
+ return result
+}
+
+/**
+ * Get the routing task assocs of a given routing
+ * @return
+ */
+def getRoutingTaskAssocs() {
+ Map result = success()
+ result.routingTaskAssocs = from("WorkEffortAssoc")
+ .where(workEffortIdFrom: parameters.workEffortId,
+ workEffortAssocTypeId: "ROUTING_COMPONENT")
+ .orderBy("sequenceNum")
+ .filterByDate()
+ .queryList()
+ return result
+}
diff --git a/applications/manufacturing/minilang/routing/RoutingServices.xml b/applications/manufacturing/minilang/routing/RoutingServices.xml
deleted file mode 100644
index 0b67c75..0000000
--- a/applications/manufacturing/minilang/routing/RoutingServices.xml
+++ /dev/null
@@ -1,131 +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="getProductRouting" short-description="Get the product's routing and routing tasks">
- <set from-field="parameters.productId" field="lookupRouting.productId"/>
- <set value="ROU_PROD_TEMPLATE" field="lookupRouting.workEffortGoodStdTypeId"/>
- <!-- If applicableDate has been passed use the value with all filter-by-date calls-->
- <if-not-empty field="parameters.applicableDate">
- <set from-field="parameters.applicableDate" field="filterDate"/>
- <else>
- <now-timestamp field="filterDate"/>
- </else>
- </if-not-empty>
- <!-- If a workEffortId has been passed, use it to look up the desired routing-->
- <if-not-empty field="parameters.workEffortId">
- <set from-field="parameters.workEffortId" field="lookupRouting.workEffortId"/>
- <find-by-and entity-name="WorkEffortGoodStandard" list="routings" map="lookupRouting"/>
- <filter-list-by-date list="routings" valid-date="filterDate"/>
- <first-from-list list="routings" entry="routingGS"/>
- <!-- If the routing is not associated with our product and it's a variant, then
- check to see if it's virtual product has the routing -->
- <if-empty field="routingGS">
- <entity-condition entity-name="ProductAssoc" list="virtualProductAssocList" filter-by-date="true">
- <condition-list combine="and">
- <condition-expr field-name="productIdTo" from-field="parameters.productId"/>
- <condition-expr field-name="productAssocTypeId" value="PRODUCT_VARIANT"/>
- </condition-list>
- </entity-condition>
- <first-from-list list="virtualProductAssocList" entry="virtualProductAssoc"/>
- <if-not-empty field="virtualProductAssoc">
- <set from-field="virtualProductAssoc.productId" field="lookupRouting.productId"/>
- <find-by-and entity-name="WorkEffortGoodStandard" list="routings" map="lookupRouting"/>
- <!-- Consider the validity against a date passed as (optional) parameter -->
- <filter-list-by-date list="routings" valid-date="filterDate"/>
- <first-from-list list="routings" entry="routingGS"/>
- </if-not-empty>
- </if-empty>
- <!-- No workEffortId has been passed, so retrieve the first routing found for this product-->
- <else>
- <find-by-and entity-name="WorkEffortGoodStandard" list="routings" map="lookupRouting"/>
- <!-- Consider the validity against a date passed as (optional) parameter -->
- <filter-list-by-date list="routings" valid-date="filterDate"/>
- <!-- TODO: we should consider the quantity to select the best routing -->
- <first-from-list list="routings" entry="routingGS"/>
- <!-- If there are no routings associated with our product and it's a variant, then
- check to see if it's virtual product has a routing -->
- <if-empty field="routingGS">
- <entity-condition entity-name="ProductAssoc" list="virtualProductAssocList">
- <condition-list combine="and">
- <condition-expr field-name="productIdTo" from-field="parameters.productId"/>
- <condition-expr field-name="productAssocTypeId" value="PRODUCT_VARIANT"/>
- </condition-list>
- </entity-condition>
- <filter-list-by-date list="virtualProductAssocList" valid-date="filterDate"/>
- <first-from-list list="virtualProductAssocList" entry="virtualProductAssoc"/>
- <if-not-empty field="virtualProductAssoc">
- <set from-field="virtualProductAssoc.productId" field="lookupRouting.productId"/>
- <set value="ROU_PROD_TEMPLATE" field="lookupRouting.workEffortGoodStdTypeId"/>
- <find-by-and entity-name="WorkEffortGoodStandard" list="routings" map="lookupRouting"/>
- <!-- Consider the validity against a date passed as (optional) parameter -->
- <filter-list-by-date list="routings" valid-date="filterDate"/>
- <!-- TODO: we should consider the quantity to select the best routing -->
- <first-from-list list="routings" entry="routingGS"/>
- </if-not-empty>
- </if-empty>
- </else>
- </if-not-empty>
- <if-not-empty field="routingGS">
- <clear-field field="lookupRouting"/>
- <set from-field="routingGS.workEffortId" field="lookupRouting.workEffortId"/>
- <find-by-primary-key entity-name="WorkEffort" value-field="routing" map="lookupRouting"/>
- <else>
- <!-- The default routing is used when no explicit routing is associated to the product
- and the ignoreDefaultRouting is not equals to Y -->
- <if>
- <condition>
- <or>
- <if-empty field="parameters.ignoreDefaultRouting"/>
- <if-compare field="parameters.ignoreDefaultRouting" operator="equals" value="N"/>
- </or>
- </condition>
- <then>
- <clear-field field="lookupRouting"/>
- <set value="DEFAULT_ROUTING" field="lookupRouting.workEffortId"/>
- <find-by-primary-key entity-name="WorkEffort" value-field="routing" map="lookupRouting"/>
- </then>
- </if>
- </else>
- </if-not-empty>
- <if-not-empty field="routing">
- <set from-field="routing.workEffortId" field="lookupTasks.workEffortIdFrom"/>
- <string-to-list string="sequenceNum" list="tasksOrder"/>
- <set value="ROUTING_COMPONENT" field="lookupTasks.workEffortAssocTypeId"/>
- <find-by-and entity-name="WorkEffortAssoc" list="tasks" map="lookupTasks" order-by-list="tasksOrder"/>
- <filter-list-by-date list="tasks"/>
- </if-not-empty>
-
- <field-to-result field="routing"/>
- <field-to-result field="tasks"/>
- </simple-method>
- <simple-method method-name="getRoutingTaskAssocs" short-description="Get the routing task assocs of a given routing">
- <set from-field="parameters.workEffortId" field="lookupTasks.workEffortIdFrom"/>
- <string-to-list string="sequenceNum" list="tasksOrder"/>
- <set value="ROUTING_COMPONENT" field="lookupTasks.workEffortAssocTypeId"/>
- <find-by-and entity-name="WorkEffortAssoc" list="routingTaskAssocs" map="lookupTasks" order-by-list="tasksOrder"/>
- <filter-list-by-date list="routingTaskAssocs"/>
- <field-to-result field="routingTaskAssocs"/>
- </simple-method>
-
-</simple-methods>
-
diff --git a/applications/manufacturing/servicedef/services_routing.xml b/applications/manufacturing/servicedef/services_routing.xml
index 8b6d6a1..ea09957 100644
--- a/applications/manufacturing/servicedef/services_routing.xml
+++ b/applications/manufacturing/servicedef/services_routing.xml
@@ -41,8 +41,8 @@ under the License.
<attribute name="create" type="String" mode="IN" optional="true"/>
<attribute name="sequenceNumNotOk" type="String" mode="OUT" optional="false"/>
</service>
- <service name="getProductRouting" engine="simple" auth="true"
- location="component://manufacturing/minilang/routing/RoutingServices.xml" invoke="getProductRouting">
+ <service name="getProductRouting" engine="groovy" auth="true"
+ location="component://manufacturing/groovyScripts/routing/RoutingServices.groovy" invoke="getProductRouting">
<description>Get the product's routing and routing tasks</description>
<attribute mode="IN" name="productId" optional="false" type="String"/>
<attribute mode="IN" name="workEffortId" optional="true" type="String"/>
@@ -51,8 +51,8 @@ under the License.
<attribute mode="OUT" name="routing" type="org.apache.ofbiz.entity.GenericValue" optional="true"/>
<attribute mode="OUT" name="tasks" type="java.util.List" optional="true"/>
</service>
- <service name="getRoutingTaskAssocs" engine="simple" auth="true"
- location="component://manufacturing/minilang/routing/RoutingServices.xml" invoke="getRoutingTaskAssocs">
+ <service name="getRoutingTaskAssocs" engine="groovy" auth="true"
+ location="component://manufacturing/groovyScripts/routing/RoutingServices.groovy" invoke="getRoutingTaskAssocs">
<description>Get the routing task assocs of a given routing</description>
<attribute mode="IN" name="workEffortId" optional="false" type="String"/>
<attribute mode="OUT" name="routingTaskAssocs" type="java.util.List" optional="true"/>