From 5b72c3e89c7bff3c52a9973351954b8ff20f8e22 Mon Sep 17 00:00:00 2001
From: "d.buechler" <d.buechler@adito.de>
Date: Sat, 20 Jul 2019 11:07:18 +0200
Subject: [PATCH] =?UTF-8?q?Die=20Dublettenermittlung=20bezieht=20nun=20den?=
 =?UTF-8?q?=20Threshold=20pro=20einzelfilter=20mit=20ein.=20Die=20Kombinat?=
 =?UTF-8?q?ion=20aus=20Filtername=20und=20Zielentity=20darf=20nur=20einmal?=
 =?UTF-8?q?=20vorkommen.=20Das=20ist=20so=20aufgrund=20des=20Designs=20des?=
 =?UTF-8?q?=20Aufrufs,=20dieser=20ist=20so=20universell=20und=20einfach=20?=
 =?UTF-8?q?wie=20m=C3=B6glich=20gestaltet=20und=20ermittelt=20den=20zu=20n?=
 =?UTF-8?q?utzenden=20Filter=20anhand=20dieser=20Konfiguration.=20Aufgrund?=
 =?UTF-8?q?=20dessen=20gibt=20es=20nun=20eine=20Validierung=20auf=20dem=20?=
 =?UTF-8?q?Filter=20Name=20Feld.=20=C3=9Cbersetzung=20f=C3=BCr=20Validieru?=
 =?UTF-8?q?ng=20eingef=C3=BCgt?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../DuplicateScan_entity.aod                  |  1 +
 .../entityfields/filter_name/onValidation.js  | 27 ++++++++++
 .../_____LANGUAGE_EXTRA.aod                   | 15 ++++++
 .../_____LANGUAGE_de/_____LANGUAGE_de.aod     |  7 +++
 .../_____LANGUAGE_en/_____LANGUAGE_en.aod     | 15 ++++++
 process/DuplicateScanner_lib/process.js       | 49 ++++++++++++++-----
 6 files changed, 103 insertions(+), 11 deletions(-)
 create mode 100644 entity/DuplicateScan_entity/entityfields/filter_name/onValidation.js

diff --git a/entity/DuplicateScan_entity/DuplicateScan_entity.aod b/entity/DuplicateScan_entity/DuplicateScan_entity.aod
index 5794d0e086..3ff1efe86f 100644
--- a/entity/DuplicateScan_entity/DuplicateScan_entity.aod
+++ b/entity/DuplicateScan_entity/DuplicateScan_entity.aod
@@ -18,6 +18,7 @@
     <entityField>
       <name>FILTER_NAME</name>
       <title>Filter Name</title>
+      <onValidation>%aditoprj%/entity/DuplicateScan_entity/entityfields/filter_name/onValidation.js</onValidation>
     </entityField>
     <entityField>
       <name>EXTERNAL_SERVICE_USAGE_ALLOWED</name>
diff --git a/entity/DuplicateScan_entity/entityfields/filter_name/onValidation.js b/entity/DuplicateScan_entity/entityfields/filter_name/onValidation.js
new file mode 100644
index 0000000000..597bb8faa5
--- /dev/null
+++ b/entity/DuplicateScan_entity/entityfields/filter_name/onValidation.js
@@ -0,0 +1,27 @@
+import("system.translate");
+import("system.result");
+import("system.db");
+import("system.vars");
+
+/*
+ * Because of the easy usage of the duplicate scan functionality, which can be called using the
+ * filtername and targetentity, this particular combination must be unique. Therefore it's
+ * uniqueness has to be verified on creation/modification
+ */
+
+var targetEntity = vars.get("$field.ENTITY_TO_SCAN_NAME");
+var currentFilterName = vars.get("$field.FILTER_NAME");
+var messageText = "The combination of filter name and target entity is already in use";
+
+if(targetEntity != "")
+{
+    var query = "select count(*) from DUPLICATESCANNER"
+                + " where ENTITY_TO_SCAN_NAME = '" + targetEntity + "'"
+                + " and FILTER_NAME = '" + currentFilterName + "'";
+    
+    var occurrences = parseInt(db.cell(query), 10);
+    
+    if(occurrences > 0)
+        result.string(translate.text(messageText));
+}
+    
\ No newline at end of file
diff --git a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
index 3c24e652a4..076e0574da 100644
--- a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
+++ b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
@@ -4956,6 +4956,21 @@
     <entry>
       <key>Configuration name</key>
     </entry>
