From 80854486330a56ede1fd931caadbc789507be32b Mon Sep 17 00:00:00 2001
From: "d.buechler" <d.buechler@adito.de>
Date: Thu, 4 Jul 2019 09:52:20 +0200
Subject: [PATCH] =?UTF-8?q?Kleine=20Fehler=20beim=20Hinzuf=C3=BCgen=20von?=
 =?UTF-8?q?=20Organisationen=20durch=20eine=20Serienaktion=20behoben.=20Lo?=
 =?UTF-8?q?gausgaben=20entfernt?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../isoperationvalid/valueProcess.js          | 24 ++------
 .../recordcontainers/jdito/onInsert.js        | 10 ++-
 .../onActionProcess.js                        |  2 -
 .../addtocampaignfromtable/onActionProcess.js |  4 --
 process/Campaign_lib/process.js               | 61 ++++---------------
 5 files changed, 22 insertions(+), 79 deletions(-)

diff --git a/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js b/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js
index 982aa7d224..3682d70ed9 100644
--- a/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js
+++ b/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js
@@ -1,15 +1,9 @@
 import("Campaign_lib");
-import("system.logging");
 import("system.result");
 import("system.translate");
 import("system.vars");
 import("system.neon");
 
-//logging.log("campaignParticipantsRowIds_param -> " + vars.get("$param.campaignParticipantsRowIds_param"));
-//logging.log("campaignParticipantsRowIds_param -> " + JSON.parse(vars.getString("$param.campaignParticipantsRowIds_param")).length);
-//logging.log("campaignParticipantsRowIds_param -> " + vars.getString("$param.campaignParticipantsRowIds_param"));
-//logging.log("campaignParticipantsCondition_param -> " + vars.getString("$param.campaignParticipantsCondition_param"));
-
 var campaignParticipantsAmount = 0;
 var informationText = translate.text("participants will be added to the selected campaign step");
 
@@ -22,7 +16,6 @@ var isUpdate = vars.get("$field.isUpdate");
 var participantCondition = "";
 var messageString = "";
 var resultValue = "false";
