From 54cd71bbce186d5d1a22010f0d40b5bef401c541 Mon Sep 17 00:00:00 2001
From: "S.Listl" <s.listl@adito.de>
Date: Thu, 28 Nov 2019 08:44:30 +0000
Subject: [PATCH] Attribute usage delete/update fix

(cherry picked from commit 39c162bff8e9472091df9167f0b4790a01bbb3dd)
---
 .../AttributeUsage_entity.aod                     |  2 +-
 .../entityfields/ab_attribute_id/valueProcess.js  |  6 ++----
 .../object_type/displayValueProcess.js            |  6 +++++-
 .../entityfields/object_type/valueProcess.js      |  5 -----
 .../recordcontainers/db/onDBDelete.js             |  4 ++--
 .../recordcontainers/db/onDBInsert.js             |  4 ++--
 .../recordcontainers/db/onDBUpdate.js             | 15 +++++++++------
 7 files changed, 21 insertions(+), 21 deletions(-)
 delete mode 100644 entity/AttributeUsage_entity/entityfields/object_type/valueProcess.js

diff --git a/entity/AttributeUsage_entity/AttributeUsage_entity.aod b/entity/AttributeUsage_entity/AttributeUsage_entity.aod
index 43d1265c56..6ebf46863e 100644
--- a/entity/AttributeUsage_entity/AttributeUsage_entity.aod
+++ b/entity/AttributeUsage_entity/AttributeUsage_entity.aod
@@ -14,7 +14,6 @@
       <name>OBJECT_TYPE</name>
       <title>Module</title>
       <consumer>Context</consumer>
-      <valueProcess>%aditoprj%/entity/AttributeUsage_entity/entityfields/object_type/valueProcess.js</valueProcess>
       <displayValueProcess>%aditoprj%/entity/AttributeUsage_entity/entityfields/object_type/displayValueProcess.js</displayValueProcess>
       <onValueChangeTypes>
         <element>MASK</element>
@@ -46,6 +45,7 @@
     <entityParameter>
       <name>AttributeId_param</name>
       <expose v="true" />
+      <mandatory v="true" />
       <description>PARAMETER</description>
     </entityParameter>
     <entityField>
diff --git a/entity/AttributeUsage_entity/entityfields/ab_attribute_id/valueProcess.js b/entity/AttributeUsage_entity/entityfields/ab_attribute_id/valueProcess.js
index 37bcaa77b0..11723fd793 100644
--- a/entity/AttributeUsage_entity/entityfields/ab_attribute_id/valueProcess.js
+++ b/entity/AttributeUsage_entity/entityfields/ab_attribute_id/valueProcess.js
@@ -2,7 +2,5 @@ import("system.vars");
 import("system.result");
 import("system.neon");
 
-if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.exists("$param.AttributeId_param") && vars.get("$param.AttributeId_param") != null)
-    result.string(vars.get("$param.AttributeId_param"));
-else if (vars.get("$this.value"))
-    result.string(vars.get("$this.value"));
\ No newline at end of file
+if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
+    result.string(vars.get("$param.AttributeId_param"));
\ No newline at end of file
diff --git a/entity/AttributeUsage_entity/entityfields/object_type/displayValueProcess.js b/entity/AttributeUsage_entity/entityfields/object_type/displayValueProcess.js
index 703c8341b7..84204be06f 100644
--- a/entity/AttributeUsage_entity/entityfields/object_type/displayValueProcess.js
+++ b/entity/AttributeUsage_entity/entityfields/object_type/displayValueProcess.js
@@ -3,7 +3,11 @@ import("system.neon");
 import("system.vars");
 import("system.project");
 
-if (vars.exists("$field.OBJECT_TYPE") && vars.get("$field.OBJECT_TYPE"))
+if (vars.get("$field.OBJECT_TYPE"))
 {
+    //this is a workaround to get the old value in the onDBUpdate process
+    //@TODO replace this when it's possible to get the old value in onDBUpdate
+    vars.set("$context.originalObjectType", vars.get("$field.OBJECT_TYPE"));
+    
     result.string(project.getDataModel(project.DATAMODEL_KIND_CONTEXT, vars.get("$field.OBJECT_TYPE"))[1]);
 }
