Related to issue Related to issue 29766: Retail Operations Buffer: store all transactions in operations table before processing
authorMartin Taal <martin.taal@openbravo.com>
Sun, 07 Jun 2015 13:09:55 +0200
changeset 26869 41fa0431e85a
parent 26868 531993ed12e7
child 26870 c57a5fc3eaf2
child 26871 456fc69bb708
child 28306 282c3ea2cbd3
Related to issue Related to issue 29766: Retail Operations Buffer: store all transactions in operations table before processing
Removed default value of imported column, set default value on importstatus, various smaller changes from code review comments
src-db/database/model/tables/C_IMPORT_ENTRY.xml
src/org/openbravo/service/importprocess/ImportEntryArchiveManager.java
src/org/openbravo/service/importprocess/ImportEntryManager.java
src/org/openbravo/service/importprocess/ImportEntryProcessor.java
src/org/openbravo/service/importprocess/ImportReprocessErrorEntries.java
src/org/openbravo/service/importprocess/ProcessImportEntriesProcessActionHandler.java
--- a/src-db/database/model/tables/C_IMPORT_ENTRY.xml	Sat Jun 06 23:54:18 2015 +0000
+++ b/src-db/database/model/tables/C_IMPORT_ENTRY.xml	Sun Jun 07 13:09:55 2015 +0200
@@ -34,7 +34,7 @@
         <onCreateDefault/>
       </column>
       <column name="IMPORTED" primaryKey="false" required="false" type="TIMESTAMP" size="7" autoIncrement="false">
-        <default><![CDATA[SYSDATE]]></default>
+        <default/>
         <onCreateDefault/>
       </column>
       <column name="JSONINFO" primaryKey="false" required="false" type="CLOB" size="4000" autoIncrement="false">
@@ -42,7 +42,7 @@
         <onCreateDefault/>
       </column>
       <column name="IMPORTSTATUS" primaryKey="false" required="true" type="VARCHAR" size="60" autoIncrement="false">
-        <default/>
+        <default><![CDATA[Initial]]></default>
         <onCreateDefault/>
       </column>
       <column name="TYPEOFDATA" primaryKey="false" required="true" type="VARCHAR" size="60" autoIncrement="false">
--- a/src/org/openbravo/service/importprocess/ImportEntryArchiveManager.java	Sat Jun 06 23:54:18 2015 +0000
+++ b/src/org/openbravo/service/importprocess/ImportEntryArchiveManager.java	Sun Jun 07 13:09:55 2015 +0200
@@ -19,7 +19,6 @@
 package org.openbravo.service.importprocess;
 
 import java.util.Date;
-import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -146,12 +145,8 @@
 
               ImportEntryArchive archiveEntry = createArchiveEntry(importEntry);
 
