{= # get_dashboard_data.cfv # This returns dashboard data for the requested profiles. include "templates.util.base_util"; include "templates.util.rbac.rbac_util"; include "templates.util.encoding"; include "templates.util.database"; include "templates.admin_pages.profiles_dashboard.get_dashboard_data_util"; debug_message("\n\n#### get_dashboard_data.cfv \n"); debug_message("\n" . node_as_string("v.fp") . "\n"); string session_id = volatile.session_id; bool is_root_admin = get_is_root_admin(); string active_page = v.fp.active_page; string page_token = v.fp.page_token; # # Check RBAC permissions # if ((is_root_admin or get_admin_feature_permission(session_id, active_page, "view")) and get_is_valid_page_token(session_id, active_page, page_token)) then ( node requested_profiles = "v.fp.profiles"; node item; string profile_name; bool requires_db_info; bool is_possible_report_data; bool waiting_for_report_data; int report_cells_code; string report_cells_dat; string dat = "["; node profiles_dashboard = "profiles_dashboard"; # Cancel any active dashboard report generation string session_profiles_dashboard_path = "sessions_cache." . session_id . ".profiles_dashboard"; # if (!?(session_profiles_dashboard_path . ".info")) { # session_profiles_dashboard_path . ".info" = ""; # save_node(session_profiles_dashboard_path . ".info"); # }; # # node dashboard_info = session_profiles_dashboard_path . ".info"; # string session_profiles_dashboard_queue_path = session_profiles_dashboard_path . ".queue"; # session_profiles_dashboard_path . ".cancel_report_generation" = true; # save_node(session_profiles_dashboard_path); # Clean up session_profiles_dashboard_queue_path by removing every node where report generation # has not yet started. If one of this profiles is still required then it will be in the # request anyway. # if (?(session_profiles_dashboard_queue_path)) then ( # # foreach item session_profiles_dashboard_queue_path ( # # if (!@item{"is_generating"}) then ( # delete_node(item); # ); # ); # ); string session_dashboard_profile_path; string cached_report_path; string report_checksum; string error_message; node profile_dashboard_report; string report_state; # Track profiles which require report generation for the current view # delete_node("v._missing_profile_dashboard_reports_in_view"); # v._missing_profile_dashboard_reports_in_view = ""; # node missing_profile_dashboard_reports_in_view = "v._missing_profile_dashboard_reports_in_view"; foreach item requested_profiles ( profile_name = node_name(item); requires_db_info = @item{"requires_db_info"}; is_possible_report_data = @item{"is_possible_report_data"}; waiting_for_report_data = @item{"waiting_for_report_data"}; error_message = ""; # # Check if a snapon operation is active # # TODO - Check if we need is_active_snapon_operation. Response is most likely much faster # without checking for active snapon. # bool is_active_snapon_operation = get_is_active_snapon_operation(profile_name); # debug_message("#### is_active_snapon_operation: " . is_active_snapon_operation . "\n"); # # Get database info # # if (requires_db_info) then ( # # ); bool get_date_info = false; # Should be false which is faster. node db_info = get_database_info(profile_name, get_date_info); debug_message("\n#### profile_name: " . profile_name . "\n"); # debug_message("\n#### get_db_info_data.cfv - database_info:\n" . node_as_string(db_info) . "\n"); bool database_is_building = get_database_is_building(profile_name, db_info); # bool initial_build_done = get_initial_build_done(db_info); bool database_is_built = @db_info{"built"}; # debug_message("#### database_is_building: " . database_is_building . "\n"); # debug_message("#### database_is_built: " . database_is_built . "\n"); # Get db_state int db_state = 0; if (database_is_building) then ( db_state = 1; ) else if (database_is_built) then ( db_state = 2; ); # TODO - check if we need to handle realtime processing # databaseIsReadyForReporting is only required for realtime processing. # bool database_is_ready_for_reporting = get_database_is_ready_for_reporting(db_info); # Get last modified in epoc string db_last_modified; int db_last_modified_epoc; # int db_modified_seconds_ago = 0; if (!database_is_building and database_is_built) then ( db_last_modified = @db_info{"last_modification_time"}; db_last_modified_epoc = date_time_to_epoc(db_last_modified); ); # # Handle report cells data (report data per profile) # # Set report_state in response: ignore, update, unchanged, ready if (database_is_built and (is_possible_report_data or waiting_for_report_data)) then ( session_dashboard_profile_path = session_profiles_dashboard_path . ".profiles." . profile_name; # cached_report_path = "profiles_cache" if (waiting_for_report_data) then ( report_checksum = @session_dashboard_profile_path{"report_checksum"}; cached_report_path = "profiles_cache." . profile_name . ".profiles_dashboard." . report_checksum; # Response is unchanged or ready # if (@(session_dashboard_profile_path . ".is_ready")) then ( if (?(cached_report_path . ".is_ready") and @(cached_report_path . ".is_ready")) then ( report_state = "ready"; report_cells_dat = get_report_cells_dat(cached_report_path . ".columns"); ) else ( report_state = "unchanged"; report_cells_dat = "[]"; ); ) else ( # Response is ignore, update or ready (if report is already cached) profile_dashboard_report = get_profile_dashboard_report( profiles_dashboard, profile_name, db_last_modified); debug_message("#### profile_dashboard_report:\n" . node_as_string(profile_dashboard_report) . "\n"); if (@profile_dashboard_report{"is_valid_dashboard_cell"}) then ( # Check if there is a cached report report_checksum = @profile_dashboard_report{"report_checksum"}; cached_report_path = "profiles_cache." . profile_name . ".profiles_dashboard." . report_checksum; debug_message("#### report_checksum 2: " . report_checksum . "\n"); debug_message("#### cached_report_path 2: " . cached_report_path . "\n"); # Add profile to session profiles dashboard session_dashboard_profile_path . ".profile_name" = profile_name; session_dashboard_profile_path . ".report_checksum" = report_checksum; session_dashboard_profile_path . ".task_id" = ""; if (?(cached_report_path)) then ( # The report already exists in cache debug_message("#### cached_report_path EXISTS \n"); if (?(cached_report_path . ".is_ready") and @(cached_report_path . ".is_ready")) then ( report_state = "ready"; ) else ( report_state = "update"; ); report_cells_dat = get_report_cells_dat(cached_report_path . ".columns"); ) else ( # Report does not yet exist. Track report_checksum and # save report data in profile_dashboard and profiles cache. debug_message("#### cached_report_path DOES NOT EXIST \n"); clone_node(profile_dashboard_report, cached_report_path); save_node(cached_report_path); report_state = "update"; report_cells_dat = get_report_cells_dat(profile_dashboard_report{"columns"}); ); ) else ( # There is no report cell to display report_state = "ignore"; report_cells_dat = "[]"; ); ); ) else ( report_state = "ignore"; report_cells_dat = "[]"; ); debug_message("#### report_state: " . report_state . "\n"); # Track profiles which are not yet ready in # profiles_dashboard_required_profiles by report_checksum # if (report_state ne "ignore" and # report_state ne "ready" and # report_checksum ne "" and # !?(session_profiles_dashboard_queue_path . "." . report_checksum)) then ( # # # # Save the node in session_profiles_dashboard_queue_path. Report generation # # will be initiated by dashboard_reports_manager.cfv. # # session_profiles_dashboard_queue_path . "." . report_checksum . ".report_checksum" = report_checksum; # session_profiles_dashboard_queue_path . "." . report_checksum . ".profile_name" = profile_name; # # session_profiles_dashboard_queue_path . "." . report_checksum . ".is_generating" = false; # # # Don't add node before it is ready # # session_profiles_dashboard_queue_path . "." . report_checksum . ".is_ready" = false; # # # missing_profile_dashboard_reports_in_view{profile_name} = true; # # save_node(session_profiles_dashboard_queue_path . "." . report_checksum); # ); string item_dat = "{"; item_dat .= add_json("name", profile_name, "string"); item_dat .= add_json("dbBuilt", database_is_built, "bool"); item_dat .= add_json("dbBuilding", database_is_building, "bool"); item_dat .= add_json("dbLastMod", db_last_modified_epoc, "int"); item_dat .= add_json("reportState", report_state, "string"); item_dat .= add_json("reportCells", report_cells_dat, "obj"); item_dat .= add_json("errorMessage", error_message, "string"); item_dat = close_json(item_dat); dat .= item_dat . ","; ); # Update session_dashboard data # clone_node(missing_profile_dashboard_reports_in_view, session_profiles_dashboard_path . ".required_profiles"); # Reset cancel_report_generation # session_profiles_dashboard_path . ".cancel_report_generation" = false; if (?(session_profiles_dashboard_path . ".profiles")) then ( save_node(session_profiles_dashboard_path . ".profiles"); # # Start generating reports while basic data are loaded # node session_profiles_dashboard_profiles = session_profiles_dashboard_path . ".profiles"; manage_profiles_dashboard_report_generation( session_id, page_token, active_page, session_profiles_dashboard_profiles); # # Start new thread to return immediately # # volatile.options.1 = "background"; # # volatile.options.2 = "-dp"; # volatile.options.3 = "templates.admin_pages.profiles_dashboard.dashboard_reports_manager"; # # volatile.options.4 = "-v"; # volatile.options.5 = "e"; # # volatile.options.6 = "volatile.session_id"; # volatile.options.7 = session_id; # # volatile.options.8 = "v.fp.page_token"; # volatile.options.9 = page_token; # # volatile.options.10 = "v.fp.active_page"; # volatile.options.11 = "profiles"; # # # debug_message("#### exec options: " . node_as_string('volatile.options') . "\n"); # # # # Wait for dashboard_reports_manager # bool wait = true; # # string pid = exec("", "volatile.options", wait); ); # # Send response # dat = replace_last(dat, ",", "]"); # debug_message("#### dat: " . dat . "\n"); 'profilesDashboard.getDashboardDataResponse(' . dat . ')'; ) else ( # No permission to view this resource (URL) display_no_permission_html(); ); =}