From 76953b7243f6fb85e6d2feff62eaa69d36590ed0 Mon Sep 17 00:00:00 2001
From: Andre Loreth <a.loreth@adito.de>
Date: Wed, 27 Mar 2019 11:21:47 +0100
Subject: [PATCH] #1035771 Standard address/communication

---
 .../recordcontainers/db/onDBUpdate.js         |  4 ---
 process/StandardObject_lib/process.js         | 32 ++++++++-----------
 2 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/entity/Communication_entity/recordcontainers/db/onDBUpdate.js b/entity/Communication_entity/recordcontainers/db/onDBUpdate.js
index bf5479355e..7e2690d20a 100644
--- a/entity/Communication_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/Communication_entity/recordcontainers/db/onDBUpdate.js
@@ -2,9 +2,5 @@ import("system.logging");
 import("system.vars");
 import("StandardObject_lib");
 
-logging.log("Object " + vars.get("$field.COMMUNICATIONID"))
-logging.log("Contact " + vars.get("$field.CONTACT_ID"))
-logging.log("Medium " + vars.get("$field.MEDIUM_ID"))
-
 new StandardObject("Communication", vars.get("$field.COMMUNICATIONID"), "Person", vars.get("$field.CONTACT_ID"))
     .onCommunicationUpdate(vars.get("$field.MEDIUM_ID"));
\ No newline at end of file
diff --git a/process/StandardObject_lib/process.js b/process/StandardObject_lib/process.js
index 15358cf2b9..28c728cd76 100644
--- a/process/StandardObject_lib/process.js
+++ b/process/StandardObject_lib/process.js
@@ -13,8 +13,6 @@ function StandardObject (pObjectType, pObjectID, pScopeType, pScopeID) {
     this.objectID = pObjectID
     this.scopeType = pScopeType
     this.scopeID = pScopeID
-
-    this.__mediumCache = {};
 }
 
 StandardObject.CONST_OBJECT_ADDRESS = function () {
@@ -122,10 +120,6 @@ StandardObject.prototype.onObjectInsert = function () {
     }
 }
 
-StandardObject.prototype.onObjectUpdate = function () {
-    
-}
-
 /**
  * Shall be execute only on the `onDBInsert` process of the recordContainer
  * of the `Address` entity. This will set the standard address on the
@@ -164,19 +158,13 @@ StandardObject.prototype.onCommunicationUpdate = function (pMediumID) {
     
     var mediumCategory = this._getMediumCategory(pMediumID);
     
-    var hasStandard = this._hasStandardCommunicationByMedium(this.scopeID, mediumCategory);
+    var contactID = this._getContactIdByCommunication(this.objectID);
+    
+    var hasStandard = this._hasStandardCommunicationByMedium(contactID, mediumCategory);
     if (!hasStandard)
         this._setStandardCommunication(this.objectID, 1);
 }
 
-StandardObject.prototype._onAddressUpdate = function (pAddressID) {
-    
-}
-
-StandardObject.prototype._onAddressDelete = function (pAddressID) {
-    
-}
-
 /**
  * Checks if the given contact ID has any address ID set. If there is a standard
  * address it will return `true`, otherwise `false`. This function asserts that
@@ -239,9 +227,7 @@ StandardObject.prototype._getCompanyStandardAddress = function (pOrganisationID)
  * @return {Boolean} If the contact already has a standard addres with the given
  * medium category.
  */
-StandardObject.prototype._hasStandardCommunicationByMedium = function (pContactID, pMediumCategory) {
-    logging.log("Contact: " + pContactID)
-   
+StandardObject.prototype._hasStandardCommunicationByMedium = function (pContactID, pMediumCategory) {   
     var dbResult = db.array(db.COLUMN, "select CHAR_VALUE from COMMUNICATION"
         + " left join AB_KEYWORD_ENTRY on KEYID = MEDIUM_ID"
         + " left join AB_KEYWORD_ATTRIBUTERELATION on AB_KEYWORD_ENTRY_ID = AB_KEYWORD_ENTRYID and AB_KEYWORD_ATTRIBUTE_ID = '7250ff28-1d48-41cc-bb36-8c33ace341bb'"
@@ -280,4 +266,14 @@ StandardObject.prototype._setStandardCommunication = function (pCommunicationID,
         db.getColumnTypes("COMMUNICATION", ["STANDARD"]), 
         [pValue], 
         "COMMUNICATIONID = '" + pCommunicationID + "'")
+}
+
+/**
+ * Will return the Contact ID by the given communication ID.
+ * 
+ * @param pCommunicationID {String} Communication ID to get the contact ID for.
+ * @return The contact ID.
+ */
+StandardObject.prototype._getContactIdByCommunication = function (pCommunicationID) {
+    return db.cell("select CONTACT_ID from COMMUNICATION where COMMUNICATIONID = '" + pCommunicationID + "'")
 }
\ No newline at end of file
-- 
GitLab