# # # This template is invoked from command line / scheduler actions -a only # # include "templates.util.base_util"; include "templates.util.get_basic_ids"; include "templates.util.database"; include "templates.util.command_line_report_util"; include "templates.statistics.util.verify_caches"; include "templates.statistics.util.create_report_info"; include "templates.statistics.util.create_report_job"; include "templates.statistics.build_report_elements"; include "templates.statistics.export.export_from_command_line"; include "templates.statistics.static_reports.assemble_static_report"; include "templates.statistics.email.email_report"; # The task_originator is command_line or scheduler # -a Actions invoked are: # export_csv_table # send_report_by_email # generate_report_files # generate_all_report_files debug_message("\n#### command_line_report.cfv START \n"); debug_message("\n" . node_as_string("command_line") . "\n"); # debug_message("\n" . node_as_string("preferences.email") . "\n"); string task_originator = volatile.task_originator; string session_id = volatile.session_id; # debug_message("#### session_id: " . session_id . "\n"); bool is_root_admin = true; string profile_name = command_line.profile; string action_name = command_line.action; string report_name = command_line.report_name; string date_filter = command_line.date_filter; string command_line_filter = command_line.filters; string command_line_filter_comment = command_line.filters_comment; string command_line_language = command_line.language; # debug_message("#### task_originator: " . task_originator . "\n"); node profiles = "profiles"; node profile = profiles{profile_name}; string user_node_name = "root_admin"; # # # Get current language # # string current_language; if (command_line_language ne "") then ( current_language = command_line_language; ) else ( current_language = get_current_language(user_node_name); ); # # # # Check for number of licensed profiles # # # handle_valid_number_of_profiles(profiles); # # # Get basic IDs # # node basic_ids = get_basic_ids(profile, current_language); # # # Create the session node # # "sessions_cache." . session_id . ".session_info" = ""; save_node("sessions_cache." . session_id . ".session_info"); string schedule_id; string report_id; # bool expand_paths = command_line.expand_paths; # # # Check if this is the scheduler # # bool is_scheduler = false; if (starts_with(task_originator, "schedule")) then ( schedule_id = replace_first(task_originator, "schedule.", ""); task_originator = "scheduler"; is_scheduler = true; ); # # # # Get the database state # # # bool is_real_time_processing = get_is_real_time_processing(profile_name); if (is_real_time_processing) then ( # Pause the database in case that it is building so that we get an up to date database info node # (This pauses any build for the current task) debug_message("#### command_line_report.cfv get_database_access() START \n"); get_database_access(); debug_message("#### command_line_report.cfv get_database_access() END \n"); ); delete_node("v.db_info"); v.db_info = ""; get_database_info(profile_name, "v.db_info", true); # get_date_info must be true! node db_info = "v.db_info"; # # # # Initial setup # (Checks/creates profile cache, basic data and sessions_cache setup) # # # bool read_extended_profile_dat_from_sessions = false; verify_caches(session_id, read_extended_profile_dat_from_sessions, is_root_admin, profile, profile_name, basic_ids); # # # Handle actions # # string filter_id = ""; bool is_command_line = true; if (action_name eq "generate_report_files" or action_name eq "generate_all_report_files") then ( string output_directory = if (command_line.output_directory ne "") then (command_line.output_directory) else (command_line.generate_html_to_directory); string divider = internal.directory_divider; if (!ends_with(output_directory, divider)) then ( output_directory .= divider; ); bool generate_pdf_friendly_files = command_line.generate_pdf_friendly_files; bool is_generate_all_report_files = ((action_name eq "generate_all_report_files") or (report_name eq "*")); command_line_generate_report_files( session_id, basic_ids, current_language, profile_name, report_name, date_filter, command_line_filter, command_line_filter_comment, output_directory, generate_pdf_friendly_files, is_generate_all_report_files, db_info, "command_line" ); ) else if (action_name eq "export_csv_table" or action_name eq "send_report_by_email") then ( # # Create report info and report job # bool is_calendar = false; string output_format; v.temp_expanded_menu_groups = ""; node expanded_menu_groups = "v.temp_expanded_menu_groups"; # expanded_menu_groups is used for dynamic reports only, so we set an empty node string report_info_id = now_us(); create_report_info(session_id, user_node_name, is_root_admin, report_info_id, profile_name, report_name, is_command_line, "command_line"); if (action_name eq "export_csv_table") then ( output_format = "csv"; ) else ( output_format = "static_email"; ); string report_job_id = create_report_job( session_id, is_root_admin, basic_ids, current_language, profile_name, date_filter, command_line_filter, command_line_filter_comment, filter_id, report_info_id, is_calendar, output_format, db_info, expanded_menu_groups ); string session_profile_path = "sessions_cache." . session_id . ".profiles." . profile_name; node report_job = session_profile_path . ".report_jobs." . report_job_id; # Check for date_filter errors in report_job (invalid date filter syntax or out of range!) # If there is any date filter error the following subroutine will throw an error. validate_date_filter_in_command_line_report(report_job); bool is_ready_report = @report_job{"is_ready_report"}; string report_content; if (action eq "export_csv_table") then ( # # export_csv_table # export_from_command_line(session_id, profile_name, report_job_id, "command_line"); ) else ( # # send_report_by_email # # # Get and verify email parameters so that we don't build any report # with invalid email paramters # node email_info = get_command_line_report_email_info("command_line", is_scheduler); validate_email_info(email_info); # Will throw an error in case of invalid email parameters if (!is_ready_report) then ( # Create the report elements build_report_elements(session_id, profile_name, report_job); ); # Note, volatile.mime_images_buffer is populated within assemble_static_report(), # so it should be available as global variable when we send the email in email_report() report_content = assemble_static_report( session_id, is_root_admin, profile_name, report_name, report_job_id, "", false, "" ); email_report(email_info, report_content); ); # # # Delete session files # # # We delete the session node because its not anymore required # KHP-RC, delete session directory? );