From 305fd250d40a603a90a002616c80cf36a0b94c01 Mon Sep 17 00:00:00 2001
From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local>
Date: Thu, 28 May 2020 16:05:25 +0200
Subject: [PATCH] Optimisation of workflow signals and workflow_lib

---
 .../WorkflowSignal_entity/WorkflowSignal_entity.aod  |  3 ---
 .../recordcontainers/db/conditionProcess.js          | 12 +++++++++++-
 .../WorkflowStartConfig_entity.aod                   |  2 ++
 .../entityfields/object_type/displayValueProcess.js  |  6 ++++++
 entity/WorkflowStartConfig_entity/imageProcess.js    |  6 ++++++
 .../WorkflowStartConfigFilter_view.aod               |  8 ++++----
 process/Workflow_lib/process.js                      |  5 +++--
 7 files changed, 32 insertions(+), 10 deletions(-)
 create mode 100644 entity/WorkflowStartConfig_entity/entityfields/object_type/displayValueProcess.js
 create mode 100644 entity/WorkflowStartConfig_entity/imageProcess.js

diff --git a/entity/WorkflowSignal_entity/WorkflowSignal_entity.aod b/entity/WorkflowSignal_entity/WorkflowSignal_entity.aod
index 22dc96a8eb..05b77e9fea 100644
--- a/entity/WorkflowSignal_entity/WorkflowSignal_entity.aod
+++ b/entity/WorkflowSignal_entity/WorkflowSignal_entity.aod
@@ -154,9 +154,6 @@
           <name>PROCESSDEFINITION_KEY.value</name>
           <recordfield>WORKFLOWSIGNAL.PROCESSDEFINITION_KEY</recordfield>
         </dbRecordFieldMapping>
-        <dbRecordFieldMapping>
-          <name>ICON.value</name>
-        </dbRecordFieldMapping>
         <dbRecordFieldMapping>
           <name>VARIABLES.value</name>
           <recordfield>WORKFLOWSIGNAL.VARIABLES</recordfield>
diff --git a/entity/WorkflowSignal_entity/recordcontainers/db/conditionProcess.js b/entity/WorkflowSignal_entity/recordcontainers/db/conditionProcess.js
index 1bae28698e..f923d3d408 100644
--- a/entity/WorkflowSignal_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/WorkflowSignal_entity/recordcontainers/db/conditionProcess.js
@@ -1,6 +1,16 @@
+import("system.vars");
+import("system.workflow");
 import("Sql_lib");
 import("system.result");
 
-var cond = newWhereIfSet("WORKFLOWSIGNAL.PROCESSDEFINITION_KEY", "$param.ProcessDefinitionKey_param");
+//include all signals with the same names as the ones in the current workflow definition to avoid conflicts
+var signals = JSON.parse(workflow.getSignalDefinitions(vars.get("$param.ProcessDefinitionId_param")));
+var signalNames = signals.map(function (signal)
+{
+    return signal.name;
+});
+
+var cond = newWhereIfSet("WORKFLOWSIGNAL.PROCESSDEFINITION_KEY", "$param.ProcessDefinitionKey_param")
+    .orIfSet("WORKFLOWSIGNAL.SIGNAL_NAME", signalNames, SqlBuilder.IN()); 
 
 result.string(cond.toString());
\ No newline at end of file
diff --git a/entity/WorkflowStartConfig_entity/WorkflowStartConfig_entity.aod b/entity/WorkflowStartConfig_entity/WorkflowStartConfig_entity.aod
index d0a308b0c5..52186117b0 100644
--- a/entity/WorkflowStartConfig_entity/WorkflowStartConfig_entity.aod
+++ b/entity/WorkflowStartConfig_entity/WorkflowStartConfig_entity.aod
@@ -4,6 +4,7 @@
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <documentation>%aditoprj%/entity/WorkflowStartConfig_entity/documentation.adoc</documentation>
   <title>Usage</title>
+  <imageProcess>%aditoprj%/entity/WorkflowStartConfig_entity/imageProcess.js</imageProcess>
   <titlePlural>Usage</titlePlural>
   <recordContainer>db</recordContainer>
   <entityFields>
