From c04255c92b996e19dc1bd109a4df464dcdc357d6 Mon Sep 17 00:00:00 2001
From: "d.buechler" <d.buechler@adito.de>
Date: Thu, 4 Apr 2019 11:34:30 +0200
Subject: [PATCH] =?UTF-8?q?Logs=20werden=20nun=20beim=20hinzuf=C3=BCgen=20?=
 =?UTF-8?q?von=20Teilnehmern=20angelegt=20Fehler:=20"Wenn=20Teilnehmer=20i?=
 =?UTF-8?q?n=20Kampagnenstufe=20hinzugef=C3=BCgt=20wird=20soll=20zus=C3=A4?=
 =?UTF-8?q?tzlich=20zur=20vorausgew=C3=A4hlten=20kampagne=20auch=20die=20a?=
 =?UTF-8?q?ktuelle=20stufe=20vorausgew=C3=A4hlt=20werden"=20wurde=20behobe?=
 =?UTF-8?q?n=20Diverse=20Logausgaben=20entfernt?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../recordcontainers/jdito/onInsert.js        | 17 ++++++--
 .../CampaignParticipant_entity.aod            |  1 +
 .../entityfields/campaign_id/valueProcess.js  |  7 +++-
 .../campaignstep_id/displayValueProcess.js    |  2 +-
 .../campaignstep_id/valueProcess.js           |  3 +-
 .../contact_id/linkedContextProcess.js        |  1 -
 .../contactcontext/valueProcess.js            |  4 --
 .../onDBInsert.js                             |  9 +++++
 .../entityfields/campaign_id/valueProcess.js  |  1 -
 process/Campaign_lib/process.js               | 40 +++++++++++++++++--
 10 files changed, 67 insertions(+), 18 deletions(-)
 create mode 100644 entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/onDBInsert.js

diff --git a/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js b/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
index 2c0ffca3092..e8edf991ced 100644
--- a/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
+++ b/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
@@ -1,19 +1,25 @@
 import("system.vars");
 import("system.db");
 import("system.util");
+import("Campaign_lib");
 
 var campaignId     = vars.getString("$field.CAMPAIGN_ID");
 var campaignStepId = vars.getString("$field.CAMPAIGNSTEP_ID");
 var participants   = JSON.parse(vars.getString("$param.campaignParticipants_param"));
 
-var cols = [ "CAMPAIGNPARTICIPANTID"
+var colNamesCampaignParticipantLog = CampaignUtils.getParticipantLogInsertColumnNames();
+var colTypesCampaignParticipantLog = CampaignUtils.getParticipantLogInsertColumnTypes();
+
+var colsCampaignParticipant = [ "CAMPAIGNPARTICIPANTID"
 ,"CONTACT_ID"
 ,"CAMPAIGN_ID"
 ,"CAMPAIGNSTEP_ID"
 ,"USER_NEW"
 ,"DATE_NEW"
 ];
-var colTypes = db.getColumnTypes("CAMPAIGNPARTICIPANT", cols);
+
+var colTypesCampaignParticipant = db.getColumnTypes("CAMPAIGNPARTICIPANT", colsCampaignParticipant);
+
 
 var insertArray = [];
 
@@ -21,15 +27,18 @@ for (participant in participants)
 {
     let campaignParticipantId = util.getNewUUID();
     
-    var vals = [ campaignParticipantId
+    var valsCampaignParticipant = [ campaignParticipantId
     , participants[participant]
     , campaignId
     , campaignStepId
     , vars.get("$sys.user")
     , vars.get("$sys.date")
     ];
+    
+    var valsCampaignParticipantLog = new Array(campaignId, campaignStepId, participants[participant], campaignParticipantId, vars.get("$sys.user"), vars.get("$sys.date"));
 
-    insertArray.push(["CAMPAIGNPARTICIPANT", cols, colTypes, vals]);
+    insertArray.push(["CAMPAIGNPARTICIPANT", colsCampaignParticipant, colTypesCampaignParticipant, valsCampaignParticipant]);
+    insertArray.push(["CAMPAIGNPARTICIPANTLOG", colNamesCampaignParticipantLog, colTypesCampaignParticipantLog, valsCampaignParticipantLog]);
 }
 
 db.inserts(insertArray);
\ No newline at end of file
diff --git a/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod b/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod
index 24a2e510c37..a049a87b4f9 100644
--- a/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod
+++ b/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod
@@ -153,6 +153,7 @@
       <name>ParticipantsDbRecordContainer</name>
       <alias>Data_alias</alias>
       <conditionProcess>%aditoprj%/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/conditionProcess.js</conditionProcess>
+      <onDBInsert>%aditoprj%/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/onDBInsert.js</onDBInsert>
       <linkInformation>
         <linkInformation>
           <name>12b5bf2e-e376-4c40-9799-fb07961a455d</name>
diff --git a/entity/CampaignParticipant_entity/entityfields/campaign_id/valueProcess.js b/entity/CampaignParticipant_entity/entityfields/campaign_id/valueProcess.js
index 95645706dce..619a4eb3879 100644
--- a/entity/CampaignParticipant_entity/entityfields/campaign_id/valueProcess.js
+++ b/entity/CampaignParticipant_entity/entityfields/campaign_id/valueProcess.js
@@ -2,5 +2,8 @@ import("system.neon");
 import("system.result");
 import("system.vars");
 
-if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.exists("$param.CampaignId_param") && vars.get("$param.CampaignId_param"))
-    result.string(vars.get("$param.CampaignId_param"));
\ No newline at end of file
+if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && 
+    vars.exists("$param.CampaignId_param") && vars.get("$param.CampaignId_param"))
+    {
+        result.string(vars.get("$param.CampaignId_param"));
+    }
\ No newline at end of file
diff --git a/entity/CampaignParticipant_entity/entityfields/campaignstep_id/displayValueProcess.js b/entity/CampaignParticipant_entity/entityfields/campaignstep_id/displayValueProcess.js
index 0bdd6ffe53a..50b15240cd3 100644
--- a/entity/CampaignParticipant_entity/entityfields/campaignstep_id/displayValueProcess.js
+++ b/entity/CampaignParticipant_entity/entityfields/campaignstep_id/displayValueProcess.js
@@ -2,4 +2,4 @@ import("system.vars");
 import("system.db");
 import("system.result");
 
