From 4929febdb3fb4add482a09a35ee27a78ce9883e4 Mon Sep 17 00:00:00 2001
From: "d.lechner" <d.lechner@adito.de>
Date: Wed, 24 Apr 2019 08:56:22 +0200
Subject: [PATCH] DocumentTemplateCategory

---
 .../DocumentTemplateTypeCategory_entity.aod   | 63 ++++++++++++++++++-
 .../recordcontainers/db/conditionProcess.js   | 27 ++++++++
 .../DocumentTemplate_entity.aod               | 10 +++
 .../classification/stateProcess.js            |  8 +++
 .../usagefilter_param/valueProcess.js         |  7 +++
 5 files changed, 114 insertions(+), 1 deletion(-)
 create mode 100644 entity/DocumentTemplateTypeCategory_entity/recordcontainers/db/conditionProcess.js
 create mode 100644 entity/DocumentTemplate_entity/entityfields/classification/stateProcess.js
 create mode 100644 entity/DocumentTemplate_entity/entityfields/documenttemplatetypecategory/children/usagefilter_param/valueProcess.js

diff --git a/entity/DocumentTemplateTypeCategory_entity/DocumentTemplateTypeCategory_entity.aod b/entity/DocumentTemplateTypeCategory_entity/DocumentTemplateTypeCategory_entity.aod
index be6730b4f07..04a41c04f80 100644
--- a/entity/DocumentTemplateTypeCategory_entity/DocumentTemplateTypeCategory_entity.aod
+++ b/entity/DocumentTemplateTypeCategory_entity/DocumentTemplateTypeCategory_entity.aod
@@ -2,13 +2,74 @@
 <entity xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.3.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/entity/1.3.1">
   <name>DocumentTemplateTypeCategory_entity</name>
   <majorModelMode>DISTRIBUTED</majorModelMode>
+  <recordContainer>db</recordContainer>
   <entityFields>
     <entityProvider>
       <name>#PROVIDER</name>
     </entityProvider>
     <entityParameter>
-      <name>usageFilterParam</name>
+      <name>usageFilter_param</name>
+      <expose v="true" />
+      <triggerRecalculation v="true" />
       <description>PARAMETER</description>
     </entityParameter>
+    <entityField>
+      <name>AB_KEYWORD_ENTRYID</name>
+    </entityField>
+    <entityField>
+      <name>KEYID</name>
+    </entityField>
+    <entityField>
+      <name>TITLE</name>
+    </entityField>
+    <entityProvider>
+      <name>ByCategory</name>
+      <fieldType>DEPENDENCY_IN</fieldType>
+      <recordContainer>db</recordContainer>
+      <dependencies>
+        <entityDependency>
+          <name>5eb6b17c-8c13-48df-84d5-a949b7d21cf3</name>
+          <entityName>DocumentTemplate_entity</entityName>
+          <fieldName>DocumentTemplateTypeCategory</fieldName>
+          <isConsumer v="false" />
+        </entityDependency>
+      </dependencies>
+      <children>
+        <entityParameter>
+          <name>usageFilter_param</name>
+          <expose v="true" />
+        </entityParameter>
+      </children>
+    </entityProvider>
   </entityFields>
+  <recordContainers>
+    <dbRecordContainer>
+      <name>db</name>
+      <alias>Data_alias</alias>
+      <conditionProcess>%aditoprj%/entity/DocumentTemplateTypeCategory_entity/recordcontainers/db/conditionProcess.js</conditionProcess>
+      <linkInformation>
+        <linkInformation>
+          <name>6cfa2424-b81b-4750-ae43-e3b1126eab0a</name>
+          <tableName>AB_KEYWORD_ENTRY</tableName>
+          <primaryKey>AB_KEYWORD_ENTRYID</primaryKey>
+          <isUIDTable v="true" />
+          <readonly v="false" />
+        </linkInformation>
+      </linkInformation>
+      <recordFieldMappings>
+        <dbRecordFieldMapping>
+          <name>AB_KEYWORD_ENTRYID.value</name>
+          <recordfield>AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID</recordfield>
+        </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>KEYID.value</name>
+          <recordfield>AB_KEYWORD_ENTRY.KEYID</recordfield>
+        </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>TITLE.value</name>
+          <recordfield>AB_KEYWORD_ENTRY.TITLE</recordfield>
+        </dbRecordFieldMapping>
+      </recordFieldMappings>
+    </dbRecordContainer>
+  </recordContainers>
 </entity>