+    <entry>
+      <key>Export letter for selection</key>
+    </entry>
+    <entry>
+      <key>Export letter</key>
+    </entry>
+    <entry>
+      <key>Privacy agreement</key>
+    </entry>
+    <entry>
+      <key>Sufficient guarantees</key>
+    </entry>
+    <entry>
+      <key>The combination of filter name and target entity is already in use</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 fca114325e..6e773b6b1b 100644
--- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
+++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
@@ -6254,6 +6254,13 @@
       <key>Configuration name</key>
       <value>Konfigurationsname</value>
     </entry>
+    <entry>
+      <key>Download letter</key>
+    </entry>
+    <entry>
+      <key>The combination of filter name and target entity is already in use</key>
+      <value>Die Kombination von Filtername und Zielentity existiert bereits</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 7feec0afc7..dc8935925a 100644
--- a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
+++ b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
@@ -5005,6 +5005,21 @@
     <entry>
       <key>Characters to use</key>
     </entry>
+    <entry>
+      <key>Export letter for selection</key>
+    </entry>
+    <entry>
+      <key>Export letter</key>
+    </entry>
+    <entry>
+      <key>Privacy agreement</key>
+    </entry>
+    <entry>
+      <key>Sufficient guarantees</key>
+    </entry>
+    <entry>
+      <key>The combination of filter name and target entity is already in use</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 a4c5ebc5a5..b18978470f 100644
--- a/process/DuplicateScanner_lib/process.js
+++ b/process/DuplicateScanner_lib/process.js
@@ -1,3 +1,4 @@
+import("system.net");
 import("system.logging");
 import("system.db");
 import("system.entities");
