From e43d468b58d62e29427973bf9a257b940692aecf Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Thu, 24 Jan 2019 13:37:52 +0100
Subject: [PATCH] [Projekt: Entwicklung - Neon][TicketNr.:
 1032308][ObjectRelation-Entity erstellen]

---
 aliasDefinition/Data_alias/Data_alias.aod     | 149 +++++++++++++++++-
 .../ObjectRelation_entity.aod                 | 101 ++++++++++++
 .../ObjectRelation_entity/documentation.adoc  |   7 +
 .../entityfields/date_edit/valueProcess.js    |   6 +
 .../entityfields/date_new/valueProcess.js     |   6 +
 .../entityfields/user_edit/valueProcess.js    |   6 +
 .../entityfields/user_new/valueProcess.js     |   6 +
 .../AditoBasic/create_ab_objectrelation.xml   |  30 ++++
 others/db_changes/masterChangelog.xml         |   3 +
 9 files changed, 312 insertions(+), 2 deletions(-)
 create mode 100644 entity/ObjectRelation_entity/ObjectRelation_entity.aod
 create mode 100644 entity/ObjectRelation_entity/documentation.adoc
 create mode 100644 entity/ObjectRelation_entity/entityfields/date_edit/valueProcess.js
 create mode 100644 entity/ObjectRelation_entity/entityfields/date_new/valueProcess.js
 create mode 100644 entity/ObjectRelation_entity/entityfields/user_edit/valueProcess.js
 create mode 100644 entity/ObjectRelation_entity/entityfields/user_new/valueProcess.js
 create mode 100644 others/db_changes/data_alias/struct/AditoBasic/create_ab_objectrelation.xml

diff --git a/aliasDefinition/Data_alias/Data_alias.aod b/aliasDefinition/Data_alias/Data_alias.aod
index 2a88ca454c0..d272eef7e75 100644
--- a/aliasDefinition/Data_alias/Data_alias.aod
+++ b/aliasDefinition/Data_alias/Data_alias.aod
@@ -4968,8 +4968,8 @@
                 <size v="10" />
                 <scale v="0" />
                 <notNull v="true" />
-                <isUnique v="false" />
-                <index v="false" />
+                <isUnique v="true" />
+                <index v="true" />
                 <documentation></documentation>
                 <title></title>
                 <description></description>
@@ -5102,6 +5102,151 @@
               </entityFieldDb>
             </entityFields>
           </entityDb>
