details: https://code.openbravo.com/erp/devel/pi/rev/9045f47e9ae7 changeset: 35174:9045f47e9ae7 user: Gorka Gil <gorka.gil <at> openbravo.com> date: Wed Nov 28 13:52:50 2018 +0100 summary: [TerminalLog] Related to issue 39360: Add Terminal Log project
Implement the ability in the import entry processor to skip the archiving per entry type diffstat: src/org/openbravo/service/importprocess/ImportEntryArchiveManager.java | 44 ++++++++- src/org/openbravo/service/importprocess/ImportEntryProcessor.java | 9 +- 2 files changed, 45 insertions(+), 8 deletions(-) diffs (115 lines): diff -r 9552199dac5a -r 9045f47e9ae7 src/org/openbravo/service/importprocess/ImportEntryArchiveManager.java --- a/src/org/openbravo/service/importprocess/ImportEntryArchiveManager.java Wed Nov 28 08:57:15 2018 +0000 +++ b/src/org/openbravo/service/importprocess/ImportEntryArchiveManager.java Wed Nov 28 13:52:50 2018 +0100 @@ -20,6 +20,8 @@ import java.util.Date; import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -38,6 +40,7 @@ import org.openbravo.dal.service.OBDal; import org.openbravo.dal.service.OBQuery; import org.openbravo.service.importprocess.ImportEntryManager.DaemonThreadFactory; +import org.openbravo.service.importprocess.ImportEntryManager.ImportEntryProcessorSelector; /** * Class responsible for moving {@link ImportEntry} objects to the {@link ImportEntryArchive} table. @@ -78,6 +81,12 @@ private boolean isShutDown = false; + @Inject + @Any + private Instance<ImportEntryProcessor> entryProcessors; + + private Map<String, ImportEntryProcessor> importEntryProcessors = new ConcurrentHashMap<String, ImportEntryProcessor>(); + public ImportEntryArchiveManager() { instance = this; } @@ -98,6 +107,21 @@ executorService = null; } + private ImportEntryProcessor getImportEntryProcessor(String qualifier) { + ImportEntryProcessor importEntryProcessor = importEntryProcessors.get(qualifier); + if (importEntryProcessor == null) { + importEntryProcessor = entryProcessors.select(new ImportEntryProcessorSelector(qualifier)) + .get(); + if (importEntryProcessor != null) { + importEntryProcessors.put(qualifier, importEntryProcessor); + } else { + // caller should handle it + return null; + } + } + return importEntryProcessor; + } + private static class ImportEntryArchiveThread implements Runnable { private final ImportEntryArchiveManager manager; @@ -177,20 +201,26 @@ dataProcessed = true; lastCreated = importEntry.getCreationDate(); - ImportEntryArchive archiveEntry = createArchiveEntry(importEntry); - if (manager.isShutDown) { return; } + ImportEntryProcessor importEntryProcessor = ImportEntryArchiveManager.getInstance() + .getImportEntryProcessor(importEntry.getTypeofdata()); + if (importEntryProcessor == null || importEntryProcessor.enableArchive()) { - for (ImportEntryArchivePreProcessor processor : manager.archiveEntryPreProcessors) { - processor.beforeArchive(importEntry, archiveEntry); + ImportEntryArchive archiveEntry = createArchiveEntry(importEntry); + + for (ImportEntryArchivePreProcessor processor : manager.archiveEntryPreProcessors) { + processor.beforeArchive(importEntry, archiveEntry); + } + + log.debug("Processed one entry"); + OBDal.getInstance().save(archiveEntry); + } else { + log.debug("Skipped one entry of type " + importEntry.getTypeofdata()); } - log.debug("Processed one entry"); - OBDal.getInstance().remove(importEntry); - OBDal.getInstance().save(archiveEntry); } // commit in batches of 1000 records OBDal.getInstance().commitAndClose(); diff -r 9552199dac5a -r 9045f47e9ae7 src/org/openbravo/service/importprocess/ImportEntryProcessor.java --- a/src/org/openbravo/service/importprocess/ImportEntryProcessor.java Wed Nov 28 08:57:15 2018 +0000 +++ b/src/org/openbravo/service/importprocess/ImportEntryProcessor.java Wed Nov 28 13:52:50 2018 +0100 @@ -11,7 +11,7 @@ * 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-2017 Openbravo SLU + * All portions are Copyright (C) 2015-2018 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -234,6 +234,13 @@ protected abstract String getProcessSelectionKey(ImportEntry importEntry); /** + * Declares if the import entry will later on be archived after it has been processed + */ + protected boolean enableArchive() { + return true; + } + + /** * The default implementation of the ImportEntryProcessRunnable. It performs the following * actions: * <ul> _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits