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-plugins.git
The following commit(s) were added to refs/heads/trunk by this push: new 24f9aec1b Improved: Convert FixedAssetMaintServices.xml to groovy (OFBIZ-11443) By the way update the groovy test syntax 24f9aec1b is described below commit 24f9aec1ba1001744106505a8a54a9ee9aa556f3 Author: Nicolas Malin <nicolas.ma...@nereide.fr> AuthorDate: Sun May 21 16:21:29 2023 +0200 Improved: Convert FixedAssetMaintServices.xml to groovy (OFBIZ-11443) By the way update the groovy test syntax Thanks to Rohit Koushal for the patch --- .../assetmaint/FixedAssetMaintServices.groovy | 79 +++++++++++ assetmaint/minilang/FixedAssetMaintServices.xml | 70 ---------- assetmaint/servicedef/services.xml | 16 +-- .../assetmaint/test/FixedAssetMaintTests.groovy | 148 ++++++++++----------- 4 files changed, 159 insertions(+), 154 deletions(-) diff --git a/assetmaint/groovyScripts/assetmaint/FixedAssetMaintServices.groovy b/assetmaint/groovyScripts/assetmaint/FixedAssetMaintServices.groovy new file mode 100644 index 000000000..965e13ce3 --- /dev/null +++ b/assetmaint/groovyScripts/assetmaint/FixedAssetMaintServices.groovy @@ -0,0 +1,79 @@ +/* + * 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 org.apache.ofbiz.entity.GenericValue + +/** + * Create FixedAssetMaint and Update Schedule information in WorkEffort + * @return + */ +def createFixedAssetMaintUpdateWorkEffort() { + Map serviceResult = run service: 'createFixedAssetMaint', with: parameters + + GenericValue findAssetMaint = from('FixedAssetMaint') + .where(maintHistSeqId: serviceResult.maintHistSeqId, + fixedAssetId: parameters.fixedAssetId) + .queryOne() + + run service: 'updateWorkEffort', with: [*: parameters, + workEffortId: findAssetMaint.scheduleWorkEffortId] + return success([maintHistSeqId: serviceResult.maintHistSeqId]) +} + +/** + * Update FixedAssetMaint and Schedule information in WorkEffort + * @return + */ + +def updateFixedAssetMaintAndWorkEffort() { + run service: 'updateFixedAssetMaint', with: parameters + + Map updateWorkEffortCtx = [*: parameters] + if (parameters.statusId == 'FAM_CANCELLED') { + updateWorkEffortCtx.currentStatusId = 'CAL_CANCELLED' + } + updateWorkEffortCtx.workEffortId = parameters.scheduleWorkEffortId + GenericValue workEffort = from('WorkEffort').where(workEffortId: parameters.scheduleWorkEffortId).queryOne() + updateWorkEffortCtx.actualCompletionDate = parameters.actualCompletionDate ?: + (workEffort ? workEffort.actualCompletionDate : null) + + run service: 'updateWorkEffort', with: updateWorkEffortCtx + return success() +} + +/** + * Create WorkEffort and Associate it with Parent (identified by workEffortFromId) + * @return + */ +def createWorkEffortAndAssocWithParent() { + Map serviceResult = run service: 'createWorkEffortAndAssoc', with: [*:parameters, + workEffortId: parameters.workEffortIdTo] + return serviceResult +} + +/** + * Asset Maintenance permission logic + * @return + */ +def assetMaintPermissionCheck() { + Map serviceResult = run service: 'genericBasePermissionCheck', with: [*:parameters, + primaryPermission: 'ASSETMAINT'] + return serviceResult +} \ No newline at end of file diff --git a/assetmaint/minilang/FixedAssetMaintServices.xml b/assetmaint/minilang/FixedAssetMaintServices.xml deleted file mode 100644 index 43b05a15f..000000000 --- a/assetmaint/minilang/FixedAssetMaintServices.xml +++ /dev/null @@ -1,70 +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="createFixedAssetMaintUpdateWorkEffort" login-required="true" - short-description="Create FixedAssetMaint and Update Schedule information in WorkEffort"> - <set-service-fields map="parameters" service-name="createFixedAssetMaint" to-map="createFixedAssetMaintCtx"/> - <call-service service-name="createFixedAssetMaint" in-map-name="createFixedAssetMaintCtx"> - <result-to-field result-name="maintHistSeqId" field="findAssetMaintLookup.maintHistSeqId"/> - <result-to-result result-name="maintHistSeqId"/> - </call-service> - <check-errors/> - <set from-field="parameters.fixedAssetId" field="findAssetMaintLookup.fixedAssetId"/> - <find-by-primary-key entity-name="FixedAssetMaint" map="findAssetMaintLookup" value-field="findAssetMaint"/> - <set from-field="findAssetMaint.scheduleWorkEffortId" field="updateWorkEffortCtx.workEffortId"/> - <set-service-fields map="parameters" service-name="updateWorkEffort" to-map="updateWorkEffortCtx"/> - <!-- Maintenance WorkEffort entity --> - <call-service service-name="updateWorkEffort" in-map-name="updateWorkEffortCtx"/> - </simple-method> - - <simple-method method-name="updateFixedAssetMaintAndWorkEffort" login-required="true" - short-description="Update FixedAssetMaint and Schedule information in WorkEffort"> - <set-service-fields map="parameters" service-name="updateFixedAssetMaint" to-map="updateFixedAssetMaintCtx"/> - <call-service service-name="updateFixedAssetMaint" in-map-name="updateFixedAssetMaintCtx"/> - <check-errors/> - <if-compare field="parameters.statusId" operator="equals" value="FAM_CANCELLED"> - <set field="updateWorkEffortCtx.currentStatusId" value="CAL_CANCELLED"/> - </if-compare> - <set-service-fields map="parameters" service-name="updateWorkEffort" to-map="updateWorkEffortCtx"/> - <set from-field="parameters.scheduleWorkEffortId" field="updateWorkEffortCtx.workEffortId"/> - <set from-field="parameters.scheduleWorkEffortId" field="workEffortId"/> - <entity-one entity-name="WorkEffort" value-field="workEffort"/> - <set field="updateWorkEffortCtx.actualCompletionDate" from-field="parameters.actualCompletionDate" default-value="${workEffort.actualCompletionDate}"/> - <call-service service-name="updateWorkEffort" in-map-name="updateWorkEffortCtx"/> - </simple-method> - - <simple-method method-name="createWorkEffortAndAssocWithParent" login-required="true" - short-description="Create WorkEffort and Associate it with Parent (identified by workEffortFromId)"> - <set from-field="parameters.workEffortIdTo" field="parameters.workEffortId"/> - <set-service-fields map="parameters" service-name="createWorkEffortAndAssoc" to-map="createWorkEffortAndAssocCtx"/> - <call-service service-name="createWorkEffortAndAssoc" in-map-name="createWorkEffortAndAssocCtx"/> - <check-errors/> - </simple-method> - - <!-- ==============Permission Checking Service============= --> - <simple-method method-name="assetMaintPermissionCheck" short-description="Asset Maintenance permission logic"> - <set field="primaryPermission" value="ASSETMAINT"/> - <call-simple-method method-name="genericBasePermissionCheck" xml-resource="component://common/minilang/permission/CommonPermissionServices.xml"/> - </simple-method> - -</simple-methods> \ No newline at end of file diff --git a/assetmaint/servicedef/services.xml b/assetmaint/servicedef/services.xml index 5d4e96c31..fe35f2619 100644 --- a/assetmaint/servicedef/services.xml +++ b/assetmaint/servicedef/services.xml @@ -29,30 +29,30 @@ under the License. <attribute type="String" mode="IN" name="facilityId" optional="false"/> </service> - <service name="assetMaintPermissionCheck" engine="simple" - location="component://assetmaint/minilang/FixedAssetMaintServices.xml" invoke="assetMaintPermissionCheck"> + <service name="assetMaintPermissionCheck" engine="groovy" + location="component://assetmaint/groovyScripts/assetmaint/FixedAssetMaintServices.groovy" invoke="assetMaintPermissionCheck"> <description>Asset Maintentance Permission Checking Logic</description> <implements service="permissionInterface"/> </service> - <service name="createFixedAssetMaintUpdateWorkEffort" engine="simple" default-entity-name="FixedAssetMaint" - location="component://assetmaint/minilang/FixedAssetMaintServices.xml" invoke="createFixedAssetMaintUpdateWorkEffort"> + <service name="createFixedAssetMaintUpdateWorkEffort" engine="groovy" default-entity-name="FixedAssetMaint" + location="component://assetmaint/groovyScripts/assetmaint/FixedAssetMaintServices.groovy" invoke="createFixedAssetMaintUpdateWorkEffort" auth="true"> <description>Create FixedAssetMaint and Update Schedule information in WorkEffort</description> <auto-attributes include="all" mode="IN" optional="true"/> <auto-attributes include="all" mode="IN" entity-name="WorkEffort" optional="true"/> <override name="fixedAssetId" mode="IN" optional="false"/> <override name="maintHistSeqId" mode="OUT" optional="false"/> </service> - <service name="updateFixedAssetMaintAndWorkEffort" engine="simple" default-entity-name="FixedAssetMaint" - location="component://assetmaint/minilang/FixedAssetMaintServices.xml" invoke="updateFixedAssetMaintAndWorkEffort"> + <service name="updateFixedAssetMaintAndWorkEffort" engine="groovy" default-entity-name="FixedAssetMaint" + location="component://assetmaint/groovyScripts/assetmaint/FixedAssetMaintServices.groovy" invoke="updateFixedAssetMaintAndWorkEffort" auth="true"> <description>Update FixedAssetMaint and Schedule information in WorkEffort</description> <auto-attributes include="pk" mode="IN" optional="false"/> <auto-attributes include="nonpk" mode="IN" optional="true"/> <auto-attributes include="all" mode="IN" entity-name="WorkEffort" optional="true"/> </service> - <service name="createWorkEffortAndAssocWithParent" engine="simple" default-entity-name="WorkEffort" - location="component://assetmaint/minilang/FixedAssetMaintServices.xml" invoke="createWorkEffortAndAssocWithParent"> + <service name="createWorkEffortAndAssocWithParent" engine="groovy" default-entity-name="WorkEffort" + location="component://assetmaint/groovyScripts/assetmaint/FixedAssetMaintServices.groovy" invoke="createWorkEffortAndAssocWithParent" auth="true"> <description>Create WorkEffort and Associate it with Parent (identified by workEffortFromId)</description> <implements service="createWorkEffortAndAssoc"/> </service> diff --git a/assetmaint/src/main/groovy/org/apache/ofbiz/assetmaint/test/FixedAssetMaintTests.groovy b/assetmaint/src/main/groovy/org/apache/ofbiz/assetmaint/test/FixedAssetMaintTests.groovy index fcaae974d..bfe08c0bb 100644 --- a/assetmaint/src/main/groovy/org/apache/ofbiz/assetmaint/test/FixedAssetMaintTests.groovy +++ b/assetmaint/src/main/groovy/org/apache/ofbiz/assetmaint/test/FixedAssetMaintTests.groovy @@ -32,29 +32,24 @@ class FixedAssetMaintTests extends OFBizTestCase { void testCreateFixedAssetMaintUpdateWorkEffortWithProductMaint() { // Test case for service createFixedAssetMaintUpdateWorkEffort with a product Maintenance - String fixedAssetId = "DEMO_VEHICLE_01" - Map serviceCtx = [:] - serviceCtx.fixedAssetId = fixedAssetId - serviceCtx.statusId = "FAM_CREATED" - serviceCtx.productMaintSeqId = "seq03" // product maintenance - serviceCtx.intervalMeterTypeId = "ODOMETER" - - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS") - String estimatedStartDate = "2009-12-18 00:00:00.000" - serviceCtx.estimatedStartDate = new Timestamp(sdf.parse(estimatedStartDate).getTime()) - - String estimatedCompletionDate = "2009-12-18 01:00:00.000" - serviceCtx.estimatedCompletionDate = new Timestamp(sdf.parse(estimatedCompletionDate).getTime()) - - String actualStartDate = "2009-12-20 00:00:00.000" - serviceCtx.actualStartDate = new Timestamp(sdf.parse(actualStartDate).getTime()) - - serviceCtx.userLogin = userLogin + SimpleDateFormat sdf = new SimpleDateFormat('yyyy-MM-dd HH:mm:ss.SSS') + String fixedAssetId = 'DEMO_VEHICLE_01' + Map serviceCtx = [fixedAssetId: fixedAssetId, + statusId: 'FAM_CREATED', + productMaintSeqId: 'seq03', // product maintenance, + intervalMeterTypeId: 'ODOMETER', + estimatedStartDate: new Timestamp(sdf.parse('2009-12-18 00:00:00.000').getTime()), + estimatedCompletionDate: new Timestamp(sdf.parse('2009-12-18 01:00:00.000').getTime()), + actualStartDate: new Timestamp(sdf.parse('2009-12-20 00:00:00.000').getTime()), + userLogin: userLogin] Map serviceResult = dispatcher.runSync('createFixedAssetMaintUpdateWorkEffort', serviceCtx) - String maintHistSeqId = serviceResult.maintHistSeqId - - GenericValue fixedAssetMaint = from("FixedAssetMaint").where("fixedAssetId", fixedAssetId).queryFirst() - GenericValue workEffort = from("WorkEffort").where("workEffortId", fixedAssetMaint.scheduleWorkEffortId).queryOne() + GenericValue fixedAssetMaint = from('FixedAssetMaint') + .where('fixedAssetId', fixedAssetId, + 'maintHistSeqId', serviceResult.maintHistSeqId) + .queryOne() + GenericValue workEffort = from('WorkEffort') + .where('workEffortId', fixedAssetMaint.scheduleWorkEffortId) + .queryOne() assert fixedAssetMaint assert fixedAssetMaint.scheduleWorkEffortId assert workEffort @@ -65,29 +60,26 @@ class FixedAssetMaintTests extends OFBizTestCase { void testCreateFixedAssetMaintUpdateWorkEffortWithoutProductMaint() { // Test case for service createFixedAssetMaintUpdateWorkEffort without a product maintenance - String fixedAssetId = "DEMO_VEHICLE_01" - Map serviceCtx = [:] - serviceCtx.fixedAssetId = fixedAssetId - serviceCtx.statusId = "FAM_CREATED" - serviceCtx.productMaintTypeId = "OIL_CHANGE" - serviceCtx.intervalMeterTypeId = "ODOMETER" - - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS") - String estimatedStartDate = "2009-12-18 00:00:00.000" - serviceCtx.estimatedStartDate = new Timestamp(sdf.parse(estimatedStartDate).getTime()) - - String estimatedCompletionDate = "2009-12-18 01:00:00.000" - serviceCtx.estimatedCompletionDate = new Timestamp(sdf.parse(estimatedCompletionDate).getTime()) - - String actualStartDate = "2009-12-20 00:00:00.000" - serviceCtx.actualStartDate = new Timestamp(sdf.parse(actualStartDate).getTime()) - - serviceCtx.userLogin = userLogin + SimpleDateFormat sdf = new SimpleDateFormat('yyyy-MM-dd HH:mm:ss.SSS') + String fixedAssetId = 'DEMO_VEHICLE_01' + Map serviceCtx = [fixedAssetId: fixedAssetId, + statusId: 'FAM_CREATED', + productMaintTypeId: 'OIL_CHANGE', + intervalMeterTypeId: 'ODOMETER', + estimatedStartDate: new Timestamp(sdf.parse('2009-12-18 00:00:00.000').getTime()), + estimatedCompletionDate: new Timestamp(sdf.parse('2009-12-18 01:00:00.000').getTime()), + actualStartDate: new Timestamp(sdf.parse('2009-12-20 00:00:00.000').getTime()), + userLogin: userLogin] Map serviceResult = dispatcher.runSync('createFixedAssetMaintUpdateWorkEffort', serviceCtx) String maintHistSeqId = serviceResult.maintHistSeqId - GenericValue fixedAssetMaint = from("FixedAssetMaint").where("fixedAssetId", fixedAssetId, "maintHistSeqId", maintHistSeqId).queryOne() - GenericValue workEffort = from("WorkEffort").where("workEffortId", fixedAssetMaint.scheduleWorkEffortId).queryOne() + GenericValue fixedAssetMaint = from('FixedAssetMaint') + .where('fixedAssetId', fixedAssetId, + 'maintHistSeqId', maintHistSeqId) + .queryOne() + GenericValue workEffort = from('WorkEffort') + .where('workEffortId', fixedAssetMaint.scheduleWorkEffortId) + .queryOne() assert fixedAssetMaint assert fixedAssetMaint.scheduleWorkEffortId @@ -99,26 +91,26 @@ class FixedAssetMaintTests extends OFBizTestCase { void testUpdateFixedAssetMaintAndWorkEffort() { // Test case for service updateFixedAssetMaintAndWorkEffort - String fixedAssetId = "DEMO_VEHICLE_01" - String maintHistSeqId = "00001" // Sequence created by testCreateFixedAssetMaintUpdateWorkEffortWithProductMaint - Map serviceCtx = [:] - serviceCtx.fixedAssetId = fixedAssetId - serviceCtx.maintHistSeqId = maintHistSeqId - serviceCtx.statusId = "FAM_CREATED" - serviceCtx.productMaintTypeId = "OIL_CHANGE" - serviceCtx.intervalMeterTypeId = "ODOMETER" - - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS") - String estimatedCompletionDate = "2009-12-22 01:00:00.000" // Changed estimatedCompletionDate to test update service - serviceCtx.estimatedCompletionDate = new Timestamp(sdf.parse(estimatedCompletionDate).getTime()) - - GenericValue fixedAssetMaint = from("FixedAssetMaint").where("fixedAssetId", fixedAssetId).queryFirst() - serviceCtx.workEffortId = fixedAssetMaint.scheduleWorkEffortId - - serviceCtx.userLogin = userLogin - Map serviceResult = dispatcher.runSync('updateFixedAssetMaintAndWorkEffort', serviceCtx) - - GenericValue workEffort = from("WorkEffort").where("workEffortId", fixedAssetMaint.scheduleWorkEffortId).queryOne() + SimpleDateFormat sdf = new SimpleDateFormat('yyyy-MM-dd HH:mm:ss.SSS') + String fixedAssetId = 'DEMO_VEHICLE_01' + String maintHistSeqId = '00001' // Sequence created by testCreateFixedAssetMaintUpdateWorkEffortWithProductMaint + GenericValue fixedAssetMaint = from('FixedAssetMaint') + .where('fixedAssetId', fixedAssetId, + 'maintHistSeqId', maintHistSeqId) + .queryOne() + Map serviceCtx = [fixedAssetId: fixedAssetId, + maintHistSeqId: maintHistSeqId, + statusId: 'FAM_CREATED', + productMaintTypeId: 'OIL_CHANGE', + intervalMeterTypeId: 'ODOMETER', + estimatedCompletionDate: new Timestamp(sdf.parse('2009-12-22 01:00:00.000').getTime()), + scheduleWorkEffortId: fixedAssetMaint.scheduleWorkEffortId, + userLogin: userLogin] + + dispatcher.runSync('updateFixedAssetMaintAndWorkEffort', serviceCtx) + GenericValue workEffort = from('WorkEffort') + .where('workEffortId', fixedAssetMaint.scheduleWorkEffortId) + .queryOne() assert fixedAssetMaint assert fixedAssetMaint.scheduleWorkEffortId @@ -128,20 +120,24 @@ class FixedAssetMaintTests extends OFBizTestCase { void testUpdateFixedAssetMaintAndWorkEffortComplete() { // Test case for service updateFixedAssetMaintAndWorkEffort - GenericValue fixedAssetMaint = from("FixedAssetMaint").where("fixedAssetId", "DEMO_VEHICLE_01", "maintHistSeqId", "00001").queryOne() - Map serviceCtx = [:] - serviceCtx.fixedAssetId = fixedAssetMaint.fixedAssetId - serviceCtx.maintHistSeqId = fixedAssetMaint.maintHistSeqId - serviceCtx.scheduleWorkEffortId = fixedAssetMaint.scheduleWorkEffortId - serviceCtx.statusId = "FAM_COMPLETED" - serviceCtx.actualCompletionDate = UtilDateTime.nowTimestamp() - serviceCtx.userLogin = userLogin - - Map serviceResult = dispatcher.runSync('updateFixedAssetMaintAndWorkEffort', serviceCtx) - GenericValue newFixedAssetMaint = from("FixedAssetMaint").where("fixedAssetId", "DEMO_VEHICLE_01", "maintHistSeqId", "00001").queryOne() - assert newFixedAssetMaint.statusId == "FAM_COMPLETED" - GenericValue workEffort = from("WorkEffort").where("workEffortId", fixedAssetMaint.scheduleWorkEffortId).queryOne() - assert workEffort.currentStatusId == "CAL_COMPLETED" + GenericValue fixedAssetMaint = from('FixedAssetMaint').where('fixedAssetId', 'DEMO_VEHICLE_01', 'maintHistSeqId', '00001').queryOne() + Map serviceCtx = [fixedAssetId: fixedAssetMaint.fixedAssetId, + maintHistSeqId: fixedAssetMaint.maintHistSeqId, + scheduleWorkEffortId: fixedAssetMaint.scheduleWorkEffortId, + statusId: 'FAM_COMPLETED', + actualCompletionDate: UtilDateTime.nowTimestamp(), + userLogin: userLogin] + + dispatcher.runSync('updateFixedAssetMaintAndWorkEffort', serviceCtx) + GenericValue newFixedAssetMaint = from('FixedAssetMaint') + .where('fixedAssetId', 'DEMO_VEHICLE_01', + 'maintHistSeqId', '00001') + .queryOne() + assert newFixedAssetMaint.statusId == 'FAM_COMPLETED' + GenericValue workEffort = from('WorkEffort') + .where('workEffortId', fixedAssetMaint.scheduleWorkEffortId) + .queryOne() + assert workEffort.currentStatusId == 'CAL_COMPLETED' assert workEffort.actualCompletionDate == serviceCtx.actualCompletionDate } }