From 188f47c27d69da94569625b882675735832c328a Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Mon, 8 Apr 2019 14:42:09 +0200
Subject: [PATCH] objectRelation tree - Update

---
 entity/Address_entity/Address_entity.aod      |  1 -
 .../contactid_param/valueProcess.js           |  0
 .../recordcontainers/jdito/onDelete.js        |  4 +-
 .../ObjectTree_entity/ObjectTree_entity.aod   | 26 ++++++-
 .../alter/children/edit/onActionProcess.js    | 18 +++++
 .../displayValueProcess.js                    |  1 +
 .../objectrelationtypeid/stateProcess.js      |  2 +-
 .../target_id/displayValueProcess.js          | 10 +++
 .../target_id/linkedContextProcess.js         |  8 +++
 .../entityfields/target_id/stateProcess.js    | 12 ++++
 .../recordcontainers/jdito/contentProcess.js  | 72 +++++++++++++------
 .../recordcontainers/jdito/onUpdate.js        | 18 +++++
 entity/Object_entity/Object_entity.aod        |  6 --
 .../Organisation_entity.aod                   | 12 ----
 neonContext/ObjectTree/ObjectTree.aod         |  5 ++
 .../ObjectTreePreview/ObjectTreePreview.aod   | 32 +++++++++
 process/ObjectRelation_lib/process.js         | 20 +++---
 17 files changed, 191 insertions(+), 56 deletions(-)
 delete mode 100644 entity/Address_entity/entityfields/contactid_param/valueProcess.js
 create mode 100644 entity/ObjectTree_entity/entityfields/alter/children/edit/onActionProcess.js
 create mode 100644 entity/ObjectTree_entity/entityfields/target_id/displayValueProcess.js
 create mode 100644 entity/ObjectTree_entity/entityfields/target_id/linkedContextProcess.js
 create mode 100644 entity/ObjectTree_entity/entityfields/target_id/stateProcess.js
 create mode 100644 entity/ObjectTree_entity/recordcontainers/jdito/onUpdate.js
 create mode 100644 neonView/ObjectTreePreview/ObjectTreePreview.aod

diff --git a/entity/Address_entity/Address_entity.aod b/entity/Address_entity/Address_entity.aod
index 76217f3083a..df8385fa8fb 100644
--- a/entity/Address_entity/Address_entity.aod
+++ b/entity/Address_entity/Address_entity.aod
@@ -105,7 +105,6 @@
     </entityProvider>
     <entityParameter>
       <name>ContactId_param</name>
-      <valueProcess>%aditoprj%/entity/Address_entity/entityfields/contactid_param/valueProcess.js</valueProcess>
       <expose v="true" />
       <mandatory v="true" />
       <documentation>%aditoprj%/entity/Address_entity/entityfields/contactid_param/documentation.adoc</documentation>
diff --git a/entity/Address_entity/entityfields/contactid_param/valueProcess.js b/entity/Address_entity/entityfields/contactid_param/valueProcess.js
deleted file mode 100644
index e69de29bb2d..00000000000
diff --git a/entity/Attribute_entity/recordcontainers/jdito/onDelete.js b/entity/Attribute_entity/recordcontainers/jdito/onDelete.js
index 61929ba31c9..046b1dca18f 100644
--- a/entity/Attribute_entity/recordcontainers/jdito/onDelete.js
+++ b/entity/Attribute_entity/recordcontainers/jdito/onDelete.js
@@ -7,13 +7,13 @@ var condition = SqlCondition.begin()
     .andPrepareVars("AB_ATTRIBUTE.AB_ATTRIBUTEID", "$field.UID")
     .build("1=2");
 
-db.deleteData("AB_ATTRIBUTE", conditon);
+db.deleteData("AB_ATTRIBUTE", condition);
 
 var attributeId = vars.get("$field.UID");
 
 var childIds = AttributeUtil.getAllChildren(attributeId).concat(attributeId);
 
-var condition = SqlCondition.begin()
+condition = SqlCondition.begin()
     .and("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID in ('" + childIds.join("','") + "')")
     .build();
 
diff --git a/entity/ObjectTree_entity/ObjectTree_entity.aod b/entity/ObjectTree_entity/ObjectTree_entity.aod
index 1be26c1bbfc..9effca076ad 100644
--- a/entity/ObjectTree_entity/ObjectTree_entity.aod
+++ b/entity/ObjectTree_entity/ObjectTree_entity.aod
@@ -11,8 +11,6 @@
     <entityProvider>
       <name>TreeProvider</name>
       <fieldType>DEPENDENCY_IN</fieldType>
