details:   https://code.openbravo.com/erp/devel/pi/rev/ea18c2c210a6
changeset: 29463:ea18c2c210a6
user:      Gorka Ion Damián <gorkaion.damian <at> openbravo.com>
date:      Fri May 13 11:26:47 2016 +0200
summary:   Fixed issue 32950.Use HashSet instead of ArrayList to avoid 
duplicates

The product ids are now stored using HashSet as this implementation does not
allow duplicates.

The method to create the vars in some scenarios is throwing a OBException that
is properly catch. It has been changed the try to avoid the OBException and
remove the error message from the logs.

diffstat:

 src/org/openbravo/event/ProductCharacteristicValueEventHandler.java |  23 
++++++---
 1 files changed, 15 insertions(+), 8 deletions(-)

diffs (70 lines):

diff -r 84003e2e052d -r ea18c2c210a6 
src/org/openbravo/event/ProductCharacteristicValueEventHandler.java
--- a/src/org/openbravo/event/ProductCharacteristicValueEventHandler.java       
Fri May 13 07:18:46 2016 +0200
+++ b/src/org/openbravo/event/ProductCharacteristicValueEventHandler.java       
Fri May 13 11:26:47 2016 +0200
@@ -18,9 +18,9 @@
  */
 package org.openbravo.event;
 
-import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
 
 import javax.enterprise.event.Observes;
 
@@ -46,7 +46,7 @@
   protected Logger logger = Logger.getLogger(this.getClass());
   private static Entity[] entities = { ModelProvider.getInstance().getEntity(
       ProductCharacteristicValue.ENTITY_NAME) };
-  private static ThreadLocal<List<String>> prodchvalueUpdated = new 
ThreadLocal<List<String>>();
+  private static ThreadLocal<Set<String>> prodchvalueUpdated = new 
ThreadLocal<Set<String>>();
 
   @Override
   protected Entity[] getObservedEntities() {
@@ -55,7 +55,7 @@
 
   @SuppressWarnings("unused")
   public void onTransactionBegin(@Observes TransactionBeginEvent event) {
-    prodchvalueUpdated.set(null);
+    prodchvalueUpdated.set(new HashSet<String>());
   }
 
   public void onNew(@Observes EntityNewEvent event) {
@@ -83,7 +83,7 @@
   }
 
   public void onTransactionCompleted(@Observes TransactionCompletedEvent 
event) {
-    List<String> productList = prodchvalueUpdated.get();
+    Set<String> productList = prodchvalueUpdated.get();
     prodchvalueUpdated.set(null);
     prodchvalueUpdated.remove();
     if (productList == null || productList.isEmpty() || 
event.getTransaction().wasRolledBack()) {
@@ -92,7 +92,14 @@
     try {
       VariablesSecureApp vars = null;
       try {
-        vars = RequestContext.get().getVariablesSecureApp();
+        if (RequestContext.get().getRequest() == null) {
+          vars = new 
VariablesSecureApp(OBContext.getOBContext().getUser().getId(), OBContext
+              .getOBContext().getCurrentClient().getId(), 
OBContext.getOBContext()
+              .getCurrentOrganization().getId(), 
OBContext.getOBContext().getRole().getId(),
+              OBContext.getOBContext().getLanguage().getLanguage());
+        } else {
+          vars = RequestContext.get().getVariablesSecureApp();
+        }
       } catch (Exception e) {
         vars = new 
VariablesSecureApp(OBContext.getOBContext().getUser().getId(), OBContext
             .getOBContext().getCurrentClient().getId(), 
OBContext.getOBContext()
@@ -115,9 +122,9 @@
   }
 
   private void addProductToList(ProductCharacteristicValue pchv) {
-    List<String> productList = prodchvalueUpdated.get();
+    Set<String> productList = prodchvalueUpdated.get();
     if (productList == null) {
-      productList = new ArrayList<String>();
+      productList = new HashSet<String>();
     }
     productList.add(pchv.getProduct().getId());
     prodchvalueUpdated.set(productList);

------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to