Skip to content
Snippets Groups Projects
Commit c52fd454 authored by Johannes Goderbauer's avatar Johannes Goderbauer
Browse files

Refactoring Audit: Historylogger (4)

parent 912aa638
No related branches found
No related tags found
No related merge requests found
......@@ -27,36 +27,14 @@ function LogHistoryExecutor(pTable, pUser, pColumns, pNewValues, pOldValues, pTi
this.sqlAction = pAction;
this.idValue = pIdValue;
this.columns = pColumns.map(function (v){
return v.toUpperCase();
});
return v.toUpperCase();
});
this.translationLanguage = LogHistoryExecutor.TRANSLATION_LANGUAGE();
}
LogHistoryExecutor.TRANSLATION_LANGUAGE = function(){
return "DE_de";
}
LogHistoryExecutor.prototype._addEntryForInsert = function (pTablename, pTablenameId, pSourceTablename, pSourceTablenameId, pDescription)
{
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"]
};
this.toInsert.types = db.getColumnTypes("AB_LOGHISTORY", this.toInsert.cols);//load only once for better performance
}
var vals = [util.getNewUUID(), this.sqlAction, pTablename, pTablenameId, pDescription, pSourceTablename, pSourceTablenameId, this.timestamp, this.triggeringUser];
this.toInsert.statements.push(["AB_LOGHISTORY", this.toInsert.cols, this.toInsert.types, vals]);
};
LogHistoryExecutor.prototype._insertLoghistEntry = function ()
LogHistoryExecutor.TRANSLATION_LANGUAGE = function()
{
if (this.toInsert && this.toInsert.statements)
db.inserts(this.toInsert.statements);
return "DE_de";
};
LogHistoryExecutor.prototype.execute = function ()
......@@ -136,7 +114,7 @@ LogHistoryExecutor.prototype.execute = function ()
}
else if(this.affectedTable == "COMMUNICATION")
{
description.push(translate.withArguments("%0 medium from \"%1\" to \"%2\"", [conf.Description, olddata[0], newdata[0]], this.translationLanguage)));
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;
......@@ -153,7 +131,7 @@ LogHistoryExecutor.prototype.execute = function ()
for (var i = 0; i < this.columns.length; i++)
{
if (this.affectedTable == "ASYS_CALENDARBACKEND" && this.columns[i] == "VCOMPONENT")
_getCalendarDescription(this.sqlAction, i, this.newValues, this.oldValues);
this._getCalendarDescription(i);
if (references[this.columns[i]])
{
......@@ -190,7 +168,7 @@ LogHistoryExecutor.prototype.execute = function ()
{
if (this.sqlAction == 'I') description = translate.withArguments("%0 added.", [description.join(", ")], this.translationLanguage);
if (this.sqlAction == 'U') description = translate.withArguments("%0 modified.", [description.join(", ")], this.translationLanguage);
if (this.sqlAction == 'D') description = translate.withArguments("%0 deleted.", [description.join(", ")], this.translationLanguage);
if (this.sqlAction == 'D') description = translate.withArguments("%0 deleted.", [description.join(", ")], this.translationLanguage);
for (index in references)
{
if (references[index].id != "")
......@@ -208,6 +186,30 @@ LogHistoryExecutor.prototype.execute = function ()
return null;
};
LogHistoryExecutor.prototype._addEntryForInsert = function (pTablename, pTablenameId, pSourceTablename, pSourceTablenameId, pDescription)
{
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"]
};
this.toInsert.types = db.getColumnTypes("AB_LOGHISTORY", this.toInsert.cols);//load only once for better performance
}
var vals = [util.getNewUUID(), this.sqlAction, pTablename, pTablenameId, pDescription, pSourceTablename, pSourceTablenameId, this.timestamp, this.triggeringUser];
this.toInsert.statements.push(["AB_LOGHISTORY", this.toInsert.cols, this.toInsert.types, vals]);
};
LogHistoryExecutor.prototype._insertLoghistEntry = function ()
{
if (this.toInsert && this.toInsert.statements)
db.inserts(this.toInsert.statements);
};
/*
* Creates the data for the tables with special cases
*
......@@ -221,7 +223,8 @@ LogHistoryExecutor.prototype._getDataForExtras = function(pId, pValues)
var data = [];
if (this.affectedTable == "AB_ATTRIBUTERELATION")
data = [AttributeUtil.getFullAttributeName(pId), pValues[(new AttributeHandler(pId)).getDatabaseField()]];
data[0] = AttributeUtil.getFullAttributeName(pId);
data[1] = AttributeRelationUtils.getAttribute(pId, (pValues["OBJECT_ROWID"]), null, true);
if (this.affectedTable == "COMMUNICATION")
{
data[0] = KeywordUtils.getResolvedTitleSqlPart("MediumOrgPers", pId, false);
......@@ -231,6 +234,26 @@ LogHistoryExecutor.prototype._getDataForExtras = function(pId, pValues)
};
/*
* Creates the description for changes in the calendar
*
* @param {String} pIndex calendarfield index (position) within the values
*
* @return {String} the description of the action
*/
LogHistoryExecutor.prototype._getCalendarDescription = function (pIndex)
{
if (this.sqlAction != "D") this.newValues[pIndex] = _getEntry("DESCRIPTION:", this.newValues[pIndex]);
if (this.sqlAction != "I") this.oldValues[pIndex] = _getEntry("DESCRIPTION:", this.oldValues[pIndex]);
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 "";
}
};
/*
* Creates an Array of AB_LOGHISTORY data for display in a view
*
......@@ -255,9 +278,11 @@ LogHistoryExecutor._getFormattedValue = function (pDescription, pValue, pLocale)
else if (pDescription.translate4Log != null && pDescription.translate4Log != "")
{
var params = {
rowId: this.idValue
,value: pValue.toString()
,action: this.sqlAction
rowId: this.idValue
,
value: pValue.toString()
,
action: this.sqlAction
};
pValue = process.executeScript("LogHistoryExecutor._getFormattedValue ", pDescription.translate4Log, params);
......@@ -285,27 +310,4 @@ LogHistoryExecutor._getFormattedValue = function (pDescription, pValue, pLocale)
}
}
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 "";
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment