From 1ff77d0c4f49bf79395d69685a5f71cd4d5f5c8f Mon Sep 17 00:00:00 2001
From: "j.goderbauer" <j.goderbauer@adito.de>
Date: Mon, 29 Apr 2019 14:34:35 +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     |  5 ++++
 .../translate4log/property.js                 |  7 +++++
 .../country/displayValueProcess.js            |  7 ++---
 process/Country_lib/Country_lib.aod           |  9 ++++++
 process/Country_lib/process.js                | 30 +++++++++++++++++++
 process/Loghistory_lib/process.js             | 10 +++----
 6 files changed, 58 insertions(+), 10 deletions(-)
 create mode 100644 aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/address/entityfields/country/customproperties/translate4log/property.js
 create mode 100644 process/Country_lib/Country_lib.aod
 create mode 100644 process/Country_lib/process.js

diff --git a/aliasDefinition/Data_alias/Data_alias.aod b/aliasDefinition/Data_alias/Data_alias.aod
index 151d58ab28..61811a2b9a 100644
--- a/aliasDefinition/Data_alias/Data_alias.aod
+++ b/aliasDefinition/Data_alias/Data_alias.aod
@@ -972,6 +972,11 @@
                     <global v="false" />
                     <property v="true" />
                   </customBooleanProperty>
+                  <customJDitoProperty>
+                    <name>translate4Log</name>
+                    <global v="false" />
+                    <property>%aditoprj%/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/address/entityfields/country/customproperties/translate4log/property.js</property>
+                  </customJDitoProperty>
                 </customProperties>
               </entityFieldDb>
               <entityFieldDb>
diff --git a/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/address/entityfields/country/customproperties/translate4log/property.js b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/address/entityfields/country/customproperties/translate4log/property.js
new file mode 100644
index 0000000000..3951889f46
--- /dev/null
+++ b/aliasDefinition/Data_alias/aliasdefinitionsub/entitygroup/entities/address/entityfields/country/customproperties/translate4log/property.js
@@ -0,0 +1,7 @@
+import("system.result");
+import("Country_lib");
+import("Loghistory_lib");
+
+var params = Translate4LogParams.load();
+var countryName = CountryUtils.getLatinNameByIso2(params.value, params.locale);
+result.string(countryName);
\ No newline at end of file
diff --git a/entity/Address_entity/entityfields/country/displayValueProcess.js b/entity/Address_entity/entityfields/country/displayValueProcess.js
index 22c043fdc3..3eb96b5258 100644
--- a/entity/Address_entity/entityfields/country/displayValueProcess.js
+++ b/entity/Address_entity/entityfields/country/displayValueProcess.js
@@ -1,11 +1,8 @@
 import("system.vars");
-import("system.db");
-import("system.translate");
 import("system.result");
-import("Sql_lib");
+import("Country_lib");
 
 //TODO: temporary testing code -> will be replaced with title-mechanic
 var isoCode = vars.get("$field.COUNTRY");
-var countryName  = db.cell(SqlCondition.begin().andPrepare("AB_COUNTRYINFO.ISO2", isoCode).buildSql("select AB_COUNTRYINFO.NAME_LATIN from AB_COUNTRYINFO"));
-countryName = translate.text(countryName);
+var countryName = CountryUtils.getLatinNameByIso2(isoCode);
 result.string(countryName);
\ No newline at end of file
diff --git a/process/Country_lib/Country_lib.aod b/process/Country_lib/Country_lib.aod
new file mode 100644
index 0000000000..7097e51847
--- /dev/null
+++ b/process/Country_lib/Country_lib.aod
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.2.1">
+  <name>Country_lib</name>
+  <majorModelMode>DISTRIBUTED</majorModelMode>
+  <process>%aditoprj%/process/Country_lib/process.js</process>
+  <variants>
+    <element>LIBRARY</element>
+  </variants>
+</process>
diff --git a/process/Country_lib/process.js b/process/Country_lib/process.js
new file mode 100644
index 0000000000..67f674c97d
--- /dev/null
+++ b/process/Country_lib/process.js
@@ -0,0 +1,30 @@
+import("system.db");
+import("system.translate");
+import("Sql_lib");
+
+/**
+ * provides functions for miscellaneous interactions with countrydata
+ * Do not create an instance of this!
+ *
+ * @class
+ * @static
+ */
+function CountryUtils() {}
+
+/**
+* loads the translated latin name of an entry within the countryinfos by a provided ISO2-code
+*
+* @param {String} pIso2 the uppercase ISO2 code whoes latin name shall be retriefed, e.g."DE"
+* @param {String} [pLocale=current client/server language] specifies the locale for translating 
+*
+* @return {String} the translated country name in the latin version
+*
+*/
+CountryUtils.getLatinNameByIso2 = function(pIso2, pLocale)
+{
+    var countryName = db.cell(SqlCondition.begin()
+                                          .andPrepare("AB_COUNTRYINFO.ISO2", pIso2)
+                                          .buildSql("select AB_COUNTRYINFO.NAME_LATIN from AB_COUNTRYINFO"));
+    countryName = pLocale ? translate.text(countryName, pLocale) : translate.text(countryName);
+    return countryName;
+};
\ No newline at end of file
diff --git a/process/Loghistory_lib/process.js b/process/Loghistory_lib/process.js
index ee9fda09a9..6e2c450766 100644
--- a/process/Loghistory_lib/process.js
+++ b/process/Loghistory_lib/process.js
@@ -79,11 +79,11 @@ LogHistoryExecutor.prototype.execute = function ()
         columnStructure = structure.tables[this.affectedTable].columns;
         for (var column in columnStructure)
         {
-            if (columnStructure[column].tableRef) references[column] = 
-            {
-                table: columnStructure[column].tableRef, 
-                id: ""
-            }
+            if (columnStructure[column].tableRef)
+                references[column] = {
+                    table: columnStructure[column].tableRef, 
+                    id: ""
+                };
             if (columnStructure[column].primaryKey)
                 primaryKey = column;
             if (columnStructure[column].log)
-- 
GitLab