From f49b129c97ec909f8d27a1044c54fb1751c323e0 Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Mon, 7 Jan 2019 16:42:51 +0100
Subject: [PATCH] Relation lookup erweitern

---
 entity/Comm_entity/Comm_entity.aod            | 26 ++++++++
 entity/Relation_entity/Relation_entity.aod    | 61 ++++++++++++++++++-
 .../entityfields/image/valueProcess.js        | 15 +++++
 .../children/commcategory_param/code.js       |  2 +
 .../children/relid_param/code.js              |  4 ++
 .../children/commcategory_param/code.js       |  2 +
 .../children/relid_param/code.js              |  4 ++
 .../standard_email_comm.value/expression.js   |  5 ++
 .../standard_phone_comm.value/expression.js   |  5 ++
 .../Relation_context/Relation_context.aod     |  1 +
 neonView/PersLookup_view/PersLookup_view.aod  |  8 +++
 .../RelationLookup_view.aod                   | 12 ++++
 process/Comm_lib/process.js                   | 12 +++-
 13 files changed, 153 insertions(+), 4 deletions(-)
 create mode 100644 entity/Relation_entity/entityfields/image/valueProcess.js
 create mode 100644 entity/Relation_entity/entityfields/relationcommemail_dfo/children/commcategory_param/code.js
 create mode 100644 entity/Relation_entity/entityfields/relationcommemail_dfo/children/relid_param/code.js
 create mode 100644 entity/Relation_entity/entityfields/relationcommphone_dfo/children/commcategory_param/code.js
 create mode 100644 entity/Relation_entity/entityfields/relationcommphone_dfo/children/relid_param/code.js
 create mode 100644 entity/Relation_entity/recordcontainers/db/recordfieldmappings/standard_email_comm.value/expression.js
 create mode 100644 entity/Relation_entity/recordcontainers/db/recordfieldmappings/standard_phone_comm.value/expression.js

diff --git a/entity/Comm_entity/Comm_entity.aod b/entity/Comm_entity/Comm_entity.aod
index ab82c3ff3c3..163c51cdc7f 100644
--- a/entity/Comm_entity/Comm_entity.aod
+++ b/entity/Comm_entity/Comm_entity.aod
@@ -159,6 +159,32 @@ Usually this is used for filtering COMM-entires by a specified contact or creati
       <mandatory v="false" />
       <description>PARAMETER</description>
     </entityParameter>
+    <entityIncomingField>
+      <name>RelationCommEmail_dfi</name>
+      <fieldType>DEPENDENCY_IN</fieldType>
+      <recordContainer>db</recordContainer>
+      <dependencies>
+        <entityDependency>
+          <name>6aaf2f88-6b5b-46ea-8b73-2a46643a70da</name>
+          <entityName>Relation_entity</entityName>
+          <fieldName>RelationCommEmail_dfo</fieldName>
+          <isOutgoing v="false" />
+        </entityDependency>
+      </dependencies>
+    </entityIncomingField>
+    <entityIncomingField>
+      <name>RelationCommPhone_dfi</name>
+      <fieldType>DEPENDENCY_IN</fieldType>
+      <recordContainer>db</recordContainer>
+      <dependencies>
+        <entityDependency>
+          <name>e2a645cf-ac79-4fb7-a706-ec853730c88f</name>
+          <entityName>Relation_entity</entityName>
+          <fieldName>RelationCommPhone_dfo</fieldName>
+          <isOutgoing v="false" />
+        </entityDependency>
+      </dependencies>
+    </entityIncomingField>
   </entityFields>
   <recordContainers>
     <dbRecordContainer>
diff --git a/entity/Relation_entity/Relation_entity.aod b/entity/Relation_entity/Relation_entity.aod
index 71d2bc934d6..a9b2399d5cb 100644
--- a/entity/Relation_entity/Relation_entity.aod
+++ b/entity/Relation_entity/Relation_entity.aod
@@ -96,7 +96,7 @@ See RelationUtils.getRelationTypeByPersOrg for possible values</description>
       <recordContainer>db</recordContainer>
       <dependencies>
         <entityDependency>
