From 3dd204b18b7bf0c1c30b33d5b83b4e2e20f9b8a6 Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Mon, 11 Feb 2019 08:53:40 +0100
Subject: [PATCH] Merge origin/master into object-relation

Conflicts:
	entity/Contract_entity/Contract_entity.aod
---
 .../ObjectRelation_entity.aod                 | 35 +++++++++++++++++++
 .../object1_type/linkedContextProcess.js      |  0
 .../children/objecttype_param/code.js         |  6 ++++
 .../children/objecttype_param/code.js         |  0
 .../recordcontainers/jdito/contentProcess.js  | 15 ++++++--
 neonContext/Object_context/Object_context.aod |  7 ++++
 .../ContactMain_view/ContactMain_view.aod     |  8 ++---
 .../ObjectLookup_view/ObjectLookup_view.aod   | 22 ++++++++++++
 process/Context_lib/process.js                | 15 +++++---
 9 files changed, 97 insertions(+), 11 deletions(-)
 create mode 100644 entity/ObjectRelation_entity/entityfields/object1_type/linkedContextProcess.js
 create mode 100644 entity/ObjectRelation_entity/entityfields/objects1/children/objecttype_param/code.js
 create mode 100644 entity/ObjectRelation_entity/entityfields/objects2/children/objecttype_param/code.js
 create mode 100644 neonView/ObjectLookup_view/ObjectLookup_view.aod

diff --git a/entity/ObjectRelation_entity/ObjectRelation_entity.aod b/entity/ObjectRelation_entity/ObjectRelation_entity.aod
index 1b9041901e..20aaa80e49 100644
--- a/entity/ObjectRelation_entity/ObjectRelation_entity.aod
+++ b/entity/ObjectRelation_entity/ObjectRelation_entity.aod
@@ -13,6 +13,7 @@
       <name>OBJECT1_TYPE</name>
       <title>Type 1</title>
       <consumer>Contexts</consumer>
+      <linkedContextProcess>%aditoprj%/entity/ObjectRelation_entity/entityfields/object1_type/linkedContextProcess.js</linkedContextProcess>
       <stateProcess>%aditoprj%/entity/ObjectRelation_entity/entityfields/object1_type/stateProcess.js</stateProcess>
       <valueProcess>%aditoprj%/entity/ObjectRelation_entity/entityfields/object1_type/valueProcess.js</valueProcess>
       <displayValueProcess>%aditoprj%/entity/ObjectRelation_entity/entityfields/object1_type/displayValueProcess.js</displayValueProcess>
@@ -20,6 +21,7 @@
     <entityField>
       <name>OBJECT1_ROWID</name>
       <title>Object 1</title>
+      <consumer>Objects1</consumer>
       <linkedContextProcess>%aditoprj%/entity/ObjectRelation_entity/entityfields/object1_rowid/linkedContextProcess.js</linkedContextProcess>
     </entityField>
     <entityField>
@@ -28,6 +30,7 @@
     <entityField>
       <name>OBJECT2_ROWID</name>
       <title>Object 2</title>
+      <consumer>Objects2</consumer>
       <linkedContextProcess>%aditoprj%/entity/ObjectRelation_entity/entityfields/object2_rowid/linkedContextProcess.js</linkedContextProcess>
     </entityField>
     <entityField>
@@ -182,6 +185,8 @@
     <entityProvider>
       <name>AnyObject</name>
       <fieldType>DEPENDENCY_IN</fieldType>
+      <targetContextField>OBJECT1_TYPE</targetContextField>
+      <targetIdField>OBJECT1_ROWID</targetIdField>
       <recordContainer>db</recordContainer>
       <dependencies>
         <entityDependency>
@@ -245,6 +250,36 @@
         <fieldName>#PROVIDER</fieldName>
       </dependency>
     </entityConsumer>
+    <entityConsumer>
+      <name>Objects1</name>
+      <fieldType>DEPENDENCY_OUT</fieldType>
+      <dependency>
+        <name>dependency</name>
+        <entityName>Object_entity</entityName>
+        <fieldName>AllObjects</fieldName>
+      </dependency>
+      <children>
+        <entityParameter>
+          <name>ObjectType_param</name>
+          <code>%aditoprj%/entity/ObjectRelation_entity/entityfields/objects1/children/objecttype_param/code.js</code>
+        </entityParameter>
+      </children>
+    </entityConsumer>
+    <entityConsumer>
+      <name>Objects2</name>
+      <fieldType>DEPENDENCY_OUT</fieldType>
+      <dependency>
+        <name>dependency</name>
+        <entityName>Object_entity</entityName>
+        <fieldName>AllObjects</fieldName>
+      </dependency>
+      <children>
+        <entityParameter>
+          <name>ObjectType_param</name>
+          <code>%aditoprj%/entity/ObjectRelation_entity/entityfields/objects2/children/objecttype_param/code.js</code>
+        </entityParameter>
+      </children>
+    </entityConsumer>
   </entityFields>
   <recordContainers>
     <dbRecordContainer>