\ No newline at end of file
diff --git a/entity/AttributeUsage_entity/entityfields/object_type/valueProcess.js b/entity/AttributeUsage_entity/entityfields/object_type/valueProcess.js
deleted file mode 100644
index 40b7c76fc5..0000000000
--- a/entity/AttributeUsage_entity/entityfields/object_type/valueProcess.js
+++ /dev/null
@@ -1,5 +0,0 @@
-import("system.vars");
-
-//this is a workaround to get the old value in the onDBUpdate process
-//@TODO replace this when it's possible to get the old value in onDBUpdate
-vars.set("$context.originalObjectType", vars.get("$field.OBJECT_TYPE"));
\ No newline at end of file
diff --git a/entity/AttributeUsage_entity/recordcontainers/db/onDBDelete.js b/entity/AttributeUsage_entity/recordcontainers/db/onDBDelete.js
index c3a22ddade..3cf3c0ecbe 100644
--- a/entity/AttributeUsage_entity/recordcontainers/db/onDBDelete.js
+++ b/entity/AttributeUsage_entity/recordcontainers/db/onDBDelete.js
@@ -2,6 +2,6 @@ import("system.vars");
 import("Attribute_lib");
 
 var data = vars.get("$local.rowdata");
-var objectType = data["OBJECT_TYPE.value"];
+var objectType = data["AB_ATTRIBUTEUSAGE.OBJECT_TYPE"];
 
-AttributeUsageUtil.deleteChildrenUsages(attributeId, objectType);
\ No newline at end of file
+AttributeUsageUtil.deleteChildrenUsages(vars.get("$field.AB_ATTRIBUTE_ID"), objectType);
\ No newline at end of file
diff --git a/entity/AttributeUsage_entity/recordcontainers/db/onDBInsert.js b/entity/AttributeUsage_entity/recordcontainers/db/onDBInsert.js
index cb887e0535..63832c618e 100644
--- a/entity/AttributeUsage_entity/recordcontainers/db/onDBInsert.js
+++ b/entity/AttributeUsage_entity/recordcontainers/db/onDBInsert.js
@@ -2,8 +2,8 @@ import("system.vars");
 import("Attribute_lib");
 
 var data = vars.get("$local.rowdata");
-var attributeId = data["AB_ATTRIBUTE_ID.value"];
-var objectType = data["OBJECT_TYPE.value"];
+var attributeId = data["AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID"];
+var objectType = data["AB_ATTRIBUTEUSAGE.OBJECT_TYPE"];
 
 AttributeUsageUtil.insertChildrenUsages(attributeId, objectType);
 AttributeUsageUtil.removeDuplicates(attributeId);
\ No newline at end of file
diff --git a/entity/AttributeUsage_entity/recordcontainers/db/onDBUpdate.js b/entity/AttributeUsage_entity/recordcontainers/db/onDBUpdate.js
index c32017dd3c..1915602ab9 100644
--- a/entity/AttributeUsage_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/AttributeUsage_entity/recordcontainers/db/onDBUpdate.js
@@ -1,10 +1,13 @@
 import("system.vars");
 import("Attribute_lib");
 
-var data = vars.get("$local.rowdata");
-var attributeId = data["AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID"];
-var oldObjectType = vars.get("$context.originalObjectType");
-var newObjectType = data["AB_ATTRIBUTEUSAGE.OBJECT_TYPE"];
-
-AttributeUsageUtil.updateChildrenUsages(attributeId, oldObjectType, newObjectType);
+if (vars.get("$local.changed").indexOf("AB_ATTRIBUTEUSAGE.OBJECT_TYPE") != -1)
+{
+    var data = vars.get("$local.rowdata");
+    var attributeId = vars.get("$field.AB_ATTRIBUTE_ID");
+    var oldObjectType = vars.get("$context.originalObjectType");
+    var newObjectType = data["AB_ATTRIBUTEUSAGE.OBJECT_TYPE"];
+    
+    AttributeUsageUtil.updateChildrenUsages(attributeId, oldObjectType, newObjectType);
+}
 AttributeUsageUtil.removeDuplicates(attributeId);
\ No newline at end of file
-- 
GitLab