From 201cc73cbaa9febecdc38f1853fbfaf1189d1bb8 Mon Sep 17 00:00:00 2001
From: "d.buechler" <d.buechler@adito.de>
Date: Tue, 27 Aug 2019 15:15:38 +0200
Subject: [PATCH] =?UTF-8?q?Allgemeine=20Dublettenansicht:=20Neuer=20Reiter?=
 =?UTF-8?q?=20f=C3=BCr=20Organisation=20Es=20werden=20sowohl=20die=20Organ?=
 =?UTF-8?q?isationscluster=20angezeigt=20als=20auch=20analog=20zu=20den=20?=
 =?UTF-8?q?Personen=20eine=20Tabelle=20mit=20ignorierten=20Dublettenkombin?=
 =?UTF-8?q?ationen.=20Entsprechende=20Aktionen=20werden=20ebenso=20angezei?=
 =?UTF-8?q?gt.=20DuplicatesUnrelated=20wurde=20um=20Logik=20f=C3=BCr=20Org?=
 =?UTF-8?q?anisationen=20erweitert=20Duplicates=20wurde=20um=20Logik=20f?=
 =?UTF-8?q?=C3=BCr=20Organisationen=20erweitert?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../DuplicatesUnrelated_entity.aod            |  5 +++
 .../jditorecordcontainer/contentProcess.js    | 42 ++++++++++++++++---
 .../Duplicates_entity/Duplicates_entity.aod   |  8 ++++
 .../recordcontainer/contentProcess.js         | 15 +++++--
 neonContext/Duplicates/Duplicates.aod         | 12 ++++++
 .../DuplicatesOverview_view.aod               |  5 +++
 ...icatesUnrelatedOrganisationFilter_view.aod | 25 +++++++++++
 .../OrganisationDuplicatesFilter_view.aod     | 31 ++++++++++++++
 .../OrganisationDuplicatesTab_view.aod        | 24 +++++++++++
 .../OrganisationUnrelatedDuplicates_view.aod  | 17 ++++++++
 .../process.js                                | 22 +++++++++-
 11 files changed, 196 insertions(+), 10 deletions(-)
 create mode 100644 neonView/OrganisationDuplicatesFilter_view/OrganisationDuplicatesFilter_view.aod
 create mode 100644 neonView/OrganisationDuplicatesTab_view/OrganisationDuplicatesTab_view.aod
 create mode 100644 neonView/OrganisationUnrelatedDuplicates_view/OrganisationUnrelatedDuplicates_view.aod

diff --git a/entity/DuplicatesUnrelated_entity/DuplicatesUnrelated_entity.aod b/entity/DuplicatesUnrelated_entity/DuplicatesUnrelated_entity.aod
index e588641673c..a5c6ac225f1 100644
--- a/entity/DuplicatesUnrelated_entity/DuplicatesUnrelated_entity.aod
+++ b/entity/DuplicatesUnrelated_entity/DuplicatesUnrelated_entity.aod
@@ -48,6 +48,11 @@
           <expose v="true" />
           <mandatory v="true" />
         </entityParameter>
+        <entityParameter>
+          <name>ClusterId_param</name>
+          <expose v="true" />
+          <mandatory v="false" />
+        </entityParameter>
       </children>
     </entityProvider>
     <entityField>
diff --git a/entity/DuplicatesUnrelated_entity/recordcontainers/jditorecordcontainer/contentProcess.js b/entity/DuplicatesUnrelated_entity/recordcontainers/jditorecordcontainer/contentProcess.js
index e128ef3d64f..80ea054419a 100644
--- a/entity/DuplicatesUnrelated_entity/recordcontainers/jditorecordcontainer/contentProcess.js
+++ b/entity/DuplicatesUnrelated_entity/recordcontainers/jditorecordcontainer/contentProcess.js
@@ -7,6 +7,9 @@ var INDEX_SOURCE_INFO1 = 1;
 var INDEX_SOURCE_INFO2 = 2;
 var INDEX_UNRELATED_INFO1 = 3;
 var INDEX_UNRELATED_INFO2 = 4;
