From 913a1ee371f8d438cb592ec7fde33634edafc7b5 Mon Sep 17 00:00:00 2001
From: cramakri <cramakri>
Date: Wed, 16 May 2012 14:58:28 +0000
Subject: [PATCH] SP-45 BIS-21 : Use the process function to process incoming
 in jython v2

SVN: 25289
---
 .../JythonTopLevelDataSetHandler.java         | 23 +++++++++++++------
 .../v2/JythonTopLevelDataSetHandlerV2.java    | 16 +++++++++++++
 .../registrator/TestingDataSetHandler.java    |  4 ++--
 .../registrator/TestingDataSetHandlerV2.java  |  4 ++--
 4 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/JythonTopLevelDataSetHandler.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/JythonTopLevelDataSetHandler.java
index e4c47cd9499..d16d8033f1d 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/JythonTopLevelDataSetHandler.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/JythonTopLevelDataSetHandler.java
@@ -163,6 +163,7 @@ public class JythonTopLevelDataSetHandler<T extends DataSetInformation> extends
                 (JythonDataSetRegistrationService<T>) genericService;
 
         executeJythonScript(dataSetFile, scriptString, service);
+        executeJythonProcessFunction(service.interpreter);
     }
 
     private void executeJythonScript(File dataSetFile, String scriptString,
@@ -178,6 +179,14 @@ public class JythonTopLevelDataSetHandler<T extends DataSetInformation> extends
         verifyEvaluatorHookFunctions(interpreter);
     }
 
+    /**
+     * Execute the function that processes the data set. Subclasses may override.
+     */
+    protected void executeJythonProcessFunction(PythonInterpreter interpreter)
+    {
+
+    }
+
     private void verifyEvaluatorHookFunctions(PythonInterpreter interpreter)
     {
         for (JythonHookFunction function : JythonHookFunction.values())
@@ -455,20 +464,20 @@ public class JythonTopLevelDataSetHandler<T extends DataSetInformation> extends
     private void invokeRollbackServiceFunction(PyFunction function,
             DataSetRegistrationService<T> service, Throwable throwable)
     {
-        invokeFuncion(service, function, service, throwable);
+        invokeFunction(service, function, service, throwable);
     }
 
     private void invokeRollbackTransactionFunction(PyFunction function,
             DataSetRegistrationService<T> service, DataSetRegistrationTransaction<T> transaction,
             DataSetStorageAlgorithmRunner<T> algorithmRunner, Throwable throwable)
     {
-        invokeFuncion(service, function, service, transaction, algorithmRunner, throwable);
+        invokeFunction(service, function, service, transaction, algorithmRunner, throwable);
     }
 
     private void invokeServiceTransactionFunction(PyFunction function,
             DataSetRegistrationService<T> service, DataSetRegistrationTransaction<T> transaction)
     {
-        invokeFuncion(service, function, service, transaction);
+        invokeFunction(service, function, service, transaction);
     }
 
     private void invokeTransactionFunctionWithContext(PyFunction function,
@@ -477,11 +486,11 @@ public class JythonTopLevelDataSetHandler<T extends DataSetInformation> extends
     {
         if (additionalArgs.length > 0)
         {
-            invokeFuncion(service, function, transaction.getTransactionPersistentMap(),
+            invokeFunction(service, function, transaction.getTransactionPersistentMap(),
                     additionalArgs);
         } else
         {
-            invokeFuncion(service, function, transaction.getTransactionPersistentMap());
+            invokeFunction(service, function, transaction.getTransactionPersistentMap());
         }
     }
 
@@ -489,14 +498,14 @@ public class JythonTopLevelDataSetHandler<T extends DataSetInformation> extends
             DataSetRegistrationService<T> service, DataSetRegistrationTransaction<T> transaction,
             List<SecondaryTransactionFailure> secondaryErrors)
     {
-        invokeFuncion(service, function, service, transaction, secondaryErrors);
+        invokeFunction(service, function, service, transaction, secondaryErrors);
     }
 
     /**
      * Turns all arguments into a python objects, and calls the specified function. Service is here
      * only for the tests, so that the tests can hook it
      */
-    protected void invokeFuncion(DataSetRegistrationService<T> service, PyFunction function,
+    protected void invokeFunction(DataSetRegistrationService<T> service, PyFunction function,
             Object... args)
     {
         PyObject[] pyArgs = new PyObject[args.length];
diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/JythonTopLevelDataSetHandlerV2.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/JythonTopLevelDataSetHandlerV2.java
index 60d395a9184..7afc1b74552 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/JythonTopLevelDataSetHandlerV2.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/JythonTopLevelDataSetHandlerV2.java
@@ -18,8 +18,10 @@ package ch.systemsx.cisd.etlserver.registrator.api.v2;
 
 import java.io.File;
 
+import org.python.core.PyFunction;
 import org.python.util.PythonInterpreter;
 
+import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel;
 import ch.systemsx.cisd.common.utilities.IDelegatedActionWithResult;
 import ch.systemsx.cisd.common.utilities.PythonUtils;
 import ch.systemsx.cisd.etlserver.ITopLevelDataSetRegistratorDelegate;
@@ -91,6 +93,20 @@ public class JythonTopLevelDataSetHandlerV2<T extends DataSetInformation> extend
         interpreter.set(FACTORY_VARIABLE_NAME, service.getDataSetRegistrationDetailsFactory());
     }
 
+    @Override
+    protected void executeJythonProcessFunction(PythonInterpreter interpreter)
+    {
+        String PROCESS_FUNCTION_NAME = "process";
+        try
+        {
+            PyFunction function = interpreter.get(PROCESS_FUNCTION_NAME, PyFunction.class);
+            function.__call__();
+        } catch (Exception e)
+        {
+            throw CheckedExceptionTunnel.wrapIfNecessary(e);
+        }
+    }
+
     @Override
     protected boolean shouldUseOldJythonHookFunctions()
     {
diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/TestingDataSetHandler.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/TestingDataSetHandler.java
index 8b082b41c37..a5b2a6a8a2c 100644
--- a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/TestingDataSetHandler.java
+++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/TestingDataSetHandler.java
@@ -56,11 +56,11 @@ public class TestingDataSetHandler extends JythonTopLevelDataSetHandler<DataSetI
     }
 
     @Override
-    protected void invokeFuncion(
+    protected void invokeFunction(
             ch.systemsx.cisd.etlserver.registrator.DataSetRegistrationService<DataSetInformation> service,
             PyFunction function, Object... args)
     {
-        super.invokeFuncion(service, function, args);
+        super.invokeFunction(service, function, args);
         expectations.checkPythonInterpreterVariables(service);
     }
 
diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/TestingDataSetHandlerV2.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/TestingDataSetHandlerV2.java
index 9188b999228..0f57f24b6bf 100644
--- a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/TestingDataSetHandlerV2.java
+++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/TestingDataSetHandlerV2.java
@@ -57,11 +57,11 @@ public class TestingDataSetHandlerV2 extends JythonTopLevelDataSetHandlerV2<Data
     }
 
     @Override
-    protected void invokeFuncion(
+    protected void invokeFunction(
             ch.systemsx.cisd.etlserver.registrator.DataSetRegistrationService<DataSetInformation> service,
             PyFunction function, Object... args)
     {
-        super.invokeFuncion(service, function, args);
+        super.invokeFunction(service, function, args);
         expectations.checkPythonInterpreterVariables(service);
     }
 
-- 
GitLab