-result.string(db.cell("select NAME from CAMPAIGNSTEP where CAMPAIGNSTEPID = '" + vars.get("$field.CAMPAIGNSTEP_ID") + "'"));
\ No newline at end of file
+result.string(db.cell("select NAME from CAMPAIGNSTEP where CAMPAIGNSTEPID = '" + vars.get("$param.CampaignStepId_param") + "'"));
\ No newline at end of file
diff --git a/entity/CampaignParticipant_entity/entityfields/campaignstep_id/valueProcess.js b/entity/CampaignParticipant_entity/entityfields/campaignstep_id/valueProcess.js
index 33f528285fb..15e340261a9 100644
--- a/entity/CampaignParticipant_entity/entityfields/campaignstep_id/valueProcess.js
+++ b/entity/CampaignParticipant_entity/entityfields/campaignstep_id/valueProcess.js
@@ -3,8 +3,7 @@ import("system.result");
 import("system.vars");
 
 if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && 
-   vars.exists("$param.CampaignStepId_param") && 
-   vars.get("$param.CampaignStepId_param"))
+   vars.exists("$param.CampaignStepId_param") && vars.get("$param.CampaignStepId_param"))
 {
    result.string(vars.get("$param.CampaignStepId_param"));
 }
\ No newline at end of file
diff --git a/entity/CampaignParticipant_entity/entityfields/contact_id/linkedContextProcess.js b/entity/CampaignParticipant_entity/entityfields/contact_id/linkedContextProcess.js
index 8196f20b7e9..6e599325755 100644
--- a/entity/CampaignParticipant_entity/entityfields/contact_id/linkedContextProcess.js
+++ b/entity/CampaignParticipant_entity/entityfields/contact_id/linkedContextProcess.js
@@ -3,5 +3,4 @@ import("system.vars");
 import("system.result");
 import("Contact_lib");
 
-logging.log("CONTACT_ID -> getContextByContactId: " +ContactUtils.getContextByContactId(vars.getString("$field.CONTACT_ID")));
 result.string(ContactUtils.getContextByContactId(vars.getString("$field.CONTACT_ID")));
\ No newline at end of file
diff --git a/entity/CampaignParticipant_entity/entityfields/contactcontext/valueProcess.js b/entity/CampaignParticipant_entity/entityfields/contactcontext/valueProcess.js
index 184fa53a959..2e504d63e3b 100644
--- a/entity/CampaignParticipant_entity/entityfields/contactcontext/valueProcess.js
+++ b/entity/CampaignParticipant_entity/entityfields/contactcontext/valueProcess.js
@@ -1,9 +1,5 @@
-import("system.logging");
 import("system.vars");
 import("system.result");
 import("Contact_lib");
 
-logging.log("getContextByContactId: " + ContactUtils.getContextByContactId(vars.getString("$field.CONTACT_ID")));
-logging.log("vars.getString($field.CONTACT_ID: " + vars.getString("$field.CONTACT_ID"));
-
 result.string(ContactUtils.getContextByContactId(vars.getString("$field.CONTACT_ID")));
