From 1ffcd3ad7343284033cbfe6d2b3f226ba4f425ce Mon Sep 17 00:00:00 2001
From: daniel <daniel@localhost>
Date: Thu, 6 Feb 2020 08:34:43 +0100
Subject: [PATCH] Zwischencommit.

---
 .liquibase/Data_alias/changelog.xml                    |  2 +-
 .../CampaignAddParticipants_entity.aod                 |  3 +++
 .../displayValueProcess.js                             |  3 ++-
 .../entityfields/isoperationvalid/valueProcess.js      |  4 ++--
 .../recordcontainers/jdito/onInsert.js                 | 10 +++++-----
 .../entityfields/countparticipants/valueProcess.js     |  2 +-
 .../CampaignParticipant_entity.aod                     |  3 +++
 .../displayValueProcess.js                             |  2 +-
 .../setsteptoparticipantselection/onActionProcess.js   |  1 -
 entity/CampaignStep_entity/CampaignStep_entity.aod     |  1 +
 .../entityfields/campaignstepid/valueProcess.js        |  7 +++++++
 .../currentmaxparticipantsinfo/valueProcess.js         |  2 +-
 entity/Campaign_entity/Campaign_entity.aod             |  1 +
 process/Campaign_lib/process.js                        |  5 +++--
 14 files changed, 31 insertions(+), 15 deletions(-)
 create mode 100644 entity/CampaignStep_entity/entityfields/campaignstepid/valueProcess.js

diff --git a/.liquibase/Data_alias/changelog.xml b/.liquibase/Data_alias/changelog.xml
index cc63bd025f4..98b7856c424 100644
--- a/.liquibase/Data_alias/changelog.xml
+++ b/.liquibase/Data_alias/changelog.xml
@@ -10,5 +10,5 @@
     <include relativeToChangelogFile="true" file="basic/2020.0.0/changelog.xml"/>
     
     <!--enable this only when you definetly want to overwrite the existing data with demo records:--> 
-    <!--<include relativeToChangelogFile="true" file="basic/_demoData/changelog.xml" context="example"/>-->
+    <include relativeToChangelogFile="true" file="basic/_demoData/changelog.xml" context="example"/>
 </databaseChangeLog>
\ No newline at end of file
diff --git a/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod b/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod
index 6f7b018b1a1..9bf84980074 100644
--- a/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod
+++ b/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod
@@ -4,6 +4,9 @@
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <documentation>%aditoprj%/entity/CampaignAddParticipants_entity/documentation.adoc</documentation>
   <title>Add participants to Campaign</title>
+  <siblings>
+    <element>CampaignParticipant_entity</element>
+  </siblings>
   <onValidation>%aditoprj%/entity/CampaignAddParticipants_entity/onValidation.js</onValidation>
   <recordContainer>jdito</recordContainer>
   <entityFields>
diff --git a/entity/CampaignAddParticipants_entity/entityfields/campaignstepcurrentparticipantcount/displayValueProcess.js b/entity/CampaignAddParticipants_entity/entityfields/campaignstepcurrentparticipantcount/displayValueProcess.js
index 3fe2184695f..3fdaf507cf5 100644
--- a/entity/CampaignAddParticipants_entity/entityfields/campaignstepcurrentparticipantcount/displayValueProcess.js
+++ b/entity/CampaignAddParticipants_entity/entityfields/campaignstepcurrentparticipantcount/displayValueProcess.js
@@ -1,5 +1,6 @@
+import("system.logging");
 import("system.result");
 import("system.vars");
 import("Campaign_lib");
 
-result.string(CampaignUtils.getParticipantCountForStep(vars.get("$field.CAMPAIGNSTEP_ID")));
\ No newline at end of file
+result.string(CampaignUtils.getParticipantCountForStep(vars.get("$field.CAMPAIGNSTEP_ID"), vars.get("$field.CAMPAIGN_ID")));
\ No newline at end of file
diff --git a/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js b/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js
index f4d6e6e52bf..47fb5627a5b 100644
--- a/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js
+++ b/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js
@@ -117,8 +117,8 @@ if(selectedCampaignId != '')
 
 function getParticipantExcess (pCountToAdd)
 {
-    let currentParticipants = CampaignUtils.getParticipantCountForStep(selectedCampaignStepId)
-    let maxParticipants = CampaignUtils.getMaxParticipantCountForStep(selectedCampaignStepId)
+    let currentParticipants = CampaignUtils.getParticipantCountForStep(selectedCampaignStepId, vars.get("$field.CAMPAIGN_ID"));
+    let maxParticipants = CampaignUtils.getMaxParticipantCountForStep(selectedCampaignStepId, vars.get("$field.CAMPAIGN_ID"));
 
     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 95c8bcbdf76..44bfa0e717f 100644
--- a/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
+++ b/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
@@ -24,7 +24,7 @@ if(participantRowIds != null && participantRowIds.length > 0)
     if(isUpdate == "false")
         contactIdsToHandle = CampaignUtils.GetContactIdsNotInCampaignByRowIds(campaignId, participantRowIds);
     
-    _handleRowIds(contactIdsToHandle);
+    _handleRowIds(contactIdsToHandle, campaignId);
 }
 else
 {
@@ -60,10 +60,10 @@ function _handleCondition(pCampaignId, pTargetTableName, pCondition)
     else
         contactIdsToHandle = CampaignUtils.GetContactIdsNotInCampaignByCondition(pCampaignId, pCondition, useRightJoinToGetOrgs);
     
-    _handleRowIds(contactIdsToHandle);
+    _handleRowIds(contactIdsToHandle, pCampaignId);
 }
 
