This topic contains example scripts for exporting changes made to networks between commits.
There are two examples:
Use the method csv_changes(commit_id_1, commit_id_2, csvfilename) to output all new, deleted and changed objects from commit id 1 to commit id 2 versions of the network to a csv file of format used by the InfoAsset Manager csv update.
The following example script that can be used to export the data for all changed objects in a network between the last version when data was exported and the current version of the network. The example can be copied and pasted into a text file.
See the Exchange Scripts - Export to CSV topic for more information on the methods used in the script.
Example
# # Example Script to export a csv update file with new, deleted and changed objects # begin puts 'Start InfoAsset Manager Changes Export to CSV Update File' # open an InfoAsset Manager database # db = WSApplication.open(nil,false) # nil indicates the last opened database # get the network from the object type and id # nw = db.model_object_from_type_and_id('Collection Network',1) # get the last version number to which we have updated # this will usually have been saved by a previous update f = File.new("commit_id.txt","r") last_commit_id = f.gets.to_i if ( last_commit_id > 0 ) then # find out if there are any new changes we want latest_commit_id = nw.latest_commit_id() if ( latest_commit_id > last_commit_id ) then # yes there are changes - puts "Exporting changes from Commit ID #{last_commit_id} to Commit ID #{latest_commit_id}" nw.csv_changes(last_commit_id, latest_commit_id, 'outfile.csv') puts "Updated to Commit ID #{latest_commit_id}" # now store the latest_commit_id somewhere safe ready for next time f = File.new("commit_id.txt","w") f.puts "#{latest_commit_id}" puts 'Done' else puts 'Network is up to date' end else # last commit id is zero - this must be a new network, # or the commit id is wrong # need to do a full export as a base line # (not included in this example) # puts 'Cannot export changes for this network' end # handle exceptions # rescue Exception => exception puts "[#{exception.backtrace}] #{exception.to_s}" end
Use the method select_changes(commit_id) to select objects which have been added or modified between the given commit id and the current commit id.
Note: The disadvantage of using this method is that it does not handle deleted objects.
The following example script that can be used to export all objects that have been modified in a network between the local version of the network and the latest version of the network. The example can be copied and pasted into a text file.
See the Exchange Scripts - Open Data Export Centre topic for more information on the methods used in the script.
Example
# # Example Script to export new objects and changes in InfoAsset Manager Data to a Comma Separated Value File # # begin puts 'Start InfoAsset Manager Changes Export to Comma Separated Value File' # open an InfoAsset Manager database # db = WSApplication.open(nil,false) # nil indicates the last opened database # get the network from the object type and id # nw = db.model_object_from_type_and_id('Collection Network',1) # find the commit id of our current network # current_commit_id = nw.current_commit_id if ( current_commit_id > 0 ) then # find out if there are any new changes we want before we load up the network latest_commit_id = nw.latest_commit_id() if ( latest_commit_id > current_commit_id ) then # yes there are changes - # puts "Updating from Commit ID #{current_commit_id} to Commit ID #{latest_commit_id}" # get all the changes in the latest version of the network # nw.update # select the new/changed objects and export them # nw.select_changes(current_commit_id) # set options - export only the selected objects # options=Hash.new options['Error File'] = 'csvexp.txt' options['Export Selection'] = true # export changed network data to csv format # nw.odec_export_ex( 'csv', # export data format => Comma Separated Value 'in_exp.cfg', # field mapping config file options, # specified options override the default options # table group 'node', # first table to export 'node.csv', # export to file name # table group 'pipe', # second table to export 'pipe.csv') # export to file name puts "Updated to Commit ID #{latest_commit_id}" puts 'Done' else puts 'Network is up to date' end else # current commit id is zero - this must be a new network, # or the local copy has been deleted. # update the network and do a full export as a new base line # (not included in this example) # puts 'Cannot export changes for this network' end # handle exceptions # rescue Exception => exception puts "[#{exception.backtrace}] #{exception.to_s}" end