+var INDEX_SOURCE_INFO = 1;
+var INDEX_UNRELATED_INFO = 2;
+
 
 let unrelatedDuplicates = [];
 let resultUnrelatedDuplicates = [];
@@ -28,17 +31,46 @@ if(targetEntity == 'Person_entity')
         if(clusterId != null && clusterId != "")
             query += " where ud.CLUSTERID = '" + clusterId + "'";
 }
+else
+{
+    query = "select ud.ID,"
+            + " oSource.\"NAME\","
+            + " oUnrelated.\"NAME\""
+            + " from UNRELATEDDUPLICATES ud"
+            + " join CONTACT cUnrelated on cUnrelated.CONTACTID = ud.UNRELATEDDUPLICATEID"
+            + " join Organisation oUnrelated on oUnrelated.ORGANISATIONID = cUnrelated.CONTACTID"
+            + " join CONTACT cSource on cSource.CONTACTID = ud.SOURCEDUPLICATEID"
+            + " join Organisation oSource on oSource.ORGANISATIONID = cSource.CONTACTID"
+        //If the clusterid parameter is present, only load the duplicates for this particular cluster
+        if(clusterId != null && clusterId != "")
+            query += " where ud.CLUSTERID = '" + clusterId + "'";
+}
 
 unrelatedDuplicates = db.table(query);
 
 for (let i = 0; i < unrelatedDuplicates.length; i++) 
 {
     let id = unrelatedDuplicates[i][INDEX_ID];
-    let sourceInfo1 = unrelatedDuplicates[i][INDEX_SOURCE_INFO1];
-    let sourceInfo2 = unrelatedDuplicates[i][INDEX_SOURCE_INFO2];
-    let unrelatedInfo1 = unrelatedDuplicates[i][INDEX_UNRELATED_INFO1];
-    let unrelatedInfo2 = unrelatedDuplicates[i][INDEX_UNRELATED_INFO2];
+    let sourceInfo = "";
+    let unrelatedInfo = "";
+    
+    if(targetEntity == 'Person_entity')
+    {
+        let sourceInfo1 = unrelatedDuplicates[i][INDEX_SOURCE_INFO1];
+        let sourceInfo2 = unrelatedDuplicates[i][INDEX_SOURCE_INFO2];
+        let unrelatedInfo1 = unrelatedDuplicates[i][INDEX_UNRELATED_INFO1];
+        let unrelatedInfo2 = unrelatedDuplicates[i][INDEX_UNRELATED_INFO2];
+        
+        sourceInfo = sourceInfo1 + " " + sourceInfo2;
+        unrelatedInfo = unrelatedInfo1 + " " + unrelatedInfo2;
+    }
+    else
+    {
+        sourceInfo = unrelatedDuplicates[i][INDEX_SOURCE_INFO];
+        unrelatedInfo = unrelatedDuplicates[i][INDEX_UNRELATED_INFO];
+    }
+    
     
-    resultUnrelatedDuplicates.push([id, sourceInfo1 + " " + sourceInfo2, unrelatedInfo1 + " " + unrelatedInfo2]);
+    resultUnrelatedDuplicates.push([id, sourceInfo, unrelatedInfo]);
 }
 result.object(resultUnrelatedDuplicates);
\ No newline at end of file
diff --git a/entity/Duplicates_entity/Duplicates_entity.aod b/entity/Duplicates_entity/Duplicates_entity.aod
index fe6100f6994..a9d5e70212d 100644
--- a/entity/Duplicates_entity/Duplicates_entity.aod
+++ b/entity/Duplicates_entity/Duplicates_entity.aod
@@ -123,6 +123,14 @@
         </entityActionField>
       </children>
     </entityActionGroup>
