From 5f847b0943f99c83a7765b5219ff2b972d860b37 Mon Sep 17 00:00:00 2001
From: "d.buechler" <d.buechler@adito.de>
Date: Thu, 31 Oct 2019 11:06:46 +0100
Subject: [PATCH] Temporarily added a new Tab in the Persons main view. It
 calculates the duplicates for the specific person on the fly. Results arent
 cached.

---
 entity/Person_entity/Person_entity.aod        | 53 ++++++++++++++++++-
 .../valueProcess.js                           |  2 +
 .../valueProcess.js                           |  3 ++
 .../onlyshowcontactids_param/valueProcess.js  | 52 ++++++++++++++++++
 neonView/PersonMain_view/PersonMain_view.aod  |  5 ++
 5 files changed, 114 insertions(+), 1 deletion(-)
 create mode 100644 entity/Person_entity/entityfields/selfduplicatesuncached/children/duplicateactionscontrol_param/valueProcess.js
 create mode 100644 entity/Person_entity/entityfields/selfduplicatesuncached/children/duplicatecurrentcontactid_param/valueProcess.js
 create mode 100644 entity/Person_entity/entityfields/selfduplicatesuncached/children/onlyshowcontactids_param/valueProcess.js

diff --git a/entity/Person_entity/Person_entity.aod b/entity/Person_entity/Person_entity.aod
index eaef0a5de0..0635d3468e 100644
--- a/entity/Person_entity/Person_entity.aod
+++ b/entity/Person_entity/Person_entity.aod
@@ -5,6 +5,9 @@
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <documentation>%aditoprj%/entity/Person_entity/documentation.adoc</documentation>
   <title>Contact</title>
+  <siblings>
+    <element>Address_entity</element>
+  </siblings>
   <grantDeleteProcess>%aditoprj%/entity/Person_entity/grantDeleteProcess.js</grantDeleteProcess>
   <contentTitleProcess>%aditoprj%/entity/Person_entity/contentTitleProcess.js</contentTitleProcess>
   <afterUiInit>%aditoprj%/entity/Person_entity/afterUiInit.js</afterUiInit>
@@ -194,6 +197,10 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact
           <name>ShowDsgvoMessage_param</name>
           <valueProcess>%aditoprj%/entity/Person_entity/entityfields/communications/children/showdsgvomessage_param/valueProcess.js</valueProcess>
         </entityParameter>
+        <entityParameter>
+          <name>ContactsMainCountry_param</name>
+          <valueProcess>%aditoprj%/entity/Person_entity/entityfields/communications/children/contactsmaincountry_param/valueProcess.js</valueProcess>
+        </entityParameter>
       </children>
     </entityConsumer>
     <entityConsumer>
@@ -1108,6 +1115,36 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact
       <name>OnlyOwnSupervised_param</name>
       <expose v="true" />
     </entityParameter>
+    <entityField>
+      <name>IndexPhoneticLastname</name>
+      <valueProcess>%aditoprj%/entity/Person_entity/entityfields/indexphoneticlastname/valueProcess.js</valueProcess>
+    </entityField>
+    <entityField>
+      <name>IndexPhoneticFirstname</name>
+      <valueProcess>%aditoprj%/entity/Person_entity/entityfields/indexphoneticfirstname/valueProcess.js</valueProcess>
+    </entityField>
+    <entityConsumer>
+      <name>SelfDuplicatesUncached</name>
+      <dependency>
+        <name>dependency</name>
+        <entityName>Person_entity</entityName>
+        <fieldName>SelfDuplicatesProvider</fieldName>
+      </dependency>
+      <children>
+        <entityParameter>
+          <name>DuplicateActionsControl_param</name>
+          <valueProcess>%aditoprj%/entity/Person_entity/entityfields/selfduplicatesuncached/children/duplicateactionscontrol_param/valueProcess.js</valueProcess>
+        </entityParameter>
+        <entityParameter>
+          <name>DuplicateCurrentContactId_param</name>
+          <valueProcess>%aditoprj%/entity/Person_entity/entityfields/selfduplicatesuncached/children/duplicatecurrentcontactid_param/valueProcess.js</valueProcess>
+        </entityParameter>
+        <entityParameter>
+          <name>OnlyShowContactIds_param</name>
+          <valueProcess>%aditoprj%/entity/Person_entity/entityfields/selfduplicatesuncached/children/onlyshowcontactids_param/valueProcess.js</valueProcess>
+        </entityParameter>
+      </children>
+    </entityConsumer>
   </entityFields>
   <recordContainers>
     <dbRecordContainer>
@@ -1386,7 +1423,7 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact
         </indexRecordFieldMapping>
         <indexRecordFieldMapping>
           <name>LASTNAME.value</name>
-          <indexFieldType>PHONETIC_NAME</indexFieldType>
+          <indexFieldType>TEXT_NO_STOPWORDS</indexFieldType>
           <isBoosted v="true" />
         </indexRecordFieldMapping>
         <indexRecordFieldMapping>
@@ -1457,6 +1494,20 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact
           </additionalFieldNameAliases>
           <isMultiValued v="true" />
         </indexRecordFieldMapping>
