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

added alpha version of process for generating liquibase systemdata

parent 8adb2099
No related branches found
No related tags found
No related merge requests found
......@@ -70,16 +70,16 @@ LiquiUtils.exportAllTablesAsLiquibaseFiles = function(pOutFolderPath, pAuthor, p
*
* @return {Object} returns an object that has currently only one property<br/>- exported:boolean if the table has been exported or not
*/
LiquiUtils.exportTableAsLiquibaseFiles = function(pPath, pTableName, pColumns, pCondition, pAuthor, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments)
LiquiUtils.exportTableAsLiquibaseFiles = function(pPath, pTableName, pColumns, pCondition, pAuthor, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments, pBlobCallbackFn, pFileName)
{
var resXml = LiquiUtils._getDataXml(pAuthor, pPath, pTableName, pColumns, pCondition, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments);
var resXml = LiquiUtils._getDataXml(pAuthor, pPath, pTableName, pColumns, pCondition, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments, pBlobCallbackFn);
if (resXml == "")
return {exported: false};
var fileName = pFileName || pTableName;
fileIO.mkdir(pPath, true);
var fullFileName = pPath += "/" + pTableName + ".xml";
var fullFileName = pPath += "/" + fileName + ".xml";
fileIO.storeData(fullFileName, resXml, util.DATA_TEXT, false, "UTF8");
return {exported: true};
return {exported: true, fileName: fileName};
};
/**
......@@ -100,7 +100,7 @@ LiquiUtils.exportTableAsLiquibaseFiles = function(pPath, pTableName, pColumns, p
*
* @return {String} the liquibase-changest in xml-form
*/
LiquiUtils._getDataXml = function(pAuthor, pLobPath, pTableName, pColumns, pCondition, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments)
LiquiUtils._getDataXml = function(pAuthor, pLobPath, pTableName, pColumns, pCondition, pIncludeClearTableDirective, pAlias, pGenerateChangeSetIdFromArguments, pBlobCallbackFn)
{
var author = pAuthor || "autogenerated";
var alias = pAlias || db.getCurrentAlias();
......@@ -128,7 +128,7 @@ LiquiUtils._getDataXml = function(pAuthor, pLobPath, pTableName, pColumns, pCond
else if(SQLTYPES.isLOBType(colType))
{
if ([SQLTYPES.BLOB, SQLTYPES.LONGVARBINARY, SQLTYPES.VARBINARY].indexOf(colType) != -1)
return LiquiXTable.prototype.addBlobCol;
return (function (pTab, pCol, pRow){ return this.addBlobCol(pTab, pCol, pRow, pBlobCallbackFn);});
else
return LiquiXTable.prototype.addClobCol;
}
......@@ -151,6 +151,9 @@ LiquiUtils._getDataXml = function(pAuthor, pLobPath, pTableName, pColumns, pCond
changeLogXml.changeSet.appendChild(<delete tableName={pTableName}/>);
dbData.forEach(function(row)
{
var rowObj = {};
for (let i = 0; i < columnLen; i++)
rowObj[columns[i]] = row[i];
var tableXml = LiquiXTable.make(pTableName);
if (pLobPath)
tableXml.setLobBasePath(pLobPath);
......@@ -160,7 +163,7 @@ LiquiUtils._getDataXml = function(pAuthor, pLobPath, pTableName, pColumns, pCond
var value = row[i];
var fnToUse = colCallbackFn[i];
if (fnToUse != null)
fnToUse.call(tableXml, colName, value)
fnToUse.call(tableXml, colName, value, rowObj)
}
changeLogXml.changeSet.insert += tableXml.xml;
});
......@@ -306,7 +309,7 @@ LiquiXTable.prototype.addClobCol = function (pColName, pValue)
}
};
LiquiXTable.prototype.addBlobCol = function (pColName, pValue)
LiquiXTable.prototype.addBlobCol = function (pColName, pValue, pRow, pFileNameCallback)
{
if (pValue == "")
return this;
......@@ -315,7 +318,11 @@ LiquiXTable.prototype.addBlobCol = function (pColName, pValue)
throw new Error(translate.withArguments("[%0]it was necessary to create a file from a blob-field but no lob-file-path was specified."
+ "The lob-file-path is required when adding blob-values.", ["LiquiXTable addClobCol"]));
var relativeFolderPath = this._name + "/" + pColName + "/blobFiles/";
var fileName = text.hash(pValue, text.HASH_MD5);
var fileName;
if (pFileNameCallback)
fileName = pFileNameCallback.apply(this, arguments);
if (!fileName)
fileName = text.hash(pValue, text.HASH_MD5);
fileIO.mkdir(lobBasePath + relativeFolderPath, true);
fileIO.storeData(lobBasePath + relativeFolderPath + fileName, pValue, util.DATA_BINARY, false);
return this.appendIfNotNull(LiquiXmlUtils.colValue(pColName, relativeFolderPath + fileName, "valueBlobFile"));
......
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.2.1">
<name>exportLiquibaseSystemalias_serverProcess</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<process>%aditoprj%/process/exportLiquibaseSystemalias_serverProcess/process.js</process>
<alias>Data_alias</alias>
<variants>
<element>EXECUTABLE</element>
</variants>
</process>
import("Util_lib");
import("system.vars");
import("Sql_lib");
import("system.datetime");
import("system.util");
import("system.logging");
import("Liquibase_lib");
import("system.db");
import("system.fileIO");
/*
* This process is still WIP.
* The process is designed to help upgrading the lqiuibase-definition of the content of the _____SYSTEMALIAS.
**/
var alias = "tempAlias";
var outFolderBase = vars.get("$sys.servertemp") + "/" + alias + "/";
_exportSystemData();
_exportAsysBinariesData();
_exportAsysUsersAdmin();
_exportAsysUsersExamples();
_exportAsysUsersWorkflow();
function _exportSystemData()
{
var outFolderPath = outFolderBase + "init/data/";
var exportTables = [];
exportTables.push({
tableName: "ASYS_ALIASCONFIG",
blobNameCallback: function(pColumnName, pValue, pRow){
return pRow.ALIASID ? pRow.ALIASID + ".xml" : null;
}
});
exportTables.push({
tableName: "ASYS_PERMISSION"
});
exportTables.push({
tableName: "ASYS_PERMISSIONACTION"
});
exportTables.push({
tableName: "ASYS_PERMISSIONSET"
});
exportTables.push({
tableName: "ASYS_SYSTEM",
blobNameCallback: function(pColumnName, pValue, pRow){
return pRow.NAME ? pRow.NAME + ".xml" : null;
}
});
var changeLogData = LiquiXmlUtils.databaseChangeLog();
exportTables.forEach(function (tableCfg){
var tableName = tableCfg.tableName;
var fileValue = tableName + ".xml";
var blobNameCallback = tableCfg.blobNameCallback;
LiquiUtils.exportTableAsLiquibaseFiles(outFolderPath, tableName, null, null, null, false, alias, true, blobNameCallback);
changeLogData.appendChild(<include relativeToChangelogFile="true" file={
fileValue
}/>);
});
changeLogData = LiquiXmlUtils.xmlHeaderLineStr() + "\n" + changeLogData.toString();
//write changelog file
fileIO.storeData(outFolderPath + "changelog.xml", changeLogData, util.DATA_TEXT, false, "UTF8");
logging.log("liquibase data (" + exportTables.length + " tables) exported into folder:" + outFolderPath);
}
function _exportAsysBinariesData()
{
var outFolderPath = outFolderBase + "_demoData/generatedData/";
LiquiUtils.exportTableAsLiquibaseFiles(outFolderPath, "ASYS_BINARIES", null, null, null, false, alias, true);
}
function _exportAsysUsersAdmin()
{
var outFolderPath = outFolderBase + "_demoData/example_asys_users/";
var cond = "NAME = (select NAME from ASYS_USERS where propkey = 'title' and propval = 'Admin')";
LiquiUtils.exportTableAsLiquibaseFiles(outFolderPath, "ASYS_USERS", null, cond, null, false, alias, true, null, "insert_asys_users-admin");
}
function _exportAsysUsersExamples()
{
var outFolderPath = outFolderBase + "_demoData/example_asys_users/";
var usersForExport = db.table("select PROPVAL, NAME from ASYS_USERS where PROPKEY = 'title' and PROPVAL not in ('flowableIdmService', 'Admin')", alias);
usersForExport.forEach(function (user){
var cond = newWhere("ASYS_USERS.NAME", user[1], SqlBuilder.EQUAL(), null, alias);
var fileName = StringUtils.replaceAll(user[0], " ", "_");//keep backwards compatible
LiquiUtils.exportTableAsLiquibaseFiles(outFolderPath, "ASYS_USERS", null, cond.toString(), null, false, alias, true, null, fileName);
});
}
function _exportAsysUsersWorkflow()
{
var outFolderPath = outFolderBase + "Workflow/";
var cond = "NAME = (select NAME from ASYS_USERS where propkey = 'title' and propval = 'flowableIdmService')";
LiquiUtils.exportTableAsLiquibaseFiles(outFolderPath, "ASYS_USERS", null, cond, null, false, alias, true, null, "webserviceUser_flowableIdmService");
}
\ 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