details:   https://code.openbravo.com/erp/devel/pi/rev/b0a2bbcee76e
changeset: 24111:b0a2bbcee76e
user:      Ioritz Cia <ioritz.cia <at> openbravo.com>
date:      Tue Jul 22 10:25:04 2014 +0200
summary:   Fixes issue 27147: [Mobile Physical Inventory] Physical Inventory 
processing needs to support hooks.

diffstat:

 src/org/openbravo/materialmgmt/InventoryCountProcess.java          |  44 
++++++++++
 src/org/openbravo/materialmgmt/hook/InventoryCountCheckHook.java   |   8 +
 src/org/openbravo/materialmgmt/hook/InventoryCountProcessHook.java |   8 +
 3 files changed, 60 insertions(+), 0 deletions(-)

diffs (114 lines):

diff -r 931f25c23aa2 -r b0a2bbcee76e 
src/org/openbravo/materialmgmt/InventoryCountProcess.java
--- a/src/org/openbravo/materialmgmt/InventoryCountProcess.java Tue Jul 22 
16:08:00 2014 +0200
+++ b/src/org/openbravo/materialmgmt/InventoryCountProcess.java Tue Jul 22 
10:25:04 2014 +0200
@@ -3,9 +3,14 @@
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
 import org.apache.commons.lang.time.DateUtils;
 import org.apache.log4j.Logger;
 import org.hibernate.Query;
@@ -30,6 +35,8 @@
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
 import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.materialmgmt.hook.InventoryCountCheckHook;
+import org.openbravo.materialmgmt.hook.InventoryCountProcessHook;
 import org.openbravo.model.ad.access.User;
 import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.model.common.plm.AttributeSet;
@@ -48,6 +55,14 @@
 public class InventoryCountProcess implements Process {
   private static final Logger log4j = 
Logger.getLogger(InventoryCountProcess.class);
 
+  @Inject
+  @Any
+  private Instance<InventoryCountCheckHook> inventoryCountChecks;
+
+  @Inject
+  @Any
+  private Instance<InventoryCountCheckHook> inventoryCountProcesses;
+
   @Override
   public void execute(ProcessBundle bundle) throws Exception {
     OBError msg = new OBError();
@@ -233,11 +248,26 @@
       checkStock(inventory);
     }
 
+    try {
+      executeHooks(inventoryCountProcesses, inventory);
+    } catch (Exception e) {
+      OBException obException = new OBException(e.getMessage(), e.getCause());
+      throw obException;
+    }
+
     inventory.setProcessed(true);
     return msg;
   }
 
   private void runChecks(InventoryCount inventory) throws OBException {
+
+    try {
+      executeHooks(inventoryCountChecks, inventory);
+    } catch (Exception e) {
+      OBException obException = new OBException(e.getMessage(), e.getCause());
+      throw obException;
+    }
+
     if (inventory.isProcessed()) {
       throw new 
OBException(OBMessageUtils.parseTranslation("@AlreadyPosted@"));
     }
@@ -382,4 +412,18 @@
           .replaceAll("%4", storageDetail.getStorageBin().getIdentifier())));
     }
   }
+
+  private void executeHooks(Instance<? extends Object> hooks, InventoryCount 
inventory)
+      throws Exception {
+    if (hooks != null) {
+      for (Iterator<? extends Object> procIter = hooks.iterator(); 
procIter.hasNext();) {
+        Object proc = procIter.next();
+        if (proc instanceof InventoryCountProcessHook) {
+          ((InventoryCountProcessHook) proc).exec(inventory);
+        } else {
+          ((InventoryCountCheckHook) proc).exec(inventory);
+        }
+      }
+    }
+  }
 }
diff -r 931f25c23aa2 -r b0a2bbcee76e 
src/org/openbravo/materialmgmt/hook/InventoryCountCheckHook.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/materialmgmt/hook/InventoryCountCheckHook.java  Tue Jul 
22 10:25:04 2014 +0200
@@ -0,0 +1,8 @@
+package org.openbravo.materialmgmt.hook;
+
+import org.openbravo.model.materialmgmt.transaction.InventoryCount;
+
+public interface InventoryCountCheckHook {
+
+  public void exec(InventoryCount inventory) throws Exception;
+}
\ No newline at end of file
diff -r 931f25c23aa2 -r b0a2bbcee76e 
src/org/openbravo/materialmgmt/hook/InventoryCountProcessHook.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/materialmgmt/hook/InventoryCountProcessHook.java        
Tue Jul 22 10:25:04 2014 +0200
@@ -0,0 +1,8 @@
+package org.openbravo.materialmgmt.hook;
+
+import org.openbravo.model.materialmgmt.transaction.InventoryCount;
+
+public interface InventoryCountProcessHook {
+
+  public void exec(InventoryCount inventory) throws Exception;
+}
\ No newline at end of file

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to