Questa è una vecchia versione del documento!
changeClassif (script lua per modificare classificazione e voce di indice)
Lo script è stato realizzato per modificare massivamente la classificazione e la voce di indice di un insieme di documenti ottenuto tramite una specifica query.
Su ogni documento viene verificato la presenza di una classificazione (in questo caso 06/32 - Definizione agevolata 2016 - tardive) e di una voce di indice (in questo caso Definizione agevolata 2016 TARDIVE - regione) e modificare secondo le regole impostate dentro lo script.
Pertanto se si vuole riutilizzare lo script è necessario modificare soltanto le denominazioni della classificazione e delle voci di indice
- changeClassif.lua
local dbg = require 'xw.dbg' ({active=false, key='acl'}) local xw = require('extraway') xw.addPackage("$.xwTools") ; --[[- --]] function changeClassif(query) -- deactivate triggers xw.triggersOff() ; local outputXML = xw.prepareRecord("<report></report>") ; local outputMainNode = outputXML:selectFirstNode("/report") ; local recordIsModified = false ; local targetRecordSet = xw.executeQuery(query) ; xw.log.msg("Working on query: "..query.." records)") if ( targetRecordSet:isValid() and 0 < #targetRecordSet ) then local targetRecord = targetRecordSet:getFirst() ; while ( targetRecord:isValid() ) do recordIsModified = false ; targetRecord_LockResult = targetRecord:lock() ; if ( targetRecord_LockResult == true ) then local targetRecordRootNode = targetRecord:selectFirstNode("/doc", nil) ; local searchClassifandReplace = targetRecord:selectFirstNode("/doc/classif", nil) ; if ( searchClassifandReplace:isValid() ) then if ( searchClassifandReplace:getValue() == '06/32 - Definizione agevolata 2016 - tardive' ) then searchClassifandReplace:setValue('06/29 - Definizione agevolata 2016') ; recordIsModified = true ; end if ( searchClassifandReplace:getAttribute("cod") == '06/32' ) then searchClassifandReplace:setAttribute("cod", '06/29') ; recordIsModified = true ; end end --local searchClassifCodandReplace = targetRecord:selectFirstNode("/doc/classif", nil) ; --if ( searchClassifCodandReplace:isValid() ) then -- if ( searchClassifCodandReplace:getAttribute("cod") == '06/32' ) then -- searchClassifCodandReplace:setAttribute("cod", '06/29') ; -- recordIsModified = true ; -- end --end local searchVoceandReplace = targetRecord:selectFirstNode("/doc/voce_indice", nil) ; if ( searchVoceandReplace:isValid() ) then if ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Abruzzo' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Abruzzo') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Basilicata' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Basilicata') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Calabria' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Calabria') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Campania' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Campania') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Emilia Romagna' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Emilia Romagna') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Friuli Venezia Giulia' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Friuli Venezia Giulia') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Lazio' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Lazio') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Liguria' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Liguria') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Lombardia' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Lombardia') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Marche' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Marche') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Piemonte e Val D\'Aosta' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Piemonte e Val D\'Aosta') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Puglia' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Puglia') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Sardegna' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Sardegna') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Toscana' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Toscana') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Trentino Alto Adige' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Trentino Alto Adige') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Umbria' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Umbria') ; recordIsModified = true ; elseif ( searchVoceandReplace:getValue() == 'Definizione agevolata 2016 TARDIVE - Veneto' ) then searchVoceandReplace:setValue('Definizione agevolata 2016 - Veneto') ; recordIsModified = true ; end end if ( recordIsModified ) then local outcome = targetRecord:save() ; if ( outcome <= 0 ) then targetRecord:unlock() ; xw.log.msg('save error') ; end else targetRecord:unlock() ; end else xw.log.msg('lock error') ; end targetRecord = targetRecordSet:getNext() ; end end -- activate triggers xw.triggersOn() ; return 'true' ; end changeClassif = { changeClassif = changeClassif, changeClassif_signature = { inParms = {"query"}, outParms = {"result"} } } ;
Per il suo utilizzo lo script va copiato nella directory /opt/3di.it/extraway/xwee/script e va eseguito tramite il seguente xmlcommand:
<?xml version="1.0" encoding="ISO-8859-1"?> <cmd stored="$.changeClassif.changeClassif"> <query>([/doc/storia/creazione/@data/]="20170725")</query> </cmd>