+    <entityConsumer>
+      <name>DuplicatesUnrelatedOrganisationConsumer</name>
+      <dependency>
+        <name>dependency</name>
+        <entityName>DuplicatesUnrelated_entity</entityName>
+        <fieldName>UnrelatedOrganisationsProvider</fieldName>
+      </dependency>
+    </entityConsumer>
   </entityFields>
   <recordContainers>
     <jDitoRecordContainer>
diff --git a/entity/Duplicates_entity/recordcontainers/recordcontainer/contentProcess.js b/entity/Duplicates_entity/recordcontainers/recordcontainer/contentProcess.js
index b41c7170c7f..c23d673b253 100644
--- a/entity/Duplicates_entity/recordcontainers/recordcontainer/contentProcess.js
+++ b/entity/Duplicates_entity/recordcontainers/recordcontainer/contentProcess.js
@@ -8,6 +8,7 @@ var INDEX_ID = 0;
 var INDEX_CLUSTERID = 1;
 var INDEX_FIRSTNAME = 2;
 var INDEX_LASTNAME = 3;
+var INDEX_ORGNAME = 2;
 
 let targetEntity = vars.get("$param.TargetEntity");
 let duplicates = [];
@@ -29,8 +30,16 @@ if(targetEntity == "Person_entity")
 
 }
 else
-    duplicateInfosQuery = "orgquery";
-                    
+{
+       duplicateInfosQuery = SqlCondition.begin()
+                .and("DUPLICATEID not in (select UNRELATEDDUPLICATES.UNRELATEDDUPLICATEID from UNRELATEDDUPLICATES)")
+                .andIn("DUPLICATECLUSTERS.CLUSTERID", vars.get("$local.idvalues"))
+                .buildSql("select DUPLICATECLUSTERS.ID, CLUSTERID, ORGANISATION.\"NAME\""
+                        + " from DUPLICATECLUSTERS"
+                        + " join CONTACT on CONTACT.CONTACTID = DUPLICATEID"
+                        + " join ORGANISATION on ORGANISATION.ORGANISATIONID = CONTACT.CONTACTID", "1=2", " ORDER BY CLUSTERID"); 
+}   
+
 let duplicateInfos = db.table(duplicateInfosQuery);
 
 let recordClusterId = "";
@@ -47,7 +56,7 @@ for (let i = 0; i < duplicateInfos.length; i++)
     if(targetEntity == "Person_entity")
         currentDescription = duplicateInfos[i][INDEX_FIRSTNAME] + " " + duplicateInfos[i][INDEX_LASTNAME];
     else