-      <targetContextField>TARGET_CONTEXT</targetContextField>
-      <targetIdField>TARGET_ID</targetIdField>
       <dependencies>
         <entityDependency>
           <name>f4c0605f-3ccb-4ff1-b460-7268e8553857</name>
@@ -42,6 +40,10 @@
           <name>RelationType_param</name>
           <expose v="false" />
         </entityParameter>
+        <entityParameter>
+          <name>Uid_param</name>
+          <expose v="false" />
+        </entityParameter>
       </children>
     </entityProvider>
     <entityParameter>
@@ -61,10 +63,12 @@
     </entityField>
     <entityField>
       <name>TITLE</name>
+      <title>Object</title>
       <searchable v="false" />
     </entityField>
     <entityField>
       <name>ICON</name>
+      <contentType>IMAGE</contentType>
       <searchable v="false" />
       <valueProcess>%aditoprj%/entity/ObjectTree_entity/entityfields/icon/valueProcess.js</valueProcess>
     </entityField>
@@ -99,8 +103,12 @@
     </entityField>
     <entityField>
       <name>TARGET_ID</name>
+      <title>Object</title>
       <consumer>Objects</consumer>
+      <linkedContextProcess>%aditoprj%/entity/ObjectTree_entity/entityfields/target_id/linkedContextProcess.js</linkedContextProcess>
       <searchable v="false" />
+      <stateProcess>%aditoprj%/entity/ObjectTree_entity/entityfields/target_id/stateProcess.js</stateProcess>
+      <displayValueProcess>%aditoprj%/entity/ObjectTree_entity/entityfields/target_id/displayValueProcess.js</displayValueProcess>
     </entityField>
     <entityField>
       <name>TARGET_CONTEXT</name>
@@ -110,6 +118,7 @@
     <entityField>
       <name>INFO</name>
       <title>Description</title>
+      <contentType>LONG_TEXT</contentType>
       <searchable v="false" />
     </entityField>
     <entityField>
@@ -152,6 +161,13 @@
           <isSelectionAction v="true" />
           <iconId>VAADIN:FILE_TREE_SMALL</iconId>
         </entityActionField>
+        <entityActionField>
+          <name>edit</name>
+          <fieldType>ACTION</fieldType>
+          <onActionProcess>%aditoprj%/entity/ObjectTree_entity/entityfields/alter/children/edit/onActionProcess.js</onActionProcess>
+          <isSelectionAction v="true" />
+          <iconId>NEON:PENCIL</iconId>
+        </entityActionField>
       </children>
     </entityActionGroup>
     <entityParameter>
@@ -159,6 +175,11 @@
       <expose v="true" />
       <description>PARAMETER</description>
     </entityParameter>
+    <entityParameter>
+      <name>Uid_param</name>
+      <expose v="true" />
+      <description>Needed to load ONE Objectrelation together with ObjectId_param and ObjectType_param to determine the side</description>
+    </entityParameter>
   </entityFields>
   <recordContainers>
     <jDitoRecordContainer>
@@ -166,6 +187,7 @@
       <jDitoRecordAlias>Data_alias</jDitoRecordAlias>
       <contentProcess>%aditoprj%/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js</contentProcess>
       <onInsert>%aditoprj%/entity/ObjectTree_entity/recordcontainers/jdito/onInsert.js</onInsert>
+      <onUpdate>%aditoprj%/entity/ObjectTree_entity/recordcontainers/jdito/onUpdate.js</onUpdate>
       <onDelete>%aditoprj%/entity/ObjectTree_entity/recordcontainers/jdito/onDelete.js</onDelete>
       <recordFields>
         <element>UID.value</element>
