From bfb60323d6b1d0aadf3534980ab590f805b076e2 Mon Sep 17 00:00:00 2001
From: "d.buechler" <d.buechler@adito.de>
Date: Thu, 10 Oct 2019 15:48:47 +0200
Subject: [PATCH] New keyword has been added for activity direct interal If a
 merge has been successful, a new acitivity gets created on the target record
 of the merge This has been implemented on Person and Organisation

---
 .../onActionProcess.js                             |  3 +++
 .../onActionProcess.js                             |  6 ++++--
 .../onActionProcess.js                             |  4 ++++
 .../onActionProcess.js                             |  7 +++++++
 .../_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod    |  6 ++++++
 language/_____LANGUAGE_de/_____LANGUAGE_de.aod     |  8 ++++++++
 language/_____LANGUAGE_en/_____LANGUAGE_en.aod     |  6 ++++++
 process/DuplicateScanner_lib/process.js            | 14 ++++++++------
 process/KeywordRegistry_basic/process.js           |  1 +
 9 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/entity/Organisation_entity/entityfields/duplicateactions/children/integratecurrentintoselectedaction/onActionProcess.js b/entity/Organisation_entity/entityfields/duplicateactions/children/integratecurrentintoselectedaction/onActionProcess.js
index 65462384c2..597cd13795 100644
--- a/entity/Organisation_entity/entityfields/duplicateactions/children/integratecurrentintoselectedaction/onActionProcess.js
+++ b/entity/Organisation_entity/entityfields/duplicateactions/children/integratecurrentintoselectedaction/onActionProcess.js
@@ -1,3 +1,4 @@
+import("Employee_lib");
 import("system.vars");
 import("system.neon");
 import("DuplicateScanner_lib");
