From c04dec672aa45d7e7f64cf0ee4d45f08709815b2 Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Tue, 12 Mar 2019 16:41:38 +0100
Subject: [PATCH] ObjectRelationType Entity

---
 .../ObjectRelationType_entity.aod             | 57 +++++--------------
 .../valueProcess.js                           |  0
 .../recordcontainers/db/conditionProcess.js   | 11 ----
 .../recordcontainers/db/fromClauseProcess.js  |  2 -
 .../expression.js                             |  3 -
 .../object_title.value/expression.js          |  3 -
 .../object_type.value/expression.js           |  3 -
 .../relation_type.value/expression.js         |  3 -
 .../recordcontainers/jdito/contentProcess.js  | 15 +++++
 .../ObjectRelationType_entity/titleProcess.js |  2 +-
 .../ObjectRelation_entity.aod                 |  4 +-
 .../_____LANGUAGE_EXTRA.aod                   |  6 ++
 .../ObjectRelationType/ObjectRelationType.aod |  6 ++
 .../OrganisationMain_view.aod                 | 10 ++--
 process/Context_lib/process.js                |  5 +-
 15 files changed, 52 insertions(+), 78 deletions(-)
 rename entity/ObjectRelationType_entity/entityfields/{ab_objectrelationtypeid => uid}/valueProcess.js (100%)
 delete mode 100644 entity/ObjectRelationType_entity/recordcontainers/db/conditionProcess.js
 delete mode 100644 entity/ObjectRelationType_entity/recordcontainers/db/fromClauseProcess.js
 delete mode 100644 entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/ab_objectrelationtypeid.value/expression.js
 delete mode 100644 entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/object_title.value/expression.js
 delete mode 100644 entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/object_type.value/expression.js
 delete mode 100644 entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/relation_type.value/expression.js
 create mode 100644 entity/ObjectRelationType_entity/recordcontainers/jdito/contentProcess.js
 create mode 100644 neonContext/ObjectRelationType/ObjectRelationType.aod

diff --git a/entity/ObjectRelationType_entity/ObjectRelationType_entity.aod b/entity/ObjectRelationType_entity/ObjectRelationType_entity.aod
index 76af46ad0b..81940835e0 100644
--- a/entity/ObjectRelationType_entity/ObjectRelationType_entity.aod
+++ b/entity/ObjectRelationType_entity/ObjectRelationType_entity.aod
@@ -3,7 +3,7 @@
   <name>ObjectRelationType_entity</name>
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <titleProcess>%aditoprj%/entity/ObjectRelationType_entity/titleProcess.js</titleProcess>
-  <recordContainer>db</recordContainer>
+  <recordContainer>jdito</recordContainer>
   <entityFields>
     <entityProvider>
       <name>#PROVIDER</name>
@@ -17,15 +17,11 @@
       </dependencies>
     </entityProvider>
     <entityField>
-      <name>AB_OBJECTRELATIONTYPEID</name>
-      <valueProcess>%aditoprj%/entity/ObjectRelationType_entity/entityfields/ab_objectrelationtypeid/valueProcess.js</valueProcess>
+      <name>UID</name>
+      <valueProcess>%aditoprj%/entity/ObjectRelationType_entity/entityfields/uid/valueProcess.js</valueProcess>
     </entityField>
     <entityField>
-      <name>OBJECT_TYPE</name>
-      <mandatory v="true" />
-    </entityField>
-    <entityField>
-      <name>OBJECT_TITLE</name>
+      <name>RELATION_TITLE</name>
     </entityField>
     <entityParameter>
       <name>SourceObjectType_param</name>
@@ -43,43 +39,16 @@
         </entityParameter>
       </children>
     </entityProvider>
-    <entityField>
-      <name>RELATION_TYPE</name>
-    </entityField>
   </entityFields>
   <recordContainers>
