[OFBiz] SVN: r5905 - in trunk/applications:
order/src/org/ofbiz/order/order party/src/org/ofbiz/party/party
jonesde at svn.ofbiz.org
jonesde at svn.ofbiz.org
Mon Oct 3 22:48:09 EDT 2005
Author: jonesde
Date: 2005-10-03 21:48:02 -0500 (Mon, 03 Oct 2005)
New Revision: 5905
Modified:
trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
trunk/applications/party/src/org/ofbiz/party/party/PartyWorker.java
Log:
Small refactoring to extract logic for getting latest UserLogin and Locale for a Party
Modified: trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
===================================================================
--- trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java 2005-10-04 01:47:42 UTC (rev 5904)
+++ trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java 2005-10-04 02:48:02 UTC (rev 5905)
@@ -70,6 +70,7 @@
import org.ofbiz.order.shoppingcart.CheckOutHelper;
import org.ofbiz.order.shoppingcart.shipping.ShippingEvents;
import org.ofbiz.party.contact.ContactHelper;
+import org.ofbiz.party.party.PartyWorker;
import org.ofbiz.product.product.ProductContentWrapper;
import org.ofbiz.product.product.ProductWorker;
import org.ofbiz.product.store.ProductStoreWorker;
@@ -1954,21 +1955,9 @@
// or if not available then the system Locale
Locale locale = null;
GenericValue placingParty = orh.getPlacingParty();
- GenericValue placingUserLogin = null;
+ GenericValue placingUserLogin = placingParty == null ? null : PartyWorker.findPartyLatestUserLogin(placingParty.getString("partyId"), delegator);
if (locale == null && placingParty != null) {
- // just get the most recent UserLogin for this party, if there is one...
- try {
- List placingUserLoginList = delegator.findByAnd("UserLogin", UtilMisc.toMap("partyId", placingParty.get("partyId")), UtilMisc.toList("-" + ModelEntity.STAMP_FIELD));
- if (placingUserLoginList != null && placingUserLoginList.size() > 0) {
- placingUserLogin = (GenericValue) placingUserLoginList.get(0);
- String localeString = placingUserLogin.getString("lastLocale");
- if (UtilValidate.isNotEmpty(localeString)) {
- locale = UtilMisc.parseLocale(localeString);
- }
- }
- } catch (GenericEntityException e) {
- Debug.logError(e, "Error getting Placing Party UserLogin for order email notification, will try other sources: " + e.toString(), module);
- }
+ locale = PartyWorker.findPartyLastLocale(placingParty.getString("partyId"), delegator);
}
GenericValue productStore = OrderReadHelper.getProductStoreFromOrder(orderHeader);
if (locale == null && productStore != null) {
Modified: trunk/applications/party/src/org/ofbiz/party/party/PartyWorker.java
===================================================================
--- trunk/applications/party/src/org/ofbiz/party/party/PartyWorker.java 2005-10-04 01:47:42 UTC (rev 5904)
+++ trunk/applications/party/src/org/ofbiz/party/party/PartyWorker.java 2005-10-04 02:48:02 UTC (rev 5905)
@@ -1,7 +1,7 @@
/*
* $Id$
*
- * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
+ * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -26,6 +26,8 @@
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
import java.util.Map;
import javax.servlet.ServletRequest;
@@ -38,6 +40,8 @@
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.model.ModelEntity;
+import org.ofbiz.entity.util.EntityUtil;
/**
* Worker methods for Party Information
@@ -114,4 +118,28 @@
return clubId;
}
+
+ public static GenericValue findPartyLatestUserLogin(String partyId, GenericDelegator delegator) {
+ try {
+ List userLoginList = delegator.findByAnd("UserLogin", UtilMisc.toMap("partyId", partyId), UtilMisc.toList("-" + ModelEntity.STAMP_FIELD));
+ return EntityUtil.getFirst(userLoginList);
+ } catch (GenericEntityException e) {
+ Debug.logError(e, "Error while finding latest UserLogin for party with ID [" + partyId + "]: " + e.toString(), module);
+ return null;
+ }
+ }
+
+ public static Locale findPartyLastLocale(String partyId, GenericDelegator delegator) {
+ // just get the most recent UserLogin for this party, if there is one...
+ GenericValue userLogin = findPartyLatestUserLogin(partyId, delegator);
+ if (userLogin == null) {
+ return null;
+ }
+ String localeString = userLogin.getString("lastLocale");
+ if (UtilValidate.isNotEmpty(localeString)) {
+ return UtilMisc.parseLocale(localeString);
+ } else {
+ return null;
+ }
+ }
}
More information about the Svn
mailing list