-          <name>ad58b5da-132a-46a8-abee-0671bfd2e006</name>
+          <name>2537ae2b-ee99-41bd-9cd5-ec482cb20a56</name>
           <entityName>Product_entity</entityName>
           <fieldName>ProductRelation_dfo</fieldName>
           <isOutgoing v="false" />
@@ -154,6 +154,57 @@ See RelationUtils.getRelationTypeByPersOrg for possible values</description>
         </entityDependency>
       </dependencies>
     </entityIncomingField>
+    <entityField>
+      <name>IMAGE</name>
+      <contentType>IMAGE</contentType>
+      <valueProcess>%aditoprj%/entity/Relation_entity/entityfields/image/valueProcess.js</valueProcess>
+    </entityField>
+    <entityOutgoingField>
+      <name>RelationCommEmail_dfo</name>
+      <fieldType>DEPENDENCY_OUT</fieldType>
+      <dependency>
+        <name>dependency</name>
+        <entityName>Comm_entity</entityName>
+        <fieldName>RelationCommEmail_dfi</fieldName>
+      </dependency>
+      <children>
+        <entityParameter>
+          <name>CommCategory_param</name>
+          <code>%aditoprj%/entity/Relation_entity/entityfields/relationcommemail_dfo/children/commcategory_param/code.js</code>
+        </entityParameter>
+        <entityParameter>
+          <name>RelId_param</name>
+          <code>%aditoprj%/entity/Relation_entity/entityfields/relationcommemail_dfo/children/relid_param/code.js</code>
+        </entityParameter>
+      </children>
+    </entityOutgoingField>
+    <entityOutgoingField>
+      <name>RelationCommPhone_dfo</name>
+      <fieldType>DEPENDENCY_OUT</fieldType>
+      <dependency>
+        <name>dependency</name>
+        <entityName>Comm_entity</entityName>
+        <fieldName>RelationCommPhone_dfi</fieldName>
+      </dependency>
+      <children>
+        <entityParameter>
+          <name>CommCategory_param</name>
+          <code>%aditoprj%/entity/Relation_entity/entityfields/relationcommphone_dfo/children/commcategory_param/code.js</code>
+        </entityParameter>
+        <entityParameter>
+          <name>RelId_param</name>
+          <code>%aditoprj%/entity/Relation_entity/entityfields/relationcommphone_dfo/children/relid_param/code.js</code>
+        </entityParameter>
+      </children>
+    </entityOutgoingField>
+    <entityField>
+      <name>STANDARD_EMAIL_COMM</name>
+      <title>standard email</title>
+    </entityField>
+    <entityField>
+      <name>STANDARD_PHONE_COMM</name>
+      <title>Phone</title>
+    </entityField>
   </entityFields>
   <recordContainers>
     <dbRecordContainer>
@@ -243,6 +294,14 @@ See RelationUtils.getRelationTypeByPersOrg for possible values</description>
           <name>PERS_LASTNAME.value</name>
           <recordfield>PERS.LASTNAME</recordfield>
         </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>STANDARD_EMAIL_COMM.value</name>
+          <expression>%aditoprj%/entity/Relation_entity/recordcontainers/db/recordfieldmappings/standard_email_comm.value/expression.js</expression>
+        </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>STANDARD_PHONE_COMM.value</name>
+          <expression>%aditoprj%/entity/Relation_entity/recordcontainers/db/recordfieldmappings/standard_phone_comm.value/expression.js</expression>
+        </dbRecordFieldMapping>
       </recordFieldMappings>
     </dbRecordContainer>
   </recordContainers>
