Files
ofbiz-framework/applications/order/groovyScripts/entry/ShipSettings.groovy
T
Jacques Le Roux 28e119027c Improved: Use Groovy Truth instead of UtilValidate Class in Groovy
(OFBIZ-11064)

As we all know, Groovy is a powerful language with great built-in functions. 
Groovy Truth[1] is one of them, which is not used properly in our code base. 
We have used UtilValidate Class to validate arguments for Empty or NotEmpty, 
which can easily be done in groovy with built-in functionality[1].
 
Current Code: if (UtilValidate.isNotEmpty(locations)) { ... }
Groovy Built-in Code: if (locations) { ... }
 
[1] - http://groovy-lang.org/semantics.html#Groovy-Truth
 
We need to careful for some points while we change this:
Like:
maxRetry = 0
if (!maxRetry)
{  // Not set, use a default  maxRetry = -1 }

Because groovy evaluates zero to be false, it wouldn't be possible to set
maxRetry to zero.  So it's best not to use groovy truth for null-checks on
numbers in some cases. 
 
Thanks: Pawan Verma

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1860051 13f79535-47bb-0310-9956-ffa450edef68
2019-05-26 10:36:16 +00:00

125 lines
5.3 KiB
Groovy

/*
* 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.condition.EntityCondition
import org.apache.ofbiz.entity.condition.EntityConditionBuilder
import org.apache.ofbiz.entity.util.EntityUtil
import org.apache.ofbiz.party.contact.ContactHelper
import org.apache.ofbiz.party.contact.ContactMechWorker
import org.apache.ofbiz.base.util.UtilValidate
cart = session.getAttribute("shoppingCart")
if (cart) {
createNewShipGroup = request.getParameter("createNewShipGroup")
if ("Y".equals(createNewShipGroup)) {
cart.addShipInfo()
}
orderPartyId = cart.getPartyId()
shipToPartyId = parameters.shipToPartyId
context.cart = cart
if(shipToPartyId) {
context.shipToPartyId = shipToPartyId
} else {
context.shipToPartyId = cart.getShipToCustomerPartyId()
}
// nuke the event messages
request.removeAttribute("_EVENT_MESSAGE_")
if ("SALES_ORDER".equals(cart.getOrderType())) {
if (!"_NA_".equals(orderPartyId)) {
orderParty = from("Party").where("partyId", orderPartyId).queryOne()
if (orderParty) {
shippingContactMechList = ContactHelper.getContactMech(orderParty, "SHIPPING_LOCATION", "POSTAL_ADDRESS", false)
orderPerson = orderParty.getRelatedOne("Person", false)
context.orderParty = orderParty
context.orderPerson = orderPerson
context.shippingContactMechList = shippingContactMechList
}
}
// Ship to another party
if (!context.shipToPartyId.equals(orderPartyId)) {
shipToParty = from("Party").where("partyId", context.shipToPartyId).queryOne()
if (shipToParty) {
shipToPartyShippingContactMechList = ContactHelper.getContactMech(shipToParty, "SHIPPING_LOCATION", "POSTAL_ADDRESS", false)
context.shipToPartyShippingContactMechList = shipToPartyShippingContactMechList
}
}
// suppliers for the drop-ship select box
suppliers = from("PartyRole").where("roleTypeId", "SUPPLIER").queryList()
context.suppliers = suppliers
//resolve Purchase agreements
EntityConditionBuilder conditionBuilder = new EntityConditionBuilder()
EntityCondition agreementCond = conditionBuilder.AND() {
IN(partyIdTo: EntityUtil.getFieldListFromEntityList(suppliers, 'partyId', true))
EQUALS(agreementTypeId: 'PURCHASE_AGREEMENT')
}
context.supplierAgreements = from("Agreement").where(agreementCond).queryList()
// facilities used to reserve the items per ship group
productStoreFacilities = from("ProductStoreFacility").where("productStoreId", cart.getProductStoreId()).queryList()
context.productStoreFacilities = productStoreFacilities
} else {
// Purchase order
if (!"_NA_".equals(orderPartyId)) {
orderParty = from("Party").where("partyId", orderPartyId).queryOne()
if (orderParty) {
orderPerson = orderParty.getRelatedOne("Person", false)
context.orderParty = orderParty
context.orderPerson = orderPerson
}
}
companyId = cart.getBillToCustomerPartyId()
if (companyId) {
facilityMaps = []
facilities = from("Facility").where("ownerPartyId", companyId).cache(true).queryList()
// if facilites is null then check the PartyRelationship where there is a relationship set for Parent & Child organization. Then also fetch the value of companyId from there.
if (!facilities) {
partyRelationship = from("PartyRelationship").where("roleTypeIdFrom": "PARENT_ORGANIZATION", "partyIdTo": companyId).queryFirst()
if (partyRelationship) {
companyId = partyRelationship.partyIdFrom
facilities = from("Facility").where("ownerPartyId", companyId).cache(true).queryList()
}
}
facilities.each { facility ->
facilityMap = [:]
facilityContactMechValueMaps = ContactMechWorker.getFacilityContactMechValueMaps(delegator, facility.facilityId, false, null)
facilityMap.facilityContactMechList = facilityContactMechValueMaps
facilityMap.facility = facility
facilityMaps.add(facilityMap)
}
context.facilityMaps = facilityMaps
}
// Ship to another party
if (!context.shipToPartyId.equals(orderPartyId)) {
shipToParty = from("Party").where("partyId", context.shipToPartyId).queryOne()
if (shipToParty)
{
shipToPartyShippingContactMechList = ContactHelper.getContactMech(shipToParty, "SHIPPING_LOCATION", "POSTAL_ADDRESS", false)
context.shipToPartyShippingContactMechList = shipToPartyShippingContactMechList
}
}
}
}