From 65e4a4c108cedc1cde7aedea3ab2684da38116f3 Mon Sep 17 00:00:00 2001
From: Sebastian Listl <s.listl@adito.de>
Date: Tue, 13 Apr 2021 14:41:23 +0200
Subject: [PATCH] Blacklist bugfixes

---
 .../CommunicationBlacklist_entity.aod         | 20 ++++++++++
 .../entityfields/date_new/valueProcess.js     |  6 +++
 .../entityfields/user_new/valueProcess.js     |  6 +++
 .../blacklist_type.displayvalue/expression.js |  5 +++
 .../_____LANGUAGE_de/_____LANGUAGE_de.aod     |  8 ++++
 process/MarketingCondition_lib/process.js     |  2 +-
 .../process.js                                | 37 ++++++++++++++++++-
 7 files changed, 82 insertions(+), 2 deletions(-)
 create mode 100644 entity/CommunicationBlacklist_entity/entityfields/date_new/valueProcess.js
 create mode 100644 entity/CommunicationBlacklist_entity/entityfields/user_new/valueProcess.js
 create mode 100644 entity/CommunicationBlacklist_entity/recordcontainers/db/recordfieldmappings/blacklist_type.displayvalue/expression.js

diff --git a/entity/CommunicationBlacklist_entity/CommunicationBlacklist_entity.aod b/entity/CommunicationBlacklist_entity/CommunicationBlacklist_entity.aod
index 58cbbc2265..0b6d0eedc3 100644
--- a/entity/CommunicationBlacklist_entity/CommunicationBlacklist_entity.aod
+++ b/entity/CommunicationBlacklist_entity/CommunicationBlacklist_entity.aod
@@ -62,6 +62,14 @@
         </entityParameter>
       </children>
     </entityConsumer>
+    <entityField>
+      <name>DATE_NEW</name>
+      <valueProcess>%aditoprj%/entity/CommunicationBlacklist_entity/entityfields/date_new/valueProcess.js</valueProcess>
+    </entityField>
+    <entityField>
+      <name>USER_NEW</name>
+      <valueProcess>%aditoprj%/entity/CommunicationBlacklist_entity/entityfields/user_new/valueProcess.js</valueProcess>
+    </entityField>
   </entityFields>
   <recordContainers>
     <dbRecordContainer>
@@ -95,6 +103,18 @@
           <recordfield>COMMUNICATIONBLACKLIST.START_DATE</recordfield>
           <isFilterable v="true" />
         </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>USER_NEW.value</name>
+          <recordfield>COMMUNICATIONBLACKLIST.USER_NEW</recordfield>
+        </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>DATE_NEW.value</name>
+          <recordfield>COMMUNICATIONBLACKLIST.DATE_NEW</recordfield>
+        </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>BLACKLIST_TYPE.displayValue</name>
+          <expression>%aditoprj%/entity/CommunicationBlacklist_entity/recordcontainers/db/recordfieldmappings/blacklist_type.displayvalue/expression.js</expression>
+        </dbRecordFieldMapping>
       </recordFieldMappings>
       <linkInformation>
         <linkInformation>
diff --git a/entity/CommunicationBlacklist_entity/entityfields/date_new/valueProcess.js b/entity/CommunicationBlacklist_entity/entityfields/date_new/valueProcess.js
new file mode 100644
index 0000000000..1dbb1c3887
--- /dev/null
+++ b/entity/CommunicationBlacklist_entity/entityfields/date_new/valueProcess.js
@@ -0,0 +1,6 @@
+import("system.result");
+import("system.neon");
+import("system.vars");
+
+if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
+    result.string(vars.get("$sys.date"));
\ No newline at end of file
diff --git a/entity/CommunicationBlacklist_entity/entityfields/user_new/valueProcess.js b/entity/CommunicationBlacklist_entity/entityfields/user_new/valueProcess.js
new file mode 100644
index 0000000000..8d9eb72f00
--- /dev/null
+++ b/entity/CommunicationBlacklist_entity/entityfields/user_new/valueProcess.js
@@ -0,0 +1,6 @@
+import("system.result");
+import("system.neon");
+import("system.vars");
+
+if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
+    result.string(vars.get("$sys.user"));
\ No newline at end of file
diff --git a/entity/CommunicationBlacklist_entity/recordcontainers/db/recordfieldmappings/blacklist_type.displayvalue/expression.js b/entity/CommunicationBlacklist_entity/recordcontainers/db/recordfieldmappings/blacklist_type.displayvalue/expression.js
new file mode 100644
index 0000000000..6cf151ddba
--- /dev/null
+++ b/entity/CommunicationBlacklist_entity/recordcontainers/db/recordfieldmappings/blacklist_type.displayvalue/expression.js
@@ -0,0 +1,5 @@
+import("KeywordRegistry_basic");
+import("system.result");
+import("Keyword_lib");
+    
+result.string(KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.communicationBlacklistType(), "COMMUNICATIONBLACKLIST.BLACKLIST_TYPE"));
\ No newline at end of file
diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
index fe6b0952f3..cb20815ec4 100644
--- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
+++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
@@ -47,6 +47,10 @@
       <key>discounted Vat</key>
       <value>Rbt. Mehrwertssteuer</value>
     </entry>
