From 3acb969ff02cc712e94907261d63af5c1370a4b6 Mon Sep 17 00:00:00 2001
From: "j.goderbauer" <j.goderbauer@adito.de>
Date: Tue, 2 Apr 2019 10:08:06 +0200
Subject: [PATCH] Context_lib: exclude private-dummy organisation

---
 process/Context_lib/process.js | 35 +++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/process/Context_lib/process.js b/process/Context_lib/process.js
index 8e16faee0d..c0673e0e7e 100644
--- a/process/Context_lib/process.js
+++ b/process/Context_lib/process.js
@@ -183,6 +183,7 @@ function ContextSelector(pTableName, pIdField, pTitleExpression)
      * @property
      */
     this.activeStates = null; ProtoPropertyUtils.makeSemiReadOnly(this, "activeStates");
+    this.condition = null; ProtoPropertyUtils.makeSemiReadOnly(this, "condition");
 }
 /**
  * creates a new instance of a ContextSelector and returns it 
@@ -252,6 +253,15 @@ ContextSelector.prototype.setActiveStates = function(pValue)
     this._activeStates = pValue;
     return this;
 };
+/**
+ * sets the condition property of a ContextSelector-object
+ * @param {Object} pSqlCondition condition as SqlCondition-object
+ */
+ContextSelector.prototype.setCondition = function(pSqlCondition)
+{
+    this._condition = pSqlCondition;
+    return this;
+};
 
 /**
  * TODO: !!!temporary function until you can get fields from another Entity!!!
@@ -261,6 +271,7 @@ ContextUtils.getSelectMap  = function()
     var maskingUtils = new SqlMaskingUtils();
     return {
         "Organisation": ContextSelector.create("ORGANISATION", "ORGANISATIONID", "NAME")
+                                       .setCondition(SqlCondition.begin().and("ORGANISATION.ORGANISATIONID != '0'"))
             ,"Person": ContextSelector.create("CONTACT", "CONTACTID")
                                       .setTitleExpression(maskingUtils.concat([
                                                 new ContactTitleRenderer(Contact.createWithColumnPreset()).asSql()
@@ -365,37 +376,39 @@ ContextUtils.getNameSql = function(pContextId, pRowId)
  */
 ContextUtils.getContextDataSql = function(pContextId, pRowId, pWithDate, pActive, pWithState)
 {
-    var selectMap = ContextUtils.getSelectMap ();
+    var selectMap = ContextUtils.getSelectMap();
+    var ownContextSelector = selectMap[pContextId];
     var cond = SqlCondition.begin();
     if (pRowId)
     {
-        cond.andPrepare(selectMap[pContextId].tableName + "." + selectMap[pContextId].contactIdField, pRowId)
+        cond.andPrepare(ownContextSelector.tableName + "." + ownContextSelector.contactIdField, pRowId)
     }
     
     if (pActive != undefined)
     {
-        var activeStates = selectMap[pContextId].activeStates;
+        var activeStates = ownContextSelector.activeStates;
         if(activeStates != null && activeStates.length > 0)
         {
             var condSub = SqlCondition.begin();
             activeStates.forEach(function (state) 
             {   
                 if(pActive)
-                    condSub.orPrepare(selectMap[pContextId].tableName + "." + selectMap[pContextId].stateField, state)
+                    condSub.orPrepare(ownContextSelector.tableName + "." + ownContextSelector.stateField, state)
                 else
-                    condSub.andPrepare(selectMap[pContextId].tableName + "." + selectMap[pContextId].stateField, state, "# != ?")
+                    condSub.andPrepare(ownContextSelector.tableName + "." + ownContextSelector.stateField, state, "# != ?")
             });
             cond.andSqlCondition(condSub);   
         }
     }
     var dateColumn = "";
     if (pWithDate === true)
-        dateColumn = ", " + (selectMap[pContextId].creationDateField || "''");
-    
+        dateColumn = ", " + (ownContextSelector.creationDateField || "''");
     var stateColumn = "";
     if (pWithState === true)
-        stateColumn = ", " + (selectMap[pContextId].stateField || "''");
-
-    return cond.buildSql("select " + selectMap[pContextId].getFullIdField() + ", " + selectMap[pContextId].titleExpression + dateColumn + stateColumn 
-                      +  " from " + selectMap[pContextId].getFullFromClause(), "1=1");
+        stateColumn = ", " + (ownContextSelector.stateField || "''");
+    if (ownContextSelector.condition)
+        cond.andSqlCondition(ownContextSelector.condition);
+    var res = cond.buildSql("select " + ownContextSelector.getFullIdField() + ", " + ownContextSelector.titleExpression + dateColumn + stateColumn 
+            +  " from " + ownContextSelector.getFullFromClause(), "1=1");
+    return res;
 }
-- 
GitLab