+          <entityDb>
+            <name>AB_OBJECTREALTION</name>
+            <dbName></dbName>
+            <idColumn>AB_OBJECTREALTIONID</idColumn>
+            <idGeneratorType v="0" />
+            <idGeneratorInterval v="1" />
+            <title></title>
+            <description></description>
+            <auditSyncConfig>
+              <name>auditSyncConfig</name>
+              <auditMode v="0" />
+              <syncActive v="false" />
+              <syncComplete v="true" />
+              <syncDirection v="1" />
+              <syncIds></syncIds>
+            </auditSyncConfig>
+            <entityFields>
+              <entityFieldDb>
+                <name>DATE_EDIT</name>
+                <dbName></dbName>
+                <primaryKey v="false" />
+                <columnType v="93" />
+                <size v="29" />
+                <scale v="9" />
+                <notNull v="false" />
+                <isUnique v="false" />
+                <index v="false" />
+                <documentation></documentation>
+                <title></title>
+                <description></description>
+              </entityFieldDb>
+              <entityFieldDb>
+                <name>AB_OBJECTREALTIONID</name>
+                <dbName></dbName>
+                <primaryKey v="true" />
+                <columnType v="1" />
+                <size v="36" />
+                <scale v="0" />
+                <notNull v="true" />
+                <isUnique v="true" />
+                <index v="false" />
+                <documentation></documentation>
+                <title></title>
+                <description></description>
+              </entityFieldDb>
+              <entityFieldDb>
+                <name>DATE_NEW</name>
+                <dbName></dbName>
+                <primaryKey v="false" />
+                <columnType v="93" />
+                <size v="29" />
+                <scale v="9" />
+                <notNull v="true" />
+                <isUnique v="false" />
+                <index v="false" />
+                <documentation></documentation>
+                <title></title>
+                <description></description>
+              </entityFieldDb>
+              <entityFieldDb>
+                <name>USER_NEW</name>
+                <dbName></dbName>
+                <primaryKey v="false" />
+                <columnType v="12" />
+                <size v="50" />
+                <scale v="0" />
+                <notNull v="true" />
+                <isUnique v="false" />
+                <index v="false" />
+                <documentation></documentation>
+                <title></title>
+                <description></description>
+              </entityFieldDb>
+              <entityFieldDb>
+                <name>USER_EDIT</name>
+                <dbName></dbName>
+                <primaryKey v="false" />
+                <columnType v="12" />
+                <size v="50" />
+                <scale v="0" />
+                <notNull v="false" />
+                <isUnique v="false" />
+                <index v="false" />
+                <documentation></documentation>
+                <title></title>
+                <description></description>
+              </entityFieldDb>
+              <entityFieldDb>
+                <name>OBJECT2_ROWID</name>
+                <dbName></dbName>
+                <primaryKey v="false" />
+                <columnType v="1" />
+                <size v="63" />
+                <scale v="0" />
+                <notNull v="true" />
+                <isUnique v="false" />
+                <index v="false" />
+                <documentation></documentation>
+                <title></title>
+                <description></description>
+              </entityFieldDb>
+              <entityFieldDb>
+                <name>OBJECT2_TYPE</name>
+                <dbName></dbName>
+                <primaryKey v="false" />
+                <columnType v="12" />
+                <size v="63" />
+                <scale v="0" />
+                <notNull v="true" />
+                <isUnique v="false" />
+                <index v="false" />
+                <documentation></documentation>
+                <title></title>
+                <description></description>
+              </entityFieldDb>
+              <entityFieldDb>
+                <name>OBJECT1_TYPE</name>
+                <dbName></dbName>
+                <primaryKey v="false" />
+                <columnType v="12" />
+                <size v="50" />
+                <scale v="0" />
+                <notNull v="true" />
+                <isUnique v="false" />
+                <index v="false" />
+                <documentation></documentation>
+                <title></title>
+                <description></description>
+              </entityFieldDb>
+              <entityFieldDb>
+                <name>OBJECT1_ROWID</name>
+                <dbName></dbName>
+                <primaryKey v="false" />
+                <columnType v="1" />
+                <size v="36" />
+                <scale v="0" />
+                <notNull v="true" />
+                <isUnique v="false" />
+                <index v="false" />
+                <documentation></documentation>
+                <title></title>
+                <description></description>
+              </entityFieldDb>
+            </entityFields>
+          </entityDb>
         </entities>
       </entityGroup>
     </aliasDefDb>
