diff --git a/aliasDefinition/Data_alias/Data_alias.aod b/aliasDefinition/Data_alias/Data_alias.aod index 506026be7f5da19d6e5a250f021c99f1224d9343..b0e2585fde4753b00ae788c749c990c272f732fb 100644 --- a/aliasDefinition/Data_alias/Data_alias.aod +++ b/aliasDefinition/Data_alias/Data_alias.aod @@ -486,6 +486,13 @@ <index v="false" /> <title></title> <description></description> + <customProperties> + <customBooleanProperty> + <name>log</name> + <global v="false" /> + <property v="true" /> + </customBooleanProperty> + </customProperties> </entityFieldDb> <entityFieldDb> <name>SALUTATION</name> diff --git a/entity/LogHistory_entity/recordcontainers/db/conditionProcess.js b/entity/LogHistory_entity/recordcontainers/db/conditionProcess.js index 64d80196abae86ad6fdd5799efb1d46c31466ca9..0ada3361d0a2a1da7f1ae23c23d242c6e1d7fce7 100644 --- a/entity/LogHistory_entity/recordcontainers/db/conditionProcess.js +++ b/entity/LogHistory_entity/recordcontainers/db/conditionProcess.js @@ -1,7 +1,7 @@ -import("system.vars"); -import("system.result"); - -var sql = "(TABLENAMEID = '" + vars.get("$param.tablenameId_param") + "' and TABLENAME = '" + vars.get("$param.tablename_param") + "') " - + "or (TABLENAMEID = '" + vars.get("$param.contactId_param") + "' " - + "and (TABLENAME='CONTACT' or TABLENAME='COMMUNICATION' or TABLENAME='ADDRESS' or TABLENAME='AB_ATTRIBUTERELATION'))"; +import("system.vars"); +import("system.result"); + +var sql = "(TABLENAMEID = '" + vars.get("$param.tablenameId_param") + "' and TABLENAME = '" + vars.get("$param.tablename_param") + "') " + + "or (TABLENAMEID = '" + vars.get("$param.contactId_param") + "' " + + "and (TABLENAME='CONTACT' or TABLENAME='PERSON' or TABLENAME='COMMUNICATION' or TABLENAME='ADDRESS' or TABLENAME='AB_ATTRIBUTERELATION'))"; result.string(sql); \ No newline at end of file diff --git a/entity/Person_entity/Person_entity.aod b/entity/Person_entity/Person_entity.aod index 6c04af722c7a2cd93a5cf75eac2afe3b735742b8..c224f074ad62d8477b0462eb39cf415b9eedfc21 100644 --- a/entity/Person_entity/Person_entity.aod +++ b/entity/Person_entity/Person_entity.aod @@ -714,7 +714,6 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact <name>LogHistoryConsumer</name> <title>LogHistory</title> <fieldType>DEPENDENCY_OUT</fieldType> - <state>READONLY</state> <dependency> <name>dependency</name> <entityName>LogHistory_entity</entityName> diff --git a/process/Loghistory_lib/process.js b/process/Loghistory_lib/process.js index 16ac3302969c4e317fe8cc44bd14a8c7b3900a7b..f8d96a04fd09d35123f501b6b1f75ca2cc7ce334 100644 --- a/process/Loghistory_lib/process.js +++ b/process/Loghistory_lib/process.js @@ -1,261 +1,262 @@ -import("system.logging"); -import("system.project"); -import("system.calendars"); -import("system.db"); -import("system.text"); -import("system.datetime"); -import("system.translate"); -import("system.SQLTYPES"); -import("Keyword_lib"); -import("Sql_lib"); -import("Attribute_lib"); -import("Contact_lib"); -import("AddressEntity_lib"); -import("Util_lib"); - -/* -* Saves changes done to db-columns that have been turned on for auditing in the repository into the table AB_LOGHISTORY -* -* @param {String} pTable req TableName -* @param {String} pUser req UserName -* @param {String []} pColumns req ColumnNames -* @param {String []} pNewValues req new Values -* @param {String []} pOldValues req old Values -* @param {Date} pTimeStamp req TimeStamp -* @param {String} pAction req SQLAction -* @param {String} pIdValue req IdValue -* -* @return {} void -*/ - -function logHistory (pTable, pUser, pColumns, pNewValues, pOldValues, pTimeStamp, pAction, pIdValue) -{ - var references = {}; - var coldef = {}; - var primaryKey = ""; - var tolog = false; - - pTable = pTable.toUpperCase(); - pColumns = pColumns.map(function (v){ return v.toUpperCase(); }); - - var structure = project.getAliasDefinitionStructure("Data_alias", pTable); - if (structure) - { - coldef = structure.tables[pTable].columns; - for (var column in coldef) - { - if (coldef[column].tableRef) references[column] = {table: coldef[column].tableRef, id: ""}; - if (coldef[column].primaryKey) primaryKey = column; - if (coldef[column].log) tolog = coldef[column].log; - } - } - - - if (tolog) - { - var idvalue = pIdValue; - var description = []; - var extra = []; - extra["COMMUNICATION"] = { - IDs: ["CONTACT_ID", "MEDIUM_ID"], - RefTable: "CONTACT", - Description: "Kommunikation" - }; - extra["AB_ATTRIBUTERELATION"] = { - IDs: ["OBJECT_ROWID", "AB_ATTRIBUTE_ID"], - Description: "Eigenschaft" - }; - - if (extra[pTable]) - { - var conf = extra[pTable]; - var oldvalues = []; - var newvalues = []; - - for(i = 0; i < pColumns.length; i++ ) - { - if (pAction == 'D' || pAction == 'U') oldvalues[pColumns[i]] = pOldValues[i]; - if (pAction == 'I' || pAction == 'U') newvalues[pColumns[i]] = pNewValues[i]; - } - if (pAction == 'D') newvalues = oldvalues; - if ((pAction == 'D' || pAction == 'I') && newvalues[conf.IDs[1]]) - { - idvalue = newvalues[conf.IDs[0]]; - var data = _getData(pTable, newvalues[conf.IDs[1]], newvalues); - description.push(conf.Description + " " + data[0] + ": '" + data[1] + "'"); - } - if (pAction == 'U') - { - var ids = db.array(db.ROW, "select " + conf.IDs.join(", ") + " from " + pTable + " where " + pTable + "ID = '" + pIdValue + "'"); - idvalue = ids[0]; - var oldid = ids[1]; - if (oldvalues[conf.IDs[1]]) oldid = oldvalues[conf.IDs[1]]; - var olddata = _getData(pTable, oldid, oldvalue); - var newdata = _getData(pTable, 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] + "' "); - } - else if(pTable == "COMMUNICATION") - { - description.push(conf.Description + " Medium von '" + olddata[0] + "' auf '" + newdata[0] + "' "); - } - } - if (conf.RefTable) pTable = conf.RefTable; - } //no extra tables - else - { - logging.log("no extra table"); - if (pTable == "ASYS_CALENDARBACKEND") { - var entrytypePosition = pColumns.indexOf("ENTRYTYPE"); - if (entrytypePosition > -1) if (pNewValues[entrytypePosition] == calendars.VEVENT) return; - } - - for(i = 0; i < pColumns.length; i++ ) - { - if (pTable == "ASYS_CALENDARBACKEND" && pColumns[i] == "VCOMPONENT") _getCalendarDescription(pAction, i, pNewValues, pOldValues); - if (references[pColumns[i]]) - { - if (pAction == "I") references[pColumns[i]].id = pNewValues[i]; - if (pAction == "D") references[pColumns[i]].id = pOldValues[i]; - } - var logfield = columns[pColumns[i]]; - if (logfield && logfield.log) - { - if (pAction != 'I' && pOldValues[i] != "") pOldValues[i] = _getFormattedValue(logfield, pOldValues[i]); - if (pAction != 'D' && pNewValues[i] != "") pNewValues[i] = _getFormattedValue(logfield, pNewValues[i]); - if (pAction == 'U' && pOldValues[i] != pNewValues[i]) - { - let value = pOldValues[i] == "[CLOB]" || pOldValues[i] == "" ? ":" : ": von '" + pOldValues[i]; - description.push(logfield.title + value + "' auf '" + pNewValues[i] + "'"); - } - if (pAction == 'I' && pNewValues[i] != "") description.push(logfield.title + ": '" + pNewValues[i] + "'"); - if (pAction == 'D' && pOldValues[i] != "") description.push(logfield.title + ": '" + pOldValues[i] + "'"); - } - } - if (pAction == "U") - { - for (var index in references) references[index].id = db.cell("select " + index + " from " + pTable + " where " + primaryKey + " = '" + pIdValue + "'"); - } - } - - if (description.length > 0) - { - if (pAction == 'I') description = description.join(", ") + " eingefügt."; - if (pAction == 'U') description = description.join(", ") + " geändert."; - if (pAction == 'D') description = description.join(", ") + " gelöscht."; - var cols = ["LOGTYPE","TABLENAME","TABLENAMEID","DESCRIPTION", "SOURCE_TABLENAME", "SOURCE_TABLENAMEID", "DATE_NEW","USER_NEW"]; - for (index in references) - { - if (references[index].id != "") - { - db.insertData("ASYS_LOGHISTORY", cols, null, [pAction, references[index].table.trim(), references[index].id, description, pTable.trim(), idvalue, pTimeStamp, pUser]); - idvalue = ""; - } - } - if (idvalue != "") db.insertData("ASYS_LOGHISTORY", cols, null, [pAction, pTable.trim(), idvalue, description, "", "", pTimeStamp, pUser]); - } - } -} - -/* -* 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) -{ - var data = []; - //TODO: Attribute_lib - if (pTable == "AB_ATTRIBUTERELATION") data = GetAttrAudit(pId, pValues[getValueFieldName(pId)]); - if (pTable == "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 -* -* @param {String} pCondition req TableName -* -* @return {[]} table -*/ -function _getFormattedValue(pDescription, pValue) -{ - if (pDescription.keyword != null && pDescription.keyword != "") - { - if (/^(; \d*)*$/.test(pValue)) - { - pValue = text.decodeMS(pValue); - for (let i = 0; i < pValue.length; i++) - { - if (!isNaN(pValue[i])) pValue[i] = getKeyName(pValue[i], pDescription.keyword); - } - pValue = pValue.join(", "); - } - else pValue = getKeyName(pValue, pDescription.keyword); - } - else if (pDescription.translate4Log != null && pDescription.translate4Log != "") - { - var params = { - rowId: pIdValue - ,value: pValue.toString() - ,action: pAction - }; - pValue = evalScript("Loghistory_lib._getFormattedValue", pDescription.translate4Log.replace(/{value}/gi, pValue.toString()), params); - } - else if (pDescription.columnType == String(SQLTYPES.TIMESTAMP)) pValue = datetime.toDate(pValue, "dd.MM.yyyy", "Europe/Berlin"); - else if (pDescription.autoMapTrueFalse4Log) - { - switch (pValue.toLowerCase()) - { - case "true": - case "t": - case "y": - case "1": - pValue = translate.text("Ja"); - break; - case "false": - case "f": - case "n": - case "0": - case "2": - pValue = translate.text("Nein"); - break; - default: - break; - } - } - return pValue; -} - -/* -* Creates the description for changes in the calendar -* -* @param {String} pAction the user action -* @param {String} pId the talbe id -* @param {String} pNewValue the old entry -* @param {String} pOldValue the new entry -* -* @return {String} the description of the action -*/ -function _getCalendarDescription(pAction, pId, pNewValue, pOldValue) -{ - if (pAction != "D") pNewValue[pId] = _getEntry("DESCRIPTION:", pNewValue[pId]); - if (pAction != "I") pOldValue[pId] = _getEntry("DESCRIPTION:", pOldValue[pId]); - - function _getEntry(pWert, pVcomponent) - { - var value = pVcomponent.toString().match(new RegExp(pWert + ".+\r")); - if (value != null) return value.toString().replace(pWert, "").replace(/\\R\\N/g, "\r\n"); - else return ""; - } -} +import("system.util"); +import("system.logging"); +import("system.project"); +import("system.calendars"); +import("system.db"); +import("system.text"); +import("system.datetime"); +import("system.translate"); +import("system.SQLTYPES"); +import("Keyword_lib"); +import("Sql_lib"); +import("Attribute_lib"); +import("Contact_lib"); +import("AddressEntity_lib"); +import("Util_lib"); + +/* +* Saves changes done to db-coldef that have been turned on for auditing in the repository into the table AB_LOGHISTORY +* +* @param {String} pTable req TableName +* @param {String} pUser req UserName +* @param {String []} pColumns req ColumnNames +* @param {String []} pNewValues req new Values +* @param {String []} pOldValues req old Values +* @param {Date} pTimeStamp req TimeStamp +* @param {String} pAction req SQLAction +* @param {String} pIdValue req IdValue +* +* @return {} void +*/ + +function logHistory (pTable, pUser, pColumns, pNewValues, pOldValues, pTimeStamp, pAction, pIdValue) +{ + var references = {}; + var coldef = {}; + var primaryKey = ""; + var tolog = false; + + pTable = pTable.toUpperCase(); + pColumns = pColumns.map(function (v){ return v.toUpperCase(); }); + + var structure = project.getAliasDefinitionStructure("Data_alias", pTable); + if (structure) + { + coldef = structure.tables[pTable].columns; + for (var column in coldef) + { + if (coldef[column].tableRef) references[column] = {table: coldef[column].tableRef, id: ""}; + if (coldef[column].primaryKey) primaryKey = column; + if (coldef[column].log) tolog = coldef[column].log; + } + } + + + if (tolog) + { + var idvalue = pIdValue; + var description = []; + var extra = []; + extra["COMMUNICATION"] = { + IDs: ["CONTACT_ID", "MEDIUM_ID"], + RefTable: "CONTACT", + Description: "Kommunikation" + }; + extra["AB_ATTRIBUTERELATION"] = { + IDs: ["OBJECT_ROWID", "AB_ATTRIBUTE_ID"], + Description: "Eigenschaft" + }; + + if (extra[pTable]) + { + var conf = extra[pTable]; + var oldvalues = []; + var newvalues = []; + + for(i = 0; i < pColumns.length; i++ ) + { + if (pAction == 'D' || pAction == 'U') oldvalues[pColumns[i]] = pOldValues[i]; + if (pAction == 'I' || pAction == 'U') newvalues[pColumns[i]] = pNewValues[i]; + } + if (pAction == 'D') newvalues = oldvalues; + if ((pAction == 'D' || pAction == 'I') && newvalues[conf.IDs[1]]) + { + idvalue = newvalues[conf.IDs[0]]; + var data = _getData(pTable, newvalues[conf.IDs[1]], newvalues); + description.push(conf.Description + " " + data[0] + ": '" + data[1] + "'"); + } + if (pAction == 'U') + { + var ids = db.array(db.ROW, "select " + conf.IDs.join(", ") + " from " + pTable + " where " + pTable + "ID = '" + pIdValue + "'"); + idvalue = ids[0]; + var oldid = ids[1]; + if (oldvalues[conf.IDs[1]]) oldid = oldvalues[conf.IDs[1]]; + var olddata = _getData(pTable, oldid, oldvalue); + var newdata = _getData(pTable, 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] + "' "); + } + else if(pTable == "COMMUNICATION") + { + description.push(conf.Description + " Medium von '" + olddata[0] + "' auf '" + newdata[0] + "' "); + } + } + if (conf.RefTable) pTable = conf.RefTable; + } //no extra tables + else + { + logging.log("no extra table"); + if (pTable == "ASYS_CALENDARBACKEND") { + var entrytypePosition = pColumns.indexOf("ENTRYTYPE"); + if (entrytypePosition > -1) if (pNewValues[entrytypePosition] == calendars.VEVENT) return; + } + + for(i = 0; i < pColumns.length; i++ ) + { + if (pTable == "ASYS_CALENDARBACKEND" && pColumns[i] == "VCOMPONENT") _getCalendarDescription(pAction, i, pNewValues, pOldValues); + if (references[pColumns[i]]) + { + if (pAction == "I") references[pColumns[i]].id = pNewValues[i]; + if (pAction == "D") references[pColumns[i]].id = pOldValues[i]; + } + var logfield = coldef[pColumns[i]]; + if (logfield && logfield.log) + { + if (pAction != 'I' && pOldValues[i] != "") pOldValues[i] = _getFormattedValue(logfield, pOldValues[i]); + if (pAction != 'D' && pNewValues[i] != "") pNewValues[i] = _getFormattedValue(logfield, pNewValues[i]); + if (pAction == 'U' && pOldValues[i] != pNewValues[i]) + { + let value = pOldValues[i] == "[CLOB]" || pOldValues[i] == "" ? ":" : ": von '" + pOldValues[i]; + description.push(logfield.title + value + "' auf '" + pNewValues[i] + "'"); + } + if (pAction == 'I' && pNewValues[i] != "") description.push(logfield.title + ": '" + pNewValues[i] + "'"); + if (pAction == 'D' && pOldValues[i] != "") description.push(logfield.title + ": '" + pOldValues[i] + "'"); + } + } + if (pAction == "U") + { + for (var index in references) references[index].id = db.cell("select " + index + " from " + pTable + " where " + primaryKey + " = '" + pIdValue + "'"); + } + } + + if (description.length > 0) + { + if (pAction == 'I') description = description.join(", ") + " eingefügt."; + if (pAction == 'U') description = description.join(", ") + " geändert."; + if (pAction == 'D') description = description.join(", ") + " gelöscht."; + var cols = ["AB_LOGHISTORYID", "LOGTYPE","TABLENAME","TABLENAMEID","DESCRIPTION", "SOURCE_TABLENAME", "SOURCE_TABLENAMEID", "DATE_NEW","USER_NEW"]; + for (index in references) + { + if (references[index].id != "") + { + db.insertData("AB_LOGHISTORY", cols, null, [util.getNewUUID(), pAction, references[index].table.trim(), references[index].id, description, pTable.trim(), idvalue, pTimeStamp, pUser]); + idvalue = ""; + } + } + if (idvalue != "") db.insertData("AB_LOGHISTORY", cols, null, [util.getNewUUID(), pAction, pTable.trim(), idvalue, description, "", "", pTimeStamp, pUser]); + } + } +} + +/* +* 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) +{ + var data = []; + //TODO: Attribute_lib + if (pTable == "AB_ATTRIBUTERELATION") data = GetAttrAudit(pId, pValues[getValueFieldName(pId)]); + if (pTable == "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 +* +* @param {String} pCondition req TableName +* +* @return {[]} table +*/ +function _getFormattedValue(pDescription, pValue) +{ + if (pDescription.keyword != null && pDescription.keyword != "") + { + if (/^(; \d*)*$/.test(pValue)) + { + pValue = text.decodeMS(pValue); + for (let i = 0; i < pValue.length; i++) + { + if (!isNaN(pValue[i])) pValue[i] = getKeyName(pValue[i], pDescription.keyword); + } + pValue = pValue.join(", "); + } + else pValue = getKeyName(pValue, pDescription.keyword); + } + else if (pDescription.translate4Log != null && pDescription.translate4Log != "") + { + var params = { + rowId: pIdValue + ,value: pValue.toString() + ,action: pAction + }; + pValue = evalScript("Loghistory_lib._getFormattedValue", pDescription.translate4Log.replace(/{value}/gi, pValue.toString()), params); + } + else if (pDescription.columnType == String(SQLTYPES.TIMESTAMP)) pValue = datetime.toDate(pValue, "dd.MM.yyyy", "Europe/Berlin"); + else if (pDescription.autoMapTrueFalse4Log) + { + switch (pValue.toLowerCase()) + { + case "true": + case "t": + case "y": + case "1": + pValue = translate.text("Ja"); + break; + case "false": + case "f": + case "n": + case "0": + case "2": + pValue = translate.text("Nein"); + break; + default: + break; + } + } + return pValue; +} + +/* +* Creates the description for changes in the calendar +* +* @param {String} pAction the user action +* @param {String} pId the talbe id +* @param {String} pNewValue the old entry +* @param {String} pOldValue the new entry +* +* @return {String} the description of the action +*/ +function _getCalendarDescription(pAction, pId, pNewValue, pOldValue) +{ + if (pAction != "D") pNewValue[pId] = _getEntry("DESCRIPTION:", pNewValue[pId]); + if (pAction != "I") pOldValue[pId] = _getEntry("DESCRIPTION:", pOldValue[pId]); + + function _getEntry(pWert, pVcomponent) + { + var value = pVcomponent.toString().match(new RegExp(pWert + ".+\r")); + if (value != null) return value.toString().replace(pWert, "").replace(/\\R\\N/g, "\r\n"); + else return ""; + } +} diff --git a/process/process_audit/process_audit.aod b/process/process_audit/process_audit.aod index ea60b01713c9af73536be2f2c0f9cb5bc2c3cc65..2cdbe602ad80730c61f3a2ee8a76958a810c2ed3 100644 --- a/process/process_audit/process_audit.aod +++ b/process/process_audit/process_audit.aod @@ -3,6 +3,7 @@ <name>process_audit</name> <majorModelMode>DISTRIBUTED</majorModelMode> <process>%aditoprj%/process/process_audit/process.js</process> + <alias>Data_alias</alias> <variants> <element>LIBRARY</element> <element>EXECUTABLE</element>