-    <dbRecordContainer>
-      <name>db</name>
-      <alias>Data_alias</alias>
-      <fromClauseProcess>%aditoprj%/entity/ObjectRelationType_entity/recordcontainers/db/fromClauseProcess.js</fromClauseProcess>
-      <conditionProcess>%aditoprj%/entity/ObjectRelationType_entity/recordcontainers/db/conditionProcess.js</conditionProcess>
-      <linkInformation>
-        <linkInformation>
-          <name>7399a9d5-2e0f-497b-a7db-d14d7ae09965</name>
-          <tableName>AB_OBJECTRELATIONTYPE</tableName>
-          <primaryKey>AB_OBJECTRELATIONTYPEID</primaryKey>
-          <isUIDTable v="true" />
-          <readonly v="false" />
-        </linkInformation>
-      </linkInformation>
-      <recordFieldMappings>
-        <dbRecordFieldMapping>
-          <name>OBJECT_TYPE.value</name>
-          <expression>%aditoprj%/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/object_type.value/expression.js</expression>
-        </dbRecordFieldMapping>
-        <dbRecordFieldMapping>
-          <name>AB_OBJECTRELATIONTYPEID.value</name>
-          <expression>%aditoprj%/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/ab_objectrelationtypeid.value/expression.js</expression>
-        </dbRecordFieldMapping>
-        <dbRecordFieldMapping>
-          <name>OBJECT_TITLE.value</name>
-          <expression>%aditoprj%/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/object_title.value/expression.js</expression>
-        </dbRecordFieldMapping>
-        <dbRecordFieldMapping>
-          <name>RELATION_TYPE.value</name>
-          <expression>%aditoprj%/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/relation_type.value/expression.js</expression>
-        </dbRecordFieldMapping>
-      </recordFieldMappings>
-    </dbRecordContainer>
+    <jDitoRecordContainer>
+      <name>jdito</name>
+      <jDitoRecordAlias>Data_alias</jDitoRecordAlias>
+      <contentProcess>%aditoprj%/entity/ObjectRelationType_entity/recordcontainers/jdito/contentProcess.js</contentProcess>
+      <recordFields>
+        <element>UID.value</element>
+        <element>RELATION_TITLE.value</element>
+      </recordFields>
+    </jDitoRecordContainer>
   </recordContainers>
 </entity>