diff --git a/entity/ObjectRelation_entity/ObjectRelation_entity.aod b/entity/ObjectRelation_entity/ObjectRelation_entity.aod
new file mode 100644
index 00000000000..a51e370c886
--- /dev/null
+++ b/entity/ObjectRelation_entity/ObjectRelation_entity.aod
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entity xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/entity/1.1.1">
+  <name>ObjectRelation_entity</name>
+  <majorModelMode>DISTRIBUTED</majorModelMode>
+  <documentation>%aditoprj%/entity/ObjectRelation_entity/documentation.adoc</documentation>
+  <entityFields>
+    <entityIncomingField>
+      <name>#INCOMING</name>
+    </entityIncomingField>
+    <entityField>
+      <name>OBJECT1_TYPE</name>
+    </entityField>
+    <entityField>
+      <name>OBJECT1_ROWID</name>
+    </entityField>
+    <entityField>
+      <name>AB_OBJECTRELATIONID</name>
+    </entityField>
+    <entityField>
+      <name>DATE_NEW</name>
+      <contentType>DATE</contentType>
+      <outputFormat>yyyy-MM-dd&amp;apos;T&amp;apos;HH:mm:ssZ</outputFormat>
+      <mandatory v="true" />
+      <valueProcess>%aditoprj%/entity/ObjectRelation_entity/entityfields/date_new/valueProcess.js</valueProcess>
+    </entityField>
+    <entityField>
+      <name>USER_NEW</name>
+      <mandatory v="true" />
+      <valueProcess>%aditoprj%/entity/ObjectRelation_entity/entityfields/user_new/valueProcess.js</valueProcess>
+    </entityField>
+    <entityField>
+      <name>DATE_EDIT</name>
+      <contentType>DATE</contentType>
+      <outputFormat>yyyy-MM-dd&amp;apos;T&amp;apos;HH:mm:ssZ</outputFormat>
+      <valueProcess>%aditoprj%/entity/ObjectRelation_entity/entityfields/date_edit/valueProcess.js</valueProcess>
+    </entityField>
+    <entityField>
+      <name>USER_EDIT</name>
+      <valueProcess>%aditoprj%/entity/ObjectRelation_entity/entityfields/user_edit/valueProcess.js</valueProcess>
+    </entityField>
+    <entityField>
+      <name>OBJECT2_ROWID</name>
+    </entityField>
+    <entityField>
+      <name>OBJECT2_TYPE</name>
+    </entityField>
+  </entityFields>
+  <recordContainers>
+    <dbRecordContainer>
+      <name>db</name>
+      <alias>Data_alias</alias>
+      <linkInformation>
+        <linkInformation>
+          <name>a654da8b-bb3f-4a8c-b4c3-4916c04b7a17</name>
+          <tableName>AB_OBJECTREALTION</tableName>
+          <primaryKey>AB_OBJECTREALTIONID</primaryKey>
+          <isUIDTable v="true" />
+          <readonly v="false" />
+        </linkInformation>
+      </linkInformation>
+      <recordFieldMappings>
+        <dbRecordFieldMapping>
+          <name>AB_OBJECTRELATIONID.value</name>
+          <recordfield>AB_OBJECTREALTION.AB_OBJECTREALTIONID</recordfield>
+        </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>OBJECT1_ROWID.value</name>
+          <recordfield>AB_OBJECTREALTION.OBJECT1_ROWID</recordfield>
+        </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>OBJECT1_TYPE.value</name>
+          <recordfield>AB_OBJECTREALTION.OBJECT1_TYPE</recordfield>
+        </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>OBJECT2_ROWID.value</name>
+          <recordfield>AB_OBJECTREALTION.OBJECT2_ROWID</recordfield>
+        </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>OBJECT2_TYPE.value</name>
+          <recordfield>AB_OBJECTREALTION.OBJECT2_TYPE</recordfield>
+        </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>DATE_EDIT.value</name>
+          <recordfield>AB_OBJECTREALTION.DATE_EDIT</recordfield>
+        </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>DATE_NEW.value</name>
+          <recordfield>AB_OBJECTREALTION.DATE_NEW</recordfield>
+        </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>USER_EDIT.value</name>
+          <recordfield>AB_OBJECTREALTION.USER_EDIT</recordfield>
+        </dbRecordFieldMapping>
+        <dbRecordFieldMapping>
+          <name>USER_NEW.value</name>
+          <recordfield>AB_OBJECTREALTION.USER_NEW</recordfield>
+        </dbRecordFieldMapping>
+      </recordFieldMappings>
+    </dbRecordContainer>
+  </recordContainers>
+</entity>
diff --git a/entity/ObjectRelation_entity/documentation.adoc b/entity/ObjectRelation_entity/documentation.adoc
new file mode 100644
index 00000000000..5b71000497c
--- /dev/null
+++ b/entity/ObjectRelation_entity/documentation.adoc
@@ -0,0 +1,7 @@
+== Object Relation ==
+
+This entity is for relation between Objects. It should be used if everything 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. 
+Use Context_lib for this.
\ No newline at end of file
diff --git a/entity/ObjectRelation_entity/entityfields/date_edit/valueProcess.js b/entity/ObjectRelation_entity/entityfields/date_edit/valueProcess.js
new file mode 100644
index 00000000000..710ac8a06a9
--- /dev/null
+++ b/entity/ObjectRelation_entity/entityfields/date_edit/valueProcess.js
@@ -0,0 +1,6 @@
+import("system.vars");
+import("system.result");
+import("system.neon");
+
+if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT)
+    result.string(vars.getString("$sys.date"));
\ No newline at end of file
diff --git a/entity/ObjectRelation_entity/entityfields/date_new/valueProcess.js b/entity/ObjectRelation_entity/entityfields/date_new/valueProcess.js
new file mode 100644
index 00000000000..3a0d59096cd
--- /dev/null
+++ b/entity/ObjectRelation_entity/entityfields/date_new/valueProcess.js
@@ -0,0 +1,6 @@
+import("system.vars");
+import("system.result");
+import("system.neon");
+
+if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
+    result.string(vars.getString("$sys.date"));
\ No newline at end of file
diff --git a/entity/ObjectRelation_entity/entityfields/user_edit/valueProcess.js b/entity/ObjectRelation_entity/entityfields/user_edit/valueProcess.js
new file mode 100644
index 00000000000..1581e18d976
--- /dev/null
+++ b/entity/ObjectRelation_entity/entityfields/user_edit/valueProcess.js
@@ -0,0 +1,6 @@
+import("system.vars");
+import("system.result");
+import("system.neon");
+
+if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT)
+    result.string(vars.getString("$sys.user"));
\ No newline at end of file
diff --git a/entity/ObjectRelation_entity/entityfields/user_new/valueProcess.js b/entity/ObjectRelation_entity/entityfields/user_new/valueProcess.js
new file mode 100644
index 00000000000..7c566863b49
--- /dev/null
+++ b/entity/ObjectRelation_entity/entityfields/user_new/valueProcess.js
@@ -0,0 +1,6 @@
+import("system.vars");
+import("system.result");
+import("system.neon");
+
+if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
+    result.string(vars.getString("$sys.user"));
\ No newline at end of file
diff --git a/others/db_changes/data_alias/struct/AditoBasic/create_ab_objectrelation.xml b/others/db_changes/data_alias/struct/AditoBasic/create_ab_objectrelation.xml
new file mode 100644
index 00000000000..f57da00c892
--- /dev/null
+++ b/others/db_changes/data_alias/struct/AditoBasic/create_ab_objectrelation.xml
@@ -0,0 +1,30 @@
+<?xml version="1.1" encoding="UTF-8" standalone="no"?>
+<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
+    <changeSet author="j.hoermann" id="4940acf4-7436-406b-9893-a1f1441ece37">
+        <createTable tableName="AB_OBJECTREALTION">
+            <column name="AB_OBJECTREALTIONID" type="CHAR(36)">
+                <constraints primaryKey="true" primaryKeyName="PK_AB_OBJECTREALTION_AB_OBJECTREALTIONID"/>
+            </column>
+            <column name="OBJECT1_TYPE" type="NVARCHAR(50)">
+                <constraints nullable="false"/>
+            </column>
+            <column name="OBJECT1_ROWID" type="CHAR(36)">
+                <constraints nullable="false"/>
+            </column>
+            <column name="OBJECT2_TYPE" type="NVARCHAR(63)">
+                <constraints nullable="false"/>
+            </column>
+            <column name="OBJECT2_ROWID" type="CHAR(63)">
+                <constraints nullable="false"/>
+            </column>
+            <column name="USER_NEW" type="NVARCHAR(50)">
+                <constraints nullable="false"/>
+            </column>
+            <column name="USER_EDIT" type="NVARCHAR(50)"/>
+            <column name="DATE_NEW" type="TIMESTAMP">
+                <constraints nullable="false"/>
+            </column>
+            <column name="DATE_EDIT" type="TIMESTAMP"/>
+        </createTable>
+    </changeSet>
+</databaseChangeLog>
\ No newline at end of file
diff --git a/others/db_changes/masterChangelog.xml b/others/db_changes/masterChangelog.xml
index 5615befbc5f..4b7365bb064 100644
--- a/others/db_changes/masterChangelog.xml
+++ b/others/db_changes/masterChangelog.xml
@@ -1,5 +1,7 @@
 <?xml version="1.1" encoding="UTF-8" standalone="no"?>
 <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
+    <include file="data_alias/struct/AditoBasic/create_ab_objectrelation.xml"/>
+    
     <include file="data_alias/struct/create_pers.xml"/>
     <include file="data_alias/struct/create_org.xml"/>
     <include file="data_alias/struct/create_relation.xml"/>    
@@ -26,6 +28,7 @@
     <include file="data_alias/struct/create_countryinfo.xml"/>
     <include file="data_alias/struct/create_timetracking.xml"/>
     <include file="data_alias/struct/create_task.xml"/>
+    
     <include file="data_alias/data/example_org/ORG_privat.xml"/>
     <include file="data_alias/data/example_org/ORG_gfk.xml"/>
     <include file="data_alias/data/example_org/ORG_mnf.xml"/>
-- 
GitLab