diff --git a/entity/ObjectRelation_entity/entityfields/object1_type/linkedContextProcess.js b/entity/ObjectRelation_entity/entityfields/object1_type/linkedContextProcess.js
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/entity/ObjectRelation_entity/entityfields/objects1/children/objecttype_param/code.js b/entity/ObjectRelation_entity/entityfields/objects1/children/objecttype_param/code.js
new file mode 100644
index 0000000000..b3edc8d512
--- /dev/null
+++ b/entity/ObjectRelation_entity/entityfields/objects1/children/objecttype_param/code.js
@@ -0,0 +1,6 @@
+import("system.logging");
+import("system.vars");
+import("system.result");
+
+logging.log("type: " + vars.get("$field.OBJECT1_TYPE"))
+result.string(vars.get("$field.OBJECT1_TYPE"))
\ No newline at end of file
diff --git a/entity/ObjectRelation_entity/entityfields/objects2/children/objecttype_param/code.js b/entity/ObjectRelation_entity/entityfields/objects2/children/objecttype_param/code.js
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/entity/Object_entity/recordcontainers/jdito/contentProcess.js b/entity/Object_entity/recordcontainers/jdito/contentProcess.js
index 261298d705..ddef820042 100644
--- a/entity/Object_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/Object_entity/recordcontainers/jdito/contentProcess.js
@@ -1,5 +1,16 @@
+import("system.db");
+import("system.vars");
+import("system.logging");
 import("system.result");
 import("Context_lib");
+logging.log("huuihuihihi");
 
-// TODO: no subselect?
-result.string(ContextUtils.getNameSubselectSql("OBJECT2_TYPE", "OBJECT2_ROWID"))
\ No newline at end of file
+if (vars.exists("$param.ObjectType_param"))
+{
+    if (vars.exists("$param.ObjectRowId_param"))
+    {
+        result.object(db.table(vars.get("$param.ObjectRowId_param"), ContextUtils.getContextDataSql(vars.get("$param.ObjectType_param"), vars.get("$param.ObjectRowId_param"))));
+    }
+    result.object(db.table(ContextUtils.getContextDataSql(vars.get("$param.ObjectType_param"))))
+}
+result.object([]);
\ No newline at end of file
diff --git a/neonContext/Object_context/Object_context.aod b/neonContext/Object_context/Object_context.aod
index c1da8f8e6f..c09553d8af 100644
--- a/neonContext/Object_context/Object_context.aod
+++ b/neonContext/Object_context/Object_context.aod
@@ -2,5 +2,12 @@
 <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>Object_context</name>
   <majorModelMode>DISTRIBUTED</majorModelMode>
+  <lookupview>ObjectLookup_view</lookupview>
   <entity>Object_entity</entity>
+  <references>
+    <neonViewReference>
+      <name>a9193747-07f9-41f4-8bea-97c46e20bd05</name>
+      <view>ObjectLookup_view</view>
+    </neonViewReference>
+  </references>
 </neonContext>
diff --git a/neonView/ContactMain_view/ContactMain_view.aod b/neonView/ContactMain_view/ContactMain_view.aod
index ceab7df984..ecebeb9bb8 100644
--- a/neonView/ContactMain_view/ContactMain_view.aod
+++ b/neonView/ContactMain_view/ContactMain_view.aod
@@ -16,22 +16,22 @@
     </neonViewReference>
     <neonViewReference>
       <name>d674b32c-0493-47ea-a51f-dff5d13d237d</name>
-      <entityField>PersActivity_dfo</entityField>
+      <entityField>Activities</entityField>
       <view>ActivityFilter_view</view>
     </neonViewReference>
     <neonViewReference>
       <name>4b50b784-484f-4cdf-a705-4c356da763fa</name>
-      <entityField>PersDocument_dfo</entityField>
+      <entityField>Documents</entityField>
       <view>DocumentFilter_view</view>
     </neonViewReference>
     <neonViewReference>
       <name>ec344a07-7b82-4c54-b06b-30ac5b8599f9</name>
