# # ITSV GmbH # CCDB - Command and Control Database # # FILE: dquermfile_createmfiles.txt # DESCRIPTION: DQUERY definition for CCDB DQUERY "createmfiles" # @querytitle Mehrere managed Files erzeugen @querydescription erzeugt mehrere Managed Files @group DATAFILE @attributenames numfiles:integer:{{numfilesoptions}},mfiletype:string:{{mfiletypeoptions}},lpath:string:{{lpathoptions}},attribs:string:{{attribsoptions}},filedata:string:{{filedataoptions}},descriptor:string:{{descriptoroptions}} @numfilesoptions { labeltext: "Anzahl Dateien", is_optional: true, typedesc: "Anzahl von Dateien, die erzeugt werden sollen, Vorgabewert = 3" } @mfiletypeoptions { labeltext: "MFILE-Type", is_optional: true, typedesc: "Type des/r Managed Files, das/die angelegt werden soll(en), mit @@..@@ Platzhaltern für Variable, Variable: filenumber, mfiletype, lpath, attribs[.attribut], filedata" } @lpathoptions { labeltext: "Logischer Pfad", is_optional: true, typedesc: "Logischer Pfad, an dem das/die erzeugten MFILEs angelegt werden soll(en), mit @@..@@ Platzhaltern für Variable, Variable: filenumber, mfiletype, lpath, attribs[.attribut], filedata" } @attribsoptions { labeltext: "Attribute", is_optional: true, typedesc: "fachliche Attribute in JSON-Format, mit @@..@@ Platzhaltern für Variable, Variable: filenumber, mfiletype, lpath, attribs[.attribut], filedata" } @filedataoptions { labeltext: "Dateiinhalt", is_optional: true, typedesc: "Text, der in die Datei(en) geschrieben werden soll(en), mit @@..@@ Platzhaltern für Variable, Variable: filenumber, mfiletype, lpath, attribs[.attribut], filedata" } @descriptoroptions { labeltext: "Deskriptor", is_optional: true, typedesc: "JSON / javascript Objekt zur Beschreibung der Erzeugung: \n"+ "Attribute: numfiles,mfiletype,lpath,attribs,filedata - "+ "mit @@..@@-Platzhaltern - "+ "Variable: filenumber, mfiletype, lpath, attribs[.attribut], filedata" } @querytype function @function seqtrans.seqtrans @formpagetitle Managed Files erzeugen @init.qexpression this.inputresult = new aux.Result({ resulttype: 'dbresult', rows: [[0]], metaData: [ { name: "column0" } ] }); ~query.tsteps # # 00: check parameters # qexpression proc: { this.descriptor = this.query.descriptor; if (!this.descriptor) { this.desc = {}; } else { this.desc = aux.txtObjDecode(this.descriptor); } if (this.query.numfiles) this.desc.numfiles = this.query.numfiles; if (this.query.mfiletype) this.desc.mfiletype = this.query.mfiletype; if (this.query.lpath) this.desc.lpath = this.query.lpath; if (this.query.attribs) this.desc.attribs = this.query.attribs; if (this.query.filedata) this.desc.filedata = this,query.filedata; if (!this.desc.numfiles) this.desc.numfiles = 3; if (!this.desc.mfiletype) this.desc.mfiletype = "gentext"; if (!this.desc.lpath) this.desc.lpath = "/TEST/MFILES"; if (!this.desc.attribs) this.desc.attribs = { DESCRIPTION: "test mfile @@filenumber@@", NUMBER: "@@filenumber@@", TYPE: "@@mfiletype@@" }; if (!this.desc.filedata) this.desc.filedata = "MFILE test data, type=@@mfiletype@@, filenumber=@@filenumber@@"; this.fnum = 0; } # # 01: begin of iteration number # nextfile: if (this.fnum>=this.desc.numfiles) goto alldone # # 02: create file number , before, file data and file attributes are placeholder-populated # aexpression proc: { this.filenumber = this.fnum + 1; let fdata = aux.populate({ template: this.desc.filedata, data: this.desc, adata: this, defval: "_createmfiles_NODATA_", delimname: "double_ats" }); logger.debug(this.phead("FDATA=")+fdata); let logpath = aux.populate({ template: this.desc.lpath, data: this.desc, adata: this, defval: "_createmfiles_NODATA_", delimname: "double_ats" }); logger.debug(this.phead("LOGPATH=")+logpath); let fattr = aux.deepCopy(this.desc.attribs); aux.populateAllStrings(fattr,{ context: this.desc, scontext: this, populate_options: { delimname: "double_ats" } }); logger.debug(this.phead("FATTR=")+aux.objTxt(fattr)); mfile.saveToMfile(null,this.desc.mfiletype,fdata,{ mfileattribs: fattr, mfilelpath: logpath }, function(err,res) { if (err) { this.errcoll.collect(err,"Error in saveToMfile",res); this(err); } logger.debug(this.phead("saveToMfile.CALLBACK")+" - res: "+aux.objTxt(res)); if (!res) { this.errcoll.collect(null,"no result from saveToMfile",{ err: err, res: res }); this(err,res); return; } if (!res.resulttype) { this.errcoll.collect(null,"no resulttype from saveToMfile",{ err: err, res: res }); this(err,res); return; } if (res.resulttype!='object') { this.errcoll.collect(null,"resulttype from saveToMfile is not object",{ err: err, res: res }); this(err,res); return; } if (!res.resultobject.mfileid) { this.errcoll.collect(null,"result from saveToMfile does not have mfileid",{ err: err, res: res }); this(err,res); return; } this.res = aux.deepCopy(res.resultobject); this(); }.bind(this)); } # # 03: end of loop body, rinse and repeat # endmove: pre_qexpression this.ppush([this.phead("FILEPROCESSED"), "NUM="+this.fnum, { rawhtml: "MFILEID="+this.res.mfileid+"" }, { rawhtml: ""+ ""+ ""+ ""+ ""+ ""+ "
STATUS "+this.res.status+"
ATTRIBS"+this.res.mfileattribs+"
LPATH "+this.res.mfilelpath+"
PATH "+this.res.mfilepath+"
NAME "+this.res.mfilename+"
" } ]); this.fnum++; goto nextfile # # 09: all files done # alldone: pre_qexpression this.ppush([this.phead("COMPLETE"),"FILESTOPROCESS="+this.desc.numfiles,"FILESPROCESSED="+this.fnum,""]); end