diff --git a/entity/Relation_entity/entityfields/image/valueProcess.js b/entity/Relation_entity/entityfields/image/valueProcess.js
new file mode 100644
index 00000000000..16b1a89eb18
--- /dev/null
+++ b/entity/Relation_entity/entityfields/image/valueProcess.js
@@ -0,0 +1,15 @@
+import("system.result");
+import("system.neon");
+import("system.vars");
+import("Pers_lib");
+import("Org_lib");
+import("Relation_lib");
+
+if (vars.get("$field.relationType") == 1) // 1 == org, 2 == pers, 3 == pers
+{
+    result.string(OrgUtils.getImage(vars.get("$field.ORG_ID"), vars.getString("$field.ORG_NAME")));
+}
+else
+{
+    result.string(PersUtils.getImage(vars.get("$field.PERS_ID"), (vars.getString("$field.PERS_FIRSTNAME") + " " + vars.getString("$field.PERS_LASTNAME")).trim()));
+}
\ No newline at end of file
diff --git a/entity/Relation_entity/entityfields/relationcommemail_dfo/children/commcategory_param/code.js b/entity/Relation_entity/entityfields/relationcommemail_dfo/children/commcategory_param/code.js
new file mode 100644
index 00000000000..4c564fa3fa1
--- /dev/null
+++ b/entity/Relation_entity/entityfields/relationcommemail_dfo/children/commcategory_param/code.js
@@ -0,0 +1,2 @@
+import("system.result");
+result.string("EMAIL");
\ No newline at end of file
diff --git a/entity/Relation_entity/entityfields/relationcommemail_dfo/children/relid_param/code.js b/entity/Relation_entity/entityfields/relationcommemail_dfo/children/relid_param/code.js
new file mode 100644
index 00000000000..9517eee9df1
--- /dev/null
+++ b/entity/Relation_entity/entityfields/relationcommemail_dfo/children/relid_param/code.js
@@ -0,0 +1,4 @@
+import("system.vars");
+import("system.result");
+
+result.string(vars.get("$field.RELATIONID"));
\ No newline at end of file
diff --git a/entity/Relation_entity/entityfields/relationcommphone_dfo/children/commcategory_param/code.js b/entity/Relation_entity/entityfields/relationcommphone_dfo/children/commcategory_param/code.js
new file mode 100644
index 00000000000..9220a2c4534
--- /dev/null
+++ b/entity/Relation_entity/entityfields/relationcommphone_dfo/children/commcategory_param/code.js
@@ -0,0 +1,2 @@
+import("system.result");
+result.string("PHONE");
\ No newline at end of file
diff --git a/entity/Relation_entity/entityfields/relationcommphone_dfo/children/relid_param/code.js b/entity/Relation_entity/entityfields/relationcommphone_dfo/children/relid_param/code.js
new file mode 100644
index 00000000000..9517eee9df1
--- /dev/null
+++ b/entity/Relation_entity/entityfields/relationcommphone_dfo/children/relid_param/code.js
@@ -0,0 +1,4 @@
+import("system.vars");
+import("system.result");
+
+result.string(vars.get("$field.RELATIONID"));
\ No newline at end of file
diff --git a/entity/Relation_entity/recordcontainers/db/recordfieldmappings/standard_email_comm.value/expression.js b/entity/Relation_entity/recordcontainers/db/recordfieldmappings/standard_email_comm.value/expression.js
new file mode 100644
index 00000000000..a371c71fba3
--- /dev/null
+++ b/entity/Relation_entity/recordcontainers/db/recordfieldmappings/standard_email_comm.value/expression.js
@@ -0,0 +1,5 @@
+import("system.result");
+import("Comm_lib");
+
+var res = CommUtil.getStandardSubSqlMail();
+result.string(res);
\ No newline at end of file
diff --git a/entity/Relation_entity/recordcontainers/db/recordfieldmappings/standard_phone_comm.value/expression.js b/entity/Relation_entity/recordcontainers/db/recordfieldmappings/standard_phone_comm.value/expression.js
new file mode 100644
index 00000000000..9b0174b05e7
--- /dev/null
+++ b/entity/Relation_entity/recordcontainers/db/recordfieldmappings/standard_phone_comm.value/expression.js
@@ -0,0 +1,5 @@
+import("system.result");
+import("Comm_lib");
+
+var res = CommUtil.getStandardSubSqlPhone();
+result.string(res);
\ No newline at end of file
diff --git a/neonContext/Relation_context/Relation_context.aod b/neonContext/Relation_context/Relation_context.aod
index 6b4088dbf9b..3362a708b4a 100644
--- a/neonContext/Relation_context/Relation_context.aod
+++ b/neonContext/Relation_context/Relation_context.aod
@@ -2,6 +2,7 @@
 <neonContext xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.0.0" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonContext/1.0.0">
   <name>Relation_context</name>
   <majorModelMode>DISTRIBUTED</majorModelMode>
