From 5b616bd50bf5539d97a406ffb412a5bc1e0ec843 Mon Sep 17 00:00:00 2001
From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local>
Date: Wed, 27 May 2020 15:32:03 +0200
Subject: [PATCH] 1058029 - Duplicate person merge fix

---
 .../WorkflowSignalFilter_view.aod             |   4 +-
 process/DuplicateScanner_lib/process.js       | 142 +++++++-----------
 process/Sql_lib/process.js                    |   2 +-
 process/workflowServiceTasks_rest/process.js  |   8 +-
 4 files changed, 63 insertions(+), 93 deletions(-)

diff --git a/neonView/WorkflowSignalFilter_view/WorkflowSignalFilter_view.aod b/neonView/WorkflowSignalFilter_view/WorkflowSignalFilter_view.aod
index 4a897cc5cc..15874fe38d 100644
--- a/neonView/WorkflowSignalFilter_view/WorkflowSignalFilter_view.aod
+++ b/neonView/WorkflowSignalFilter_view/WorkflowSignalFilter_view.aod
@@ -4,9 +4,9 @@
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <filterable v="true" />
   <layout>
-    <noneLayout>
+    <boxLayout>
       <name>layout</name>
-    </noneLayout>
+    </boxLayout>
   </layout>
   <children>
     <tableViewTemplate>
diff --git a/process/DuplicateScanner_lib/process.js b/process/DuplicateScanner_lib/process.js
index 6e41ec3a6b..3576d4dcf3 100644
--- a/process/DuplicateScanner_lib/process.js
+++ b/process/DuplicateScanner_lib/process.js
@@ -653,7 +653,7 @@ DuplicateScannerUtils.MergePerson = function(pSourceContactId, pTargetContactId)
     var tableInfosCurrentAlias = _DuplicateScannerUtils._getMergeUpdateTableInfosCurrentAlias();
     var tableInfosSystemAlias = _DuplicateScannerUtils._getMergeUpdateTableInfosSystemAlias();
 
-    updateStatementsCurrentAlias = updateStatementsCurrentAlias.concat(_DuplicateScannerUtils._buildUpdateResetStandardCommunications(pSourceContactId));
+    updateStatementsCurrentAlias.push(_DuplicateScannerUtils._buildUpdateResetStandardCommunications(pSourceContactId));
     updateStatementsCurrentAlias = updateStatementsCurrentAlias.concat(_DuplicateScannerUtils._buildUpdateContactIdStatements(tableInfosCurrentAlias, pSourceContactId, pTargetContactId));
     updateStatementsCurrentAlias = updateStatementsCurrentAlias.concat(_DuplicateScannerUtils._buildUpdateAttachParticipantsToNewContactQuery("CAMPAIGNPARTICIPANT", "CONTACT_ID", "CAMPAIGN_ID", pSourceContactId, pTargetContactId));
 
@@ -673,7 +673,7 @@ DuplicateScannerUtils.MergePerson = function(pSourceContactId, pTargetContactId)
 
     DuplicateScannerUtils.DeleteCachedDuplicate(pSourceContactId);
 
-    return (affectedRowsCurrentAlias > 0 && deletedRows >= 2);
+    return (affectedRowsCurrentAlias > 0 && deletedRows > 0);
 }
 
 DuplicateScannerUtils.CreateMergeSuccessActivity = function(pSourceContactId, pTargetContactId, pCurrentContactId, pContext)
@@ -830,14 +830,6 @@ DuplicateScannerUtils.GetUnrelatedRelationsForDuplicate = function(pDuplicateId)
 
 function _DuplicateScannerUtils() {}
 
