From 35b5d75866d799aa5caac27b13caa2ffa164c99a Mon Sep 17 00:00:00 2001
From: "j.goderbauer" <j.goderbauer@adito.de>
Date: Mon, 29 Apr 2019 11:20:06 +0200
Subject: [PATCH] =?UTF-8?q?[Projekt:=20Entwicklung=20-=20Neon][TicketNr.:?=
 =?UTF-8?q?=201036415][=C3=9Cbernahme=20AUDIT=20und=20Logging=20aus=20best?=
 =?UTF-8?q?ehendem=20xRM-Basic=20f=C3=BCr=20ADITO=202019]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 aliasDefinition/Data_alias/Data_alias.aod     | 59 ++---------------
 .../translate4log/property.js                 |  7 +++
 process/Keyword_lib/process.js                |  5 +-
 process/Loghistory_lib/process.js             | 63 ++++++++++++++++---
 4 files changed, 69 insertions(+), 65 deletions(-)
 create mode 100644 aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/contact/entityfields/language/customproperties/translate4log/property.js

diff --git a/aliasDefinition/Data_alias/Data_alias.aod b/aliasDefinition/Data_alias/Data_alias.aod
index 81b8e1987e..151d58ab28 100644
--- a/aliasDefinition/Data_alias/Data_alias.aod
+++ b/aliasDefinition/Data_alias/Data_alias.aod
@@ -253,6 +253,11 @@
                     <global v="false" />
                     <property v="true" />
                   </customBooleanProperty>
+                  <customJDitoProperty>
+                    <name>translate4Log</name>
+                    <global v="false" />
+                    <property>%aditoprj%/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/contact/entityfields/language/customproperties/translate4log/property.js</property>
+                  </customJDitoProperty>
                 </customProperties>
               </entityFieldDb>
               <entityFieldDb>
@@ -8055,13 +8060,6 @@
                 <documentation></documentation>
                 <title>Tablename</title>
                 <description></description>
-                <customProperties>
-                  <customBooleanProperty>
-                    <name>log</name>
-                    <global v="false" />
-                    <property v="true" />
-                  </customBooleanProperty>
-                </customProperties>
               </entityFieldDb>
               <entityFieldDb>
                 <name>DATE_EDIT</name>
@@ -8076,12 +8074,6 @@
                 <documentation></documentation>
                 <title>Modification date</title>
                 <description></description>
-                <customProperties>
-                  <customBooleanProperty>
-                    <name>log</name>
-                    <global v="false" />
-                  </customBooleanProperty>
-                </customProperties>
               </entityFieldDb>
               <entityFieldDb>
                 <name>DESCRIPTION</name>
@@ -8096,13 +8088,6 @@
                 <documentation></documentation>
                 <title>Description</title>
                 <description></description>
-                <customProperties>
-                  <customBooleanProperty>
-                    <name>log</name>
-                    <global v="false" />
-                    <property v="true" />
-                  </customBooleanProperty>
-                </customProperties>
               </entityFieldDb>
               <entityFieldDb>
                 <name>SOURCE_TABLENAMEID</name>
@@ -8117,13 +8102,6 @@
                 <documentation></documentation>
                 <title>Source tablename Id</title>
                 <description></description>
-                <customProperties>
-                  <customBooleanProperty>
-                    <name>log</name>
-                    <global v="false" />
-                    <property v="true" />
-                  </customBooleanProperty>
-                </customProperties>
               </entityFieldDb>
               <entityFieldDb>
                 <name>LOGTYPE</name>
@@ -8138,13 +8116,6 @@
                 <documentation></documentation>
                 <title>Log type</title>
                 <description></description>
-                <customProperties>
-                  <customBooleanProperty>
-                    <name>log</name>
-                    <global v="false" />
-                    <property v="true" />
-                  </customBooleanProperty>
-                </customProperties>
               </entityFieldDb>
               <entityFieldDb>
                 <name>SOURCE_TABLENAME</name>
@@ -8159,13 +8130,6 @@
                 <documentation></documentation>
                 <title>Source tablename</title>
                 <description></description>
-                <customProperties>
-                  <customBooleanProperty>
-                    <name>log</name>
-                    <global v="false" />
-                    <property v="true" />
-                  </customBooleanProperty>
-                </customProperties>
               </entityFieldDb>
               <entityFieldDb>
                 <name>AB_LOGHISTORYID</name>
@@ -8194,13 +8158,6 @@
                 <documentation></documentation>
                 <title>Tablename Id</title>
                 <description></description>
-                <customProperties>
-                  <customBooleanProperty>
-                    <name>log</name>
-                    <global v="false" />
-                    <property v="true" />
-                  </customBooleanProperty>
-                </customProperties>
               </entityFieldDb>
               <entityFieldDb>
                 <name>DATE_NEW</name>
@@ -8215,12 +8172,6 @@
                 <documentation></documentation>
                 <title>Creation date</title>
                 <description></description>