+        <indexRecordFieldMapping>
+          <name>IndexPhoneticFirstname.value</name>
+          <indexFieldType>PHONETIC_NAME</indexFieldType>
+          <additionalFieldNameAliases>
+            <element>firstname</element>
+          </additionalFieldNameAliases>
+        </indexRecordFieldMapping>
+        <indexRecordFieldMapping>
+          <name>IndexPhoneticLastname.value</name>
+          <indexFieldType>PHONETIC_NAME</indexFieldType>
+          <additionalFieldNameAliases>
+            <element>lastname</element>
+          </additionalFieldNameAliases>
+        </indexRecordFieldMapping>
       </indexFieldMappings>
     </indexRecordContainer>
   </recordContainers>
diff --git a/entity/Person_entity/entityfields/selfduplicatesuncached/children/duplicateactionscontrol_param/valueProcess.js b/entity/Person_entity/entityfields/selfduplicatesuncached/children/duplicateactionscontrol_param/valueProcess.js
new file mode 100644
index 0000000000..81570217c3
--- /dev/null
+++ b/entity/Person_entity/entityfields/selfduplicatesuncached/children/duplicateactionscontrol_param/valueProcess.js
@@ -0,0 +1,2 @@
+import("system.result");
+result.string("1");//todo use keyword
\ No newline at end of file
diff --git a/entity/Person_entity/entityfields/selfduplicatesuncached/children/duplicatecurrentcontactid_param/valueProcess.js b/entity/Person_entity/entityfields/selfduplicatesuncached/children/duplicatecurrentcontactid_param/valueProcess.js
new file mode 100644
index 0000000000..821415ae69
--- /dev/null
+++ b/entity/Person_entity/entityfields/selfduplicatesuncached/children/duplicatecurrentcontactid_param/valueProcess.js
@@ -0,0 +1,3 @@
+import("system.vars");
+import("system.result");
+result.string(vars.get("$field.CONTACTID"));
\ No newline at end of file
diff --git a/entity/Person_entity/entityfields/selfduplicatesuncached/children/onlyshowcontactids_param/valueProcess.js b/entity/Person_entity/entityfields/selfduplicatesuncached/children/onlyshowcontactids_param/valueProcess.js
new file mode 100644
index 0000000000..e6e230e458
--- /dev/null
+++ b/entity/Person_entity/entityfields/selfduplicatesuncached/children/onlyshowcontactids_param/valueProcess.js
@@ -0,0 +1,52 @@
+import("system.indexsearch");
+import("system.project");
+import("system.logging");
+import("system.vars");
+import("DuplicateScanner_lib");
+import("system.result");
+
+let targetEntity = "Person_entity";
+let valuesToCheck = {};
+var entityModel = project.getEntityStructure(targetEntity);
+
+ //Read the values of all available entity fields and write the fieldname7value combination
+ //as key/value pairs into an object. This is used to trigger the scan for duplicates
+let fieldValue = "";
+let entityFields = [];
+for (fieldname in entityModel.fields) 
+{ 
+    field = entityModel.fields[fieldname]; 
+    if(field.fieldType == project.ENTITYFIELDTYPE_FIELD)
+    {
+        fieldValue = vars.get("$field." + field.name);
+        
+        if(fieldValue != null && fieldValue != "")
+        {
+//            logging.log("field.name -> " + field.name);
+            valuesToCheck[field.name] = fieldValue;
+//            logging.log("field value -> " + fieldValue);
+        }
+    }
+}
+
+let scanResults = DuplicateScannerUtils.ScanForDuplicates("PersonDuplicates", targetEntity,
+valuesToCheck, null);
+
+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 < scanResults.length; i++)
+{
+    let duplicateContactId = scanResults[i][indexsearch.FIELD_ID];
+    duplicateIds.push(duplicateContactId);
+}
+logging.log("duplicateIds.length -> " + duplicateIds.length);
+/*
+ * To achieve that if there are no duplicates, no contacts should be shown and therefore returned by the 
+ * recordcontainer, an invalid id gets returned. It then is used in the conditionProcess to load the duplicates.
+ * Because of its invalidity, no records are shown.
+*/
+if(duplicateIds.length == 0)
+    result.string(JSON.stringify(["nodata"]));
+else
+    result.string(JSON.stringify(duplicateIds));
\ No newline at end of file
diff --git a/neonView/PersonMain_view/PersonMain_view.aod b/neonView/PersonMain_view/PersonMain_view.aod
index 527484f884..d9124c0e81 100644
--- a/neonView/PersonMain_view/PersonMain_view.aod
+++ b/neonView/PersonMain_view/PersonMain_view.aod
@@ -69,5 +69,10 @@
       <entityField>SelfDuplicates</entityField>
       <view>PersonFilter_view</view>
     </neonViewReference>
+    <neonViewReference>
+      <name>d8db5358-3aed-46d9-8e57-1fd093eb92ad</name>
+      <entityField>SelfDuplicatesUncached</entityField>
+      <view>PersonFilter_view</view>
+    </neonViewReference>
   </children>
 </neonView>
-- 
GitLab