@@ -18,9 +19,14 @@ DuplicateScannerUtils.ScanForDuplicates = function(pFilterName, pTargetEntity,
 
     let possibleDuplicates = _DuplicateScannerUtils._applyPreFilter(pTargetEntity, configuredFilters, pTargetEntityResultFields, pFilterValues);
     
-//    if(_DuplicateScannerUtils._isExternalScanServiceAvailable())
+    if(possibleDuplicates.length <= 0)
+    {
+        return [];
+    }
+//    if(_DuplicateScannerUtils._isExternalScanServiceAvailable() 
+//      && _DuplicateScannerUtils._useExternalScanServiceAllowed(pFilterName, pTargetEntity))
 //    {
-//        
+//        _DuplicateScannerUtils._callExternalScanService();
 //    }
     
     return possibleDuplicates;
@@ -29,15 +35,19 @@ DuplicateScannerUtils.ScanForDuplicates = function(pFilterName, pTargetEntity,
 
 function _DuplicateScannerUtils() {}
 
+var INDEX_FILTER_CONDITION = 0;
+var INDEX_COUNT_CHARS_TO_USE = 1;
+var INDEX_MAX_RESULTS_THRESHOLD = 2;
+
 _DuplicateScannerUtils._applyPreFilter = function(pTargetEntity, pFilterCountCharactersToUseRay, pTargetEntityResultFields, pFilterValues)
 {
-    var maxResultsTreshold = 4;
     var combinedFilter = {};
 
     for (i = 0; i < pFilterCountCharactersToUseRay.length; i++) 
     {
-        let filter = pFilterCountCharactersToUseRay[i][0];
-        let countCharsOfValueToUse = pFilterCountCharactersToUseRay[i][1];
+        let filter = pFilterCountCharactersToUseRay[i][INDEX_FILTER_CONDITION];
+        let countCharsOfValueToUse = pFilterCountCharactersToUseRay[i][INDEX_COUNT_CHARS_TO_USE];
+        let maxResultsThreshold = pFilterCountCharactersToUseRay[i][INDEX_MAX_RESULTS_THRESHOLD];
         
         if(filter == null || filter == "")
             continue;
@@ -73,9 +83,9 @@ _DuplicateScannerUtils._applyPreFilter = function(pTargetEntity, pFilterCountCha
         
         logging.log("rowCount -> " + rowCount);
         
-        if(rowCount > maxResultsTreshold)
+        if(rowCount > maxResultsThreshold)
         {
-            logging.log("zu viele rows gefundenn nächsten Filter anwenden -> rowCount:" + rowCount + " maxResultsTreshold:" + maxResultsTreshold);
+            logging.log("zu viele rows gefundenn nächsten Filter anwenden -> rowCount:" + rowCount + " maxResultsThreshold:" + maxResultsThreshold);
             //Found more rows than allowed by the threshold, run next filter to narrow the results
             continue;
         }
@@ -105,19 +115,36 @@ _DuplicateScannerUtils._isExternalScanServiceAvailable = function()
 }
 
 _DuplicateScannerUtils._callExternalScanService = function(pFormattedJsonValues)
+{
+    let serviceConfig = _DuplicateScannerUtils._getExternalServiceConfiguration();
+    let serviceUrl = "";
+    let actionType = "";
+    let queryParameter = "";
+//    let serviceUrl = "";
+//    let serviceUrl = "";
+//    let serviceUrl = "";
+//    let serviceUrl = "";
+//    let serviceUrl = "";
+//    let serviceUrl = "";
+//    let serviceUrl = "";
+//    let serviceUrl = "";
+//    let serviceUrl = "";
+//    
+//    net.callRestWebserviceBasicAuth(serviceUrl, actionType, pQueryParams, pRequestEntity, pHeaders, pDatatypeAccept, pDataTypeSend, pDatatypeJDitoAccept, pDatatypeJDitoSend, pUser, pPassword, pReturnExtendedResponseInfos);
+}
+
+_DuplicateScannerUtils._getExternalServiceConfiguration = function(pFormattedJsonValues)
 {
     //todo load config and call ws
 }
 
 _DuplicateScannerUtils._loadFilters = function(pFilterName, pTargetEntity)
 {
-    //entities.createConfigForLoadingRows().entity("DuplicateScanConditionConfig_entity")..fields(["$field.CONDITION", "$field.CONDITION_CONFIG_NAME", "$field.COUNT_CHARACTERS_TO_USE"])
-    let query = "select \"CONDITION\", COUNT_CHARACTERS_TO_USE, EXTERNAL_SERVICE_USAGE_ALLOWED from DUPLICATESCANCONDITIONCONFIG"
+    let query = "select \"CONDITION\", COUNT_CHARACTERS_TO_USE, MAX_RESULTS_TRESHOLD from DUPLICATESCANCONDITIONCONFIG"
                 + " join DUPLICATESCANNER on DUPLICATESCANNER.ID = DUPLICATESCANCONDITIONCONFIG.DUPLICATESCAN_ID"
                 + " where FILTER_NAME = '" + pFilterName + "'"
             + " and ENTITY_TO_SCAN_NAME = '" + pTargetEntity + "'";
             
-    logging.log("_loadFilters query -> " + query);
     return db.table(query);
 }
 
@@ -162,7 +189,7 @@ _DuplicateScannerUtils._insertValuesInFilterTemplate = function(pJsonRootNode, p
 /*
  * Returns wether or not a value should be substring'd
  *
- * @return If pCountCharsOfValueToUse is a number, greater than 0 and smaller than the values length -> true
+ * @return true if pCountCharsOfValueToUse is a number, greater than 0 and smaller than the values length
  */
 _DuplicateScannerUtils._isValueLongerThanCharsToUse = function(pValueLength, pCountCharsOfValueToUse)
 {
-- 
GitLab