+  <lookupview>RelationLookup_view</lookupview>
   <entity>Relation_entity</entity>
   <references>
     <neonViewReference>
diff --git a/neonView/PersLookup_view/PersLookup_view.aod b/neonView/PersLookup_view/PersLookup_view.aod
index 7daae42d3a1..1c7fdd8c23d 100644
--- a/neonView/PersLookup_view/PersLookup_view.aod
+++ b/neonView/PersLookup_view/PersLookup_view.aod
@@ -24,6 +24,14 @@
           <name>fb150402-a576-4e21-855c-91dd7574f353</name>
           <entityField>LASTNAME</entityField>
         </neonTableColumn>
+        <neonTableColumn>
+          <name>768f2294-2c4e-4c71-9992-ee9cea299041</name>
+          <entityField>STANDARD_PHONE_COMM</entityField>
+        </neonTableColumn>
+        <neonTableColumn>
+          <name>eb778e57-1f2d-436e-b22a-e92f7a190606</name>
+          <entityField>STANDARD_EMAIL_COMM</entityField>
+        </neonTableColumn>
       </columns>
     </tableViewTemplate>
   </children>
diff --git a/neonView/RelationLookup_view/RelationLookup_view.aod b/neonView/RelationLookup_view/RelationLookup_view.aod
index 087c22f3a3c..1c221bc8979 100644
--- a/neonView/RelationLookup_view/RelationLookup_view.aod
+++ b/neonView/RelationLookup_view/RelationLookup_view.aod
@@ -12,6 +12,10 @@
       <name>relationLookupList_template</name>
       <entityField>#ENTITY</entityField>
       <columns>
+        <neonTableColumn>
+          <name>5a0d38bb-bfa5-4abc-86e7-fac65804bb5c</name>
+          <entityField>IMAGE</entityField>
+        </neonTableColumn>
         <neonTableColumn>
           <name>ca59a64a-adce-49c3-93ad-2978c81809f8</name>
           <entityField>ORG_NAME</entityField>
@@ -26,6 +30,14 @@
           <width v="75" />
           <expandRatio v="100" />
         </neonTableColumn>
+        <neonTableColumn>
+          <name>2ee5838b-e0ff-4f21-bf57-e41d0766fdec</name>
+          <entityField>STANDARD_PHONE_COMM</entityField>
+        </neonTableColumn>
+        <neonTableColumn>
+          <name>16174be3-c8fb-46a8-8f73-f6b8d8fad963</name>
+          <entityField>STANDARD_EMAIL_COMM</entityField>
+        </neonTableColumn>
       </columns>
     </tableViewTemplate>
   </children>
diff --git a/process/Comm_lib/process.js b/process/Comm_lib/process.js
index 854e3aaace1..08093abd9c9 100644
--- a/process/Comm_lib/process.js
+++ b/process/Comm_lib/process.js
@@ -113,7 +113,7 @@ CommUtil.getStandardSubSqlForCategory = function(pCategory, pRelationField)
     if (pRelationField == undefined)
         cond.and("COMM.RELATION_ID = RELATION.RELATIONID");
     else if (typeof(pRelationField) == "string")
-        cond.and("COMM.RELATION_ID = " + pRelationField);
+        cond.andPrepare("COMM.RELATION_ID", pRelationField);
     else if (typeof(pRelationField) == "object")
     {
         //you may want to sepcify a concrete value
@@ -126,10 +126,16 @@ CommUtil.getStandardSubSqlForCategory = function(pCategory, pRelationField)
     if (mediumIds.length == 0)
         return "''";
     
-    cond.and("COMM.MEDIUM_ID in (" + mediumIds.join(", ") + ")");
+    var anyMediumIdCond = SqlCondition.begin();
+    mediumIds.forEach(function(pMediumId)
+    {
+        anyMediumIdCond.orPrepare("COMM.MEDIUM_ID", pMediumId);
+    });
+    cond.andSqlCondition(anyMediumIdCond, "1=0");
+    
     cond.and("COMM.STANDARD = 1");
     
-    var res = "select max(COMM.ADDR) from COMM" + cond.toWhereString();
+    var res = db.translateStatement(cond.buildSelect("select max(COMM.ADDR) from COMM", "1=0"));
     return res;
 };
 
-- 
GitLab