From 7d62fb8f54bbdfd37e8568817740ee158fdeb5c5 Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Tue, 12 Feb 2019 15:04:26 +0100
Subject: [PATCH] Object relation fixes & documentation

---
 entity/Context_entity/Context_entity.aod      |  2 +
 entity/Context_entity/documentation.adoc      |  9 ++++
 .../contextid_param/documentation.adoc        |  1 +
 .../recordcontainers/jdito/contentProcess.js  | 20 +--------
 .../ObjectRelation_entity.aod                 |  4 ++
 .../ObjectRelation_entity/documentation.adoc  |  2 +-
 .../entityfields/anyobject/documentation.adoc | 10 +++++
 .../anytargetrowid/valueProcess.js            |  8 ++--
 .../anytargettype/valueProcess.js             |  9 ++--
 .../bothobjects/documentation.adoc            | 16 +++++++
 .../entityfields/object1/documentation.adoc   | 16 +++++++
 .../object1_rowid/displayValueProcess.js      |  3 --
 .../object1_rowid/valueProcess.js             |  2 -
 .../entityfields/object2/documentation.adoc   | 17 ++++++++
 .../object2_rowid/stateProcess.js             |  2 -
 .../recordcontainers/db/conditionProcess.js   |  1 -
 entity/Object_entity/Object_entity.aod        |  4 +-
 entity/Object_entity/documentation.adoc       |  8 ++++
 .../allobjects/documentation.adoc             |  3 ++
 .../entityfields/oneobject/documentation.adoc |  3 ++
 .../recordcontainers/jdito/contentProcess.js  | 15 ++++---
 process/Context_lib/process.js                | 43 +++++++++++++++++++
 22 files changed, 154 insertions(+), 44 deletions(-)
 create mode 100644 entity/Context_entity/documentation.adoc
 create mode 100644 entity/Context_entity/entityfields/contextid_param/documentation.adoc
 create mode 100644 entity/ObjectRelation_entity/entityfields/anyobject/documentation.adoc
 create mode 100644 entity/ObjectRelation_entity/entityfields/bothobjects/documentation.adoc
 create mode 100644 entity/ObjectRelation_entity/entityfields/object1/documentation.adoc
 create mode 100644 entity/ObjectRelation_entity/entityfields/object2/documentation.adoc
 create mode 100644 entity/Object_entity/documentation.adoc
 create mode 100644 entity/Object_entity/entityfields/allobjects/documentation.adoc
 create mode 100644 entity/Object_entity/entityfields/oneobject/documentation.adoc

diff --git a/entity/Context_entity/Context_entity.aod b/entity/Context_entity/Context_entity.aod
index 307bf15c0a2..31626ace6b0 100644
--- a/entity/Context_entity/Context_entity.aod
+++ b/entity/Context_entity/Context_entity.aod
@@ -2,6 +2,7 @@
 <entity xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.0" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/entity/1.2.0">
   <name>Context_entity</name>
   <majorModelMode>DISTRIBUTED</majorModelMode>
+  <documentation>%aditoprj%/entity/Context_entity/documentation.adoc</documentation>
   <titleProcess>%aditoprj%/entity/Context_entity/titleProcess.js</titleProcess>
   <recordContainer>jdito</recordContainer>
   <entityFields>
@@ -29,6 +30,7 @@
       <name>ContextId_param</name>
       <expose v="true" />
       <mandatory v="false" />
+      <documentation>%aditoprj%/entity/Context_entity/entityfields/contextid_param/documentation.adoc</documentation>
       <description>PARAMETER</description>
     </entityParameter>
     <entityProvider>