-function _handleRowIds(pParticipantRowIds)
+function _handleRowIds(pParticipantRowIds, pCampaignId)
 {
     var oldStepIds = {};
     if(isUpdate == "true")
@@ -72,10 +72,10 @@ function _handleRowIds(pParticipantRowIds)
                  "USER_EDIT",
                  "DATE_EDIT"
                 ];
-        
         let oldSteps = newSelect("CAMPAIGNPARTICIPANTID, CAMPAIGNSTEP_ID")
                         .from("CAMPAIGNPARTICIPANT")
-                        .whereIfSet("CAMPAIGNPARTICIPANT.CAMPAIGNPARTICIPANTID", pParticipantRowIds, SqlBuilder.IN())
+                        .whereIfSet("CAMPAIGNPARTICIPANT.CONTACT_ID", pParticipantRowIds, SqlBuilder.IN())
+                        .and("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", pCampaignId)
                         .table(true);
                         
         oldSteps.forEach(function (step)
diff --git a/entity/CampaignCost_entity/entityfields/countparticipants/valueProcess.js b/entity/CampaignCost_entity/entityfields/countparticipants/valueProcess.js
index 6952bc19fb1..b717a893620 100644
--- a/entity/CampaignCost_entity/entityfields/countparticipants/valueProcess.js
+++ b/entity/CampaignCost_entity/entityfields/countparticipants/valueProcess.js
@@ -4,7 +4,7 @@ import("Campaign_lib");
 
 if (vars.get("$field.CAMPAIGNSTEP_ID"))
 {
-    result.string(CampaignUtils.getParticipantCountForStep(vars.get("$field.CAMPAIGNSTEP_ID")));
+    result.string(CampaignUtils.getParticipantCountForStep(vars.get("$field.CAMPAIGNSTEP_ID"), vars.get("$field.CAMPAIGN_ID")));
 }
 else
 {
diff --git a/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod b/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod
index e1d7172fd02..0572cb1c001 100644
--- a/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod
+++ b/entity/CampaignParticipant_entity/CampaignParticipant_entity.aod
@@ -96,6 +96,7 @@
     </entityField>
     <entityConsumer>
       <name>CampaignsConsumer</name>
+      <refreshParent v="true" />
       <dependency>
         <name>dependency</name>
         <entityName>Campaign_entity</entityName>
@@ -142,6 +143,7 @@
     </entityConsumer>
     <entityConsumer>
       <name>CampaignSteps</name>
+      <refreshParent v="true" />
       <dependency>
         <name>dependency</name>
         <entityName>CampaignStep_entity</entityName>
@@ -229,6 +231,7 @@
     <dbRecordContainer>
       <name>ParticipantsDbRecordContainer</name>
       <alias>Data_alias</alias>
+      <hasDependentRecords v="true" />
       <conditionProcess>%aditoprj%/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/conditionProcess.js</conditionProcess>
       <onDBInsert>%aditoprj%/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/onDBInsert.js</onDBInsert>
       <linkInformation>
diff --git a/entity/CampaignParticipant_entity/entityfields/campaignstepcurrentparticipantcount/displayValueProcess.js b/entity/CampaignParticipant_entity/entityfields/campaignstepcurrentparticipantcount/displayValueProcess.js
index 3fe2184695f..d4be69539f8 100644
--- a/entity/CampaignParticipant_entity/entityfields/campaignstepcurrentparticipantcount/displayValueProcess.js
+++ b/entity/CampaignParticipant_entity/entityfields/campaignstepcurrentparticipantcount/displayValueProcess.js
@@ -2,4 +2,4 @@ import("system.result");
 import("system.vars");
 import("Campaign_lib");
 
-result.string(CampaignUtils.getParticipantCountForStep(vars.get("$field.CAMPAIGNSTEP_ID")));
\ No newline at end of file
+result.string(CampaignUtils.getParticipantCountForStep(vars.get("$field.CAMPAIGNSTEP_ID"), vars.get("$field.CAMPAIGN_ID")));
\ No newline at end of file
diff --git a/entity/CampaignParticipant_entity/entityfields/filterviewactiongroup/children/setsteptoparticipantselection/onActionProcess.js b/entity/CampaignParticipant_entity/entityfields/filterviewactiongroup/children/setsteptoparticipantselection/onActionProcess.js
index f7f984d9379..1537b3bbbc7 100644
--- a/entity/CampaignParticipant_entity/entityfields/filterviewactiongroup/children/setsteptoparticipantselection/onActionProcess.js
+++ b/entity/CampaignParticipant_entity/entityfields/filterviewactiongroup/children/setsteptoparticipantselection/onActionProcess.js
@@ -14,6 +14,5 @@ if(sysSelection.length > 0) //selektierte IDs als Array
 else
 {
     let sysFilter = vars.get("$sys.filter");//todo change name
-
     CampaignUtils.openSetCampaignStepViewByCondition(JSON.stringify(sysFilter), campaignId, campaignStepId);
 }
\ No newline at end of file
diff --git a/entity/CampaignStep_entity/CampaignStep_entity.aod b/entity/CampaignStep_entity/CampaignStep_entity.aod
index 3723efe444e..cec7f035cba 100644
--- a/entity/CampaignStep_entity/CampaignStep_entity.aod
+++ b/entity/CampaignStep_entity/CampaignStep_entity.aod
@@ -36,6 +36,7 @@
     <entityField>
       <name>CAMPAIGNSTEPID</name>
       <mandatory v="true" />
+      <valueProcess>%aditoprj%/entity/CampaignStep_entity/entityfields/campaignstepid/valueProcess.js</valueProcess>
     </entityField>
     <entityField>
       <name>CAMPAIGN_ID</name>
diff --git a/entity/CampaignStep_entity/entityfields/campaignstepid/valueProcess.js b/entity/CampaignStep_entity/entityfields/campaignstepid/valueProcess.js
new file mode 100644
index 00000000000..86ef789e064
--- /dev/null
+++ b/entity/CampaignStep_entity/entityfields/campaignstepid/valueProcess.js
@@ -0,0 +1,7 @@
+import("system.util");
+import("system.vars");
+import("system.result");
+import("system.neon");
+
+if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
+    result.string(util.getNewUUID());
\ No newline at end of file
diff --git a/entity/CampaignStep_entity/entityfields/currentmaxparticipantsinfo/valueProcess.js b/entity/CampaignStep_entity/entityfields/currentmaxparticipantsinfo/valueProcess.js
index 4f1a6b39640..86c117c70dd 100644
--- a/entity/CampaignStep_entity/entityfields/currentmaxparticipantsinfo/valueProcess.js
+++ b/entity/CampaignStep_entity/entityfields/currentmaxparticipantsinfo/valueProcess.js
@@ -2,6 +2,6 @@ import("system.result");
 import("system.vars");
 import("Campaign_lib");
 
-let currentParticipantsCount = CampaignUtils.getParticipantCountForStep(vars.get("$field.CAMPAIGNSTEPID"));
+let currentParticipantsCount = CampaignUtils.getParticipantCountForStep(vars.get("$field.CAMPAIGNSTEPID"), vars.get("$field.CAMPAIGN_ID"));
 let maxParticipantsStepCount = vars.get("$field.MAXPARTICIPANTS");
 result.string(currentParticipantsCount + "/" + maxParticipantsStepCount);
\ No newline at end of file
diff --git a/entity/Campaign_entity/Campaign_entity.aod b/entity/Campaign_entity/Campaign_entity.aod
index 3165e68b887..60605812492 100644
--- a/entity/Campaign_entity/Campaign_entity.aod
+++ b/entity/Campaign_entity/Campaign_entity.aod
@@ -174,6 +174,7 @@
     </entityProvider>
     <entityConsumer>
       <name>CampaignParticipants</name>
+      <refreshParent v="false" />
       <selectionMode>MULTI</selectionMode>
       <dependency>
         <name>dependency</name>
diff --git a/process/Campaign_lib/process.js b/process/Campaign_lib/process.js
index 2e1cc2f66a3..9d80baee3df 100644
--- a/process/Campaign_lib/process.js
+++ b/process/Campaign_lib/process.js
@@ -67,11 +67,12 @@ CampaignUtils.getCampaignStepNameById = function(pCampaignStepId)
  * 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)
+CampaignUtils.getParticipantCountForStep = function(pCampaignStepId, pCampaignId)
 {
     return newSelect("count(*)")
         .from("CAMPAIGNPARTICIPANT")
         .whereIfSet("CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID", pCampaignStepId)
+        .and("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", pCampaignId)
         .cell(true, 0);
 }
 
@@ -373,7 +374,7 @@ CampaignUtils.GetContactIdsInCampaignByCondition = function(pCampaignId, pCondit
     
 //    if(pRightJoinContacts == "true")
 //        query += " right"
-    
+
     query.leftJoin("PERSON", "CONTACT.PERSON_ID = PERSON.PERSONID")
         .leftJoin("ORGANISATION", "ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID")
         .leftJoin("ADDRESS", "ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID")
-- 
GitLab