# # action sequence for object action setPersonAttribute # # <>: determine attribute names in database # qexpression proc: { copycvars(this,"action,objtype,attribute,key,value"); this.attvariant = "SETPERSATT"; this.uskurzz = getcvar(this,"key"); switch (this.action) { case "SET": this.actvariant = "SET"; this.attvariant = "SETPERSATT"; break; case "DELETE": this.actvariant = "DEL"; this.attvariant = "DELPERSATT"; break; default: this.errcoll.collect(null,"Illegal action \""+this.action+"\" for setPersonAttribute",{ query: this.query }); break proc; } switch (this.attribute) { case "TELEFON": this.attarchtyp= "PERSINFO"; this.attname = "FON"; break; case "EMAIL": this.attarchtyp= "USEMAIL"; this.attname = "EMAIL"; break; case "MOBILE": this.attarchtyp= "PERSINFO"; this.attname = "MOBILE"; break; case "DEVOPSUSER": this.attarchtyp= "PERSINFO"; this.attname = "DEVOPSUSER"; break; case "TELEFON_PRE_20200101": this.attarchtyp = "PERSINFO"; this.attname = "TELEFON_PRE_20200101"; break; case "EMAIL_PRE_20200101": this.attarchtyp = "USEMAIL"; this.attname = "EMAIL_PRE_20200101"; break; case "FAX": this.attarchtyp = "PERSINFO"; this.attname = "FAX"; break; case "GRUPPE": this.attvariant = this.actvariant + "PERSGROUP"; break; case "NAME": this.attvariant = this.actvariant + "PERSNAME"; break; case "TITELVORNE": this.attarchtyp = "PERSINFO"; this.attname = "TITELVORNE"; break; case "TITELHINTEN": this.attarchtyp = "PERSINFO"; this.attname = "TITELHINTEN"; break; case "VORNAME": this.attvariant = this.actvariant + "PERSVORNAME"; break; case "FAMILIENNAME": this.attvariant = this.actvariant + "PERSFAMNAME"; break; case "USKURZZ": is.attvariant = this.actvariant + "PERSKURZZ"; break; default: this.errcoll.collect(null,"Illegal Person Attribute "+this.attribute); } this.att_insertsql = "insert into CCATT(ATTARCHTYP,ATTPARTYPE,ATTPARKURZ,ATTNAME,ATTVALUE) values(::attarchtyp::,'CCUS',::key::,::attname::,::value::)"; this.att_updatesql = "update CCATT set ATTVALUE=::value:: where ATTARCHTYP=::attarchtyp:: and ATTPARTYPE='CCUS' and ATTPARKURZ=::key:: and ATTNAME=::attname::"; this.att_deletesql = "delete from CCATT where ATTARCHTYP=::attarchtyp:: and ATTPARTYPE='CCUS' and ATTPARKURZ=::key:: and ATTNAME=::attname::"; } # # <>: check which type of attribute to set # pre_qexpression proc: { if (!this.labels[this.attvariant]) { this.errcoll.collect(null,"cannot "+this.action+"("+this.actvariant+") attribute "+this.attribute+" of person "+this.key+", sequence label \""+this.attvariant+"\" does not exist", { query: this.query, actvariant: this.actvariant, attvariant: this.attvariant }); break proc; } } goto @@attvariant@@ # # ------------------------------------------- # # # <>: variant SETPERSATT, check if attribute is already set in database # SETPERSATT: sql select * from CCATT where ATTARCHTYP=::attarchtyp:: and ATTPARTYPE='CCUS' and ATTPARKURZ=::key:: and ATTNAME=::attname:: named_params attarchtyp,key,attname result_varname cqpares # # <>: determine the database statement to use, dependent if previous select delivered rows or not # qexpression if (this.cqpares.getRowCount()>0) { this.actsql = this.att_updatesql; } else { this.actsql = this.att_insertsql; } # # <>: perform the appropriate SQL # sql_varname actsql named_params attarchtyp,key,attname,value # # <>: variant SETPERSATT is complete # goto done # ------------------------------- # # <>: variant DELPERSATT # DELPERSATT: sql @@att_deletesql@@ named_params attarchtyp,key,attname,value then_goto done # ------------------------------- # # <>: variant SETPERSGROUP # SETPERSGROUP: pre_qexpression logger.debug("setPersonAttribute.SETPERSGROUP.USKURZZ="+this.uskurzz+".attribute="+this.attribute+".value="+this.value); sql select * from CCUSAS where USKURZZ=::uskurzz:: and GRP=::value:: named_params uskurzz,value result_varname cagmres # # <>: check if person already in group # if (this.cagmres.getRowCount()>0) goto already_in_group # # <>: get OE for which to join the group # sql select ATTVALUE from CCATT where ATTARCHTYP='ORGINFO' and ATTPARTYPE='CCUS' and ATTPARKURZ=::uskurzz:: and ATTNAME='HOME_OE' named_params uskurzz result_varname hoeres # # <>: check if we have a home OE # if (this.hoeres.getRowCount!=1) goto no_valid_home_oe # # <>: prepare parameters for group membership record # qexpression this.nowdate = new Date(); this.vonjahr = this.nowdate.getFullYear(); this.vonmonat = this.nowdate.getMonth()+1; this.homeoe = this.hoeres.getCellValue(0,0); this.role = 'MEMBER'; # # <>: create group membership record # sql insert into CCUSAS(uskurzz,grp,oe,role,vonjahr,vonmonat,bisjahr,bismonat,assfte) values(::uskurzz::,::value::,::homeoe::,::role::,::vonjahr::,::vonmonat::,null,null,1) named_params uskurzz,value,homeoe,role,vonjahr,vonmonat # # <>: SETPERSGROUP complete # goto done # # <>: collect error for person already in group, this will cause the action to fail # already_in_group: qexpression this.errcoll.collect(null,"Person "+this.uskurzz+" already in group "+this.value); # # <>: terminate processing # goto done # # <>: collect error for person not having a home-OE # no_valid_home_oe: qexpression this.errcoll.collect(null,"Person "+this.uskurzz+" has no valid home Org.-Einheit"); # # <>: terminate processing # goto done # # ------------------------------------------------------------------------------- # # <>: variant DELPERSGROUP - get group membership record # DELPERSGROUP: sql SELECT * from CCUSAS where USKURZZ=::key:: and GRP=::value:: named_params key,value result_varname gmres post_qexpression proc: { if (this.gmres.getRowCount()!=1) { this.errcoll.collect(null,"more than one group membership record for person \""+this.uskurzz+"\" in group \""+this.value+"\"", { memberships: this.gmres }); break proc; } # # <>: delete group membership record # sql DELETE from CCUSAS where USKURZZ=::key:: and GRP=::value:: named_params key,value then_goto done # # ------------------------------------------------------------------------------- # # <>: variant SETPERSVORNAME # SETPERSVORNAME: sql update CCUS set USVORNAME=::value:: where USKURZZ=::key:: named_params key,value # # <>: SETPERSVORNAME complete # goto done # # ------------------------------------------------------------------------------- # # <>: variant SETPERSFAMNAME # SETPERSFAMNAME: sql update CCUS set USFAMILIENNAME=::value:: where USKURZZ=::key:: named_params key,value # # <>: SETPERSFAMNAME complete # goto done # # ------------------------------------------------------------------------------- # # <>: variant SETEPRSKURZZ - start with getting person info # SETPERSKURZZ: sql select ATTNAME,ATTWERT from CCVUSATT where USKURZZ=::key:: named_params key result_varname ccvusatt_result # # <>: extract person attributes from CCVUSATT result # qexpression this.acn = this.ccvusatt_result.findColumn("ATTNAME"); if (this.acn<0) throw new Error("ATTNAME not found in CCVUSATT result"); this.avn = this.ccvusatt_result.findColumn("ATTWERT"); if (this.avn<0) throw new Error("ATTWERT not found in CCVUSATT result"); this.oas = {}; for (let ai=0; ai>: check if USKURZZ has changed # if (this.oas.USKURZZ == this.value) goto done # # <>: check if new USKURZZ not yet in use # sql select USKURZZ,USVORNAME,USFAMILIENNAME from CCUS where USKURZZ=::value:: named_params value result_varname uskinuse # # <>: error stop if already in use # qexpression if (this.uskinuse.getRowCount()>0) { /* the new USKURZZ is already in use, throw an error, this will cancel the whole operation */ throw new Error("USKURZZ \""+this.value+"\" already in use for "+this.uskinuse.getRowCount()+" person(s): "+aux.objTxt(this.uskinuse.getRowObject(0))); } # # <>: change USKURZZ in CCATT # sql update CCATT set ATTPARKURZ=::value:: where ATTPARTYPE='CCUS' and ATTPARKURZ=::key:: named_params value,key # # <>: get all tables having USKURZZs # sql select TABLE_NAME from information_schema.COLUMNS where COLUMN_NAME='USKURZZ' result_varname uskt # # <>: prepare table loop # qexpression this.tli = 0; # # <>: check if complete # nxtusk: if (this.tli>=this.uskt.getRowCount()) goto setusk_done # # <>: # qexpression this.usktable = this.uskt.getCellValue(this.tli,0); this.sql_usktab = "update "+this.usktable+" set USKURZZ=::value:: where USKURZZ=::key::"; # # <>: skip views (by convention, views in CCDB start with "CCV" or "ccv") # if (this.usktable.toUpperCase().startsWith("CCV")) goto usk_skip # # <>: execute update in <.usktable> # sql_varname sql_usktab named_params value,key # # <>: one USK-table done # usk_skip: qexpression this.tli++; # # <>: # goto nxtusk # # <>: change of USKURZZ done (or not necessary), redirect key to new USKURZZ to show the same person, but with new USKURZZ in the chain_query # setusk_done: qexpression this.key = this.value # # <>: terminate processing # goto done # # ------------------------------------------------------------------------------- # # <>: variant SETPERSNAME - determine new parts values # SETPERSNAME: qexpression this.nameutils = require("./nameutils.js"); this.nas = this.nameutils.parseName(this.value); # # <>: get person record from CCVUSATT # sql select ATTNAME,ATTWERT from CCVUSATT where USKURZZ=::key:: named_params key result_varname ccvusatt_result # # <>: extract person attributes from CCVUSATT result_varname # qexpression this.acn = this.ccvusatt_result.findColumn("ATTNAME"); if (this.acn<0) throw new Error("ATTNAME not found in CCVUSATT result"); this.avn = this.ccvusatt_result.findColumn("ATTWERT"); if (this.avn<0) throw new Error("ATTWERT not found in CCVUSATT result"); this.oas = {}; for (let ai=0; ai>: check which name attributes have changed in what way # qexpression /* ccl dictates which attributes of the name to be checked for a change: */ /* nan: new attribute name oan: old attribute name cat: category caa: CCATT archetype */ let ccl = [ {nan: 'titelvorne', oan: 'TITELVORNE', cat: "ATT", caa: "PERSINFO" }, {nan: 'vorname', oan: 'VORNAME', cat: "VNAME", caa: "CCUS" }, {nan: 'familienname', oan: 'FAMILIENNAME', cat: "FNAME", caa: "CCUS" }, {nam: 'titelhinten', oan: 'TITELHINTEN', cat: "ATT", caa: "PERSINFO" } ]; let ca; /* build a sequence of instructions in this.ccs based on the changed attributes */ this.ccs = new Array(); for (let ai=0; ai>: process all queued name attribute change instructions: - check if we're ready # chgnxtatt: if (this.cci>=this.ccs.length) goto nameset_done # # <>: prepare current name attribute change # qexpression this.cop = this.ccs[this.cci].cop; this.can = this.ccs[this.cci].can; this.cav = this.ccs[this.cci].cav; this.cat = this.ccs[this.cci].cat; this.caa = this.ccs[this.cci].caa; this.cpstepname = this.cop + "_" + this.cat; # # <>: branch to appropriate processing step # goto @@pstepname@@ # # <>: NOP_ATT - nothing to be done for a generic attribute # NOP_ATT: goto chgnamattdon # # <>: NEW_ATT - have to ADD a generic attribute # NEW_ATT: sql INSERT INTO CCATT(ATTARCHTYP,ATTPARTYP,ATTPARKURZ,ATTNAME,ATTVALUE) values(::caa::,'CCUS',::key::,::can::,::cav::) named_params caa,key,can,cav then_goto chgnamattdon # # <>: DEL_ATT - have to delete a generic attribtues # DEL_ATT: sql DELETE FROM CCATT WHERE ATTARCHTYP=::caa:: and ATTPARTYP='CCUS' and ATTPARKURZ=::key:: and ATTNAME=::can:: named_params caa,key,can then_goto chgnamattdon # # <>: UPD_ATT - have to UPDATE a generic attributes' value # UPD_ATT: sql UPDATE CCATT SET ATTVALUE=::cav:: WHERE ATTARCHTYP=::caa:: and ATTPARTYP='CCUS' and ATTPARKURZ=::key:: and ATTNAME=::can:: then_goto chgnamattdon # # <>: NEW_VNAME - have to add specific attribute VNAME # NEW_VNAME: sql UPDATE CCUS set USVORNAME=::cav:: where USKURZZ=::key:: named_params cav,key then_goto chgnamattdon # # <>: DEL_VNAME - have to delete specific attribute VNAME # DEL_VNAME: sql UPDATE CCUS set USVORNAME='' where USKURZZ=::key:: named_params key then_goto chgnamattdon # # <>: UPD_VNAME - have to update specific attribute VNAME (VORNAME of a person) # UPD_VNAME: sql UPDATE CCUS set USVORNAME=::cav:: where USKURZZ=::key:: named_params cav,key then_goto chgnamattdon # # <>: NEW_FNAME # NEW_FNAME: sql UPDATE CCUS set USFAMILIENNAME=::cav:: where USKURZZ=::key:: named_params cav,key then_goto chgnamattdon # # <>: DEL_FNAME # DEL_FNAME: sql UPDATE CCUS set USFAMILIENNAME='' where USKURZZ=::key:: named_params key then_goto chgnamattdon # # <>: UPD_FNAME # UPD_FNAME: sql UPDATE CCUS set USFAMILIENNAME=::cav:: where USKURZZ=::key:: named_params cav,key then_goto chgnamattdon # # <>: one name attribute change done, increment counter at repeat loop # chgnamattdon: pre_qexpression this.cci++; goto chgnxtatt # # <>: NAME set complete # nameset_done: goto done # # <>: finally, set chain query to re-display person info after having performed the action # done: qexpression this.query.chain_query = {dataname: "personinfo", uskurzz: this.key};