-                <customProperties>
-                  <customBooleanProperty>
-                    <name>log</name>
-                    <global v="false" />
-                  </customBooleanProperty>
-                </customProperties>
               </entityFieldDb>
               <entityFieldDb>
                 <name>USER_NEW</name>
diff --git a/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/contact/entityfields/language/customproperties/translate4log/property.js b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/contact/entityfields/language/customproperties/translate4log/property.js
new file mode 100644
index 0000000000..51a8cec57a
--- /dev/null
+++ b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/contact/entityfields/language/customproperties/translate4log/property.js
@@ -0,0 +1,7 @@
+import("system.result");
+import("Loghistory_lib");
+import("Keyword_lib");
+
+var params = Translate4LogParams.load();
+var res = LanguageKeywordUtils.getViewValue(params.value, params.locale);
+result.string(res);
\ No newline at end of file
diff --git a/process/Keyword_lib/process.js b/process/Keyword_lib/process.js
index 2403beea88..1b01908232 100644
--- a/process/Keyword_lib/process.js
+++ b/process/Keyword_lib/process.js
@@ -295,11 +295,12 @@ LanguageKeywordUtils.getResolvedTitleSqlPart = function(pDbFieldName, pLocale)
  * returns a specific name (translated) - this is normally the view-value of a language
  * 
  * @param {String} key id value of the language where the view-value shall be searched
+ * @param {String} [locale] Language-value for translations
  *
  * @return {String} representation of the translated name 
  * 
  */
-LanguageKeywordUtils.getViewValue = function(key)
+LanguageKeywordUtils.getViewValue = function(key, locale)
 {
     if (!key)
         return "";
@@ -310,7 +311,7 @@ LanguageKeywordUtils.getViewValue = function(key)
     var originalTitle = db.cell(sql);
     if (originalTitle == "")
         return "";
-    var translatedTitle = translate.text(originalTitle);
+    var translatedTitle = locale ? translate.text(originalTitle, locale) : translate.text(originalTitle);
     return translatedTitle;
 };
 
diff --git a/process/Loghistory_lib/process.js b/process/Loghistory_lib/process.js
index 396fb3eb19..ee9fda09a9 100644
--- a/process/Loghistory_lib/process.js
+++ b/process/Loghistory_lib/process.js
@@ -1,3 +1,4 @@
+import("system.vars");
 import("system.util");
 import("system.logging");
 import("system.project");
@@ -334,14 +335,8 @@ LogHistoryExecutor.prototype._getFormattedValue = function (pDescription, pValue
     }
     else if (pDescription.translate4Log != null && pDescription.translate4Log != "") 
     {
-        var params = {
-            rowId: this.idValue,
-            value: pValue.toString(),
-            action: this.sqlAction,
-            locale: this.translationLanguage
-        };
-        
-        pValue = process.executeScript("LogHistoryExecutor._getFormattedValue ", pDescription.translate4Log, params);
+        var params = Translate4LogParams.generateParams(this.idValue, pValue.toString(), this.sqlAction, this.translationLanguage);
+        pValue = process.executeScript("LogHistoryExecutor._getFormattedValue ", pDescription.translate4Log, params, vars.get("$sys.dbalias"));
     }
     else if (pDescription.columnType == String(SQLTYPES.TIMESTAMP)) 
         pValue = datetime.toDate(pValue, translate.text("dd.MM.yyyy", this.translationLanguage), "Europe/Berlin");//TODO: timezone?
@@ -367,4 +362,54 @@ LogHistoryExecutor.prototype._getFormattedValue = function (pDescription, pValue
         }
     }
     return pValue;
-}
\ No newline at end of file
+}
+
+
+/**
+ * object for easier handling of the parameters that are provided within the translate4Log-process for auditing
+ *
+ * @example 
+ * import("system.result");
+ * import("Loghistory_lib");
+ * import("Keyword_lib");
+ * 
+ * var params = Translate4LogParams.load();
+ * var res = LanguageKeywordUtils.getViewValue(params.value, params.locale);
+ * result.string(res);
+ * @class
+ */
+function Translate4LogParams()
+{
+    //watch out the Translate4LogParams.generateParams function
+    this.rowId = vars.get("$local.rowId");
+    this.value = vars.get("$local.value");
+    this.action = vars.get("$local.action");
+    this.locale = vars.get("$local.locale");
+}
+
+
+/**
+ * function for generating the parameters which can be passed to another process
+ * the parameters should be self explaing since every single of them is a parametervalue that will be passed to anotherProcess
+ *
+ * @static
+ */
+Translate4LogParams.generateParams = function (pRowId, pValue, pAction, pLocale)
+{
+    //watch out the Translate4LogParams-constructor function
+    var res = {
+            rowId: pRowId,
+            value: pValue,
+            action: pAction,
+            locale: pLocale
+        };
+    return res;//store in variable for autocomplete of the ADITO designer
+};
+
+/**
+ * creates an instnace of Translate4LogParams and loads the data
+ */
+Translate4LogParams.load = function()
+{
+    return new Translate4LogParams();
+};
\ No newline at end of file
-- 
GitLab