FSN#28168 gen_export settings naar de database
svn path=/Website/trunk/; revision=20017
This commit is contained in:
186
APPL/EXP/exp_shared.js
Normal file
186
APPL/EXP/exp_shared.js
Normal file
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
$Revision$
|
||||
$Id$
|
||||
|
||||
File: exp_shared.js
|
||||
Description: Helper functie
|
||||
Parameters:
|
||||
export_app_key Exportfunctie key
|
||||
Context:
|
||||
Note: ========= LET OP LET OP =========
|
||||
Dit bestand wordt ook gebruikt door ../../utils/gen_export/gen_export.wsf
|
||||
Daar hebben we door CScript maar heel weinig functies!
|
||||
DUS: Geen L() functie voor locale!!!!
|
||||
EN: Geen Server.CreateObject maar new ActiveXObject
|
||||
========= LET OP LET OP =========
|
||||
*/
|
||||
|
||||
// fileStream moet onze data bevatten
|
||||
// export_app_key de export-functie
|
||||
// params export_key mag/zal leeg zijn voor het eerste bestand
|
||||
// customerId: "UWVA"
|
||||
// fac_home: net boven de APPL dus bijv. "d:/apps/facilitor/"
|
||||
// filepathname: optioneel: stoppen we in fac_export_filenaam
|
||||
function expCreateStream(export_key, params)
|
||||
{
|
||||
// params.customerId
|
||||
var ini = getSettings(export_key);
|
||||
ini.applrun = new Date();
|
||||
ini.custid = params.customerId;
|
||||
|
||||
exportResults(ini);
|
||||
var streamObj = { exportFile: getFileName(ini.prefix, ini.postfix, ini.applrun, ini.timestamp)
|
||||
, streamData: exportToStream(ini)
|
||||
};
|
||||
|
||||
return streamObj;
|
||||
}
|
||||
|
||||
|
||||
function getSettings(app_key)
|
||||
{
|
||||
// Read settings from database
|
||||
//
|
||||
var settings = {};
|
||||
var sql = "SELECT *"
|
||||
+ " FROM fac_export_app"
|
||||
+ " WHERE fac_export_app_key = " + app_key;
|
||||
var oRs = Oracle.Execute(sql);
|
||||
if (oRs.Eof)
|
||||
{
|
||||
__Log("Unable to find " + app_key + " in fac_export_app");
|
||||
}
|
||||
else
|
||||
{
|
||||
settings = { code: oRs("fac_export_app_code").value
|
||||
, oms: oRs("fac_export_app_oms").value
|
||||
, xsl: oRs("fac_export_app_xsl").value || ""
|
||||
, charset: oRs("fac_export_app_charset").value || "Windows-1252"
|
||||
, folder: oRs("fac_export_app_folder").value || ""
|
||||
, prefix: oRs("fac_export_app_prefix").value || ""
|
||||
, postfix: oRs("fac_export_app_postfix").value || ""
|
||||
, timestamp: oRs("fac_export_app_timestamp").value || ""
|
||||
, functie_key: oRs("fac_functie_key").value
|
||||
, logpostfix: oRs("fac_export_app_log_postfix").value || ""
|
||||
}
|
||||
}
|
||||
oRs.Close();
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
||||
function exportResults(ini)
|
||||
{
|
||||
// Clean up the mess of the previous run
|
||||
//
|
||||
var sql = "DELETE FROM imp_log"
|
||||
+ " WHERE imp_log_applicatie = " + safe.quoted_sql(ini.code);
|
||||
__Log("SQL: " + sql);
|
||||
Oracle.Execute(sql);
|
||||
//
|
||||
// Call the database procedure for selecting the export results.
|
||||
var selectProc = (ini.custid + "_SELECT_" + ini.code).toUpperCase();
|
||||
var sql = "SELECT DISTINCT name"
|
||||
+ " FROM user_source"
|
||||
+ " WHERE type = 'PROCEDURE'"
|
||||
+ " AND name = " + safe.quoted_sql(selectProc);
|
||||
__Log("SQL: " + sql);
|
||||
var oRs = Oracle.Execute(sql);
|
||||
if(!oRs.Eof)
|
||||
{
|
||||
sql = "BEGIN " + selectProc + "(" + "'" + ini.code + "', '" + ini.applrun + "'" + "); END;";
|
||||
__Log("SQL: " + sql);
|
||||
Oracle.Execute(sql);
|
||||
}
|
||||
else
|
||||
{
|
||||
__Log("Select procedure not found: " + selectProc);
|
||||
}
|
||||
oRs.Close();
|
||||
}
|
||||
|
||||
|
||||
function exportToStream(ini)
|
||||
{
|
||||
var fstr;
|
||||
var exportView = (ini.custid + "_V_EXPORT_" + ini.code).toUpperCase();
|
||||
var sql = "SELECT DISTINCT view_name"
|
||||
+ " FROM USER_VIEWS"
|
||||
+ " WHERE view_name = " + safe.quoted_sql(exportView);
|
||||
__Log("SQL: " + sql);
|
||||
var oRs = Oracle.Execute(sql);
|
||||
if (oRs.Eof)
|
||||
{
|
||||
__Log("Export view not found: " + exportView);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write data to stream.
|
||||
fstr = openStreamWriteText({charset: ini.charset});
|
||||
var sql_v = "SELECT result"
|
||||
+ " FROM " + exportView
|
||||
+ " ORDER BY result_order";
|
||||
__Log("SQL: " + sql_v);
|
||||
var oRs_v = Oracle.Execute(sql_v);
|
||||
while (!oRs_v.Eof)
|
||||
{
|
||||
fstr.WriteText(oRs_v("result").Value, 1); // 0=adWriteChar, 1=adWriteLine (LineSeparator required)
|
||||
oRs_v.MoveNext();
|
||||
}
|
||||
oRs_v.Close();
|
||||
}
|
||||
oRs.Close();
|
||||
return fstr;
|
||||
}
|
||||
|
||||
|
||||
function openStreamWriteText(params)
|
||||
{
|
||||
// params:
|
||||
// lineseparator: -1=adCRLF, 10=adLF, 13=adCR
|
||||
// streamwrite: 1=adSaveCreateNotExist, 2=adSaveCreateOverWrite
|
||||
// charset:
|
||||
var streamwrite = (params.streamwrite ? params.streamwrite : 1);
|
||||
|
||||
var fileStream = new ActiveXObject("ADODB.Stream");
|
||||
fileStream.CharSet = (params.charset ? params.charset : "Windows-1252");
|
||||
fileStream.LineSeparator = (params.lineseparator ? params.lineseparator : -1);
|
||||
fileStream.Type = 2; // 1=adTypeBinary, 2=adTypeText
|
||||
fileStream.Open();
|
||||
|
||||
return fileStream;
|
||||
}
|
||||
|
||||
|
||||
function getFileName(prefix, postfix, daterun, dateformat)
|
||||
{
|
||||
var index = prefix.indexOf(".");
|
||||
var naam = (index==-1?prefix:prefix.substr(0, index)) + formatDate(daterun, dateformat) + postfix;
|
||||
return naam;
|
||||
}
|
||||
|
||||
|
||||
function formatDate(datum, format)
|
||||
{
|
||||
var onejan = new Date(datum.getFullYear(),0,1);
|
||||
var o = { "m+" : datum.getMonth()+1 //month
|
||||
, "d+" : datum.getDate() //day
|
||||
, "H+" : datum.getHours() //hour
|
||||
, "M+" : datum.getMinutes() //minute
|
||||
, "S+" : datum.getSeconds() //second
|
||||
, "q+" : Math.floor((datum.getMonth()+3)/3) //quarter
|
||||
, "s" : datum.getMilliseconds() //millisecond
|
||||
, "w+" : Math.ceil((((datum - onejan) / 86400000) + onejan.getDay()+1)/7) // weeknumber
|
||||
};
|
||||
if (/(y+)/.test(format))
|
||||
format = format.replace(RegExp.$1, (datum.getFullYear()+"").substr(4 - RegExp.$1.length));
|
||||
for(var k in o)
|
||||
{
|
||||
if(new RegExp("("+ k +")").test(format))
|
||||
{
|
||||
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
|
||||
}
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
||||
359
UTILS/gen_export/gen_export.wsf
Normal file
359
UTILS/gen_export/gen_export.wsf
Normal file
@@ -0,0 +1,359 @@
|
||||
<![CDATA[
|
||||
/*
|
||||
$Revision$
|
||||
$Id$
|
||||
|
||||
File: gen_export.wsf
|
||||
Calling: cscript ..\..\..\utils\gen_export\gen_export.wsf UWVA 234 >>genexport.log 2>>&1
|
||||
Parameters: 0: customerId
|
||||
1: fac_export_app_key
|
||||
Context: Scheduled task
|
||||
Note:
|
||||
*/
|
||||
]]>
|
||||
|
||||
<job id="IncludeGenExport">
|
||||
<script language="JScript" src="../wsf_shared.js"/>
|
||||
<script language="JScript" src="../../appl/exp/exp_shared.js"/>
|
||||
<script language="JScript">
|
||||
|
||||
__Log('$Workfile: gen_export.wsf $','$Revision$');
|
||||
if (WScript.Arguments.length < 2)
|
||||
{
|
||||
__Log("Usage: CScript gen_export.wsf XXXX [fac_export_app_key | fac_import_app_code] \n");
|
||||
WScript.Quit();
|
||||
}
|
||||
var customerId = WScript.Arguments(0);
|
||||
var export_app_id = WScript.Arguments(1);
|
||||
|
||||
var applicatieRun = new Date();
|
||||
var udl = "../Oracle.udl";
|
||||
var Oracle = new ActiveXObject("ADODB.Connection");
|
||||
Oracle.Open('File Name='+udl);
|
||||
sql = "BEGIN fac.initsession(NULL); END;"
|
||||
Oracle.Execute(sql)
|
||||
|
||||
convertIni();
|
||||
app_key = getAppKey(export_app_id);
|
||||
if (app_key == -1)
|
||||
WScript.Quit();
|
||||
|
||||
var ini = getSettings(app_key);
|
||||
ini.applrun = applicatieRun;
|
||||
ini.custid = customerId.toUpperCase();
|
||||
|
||||
__Log("Start schedule task");
|
||||
exportResults(ini);
|
||||
|
||||
//
|
||||
var streamParams = {streamwrite: 2};
|
||||
var exportFile = getFileName(ini.prefix, ini.postfix, ini.applrun, ini.timestamp);
|
||||
var expPath = checkDestination(ini.folder, exportFile, streamParams);
|
||||
if (expPath.success)
|
||||
{
|
||||
var streamData = exportToStream(ini);
|
||||
streamData.SaveToFile(expPath.destination, streamParams.streamwrite);
|
||||
streamData.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
__Log(expPath.message);
|
||||
}
|
||||
|
||||
//
|
||||
exportCreate(ini);
|
||||
|
||||
//
|
||||
var logFile = getFileName(ini.prefix, ini.logpostfix, ini.applrun, ini.timestamp);
|
||||
var logPath = checkDestination(ini.folder, logFile, streamParams);
|
||||
if (logPath.success)
|
||||
{
|
||||
logErrors(logPath.destination, ini, {streamwrite: 2});
|
||||
}
|
||||
else
|
||||
{
|
||||
__Log(logPath.message);
|
||||
}
|
||||
__Log("End schedule task");
|
||||
|
||||
//
|
||||
// FUNCTIES
|
||||
//
|
||||
|
||||
|
||||
function trimall(s)
|
||||
{
|
||||
//Spaties *en quotes* er af
|
||||
s = s.replace(/^\s+|\s+$/g,"");
|
||||
s = s.replace(/^\'+|\'+$/g,"");
|
||||
s = s.replace(/^\"+|\"+$/g,"");
|
||||
return s;
|
||||
}
|
||||
|
||||
function convertIni()
|
||||
{
|
||||
// Als er nog een ini-bestand aanwezig is, kopieer dan de instellingen naar de database.
|
||||
//
|
||||
fso = new ActiveXObject("Scripting.FileSystemObject");
|
||||
var genini = "gen_export.ini";
|
||||
if (fso.FileExists(genini))
|
||||
{
|
||||
__Log("Converting " + genini);
|
||||
var f = fso.OpenTextFile(genini, 1); // 1=ForReading
|
||||
var tekst = f.ReadAll();
|
||||
f.Close();
|
||||
var secties = tekst.split("\n[");
|
||||
for (var sectie in secties)
|
||||
{
|
||||
var lines = secties[sectie].split("\n");
|
||||
var sectienaam = trimall(lines[0].replace(/[\[|\]]/ig, "")).toUpperCase();
|
||||
if (sectienaam == "ADO" || sectienaam == "SYSTEM")
|
||||
continue;
|
||||
//
|
||||
__Log("sectie: '" + sectienaam + "' " + lines.length + " lines");
|
||||
var ExportCharset = "";
|
||||
var ExportFolder = "";
|
||||
var ExportPrefix = "";
|
||||
var ExportPostfix = "";
|
||||
var ExportStyleSheet = "";
|
||||
var LogPostfix = "";
|
||||
var BackupTimestamp = "";
|
||||
|
||||
for (var l in lines)
|
||||
{
|
||||
var sp = lines[l].split("=")
|
||||
if (sp.length != 2)
|
||||
continue;
|
||||
var nm = trimall(sp[0]);
|
||||
var vl = trimall(sp[1]);
|
||||
switch (nm.toLowerCase())
|
||||
{
|
||||
case "encoding":
|
||||
ExportCharset = vl;
|
||||
break;
|
||||
case "localpath":
|
||||
ExportFolder = vl||".";
|
||||
break;
|
||||
case "exportfileprefix":
|
||||
ExportPrefix = vl;
|
||||
break;
|
||||
case "exportfilepostfix":
|
||||
ExportPostfix = vl;
|
||||
break;
|
||||
case "stylesheet":
|
||||
ExportStyleSheet = vl;
|
||||
if (ExportStyleSheet.substring(0, 3) == "../")
|
||||
ExportStyleSheet = ExportStyleSheet.substring(3); // Haal ../ er af: wij redeneren vanuit cust-folder
|
||||
if (ExportStyleSheet.substring(0, 2) == "./")
|
||||
ExportStyleSheet = "export/" + ExportStyleSheet.substring(2);
|
||||
break;
|
||||
case "logfilepostfix":
|
||||
LogPostfix = vl;
|
||||
break;
|
||||
case "backupfiletimestamp":
|
||||
BackupTimestamp = vl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ExportFolder && ExportPostfix)
|
||||
{
|
||||
if (ExportFolder == ".")
|
||||
ExportFolder = "../export/";
|
||||
//
|
||||
__Log("Found '" + sectienaam + "' '" + ExportFolder + "' '" + ExportPrefix + "*" + ExportPostfix + "'");
|
||||
sql = "SELECT *"
|
||||
+ " FROM fac_export_app"
|
||||
+ " WHERE fac_export_app_code = " + safe.quoted_sql(sectienaam)
|
||||
+ " AND fac_export_app_prefix IS NOT NULL";
|
||||
//__Log(sql);
|
||||
var oRs = Oracle.Execute(sql);
|
||||
if (!oRs.Eof)
|
||||
{
|
||||
__Log("Reuse key " + oRs("fac_export_app_key").Value);
|
||||
sql = "UPDATE fac_export_app"
|
||||
+ " SET fac_export_app_charset = " + safe.quoted_sql(ExportCharset)
|
||||
+ " , fac_export_app_folder = " + safe.quoted_sql(ExportFolder)
|
||||
+ " , fac_export_app_prefix = " + safe.quoted_sql(ExportPrefix)
|
||||
+ " , fac_export_app_postfix = " + safe.quoted_sql(ExportPostfix)
|
||||
+ " , fac_export_app_xsl = " + safe.quoted_sql(ExportStyleSheet)
|
||||
+ " , fac_export_app_log_postfix = " + safe.quoted_sql(LogPostfix)
|
||||
+ " , fac_export_app_timestamp = " + safe.quoted_sql(BackupTimestamp)
|
||||
+ " WHERE fac_export_app_key = " + oRs("fac_export_app_key").Value
|
||||
//__Log(sql);
|
||||
Oracle.Execute(sql);
|
||||
}
|
||||
else
|
||||
{
|
||||
__Log("New entry '" + sectienaam + "'");
|
||||
sql = "INSERT INTO fac_export_app"
|
||||
+ "( fac_export_app_code"
|
||||
+ ", fac_export_app_oms"
|
||||
+ ", fac_export_app_charset"
|
||||
+ ", fac_export_app_folder"
|
||||
+ ", fac_export_app_prefix"
|
||||
+ ", fac_export_app_postfix"
|
||||
+ ", fac_export_app_xsl"
|
||||
+ ", fac_functie_key"
|
||||
+ ", fac_export_app_log_postfix"
|
||||
+ ", fac_export_app_timestamp"
|
||||
+ ") "
|
||||
+ "SELECT " + safe.quoted_sql(sectienaam)
|
||||
+ " , 'From gen_export.ini '||" + safe.quoted_sql(sectienaam)
|
||||
+ " , " + safe.quoted_sql(ExportCharset)
|
||||
+ " , " + safe.quoted_sql(ExportFolder)
|
||||
+ " , " + safe.quoted_sql(ExportPrefix)
|
||||
+ " , " + safe.quoted_sql(ExportPostfix)
|
||||
+ " , " + safe.quoted_sql(ExportStyleSheet)
|
||||
+ " , fac_functie_key"
|
||||
+ " , " + safe.quoted_sql(LogPostfix)
|
||||
+ " , " + safe.quoted_sql(BackupTimestamp)
|
||||
+ " FROM fac_functie"
|
||||
+ " WHERE fac_functie_code = 'WEB_PRSSYS'"; // veilig
|
||||
//__Log(sql);
|
||||
Oracle.Execute(sql);
|
||||
}
|
||||
oRs.Close();
|
||||
} // if (ExportFolder && ExportPostfix)
|
||||
}
|
||||
// Verwijderen ini file ?
|
||||
}
|
||||
else
|
||||
{
|
||||
__Log("Conversion of " + genini + " not needed.");
|
||||
}
|
||||
}
|
||||
|
||||
function getAppKey(app_id)
|
||||
{
|
||||
// Get a valid fac_export_app_key by app_code or app_key
|
||||
//
|
||||
var export_app_key = -1;
|
||||
if (isNaN(parseInt(app_id)))
|
||||
{
|
||||
var sql = "SELECT fac_export_app_key"
|
||||
+ " FROM fac_export_app"
|
||||
+ " WHERE fac_export_app_code = " + safe.quoted_sql(app_id.toUpperCase());
|
||||
var oRs = Oracle.Execute(sql);
|
||||
if (oRs.Eof)
|
||||
{
|
||||
__Log("Unable to find " + safe.quoted_sql(app_id) + " in fac_export_app");
|
||||
}
|
||||
else
|
||||
{
|
||||
export_app_key = oRs("fac_export_app_key").Value;
|
||||
__Log("Next time change call to: CScript gen_import.wsf " + customerId + " " + export_app_key);
|
||||
}
|
||||
oRs.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
var sql = "SELECT fac_export_app_key"
|
||||
+ " FROM fac_export_app"
|
||||
+ " WHERE fac_export_app_key = " + app_id;
|
||||
var oRs = Oracle.Execute(sql);
|
||||
if (oRs.Eof)
|
||||
{
|
||||
__Log("Unable to find " + app_id + " in fac_export_app");
|
||||
}
|
||||
else
|
||||
{
|
||||
export_app_key = app_id;
|
||||
}
|
||||
oRs.Close();
|
||||
}
|
||||
return export_app_key;
|
||||
}
|
||||
|
||||
|
||||
function exportCreate(ini)
|
||||
{
|
||||
// Call the database procedure for creation of exportfile.
|
||||
var filename = getFileName(ini.prefix, ini.postfix, ini.applrun, ini.timestamp);
|
||||
var exportProc = ini.custid + "_EXPORT_" + ini.code;
|
||||
var sql = "SELECT DISTINCT name"
|
||||
+ " FROM user_source"
|
||||
+ " WHERE type='PROCEDURE'"
|
||||
+ " AND name = " + safe.quoted_sql(exportProc);
|
||||
__Log("SQL: " + sql);
|
||||
var oRs = Oracle.Execute(sql);
|
||||
if (!oRs.Eof)
|
||||
{
|
||||
var sql = "BEGIN "
|
||||
+ exportProc + "(" + safe.quoted_sql(ini.code)
|
||||
+ "," + safe.quoted_sql(ini.applrun)
|
||||
+ ",'-1'" //+ safe.quoted_sql(iniOraclePath) // ??
|
||||
+ "," + safe.quoted_sql(filename)
|
||||
+ ");"
|
||||
+ " END;"
|
||||
__Log("SQL: " + sql);
|
||||
Oracle.Execute(sql);
|
||||
}
|
||||
else
|
||||
{
|
||||
__Log("Export procedure not found: " + exportProc);
|
||||
}
|
||||
oRs.Close();
|
||||
}
|
||||
|
||||
|
||||
function logErrors(folderfile, ini, params)
|
||||
{
|
||||
// log errors
|
||||
var params = params || {};
|
||||
var streamwrite = (params.streamwrite ? params.streamwrite : 1);
|
||||
if (ini.logpostfix != "")
|
||||
{
|
||||
var sql = "SELECT imp_log_datum||';'||imp_log_status||';'||imp_log_omschrijving||';'||imp_log_hint result"
|
||||
+ " FROM imp_log"
|
||||
+ " WHERE imp_log_applicatie = " + safe.quoted_sql(ini.code)
|
||||
+ " ORDER BY imp_log_datum";
|
||||
var oRs = Oracle.Execute(sql);
|
||||
if (!oRs.Eof)
|
||||
{
|
||||
fstr = openStreamWriteText({charset: ini.charset});
|
||||
while (!oRs.Eof)
|
||||
{
|
||||
fstr.WriteText(oRs("result").Value, 1); // 0=adWriteChar, 1=adWriteLine (LineSeparator required);
|
||||
oRs.MoveNext();
|
||||
}
|
||||
fstr.Position = 0;
|
||||
fstr.SaveToFile(folderfile, streamwrite);
|
||||
fstr.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function checkDestination(folder, file, params)
|
||||
{
|
||||
// params
|
||||
// streamwrite: 1=adSaveCreateNotExist, 2=adSaveCreateOverWrite
|
||||
var param = params || {};
|
||||
var result = {destination: "", message: "", success: false};
|
||||
var folderfile = folder + "\\" + file;
|
||||
var streamwrite = (params.streamwrite ? params.streamwrite : 1);
|
||||
|
||||
var fso = new ActiveXObject("Scripting.FileSystemObject");
|
||||
if (!fso.FolderExists(folder))
|
||||
{
|
||||
result.message = "Folder " + folder + " does not exist.";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fso.fileExists(folderfile) && streamwrite == 1)
|
||||
{
|
||||
// Bestand bestaat al, dus kan niet nogmaals gemaakt worden.
|
||||
result.message = "File " + folderfile + " does already exist.";
|
||||
}
|
||||
else
|
||||
{
|
||||
result.destination = folderfile;
|
||||
result.success = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
</script>
|
||||
</job>
|
||||
Reference in New Issue
Block a user