oacs_util::process_objects_csv (public)

 oacs_util::process_objects_csv -object_type object_type -file file \
    [ -header_line header_line ] \
    [ -override_headers override_headers ] [ -constants constants ]

Defined in packages/acs-tcl/tcl/utilities-procs.tcl

This processes a comma separated set of objects, taking the CSV and calling package_instantiate_object for each one.

Switches:
-object_type (required)
-file (required)
-header_line (optional, defaults to "1")
-override_headers (optional)
-constants (optional)
Returns:
a list of the created object_ids

Partial Call Graph (max 5 caller/called nodes):
%3 test_process_objects_csv process_objects_csv (test acs-tcl) oacs_util::process_objects_csv oacs_util::process_objects_csv test_process_objects_csv->oacs_util::process_objects_csv db_transaction db_transaction (public) oacs_util::process_objects_csv->db_transaction package_instantiate_object package_instantiate_object (public) oacs_util::process_objects_csv->package_instantiate_object

Testcases:
process_objects_csv
Source code:
    # FIXME: We should catch the error here
    set csv_stream [open $file r]

    # Check if there are headers
    if {$override_headers ne ""} {
        set headers $override_headers
    } else {
        if {!$header_line} {
            return -code error "There is no header!"
        }

        # get the headers
        ns_getcsv $csv_stream headers
    }

    set list_of_object_ids [list]

    # Process the file
    db_transaction {
        while {1} {
            # Get a line
            set n_fields [ns_getcsv $csv_stream one_line]

            # end of things
            if {$n_fields == -1} {
                break
            }

            # ignore empty lines
            if {$n_fields == 0} {
                continue
            }

            # Process the row
            set extra_vars [ns_set create]
            for {set i 0} {$i < $n_fields} {incr i} {
                set varname [string tolower [lindex $headers $i]]
                set varvalue [lindex $one_line $i]

                # Set the value
                ns_log debug "oacs_util::process_objects_csv: setting $varname to $varvalue"
                ns_set put $extra_vars $varname $varvalue
            }

            # Add in the constants
            if {$constants ne ""} {
                # This modifies extra_vars, without touching constants
                ns_set merge $constants $extra_vars
            }

            # Create object and go for it
            set object_id [package_instantiate_object -extra_vars $extra_vars $object_type]
            lappend list_of_object_ids $object_id

            # Clean Up
            ns_set free $extra_vars
        }
    }

    close $csv_stream

    # Return the list of objects
    return $list_of_object_ids
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-tcl/tcl/utilities-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: