From a94a8a088eb8018fb0be452f4af82178c7bcbb8b Mon Sep 17 00:00:00 2001 From: "j.goderbauer" <j.goderbauer@adito.de> Date: Tue, 16 Apr 2019 14:18:30 +0200 Subject: [PATCH] Refactoring Audit: Historylogger (3) --- aliasDefinition/Data_alias/Data_alias.aod | 37 +++++++++++++++- .../LogHistory_entity/LogHistory_entity.aod | 16 +------ .../recordcontainers/jdito/contentProcess.js | 39 +++-------------- .../Organisation_entity.aod | 15 ------- .../children/contactid_param/valueProcess.js | 4 -- .../children/tablename_param/valueProcess.js | 14 +++++-- .../tablenameid_param/valueProcess.js | 4 -- entity/Person_entity/Person_entity.aod | 14 ------- .../children/contactid_param/valueProcess.js | 4 -- .../children/tablename_param/valueProcess.js | 2 +- .../tablenameid_param/valueProcess.js | 4 -- process/Loghistory_lib/process.js | 42 +++++++++---------- 12 files changed, 74 insertions(+), 121 deletions(-) delete mode 100644 entity/Organisation_entity/entityfields/loghistoryconsumer/children/contactid_param/valueProcess.js delete mode 100644 entity/Organisation_entity/entityfields/loghistoryconsumer/children/tablenameid_param/valueProcess.js delete mode 100644 entity/Person_entity/entityfields/loghistoryconsumer/children/contactid_param/valueProcess.js delete mode 100644 entity/Person_entity/entityfields/loghistoryconsumer/children/tablenameid_param/valueProcess.js diff --git a/aliasDefinition/Data_alias/Data_alias.aod b/aliasDefinition/Data_alias/Data_alias.aod index b2e73a04e97..789fed08a6e 100644 --- a/aliasDefinition/Data_alias/Data_alias.aod +++ b/aliasDefinition/Data_alias/Data_alias.aod @@ -4534,7 +4534,7 @@ <description></description> <auditSyncConfig> <name>auditSyncConfig</name> - <auditMode v="0" /> + <auditMode v="1" /> <syncActive v="false" /> <syncComplete v="true" /> <syncDirection v="1" /> @@ -4568,6 +4568,13 @@ <documentation></documentation> <title></title> <description></description> + <customProperties> + <customBooleanProperty> + <name>log</name> + <global v="false" /> + <property v="true" /> + </customBooleanProperty> + </customProperties> </entityFieldDb> <entityFieldDb> <name>NUMBER_VALUE</name> @@ -4582,6 +4589,13 @@ <documentation></documentation> <title></title> <description></description> + <customProperties> + <customBooleanProperty> + <name>log</name> + <global v="false" /> + <property v="true" /> + </customBooleanProperty> + </customProperties> </entityFieldDb> <entityFieldDb> <name>AB_ATTRIBUTERELATIONID</name> @@ -4624,6 +4638,13 @@ <documentation></documentation> <title></title> <description></description> + <customProperties> + <customBooleanProperty> + <name>log</name> + <global v="false" /> + <property v="true" /> + </customBooleanProperty> + </customProperties> </entityFieldDb> <entityFieldDb> <name>AB_ATTRIBUTE_ID</name> @@ -4652,6 +4673,13 @@ <documentation></documentation> <title></title> <description></description> + <customProperties> + <customBooleanProperty> + <name>log</name> + <global v="false" /> + <property v="true" /> + </customBooleanProperty> + </customProperties> </entityFieldDb> <entityFieldDb> <name>DATE_EDIT</name> @@ -4722,6 +4750,13 @@ <documentation></documentation> <title></title> <description></description> + <customProperties> + <customBooleanProperty> + <name>log</name> + <global v="false" /> + <property v="true" /> + </customBooleanProperty> + </customProperties> </entityFieldDb> </entityFields> </entityDb> diff --git a/entity/LogHistory_entity/LogHistory_entity.aod b/entity/LogHistory_entity/LogHistory_entity.aod index a445357040b..5d0922509ed 100644 --- a/entity/LogHistory_entity/LogHistory_entity.aod +++ b/entity/LogHistory_entity/LogHistory_entity.aod @@ -31,13 +31,6 @@ <contentType>TEXT</contentType> <mandatory v="true" /> </entityField> - <entityParameter> - <name>tablenameId_param</name> - <expose v="true" /> - <triggerRecalculation v="true" /> - <mandatory v="true" /> - <description>PARAMETER</description> - </entityParameter> <entityProvider> <name>LogHistoryProvider</name> <fieldType>DEPENDENCY_IN</fieldType> @@ -56,13 +49,6 @@ </entityDependency> </dependencies> </entityProvider> - <entityParameter> - <name>contactId_param</name> - <expose v="true" /> - <triggerRecalculation v="true" /> - <mandatory v="false" /> - <description>PARAMETER</description> - </entityParameter> <entityParameter> <name>tablenames_param</name> <expose v="true" /> @@ -121,7 +107,7 @@ <name>jdito</name> <jDitoRecordAlias>Data_alias</jDitoRecordAlias> <isPageable v="false" /> - <isSortable v="true" /> + <isSortable v="false" /> <contentProcess>%aditoprj%/entity/LogHistory_entity/recordcontainers/jdito/contentProcess.js</contentProcess> <rowCountProcess>%aditoprj%/entity/LogHistory_entity/recordcontainers/jdito/rowCountProcess.js</rowCountProcess> <recordFields> diff --git a/entity/LogHistory_entity/recordcontainers/jdito/contentProcess.js b/entity/LogHistory_entity/recordcontainers/jdito/contentProcess.js index 10c8b09f181..ee5db9ec132 100644 --- a/entity/LogHistory_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/LogHistory_entity/recordcontainers/jdito/contentProcess.js @@ -1,3 +1,4 @@ +import("Util_lib"); import("system.datetime"); import("system.result"); import("system.logging"); @@ -29,17 +30,11 @@ else } } -//var startRow = vars.get("$local.startrow"); -//var pageSize = vars.get("$local.pagesize");//TODO: pageable? ja oder nein? - var dataQuery = recordCond.buildSql("select AB_LOGHISTORY.DATE_NEW, AB_LOGHISTORY.USER_NEW, AB_LOGHISTORY.DESCRIPTION \n\ - from AB_LOGHISTORY ", "1 = 2", _transformOrder(vars.get("$local.order"))); - -logging.log("dataQuery>>>" + db.translateStatement(dataQuery)); + from AB_LOGHISTORY ", "1 = 2", "order by DATE_NEW desc, USER_NEW asc"); var data = db.table(dataQuery); var resultData = _groupData(data); - result.object(resultData); function _makeGroupingIdentifier(pDatetime, pUser) @@ -81,8 +76,9 @@ function _groupData(pData) function _getTableNameCondition() { var tableNameCond = SqlCondition.begin(); - var tableNames = JSON.parse(vars.get("$param.tablenames_param")); + var tableNamesList = JSON.parse(vars.get("$param.tablenames_param")); + //returns the condition for one entry in the tableNamesList var _getCond = function(pDefinition) { var resCond = SqlCondition.begin(); @@ -94,34 +90,9 @@ function _getTableNameCondition() return resCond; }; - tableNames.forEach(function(e){ + tableNamesList.forEach(function(e){ tableNameCond.orSqlCondition(_getCond.call(this, e)); }); return tableNameCond; -} - -function _transformOrder(orderDefinition) -{ - //ignore description sort, since this is not possible in all database-systems - var config = { - "DATE_NEW.value": "AB_LOGHISTORY.DATE_NEW", - "USER_NEW.value": "AB_LOGHISTORY.USER_NEW" - }; - - var orderByElements = []; - for (var fieldExpression in orderDefinition) - { - var dbColumn = config[fieldExpression]; - if (dbColumn) - { - var sort = orderDefinition[fieldExpression] == "DOWN" ? "desc" : "asc" - orderByElements.push(dbColumn + " " + sort) - } - } - - if (orderByElements.length == 0) - return "order by DATE_NEW desc, USER_NEW asc"; - - return "order by " + orderByElements.join(", "); } \ No newline at end of file diff --git a/entity/Organisation_entity/Organisation_entity.aod b/entity/Organisation_entity/Organisation_entity.aod index c2bce1ce62f..3983f79afdc 100644 --- a/entity/Organisation_entity/Organisation_entity.aod +++ b/entity/Organisation_entity/Organisation_entity.aod @@ -592,27 +592,12 @@ <name>LogHistoryConsumer</name> <title>LogHistory</title> <fieldType>DEPENDENCY_OUT</fieldType> - <state>READONLY</state> <dependency> <name>dependency</name> <entityName>LogHistory_entity</entityName> <fieldName>LogHistoryProvider</fieldName> </dependency> <children> - <entityParameter> - <name>contactId_param</name> - <valueProcess>%aditoprj%/entity/Organisation_entity/entityfields/loghistoryconsumer/children/contactid_param/valueProcess.js</valueProcess> - <expose v="true" /> - <triggerRecalculation v="true" /> - <mandatory v="true" /> - </entityParameter> - <entityParameter> - <name>tablenameId_param</name> - <valueProcess>%aditoprj%/entity/Organisation_entity/entityfields/loghistoryconsumer/children/tablenameid_param/valueProcess.js</valueProcess> - <expose v="true" /> - <triggerRecalculation v="true" /> - <mandatory v="true" /> - </entityParameter> <entityParameter> <name>tablenames_param</name> <valueProcess>%aditoprj%/entity/Organisation_entity/entityfields/loghistoryconsumer/children/tablename_param/valueProcess.js</valueProcess> diff --git a/entity/Organisation_entity/entityfields/loghistoryconsumer/children/contactid_param/valueProcess.js b/entity/Organisation_entity/entityfields/loghistoryconsumer/children/contactid_param/valueProcess.js deleted file mode 100644 index f0d7cb920e3..00000000000 --- a/entity/Organisation_entity/entityfields/loghistoryconsumer/children/contactid_param/valueProcess.js +++ /dev/null @@ -1,4 +0,0 @@ -import("system.result"); -import("system.vars"); - -result.string(vars.get("$field.CONTACTID")); \ No newline at end of file diff --git a/entity/Organisation_entity/entityfields/loghistoryconsumer/children/tablename_param/valueProcess.js b/entity/Organisation_entity/entityfields/loghistoryconsumer/children/tablename_param/valueProcess.js index 14d68713930..17ba5b0226b 100644 --- a/entity/Organisation_entity/entityfields/loghistoryconsumer/children/tablename_param/valueProcess.js +++ b/entity/Organisation_entity/entityfields/loghistoryconsumer/children/tablename_param/valueProcess.js @@ -1,4 +1,10 @@ -import("system.result"); -import("Context_lib"); - -result.string(ContextUtils.getContextName(ContextUtils.getCurrentContextId()).toUpperCase()); \ No newline at end of file +import("system.vars"); +import("system.result"); +import("Context_lib"); + +var res = []; +res.push({id: vars.get("$field.CONTACTID"), tableNames: ["CONTACT", "COMMUNICATION", "ADDRESS", "AB_ATTRIBUTERELATION"]}); +res.push({id: vars.get("$field.ORGANISATIONID"), tableNames: ["ORGANISATION"]}); + +res = JSON.stringify(res);//currently only strings can be passed as param +result.object(res); \ No newline at end of file diff --git a/entity/Organisation_entity/entityfields/loghistoryconsumer/children/tablenameid_param/valueProcess.js b/entity/Organisation_entity/entityfields/loghistoryconsumer/children/tablenameid_param/valueProcess.js deleted file mode 100644 index 2fe1b93f1ab..00000000000 --- a/entity/Organisation_entity/entityfields/loghistoryconsumer/children/tablenameid_param/valueProcess.js +++ /dev/null @@ -1,4 +0,0 @@ -import("system.result"); -import("system.vars"); - -result.string(vars.get("$field.ORGANISATIONID")); \ No newline at end of file diff --git a/entity/Person_entity/Person_entity.aod b/entity/Person_entity/Person_entity.aod index 119f7c36ef5..751bdc9d229 100644 --- a/entity/Person_entity/Person_entity.aod +++ b/entity/Person_entity/Person_entity.aod @@ -723,20 +723,6 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact <fieldName>LogHistoryProvider</fieldName> </dependency> <children> - <entityParameter> - <name>contactId_param</name> - <valueProcess>%aditoprj%/entity/Person_entity/entityfields/loghistoryconsumer/children/contactid_param/valueProcess.js</valueProcess> - <expose v="true" /> - <triggerRecalculation v="true" /> - <mandatory v="true" /> - </entityParameter> - <entityParameter> - <name>tablenameId_param</name> - <valueProcess>%aditoprj%/entity/Person_entity/entityfields/loghistoryconsumer/children/tablenameid_param/valueProcess.js</valueProcess> - <expose v="true" /> - <triggerRecalculation v="true" /> - <mandatory v="true" /> - </entityParameter> <entityParameter> <name>tablenames_param</name> <valueProcess>%aditoprj%/entity/Person_entity/entityfields/loghistoryconsumer/children/tablename_param/valueProcess.js</valueProcess> diff --git a/entity/Person_entity/entityfields/loghistoryconsumer/children/contactid_param/valueProcess.js b/entity/Person_entity/entityfields/loghistoryconsumer/children/contactid_param/valueProcess.js deleted file mode 100644 index 3a606135e9c..00000000000 --- a/entity/Person_entity/entityfields/loghistoryconsumer/children/contactid_param/valueProcess.js +++ /dev/null @@ -1,4 +0,0 @@ -import("system.result"); -import("system.vars"); - -result.string(vars.get("$field.PERSONID")); \ No newline at end of file diff --git a/entity/Person_entity/entityfields/loghistoryconsumer/children/tablename_param/valueProcess.js b/entity/Person_entity/entityfields/loghistoryconsumer/children/tablename_param/valueProcess.js index 9d7e2a467a9..4941f4e6817 100644 --- a/entity/Person_entity/entityfields/loghistoryconsumer/children/tablename_param/valueProcess.js +++ b/entity/Person_entity/entityfields/loghistoryconsumer/children/tablename_param/valueProcess.js @@ -3,7 +3,7 @@ import("system.result"); import("Context_lib"); var res = []; -res.push({id: vars.get("$field.CONTACTID"), tableNames: ["CONTACT", "COMMUNICATION", "ADDRESS"]}); +res.push({id: vars.get("$field.CONTACTID"), tableNames: ["CONTACT", "COMMUNICATION", "ADDRESS", "AB_ATTRIBUTERELATION"]}); res.push({id: vars.get("$field.PERSONID"), tableNames: ["PERSON"]}); res = JSON.stringify(res);//currently only strings can be passed as param diff --git a/entity/Person_entity/entityfields/loghistoryconsumer/children/tablenameid_param/valueProcess.js b/entity/Person_entity/entityfields/loghistoryconsumer/children/tablenameid_param/valueProcess.js deleted file mode 100644 index 70a1c0fcc12..00000000000 --- a/entity/Person_entity/entityfields/loghistoryconsumer/children/tablenameid_param/valueProcess.js +++ /dev/null @@ -1,4 +0,0 @@ -import("system.result"); -import("system.vars"); - -result.string(vars.get("$field.CONTACTID")); \ No newline at end of file diff --git a/process/Loghistory_lib/process.js b/process/Loghistory_lib/process.js index 41efba3c93e..6da79882e40 100644 --- a/process/Loghistory_lib/process.js +++ b/process/Loghistory_lib/process.js @@ -9,17 +9,13 @@ import("system.datetime"); import("system.translate"); import("system.SQLTYPES"); import("Keyword_lib"); +import("Attribute_lib"); import("Sql_lib"); import("Attribute_lib"); import("Contact_lib"); import("AddressEntity_lib"); import("Util_lib"); -function test() -{ - return "asdf"; -} - function LogHistoryExecutor(pTable, pUser, pColumns, pNewValues, pOldValues, pTimeStamp, pAction, pIdValue) { this.structureDefinitionAlias = "Data_alias";//alias where the definition of what shall be logged is stored @@ -45,6 +41,7 @@ LogHistoryExecutor.prototype._addEntryForInsert = function (pTablename, pTablena { if (this.toInsert == undefined) { + //the "SOURCE_TABLENAME" and "SOURCE_TABLENAMEID" are reserved for later usage in the change-notification-subscriptions //TODO: check if they are really needed this.toInsert = { statements: [] ,cols: ["AB_LOGHISTORYID", "LOGTYPE","TABLENAME","TABLENAMEID","DESCRIPTION", "SOURCE_TABLENAME", "SOURCE_TABLENAMEID", "DATE_NEW","USER_NEW"] @@ -107,8 +104,8 @@ LogHistoryExecutor.prototype.execute = function () if (extra[this.affectedTable]) { var conf = extra[this.affectedTable]; - var oldvalues = []; - var newvalues = []; + var oldvalues = {}; + var newvalues = {}; for(i = 0; i < this.columns.length; i++ ) { @@ -119,25 +116,27 @@ LogHistoryExecutor.prototype.execute = function () if ((this.sqlAction == 'D' || this.sqlAction == 'I') && newvalues[conf.IDs[1]]) { idvalue = newvalues[conf.IDs[0]]; - var data = _getData(this.affectedTable, newvalues[conf.IDs[1]], newvalues); - description.push(conf.Description + " " + data[0] + ": '" + data[1] + "'"); + var data = this._getDataForExtras(newvalues[conf.IDs[1]], newvalues); + description.push(translate.withArguments("%0 \"%1\"", [conf.Description + " " + data[0] + ":", data[1]], this.translationLanguage)); } if (this.sqlAction == 'U') { - var ids = db.array(db.ROW, "select " + conf.IDs.join(", ") + " from " + this.affectedTable + " where " + this.affectedTable + "ID = '" + pIdValue + "'"); + var ids = db.array(db.ROW, "select " + conf.IDs.join(", ") + " from " + this.affectedTable + " where " + this.affectedTable + "ID = '" + idvalue + "'"); idvalue = ids[0]; var oldid = ids[1]; if (oldvalues[conf.IDs[1]]) oldid = oldvalues[conf.IDs[1]]; - var olddata = _getData(this.affectedTable, oldid, this.oldValues); - var newdata = _getData(this.affectedTable, ids[1], newvalues); + var olddata = this._getDataForExtras(oldid, oldvalues); + var newdata = this._getDataForExtras(ids[1], newvalues); if (newdata[1] && olddata[1]) { - if (olddata[0] == newdata[0]) description.push(conf.Description + " " + olddata[0] + " von '" + olddata[1] + "' auf '" + newdata[1] + "' "); - else description.push(conf.Description + " " + olddata[0] + " von '" + olddata[1] + "' auf " + conf.Description + " " + newdata[0] + " '" + newdata[1] + "' "); + if (olddata[0] == newdata[0]) + description.push(translate.withArguments("%0 from \"%1\" to \"%2\"", [conf.Description + " " + olddata[0], olddata[1], newdata[1]], this.translationLanguage)); + else + description.push(translate.withArguments("%0 from \"%1\" to %2 \"%3\"", [conf.Description + " " + olddata[0], olddata[1], conf.Description + " " + newdata[0] , newdata[1]], this.translationLanguage)); } else if(this.affectedTable == "COMMUNICATION") { - description.push(conf.Description + " Medium von '" + olddata[0] + "' auf '" + newdata[0] + "' "); + description.push(translate.withArguments("%0 medium from \"%1\" to \"%2\"", [conf.Description, olddata[0], newdata[0]], this.translationLanguage))); } } if (conf.RefTable) this.affectedTable = conf.RefTable; @@ -212,24 +211,25 @@ LogHistoryExecutor.prototype.execute = function () /* * Creates the data for the tables with special cases * -* @param {String} pTable the table name * @param {String} pId the table id * @param {[]} pValues the values * * @return {[]} table */ -function _getData(pTable, pId, pValues) +LogHistoryExecutor.prototype._getDataForExtras = function(pId, pValues) { var data = []; - //TODO: Attribute_lib - if (pTable == "AB_ATTRIBUTERELATION") data = GetAttrAudit(pId, pValues[getValueFieldName(pId)]); - if (pTable == "COMMUNICATION") + + if (this.affectedTable == "AB_ATTRIBUTERELATION") + data = [AttributeUtil.getFullAttributeName(pId), pValues[(new AttributeHandler(pId)).getDatabaseField()]]; + if (this.affectedTable == "COMMUNICATION") { data[0] = KeywordUtils.getResolvedTitleSqlPart("MediumOrgPers", pId, false); data[1] = pValues["ADDR"]; } return data; -} +}; + /* * Creates an Array of AB_LOGHISTORY data for display in a view -- GitLab