+    <entry>
+      <key>Filter can't be empty</key>
+      <value>Filter darf nicht leer sein</value>
+    </entry>
     <entry>
       <key>Illegal Parent Operator in buildFilterObj-Function:</key>
       <value>Übergebener Operator ungültig in Funktion "buildFilterObj"</value>
@@ -83,6 +87,10 @@
       <key>descending</key>
       <value>absteigend</value>
     </entry>
+    <entry>
+      <key>Recipient filter</key>
+      <value>Empfänger Filter</value>
+    </entry>
     <entry>
       <key>Salesproject phases</key>
       <value>Vertriebsprojektphasen</value>
diff --git a/process/MarketingCondition_lib/process.js b/process/MarketingCondition_lib/process.js
index b6dfc6cd6a..bf6b48ce21 100644
--- a/process/MarketingCondition_lib/process.js
+++ b/process/MarketingCondition_lib/process.js
@@ -194,7 +194,7 @@ CommunicationBlacklist.getMailRecipientBlacklist = function ()
     return blacklist;
 }
 
-CommunicationBlacklistCondition.prototype.buildCondition = function ()
+CommunicationBlacklist.prototype.buildCondition = function ()
 {
     return new FilterSqlTranslator()
         .filter(this.filter)
diff --git a/process/SetCommunicationSetting_workflowService/process.js b/process/SetCommunicationSetting_workflowService/process.js
index 0af3ff5f17..8aa215483e 100644
--- a/process/SetCommunicationSetting_workflowService/process.js
+++ b/process/SetCommunicationSetting_workflowService/process.js
@@ -1,3 +1,5 @@
+import("system.util");
+import("Sql_lib");
 import("KeywordRegistry_basic");
 import("system.vars");
 
@@ -5,4 +7,37 @@ var variables = JSON.parse(vars.get("$local.value"));
 var contactId = variables.contactId || variables.targetId;
 var channelType = variables.channelType;
 var channelId = variables.channelId;
-var status = variables.status || $KeywordRegistry.communicationSettingStatus$rejected();
\ No newline at end of file
+var status = variables.status || $KeywordRegistry.communicationSettingStatus$rejected();
+
+var settingsId = newSelect("COMMUNICATIONSETTINGSID")
+    .from("COMMUNICATIONSETTINGS")
+    .where("COMMUNICATIONSETTINGS.CONTACT_ID", contactId)
+    .and("COMMUNICATIONSETTINGS.CHANNEL_TYPE", channelType)
+    .and("COMMUNICATIONSETTINGS.CHANNEL_ID", channelId)
+    .cell();
+    
+if (settingsId)
+{
+    newWhere("COMMUNICATIONSETTINGS.COMMUNICATIONSETTINGSID")
+        .updateFields({"STATUS": status});
+}
+else
+{
+    settingsId = util.getNewUUID();
+    new SqlBuilder()
+        .tableName("COMMUNICATIONSETTINGS")
+        .insertFields({
+            "COMMUNICATIONSETTINGSID": settingsId,
+            "CHANNEL_TYPE": channelType,
+            "CHANNEL_ID": channelId,
+            "MEDIUM": medium,
+            "STATUS": status
+        });
+    new SqlBuilder()
+        .tableName("COMMUNICATIONLEGALBASE")
+        .insertFields({
+            "COMMUNICATIONLEGALBASEID": util.getNewUUID(),
+            "COMMUNICATIONSETTINGS_ID": settingsId,
+            "VERSION": 1
+        });
+}
\ No newline at end of file
-- 
GitLab