diff --git a/entity/ObjectTree_entity/entityfields/alter/children/edit/onActionProcess.js b/entity/ObjectTree_entity/entityfields/alter/children/edit/onActionProcess.js
new file mode 100644
index 00000000000..8cbab647793
--- /dev/null
+++ b/entity/ObjectTree_entity/entityfields/alter/children/edit/onActionProcess.js
@@ -0,0 +1,18 @@
+import("ObjectRelation_lib");
+import("system.neon");
+import("system.vars");
+
+if (vars.exists("$local.rows") && vars.get("$local.rows"))
+{
+    var selectedRows = JSON.parse(vars.get("$local.rows"));
+    var uid = JSON.parse(selectedRows[0]["#LOOKUPID"]);
+    var isObjectRelationNode = typeof uid[2] == "string";
+        
+    if (isObjectRelationNode)
+    {
+        var params = {
+            "Uid_param" : selectedRows[0]["#LOOKUPID"]
+        }
+        neon.openContext("ObjectTree", "ObjectTreeEdit_view", null, neon.OPERATINGSTATE_EDIT, params);
+    }
+}
\ No newline at end of file
diff --git a/entity/ObjectTree_entity/entityfields/objectrelationtypeid/displayValueProcess.js b/entity/ObjectTree_entity/entityfields/objectrelationtypeid/displayValueProcess.js
index 83a799bf342..e4ddc9dc597 100644
--- a/entity/ObjectTree_entity/entityfields/objectrelationtypeid/displayValueProcess.js
+++ b/entity/ObjectTree_entity/entityfields/objectrelationtypeid/displayValueProcess.js
@@ -1,3 +1,4 @@
+import("system.neon");
 import("system.translate");
 import("system.result");
 import("system.vars");
diff --git a/entity/ObjectTree_entity/entityfields/objectrelationtypeid/stateProcess.js b/entity/ObjectTree_entity/entityfields/objectrelationtypeid/stateProcess.js
index 7c27f2f690b..7d9ab38c5c7 100644
--- a/entity/ObjectTree_entity/entityfields/objectrelationtypeid/stateProcess.js
+++ b/entity/ObjectTree_entity/entityfields/objectrelationtypeid/stateProcess.js
@@ -2,7 +2,7 @@ import("system.result");
 import("system.vars");
 import("system.neon");
 
-if (vars.exists("$param.RelationType_param") && vars.get("$param.RelationType_param"))
+if (vars.exists("$param.RelationType_param") && vars.get("$param.RelationType_param") || vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT)
 {
     result.string(neon.COMPONENTSTATE_DISABLED);
 }
diff --git a/entity/ObjectTree_entity/entityfields/target_id/displayValueProcess.js b/entity/ObjectTree_entity/entityfields/target_id/displayValueProcess.js
new file mode 100644
index 00000000000..d074689525f
--- /dev/null
+++ b/entity/ObjectTree_entity/entityfields/target_id/displayValueProcess.js
@@ -0,0 +1,10 @@
+import("system.db");
+import("system.result");
+import("system.neon");
+import("system.vars");
+import("Context_lib");
+
+if (vars.get("$field.TARGET_ID") && vars.get("$field.TARGET_CONTEXT"))
+{
+    result.string(db.cell(ContextUtils.getNameSql(vars.get("$field.TARGET_CONTEXT"), vars.get("$field.TARGET_ID"))));
+}
\ No newline at end of file
diff --git a/entity/ObjectTree_entity/entityfields/target_id/linkedContextProcess.js b/entity/ObjectTree_entity/entityfields/target_id/linkedContextProcess.js
new file mode 100644
index 00000000000..1309ba4e92d
--- /dev/null
+++ b/entity/ObjectTree_entity/entityfields/target_id/linkedContextProcess.js
@@ -0,0 +1,8 @@
+import("system.vars");
+import("system.result");
+import("Context_lib");
+
+if (vars.get("$field.TARGET_CONTEXT"))
+{
+    result.string(ContextUtils.getContextName(vars.get("$field.TARGET_CONTEXT")));
+}
diff --git a/entity/ObjectTree_entity/entityfields/target_id/stateProcess.js b/entity/ObjectTree_entity/entityfields/target_id/stateProcess.js
new file mode 100644
index 00000000000..432b555ce84
--- /dev/null
+++ b/entity/ObjectTree_entity/entityfields/target_id/stateProcess.js
@@ -0,0 +1,12 @@
+import("system.result");
+import("system.vars");
+import("system.neon");
+
+if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT)
+{
+    result.string(neon.COMPONENTSTATE_DISABLED);
+}
+else 
+{
+    result.string(neon.COMPONENTSTATE_AUTO);
+}
\ No newline at end of file
diff --git a/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js b/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js
index bc49795bd4c..797fe1f60a5 100644
--- a/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js
@@ -7,23 +7,45 @@ import("Context_lib");
 import("Sql_lib");
 
 var tree = []
