Slate Implementation Testing Help

Initialize Variables

This set of functions provides a framework for managing and processing student records in a batch or interactive environment. The process begins with initializing the environment, loading global configurations, and validating key data fields. Records are then enriched with default values, and their fields are organized into a structured map. SQL queries are dynamically generated to populate forms and match records based on specific criteria.

Additionally, key data points are logged for workflow notifications and debugging purposes. This system ensures data consistency, supports flexible query generation, and enables effective batch or interactive processing.

Processing Workflow

  1. Initialize Environment (initialize_variables)

    • Sets up global and local configurations.

    • Validates essential record fields.

    • Determines batch or interactive mode.

  2. Fetch Record Data (get_record_fields)

    • Extracts and organizes raw record data into a structured format.

  3. Apply Default Values (get_defaults)

    • Populates missing record fields with defaults from the GLOBALS DataList.

  4. Generate SQL Query for Form Population

    • Calls get_query() to dynamically create a SQL query for retrieving additional data.

  5. Log Record Entries (set_record_entries)

    • Logs critical record data fields for use in workflow and notifications.

  6. Additional Query (get_query_inline)

    • Generates a detailed inline SQL query for advanced data retrieval and matching.

Function Summary

Function Name

Purpose

Key Outputs

initialize_variables

Initializes the environment and validates key fields.

Record map, default values, query, logs.

get_record_fields

Converts raw record data into a structured format.

Structured map of record fields.

get_defaults

Applies default values to missing record fields.

Enriched record map with defaults.

get_query

Dynamically generates a SQL query.

SQL query for data retrieval.

set_record_entries

Logs critical fields for debugging.

Record entries for notifications.

get_query_inline

Provides a template for inline SQL queries.

SQL query template.

Core Functions

initialize_variables()

Purpose:
Prepares the environment, initializes key variables, and validates critical fields.

Key Steps:

  1. Load global configurations and log settings.

  2. Initialize record map and apply default values.

  3. Generate SQL query for data retrieval.

  4. Validate critical fields (student_type, entry_term, residency).

void initialize_variables() { string rev = Batch.getRevision(); DataList GLOBALS = datalists["GLOBALS"]; log_sql = GLOBALS.get("CONFIG", "log_sql") == "true"; ssn_checks = 0; route_to_form = false; _record = get_record_fields(Record.get(".*")); _record = get_defaults(_record, GLOBALS, "DEFAULT"); form_query = get_query(); set_record_entries(); if (rev == "Test") { _record.put("banner_id", ""); } operator = User.getId(); Record.log("operator - " + operator); matches = {}; if (_record.get("student_type") == "") Record.wait("No Student Type"); if (_record.get("entry_term") == "") Record.wait("No Application Start Term"); if (_record.get("residency") == "") Record.wait("No Residency"); Map essays = get_record_fields(Record.get("essay_*")); string[] essay_keys = essays.keySet(); }

get_record_fields()

Purpose:
Converts raw record data into a structured map for easier handling.

Key Steps:

  1. Iterate through the raw record data.

  2. Convert key-value pairs into a structured map.

  3. Replace null values with empty strings.

Map get_record_fields(Map[] record_data) { Map record = new Map(); for (integer i = 0; i < record_data.size(); i++) { string key = record_data[i].get("name"); string value = record_data[i].get("value"); value = value == null ? "" : value; record.put(key, value); } return record; }

get_defaults()

Purpose:
Applies default values to missing fields in the record map.

Key Steps:

  1. Retrieve default values from the GLOBALS DataList.

  2. Identify missing fields in the record map.

  3. Apply corresponding default values to these fields.

Map get_defaults(Map _record, DataList dl, string group) { Map defaults = dl.getByGroup(group); string[] default_keys = defaults.keySet(); for (integer i = 0; i < default_keys.size(); i++) { string key = default_keys[i]; string value = defaults.get(key); if (_record.get(key) == null) { _record.put(key, value); } } return _record; }

get_query()

Purpose:
Dynamically generates a SQL query for form population.

Key Steps:

  1. Define query parameters based on the record.

  2. Use a formatter to construct the query dynamically.

string get_query() { string query = ""; Map query_params = new Map(); query_params.put("tele_code", "PR"); query_params.put("ref_id_type", _record.get("slate_ref_type")); query_params.put("perm_addr_type", "PR"); query_params.put("term", _record.get("entry_term")); query_params.put("mail_addr_type", "MA"); query_params.put("student_email_type", "PE"); query_params.put("cell_phone_type", "CELL"); Formatter f = formatters["Match Form Query Formatter"]; f.setDataModel(query_params); query = f.parse(); return query; }

set_record_entries()

Purpose:
Logs key record fields for notifications or debugging.

Key Steps:

  1. Clear existing entries.

  2. Add critical fields (e.g., student_first_name, student_last_name).

  3. Log the entries for review.

void set_record_entries() { Record.clearEntries(); Record.putEntry("student_level", Record.getData("level")); Record.putEntry("student_first_name", Record.getData("student_first_name")); Record.putEntry("student_last_name", Record.getData("student_last_name")); Record.putEntry("student_ref_id", Record.getData("slate_ref")); JSONObject record_entry_json = Record.getEntries(); Console.log("Begin Record Entries: "); Console.log(toString(record_entry_json)); Console.log("End Record Entries: "); }

get_query_inline()

Purpose:
Provides a template for detailed inline SQL queries.

Key Steps:

  1. Define a SQL template.

  2. Use placeholders for dynamic data injection.

string get_query_inline() { string query = "SELECT spriden.spriden_id, ... WHERE spriden.spriden_pidm = {{pidm}}"; return query; }
Last modified: 13 January 2025