diff --git a/entity/DocumentTemplateTypeCategory_entity/recordcontainers/db/conditionProcess.js b/entity/DocumentTemplateTypeCategory_entity/recordcontainers/db/conditionProcess.js
new file mode 100644
index 00000000000..468d604de3c
--- /dev/null
+++ b/entity/DocumentTemplateTypeCategory_entity/recordcontainers/db/conditionProcess.js
@@ -0,0 +1,27 @@
+import("system.logging");
+import("system.db");
+import("system.vars");
+import("system.result");
+import("KeywordRegistry_basic");
+import("Sql_lib");
+import("Keyword_lib");
+
+var cond = SqlCondition.begin()
+                       .andPrepare("AB_KEYWORD_ENTRY.CONTAINER", $KeywordRegistry.documentTemplateTypeCategory()());
+
+logging.log("hallo");
+
+var usageFilter = vars.get("$param.usageFilter_param");
+if (usageFilter)
+{
+    var keywordAttribute = new KeywordAttribute($KeywordRegistry.documentTemplateTypeCategory(), usageFilter);
+    cond.andAttachPrepared(SqlCondition.begin()
+                                       .andPrepare("AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ATTRIBUTE_ID", keywordAttribute.id)
+                                       .andPrepare("AB_KEYWORD_ATTRIBUTERELATION." + keywordAttribute.dbField, "1")
+                                       .buildSql("AB_KEYWORD_ENTRY.AB_KEYWORD_ENTRYID in (\n\
+                                                    select AB_KEYWORD_ATTRIBUTERELATION.AB_KEYWORD_ENTRY_ID \n\
+                                                    from AB_KEYWORD_ATTRIBUTERELATION ", null, ")"));
+}
+
+cond = db.translateStatement(cond.build("1 = 2"));
+result.string(cond);
\ No newline at end of file
diff --git a/entity/DocumentTemplate_entity/DocumentTemplate_entity.aod b/entity/DocumentTemplate_entity/DocumentTemplate_entity.aod
index c2c38566479..10c12a00a1e 100644
--- a/entity/DocumentTemplate_entity/DocumentTemplate_entity.aod
+++ b/entity/DocumentTemplate_entity/DocumentTemplate_entity.aod
@@ -162,13 +162,23 @@
       <name>CLASSIFICATION</name>
       <title>Classification</title>
       <consumer>DocumentTemplateTypeCategory</consumer>
+      <state>DISABLED</state>
+      <stateProcess>%aditoprj%/entity/DocumentTemplate_entity/entityfields/classification/stateProcess.js</stateProcess>
     </entityField>
     <entityConsumer>
       <name>DocumentTemplateTypeCategory</name>
       <fieldType>DEPENDENCY_OUT</fieldType>
       <dependency>
         <name>dependency</name>
+        <entityName>DocumentTemplateTypeCategory_entity</entityName>
+        <fieldName>ByCategory</fieldName>
       </dependency>
+      <children>
+        <entityParameter>
+          <name>usageFilter_param</name>
+          <valueProcess>%aditoprj%/entity/DocumentTemplate_entity/entityfields/documenttemplatetypecategory/children/usagefilter_param/valueProcess.js</valueProcess>
+        </entityParameter>
+      </children>
     </entityConsumer>
   </entityFields>
   <recordContainers>
diff --git a/entity/DocumentTemplate_entity/entityfields/classification/stateProcess.js b/entity/DocumentTemplate_entity/entityfields/classification/stateProcess.js
new file mode 100644
index 00000000000..bada82b49dc
--- /dev/null
+++ b/entity/DocumentTemplate_entity/entityfields/classification/stateProcess.js
@@ -0,0 +1,8 @@
+import("system.vars");
+import("system.result");
+import("system.neon");
+
+if(vars.get("$field.TYPE") != "")
+{
+    result.string(neon.COMPONENTSTATE_EDITABLE);
+}
\ No newline at end of file
diff --git a/entity/DocumentTemplate_entity/entityfields/documenttemplatetypecategory/children/usagefilter_param/valueProcess.js b/entity/DocumentTemplate_entity/entityfields/documenttemplatetypecategory/children/usagefilter_param/valueProcess.js
new file mode 100644
index 00000000000..362313e65fd
--- /dev/null
+++ b/entity/DocumentTemplate_entity/entityfields/documenttemplatetypecategory/children/usagefilter_param/valueProcess.js
@@ -0,0 +1,7 @@
+import("system.logging");
+import("system.vars");
+import("system.result");
+
+logging.log("aufruf");
+
+result.object(vars.get("$field.TYPE"));
\ No newline at end of file
-- 
GitLab