Project:
View Issue Details[ Jump to Notes ] | [ Issue History ] [ Print ] | |||||||||||
ID | ||||||||||||
0033644 | ||||||||||||
Type | Category | Severity | Reproducibility | Date Submitted | Last Update | |||||||
design defect | [Retail Modules] Web POS | minor | have not tried | 2016-08-07 11:13 | 2017-01-17 17:23 | |||||||
Reporter | mtaal | View Status | public | |||||||||
Assigned To | Retail | |||||||||||
Priority | normal | Resolution | open | Fixed in Version | ||||||||
Status | new | Fix in branch | Fixed in SCM revision | |||||||||
Projection | none | ETA | none | Target Version | ||||||||
OS | Any | Database | Any | Java version | ||||||||
OS Version | Database version | Ant version | ||||||||||
Product Version | SCM revision | |||||||||||
Review Assigned To | ||||||||||||
Regression level | ||||||||||||
Regression date | ||||||||||||
Regression introduced in release | ||||||||||||
Regression introduced by commit | ||||||||||||
Triggers an Emergency Pack | No | |||||||||||
Summary | 0033644: Too many preference queries, this while preferences are cached in the http session already | |||||||||||
Description | When using WebPOS there are many places where a query for preferences is done for the current user, code like this [1]. In addition while logging in all preferences are read/queried [2]. This can also all be read from the session as all preferences are already loaded in the session also [3]. [1] https://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/file/6de25cf75f58/src/org/openbravo/retail/posterminal/master/Product.java#l76 [^] [2] https://code.openbravo.com/erp/pmods/org.openbravo.mobile.core/file/0b3137a4bb61/src/org/openbravo/mobile/core/login/RolePermissions.java#l122 [^] [3] https://code.openbravo.com/erp/devel/pi/file/ae1076c7e9ea/src/org/openbravo/base/secureApp/LoginUtils.java#l332 [^] | |||||||||||
Steps To Reproduce | Enable sql logging Login to webpos check how many preference queries are being done | |||||||||||
Proposed Solution | Add a method to the Preferences class to read a preference for the current user. When logging in then instead of calling getAllPreferences, read the preferences which are already present in the session. | |||||||||||
Tags | No tags attached. | |||||||||||
Attached Files | rolepermission-diff-not-applied.diff [^] (4,133 bytes) 2016-08-07 11:38 [Show Content] [Hide Content]diff --git a/src/org/openbravo/mobile/core/login/RolePermissions.java b/src/org/openbravo/mobile/core/login/RolePermissions.java --- a/src/org/openbravo/mobile/core/login/RolePermissions.java +++ b/src/org/openbravo/mobile/core/login/RolePermissions.java @@ -12,16 +12,19 @@ import java.io.IOException; import java.io.Writer; import java.util.ArrayList; +import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import javax.servlet.ServletException; +import javax.servlet.http.HttpSession; import org.apache.log4j.Logger; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; +import org.openbravo.client.kernel.RequestContext; import org.openbravo.dal.core.OBContext; import org.openbravo.dal.service.OBDal; import org.openbravo.dal.service.OBQuery; @@ -72,8 +75,9 @@ Map<String, Object> prefValues = new HashMap<String, Object>(); // default is false + System.err.println("test"); for (String pref : prefs) { - prefValues.put(pref, false); + prefValues.put(pref.toUpperCase(), false); } prefValues.putAll(getPreferenceValues(prefs)); @@ -119,21 +123,49 @@ private Map<String, Object> getPreferenceValues(List<String> preferenceKeys) { HashSet<String> prefKeys = new HashSet<String>(preferenceKeys); - List<Preference> preferences = Preferences.getAllPreferences(OBContext.getOBContext() - .getCurrentClient().getId(), OBContext.getOBContext().getCurrentOrganization().getId(), - OBContext.getOBContext().getUser().getId(), OBContext.getOBContext().getRole().getId()); + final HttpSession session = RequestContext.get().getSession(); Map<String, Object> result = new HashMap<String, Object>(); - for (Preference preference : preferences) { - if (preference.getProperty() == null || !prefKeys.contains(preference.getProperty())) { - continue; + boolean foundCachedPreferences = false; + if (session != null) { + final Enumeration<?> enumeration = RequestContext.get().getSessionAttributeNames(); + while (enumeration.hasMoreElements()) { + final String enumerationKey = (String) enumeration.nextElement(); + if (enumerationKey.startsWith("P|")) { + final int lastIndexOf = enumerationKey.lastIndexOf("|"); + final String prefKey = enumerationKey.substring(lastIndexOf + 1); + foundCachedPreferences = true; + System.err.println(prefKey); + if (prefKeys.contains(prefKey)) { + + Object prefValue = (String) session.getAttribute(enumerationKey); + if ("Y".equals(prefValue)) { + prefValue = Boolean.TRUE; + } else if ("N".equals(prefValue)) { + prefValue = Boolean.FALSE; + } + System.err.println(prefKey + " --> " + prefValue); + result.put(prefKey, prefValue); + } + } } - Object prefValue = preference.getSearchKey(); - if ("Y".equals(prefValue)) { - prefValue = Boolean.TRUE; - } else if ("N".equals(prefValue)) { - prefValue = Boolean.FALSE; + } + // nothing cached, use the traditional approach + if (!foundCachedPreferences) { + List<Preference> preferences = Preferences.getAllPreferences(OBContext.getOBContext() + .getCurrentClient().getId(), OBContext.getOBContext().getCurrentOrganization().getId(), + OBContext.getOBContext().getUser().getId(), OBContext.getOBContext().getRole().getId()); + for (Preference preference : preferences) { + if (preference.getProperty() == null || !prefKeys.contains(preference.getProperty())) { + continue; + } + Object prefValue = preference.getSearchKey(); + if ("Y".equals(prefValue)) { + prefValue = Boolean.TRUE; + } else if ("N".equals(prefValue)) { + prefValue = Boolean.FALSE; + } + result.put(preference.getProperty(), prefValue); } - result.put(preference.getProperty(), prefValue); } return result; } 33644-posterminal.diff [^] (22,318 bytes) 2016-08-07 12:03 [Show Content] [Hide Content] diff --git a/src/org/openbravo/retail/posterminal/OrderLoader.java b/src/org/openbravo/retail/posterminal/OrderLoader.java --- a/src/org/openbravo/retail/posterminal/OrderLoader.java +++ b/src/org/openbravo/retail/posterminal/OrderLoader.java @@ -158,10 +158,8 @@ */ public void initializeVariables(JSONObject jsonorder) throws JSONException { try { - useOrderDocumentNoForRelatedDocs = "Y".equals(Preferences.getPreferenceValue( - "OBPOS_UseOrderDocumentNoForRelatedDocs", true, OBContext.getOBContext() - .getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(), OBContext - .getOBContext().getUser(), OBContext.getOBContext().getRole(), null)); + useOrderDocumentNoForRelatedDocs = "Y".equals(Preferences.getCurrentPreferenceValue( + "OBPOS_UseOrderDocumentNoForRelatedDocs", true, null)); } catch (PropertyException e1) { log.error( "Error getting OBPOS_UseOrderDocumentNoForRelatedDocs preference: " + e1.getMessage(), e1); diff --git a/src/org/openbravo/retail/posterminal/PaidReceiptsHeader.java b/src/org/openbravo/retail/posterminal/PaidReceiptsHeader.java --- a/src/org/openbravo/retail/posterminal/PaidReceiptsHeader.java +++ b/src/org/openbravo/retail/posterminal/PaidReceiptsHeader.java @@ -45,10 +45,8 @@ boolean useContains = true; try { OBContext.setAdminMode(false); - useContains = "Y".equals(Preferences.getPreferenceValue( - "OBPOS_remote.receipt_usesContains", true, OBContext.getOBContext().getCurrentClient(), - OBContext.getOBContext().getCurrentOrganization(), OBContext.getOBContext().getUser(), - OBContext.getOBContext().getRole(), null)); + useContains = "Y".equals(Preferences.getCurrentPreferenceValue( + "OBPOS_remote.receipt_usesContains", true, null)); } catch (PropertyException e) { log.error("Error getting preference OBPOS_remote.receipt_usesContains " + e.getMessage(), e); } finally { diff --git a/src/org/openbravo/retail/posterminal/event/ProductListEventHandler.java b/src/org/openbravo/retail/posterminal/event/ProductListEventHandler.java --- a/src/org/openbravo/retail/posterminal/event/ProductListEventHandler.java +++ b/src/org/openbravo/retail/posterminal/event/ProductListEventHandler.java @@ -58,9 +58,8 @@ boolean isRemote = false; try { OBContext.setAdminMode(false); - isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.product", true, OBContext - .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(), - OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null)); + isRemote = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_remote.product", true, + null)); } catch (PropertyException e) { logger.error("Error getting preference OBPOS_remote.product " + e.getMessage(), e); } finally { diff --git a/src/org/openbravo/retail/posterminal/master/Brand.java b/src/org/openbravo/retail/posterminal/master/Brand.java --- a/src/org/openbravo/retail/posterminal/master/Brand.java +++ b/src/org/openbravo/retail/posterminal/master/Brand.java @@ -48,9 +48,8 @@ boolean isRemote = false; try { OBContext.setAdminMode(false); - isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.product", true, OBContext - .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(), - OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null)); + isRemote = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_remote.product", true, + null)); } catch (PropertyException e) { log.error("Error getting preference OBPOS_remote.product " + e.getMessage(), e); } finally { @@ -78,10 +77,8 @@ boolean isRemote = false; try { OBContext.setAdminMode(false); - isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.product", true, - OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext() - .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext - .getOBContext().getRole(), null)); + isRemote = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_remote.product", true, + null)); } catch (PropertyException e) { log.error("Error getting preference OBPOS_remote.product " + e.getMessage(), e); } finally { @@ -110,9 +107,8 @@ boolean isRemote = false; try { OBContext.setAdminMode(false); - isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.product", true, OBContext - .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(), - OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null)); + isRemote = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_remote.product", true, + null)); } catch (PropertyException e) { log.error("Error getting preference OBPOS_remote.product " + e.getMessage(), e); } finally { diff --git a/src/org/openbravo/retail/posterminal/master/BrandProperties.java b/src/org/openbravo/retail/posterminal/master/BrandProperties.java --- a/src/org/openbravo/retail/posterminal/master/BrandProperties.java +++ b/src/org/openbravo/retail/posterminal/master/BrandProperties.java @@ -22,9 +22,8 @@ boolean isRemote = false; try { OBContext.setAdminMode(false); - isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.product", true, OBContext - .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(), - OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null)); + isRemote = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_remote.product", true, + null)); } catch (PropertyException e) { log.error("Error getting preference OBPOS_remote.product " + e.getMessage(), e); } finally { diff --git a/src/org/openbravo/retail/posterminal/master/Category.java b/src/org/openbravo/retail/posterminal/master/Category.java --- a/src/org/openbravo/retail/posterminal/master/Category.java +++ b/src/org/openbravo/retail/posterminal/master/Category.java @@ -53,10 +53,8 @@ boolean isRemote = false; try { OBContext.setAdminMode(false); - isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.product", true, - OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext() - .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext - .getOBContext().getRole(), null)); + isRemote = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_remote.product", true, + null)); } catch (PropertyException e) { log.error("Error getting preference OBPOS_remote.product " + e.getMessage(), e); } finally { @@ -102,9 +100,8 @@ boolean isRemote = false; try { OBContext.setAdminMode(false); - isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.product", true, OBContext - .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(), - OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null)); + isRemote = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_remote.product", true, + null)); } catch (PropertyException e) { log.error("Error getting preference OBPOS_remote.product " + e.getMessage(), e); } finally { diff --git a/src/org/openbravo/retail/posterminal/master/CategoryTree.java b/src/org/openbravo/retail/posterminal/master/CategoryTree.java --- a/src/org/openbravo/retail/posterminal/master/CategoryTree.java +++ b/src/org/openbravo/retail/posterminal/master/CategoryTree.java @@ -49,10 +49,8 @@ boolean isRemote = false; try { OBContext.setAdminMode(false); - isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.product", true, - OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext() - .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext - .getOBContext().getRole(), null)); + isRemote = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_remote.product", true, + null)); } catch (PropertyException e) { log.error("Error getting preference OBPOS_remote.product " + e.getMessage(), e); } finally { @@ -84,9 +82,8 @@ boolean isRemote = false; try { OBContext.setAdminMode(true); - isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.product", true, OBContext - .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(), - OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null)); + isRemote = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_remote.product", true, + null)); } catch (PropertyException e) { log.error("Error getting preference OBPOS_remote.product " + e.getMessage(), e); } finally { diff --git a/src/org/openbravo/retail/posterminal/master/Characteristic.java b/src/org/openbravo/retail/posterminal/master/Characteristic.java --- a/src/org/openbravo/retail/posterminal/master/Characteristic.java +++ b/src/org/openbravo/retail/posterminal/master/Characteristic.java @@ -62,9 +62,8 @@ boolean isRemote = false; try { OBContext.setAdminMode(false); - isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.product", true, OBContext - .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(), - OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null)); + isRemote = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_remote.product", true, + null)); } catch (PropertyException e) { log.error("Error getting preference OBPOS_remote.product " + e.getMessage(), e); } finally { diff --git a/src/org/openbravo/retail/posterminal/master/CharacteristicValue.java b/src/org/openbravo/retail/posterminal/master/CharacteristicValue.java --- a/src/org/openbravo/retail/posterminal/master/CharacteristicValue.java +++ b/src/org/openbravo/retail/posterminal/master/CharacteristicValue.java @@ -66,9 +66,8 @@ boolean isRemote = false; try { OBContext.setAdminMode(false); - isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.product", true, OBContext - .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(), - OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null)); + isRemote = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_remote.product", true, + null)); } catch (PropertyException e) { log.error("Error getting preference OBPOS_remote.product " + e.getMessage(), e); } finally { diff --git a/src/org/openbravo/retail/posterminal/master/Discount.java b/src/org/openbravo/retail/posterminal/master/Discount.java --- a/src/org/openbravo/retail/posterminal/master/Discount.java +++ b/src/org/openbravo/retail/posterminal/master/Discount.java @@ -58,10 +58,8 @@ } boolean multiPrices = false; try { - multiPrices = "Y".equals(Preferences.getPreferenceValue("OBPOS_EnableMultiPriceList", true, - OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext() - .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext - .getOBContext().getRole(), null)); + multiPrices = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_EnableMultiPriceList", + true, null)); } catch (PropertyException e1) { log.error("Error getting Preference: " + e1.getMessage(), e1); } diff --git a/src/org/openbravo/retail/posterminal/master/PriceList.java b/src/org/openbravo/retail/posterminal/master/PriceList.java --- a/src/org/openbravo/retail/posterminal/master/PriceList.java +++ b/src/org/openbravo/retail/posterminal/master/PriceList.java @@ -64,10 +64,8 @@ HQLPropertyList priceListHQLProperties = ModelExtensionUtils.getPropertyExtensions(extensions); try { - multiPrices = "Y".equals(Preferences.getPreferenceValue("OBPOS_EnableMultiPriceList", true, - OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext() - .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext - .getOBContext().getRole(), null)); + multiPrices = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_EnableMultiPriceList", + true, null)); } catch (PropertyException e1) { log.error("Error getting Preference: " + e1.getMessage(), e1); } diff --git a/src/org/openbravo/retail/posterminal/master/Product.java b/src/org/openbravo/retail/posterminal/master/Product.java --- a/src/org/openbravo/retail/posterminal/master/Product.java +++ b/src/org/openbravo/retail/posterminal/master/Product.java @@ -73,9 +73,8 @@ posPrecision = (priceList.getCurrency().getObposPosprecision() == null ? priceList .getCurrency().getPricePrecision() : priceList.getCurrency().getObposPosprecision()) .toString(); - isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.product", true, OBContext - .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(), - OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null)); + isRemote = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_remote.product", true, + null)); } catch (PropertyException e) { log.error("Error getting preference OBPOS_remote.product " + e.getMessage(), e); } finally { @@ -84,10 +83,8 @@ boolean isMultipricelist = false; try { OBContext.setAdminMode(false); - isMultipricelist = "Y".equals(Preferences.getPreferenceValue("OBPOS_EnableMultiPriceList", - true, OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext() - .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext - .getOBContext().getRole(), null)); + isMultipricelist = "Y".equals(Preferences.getCurrentPreferenceValue( + "OBPOS_EnableMultiPriceList", true, null)); } catch (PropertyException e) { log.error("Error getting preference EnableMultiPriceList " + e.getMessage(), e); } finally { @@ -132,10 +129,8 @@ boolean isMultipricelist = false; try { OBContext.setAdminMode(false); - isMultipricelist = "Y".equals(Preferences.getPreferenceValue("OBPOS_EnableMultiPriceList", - true, OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext() - .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext - .getOBContext().getRole(), null)); + isMultipricelist = "Y".equals(Preferences.getCurrentPreferenceValue( + "OBPOS_EnableMultiPriceList", true, null)); } catch (PropertyException e) { log.error("Error getting preference EnableMultiPriceList " + e.getMessage(), e); } finally { @@ -144,10 +139,8 @@ boolean isRemote = false; try { OBContext.setAdminMode(false); - isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.product", true, - OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext() - .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext - .getOBContext().getRole(), null)); + isRemote = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_remote.product", true, + null)); } catch (PropertyException e) { log.error("Error getting preference OBPOS_remote.product " + e.getMessage(), e); } finally { @@ -201,9 +194,8 @@ posPrecision = (priceList.getCurrency().getObposPosprecision() == null ? priceList .getCurrency().getPricePrecision() : priceList.getCurrency().getObposPosprecision()) .toString(); - isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.product", true, OBContext - .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(), - OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null)); + isRemote = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_remote.product", true, + null)); } catch (PropertyException e) { log.error("Error getting preference OBPOS_remote.product " + e.getMessage(), e); } finally { @@ -212,10 +204,8 @@ boolean isMultipricelist = false; try { OBContext.setAdminMode(false); - isMultipricelist = "Y".equals(Preferences.getPreferenceValue("OBPOS_EnableMultiPriceList", - true, OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext() - .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext - .getOBContext().getRole(), null)); + isMultipricelist = "Y".equals(Preferences.getCurrentPreferenceValue( + "OBPOS_EnableMultiPriceList", true, null)); } catch (PropertyException e) { log.error("Error getting preference EnableMultiPriceList " + e.getMessage(), e); } finally { diff --git a/src/org/openbravo/retail/posterminal/master/ProductDiscProperties.java b/src/org/openbravo/retail/posterminal/master/ProductDiscProperties.java --- a/src/org/openbravo/retail/posterminal/master/ProductDiscProperties.java +++ b/src/org/openbravo/retail/posterminal/master/ProductDiscProperties.java @@ -49,10 +49,8 @@ { String discountNameTrl; try { - boolean isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.customer", - true, OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext() - .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext - .getOBContext().getRole(), null)); + boolean isRemote = "Y".equals(Preferences.getCurrentPreferenceValue( + "OBPOS_remote.customer", true, null)); if (OBContext.hasTranslationInstalled() && !isRemote) { discountNameTrl = "coalesce ((select pt.name from PricingAdjustmentTrl pt where pt.promotionDiscount=p and pt.language='" + OBContext.getOBContext().getLanguage().getLanguage() + "'), p.name) "; diff --git a/src/org/openbravo/retail/posterminal/master/ProductPrice.java b/src/org/openbravo/retail/posterminal/master/ProductPrice.java --- a/src/org/openbravo/retail/posterminal/master/ProductPrice.java +++ b/src/org/openbravo/retail/posterminal/master/ProductPrice.java @@ -89,10 +89,8 @@ } try { - multiPrices = "Y".equals(Preferences.getPreferenceValue("OBPOS_EnableMultiPriceList", true, - OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext() - .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext - .getOBContext().getRole(), null)); + multiPrices = "Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_EnableMultiPriceList", + true, null)); } catch (PropertyException e1) { log.error("Error getting Preference: " + e1.getMessage(), e1); } diff --git a/src/org/openbravo/retail/posterminal/master/ProductProperties.java b/src/org/openbravo/retail/posterminal/master/ProductProperties.java --- a/src/org/openbravo/retail/posterminal/master/ProductProperties.java +++ b/src/org/openbravo/retail/posterminal/master/ProductProperties.java @@ -64,10 +64,8 @@ private static final long serialVersionUID = 1L; { try { - if ("Y".equals(Preferences.getPreferenceValue("OBPOS_retail.productImages", true, - OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext() - .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext - .getOBContext().getRole(), null))) { + if ("Y".equals(Preferences.getCurrentPreferenceValue("OBPOS_retail.productImages", true, + null))) { } else { add(new HQLProperty("img.bindaryData", "img")); } @@ -146,10 +144,8 @@ { String trlName; try { - boolean isRemote = "Y".equals(Preferences.getPreferenceValue("OBPOS_remote.product", - true, OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext() - .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext - .getOBContext().getRole(), null)); + boolean isRemote = "Y".equals(Preferences.getCurrentPreferenceValue( + "OBPOS_remote.product", true, null)); if (OBContext.hasTranslationInstalled() && !isRemote) { trlName = "coalesce((select pt.name from ProductTrl AS pt where pt.language='" diff --git a/src/org/openbravo/retail/posterminal/term/Terminal.java b/src/org/openbravo/retail/posterminal/term/Terminal.java --- a/src/org/openbravo/retail/posterminal/term/Terminal.java +++ b/src/org/openbravo/retail/posterminal/term/Terminal.java @@ -133,10 +133,8 @@ int sessionTimeout; try { - String sessionShouldExpire = Preferences.getPreferenceValue("OBPOS_SessionTimeout", true, - OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext() - .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext - .getOBContext().getRole(), null); + String sessionShouldExpire = Preferences.getCurrentPreferenceValue("OBPOS_SessionTimeout", + true, null); try { sessionTimeout = sessionShouldExpire == null ? 0 : Integer.parseInt(sessionShouldExpire); } catch (NumberFormatException nfe) { 33644-mobile-core.diff [^] (2,495 bytes) 2016-08-07 12:03 [Show Content] [Hide Content] diff --git a/src/org/openbravo/mobile/core/login/MobileCoreLoginUtilsServlet.java b/src/org/openbravo/mobile/core/login/MobileCoreLoginUtilsServlet.java --- a/src/org/openbravo/mobile/core/login/MobileCoreLoginUtilsServlet.java +++ b/src/org/openbravo/mobile/core/login/MobileCoreLoginUtilsServlet.java @@ -284,8 +284,7 @@ String value; try { - value = Preferences.getPreferenceValue("OBMOBC_ExecutePerformanceTest", true, null, null, - null, null, (String) null); + value = Preferences.getCurrentPreferenceValue("OBMOBC_ExecutePerformanceTest", true, null); data.put("executePerformanceTest", value); } catch (PropertyException e) { data.put("executePerformanceTest", "Y"); diff --git a/src/org/openbravo/mobile/core/process/SecuredJSONProcess.java b/src/org/openbravo/mobile/core/process/SecuredJSONProcess.java --- a/src/org/openbravo/mobile/core/process/SecuredJSONProcess.java +++ b/src/org/openbravo/mobile/core/process/SecuredJSONProcess.java @@ -147,9 +147,7 @@ String property = getProperty(); if (StringUtils.isNotEmpty(property)) { try { - return "Y".equals(Preferences.getPreferenceValue(property, true, OBContext.getOBContext() - .getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(), OBContext - .getOBContext().getUser(), OBContext.getOBContext().getRole(), null)); + return "Y".equals(Preferences.getCurrentPreferenceValue(property, true, null)); } catch (PropertyException e) { return false; } diff --git a/src/org/openbravo/mobile/core/servercontroller/MobileServerUtils.java b/src/org/openbravo/mobile/core/servercontroller/MobileServerUtils.java --- a/src/org/openbravo/mobile/core/servercontroller/MobileServerUtils.java +++ b/src/org/openbravo/mobile/core/servercontroller/MobileServerUtils.java @@ -80,9 +80,7 @@ public static Integer getIntegerPreference(String preference, Integer defaultVal) { try { OBContext.setAdminMode(false); - final String value = Preferences.getPreferenceValue(preference, true, OBContext - .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(), - OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null); + final String value = Preferences.getCurrentPreferenceValue(preference, true, null); return Integer.parseInt(value); } catch (Exception e) { return defaultVal; 33644-erp-core.diff [^] (3,375 bytes) 2016-08-07 12:03 [Show Content] [Hide Content] diff --git a/src/org/openbravo/erpCommon/businessUtility/Preferences.java b/src/org/openbravo/erpCommon/businessUtility/Preferences.java --- a/src/org/openbravo/erpCommon/businessUtility/Preferences.java +++ b/src/org/openbravo/erpCommon/businessUtility/Preferences.java @@ -25,6 +25,7 @@ import org.apache.log4j.Logger; import org.openbravo.base.provider.OBProvider; import org.openbravo.base.secureApp.VariablesSecureApp; +import org.openbravo.client.kernel.RequestContext; import org.openbravo.dal.core.OBContext; import org.openbravo.dal.service.OBDal; import org.openbravo.dal.service.OBQuery; @@ -159,18 +160,18 @@ } /** - * Obtains the value for a given property with the visibility defined by the parameters. In case - * of conflict or the property is not defined an exception is thrown. + * Obtains the value for a given property with the visibility defined by the parameters. In case of conflict or the property is + * not defined an exception is thrown. * <p> - * This method is used to query in database for the property value, note that when properties are - * set, they are also saved as session values and it is possible to obtain them using - * {@link Utility#getPreference(VariablesSecureApp, String, String) Utility.getPreference}. + * This method is used to query in database for the property value, note that when properties are set, they are also saved as + * session values and it is possible to obtain them using {@link Utility#getPreference(VariablesSecureApp, String, String) + * Utility.getPreference}. * * @throws PropertyException * if the property cannot be resolved in a single value: * <ul> - * <li> {@link PropertyNotFoundException} if the property is not defined. <li> - * {@link PropertyConflictException} in case of conflict + * <li> {@link PropertyNotFoundException} if the property is not defined. <li> {@link PropertyConflictException} in + * case of conflict * </ul> */ public static String getPreferenceValue(String property, boolean isListProperty, Client client, @@ -321,6 +322,26 @@ } /** + * Returns a preference value for the current user, using the current users client/org/rol. It also tries to find the preference + * value in the http session, if not found there then it queries for it Storing the result in the http session (if present). The + * http session is only checked if it is present. + */ + public static String getCurrentPreferenceValue(String property, boolean isListProperty, + Window window) throws PropertyException { + final String sessionKey = ("P|" + (window != null ? window.getId() + "|" : "" + property)) + .toUpperCase(); + + String value = RequestContext.get().getVariablesSecureApp().getSessionValue(sessionKey); + if (value == null || value.length() == 0) { + value = getPreferenceValue(property, isListProperty, OBContext.getOBContext() + .getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(), OBContext + .getOBContext().getUser(), OBContext.getOBContext().getRole(), window); + RequestContext.get().getVariablesSecureApp().setSessionValue(sessionKey, value); + } + return value; + } + + /** * Stores the preference as a session value * * @param vars | |||||||||||
Relationships [ Relation Graph ] [ Dependency Graph ] | |
Notes | |
(0088866) mtaal (manager) 2016-08-07 11:33 |
Note: it does not seem possible right away to replace the getAllPreferences in the RolePermission class. This because the preference name is cached in upper case in the http session, while the webpos client uses them in their original mixed casing. |
Issue History | |||
Date Modified | Username | Field | Change |
2016-08-07 11:13 | mtaal | New Issue | |
2016-08-07 11:13 | mtaal | Assigned To | => mtaal |
2016-08-07 11:13 | mtaal | Triggers an Emergency Pack | => No |
2016-08-07 11:33 | mtaal | Note Added: 0088866 | |
2016-08-07 11:38 | mtaal | File Added: rolepermission-diff-not-applied.diff | |
2016-08-07 12:03 | mtaal | File Added: 33644-posterminal.diff | |
2016-08-07 12:03 | mtaal | File Added: 33644-mobile-core.diff | |
2016-08-07 12:03 | mtaal | File Added: 33644-erp-core.diff | |
2016-08-31 01:18 | mtaal | Target Version | RR16Q4 => |
2017-01-17 17:23 | mtaal | Assigned To | mtaal => Retail |
Copyright © 2000 - 2009 MantisBT Group |