From 15494d2f4f5255e571825f2f8d3ec1211900f2f5 Mon Sep 17 00:00:00 2001
From: Sebastian Listl <s.listl@adito.de>
Date: Thu, 1 Oct 2020 15:15:03 +0200
Subject: [PATCH] DuplicateScanner fix for excluded words

---
 .../duplicates/duplicatescanner.xml             |  2 +-
 entity/DSGVOInfo_entity/afterSave.js            |  5 +++--
 process/DuplicateScanner_lib/process.js         | 17 +++++++++--------
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/.liquibase/Data_alias/basic/_demoData/generatedData/duplicates/duplicatescanner.xml b/.liquibase/Data_alias/basic/_demoData/generatedData/duplicates/duplicatescanner.xml
index c68b0f2baa..d9a1e3cecf 100644
--- a/.liquibase/Data_alias/basic/_demoData/generatedData/duplicates/duplicatescanner.xml
+++ b/.liquibase/Data_alias/basic/_demoData/generatedData/duplicates/duplicatescanner.xml
@@ -20,7 +20,7 @@
             <column name="FILTER_NAME" value="OrganisationDuplicates" />
             <column name="EXTERNAL_SERVICE_USAGE_ALLOWED" valueNumeric="0" />
             <column name="ID_FIELD_NAME" value="CONTACTID" />
-            <column name="SCAN_PATTERN" value="{&quot;entity&quot;:&quot;Organisation_entity&quot;,&quot;provider&quot;:&quot;indexP&quot;,&quot;filter&quot;:{&quot;type&quot;:&quot;group&quot;,&quot;operator&quot;:&quot;AND&quot;,&quot;childs&quot;:[{&quot;type&quot;:&quot;row&quot;,&quot;name&quot;:&quot;NAME&quot;,&quot;operator&quot;:&quot;CONTAINSNOT&quot;,&quot;value&quot;:&quot;[\&quot;gmbh\&quot;, \&quot;co\&quot;, \&quot;kg\&quot;, \&quot;ag\&quot;, \&quot;bank\&quot;, \&quot;deutsche\&quot;, \&quot;van\&quot;, \&quot;software\&quot;, \&quot;medien\&quot;, \&quot;print\&quot;]&quot;,&quot;key&quot;:&quot;[\&quot;gmbh\&quot;, \&quot;co\&quot;, \&quot;kg\&quot;, \&quot;ag\&quot;, \&quot;bank\&quot;, \&quot;deutsche\&quot;, \&quot;van\&quot;, \&quot;software\&quot;, \&quot;medien\&quot;, \&quot;print\&quot;]&quot;,&quot;contenttype&quot;:&quot;LONG_TEXT&quot;},{&quot;type&quot;:&quot;row&quot;,&quot;name&quot;:&quot;STANDARD_CITY&quot;,&quot;operator&quot;:&quot;ISNOTNULL&quot;,&quot;value&quot;:&quot;&quot;,&quot;key&quot;:&quot;&quot;,&quot;contenttype&quot;:&quot;TEXT&quot;}]}}" />
+            <column name="SCAN_PATTERN" value="{&quot;entity&quot;:&quot;Organisation_entity&quot;,&quot;provider&quot;:&quot;indexP&quot;,&quot;filter&quot;:{&quot;type&quot;:&quot;group&quot;,&quot;operator&quot;:&quot;AND&quot;,&quot;childs&quot;:[{&quot;type&quot;:&quot;row&quot;,&quot;name&quot;:&quot;NAME&quot;,&quot;operator&quot;:&quot;CONTAINSNOT&quot;,&quot;value&quot;:&quot;[\&quot;gmbh\&quot;, \&quot;co\&quot;, \&quot;kg\&quot;, \&quot;ag\&quot;, \&quot;se\&quot;, \&quot;bank\&quot;, \&quot;deutsche\&quot;, \&quot;van\&quot;, \&quot;software\&quot;, \&quot;medien\&quot;, \&quot;print\&quot;]&quot;,&quot;key&quot;:&quot;[\&quot;gmbh\&quot;, \&quot;co\&quot;, \&quot;kg\&quot;, \&quot;ag\&quot;, \&quot;bank\&quot;, \&quot;deutsche\&quot;, \&quot;van\&quot;, \&quot;software\&quot;, \&quot;medien\&quot;, \&quot;print\&quot;]&quot;,&quot;contenttype&quot;:&quot;LONG_TEXT&quot;},{&quot;type&quot;:&quot;row&quot;,&quot;name&quot;:&quot;STANDARD_CITY&quot;,&quot;operator&quot;:&quot;ISNOTNULL&quot;,&quot;value&quot;:&quot;&quot;,&quot;key&quot;:&quot;&quot;,&quot;contenttype&quot;:&quot;TEXT&quot;}]}}" />
             <column name="USER_NEW" value="Admin" />
             <column name="DATE_NEW" valueDate="2020-06-26T00:00:00" />
             <column name="USER_EDIT" value="Admin" />
diff --git a/entity/DSGVOInfo_entity/afterSave.js b/entity/DSGVOInfo_entity/afterSave.js
index fab6c5f77c..d6e70c7916 100644
--- a/entity/DSGVOInfo_entity/afterSave.js
+++ b/entity/DSGVOInfo_entity/afterSave.js
@@ -18,6 +18,7 @@ var contactId = entityData["param.ContactId_param"];
 var reportType = entityData["param.ReportType_param"];
 
 if (reportType)
+{
     DataPrivacyUtils.openReport(contactId, reportType, params);
-
-result.string(true);
\ No newline at end of file
+    result.string(true);
+}
diff --git a/process/DuplicateScanner_lib/process.js b/process/DuplicateScanner_lib/process.js
index d6feb5a5eb..3a8ac98fef 100644
--- a/process/DuplicateScanner_lib/process.js
+++ b/process/DuplicateScanner_lib/process.js
@@ -731,13 +731,13 @@ DuplicateScannerUtils.buildEntityFieldConfigs = function(pDuplicateFieldsConfig,
             entityFieldValue = entityFieldValue.toLowerCase().replace(/[():\.\/!]/gi, "").trim();
         
         let exclude = fieldConfig.exclude;
-        if ( exclude )
+        if (exclude)
         {   
-            for(let i = 0; i < exclude.length; i++)
-            {    
+            exclude.forEach(function (excludeValue)
+            {
                 entityFieldValue = " " + entityFieldValue + " ";
-                entityFieldValue = entityFieldValue.replace(new RegExp( " " + exclude[i] + " ", "gi"), "");
-            }    
+                entityFieldValue = entityFieldValue.replace(new RegExp( " " + excludeValue + " ", "gi"), "");
+            });  
         }
         
         let valuelength = fieldConfig.length; 
@@ -893,9 +893,10 @@ _DuplicateScannerUtils._filterChildsRowToScanPattern = function (name, operator,
     let row = "";
     row = row + name.toLowerCase() + ':({"entityfield":"' + name + '"';
     switch (operator){
-        case 'NOT_EQUAL':
-            row = row + ', "exclude":' + JSON.parse(value);
-        case 'ISNOTNULL':
+        case "NOT_EQUAL":
+        case "CONTAINSNOT":
+            row = row + ', "exclude":' + value;
+        case "ISNOTNULL":
             row = row + ', "empty":' + false;
     }
     row = row + '})';
-- 
GitLab