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
This commit is contained in:
@@ -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)
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user