\ No newline at end of file
diff --git a/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/onDBInsert.js b/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/onDBInsert.js
new file mode 100644
index 00000000000..c6903032cc3
--- /dev/null
+++ b/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/onDBInsert.js
@@ -0,0 +1,9 @@
+import("system.vars");
+import("Campaign_lib");
+
+var campaignId = vars.get("$field.CAMPAIGN_ID");
+var campaignStepId = vars.get("$field.CAMPAIGNSTEP_ID");
+var contactId = vars.get("$field.CONTACT_ID");
+var campaignParticipantId = vars.get("$field.CAMPAIGNPARTICIPANTID");
+
+CampaignUtils.createLogEntry(campaignId, campaignStepId, contactId, campaignParticipantId);
\ No newline at end of file
diff --git a/entity/CampaignStep_entity/entityfields/campaign_id/valueProcess.js b/entity/CampaignStep_entity/entityfields/campaign_id/valueProcess.js
index 7ae7bfcabec..0a46eaaae9f 100644
--- a/entity/CampaignStep_entity/entityfields/campaign_id/valueProcess.js
+++ b/entity/CampaignStep_entity/entityfields/campaign_id/valueProcess.js
@@ -2,6 +2,5 @@ import("system.logging");
 import("system.result");
 import("system.vars");
 
-logging.log("______CampaignStep_Campaign_ID_valueProcess: -> " + vars.get("$param.campaignId_param"));
 if(vars.exists("$param.campaignId_param") && vars.get("$param.campaignId_param"))
     result.string(vars.get("$param.campaignId_param"));
\ No newline at end of file
diff --git a/process/Campaign_lib/process.js b/process/Campaign_lib/process.js
index 739c90141be..c4842134323 100644
--- a/process/Campaign_lib/process.js
+++ b/process/Campaign_lib/process.js
@@ -1,3 +1,4 @@
+import("system.vars");
 import("system.db");
 import("system.neon");
 import("Sql_lib");
@@ -15,11 +16,11 @@ function CampaignUtils() {}
 /**
  * Add one Contact (Person or Organistaion) to a Campaign
  * 
- * @param {String} pRowId req ContactId
+ * @param {String} pContactId req ContactId
  */
-CampaignUtils.addParticipant = function(pRowId)
+CampaignUtils.addParticipant = function(pContactId)
 {
-    _CampaignUtils._openAddParticipantContext("CampaignParticipant", pRowId, "ContactId_param", "CampaignParticipantEdit_view");
+    _CampaignUtils._openAddParticipantContext("CampaignParticipant", pContactId, "ContactId_param", "CampaignParticipantEdit_view");
 }
 
 /**
@@ -70,6 +71,36 @@ CampaignUtils.getCampaignStatusByCampaignId = function(pCampaignId)
     return KeywordUtils.getViewValue(campaignState, statusId);
 }
 
+/**
+ * todo
+ */
+CampaignUtils.createLogEntry = function(pCampaignId, pCampaignStepId, pContactId, pCampaignParticipantId)
+{
+    let colsCampaignParticipantLog = CampaignUtils.getParticipantLogInsertColumnNames();
+    let colTypesCampaignParticipantLog = CampaignUtils.getParticipantLogInsertColumnTypes();
+    
+    let valsCampaignParticipantLog = new Array(pCampaignId, pCampaignStepId, pContactId, pCampaignParticipantId, vars.get("$sys.user"), vars.get("$sys.date"));
+    
+    let rows = db.insertData("CAMPAIGNPARTICIPANTLOG", colsCampaignParticipantLog, colTypesCampaignParticipantLog, valsCampaignParticipantLog);
+    return (rows == 1);
+}
+
+/**
+ * todo
+ */
+CampaignUtils.getParticipantLogInsertColumnNames = function()
+{
+    return new Array("CAMPAIGN_ID", "CAMPAIGNSTEP_ID", "CONTACT_ID", "CAMPAIGNPARTICIPANTLOGID", "USER_NEW", "DATE_NEW");
+}
+
+/**
+ * todo
+ */
+CampaignUtils.getParticipantLogInsertColumnTypes = function()
+{
+    return db.getColumnTypes("CAMPAIGNPARTICIPANTLOG", CampaignUtils.getParticipantLogInsertColumnNames());
+}
+
 /**
  * Methods for campaignmanagement.
  * Do not create an instance of this!
@@ -100,6 +131,9 @@ _CampaignUtils._openAddParticipantContext = function(pContext, pRowIds, pEntityP
     neon.openContext(pContext, pView, null, neon.OPERATINGSTATE_NEW, params);
 }
 
+/**
+ * todo
+ */
 _CampaignUtils._loadSingleValueFromDb = function(pSelectQuery, pConditionField, pConditionValue, pDefaultValue)
 {
     let res = pDefaultValue;
-- 
GitLab