diff --git a/entity/ObjectRelationType_entity/entityfields/ab_objectrelationtypeid/valueProcess.js b/entity/ObjectRelationType_entity/entityfields/uid/valueProcess.js
similarity index 100%
rename from entity/ObjectRelationType_entity/entityfields/ab_objectrelationtypeid/valueProcess.js
rename to entity/ObjectRelationType_entity/entityfields/uid/valueProcess.js
diff --git a/entity/ObjectRelationType_entity/recordcontainers/db/conditionProcess.js b/entity/ObjectRelationType_entity/recordcontainers/db/conditionProcess.js
deleted file mode 100644
index 6988e47755..0000000000
--- a/entity/ObjectRelationType_entity/recordcontainers/db/conditionProcess.js
+++ /dev/null
@@ -1,11 +0,0 @@
-import("system.logging");
-import("system.vars");
-import("system.db");
-import("system.result");
-import("Sql_lib");
-
-
-logging.log(vars.getString("$param.SourceObjectType_param"))
-
-// TODO: SQL Condition
-result.string("'" + vars.getString("$param.SourceObjectType_param") + "' = type2 where type2.AB_OBJECTRELATIONTYPEID <> type1.AB_OBJECTRELATIONTYPEID and type2.RELATION_TYPE = type1.RELATION_TYPE)");
\ No newline at end of file
diff --git a/entity/ObjectRelationType_entity/recordcontainers/db/fromClauseProcess.js b/entity/ObjectRelationType_entity/recordcontainers/db/fromClauseProcess.js
deleted file mode 100644
index 82b8e7888e..0000000000
--- a/entity/ObjectRelationType_entity/recordcontainers/db/fromClauseProcess.js
+++ /dev/null
@@ -1,2 +0,0 @@
-import("system.result");
-result.string("AB_OBJECTRELATIONTYPEID type1")
\ No newline at end of file
diff --git a/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/ab_objectrelationtypeid.value/expression.js b/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/ab_objectrelationtypeid.value/expression.js
deleted file mode 100644
index abc68c28f3..0000000000
--- a/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/ab_objectrelationtypeid.value/expression.js
+++ /dev/null
@@ -1,3 +0,0 @@
-import("system.result");
-
-result.string("type1.AB_OBJECTRELATIONTYPEID");
\ No newline at end of file
diff --git a/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/object_title.value/expression.js b/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/object_title.value/expression.js
deleted file mode 100644
index 7f29eafac8..0000000000
--- a/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/object_title.value/expression.js
+++ /dev/null
@@ -1,3 +0,0 @@
-import("system.result");
-
-result.string("type1.RELATION_TITLE");
\ No newline at end of file
diff --git a/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/object_type.value/expression.js b/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/object_type.value/expression.js
deleted file mode 100644
index e5b18cf002..0000000000
--- a/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/object_type.value/expression.js
+++ /dev/null
@@ -1,3 +0,0 @@
-import("system.result");
-
-result.string("type1.OBJECT_TYPE");
\ No newline at end of file
diff --git a/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/relation_type.value/expression.js b/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/relation_type.value/expression.js
deleted file mode 100644
index fb8d3359a7..0000000000
--- a/entity/ObjectRelationType_entity/recordcontainers/db/recordfieldmappings/relation_type.value/expression.js
+++ /dev/null
@@ -1,3 +0,0 @@
-import("system.result");
-
-result.string("type1.RELATION_TYPE");
\ No newline at end of file
diff --git a/entity/ObjectRelationType_entity/recordcontainers/jdito/contentProcess.js b/entity/ObjectRelationType_entity/recordcontainers/jdito/contentProcess.js
new file mode 100644
index 0000000000..94dea6f21f
--- /dev/null
+++ b/entity/ObjectRelationType_entity/recordcontainers/jdito/contentProcess.js
@@ -0,0 +1,15 @@
+import("system.logging");
+import("system.translate");
+import("system.db");
+import("system.result");
+import("system.vars");
+logging.log(vars.get("$param.SourceObjectType_param"))
+result.object(db.table(
+["select main.AB_OBJECTRELATIONTYPEID, main.RELATION_TITLE \n\
+    from AB_OBJECTRELATIONTYPE main \n\
+    left join AB_OBJECTRELATIONTYPE type2 on (type2.AB_OBJECTRELATIONTYPEID <> main.AB_OBJECTRELATIONTYPEID and type2.RELATION_TYPE = main.RELATION_TYPE) \n\
+    where case when type2.OBJECT_TYPE is null then ( ? = main.OBJECT_TYPE) else ( ? = type2.OBJECT_TYPE) end"
+, [
+  [vars.get("$param.SourceObjectType_param"), db.getColumnTypes("AB_OBJECTRELATIONTYPE", ["OBJECT_TYPE"])[0]],
+  [vars.get("$param.SourceObjectType_param"), db.getColumnTypes("AB_OBJECTRELATIONTYPE", ["OBJECT_TYPE"])[0]],
+]]));
\ No newline at end of file
diff --git a/entity/ObjectRelationType_entity/titleProcess.js b/entity/ObjectRelationType_entity/titleProcess.js
index 91cc98796b..6a95b85f75 100644
--- a/entity/ObjectRelationType_entity/titleProcess.js
+++ b/entity/ObjectRelationType_entity/titleProcess.js
@@ -1,4 +1,4 @@
 import("system.vars");
 import("system.result");
 
-result.string(vars.get("$field.OBJECT_TITLE"))
\ No newline at end of file
+result.string(vars.get("$field.RELATION_TITLE"))
\ No newline at end of file
diff --git a/entity/ObjectRelation_entity/ObjectRelation_entity.aod b/entity/ObjectRelation_entity/ObjectRelation_entity.aod
index fa4333e876..55c98e2e08 100644
--- a/entity/ObjectRelation_entity/ObjectRelation_entity.aod
+++ b/entity/ObjectRelation_entity/ObjectRelation_entity.aod
@@ -124,14 +124,14 @@
     </entityParameter>
     <entityField>
       <name>selectedObjectRelationTypeIdProxy</name>