-//logging.log("selectedCampaignId -> " + selectedCampaignId);
 
 if(selectedCampaignId != '')
 {
@@ -68,14 +61,17 @@ if(selectedCampaignId != '')
     else
     {
         participantCondition = JSON.parse(vars.getString("$param.campaignParticipantsCondition_param")).condition;
-        logging.log("im isOperationValid -> ");
         
         let useRightJoinToGetOrgs = "false";
         if(targetTable == "ORGANISATION")
+        {
             useRightJoinToGetOrgs = "true";
+            
+            //Necessary because organisations don't have a personid'
+            participantCondition += "  and PERSON.PERSONID is NULL"
+        }
         
         countParticipantsToAdd = CampaignUtils.GetContactCountByCondition(participantCondition, isUpdate, useRightJoinToGetOrgs);
-                logging.log("countParticipantsToAdd -> " + countParticipantsToAdd);
 
         /*
          * If the update mode is active, the goal is to move participants between steps.
@@ -90,14 +86,9 @@ if(selectedCampaignId != '')
             whereCondition = "CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + selectedCampaignId + "'";
 
         countParticipantsAlreadyInCampaign = CampaignUtils.GetParticipantsAlreadyAddedCountByCondition(whereCondition, participantCondition, useRightJoinToGetOrgs);
-        //CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "'"
     }
     countValidParticipantsToAdd = countParticipantsToAdd - countParticipantsAlreadyInCampaign;
     
-    logging.log("countParticipantsToAdd -> " + countParticipantsToAdd);
-    logging.log("countParticipantsAlreadyInCampaign -> " + countParticipantsAlreadyInCampaign);
-    logging.log("countValidParticipantsToAdd -> " + countValidParticipantsToAdd);
-    
     if(countValidParticipantsToAdd <= 0)
     {
         messageString = "Alle selektierten Teilnehmer befinden sich bereits in der Stufe";
@@ -119,11 +110,8 @@ if(selectedCampaignId != '')
 
 function hasStepEnoughSlots(pCountToAdd)
 {
-//    logging.log(" selectedCampaignStepId-> " + selectedCampaignStepId);
     let currentParticipants = CampaignUtils.getParticipantCountForStep(selectedCampaignStepId)
     let maxParticipants = CampaignUtils.getMaxParticipantCountForStep(selectedCampaignStepId)
-//    logging.log(" currentParticipants + pCountToAdd-> " + (parseInt(currentParticipants) + parseInt(pCountToAdd)));
-//    logging.log(" maxParticipants-> " + maxParticipants);
-//    logging.log(" (currentParticipants + pCountToAdd) <= maxParticipants-> " + ((currentParticipants + pCountToAdd) <= maxParticipants));
+
     return (parseInt(currentParticipants) + parseInt(pCountToAdd)) <= maxParticipants;
 }
\ No newline at end of file
diff --git a/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js b/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
index 6ae8f16c2a..c471c8a13c 100644
--- a/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
+++ b/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
@@ -1,4 +1,3 @@
-import("system.logging");
 import("system.vars");
 import("system.db");
 import("system.util");
@@ -23,7 +22,6 @@ if(participantRowIds != null && participantRowIds.length > 0)
     if(isUpdate == "false")
         contactIdsToHandle = CampaignUtils.GetContactIdsNotInCampaignByRowIds(campaignId, participantRowIds);
     
-    logging.log("contactIdsToHandle by rowIds -> " + contactIdsToHandle);
     _handleRowIds(contactIdsToHandle);
 }
 else
@@ -40,7 +38,10 @@ function _handleCondition(pCampaignId, pTargetTableName, pCondition)
     
     let useRightJoinToGetOrgs = "false";
     if(pTargetTableName == "ORGANISATION")
+    {
         useRightJoinToGetOrgs = "true";
+        pCondition += "  and PERSON.PERSONID is NULL"
+    }
         
     /*
      * If it's an update of participants, get the participants defined by the condition in the selected campaign
@@ -56,7 +57,6 @@ function _handleCondition(pCampaignId, pTargetTableName, pCondition)
     else
         contactIdsToHandle = CampaignUtils.GetContactIdsNotInCampaignByCondition(pCampaignId, pCondition, useRightJoinToGetOrgs);
     
-    logging.log("contactIdsToHandle -> " + contactIdsToHandle);
     _handleRowIds(contactIdsToHandle);
 }
 
@@ -82,7 +82,7 @@ function _handleRowIds(pParticipantRowIds)
 
     let statementArray = [];
     let logArray = [];
-    logging.log("pParticipantRowIds -> " + pParticipantRowIds);
+
     for (participant in pParticipantRowIds)
     {
         let campaignParticipantLogId = util.getNewUUID();
@@ -116,10 +116,8 @@ function _handleRowIds(pParticipantRowIds)
             statementArray.push(["CAMPAIGNPARTICIPANT", cols, null, valsCampaignParticipant]);
         }
     }
-    logging.log("statementArray -> " + statementArray);
     if(isUpdate == "true")
         {
-            logging.log("vor db.updates??? -> ");
             db.updates(statementArray)
         }
     else
diff --git a/entity/CampaignParticipant_entity/entityfields/filterviewactiongroup/children/setsteptoparticipantselection/onActionProcess.js b/entity/CampaignParticipant_entity/entityfields/filterviewactiongroup/children/setsteptoparticipantselection/onActionProcess.js
index 15d7c2f29e..f7f984d937 100644
--- a/entity/CampaignParticipant_entity/entityfields/filterviewactiongroup/children/setsteptoparticipantselection/onActionProcess.js
+++ b/entity/CampaignParticipant_entity/entityfields/filterviewactiongroup/children/setsteptoparticipantselection/onActionProcess.js
@@ -1,4 +1,3 @@
-import("system.logging");
 import("system.vars");
 import("system.neon");
 import("Campaign_lib");
@@ -15,7 +14,6 @@ if(sysSelection.length > 0) //selektierte IDs als Array
 else
 {
     let sysFilter = vars.get("$sys.filter");//todo change name
-    logging.log("sysFilter -> " + sysFilter);
 
     CampaignUtils.openSetCampaignStepViewByCondition(JSON.stringify(sysFilter), campaignId, campaignStepId);
 }
\ No newline at end of file
diff --git a/entity/Person_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js b/entity/Person_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js
index e6a1e385e5..9dbd200763 100644
--- a/entity/Person_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js
+++ b/entity/Person_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js
@@ -1,4 +1,3 @@
-import("system.logging");
 import("system.vars");
 import("system.neon");
 import("Campaign_lib");
@@ -13,14 +12,11 @@ var sysSelection = vars.get("$sys.selection");
 
 if(sysSelection.length > 0) //selektierte IDs als Array
 {
-    logging.log("sysSelection -> " + sysSelection);
     CampaignUtils.addParticipantsByRowIds(JSON.stringify(sysSelection), "PERSON");
 }
 else
 {
     let sysFilter = vars.get("$sys.filter");//todo change name
-    logging.log("sysFilter -> " + sysFilter);
-    logging.log("asdasd sysFilter.condition -> " + sysFilter.condition);
 
     CampaignUtils.addParticipantsByCondition(JSON.stringify(sysFilter), "PERSON");
 }
\ No newline at end of file
diff --git a/process/Campaign_lib/process.js b/process/Campaign_lib/process.js
index d055712e83..d9368a36af 100644
--- a/process/Campaign_lib/process.js
+++ b/process/Campaign_lib/process.js
@@ -43,13 +43,13 @@ CampaignUtils.addParticipantsByRowIds = function(pRowIds, pSourceTableName)
  */
 CampaignUtils.addParticipantsByCondition = function(pCondition, pSourceTableName)
 {
-    logging.log(" asdf-> " + pCondition);
     _CampaignUtils._openAddParticipantContext("CampaignAddParticipants", pCondition, 
     "campaignParticipantsCondition_param", "CampaignAddParticipantsEdit_view", pSourceTableName);
 }
 
 /**
- * todo
+ * Gets the campaign name per Id
+ * @return Name of a campaign, empty string if no campaign could be found for the id
  */
 CampaignUtils.getCampaignNameById = function(pCampaignId)
 {
@@ -61,7 +61,8 @@ CampaignUtils.getCampaignNameById = function(pCampaignId)
 }
 
 /**
- * todo
+ * Gets the campaign step name per Id
+ * @return Name of a campaignstep, empty string if no step could be found for the id
  */
 CampaignUtils.getCampaignStepNameById = function(pCampaignStepId)
 {
@@ -73,7 +74,8 @@ CampaignUtils.getCampaignStepNameById = function(pCampaignStepId)
 }
 
 /**
- * todo
+ * The current count of participants in the given campaignstep
+ * @return count of participants, 0 if no campaignstep could be found for the id
  */
 CampaignUtils.getParticipantCountForStep = function(pCampaignStepId)
 {
@@ -85,7 +87,8 @@ CampaignUtils.getParticipantCountForStep = function(pCampaignStepId)
 }
 
 /**
- * todo
+ * The current count of participants in the given campaign
+ * @return count of participants, 0 if no campaign could be found for the id
  */
 CampaignUtils.getParticipantCount = function(pCampaignId)
 {
@@ -97,7 +100,8 @@ CampaignUtils.getParticipantCount = function(pCampaignId)
 }
 
 /**
- * todo
+ * The max participants value for the given campaignstep
+ * @return max count of participants, 0 if no campaignstep could be found for the id
  */
 CampaignUtils.getMaxParticipantCountForStep = function(pCampaignStepId)
 {
@@ -108,9 +112,6 @@ CampaignUtils.getMaxParticipantCountForStep = function(pCampaignStepId)
     return _CampaignUtils._loadSingleValueFromDb(selectQuery, conditionField, pCampaignStepId, defaultValue);
 }
 
-/**
- * todo
- */
 CampaignUtils.getStepCount = function(pCampaignId)
 {
     let selectQuery = "select count(*) from CAMPAIGNSTEP";
@@ -120,9 +121,6 @@ CampaignUtils.getStepCount = function(pCampaignId)
     return _CampaignUtils._loadSingleValueFromDb(selectQuery, conditionField, pCampaignId, defaultValue);
 }
 
-/**
- * todo
- */
 CampaignUtils.getCampaignStatusByCampaignId = function(pCampaignId)
 {
     let selectQuery = "select CAMPAIGN.STATE from CAMPAIGN";
@@ -134,9 +132,6 @@ CampaignUtils.getCampaignStatusByCampaignId = function(pCampaignId)
     return KeywordUtils.getViewValue(campaignState, statusId);
 }
 
-/**
- * todo
- */
 CampaignUtils.createLogEntry = function(pCampaignId, pCampaignStepId, pContactId, pCampaignParticipantId)
 {
     let colsCampaignParticipantLog = CampaignUtils.getParticipantLogInsertColumnNames();
@@ -147,17 +142,11 @@ CampaignUtils.createLogEntry = function(pCampaignId, pCampaignStepId, pContactId
     return (rows == 1);
 }
 
-/**
- * todo
- */
 CampaignUtils.getParticipantLogInsertColumnNames = function()
 {
     return ["CAMPAIGNPARTICIPANT_ID", "CAMPAIGN_ID", "CAMPAIGNSTEP_ID", "CAMPAIGNPARTICIPANTLOGID", "USER_NEW", "DATE_NEW"];
 }
 
-/**
- * todo
- */
 CampaignUtils.openSetCampaignStepViewByRowIds = function(pParticipantIds, pCampaignId, pCampaignStepId)
 {
     var params = {};
@@ -169,9 +158,6 @@ CampaignUtils.openSetCampaignStepViewByRowIds = function(pParticipantIds, pCampa
     neon.openContext("CampaignAddParticipants", "CampaignAddParticipantsEdit_view", null, neon.OPERATINGSTATE_NEW, params);
 }
 
-/**
- * todo
- */
 CampaignUtils.openSetCampaignStepViewByCondition = function(pCondition, pCampaignId, pCampaignStepId)
 {
     var params = {};
@@ -208,9 +194,6 @@ CampaignUtils.openNewCampaignView = function()
     neon.openContext("Campaign", "CampaignEdit_view", null, neon.OPERATINGSTATE_NEW, params);
 }
 
-/**
- * todo
- */
 CampaignUtils.getDefaultCampaignStep = function(pCampaignId)
 {
     let selectQuery = "select CAMPAIGNSTEPID from CAMPAIGNSTEP " +
@@ -221,9 +204,6 @@ CampaignUtils.getDefaultCampaignStep = function(pCampaignId)
     return db.cell(selectQuery)   
 }
 
-/**
- * todo
- */
 CampaignUtils.getCampaignStartDate = function(pCapmaignId)
 {
     let campaignIdCondition = SqlCondition.begin()
@@ -231,9 +211,6 @@ CampaignUtils.getCampaignStartDate = function(pCapmaignId)
     return db.cell(campaignIdCondition.buildSql("SELECT DATE_START, SORTING FROM CAMPAIGNSTEP", "1=2", "order by SORTING ASC"));
 }
 
-/**
- * todo
- */
 CampaignUtils.getCampaignEndDate = function(pCapmaignId)
 {
     let campaignIdCondition = SqlCondition.begin()
@@ -242,9 +219,6 @@ CampaignUtils.getCampaignEndDate = function(pCapmaignId)
     return db.cell(campaignIdCondition.buildSql("SELECT DATE_END, SORTING FROM CAMPAIGNSTEP", "1=2", "order by SORTING DESC"));
 }
 
-/**
- * todo
- */
 CampaignUtils.getMaxParticipantsValidationMessage = function()
 {
     //todo how/where should this text be stored?
@@ -330,8 +304,6 @@ CampaignUtils.GetParticipantsAlreadyAddedCountByRowId = function(pWhereCondition
     + " where " + pWhereCondition + " AND"
     + " " + pRowIdsComparisonField + " IN " + rowIdsAsRay;
 
-        logging.log("GetParticipantsAlreadyInStepCountByRowId query -> " + query);
-        
     return db.cell(query)
 }
 
@@ -351,8 +323,6 @@ CampaignUtils.GetParticipantsAlreadyAddedCountByCondition = function(pWhereCondi
     if(pCondition != "")
         query += " and " + pCondition;
     
-    logging.log("GetParticipantsAlreadyAddedCountByCondition query -> " + query);
-
     return db.cell(query)
 }
 
@@ -385,7 +355,7 @@ CampaignUtils.GetContactIdsNotInCampaignByCondition = function(pCampaignId, pCon
     
     if(pCondition != "")
         query += " and " + pCondition;
-    logging.log("GetContactIdsNotInCampaignByCondition -> " + query);
+
     return db.array(db.COLUMN, query);
 }
 
@@ -402,7 +372,7 @@ CampaignUtils.GetContactIdsInCampaignByCondition = function(pCampaignId, pCondit
     + " left join CAMPAIGNPARTICIPANT on CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID"
     + " where " + pCondition
     + " and CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "'";
-        logging.log("GetContactIdsInCampaignByCondition -> " + GetContactIdsInCampaignByCondition);
+
     return db.array(db.COLUMN, query);
 }
 
@@ -423,7 +393,6 @@ CampaignUtils.GetContactCountByCondition = function(pCondition, pLookInCampaignO
     if(pCondition != "")
         query += " where " + pCondition;
     
-    logging.log("GetContactCountByCondition -> " + query);
     return db.cell(query);
 }
 
@@ -481,9 +450,6 @@ _CampaignUtils._openAddParticipantContext = function(pContext, pTargetDataExpres
     neon.openContext(pContext, null, null, neon.OPERATINGSTATE_NEW, params);
 }
 
-/**
- * todo
- */
 _CampaignUtils._convertToSqlValuesList = function(pValuesArray)
 {
     let rowIds = "(";
@@ -497,9 +463,6 @@ _CampaignUtils._convertToSqlValuesList = function(pValuesArray)
     return rowIds;
 }
 
-/**
- * todo
- */
 _CampaignUtils._loadSingleValueFromDb = function(pSelectQuery, pConditionField, pConditionValue, pDefaultValue)
 {
     let res = pDefaultValue;
-- 
GitLab