From 59d17e5036f71ee9ede12185df4243aaf1711015 Mon Sep 17 00:00:00 2001
From: "d.buechler" <d.buechler@adito.de>
Date: Tue, 8 Oct 2019 07:16:36 +0200
Subject: [PATCH] If duplicates have been found while saving a new contact, a
 notification will be shown, alerting the user

---
 .../recordcontainers/db/onDBInsert.js         | 27 +++++++++++++++++--
 .../_____LANGUAGE_EXTRA.aod                   |  9 +++++++
 .../_____LANGUAGE_de/_____LANGUAGE_de.aod     | 12 +++++++++
 .../_____LANGUAGE_en/_____LANGUAGE_en.aod     |  9 +++++++
 process/DuplicateScanner_lib/process.js       |  8 +++---
 5 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/entity/Person_entity/recordcontainers/db/onDBInsert.js b/entity/Person_entity/recordcontainers/db/onDBInsert.js
index 24cf1d86f3..0a1ea849e4 100644
--- a/entity/Person_entity/recordcontainers/db/onDBInsert.js
+++ b/entity/Person_entity/recordcontainers/db/onDBInsert.js
@@ -1,3 +1,5 @@
+import("system.translate");
+import("Employee_lib");
 import("system.util");
 import("system.logging");
 import("system.vars");
@@ -45,6 +47,27 @@ if(scanResults.length > 0)
     let insertCount = DuplicateScannerUtils.CacheNewScanResults(contactId, scanResults, targetEntity);
     logging.log("insertCount -> " + insertCount);
   
-//todo create notification  
-//notification.addNotification(util.getNewUUID(), null, null, null, notification., notification.PRIO_NORMAL, 2, notification.STATE_UNSEEN, [user], message, description);
+  
+let userId = EmployeeUtils.getCurrentUserId();
+let caption = translate.text("Duplicates have been found");
+let descriptionText = "%0 duplicates have been identified.";
+
+if(scanResults.length == 1)
+    descriptionText = "%0 duplicate has been identified."
+
+let description = translate.withArguments(descriptionText, [scanResults.length]);
+
+let notificationConfig = notification.createConfig()
+                                     .addUserWithId(userId)
+                                     .forcedPriority(notification.PRIO_NORMAL)
+                                     .notificationType("_____SYSTEM_NOTIFICATION_MESSAGE")
+                                     .initialState(notification.STATE_UNSEEN)
+                                     .caption(caption)
+                                     .description(description)
+                                     .daysToLive(1);
+                                     
+notification.addNotificationWith(notificationConfig);
+
+//notification.addNotification(util.getNewUUID(), null, null, null, "_____SYSTEM_NOTIFICATION_MESSAGE", notification.PRIO_NORMAL, 1, notification.STATE_UNSEEN, [EmployeeUtils.getCurrentUserId()], "message", "description");
+
 }
\ No newline at end of file
diff --git a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
index ee0f9cacab..9b604892da 100644
--- a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
+++ b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
@@ -5184,6 +5184,15 @@
     <entry>
       <key>Data block size</key>
     </entry>
+    <entry>
+      <key>%0 duplicate has been identified.</key>
+    </entry>
+    <entry>
+      <key>%0 duplicates have been identified.</key>
+    </entry>
+    <entry>
+      <key>Duplicates have been found</key>
+    </entry>
   </keyValueMap>
   <font name="Dialog" style="0" size="11" />
   <sqlModels>
diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
index b8fe1b3b4d..aacef49ca7 100644
--- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
+++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
@@ -6537,6 +6537,18 @@
       <key>Data block size</key>
       <value>Datenblockgröße</value>
     </entry>
+    <entry>
+      <key>%0 duplicate has been identified.</key>
+      <value>Es wurde %0 Dublette identifiziert.</value>
+    </entry>
+    <entry>
+      <key>%0 duplicates have been identified.</key>
+      <value>Es wurden %0 Dubletten identifiziert.</value>
+    </entry>
+    <entry>
+      <key>Duplicates have been found</key>
+      <value>Dubletten gefunden!</value>
+    </entry>
   </keyValueMap>
   <font name="Dialog" style="0" size="11" />
 </language>
diff --git a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
index 8c4f9f0883..33425616e0 100644
--- a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
+++ b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
@@ -5234,6 +5234,15 @@
     <entry>
       <key>Data block size</key>
     </entry>
+    <entry>
+      <key>Duplicates have been found</key>
+    </entry>
+    <entry>
+      <key>%0 duplicates have been identified.</key>
+    </entry>
+    <entry>
+      <key>%0 duplicate has been identified.</key>
+    </entry>
   </keyValueMap>
   <font name="Dialog" style="0" size="11" />
 </language>
diff --git a/process/DuplicateScanner_lib/process.js b/process/DuplicateScanner_lib/process.js
index c9e8a0da62..e574027be2 100644
--- a/process/DuplicateScanner_lib/process.js
+++ b/process/DuplicateScanner_lib/process.js
@@ -432,18 +432,18 @@ pDuplicateFieldsConfig, pResultFields, pUseExternalWebservice, pFormatValuesCons
  * The contents of the cluster have to be identical, if no fitting cluster could be found an empty string is returned.
  * 
  * @param {String} pNewRecordId The id of the record which was used to scan for duplicates
- * @param {String[]} pDuplicateIds Duplicate ids used to search for a cluster containing them
+ * @param {String[]} pScanResults The scan results containing the Duplicate ids which are used to search for a cluster containing them
  * @param {String} pTargetEntity Entity which has been configured
  * @returns {String} A clusterid if a matching cluster has been found, otherwise ""
  */
-DuplicateScannerUtils.CacheNewScanResults = function(pNewRecordId, pDuplicateIds, pTargetEntity)
+DuplicateScannerUtils.CacheNewScanResults = function(pNewRecordId, pScanResults, pTargetEntity)
 {
     let duplicateIds = [];
     //Run thru every duplicate result and read out the id. 
     //Do it now to have a simple array on all usages lateron.
-    for (let i = 0; i < pDuplicateIds.length; i++)
+    for (let i = 0; i < pScanResults.length; i++)
     {
-        let duplicateContactId = pDuplicateIds[i][indexsearch.FIELD_ID];
+        let duplicateContactId = pScanResults[i][indexsearch.FIELD_ID];
         duplicateIds.push(duplicateContactId);
     }
     
-- 
GitLab