# # # # export_from_command_line() # # # # This template is only used when exporting from the command line and command line via scheduler. # It does the initial setup and then executes export_report_element() include "templates.statistics.export.export_report_element"; subroutine(export_from_command_line( string session_id, string profile_name, string report_job_id, node command_line), ( debug_message("\n\n#### export_report() START \n\n"); # debug_message("#### report_job_id: " . report_job_id . "\n"); bool is_root_admin = true; string session_profile_path = "sessions_cache." . session_id . ".profiles." . profile_name; node report_job = session_profile_path . ".report_jobs." . report_job_id; string report_info_id = @report_job{"report_info_id"}; node report_info = session_profile_path . ".report_infos." . report_info_id; string report_name = @report_info{"report_name"}; node report_elements = report_job{"report_elements"}; node report_element; string report_element_name; string report_element_type; subroutine(export_report_is_valid_report_element( string report_element_type), ( bool is_valid = true; if (matches_regular_expression(report_element_type, "(overview|paths)")) then ( is_valid = false; ); is_valid; )); # # # Get export parameters # # # Note, we allow an output_directory and output_file, though only one of the two can be used! bool export_average = @command_line{"export_average"}; bool export_min = @command_line{"export_min"}; bool export_max = @command_line{"export_max"}; bool export_total = @command_line{"export_total"} or @command_line{"total_row"}; # total_row has been replaced with export_total in v8, though the option remains active for backward compatibility string end_of_line = @command_line{"end_of_line"}; string output_directory = @command_line{"output_directory"}; string output_file = @command_line{"output_file"}; bool is_output_directory = if (output_directory ne "") then (true) else (false); bool is_output_file = if (!is_output_directory and (output_file ne "")) then (true) else (false); # # # # Check the number of report elements to be exported # # # # There must be at least one valid report element to export, else we throw an error. # # Note, we allow to export multiple report elements to command line stream or # when a ouput_directory is defined. We don't allow multiple report elements export # if a single output_file is defined because we can't change the file name! # # int number_of_report_elements_to_export = 0; foreach report_element report_elements ( report_element_type = @report_element{"type"}; if (export_report_is_valid_report_element(report_element_type)) then ( number_of_report_elements_to_export++; ); ); # # # Check if export is valid # # bool is_valid_export = false; if (is_output_file) then ( # We only allow to export a single report element # because the ouput_file already specifies the file name if (number_of_report_elements_to_export == 1) then ( is_valid_export = true; ); ) else ( # We allow to export all valid report elements # of the report. if (number_of_report_elements_to_export > 0) then ( is_valid_export = true; ); ); # # # Handle export # # if (is_valid_export) then ( # If there are multiple report elements and if there is an output_file defined # then we append the report element name to the output_file name # bool modify_output_file = if ((number_of_report_elements_to_export > 1) and (output_file ne "")) then (true) else (false); string cvs_file = if (is_output_file) then (output_file) else (""); if (is_output_directory) then ( # make sure the output_directory ends with a divider if (!ends_with(output_directory, "/") and !ends_with(output_directory, "\\")) then ( # Add last divider output_directory .= "/"; ); ); foreach report_element report_elements ( report_element_name = node_name(report_element); report_element_type = @report_element{"type"}; if (export_report_is_valid_report_element(report_element_type)) then ( if (is_output_directory) then ( # Define the cvs_file name if (number_of_report_elements_to_export == 1) then ( cvs_file = output_directory . report_name . ".csv"; ) else ( cvs_file = output_directory . report_name . "_" . report_element_name . ".csv"; ); ); export_report_element( session_id, is_root_admin, profile_name, report_job, report_element_name, export_average, export_min, export_max, export_total, end_of_line, cvs_file ); ); ); ) else ( # Throw an error if (number_of_report_elements_to_export == 0) then ( # There is no valid report element to export volatile.param1 = report_name; error(lang_messages.ERROR_CSV_EXPORTING_NONE_TABLE_TYPE); ) else ( # There are multiple report elements to export but the user # specified an output_file which doesn't allow exporting # multiple report elements. error(lang_messages.ERROR_MULTI_ELEMENT_EXPORT_OF); ); ); ));