@@ -10,5 +11,7 @@ let mergeSuccess = DuplicateScannerUtils.MergeOrganisation(sourceContactId, targ
 
 if(mergeSuccess)
 {
+    let currentContactId = EmployeeUtils.getCurrentContactId();
+    DuplicateScannerUtils.CreateMergeSuccessActivity(sourceContactId, targetContactId, currentContactId, "Organisation");
     neon.openContext("Organisation", "OrganisationMain_view", [targetContactId], neon.OPERATINGSTATE_VIEW, null)
 }
\ No newline at end of file
diff --git a/entity/Organisation_entity/entityfields/duplicateactions/children/integrateselectedintocurrentaction/onActionProcess.js b/entity/Organisation_entity/entityfields/duplicateactions/children/integrateselectedintocurrentaction/onActionProcess.js
index 85447cf556..519f845eb2 100644
--- a/entity/Organisation_entity/entityfields/duplicateactions/children/integrateselectedintocurrentaction/onActionProcess.js
+++ b/entity/Organisation_entity/entityfields/duplicateactions/children/integrateselectedintocurrentaction/onActionProcess.js
@@ -1,3 +1,4 @@
+import("Employee_lib");
 import("system.logging");
 import("system.vars");
 import("system.neon");
@@ -5,12 +6,13 @@ import("DuplicateScanner_lib");
 
 let targetContactId = vars.get("$param.DuplicateCurrentContactId_param");
 let sourceContactId = vars.get("$sys.selection");
-logging.log("targetContactId -> " + targetContactId);
-logging.log("sourceContactId -> "+ sourceContactId);
+
 //todo the actual merge ought to happen in a separate view where the contact infos can be merged manually by the user.
 let mergeSuccess = DuplicateScannerUtils.MergeOrganisation(sourceContactId, targetContactId);
 
 if(mergeSuccess)
 {
+    let currentContactId = EmployeeUtils.getCurrentContactId();
+    DuplicateScannerUtils.CreateMergeSuccessActivity(sourceContactId, targetContactId, currentContactId, "Organisation");
     neon.refreshAll();
 }
\ No newline at end of file
diff --git a/entity/Person_entity/entityfields/duplicateactions/children/integratecurrentintoselectedaction/onActionProcess.js b/entity/Person_entity/entityfields/duplicateactions/children/integratecurrentintoselectedaction/onActionProcess.js
index b752040252..bf7678e3b0 100644
--- a/entity/Person_entity/entityfields/duplicateactions/children/integratecurrentintoselectedaction/onActionProcess.js
+++ b/entity/Person_entity/entityfields/duplicateactions/children/integratecurrentintoselectedaction/onActionProcess.js
@@ -1,3 +1,4 @@
+import("Employee_lib");
 import("system.vars");
 import("system.neon");
 import("DuplicateScanner_lib");
@@ -10,5 +11,8 @@ let mergeSuccess = DuplicateScannerUtils.MergePerson(sourceContactId, targetCont
 
 if(mergeSuccess)
 {
+    let currentContactId = EmployeeUtils.getCurrentContactId();
+    DuplicateScannerUtils.CreateMergeSuccessActivity(sourceContactId, targetContactId, currentContactId, "Person");
+
     neon.openContext("Person", "PersonMain_view", [targetContactId], neon.OPERATINGSTATE_VIEW, null)
 }
\ No newline at end of file
diff --git a/entity/Person_entity/entityfields/duplicateactions/children/integrateselectedintocurrentaction/onActionProcess.js b/entity/Person_entity/entityfields/duplicateactions/children/integrateselectedintocurrentaction/onActionProcess.js
index ea59a8ed29..69765d3ca5 100644
--- a/entity/Person_entity/entityfields/duplicateactions/children/integrateselectedintocurrentaction/onActionProcess.js
+++ b/entity/Person_entity/entityfields/duplicateactions/children/integrateselectedintocurrentaction/onActionProcess.js
@@ -1,3 +1,7 @@
+import("system.db");
+import("Employee_lib");
+import("KeywordRegistry_basic");
+import("ActivityTask_lib");
 import("system.logging");
 import("system.vars");
 import("system.neon");
@@ -12,5 +16,8 @@ let mergeSuccess = DuplicateScannerUtils.MergePerson(sourceContactId, targetCont
 
 if(mergeSuccess)
 {
+    let currentContactId = EmployeeUtils.getCurrentContactId();
+    DuplicateScannerUtils.CreateMergeSuccessActivity(sourceContactId, targetContactId, currentContactId, "Person");
+
     neon.refreshAll();
 }
\ No newline at end of file
diff --git a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
index f610601e65..6a76f46927 100644
--- a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
+++ b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
@@ -5196,6 +5196,12 @@
     <entry>
       <key>Field configuration</key>
     </entry>
+    <entry>
+      <key>%0 with ID \"%1\" has been integrated into the %0 with the ID \"%2\"</key>
+    </entry>
+    <entry>
+      <key>A %0 record has been merged</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 52bbbd711b..53cf55f14e 100644
--- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
+++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
@@ -6553,6 +6553,14 @@
       <key>Field configuration</key>
       <value>Feldkonfiguration</value>
     </entry>
+    <entry>
+      <key>%0 with ID \"%1\" has been integrated into the %0 with the ID \"%2\"</key>
+      <value>%0 mit der ID \"%1\" wurde in %0 mit der ID \"%2\" integriert</value>
+    </entry>
+    <entry>
+      <key>A %0 record has been merged</key>
+      <value>Zwei Datensätze vom Typ %0 wurden zusammengeführt</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 147496b33d..c0b3cccc55 100644
--- a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
+++ b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
@@ -5246,6 +5246,12 @@
     <entry>
       <key>Field configuration</key>
     </entry>
+    <entry>
+      <key>A %0 record has been merged</key>
+    </entry>
+    <entry>
+      <key>%0 with ID \"%1\" has been integrated into the %0 with the ID \"%2\"</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 5b76a06e6d..02512e08de 100644
--- a/process/DuplicateScanner_lib/process.js
+++ b/process/DuplicateScanner_lib/process.js
@@ -1,3 +1,4 @@
+import("KeywordRegistry_basic");
 import("system.translate");
 import("ActivityTask_lib");
 import("Contact_lib");
@@ -761,14 +762,14 @@ DuplicateScannerUtils.MergePerson = function(pSourceContactId, pTargetContactId)
 DuplicateScannerUtils.CreateMergeSuccessActivity = function(pSourceContactId, pTargetContactId, pCurrentContactId, pContext)
 {
     var activityDataForInsert = {
-        subject: translate.withArguments("A %0 record has been merged", [pContext]),//"Es wurde ein Personendatensatz in diesen integriert",
+        subject: translate.withArguments("A %0 record has been merged", [pContext]),
         content: translate.withArguments("%0 with ID \"%1\" has been integrated into the %0 with the ID \"%2\"", [pContext, pSourceContactId, pTargetContactId]),
         //categoryKeywordId: $KeywordRegistry.ac
-        directionKeywordId: "x",
+        directionKeywordId: $KeywordRegistry.activityDirection$internal(),
         responsibleContactId: pCurrentContactId
     };
     var activityLinks = [[pContext, pTargetContactId]];
-    
+
     return ActivityUtils.insertNewActivity(activityDataForInsert, activityLinks, null, db.getCurrentAlias());
 }
 
@@ -1118,9 +1119,10 @@ _DuplicateScannerUtils._callIndexSearch = function(pTargetEntity, pPreFilterJson
 
     if(filterPattern != null)
         indexQuery = indexQuery.addFilter(filterPattern);
-        logging.log("indexQuery.getPattern -> " + indexQuery.getPattern());
-        logging.log("indexQuery.getFilters -> " + indexQuery.getFilters());
-    //logging.log("Starte Indexsuche -> ");
+    
+    logging.log("indexQuery.getPattern -> " + indexQuery.getPattern());
+    logging.log("indexQuery.getFilters -> " + indexQuery.getFilters());
+
     return indexsearch.searchIndex(indexQuery);
 }
 
diff --git a/process/KeywordRegistry_basic/process.js b/process/KeywordRegistry_basic/process.js
index f3db525581..c1a2df5bda 100644
--- a/process/KeywordRegistry_basic/process.js
+++ b/process/KeywordRegistry_basic/process.js
@@ -33,6 +33,7 @@ $KeywordRegistry.contractType = function(){return "ContractType";};
 $KeywordRegistry.activityDirection = function(){return "ActivityDirection";};
 $KeywordRegistry.activityDirection$incoming = function(){return $KeywordRegistry._autoPad("i");};
 $KeywordRegistry.activityDirection$outgoing = function(){return $KeywordRegistry._autoPad("o");};
+$KeywordRegistry.activityDirection$internal = function(){return $KeywordRegistry._autoPad("x");};
 
 $KeywordRegistry.contactStatus = function(){return "ContactStatus";};
 $KeywordRegistry.contactStatus$active = function(){return $KeywordRegistry._autoPad("CONTACTSTATACTIVE");};
-- 
GitLab