-      <entityField>PersContract_dfo</entityField>
+      <entityField>Contracts</entityField>
       <view>ContractFilter_view</view>
     </neonViewReference>
     <neonViewReference>
       <name>726f10a6-dad6-4325-a73e-2d6caf0340db</name>
-      <entityField>ObjectRelation_dfo</entityField>
+      <entityField>ObjectRelations</entityField>
       <view>ObjectRelationFilter_view</view>
     </neonViewReference>
   </children>
diff --git a/neonView/ObjectLookup_view/ObjectLookup_view.aod b/neonView/ObjectLookup_view/ObjectLookup_view.aod
new file mode 100644
index 0000000000..b6116c46e2
--- /dev/null
+++ b/neonView/ObjectLookup_view/ObjectLookup_view.aod
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<neonView xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.0.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.0.1">
+  <name>ObjectLookup_view</name>
+  <majorModelMode>DISTRIBUTED</majorModelMode>
+  <layout>
+    <boxLayout>
+      <name>layout</name>
+    </boxLayout>
+  </layout>
+  <children>
+    <tableViewTemplate>
+      <name>objects</name>
+      <entityField>#ENTITY</entityField>
+      <columns>
+        <neonTableColumn>
+          <name>f131a39f-a3fe-42a6-b5df-65e12ae9eea7</name>
+          <entityField>TITLE</entityField>
+        </neonTableColumn>
+      </columns>
+    </tableViewTemplate>
+  </children>
+</neonView>
diff --git a/process/Context_lib/process.js b/process/Context_lib/process.js
index 816a7bb13e..0ee031cecc 100644
--- a/process/Context_lib/process.js
+++ b/process/Context_lib/process.js
@@ -57,8 +57,8 @@ ContextUtils._getSelectMap = function()
     var maskingUtils = new SqlMaskingUtils();
     return {
           // contextId   nameField  Tablename, IDField
-        "Org_context": ["\"NAME\"", "ORG", "ORGID"],
-        "Pers_context": [maskingUtils.concat(["FIRSTNAME", "LASTNAME"]), "PERS", "PERSID"],
+        "Organisation_context": ["\"NAME\"", "ORG", "ORGID"],
+        "Contact_context": [maskingUtils.concat(["FIRSTNAME", "LASTNAME"]), "PERS", "PERSID"],
         "Activity_context": ["SUBJECT", "ACTIVITY", "ACTIVITYID"],
         "Salesproject_context": [maskingUtils.concat([maskingUtils.cast("PROJECTCODE", SQLTYPES.VARCHAR, 10), "':'", "PROJECTTITLE"]), "SALESPROJECT", "SALESPROJECTID"],
         // TODO: keywords sind noch nicht in der DB somit gibt es nichts ähnliches zu getKeySQL.
@@ -74,11 +74,10 @@ ContextUtils.getNameSubselectSql = function(pContextIdDbField, pRowIdDbField)
 {
     var select = "(case " + pContextIdDbField + " ";
     
-    
     var selectMap = ContextUtils._getSelectMap()
     for (let contextId in selectMap) 
     {
-        select += "when '" + contextId + "' then (select " + selectMap[contextId][0] + " from " + selectMap[contextId][1] + " where " + selectMap[contextId][2] + " = " + pRowIdDbField + ") ";
+        select += "when '" + contextId + "' then (select " + selectMap[contextId][0] + " from " + selectMap[contextId][1] + (pRowIdDbField ? " where " + selectMap[contextId][2] + " = " + pRowIdDbField : " ") + ") ";
     }
     
     select += "else 'Not defined in ContextUtils.getNameSql()!'";
@@ -102,5 +101,11 @@ ContextUtils.getNameSql = function(pContextId, pRowId)
 ContextUtils.getContextDataSql = function(pContextId, pRowId)
 {
     var selectMap = ContextUtils._getSelectMap()
-    return SqlCondition.begin().andPrepare(selectMap[pContextId][1] + "." + selectMap[pContextId][2], pRowId).buildSql("select " + selectMap[contextId][2] + ", " + selectMap[contextId][0] + " from " + selectMap[contextId][1], "1=1");
+    var cond = SqlCondition.begin();
+    if (pRowId)
+    {
+        cond.andPrepare(selectMap[pContextId][1] + "." + selectMap[pContextId][2], pRowId)
+    }
+    
+    return cond.buildSql("select " + selectMap[pContextId][2] + ", " + selectMap[pContextId][0] + " from " + selectMap[pContextId][1], "1=1");
 }
\ No newline at end of file
-- 
GitLab