-var filter = JSON.parse(vars.get("$local.filter"))
-var selectedRelationType = null;
 
-if (filter)
+// uidParam: if only one row should be loaded
+var uidParam;
+if (vars.exists("$param.Uid_param") && vars.get("$param.Uid_param"))
 {
-    if (filter.childs.length > 0)
+    uidParam = vars.get("$param.Uid_param");
+} 
+else if(vars.exists("$local.idvalues") && vars.get("$local.idvalues") && vars.get("$local.idvalues").length > 0)
+{
+    uidParam = vars.get("$local.idvalues")[0];
+}
+
+if (uidParam)
+{
+    let uid = JSON.parse(uidParam);
+    
+    let relationTypeData = ObjectRelationUtils.getRelationType(uid[2]);
+    _insertEntry(tree, _getEntryData(uid[0], relationTypeData[3], relationTypeData[7], relationTypeData[8], undefined, false, uid[6]), "", 0, uid[3], relationTypeData[10]);
+}
+else
+{
+    var filter = JSON.parse(vars.get("$local.filter"))
+    var selectedRelationType = null;
+
+    if (filter)
     {
-        selectedRelationType = filter.childs[0].value;
+        if (filter.childs.length > 0)
+        {
+            selectedRelationType = filter.childs[0].value;
+        }
     }
-}
-var originalObjectId = vars.get("$param.ObjectId_param");
+    var originalObjectId = vars.get("$param.ObjectId_param");
 
-_loadObjectRelationTree(originalObjectId, vars.get("$param.ObjectType_param"), selectedRelationType);
+    _loadObjectRelationTree(originalObjectId, vars.get("$param.ObjectType_param"), selectedRelationType);
+}
 
 result.object(tree);
 
-function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId, pNodeId, pLayer, pRelationTypeData)
+function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId, pNodeId, pLayer, pRelationTypeData, pObjectRelationId)
 {
     // prevent stack overflows
     if (pLayer > 30)
@@ -41,9 +63,14 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId,
     {
         if (pLayer == 0)
         {
-            if (pObjectRelationTypeId)
+            // load only one ObjectRelation (e.g. for edit mode)
+            if (pObjectRelationId)
+            {
+                
+            }
+            else if (pObjectRelationTypeId)
             {
-                var relationTypeData = ObjectRelationUtils.getRelationType(pObjectRelationTypeId);
+                let relationTypeData = ObjectRelationUtils.getRelationType(pObjectRelationTypeId);
                 
                 // if hirachy: get most top id else use the current currentObjectId
                 if (relationTypeData[4] == "1")
@@ -76,7 +103,7 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId,
                         let uid = [currentObjectId, i, relationTypes[i]];
                         tree.push([JSON.stringify(uid), translate.text(relationTypes[i][1]), JSON.stringify(pNodeId), true, null, null, "", relationTypes[i][0]]);
                         
-                        _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId, uid, pLayer+1, relationTypeData);
+                        _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId, uid, pLayer+1, relationTypes[i]);
                     }
                 }
             }
@@ -154,12 +181,13 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId,
  * @param {String} pDirection
  * @param {String} pRelationType1
  * @param {String} pRelationType2
- * @param {String} pPrevId Id of the previous node to exclude it
+ * @param {String} [pPrevId=undefined] Id of the previous node to exclude it
  * @param {Boolean} [pNoRecursion=false] if false: select for direction "same" the other direction, if result is empty.
+ * @param {Boolean} [pObjectRelationId=false] provide if only one special node is needed
  * 
  * @return {[][]}
  */
-function _getEntryData(pObjectId, pDirection, pRelationType1, pRelationType2, pPrevId, pNoRecursion)
+function _getEntryData(pObjectId, pDirection, pRelationType1, pRelationType2, pPrevId, pNoRecursion, pObjectRelationId)
 {
     if (pRelationType1 == undefined || pRelationType2 == undefined) 
         return [];
@@ -181,7 +209,8 @@ function _getEntryData(pObjectId, pDirection, pRelationType1, pRelationType2, pP
     var cond = SqlCondition.begin()
                            .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pRelationType1)
                            .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pRelationType2)