-              for (Iterator<? extends Object> procIter = manager.archiveEntryPreProcessors
-                  .iterator(); procIter.hasNext();) {
-                ImportEntryArchivePreProcessor processor = (ImportEntryArchivePreProcessor) procIter
-                    .next();
+              for (ImportEntryArchivePreProcessor processor : manager.archiveEntryPreProcessors) {
                 processor.beforeArchive(importEntry, archiveEntry);
-
               }
 
               log.debug("Processed one entry");
--- a/src/org/openbravo/service/importprocess/ImportEntryManager.java	Sat Jun 06 23:54:18 2015 +0000
+++ b/src/org/openbravo/service/importprocess/ImportEntryManager.java	Sun Jun 07 13:09:55 2015 +0200
@@ -24,7 +24,6 @@
 import java.lang.annotation.Target;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ArrayBlockingQueue;
@@ -239,8 +238,10 @@
    * Note will commit the session/connection using {@link OBDal#commitAndClose()}
    */
   public void createImportEntry(String id, String typeOfData, String json) {
+    // make sure that everything is flushed to the db before checking import entry
+    // content
     OBDal.getInstance().flush();
-    OBContext.setAdminMode(false);
+    OBContext.setAdminMode(true);
     try {
       // check if it is not there already or already archived
       {
@@ -276,8 +277,7 @@
       importEntry.setTypeofdata(typeOfData);
       importEntry.setJsonInfo(json);
 
-      for (Iterator<? extends Object> procIter = entryPreProcessors.iterator(); procIter.hasNext();) {
-        ImportEntryPreProcessor processor = (ImportEntryPreProcessor) procIter.next();
+      for (ImportEntryPreProcessor processor : entryPreProcessors) {
         processor.beforeCreate(importEntry);
       }
       OBDal.getInstance().save(importEntry);
@@ -398,7 +398,8 @@
     final OBContext prevOBContext = OBContext.getOBContext();
     OBContext.setOBContext("0", "0", "0", "0");
     try {
-      OBContext.setAdminMode();
+      // no need to do client/org checks on these actions, as in error, do the least possible
+      OBContext.setAdminMode(false);
       ImportEntry importEntry = OBDal.getInstance().get(ImportEntry.class, importEntryId);
       if (importEntry != null && !"Processed".equals(importEntry.getImportStatus())) {
         importEntry.setImportStatus("Error");
@@ -517,7 +518,6 @@
                       // errors, so always catch them to prevent other import entries
                       // from not getting processed
                       manager.setImportEntryError(entry.getId(), t);
-                      OBDal.getInstance().flush();
                     }
                   }
                 } finally {
--- a/src/org/openbravo/service/importprocess/ImportEntryProcessor.java	Sat Jun 06 23:54:18 2015 +0000
+++ b/src/org/openbravo/service/importprocess/ImportEntryProcessor.java	Sun Jun 07 13:09:55 2015 +0200
@@ -285,7 +285,7 @@
             setOBContext(queuedImportEntry);
 
             try {
-              OBContext.setAdminMode();
+              OBContext.setAdminMode(true);
               ImportEntry localImportEntry;
               try {
                 // reload the importEntry
@@ -398,7 +398,7 @@
     }
 
     protected void setVariablesSecureApp(OBContext obContext) {
-      OBContext.setAdminMode();
+      OBContext.setAdminMode(true);
       try {
         final VariablesSecureApp variablesSecureApp = new VariablesSecureApp(obContext.getUser()
             .getId(), obContext.getCurrentClient().getId(), obContext.getCurrentOrganization()
--- a/src/org/openbravo/service/importprocess/ImportReprocessErrorEntries.java	Sat Jun 06 23:54:18 2015 +0000
+++ b/src/org/openbravo/service/importprocess/ImportReprocessErrorEntries.java	Sun Jun 07 13:09:55 2015 +0200
@@ -40,7 +40,8 @@
   protected void doExecute(ProcessBundle bundle) throws Exception {
     super.setDoCommit(false);
     logger = bundle.getLogger();
-    OBContext.setAdminMode();
+    // don't do client/org check on resetting import error status
+    OBContext.setAdminMode(false);
     try {
       final Query qry = OBDal
           .getInstance()
--- a/src/org/openbravo/service/importprocess/ProcessImportEntriesProcessActionHandler.java	Sat Jun 06 23:54:18 2015 +0000
+++ b/src/org/openbravo/service/importprocess/ProcessImportEntriesProcessActionHandler.java	Sun Jun 07 13:09:55 2015 +0200
@@ -56,7 +56,8 @@
       JSONObject msgTotal = new JSONObject();
       JSONArray actions = new JSONArray();
 
-      final DalConnectionProvider dalConnectionProvider = new DalConnectionProvider();
+      // no flush needed as only needed to get some messages
+      final DalConnectionProvider dalConnectionProvider = new DalConnectionProvider(false);
 
       final String importProcessLbl = Utility.messageBD(dalConnectionProvider, "ImportProcess",
           OBContext.getOBContext().getLanguage().getLanguage());