-      <title>Relation type</title>
+      <title>Relationtype</title>
       <possibleItemsProcess>%aditoprj%/entity/ObjectRelation_entity/entityfields/selectedobjectrelationtypeidproxy/possibleItemsProcess.js</possibleItemsProcess>
       <valueProcess>%aditoprj%/entity/ObjectRelation_entity/entityfields/selectedobjectrelationtypeidproxy/valueProcess.js</valueProcess>
       <onValueChange>%aditoprj%/entity/ObjectRelation_entity/entityfields/selectedobjectrelationtypeidproxy/onValueChange.js</onValueChange>
     </entityField>
     <entityField>
       <name>relationTypeProxy</name>
-      <title>Relation type</title>
+      <title>Relationtype</title>
       <valueProcess>%aditoprj%/entity/ObjectRelation_entity/entityfields/relationtypeproxy/valueProcess.js</valueProcess>
     </entityField>
     <entityField>
diff --git a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
index 313e1665a1..e4ca214b20 100644
--- a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
+++ b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
@@ -2556,6 +2556,12 @@
     <entry>
       <key>New attribute</key>
     </entry>
+    <entry>
+      <key>MQC</key>
+    </entry>
+    <entry>
+      <key>Relation type</key>
+    </entry>
   </keyValueMap>
   <font name="Dialog" style="0" size="11" />
   <sqlModels>
diff --git a/neonContext/ObjectRelationType/ObjectRelationType.aod b/neonContext/ObjectRelationType/ObjectRelationType.aod
new file mode 100644
index 0000000000..f53678bffa
--- /dev/null
+++ b/neonContext/ObjectRelationType/ObjectRelationType.aod
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>ObjectRelationType</name>
+  <majorModelMode>DISTRIBUTED</majorModelMode>
+  <entity>ObjectRelationType_entity</entity>
+</neonContext>
diff --git a/neonView/OrganisationMain_view/OrganisationMain_view.aod b/neonView/OrganisationMain_view/OrganisationMain_view.aod
index 57893f5b20..b708d1e0bf 100644
--- a/neonView/OrganisationMain_view/OrganisationMain_view.aod
+++ b/neonView/OrganisationMain_view/OrganisationMain_view.aod
@@ -40,6 +40,11 @@
       <entityField>Contracts</entityField>
       <view>ContractFilter_view</view>
     </neonViewReference>
+    <neonViewReference>
+      <name>ab7d3db4-af9d-4903-b28a-6347f2512a54</name>
+      <entityField>ObjectRelations</entityField>
+      <view>ObjectRelationFilter_view</view>
+    </neonViewReference>
     <neonViewReference>
       <name>39c98ccb-7f77-4df0-818f-1f302f69fec4</name>
       <entityField>Attributes</entityField>
@@ -50,10 +55,5 @@
       <entityField>Salesprojects</entityField>
       <view>SalesprojectFilter_view</view>
     </neonViewReference>
-    <neonViewReference>
-      <name>ab7d3db4-af9d-4903-b28a-6347f2512a54</name>
-      <entityField>ObjectRelations</entityField>
-      <view>ObjectRelationFilter_view</view>
-    </neonViewReference>
   </children>
 </neonView>
diff --git a/process/Context_lib/process.js b/process/Context_lib/process.js
index a2480fc343..b0c76ff639 100644
--- a/process/Context_lib/process.js
+++ b/process/Context_lib/process.js
@@ -156,7 +156,10 @@ ContextUtils.getNameSubselectSql = function(pContextIdDbField, pRowIdDbField)
 ContextUtils.getNameSql = function(pContextId, pRowId)
 {
     var selectMap = ContextUtils._getSelectMap()
-    return SqlCondition.begin().andPrepare(selectMap[pContextId][1] + "." + selectMap[pContextId][2], pRowId).buildSql("select " + selectMap[pContextId][0] + " from " + selectMap[pContextId][1], "1=2");
+    if (selectMap[pContextId] != undefined)
+        return SqlCondition.begin().andPrepare(selectMap[pContextId][1] + "." + selectMap[pContextId][2], pRowId).buildSql("select " + selectMap[pContextId][0] + " from " + selectMap[pContextId][1], "1=2");
+    else
+        return "select 1 from person where 1=2";
 }
 
 /**
-- 
GitLab