-                           .andPrepare("AB_OBJECTRELATION.OBJECT" + myNum + "_ROWID", pObjectId);
+                           .andPrepare("AB_OBJECTRELATION.OBJECT" + myNum + "_ROWID", pObjectId)
+                           .andPrepareIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", pObjectRelationId);
     
     // exclude previous node
     if (!pPrevId)
@@ -193,17 +222,16 @@ function _getEntryData(pObjectId, pDirection, pRelationType1, pRelationType2, pP
         
     // TODO: BINDATA?
     // var image = getImageObject("Beziehung");
-
     var data = db.table(cond.buildSql(
-                "select OBJECT" + otherNum + "_ROWID, AB_OBJECTRELATIONID, OBJECT_TYPE, RELATION_TITLE, INFO, AB_OBJECTRELATIONTYPEID \n\
+                "select OBJECT" + (pObjectRelationId ? myNum : otherNum) + "_ROWID, AB_OBJECTRELATIONID, OBJECT_TYPE, RELATION_TITLE, INFO, AB_OBJECTRELATIONTYPEID \n\
                  from AB_OBJECTRELATION \n\
                  join AB_OBJECTRELATIONTYPE on AB_OBJECTRELATIONTYPEID = AB_OBJECTRELATIONTYPE" + myNum + " and ","1=2", "", false));
-
-    if (data.length == 0 && pDirection == "same" && !pNoRecursion)
+    
+    // try again with other side for "same"
+    if (data.length == 0 && pDirection == "same" && !pNoRecursion || pObjectRelationId && data.length > 0 && !data[0][0])
     {
-         return _getEntryData(pObjectId, "normal", pRelationType1, pRelationType2, pPrevId, true)
+         return _getEntryData(pObjectId, "normal", pRelationType1, pRelationType2, pPrevId, true, pObjectRelationId)
     }
-    
     // TODO: BINDATA?
     //for ( var i = 0; i < data.length; i++)  data[i][2] = image[data[i][2]] == undefined ? "" : image[data[i][2]];
     return data;
@@ -226,7 +254,7 @@ function _getRelationTypes(pObjectType)
  * @param {String} pNewRelationTypeId the RelationType, a new relation should have, if this node is selected.
  * @param {Integer} [pNum=undefined] optional number added to the key. Needed, if the key would not be unique.
  * 
- * @return {Array[][]} the uids of the inserted data. Consists of [ObjectId, pEntryData-Index, AB_OBJECTRELATIONTYPEID, pObjectType, pNodeId, objectrelationid, objecttype
+ * @return {Array[][]} the uids of the inserted data. Consists of [ObjectId, pEntryData-Index, AB_OBJECTRELATIONTYPEID, pObjectType (from param), pNodeId, objecttype (from entryId), objectrelationid]
  */
 function _insertEntry(pTree, pEntryData, pNodeId, pLayer, pObjectType, pNewRelationTypeId, pNum)
 {
diff --git a/entity/ObjectTree_entity/recordcontainers/jdito/onUpdate.js b/entity/ObjectTree_entity/recordcontainers/jdito/onUpdate.js
new file mode 100644
index 00000000000..23a87592d89
--- /dev/null
+++ b/entity/ObjectTree_entity/recordcontainers/jdito/onUpdate.js
@@ -0,0 +1,18 @@
+import("system.vars");
+import("system.neon");
+import("system.db");
+import("Sql_lib");
+
+
+var uid = JSON.parse(vars.get("$field.UID"));
+var isObjectRelationNode = typeof uid[2] == "string";
+
+if (isObjectRelationNode)
+{
+    var objectRelationId = uid[6];
+   
+    db.updateData("AB_OBJECTRELATION", ["INFO"], null, [vars.get("$field.INFO")], 
+                    SqlCondition.begin()
+                                .andPrepareIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", objectRelationId)
+                                .build("1=2"));
+}
diff --git a/entity/Object_entity/Object_entity.aod b/entity/Object_entity/Object_entity.aod
index 189f11b3a9e..a35318329e9 100644
--- a/entity/Object_entity/Object_entity.aod
+++ b/entity/Object_entity/Object_entity.aod
@@ -9,12 +9,6 @@
     <entityProvider>
       <name>#PROVIDER</name>
       <recordContainer>jdito</recordContainer>
-      <children>
-        <entityParameter>
-          <name>ObjectRowId_param</name>
-          <expose v="false" />
-        </entityParameter>
-      </children>
     </entityProvider>
     <entityField>
       <name>UID</name>
diff --git a/entity/Organisation_entity/Organisation_entity.aod b/entity/Organisation_entity/Organisation_entity.aod
index 4da1b5d9f85..0cfafe4ba1e 100644
--- a/entity/Organisation_entity/Organisation_entity.aod
+++ b/entity/Organisation_entity/Organisation_entity.aod
@@ -123,10 +123,6 @@
       <fieldType>DEPENDENCY_IN</fieldType>
       <recordContainer>db</recordContainer>
       <children>
-        <entityParameter>
-          <name>ContactId_param</name>
-          <expose v="true" />
-        </entityParameter>
         <entityParameter>
           <name>WithPrivate_param</name>
           <expose v="true" />
@@ -644,10 +640,6 @@
         </entityDependency>
       </dependencies>
       <children>
-        <entityParameter>
-          <name>ContactId_param</name>
-          <expose v="false" />
-        </entityParameter>
         <entityParameter>
           <name>ExcludeOrganisationsByPersonId</name>
           <title></title>
@@ -709,10 +701,6 @@
           <name>AttributeKeyId_param</name>
           <expose v="true" />
         </entityParameter>
-        <entityParameter>
-          <name>ContactId_param</name>
-          <expose v="false" />
-        </entityParameter>
         <entityParameter>
           <name>ExcludeOrganisationsByPersonId</name>
           <expose v="false" />
diff --git a/neonContext/ObjectTree/ObjectTree.aod b/neonContext/ObjectTree/ObjectTree.aod
index a8f24a44156..3a0bc38b2c9 100644
--- a/neonContext/ObjectTree/ObjectTree.aod
+++ b/neonContext/ObjectTree/ObjectTree.aod
@@ -4,6 +4,7 @@
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <filterview>ObjectTreeFilter_view</filterview>
   <editview>ObjectTreeEdit_view</editview>
+  <preview>ObjectTreePreview</preview>
   <entity>ObjectTree_entity</entity>
   <references>
     <neonViewReference>
@@ -14,5 +15,9 @@
       <name>1122516a-5f1c-4f08-9995-02acaee2a0cd</name>
       <view>ObjectTreeEdit_view</view>
     </neonViewReference>
+    <neonViewReference>
+      <name>1caa61e2-0e59-47bd-a996-db49867e3908</name>
+      <view>ObjectTreePreview</view>
+    </neonViewReference>
   </references>
 </neonContext>
diff --git a/neonView/ObjectTreePreview/ObjectTreePreview.aod b/neonView/ObjectTreePreview/ObjectTreePreview.aod
new file mode 100644
index 00000000000..b6b2c90c68a
--- /dev/null
+++ b/neonView/ObjectTreePreview/ObjectTreePreview.aod
@@ -0,0 +1,32 @@
+<?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.1.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.1">
+  <name>ObjectTreePreview</name>
+  <majorModelMode>DISTRIBUTED</majorModelMode>
+  <layout>
+    <boxLayout>
+      <name>layout</name>
+    </boxLayout>
+  </layout>
+  <children>
+    <genericViewTemplate>
+      <name>Info</name>
+      <showDrawer v="true" />
+      <drawerCaption>Info</drawerCaption>
+      <entityField>#ENTITY</entityField>
+      <fields>
+        <entityFieldLink>
+          <name>a7ff1a5c-1ea5-4904-a802-b3da55c07341</name>
+          <entityField>OBJECTRELATIONTYPEID</entityField>
+        </entityFieldLink>
+        <entityFieldLink>
+          <name>0b612a60-d882-4def-b569-7146e1b1ccb6</name>
+          <entityField>TARGET_ID</entityField>
+        </entityFieldLink>
+        <entityFieldLink>
+          <name>6ed4e675-b1f5-4790-97d1-d015f87f37e4</name>
+          <entityField>INFO</entityField>
+        </entityFieldLink>
+      </fields>
+    </genericViewTemplate>
+  </children>
+</neonView>
diff --git a/process/ObjectRelation_lib/process.js b/process/ObjectRelation_lib/process.js
index 1010f1a6586..f44bc3ead92 100644
--- a/process/ObjectRelation_lib/process.js
+++ b/process/ObjectRelation_lib/process.js
@@ -1,4 +1,4 @@
-import("system.logging");
+import("Sql_lib");
 import("system.db");
 
 /**
@@ -10,11 +10,11 @@ import("system.db");
 function ObjectRelationUtils() {}
 
 /**
- * Get all possible relationTypes by a objectType.
+ * Get all possible relationTypes by a objectType. (objectrelationtypeId and title)
  * Normally it only returns the id and title. If you set pFullInfo to true, you will get additional information, too.
  * 
  * @param {String} pObjectType the object type to load the relation types for.] 
- * @param {Boolean} [pFullInfo=false] return also RELATION_TYPE, direction (normal, reverse, same), hierarchy, OBJECT_TYPE dest, OBJECT_TYPE source, objectrelationtypeId1, objectrelationtypeId2, side, otherSide-RELATION_TYPE
+ * @param {Boolean} [pFullInfo=false] return also RELATION_TYPE, direction (normal, reverse, same), hierarchy, OBJECT_TYPE dest, OBJECT_TYPE source, objectrelationtypeId1, objectrelationtypeId2, side, objectrelationtypeId
  * 
  * @return {String[][]}
  */
@@ -54,7 +54,7 @@ ObjectRelationUtils.getPossibleRelationTypes = function(pObjectType, pFullInfo)
         -- typeId of Object1\n\
         case when type2.AB_OBJECTRELATIONTYPEID is null or main.SIDE = 2 then main.AB_OBJECTRELATIONTYPEID\n\
              else type2.AB_OBJECTRELATIONTYPEID end objectrelationtypeId2, \n\
-        main.SIDE, type2.AB_OBJECTRELATIONTYPEID" + sql, 
+        main.SIDE, case when type2.AB_OBJECTRELATIONTYPEID is  null then main.AB_OBJECTRELATIONTYPEID else type2.AB_OBJECTRELATIONTYPEID end" + sql, 
         [
           [pObjectType, db.getColumnTypes("AB_OBJECTRELATIONTYPE", ["OBJECT_TYPE"])[0]]
         ]
@@ -64,14 +64,14 @@ ObjectRelationUtils.getPossibleRelationTypes = function(pObjectType, pFullInfo)
 }
 
 /**
- * Get all possible relationTypes by a objectType.
- * returns the id, title, RELATION_TYPE, direction (normal, reverse, same), hierarchy, OBJECT_TYPE dest, OBJECT_TYPE source, objectrelationtypeId1, objectrelationtypeId2, side, otherSide-RELATION_TYPE
+ * Get relationType by a RelationTypeId.
+ * returns the objectrelationtypeId, title, RELATION_TYPE, direction (normal, reverse, same), hierarchy, OBJECT_TYPE dest, OBJECT_TYPE source, objectrelationtypeId1, objectrelationtypeId2, side,objectrelationtypeId
  * 
- * @param {String} pObjectTypeId the object type to load the relation types for.] 
+ * @param {String} pRelationTypeId the RelationTypeId to load the full relation type for.
  * 
  * @return {String[][]}
  */
-ObjectRelationUtils.getRelationType = function(pObjectTypeId)
+ObjectRelationUtils.getRelationType = function(pRelationTypeId)
 {
     // TODO: funktionen evtl. zusammenfassen
     var sql = " from AB_OBJECTRELATIONTYPE main \n\
@@ -94,9 +94,9 @@ ObjectRelationUtils.getRelationType = function(pObjectTypeId)
         -- typeId of Object1\n\
         case when type2.AB_OBJECTRELATIONTYPEID is null or main.SIDE = 2 then main.AB_OBJECTRELATIONTYPEID\n\
              else type2.AB_OBJECTRELATIONTYPEID end objectrelationtypeId2, \n\
-        main.SIDE, type2.AB_OBJECTRELATIONTYPEID" + sql, 
+        main.SIDE, case when type2.AB_OBJECTRELATIONTYPEID is  null then main.AB_OBJECTRELATIONTYPEID else type2.AB_OBJECTRELATIONTYPEID end" + sql, 
         [
-          [pObjectTypeId, db.getColumnTypes("AB_OBJECTRELATIONTYPE", ["AB_OBJECTRELATIONTYPEID"])[0]],
+          [pRelationTypeId, db.getColumnTypes("AB_OBJECTRELATIONTYPE", ["AB_OBJECTRELATIONTYPEID"])[0]],
         ]
     ]));
 
-- 
GitLab