-var INDEX_FILTER_CONDITION = 0;
-var INDEX_COUNT_CHARS_TO_USE = 1;
-var INDEX_MAX_RESULTS_THRESHOLD = 2;
-
-var INDEX_TABLE_NAME = 0;
-var INDEX_COLUMN_NAME = 1;
-var INDEX_CONDITION = 2;
-
 _DuplicateScannerUtils._loadEntityFieldsFromFieldConfigs = function(pEntityFieldConfigs)
 {
     let fieldNames = [];
@@ -852,7 +844,7 @@ _DuplicateScannerUtils._loadEntityFieldsFromFieldConfigs = function(pEntityField
 
 _DuplicateScannerUtils._buildUpdateResetStandardCommunications = function(pSourceContactId)
 {
-    return [["COMMUNICATION", ["ISSTANDARD"], null, ["0"], newWhere("COMMUNICATION.CONTACT_ID", pSourceContactId).build()]];
+    return newWhere("COMMUNICATION.CONTACT_ID", pSourceContactId).buildUpdateStatement({"ISSTANDARD" : "0"});
 }
 
 /*
@@ -947,7 +939,7 @@ _DuplicateScannerUtils._isUseExternalWebservice = function(pFilterName, pTargetE
                                 .where("DUPLICATESCANNER.FILTER_NAME", pFilterName)
                                 .and("DUPLICATESCANNER.ENTITY_TO_SCAN_NAME", pTargetEntity)
                                 .cell();
-    return (isUseWebservice == 0) ? false : true;
+    return isUseWebservice != 0;
 }
 
 /*
@@ -1090,25 +1082,23 @@ _DuplicateScannerUtils._buildDeleteRemoveObsoleteParticipantsRecordsQuery = func
     let deleteCondition = newWhere([pTableName, pAssignableIdColumn], selectAssignableIdsOfTargetContactQuery, SqlBuilder.IN())
                                 .and([pTableName, pAssignableIdColumn], pSourceContactId)
 
-    let recordsToDelete = [];
-    recordsToDelete.push([pTableName, deleteCondition.build()]);
-    return recordsToDelete;
+    return [[pTableName, deleteCondition.build()]];
 }
 
 _DuplicateScannerUtils._buildDeleteOrganisationAndContactQuery = function(pSourceOrganisationId, pSourceContactId)
 {
-    let recordsToDelete = []
-    recordsToDelete.push(["ORGANISATION", newWhere("ORGANISATION.ORGANISATIONID", pSourceOrganisationId).build()]);
-    recordsToDelete.push(["CONTACT", newWhere("CONTACT.CONTACTID", pSourceContactId).build()]);
-    return recordsToDelete;
+    return [
+        newWhere("ORGANISATION.ORGANISATIONID", pSourceOrganisationId).buildDeleteStatement(),
+        newWhere("CONTACT.CONTACTID", pSourceContactId).buildDeleteStatement()
+    ];
 }
 
 _DuplicateScannerUtils._buildDeleteCachedUnrelatedDuplicateQuery = function(pSourceContactId)
 {
-    let recordsToDelete = []
-    recordsToDelete.push(["UNRELATEDDUPLICATES", newWhere("UNRELATEDDUPLICATES.SOURCEDUPLICATEID", pSourceContactId).build()]);
-    recordsToDelete.push(["UNRELATEDDUPLICATES", newWhere("UNRELATEDDUPLICATES.UNRELATEDDUPLICATEID", pSourceContactId).build()]);
-    return recordsToDelete;
+    return [
+        newWhere("UNRELATEDDUPLICATES.SOURCEDUPLICATEID", pSourceContactId).buildDeleteStatement(),
+        newWhere("UNRELATEDDUPLICATES.UNRELATEDDUPLICATEID", pSourceContactId).buildDeleteStatement()
+    ];
 }
 
 /*
@@ -1124,29 +1114,14 @@ _DuplicateScannerUtils._getIgnoreSourceRecordPattern = function(pRecordIdValueTo
 
 _DuplicateScannerUtils._buildUpdateContactIdStatements = function(pTableInfos, pSourceContactId, pTargetContactId, pAlias)
 {
-    let statements = [];
-
-    for (let i = 0; i < pTableInfos.length; i++)
+    return pTableInfos.map(function ([tableName, columnName, additionalCondition])
     {
-        let tableInfo = pTableInfos[i];
-        let updateStatement = _DuplicateScannerUtils._buildStatement(tableInfo, pSourceContactId, pTargetContactId, pAlias);
-        statements.push(updateStatement);
-    }
-    return statements;
-}
-
-_DuplicateScannerUtils._buildStatement = function(pTableinfos, pSourceContactId, pTargetContactId, pAlias)
-{
-    let tableName = pTableinfos[INDEX_TABLE_NAME];
-    let columnName = pTableinfos[INDEX_COLUMN_NAME];
-    let additionalCondition = pTableinfos[INDEX_CONDITION];
-
-    let condition = newWhere([tableName, columnName], pSourceContactId, undefined, undefined, pAlias);
-
-    if(additionalCondition != "")
-        condition.and(additionalCondition);
-
-    return [tableName, [columnName], null, [pTargetContactId], condition.build()];
+        var updateValues = {};
+        updateValues[columnName] = pTargetContactId;
+        return newWhere([tableName, columnName], pSourceContactId, undefined, undefined, pAlias)
+            .andIfSet(additionalCondition)
+            .buildUpdateStatement(updateValues, tableName)
+    });
 }
 
 /*
@@ -1156,41 +1131,40 @@ _DuplicateScannerUtils._buildStatement = function(pTableinfos, pSourceContactId,
  */
 _DuplicateScannerUtils._getMergeUpdateTableInfosCurrentAlias = function()
 {
-    var tableInfos = new Array();
-    tableInfos.push(["AB_APPOINTMENTLINK", "OBJECT_ROWID", ""]);
-    tableInfos.push(["AB_CTILOG", "CONTACT_ID", ""]);
-    tableInfos.push(["AB_OBJECTRELATION", "AB_OBJECTRELATIONID", ""]);
-    tableInfos.push(["AB_OBJECTRELATION", "OBJECT1_ROWID", ""]);
-    tableInfos.push(["AB_OBJECTRELATION", "OBJECT2_ROWID", ""]);
-    tableInfos.push(["AB_LOGHISTORY", "TABLENAMEID", ""]);
-    tableInfos.push(["ADDRESS", "CONTACT_ID", ""]);
-    tableInfos.push(["BULKMAILRECIPIENT", "CONTACT_ID", ""]);
-    tableInfos.push(["BULKMAIL", "TESTING_CONTACT_ID", ""]);
-    tableInfos.push(["CAMPAIGN", "EMPLOYEE_CONTACT_ID", ""]);
-    tableInfos.push(["CAMPAIGNSTEP", "EMPLOYEE_CONTACT_ID", ""]);
-    tableInfos.push(["COMMRESTRICTION", "CONTACT_ID", ""]);
-    tableInfos.push(["COMMRESTRICTION", "EMPLOYEE_INVOLVED", ""]);
-    tableInfos.push(["COMMUNICATION", "CONTACT_ID", ""]);
-    tableInfos.push(["COMPETITION", "CONTACT_ID", ""]);
-    tableInfos.push(["CONTRACT", "CONTACT_ID", ""]);
-    tableInfos.push(["LETTERRECIPIENT", "CONTACT_ID", ""]);
-    tableInfos.push(["OBJECTMEMBER", "CONTACT_ID", ""]);
-    tableInfos.push(["OFFER", "CONTACT_ID", ""]);
-    tableInfos.push(["PRODUCT", "CONTACT_ID", ""]);
-    tableInfos.push(["PRODUCTPRICE", "CONTACT_ID", ""]);
-    tableInfos.push(["SALESORDER", "CONTACT_ID", ""]);
-    tableInfos.push(["SALESPROJECT", "CONTACT_ID", ""]);
-    tableInfos.push(["TASK", "REQUESTOR_CONTACT_ID", ""]);
-    tableInfos.push(["TASK", "EDITOR_CONTACT_ID", ""]);
-    tableInfos.push(["TASKLINK", "OBJECT_ROWID", ""]);
-    tableInfos.push(["ACTIVITY", "RESPONSIBLE", ""]);
-    tableInfos.push(["DSGVO", "CONTACT_ID", ""]);
-    tableInfos.push(["DSGVOINFO", "CONTACT_ID", ""]);
-    tableInfos.push(["TIMETRACKING", "CONTACT_ID", ""]);
-    tableInfos.push(["ACTIVITYLINK", "OBJECT_ROWID", ""]);
-    tableInfos.push(["AB_ATTRIBUTERELATION", "OBJECT_ROWID", ""]);
-
-    return tableInfos;
+    return [
+        ["AB_APPOINTMENTLINK", "OBJECT_ROWID", ""],
+        ["AB_CTILOG", "CONTACT_ID", ""],
+        ["AB_OBJECTRELATION", "AB_OBJECTRELATIONID", ""],
+        ["AB_OBJECTRELATION", "OBJECT1_ROWID", ""],
+        ["AB_OBJECTRELATION", "OBJECT2_ROWID", ""],
+        ["AB_LOGHISTORY", "TABLENAMEID", ""],
+        ["ADDRESS", "CONTACT_ID", ""],
+        ["BULKMAILRECIPIENT", "CONTACT_ID", ""],
+        ["BULKMAIL", "TESTING_CONTACT_ID", ""],
+        ["CAMPAIGN", "EMPLOYEE_CONTACT_ID", ""],
+        ["CAMPAIGNSTEP", "EMPLOYEE_CONTACT_ID", ""],
+        ["COMMRESTRICTION", "CONTACT_ID", ""],
+        ["COMMRESTRICTION", "EMPLOYEE_INVOLVED", ""],
+        ["COMMUNICATION", "CONTACT_ID", ""],
+        ["COMPETITION", "CONTACT_ID", ""],
+        ["CONTRACT", "CONTACT_ID", ""],
+        ["LETTERRECIPIENT", "CONTACT_ID", ""],
+        ["OBJECTMEMBER", "CONTACT_ID", ""],
+        ["OFFER", "CONTACT_ID", ""],
+        ["PRODUCT", "CONTACT_ID", ""],
+        ["PRODUCTPRICE", "CONTACT_ID", ""],
+        ["SALESORDER", "CONTACT_ID", ""],
+        ["SALESPROJECT", "CONTACT_ID", ""],
+        ["TASK", "REQUESTOR_CONTACT_ID", ""],
+        ["TASK", "EDITOR_CONTACT_ID", ""],
+        ["TASKLINK", "OBJECT_ROWID", ""],
+        ["ACTIVITY", "RESPONSIBLE", ""],
+        ["DSGVO", "CONTACT_ID", ""],
+        ["DSGVOINFO", "CONTACT_ID", ""],
+        ["TIMETRACKING", "CONTACT_ID", ""],
+        ["ACTIVITYLINK", "OBJECT_ROWID", ""],
+        ["AB_ATTRIBUTERELATION", "OBJECT_ROWID", ""]
+    ];
 }
 
 /*
@@ -1200,10 +1174,10 @@ _DuplicateScannerUtils._getMergeUpdateTableInfosCurrentAlias = function()
  */
 _DuplicateScannerUtils._getMergeUpdateTableInfosSystemAlias = function()
 {
-    var tableInfos = new Array();
-    tableInfos.push(["ASYS_CALENDARLINK", "DBID", ""]);
-    tableInfos.push(["ASYS_BINARIES", "ROW_ID", "TABLENAME = 'CONTACT'"]);
-    return tableInfos;
+    return [
+        ["ASYS_CALENDARLINK", "DBID", ""],
+        ["ASYS_BINARIES", "ROW_ID", "TABLENAME = 'CONTACT'"]
+    ];
 }
 
 /*
diff --git a/process/Sql_lib/process.js b/process/Sql_lib/process.js
index 4712df6bfd..fb933d980b 100644
--- a/process/Sql_lib/process.js
+++ b/process/Sql_lib/process.js
@@ -2489,7 +2489,7 @@ SqlBuilder.prototype.buildUpdateStatement = function (pFieldValues, pTableName)
         values.push(pFieldValues[field].toString());
     }
     
-    if (columns.length !== 0 && this._checkForUpdate(pExecuteOnlyIfConditionExists))
+    if (columns.length !== 0 && this._checkForUpdate())
     {
         if (!pTableName && !this._tableName)
             throw SqlBuilder._ERROR_NO_TABLE();
diff --git a/process/workflowServiceTasks_rest/process.js b/process/workflowServiceTasks_rest/process.js
index 2da45ade35..470717e7e1 100644
--- a/process/workflowServiceTasks_rest/process.js
+++ b/process/workflowServiceTasks_rest/process.js
@@ -6,12 +6,8 @@ function restget (pRequest)
 {
     var request = JSON.parse(pRequest);
     
-    var serviceTasks = project.getDataModels(project.DATAMODEL_KIND_PROCESS)
-    .filter(function (row)
-    {
-        return /.+_workflowService$/.test(row[0]);
-    })
-    .map(function (row)
+    var serviceTaskNames = process.getProcesses([process.VARIANT_WORKFLOW]);
+    var serviceTasks = project.getDataModels(project.DATAMODEL_KIND_PROCESS, serviceTaskNames).map(function (row)
     {
         return {
             id : row[0],
-- 
GitLab