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 735048f6be Improved: Convert StorageServices.xml mini-lang to groovyDSL (OFBIZ-9350) (OFBIZ-12669) 735048f6be is described below commit 735048f6be36e428e4ff14078cb5d59090efe8ee Author: Nicolas Malin <nicolas.ma...@nereide.fr> AuthorDate: Fri Jul 15 14:31:18 2022 +0200 Improved: Convert StorageServices.xml mini-lang to groovyDSL (OFBIZ-9350) (OFBIZ-12669) Convert the service createFacilityLocation from minilang to groovyDSL Thanks to Tom Gibert for the help --- .../facility/storage/StorageServices.groovy | 48 +++++++++++++++++++ .../minilang/product/storage/StorageServices.xml | 56 ---------------------- .../product/servicedef/services_facility.xml | 9 ++-- 3 files changed, 52 insertions(+), 61 deletions(-) diff --git a/applications/product/groovyScripts/facility/storage/StorageServices.groovy b/applications/product/groovyScripts/facility/storage/StorageServices.groovy new file mode 100644 index 0000000000..295a24fda7 --- /dev/null +++ b/applications/product/groovyScripts/facility/storage/StorageServices.groovy @@ -0,0 +1,48 @@ +/* + * 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 facility.storage + +import org.apache.ofbiz.entity.GenericValue + +/** + * Create a Facility Location + * @return + */ +def createFacilityLocation() { + GenericValue newEntity = makeValue("FacilityLocation", parameters) + + String locationSeqId = "${parameters.areaId ?: ''}${parameters.aisleId ?: ''}${parameters.sectionId ?: ''}${parameters.levelId ?: ''}${parameters.positionId ?: ''}" + if (locationSeqId) { + int i = 1 + String nextLocationSeqId = locationSeqId + while (from("FacilityLocation") + .where([locationSeqId: nextLocationSeqId, + facilityId: parameters.facilityId]) + .queryOne()) { + nextLocationSeqId = "${locationSeqId}_${i++}" + } + locationSeqId = nextLocationSeqId + } else { + locationSeqId = delegator.getNextSeqId("FacilityLocation") + } + + newEntity.locationSeqId = locationSeqId + newEntity.create() + return success(locationSeqId : newEntity.locationSeqId) +} diff --git a/applications/product/minilang/product/storage/StorageServices.xml b/applications/product/minilang/product/storage/StorageServices.xml deleted file mode 100644 index 0383a7db23..0000000000 --- a/applications/product/minilang/product/storage/StorageServices.xml +++ /dev/null @@ -1,56 +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"> - - <!-- Facility Location Services --> - <simple-method method-name="createFacilityLocation" short-description="Create a Facility Location"> - <make-value entity-name="FacilityLocation" value-field="newEntity"/> - <set-nonpk-fields map="parameters" value-field="newEntity"/> - <set field="newEntity.facilityId" from-field="parameters.facilityId"/> - - <set field="locationSeqId" value="${parameters.areaId}${parameters.aisleId}${parameters.sectionId}${parameters.levelId}${parameters.positionId}"/> - <!-- check to see if it exists already, if so try a simple suffix, then give up and use a sequenced id --> - <if-not-empty field="locationSeqId"> - <set field="checkLocationSeqIdMap.locationSeqId" from-field="locationSeqId"/> - <set field="checkLocationSeqIdMap.facilityId" from-field="parameters.facilityId"/> - <find-by-primary-key entity-name="FacilityLocation" map="checkLocationSeqIdMap" value-field="checkLocationSeqIdValue"/> - <if-not-empty field="checkLocationSeqIdValue"> - <set field="locationSeqId" value="${locationSeqId}_2"/> - <set field="checkLocationSeqIdMap.locationSeqId" from-field="locationSeqId"/> - <set field="checkLocationSeqIdMap.facilityId" from-field="parameters.facilityId"/> - <find-by-primary-key entity-name="FacilityLocation" map="checkLocationSeqIdMap" value-field="checkLocationSeqIdValue"/> - <if-not-empty field="checkLocationSeqIdValue"> - <set field="locationSeqId" value=""/> - </if-not-empty> - </if-not-empty> - </if-not-empty> - - <if-empty field="locationSeqId"> - <sequenced-id sequence-name="FacilityLocation" field="locationSeqId"/> - <to-string field="locationSeqId"/> - </if-empty> - <set field="newEntity.locationSeqId" from-field="locationSeqId"/> - <field-to-result field="locationSeqId" result-name="locationSeqId"/> - - <create-value value-field="newEntity"/> - </simple-method> -</simple-methods> diff --git a/applications/product/servicedef/services_facility.xml b/applications/product/servicedef/services_facility.xml index f794acad9c..e48439ba9e 100644 --- a/applications/product/servicedef/services_facility.xml +++ b/applications/product/servicedef/services_facility.xml @@ -917,18 +917,17 @@ under the License. <auto-attributes mode="IN" entity-name="FacilityAttribute" include="pk" optional="false"/> </service> - <service name="createFacilityLocation" default-entity-name="FacilityLocation" engine="simple" - location="component://product/minilang/product/storage/StorageServices.xml" invoke="createFacilityLocation" auth="true"> + <service name="createFacilityLocation" default-entity-name="FacilityLocation" engine="groovy" invoke="createFacilityLocation" + location="component://product/groovyScripts/facility/storage/StorageServices.groovy" auth="true"> <description>Create a Facility Location</description> <permission-service service-name="facilityGenericPermission" main-action="CREATE"/> <auto-attributes include="nonpk" mode="IN" optional="true"/> - <attribute name="facilityId" type="String" mode="IN" optional="false"> + <attribute name="facilityId" type="String" mode="IN"> <type-validate> <fail-property resource="ProductErrorUiLabels" property="facility.facilityId"/> </type-validate> </attribute> - - <attribute name="locationSeqId" type="String" mode="OUT" optional="false"/> + <attribute name="locationSeqId" type="String" mode="OUT"/> </service> <service name="updateFacilityLocation" default-entity-name="FacilityLocation" engine="entity-auto" invoke="update" auth="true"> <description>Update a Facility Location</description>