@@ -18,6 +19,7 @@
       <title>Module</title>
       <consumer>Contexts</consumer>
       <mandatory v="true" />
+      <displayValueProcess>%aditoprj%/entity/WorkflowStartConfig_entity/entityfields/object_type/displayValueProcess.js</displayValueProcess>
     </entityField>
     <entityField>
       <name>TRIGGER_EVENT</name>
diff --git a/entity/WorkflowStartConfig_entity/entityfields/object_type/displayValueProcess.js b/entity/WorkflowStartConfig_entity/entityfields/object_type/displayValueProcess.js
new file mode 100644
index 0000000000..af662ad247
--- /dev/null
+++ b/entity/WorkflowStartConfig_entity/entityfields/object_type/displayValueProcess.js
@@ -0,0 +1,6 @@
+import("Context_lib");
+import("system.result");
+import("system.vars");
+
+var context = vars.get("$field.OBJECT_TYPE");
+result.string(context ? ContextUtils.getTitle(context, true) : "");
\ No newline at end of file
diff --git a/entity/WorkflowStartConfig_entity/imageProcess.js b/entity/WorkflowStartConfig_entity/imageProcess.js
new file mode 100644
index 0000000000..34147b89bd
--- /dev/null
+++ b/entity/WorkflowStartConfig_entity/imageProcess.js
@@ -0,0 +1,6 @@
+import("system.result");
+import("system.vars");
+import("system.project");
+
+var contextModel = project.getDataModel(project.DATAMODEL_KIND_CONTEXT, vars.get("$field.OBJECT_TYPE"));
+result.string(contextModel ? contextModel[5] : "");
\ No newline at end of file
diff --git a/neonView/WorkflowStartConfigFilter_view/WorkflowStartConfigFilter_view.aod b/neonView/WorkflowStartConfigFilter_view/WorkflowStartConfigFilter_view.aod
index 4b53e42cfc..cdac1faccf 100644
--- a/neonView/WorkflowStartConfigFilter_view/WorkflowStartConfigFilter_view.aod
+++ b/neonView/WorkflowStartConfigFilter_view/WorkflowStartConfigFilter_view.aod
@@ -15,12 +15,12 @@
       <autoNewRow v="true" />
       <columns>
         <neonTableColumn>
-          <name>0784e90b-133d-4d2b-b499-ac731a690f64</name>
-          <entityField>OBJECT_TYPE</entityField>
+          <name>4935777f-8760-4759-a70a-0ad64c506418</name>
+          <entityField>#IMAGE</entityField>
         </neonTableColumn>
         <neonTableColumn>
-          <name>c8b4032c-ce59-45fe-ab03-e393f8cdc050</name>
-          <entityField>TRIGGER_EVENT</entityField>
+          <name>0784e90b-133d-4d2b-b499-ac731a690f64</name>
+          <entityField>OBJECT_TYPE</entityField>
         </neonTableColumn>
       </columns>
     </tableViewTemplate>
diff --git a/process/Workflow_lib/process.js b/process/Workflow_lib/process.js
index 39b2bdb10b..179875a721 100644
--- a/process/Workflow_lib/process.js
+++ b/process/Workflow_lib/process.js
@@ -204,8 +204,9 @@ WorkflowSignalSender.deleted = function (pTargetId, pTargetContext)
  * @param {String} pEvent event
  * @param {String} pTargetId uid of the dataset
  * @param {String} pTargetContext context of the dataset
+ * @param {Object} pVariables additional variables to set
  */
-WorkflowSignalSender.eventHappened = function (pEvent, pTargetId, pTargetContext)
+WorkflowSignalSender.eventHappened = function (pEvent, pTargetId, pTargetContext, pVariables)
 {
     var variables = WorkflowVariables.getTargetVariables(pTargetId, pTargetContext);
     
@@ -214,7 +215,7 @@ WorkflowSignalSender.eventHappened = function (pEvent, pTargetId, pTargetContext
     {
         if (_checkCondition(signal.entity, variables[WorkflowVariables.TARGET_ID()], signal.condition))
         {
-            var filteredVariables = {};
+            var filteredVariables = pVariables || {};
             signal.variables.forEach(function (varName)
             {
                 filteredVariables[varName] = variables[varName];
-- 
GitLab