# HG changeset patch
# User Gorka Ion Damián <gorkaion.damian@openbravo.com>
# Date 1448366606 -3600
# Node ID 23e12d1939b871c84613193d6fe6f77d5c968757
# Parent  9bd74e8a00d328f4af989e10fb1fa5e4736f857f
Fixed issue 31564.Added ImportEntryPostProcessor hook.

Added new ImportEntryPostProcessor hook. This hook is executed in the
ImportEntryProcessRunnable class after the processEntry() method is called.
This hook is then executed after the main Import Entry process is executed and
finished and it is committed.

diff -r 9bd74e8a00d3 -r 23e12d1939b8 src/org/openbravo/service/importprocess/ImportEntryPostProcessor.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/service/importprocess/ImportEntryPostProcessor.java	Tue Nov 24 13:03:26 2015 +0100
@@ -0,0 +1,33 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2015 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.service.importprocess;
+
+import org.openbravo.service.importprocess.ImportEntryProcessor.ImportEntryProcessRunnable;
+
+/**
+ * Abstract/default class used to inject logic to an Import Entry when its process is finished and
+ * the commit is done.
+ * 
+ * Is called from the {@link ImportEntryProcessRunnable#run()} method.
+ * 
+ */
+public abstract class ImportEntryPostProcessor {
+
+  public abstract void afterCreate(ImportEntry importEntry);
+}
diff -r 9bd74e8a00d3 -r 23e12d1939b8 src/org/openbravo/service/importprocess/ImportEntryProcessor.java
--- a/src/org/openbravo/service/importprocess/ImportEntryProcessor.java	Tue Nov 24 12:41:26 2015 +0100
+++ b/src/org/openbravo/service/importprocess/ImportEntryProcessor.java	Tue Nov 24 13:03:26 2015 +0100
@@ -29,6 +29,8 @@
 import java.util.concurrent.ExecutorService;
 
 import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
 import javax.inject.Inject;
 
 import org.apache.log4j.Logger;
@@ -40,6 +42,7 @@
 import org.openbravo.dal.core.TriggerHandler;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.model.common.enterprise.Organization;
+import org.openbravo.service.importprocess.ImportEntryManager.ImportEntryProcessorSelector;
 
 /**
  * The {@link ImportEntryProcessor} is responsible for importing/processing {@link ImportEntry}
@@ -270,6 +273,10 @@
     // when the garbagecollector runs
     private Map<String, OBContext> cachedOBContexts = new HashMap<String, OBContext>();
 
+    @Inject
+    @Any
+    private Instance<ImportEntryPostProcessor> importEntryPostProcessors;
+
     public ImportEntryProcessRunnable() {
       logger = Logger.getLogger(this.getClass());
     }
@@ -356,6 +363,12 @@
 
           processEntry(localImportEntry);
 
+          // Execute post process hooks.
+          for (ImportEntryPostProcessor importEntryPostProcessor : importEntryPostProcessors
+              .select(new ImportEntryProcessorSelector(typeOfData))) {
+            importEntryPostProcessor.afterCreate(localImportEntry);
+          }
+
           if (logger.isDebugEnabled()) {
             logger.debug("Finished Processing entry " + localImportEntry.getIdentifier() + " "
                 + typeOfData);