diff --git a/entity/Context_entity/documentation.adoc b/entity/Context_entity/documentation.adoc
new file mode 100644
index 00000000000..b7049946054
--- /dev/null
+++ b/entity/Context_entity/documentation.adoc
@@ -0,0 +1,9 @@
+== Context_entity ==
+
+This Entity provides access to contexts.
+
+It provides:
+
+- the context ID (currently (12.02.2019) it is the context name) 
+- the context name (the name which is used in the designer) 
+- the context title (the title of the context which is a property of the context. If it is not defined you get the context name. 
\ No newline at end of file
diff --git a/entity/Context_entity/entityfields/contextid_param/documentation.adoc b/entity/Context_entity/entityfields/contextid_param/documentation.adoc
new file mode 100644
index 00000000000..abbd33cd243
--- /dev/null
+++ b/entity/Context_entity/entityfields/contextid_param/documentation.adoc
@@ -0,0 +1 @@
+If you provide the ContextId_param only this context is provided.
\ No newline at end of file
diff --git a/entity/Context_entity/recordcontainers/jdito/contentProcess.js b/entity/Context_entity/recordcontainers/jdito/contentProcess.js
index e0eac166061..07c0d727b9a 100644
--- a/entity/Context_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/Context_entity/recordcontainers/jdito/contentProcess.js
@@ -1,28 +1,12 @@
 import("system.vars");
 import("system.result");
-import("system.project");
 import("Context_lib");
 
 if (vars.exists("$param.ContextId_param") && vars.get("$param.ContextId_param"))
 {
-    result.object(_contextDataMapping(project.getDataModel(project.DATAMODEL_KIND_CONTEXT, vars.get("$param.ContextId_param"))));
+    result.object(ContextUtils.getContext(vars.get("$param.ContextId_param")));
 }
 else
 {
-    result.object(project.getDataModels(project.DATAMODEL_KIND_CONTEXT).map(_contextDataMapping).sort(function(pContext1, pContext2) {
-        if (pContext1[2] > pContext2[2])
-            return 1;
-        
-        if (pContext1[2] < pContext2[2])
-            return -1;
-        
-        return 0;
-    }));
-}
-
-function _contextDataMapping(pContext)
-{
-    var contextName = ContextUtils.getContextName(pContext[0]);
-
-    return [pContext[0], contextName, (pContext[1] ? pContext[1] : contextName)];
+    result.object(ContextUtils.getContexts(true));
 }
\ No newline at end of file
diff --git a/entity/ObjectRelation_entity/ObjectRelation_entity.aod b/entity/ObjectRelation_entity/ObjectRelation_entity.aod
index f182efcba85..4979183f705 100644
--- a/entity/ObjectRelation_entity/ObjectRelation_entity.aod
+++ b/entity/ObjectRelation_entity/ObjectRelation_entity.aod
@@ -62,6 +62,7 @@
       <fieldType>DEPENDENCY_IN</fieldType>
       <targetContextField>OBJECT2_TYPE</targetContextField>
       <targetIdField>OBJECT2_ROWID</targetIdField>
+      <documentation>%aditoprj%/entity/ObjectRelation_entity/entityfields/object1/documentation.adoc</documentation>
       <recordContainer>db</recordContainer>
       <dependencies>
         <entityDependency>
@@ -113,6 +114,7 @@
       <fieldType>DEPENDENCY_IN</fieldType>
       <targetContextField>OBJECT1_TYPE</targetContextField>
       <targetIdField>OBJECT1_ROWID</targetIdField>
+      <documentation>%aditoprj%/entity/ObjectRelation_entity/entityfields/object2/documentation.adoc</documentation>
       <recordContainer>db</recordContainer>
       <children>
         <entityParameter>
@@ -146,6 +148,7 @@
       <fieldType>DEPENDENCY_IN</fieldType>
       <targetContextField>OBJECT2_TYPE</targetContextField>
       <targetIdField>OBJECT2_ROWID</targetIdField>
+      <documentation>%aditoprj%/entity/ObjectRelation_entity/entityfields/bothobjects/documentation.adoc</documentation>
       <recordContainer>db</recordContainer>
       <children>
         <entityParameter>
@@ -203,6 +206,7 @@
       <fieldType>DEPENDENCY_IN</fieldType>
       <targetContextField>AnyTargetType</targetContextField>
       <targetIdField>AnyTargetRowid</targetIdField>
+      <documentation>%aditoprj%/entity/ObjectRelation_entity/entityfields/anyobject/documentation.adoc</documentation>
       <recordContainer>db</recordContainer>
       <dependencies>
         <entityDependency>
diff --git a/entity/ObjectRelation_entity/documentation.adoc b/entity/ObjectRelation_entity/documentation.adoc
index 5b71000497c..c65aa9a8f37 100644
--- a/entity/ObjectRelation_entity/documentation.adoc
+++ b/entity/ObjectRelation_entity/documentation.adoc
@@ -1,6 +1,6 @@
 == Object Relation ==
 
-This entity is for relation between Objects. It should be used if everything can be related to something.
+This entity is for relation between Objects. It should be used if something can be related to something.
 If only special objects should be connected where you always know what it is, it is better to create a custom relation table/entity which is only for this purpose. (e.g. Prod2Prod, Relation, ActitvityLink, ...)
 
 The Object type is the ID of the context. 
diff --git a/entity/ObjectRelation_entity/entityfields/anyobject/documentation.adoc b/entity/ObjectRelation_entity/entityfields/anyobject/documentation.adoc
new file mode 100644
index 00000000000..11ee142148f
--- /dev/null
+++ b/entity/ObjectRelation_entity/entityfields/anyobject/documentation.adoc
@@ -0,0 +1,10 @@
+== AnyObject provider ==
+
+is for bidirectional Objectrelations.
+
+Example:
+if you provide the contact "Lisa Sommer" as parameters (any..._param) you will get all relations which contain "Lisa Sommer" as Object1 OR Object2.
+
+You will get both:
+Object1 = "Lisa Sommer", Object2 = "GFK"
+Object1 = "GFK", Object2 = "Lisa Sommer"
\ No newline at end of file
diff --git a/entity/ObjectRelation_entity/entityfields/anytargetrowid/valueProcess.js b/entity/ObjectRelation_entity/entityfields/anytargetrowid/valueProcess.js
index 9f0983d754b..30698cf10e5 100644
--- a/entity/ObjectRelation_entity/entityfields/anytargetrowid/valueProcess.js
+++ b/entity/ObjectRelation_entity/entityfields/anytargetrowid/valueProcess.js
@@ -8,18 +8,18 @@ var openedRowid;
 if (vars.exists("$param.AnyObjectType_param") && vars.get("$param.AnyObjectType_param"))
 {
     openedType = vars.get("$param.AnyObjectType_param");
-    if (vars.exists("$param.Object1Rowid_param") && vars.get("$param.Object1Rowid_param"))
+    if (vars.exists("$param.AnyObjectRowid_param") && vars.get("$param.AnyObjectRowid_param"))
     {
-        openedRowid = vars.get("$param.Object1Rowid_param");
+        openedRowid = vars.get("$param.AnyObjectRowid_param");
         // anyObject and object 1 == opened object --> target is object2
         if (vars.get("$field.OBJECT1_ROWID") == openedRowid && vars.get("$field.OBJECT1_TYPE") == openedType)
         {
-            result.string(vars.get(vars.get("$field.OBJECT2_ROWID")));
+            result.string(vars.get("$field.OBJECT2_ROWID"));
         }
         // anyObject and object 2 == opened object --> target is object1
         else if (vars.get("$field.OBJECT2_ROWID") == openedRowid && vars.get("$field.OBJECT2_TYPE") == openedType)
         {
-            result.string(vars.get(vars.get("$field.OBJECT1_ROWID")));
+            result.string(vars.get("$field.OBJECT1_ROWID"));
         }
     }
 }
\ No newline at end of file
diff --git a/entity/ObjectRelation_entity/entityfields/anytargettype/valueProcess.js b/entity/ObjectRelation_entity/entityfields/anytargettype/valueProcess.js
index 4edbbede26f..c8dd2fb8c6f 100644
--- a/entity/ObjectRelation_entity/entityfields/anytargettype/valueProcess.js
+++ b/entity/ObjectRelation_entity/entityfields/anytargettype/valueProcess.js
@@ -1,4 +1,3 @@
-import("system.logging");
 import("system.result");
 import("system.vars");
 
@@ -9,18 +8,18 @@ var openedRowid;
 if (vars.exists("$param.AnyObjectType_param") && vars.get("$param.AnyObjectType_param"))
 {
     openedType = vars.get("$param.AnyObjectType_param");
-    if (vars.exists("$param.Object1Rowid_param") && vars.get("$param.Object1Rowid_param"))
+    if (vars.exists("$param.AnyObjectRowid_param") && vars.get("$param.AnyObjectRowid_param"))
     {
-        openedRowid = vars.get("$param.Object1Rowid_param");
+        openedRowid = vars.get("$param.AnyObjectRowid_param");
         // anyObject and object 1 == opened object --> target is object2
         if (vars.get("$field.OBJECT1_ROWID") == openedRowid && vars.get("$field.OBJECT1_TYPE") == openedType)
         {
-            result.string(vars.get(vars.get("$field.OBJECT2_TYPE")));
+            result.string(vars.get("$field.OBJECT2_TYPE"));
         }
         // anyObject and object 2 == opened object --> target is object1
         else if (vars.get("$field.OBJECT2_ROWID") == openedRowid && vars.get("$field.OBJECT2_TYPE") == openedType)
         {
-            result.string(vars.get(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/bothobjects/documentation.adoc b/entity/ObjectRelation_entity/entityfields/bothobjects/documentation.adoc
new file mode 100644
index 00000000000..12b757625cd
--- /dev/null
+++ b/entity/ObjectRelation_entity/entityfields/bothobjects/documentation.adoc
@@ -0,0 +1,16 @@
+== BothObject provider ==
+
+is for getting relations between TWO SPECIFIC objects.
+
+Example:
+if you provide the contact "Lisa Sommer" and organisation "GFK" as parameters (objectX..._param) you will get all relations which contain "Lisa Sommer" as Object1 and "GFK" as Object2.
+
+You will get only:
+Object1 = "Lisa Sommer", Object2 = "GFK"
+
+
+You WON'T get:
+Object1 = "GFK", Object2 = "Lisa Sommer"
+Object1 = "Peter Pfiffig", Object2 = "Lisa Sommer"
+Object1 = "Peter Pfiffig", Object2 = "GFK"
+...
\ No newline at end of file
diff --git a/entity/ObjectRelation_entity/entityfields/object1/documentation.adoc b/entity/ObjectRelation_entity/entityfields/object1/documentation.adoc
new file mode 100644
index 00000000000..ba1539f3db1
--- /dev/null
+++ b/entity/ObjectRelation_entity/entityfields/object1/documentation.adoc
@@ -0,0 +1,16 @@
+== Object1 provider ==
+
+is for getting relations between Object1 and something.
+
+Example:
+if you provide the contact "Lisa Sommer" as parameter (object1..._param) you will get all relations which contain "Lisa Sommer" as Object1.
+
+You will get:
+Object1 = "Lisa Sommer", Object2 = "GFK"
+
+
+You WON'T get:
+Object1 = "GFK", Object2 = "Lisa Sommer"
+Object1 = "Peter Pfiffig", Object2 = "Lisa Sommer"
+Object1 = "Peter Pfiffig", Object2 = "GFK"
+...
\ No newline at end of file
diff --git a/entity/ObjectRelation_entity/entityfields/object1_rowid/displayValueProcess.js b/entity/ObjectRelation_entity/entityfields/object1_rowid/displayValueProcess.js
index 94cfeeb560e..f82167f8b69 100644
--- a/entity/ObjectRelation_entity/entityfields/object1_rowid/displayValueProcess.js
+++ b/entity/ObjectRelation_entity/entityfields/object1_rowid/displayValueProcess.js
@@ -1,4 +1,3 @@
-import("system.logging");
 import("system.neon");
 import("system.vars");
 import("system.result");
@@ -19,10 +18,8 @@ if (recordstate == neon.OPERATINGSTATE_NEW)
 }
 else if (recordstate == neon.OPERATINGSTATE_EDIT)
 {
-    logging.log("edit")
     if (vars.exists("$field.OBJECT1_ROWID") && vars.get("$field.OBJECT1_ROWID") && vars.exists("$field.OBJECT1_TYPE") && vars.get("$field.OBJECT1_TYPE"))
     {
-        logging.log(db.cell(ContextUtils.getNameSql(vars.get("$field.OBJECT1_TYPE"), vars.get("$field.OBJECT1_ROWID"))))
         result.string(db.cell(ContextUtils.getNameSql(vars.get("$field.OBJECT1_TYPE"), vars.get("$field.OBJECT1_ROWID"))));
     }
 }
\ No newline at end of file
diff --git a/entity/ObjectRelation_entity/entityfields/object1_rowid/valueProcess.js b/entity/ObjectRelation_entity/entityfields/object1_rowid/valueProcess.js
index ddfeaf3a855..679db41733d 100644
--- a/entity/ObjectRelation_entity/entityfields/object1_rowid/valueProcess.js
+++ b/entity/ObjectRelation_entity/entityfields/object1_rowid/valueProcess.js
@@ -1,10 +1,8 @@
-import("system.logging");
 import("system.result");
 import("system.neon");
 import("system.vars");
 
 var recordstate = vars.get("$sys.recordstate");
-logging.log(recordstate)
 
 if (recordstate == neon.OPERATINGSTATE_NEW || recordstate == neon.OPERATINGSTATE_EDIT)
 {
diff --git a/entity/ObjectRelation_entity/entityfields/object2/documentation.adoc b/entity/ObjectRelation_entity/entityfields/object2/documentation.adoc
new file mode 100644
index 00000000000..9ce67b8769d
--- /dev/null
+++ b/entity/ObjectRelation_entity/entityfields/object2/documentation.adoc
@@ -0,0 +1,17 @@
+== Object2 provider ==
+
+is for getting relations between something and Object2.
+
+Example:
+if you provide the contact "Lisa Sommer" as parameter (object2..._param) you will get all relations which contain "Lisa Sommer" as Object2.
+
+You will get:
+Object1 = "GFK", Object2 = "Lisa Sommer"
+Object1 = "Peter Pfiffig", Object2 = "Lisa Sommer"
+
+
+You WON'T get:
+Object1 = "Lisa Sommer", Object2 = "GFK"
+Object1 = "Peter Pfiffig", Object2 = "GFK"
+Object1 = "Lisa Sommer", Object2 = "Peter Pfiffig"
+...
\ No newline at end of file
diff --git a/entity/ObjectRelation_entity/entityfields/object2_rowid/stateProcess.js b/entity/ObjectRelation_entity/entityfields/object2_rowid/stateProcess.js
index b78d71076c7..51c5fa78a28 100644
--- a/entity/ObjectRelation_entity/entityfields/object2_rowid/stateProcess.js
+++ b/entity/ObjectRelation_entity/entityfields/object2_rowid/stateProcess.js
@@ -1,4 +1,3 @@
-import("system.logging");
 import("system.result");
 import("system.neon");
 import("system.vars");
@@ -6,7 +5,6 @@ import("system.vars");
 var recordstate = vars.get("$sys.recordstate");
 if (recordstate == neon.OPERATINGSTATE_NEW || recordstate == neon.OPERATINGSTATE_EDIT)
 {
-    logging.log(vars.exists("$param.Object2Rowid_param") && vars.get("$param.Object2Rowid_param"))
     if (vars.exists("$param.Object2Rowid_param") && vars.get("$param.Object2Rowid_param"))
         result.string(neon.COMPONENTSTATE_READONLY);
 }
\ No newline at end of file
diff --git a/entity/ObjectRelation_entity/recordcontainers/db/conditionProcess.js b/entity/ObjectRelation_entity/recordcontainers/db/conditionProcess.js
index 0c33f31769c..fd3608bd870 100644
--- a/entity/ObjectRelation_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/ObjectRelation_entity/recordcontainers/db/conditionProcess.js
@@ -1,5 +1,4 @@
 import("system.vars");
-import("system.logging");
 import("system.result");
 import("system.db");
 import("Sql_lib");
diff --git a/entity/Object_entity/Object_entity.aod b/entity/Object_entity/Object_entity.aod
index 09a765c2625..68ae8000ad6 100644
--- a/entity/Object_entity/Object_entity.aod
+++ b/entity/Object_entity/Object_entity.aod
@@ -2,12 +2,12 @@
 <entity xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.0" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/entity/1.2.0">
   <name>Object_entity</name>
   <majorModelMode>DISTRIBUTED</majorModelMode>
+  <documentation>%aditoprj%/entity/Object_entity/documentation.adoc</documentation>
   <titleProcess>%aditoprj%/entity/Object_entity/titleProcess.js</titleProcess>
   <recordContainer>jdito</recordContainer>
   <entityFields>
     <entityProvider>
       <name>#PROVIDER</name>
-      <recordContainer>jdito</recordContainer>
       <children>
         <entityParameter>
           <name>ObjectRowId_param</name>
@@ -37,6 +37,7 @@
     <entityProvider>
       <name>OneObject</name>
       <fieldType>DEPENDENCY_IN</fieldType>
+      <documentation>%aditoprj%/entity/Object_entity/entityfields/oneobject/documentation.adoc</documentation>
       <recordContainer>jdito</recordContainer>
       <dependencies>
         <entityDependency>
@@ -70,6 +71,7 @@
     <entityProvider>
       <name>AllObjects</name>
       <fieldType>DEPENDENCY_IN</fieldType>
+      <documentation>%aditoprj%/entity/Object_entity/entityfields/allobjects/documentation.adoc</documentation>
       <recordContainer>jdito</recordContainer>
       <dependencies>
         <entityDependency>
diff --git a/entity/Object_entity/documentation.adoc b/entity/Object_entity/documentation.adoc
new file mode 100644
index 00000000000..85191c1903e
--- /dev/null
+++ b/entity/Object_entity/documentation.adoc
@@ -0,0 +1,8 @@
+== Object_entity ==
+
+This Entity provides access to different Objects.
+
+It provides:
+
+- the object ID (the UUID of the object) 
+- the object title (the display name. Currently (12.02.2019) it is configured in the Context_lib. This may change!
\ No newline at end of file
diff --git a/entity/Object_entity/entityfields/allobjects/documentation.adoc b/entity/Object_entity/entityfields/allobjects/documentation.adoc
new file mode 100644
index 00000000000..66f07aa06c5
--- /dev/null
+++ b/entity/Object_entity/entityfields/allobjects/documentation.adoc
@@ -0,0 +1,3 @@
+== AllObjects provider ==
+
+This provider returns all objects of one type.
\ No newline at end of file
diff --git a/entity/Object_entity/entityfields/oneobject/documentation.adoc b/entity/Object_entity/entityfields/oneobject/documentation.adoc
new file mode 100644
index 00000000000..628c2147801
--- /dev/null
+++ b/entity/Object_entity/entityfields/oneobject/documentation.adoc
@@ -0,0 +1,3 @@
+== OneObjects provider ==
+
+This provider returns one specific object.
\ No newline at end of file
diff --git a/entity/Object_entity/recordcontainers/jdito/contentProcess.js b/entity/Object_entity/recordcontainers/jdito/contentProcess.js
index e5a6d3fab4c..fa1404cf0aa 100644
--- a/entity/Object_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/Object_entity/recordcontainers/jdito/contentProcess.js
@@ -1,19 +1,20 @@
 import("system.db");
 import("system.vars");
-import("system.logging");
 import("system.result");
 import("Context_lib");
 
-logging.log(vars.get("$param.ObjectType_param").toSource())
-
 if (vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param"))
 {
     if (vars.exists("$param.ObjectRowId_param") && vars.get("$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"))))
-} else {
-    result.object([]);
+    else
+    {
+        result.object(db.table(ContextUtils.getContextDataSql(vars.get("$param.ObjectType_param"))))
+    }
 } 
+else
+{
+    result.object([]);
+}
\ No newline at end of file
diff --git a/process/Context_lib/process.js b/process/Context_lib/process.js
index ea67ede99bb..db46760fc31 100644
--- a/process/Context_lib/process.js
+++ b/process/Context_lib/process.js
@@ -36,6 +36,49 @@ ContextUtils.getContextName = function(pContextId)
     return pContextId;
 }
 
+ContextUtils.getContexts = function(pFilter)
+{
+    if (pFilter == undefined) 
+        pFilter = false;
+    
+    
+    var contexts = project.getDataModels(project.DATAMODEL_KIND_CONTEXT);
+    
+    if (pFilter)
+    {
+        contexts = contexts.filter(function(pContext) 
+        {
+            // filter only contexts which have defined mappings in Context_lib
+            return ContextUtils._getSelectMap()[pContext[0]] != undefined;
+        });
+    }
+    
+    
+    return contexts.map(ContextUtils._contextDataMapping).sort(function(pContext1, pContext2) 
+            {
+                // sort after ContextTitle
+                if (pContext1[2] > pContext2[2])
+                    return 1;
+
+                if (pContext1[2] < pContext2[2])
+                    return -1;
+
+                return 0;
+            });
+}
+
+ContextUtils.getContext = function(pContextId)
+{
+    return ContextUtils._contextDataMapping(project.getDataModel(project.DATAMODEL_KIND_CONTEXT, pContextId));
+}
+
+ContextUtils._contextDataMapping = function(pContext)
+{
+    var contextName = ContextUtils.getContextName(pContext[0]);
+
+    return [pContext[0], contextName, (pContext[1] ? pContext[1] : contextName)];
+}
+
 /**
  * TODO: !!!temporary function until you can get fields from another Entity!!!
  */
-- 
GitLab