-        currentDescription = "orgfields";
+        currentDescription = duplicateInfos[i][INDEX_ORGNAME];
     
     if(i == 0)
     {
diff --git a/neonContext/Duplicates/Duplicates.aod b/neonContext/Duplicates/Duplicates.aod
index 0926349b865..08035e98574 100644
--- a/neonContext/Duplicates/Duplicates.aod
+++ b/neonContext/Duplicates/Duplicates.aod
@@ -27,5 +27,17 @@
       <name>7cdb6ca7-e99d-4eb6-897a-0953157bf62f</name>
       <view>DuplicatesUnrelatedCluster_view</view>
     </neonViewReference>
+    <neonViewReference>
+      <name>4b9a1a26-e14f-4246-b474-8bfb3e3a95b0</name>
+      <view>OrganisationDuplicatesTab_view</view>
+    </neonViewReference>
+    <neonViewReference>
+      <name>f9b46eab-7417-4f61-b7cd-dc772c04ddc0</name>
+      <view>OrganisationDuplicatesFilter_view</view>
+    </neonViewReference>
+    <neonViewReference>
+      <name>d68a425a-037a-4725-8dc1-b0afac277bdd</name>
+      <view>OrganisationUnrelatedDuplicates_view</view>
+    </neonViewReference>
   </references>
 </neonContext>
diff --git a/neonView/DuplicatesOverview_view/DuplicatesOverview_view.aod b/neonView/DuplicatesOverview_view/DuplicatesOverview_view.aod
index cdbcf32c67c..e733c2ef89c 100644
--- a/neonView/DuplicatesOverview_view/DuplicatesOverview_view.aod
+++ b/neonView/DuplicatesOverview_view/DuplicatesOverview_view.aod
@@ -13,5 +13,10 @@
       <entityField>#ENTITY</entityField>
       <view>PersonDublicatesTab_view</view>
     </neonViewReference>
+    <neonViewReference>
+      <name>8e19d057-58da-4db8-8119-ecf070af86ab</name>
+      <entityField>#ENTITY</entityField>
+      <view>OrganisationDuplicatesTab_view</view>
+    </neonViewReference>
   </children>
 </neonView>
diff --git a/neonView/DuplicatesUnrelatedOrganisationFilter_view/DuplicatesUnrelatedOrganisationFilter_view.aod b/neonView/DuplicatesUnrelatedOrganisationFilter_view/DuplicatesUnrelatedOrganisationFilter_view.aod
index 0962b89c7f0..0c2a6665e48 100644
--- a/neonView/DuplicatesUnrelatedOrganisationFilter_view/DuplicatesUnrelatedOrganisationFilter_view.aod
+++ b/neonView/DuplicatesUnrelatedOrganisationFilter_view/DuplicatesUnrelatedOrganisationFilter_view.aod
@@ -2,4 +2,29 @@
 <neonView xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.2" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.2">
   <name>DuplicatesUnrelatedOrganisationFilter_view</name>
   <majorModelMode>DISTRIBUTED</majorModelMode>
+  <layout>
+    <boxLayout>
+      <name>layout</name>
+    </boxLayout>
+  </layout>
+  <children>
+    <tableViewTemplate>
+      <name>UnrelatedOrganisations</name>
+      <hideContentSearch v="true" />
+      <entityField>#ENTITY</entityField>
+      <isCreatable v="false" />
+      <isEditable v="false" />
+      <title>Unrelated organisation duplicates</title>
+      <columns>
+        <neonTableColumn>
+          <name>04681f8d-b941-4a66-be50-6ac08d6f52a4</name>
+          <entityField>SourceDuplicateDescription</entityField>
+        </neonTableColumn>
+        <neonTableColumn>
+          <name>b293ed18-ebf5-474e-8ec2-851a3562b4d5</name>
+          <entityField>UnrelatedDuplicateDescription</entityField>
+        </neonTableColumn>
+      </columns>
+    </tableViewTemplate>
+  </children>
 </neonView>
diff --git a/neonView/OrganisationDuplicatesFilter_view/OrganisationDuplicatesFilter_view.aod b/neonView/OrganisationDuplicatesFilter_view/OrganisationDuplicatesFilter_view.aod
new file mode 100644
index 00000000000..6579ac0f55f
--- /dev/null
+++ b/neonView/OrganisationDuplicatesFilter_view/OrganisationDuplicatesFilter_view.aod
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<neonView xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.2" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.2">
+  <name>OrganisationDuplicatesFilter_view</name>
+  <majorModelMode>DISTRIBUTED</majorModelMode>
+  <layout>
+    <boxLayout>
+      <name>layout</name>
+    </boxLayout>
+  </layout>
+  <children>
+    <tableViewTemplate>
+      <name>OrganisationDuplicatesTable</name>
+      <favoriteActionGroup2>DuplicateClusterActionGroup</favoriteActionGroup2>
+      <hideContentSearch v="true" />
+      <entityField>#ENTITY</entityField>
+      <isCreatable v="false" />
+      <isEditable v="false" />
+      <isDeletable v="false" />
+      <columns>
+        <neonTableColumn>
+          <name>ebe8d904-449c-49bd-915c-5b4fee894bc2</name>
+          <entityField>CLUSTER_DESCRIPTION</entityField>
+        </neonTableColumn>
+        <neonTableColumn>
+          <name>48db4335-6bdb-4a6a-809e-f9c371733f85</name>
+          <entityField>COUNT_DUPLICATES_IN_CLUSTER</entityField>
+        </neonTableColumn>
+      </columns>
+    </tableViewTemplate>
+  </children>
+</neonView>
diff --git a/neonView/OrganisationDuplicatesTab_view/OrganisationDuplicatesTab_view.aod b/neonView/OrganisationDuplicatesTab_view/OrganisationDuplicatesTab_view.aod
new file mode 100644
index 00000000000..601b065b7aa
--- /dev/null
+++ b/neonView/OrganisationDuplicatesTab_view/OrganisationDuplicatesTab_view.aod
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<neonView xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.2" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.2">
+  <name>OrganisationDuplicatesTab_view</name>
+  <title>Organisation duplicates</title>
+  <majorModelMode>DISTRIBUTED</majorModelMode>
+  <layout>
+    <boxLayout>
+      <name>layout</name>
+      <direction>HORIZONTAL</direction>
+    </boxLayout>
+  </layout>
+  <children>
+    <neonViewReference>
+      <name>8b4ab951-afb3-4fac-915b-89226ab2f849</name>
+      <entityField>SelfOrganisationDuplicatesConsumer</entityField>
+      <view>OrganisationDuplicatesFilter_view</view>
+    </neonViewReference>
+    <neonViewReference>
+      <name>d1e2ba4a-a5d6-4bba-a646-5918490e43a4</name>
+      <entityField>#ENTITY</entityField>
+      <view>OrganisationUnrelatedDuplicates_view</view>
+    </neonViewReference>
+  </children>
+</neonView>
diff --git a/neonView/OrganisationUnrelatedDuplicates_view/OrganisationUnrelatedDuplicates_view.aod b/neonView/OrganisationUnrelatedDuplicates_view/OrganisationUnrelatedDuplicates_view.aod
new file mode 100644
index 00000000000..80177f02af3
--- /dev/null
+++ b/neonView/OrganisationUnrelatedDuplicates_view/OrganisationUnrelatedDuplicates_view.aod
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<neonView xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.2" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.2">
+  <name>OrganisationUnrelatedDuplicates_view</name>
+  <majorModelMode>DISTRIBUTED</majorModelMode>
+  <layout>
+    <boxLayout>
+      <name>layout</name>
+    </boxLayout>
+  </layout>
+  <children>
+    <neonViewReference>
+      <name>edc0822d-4388-4e3d-93d7-2e46e32f5742</name>
+      <entityField>DuplicatesUnrelatedOrganisationConsumer</entityField>
+      <view>DuplicatesUnrelatedOrganisationFilter_view</view>
+    </neonViewReference>
+  </children>
+</neonView>
diff --git a/process/RebuildDuplicatesCache_serverProcess/process.js b/process/RebuildDuplicatesCache_serverProcess/process.js
index d7ee47f9636..c8efbfd89c7 100644
--- a/process/RebuildDuplicatesCache_serverProcess/process.js
+++ b/process/RebuildDuplicatesCache_serverProcess/process.js
@@ -1,7 +1,25 @@
 import("DuplicateScanner_lib");
 
-
-// Build Organisation duplicate cache
+/* 
+ * Serverprocess to reload duplicates
+ * It is dividede by the filter and their respective target entities.
+ * 
+ * Step #1:
+ * All Clusters for the specified targetEntity are deleted. 
+ * Relations between records marked as unrelated are not deleted at this moment
+ * Step #2
+ * The duplicates cache gets rebuilt
+ * 
+ * Step #3:
+ * All unrelated relations between duplicate ids hold their respective cluster id
+ * If the same combination of duplicate ids exists in the duplicate cache after the rebuild,
+ * it is assumed that those records remain duplicates. 
+ * Therefore the saved clusterId gets refreshed with the newly created clusters id.
+ * 
+ * Relations between unrelated duplicates are deleted, if no cluster contains the same combination of duplicate ids 
+ */
+
+// Build Person duplicate cache
 
 var filterName = "PersonDuplicates";
 var targetEntity = "Person_entity";
-- 
GitLab