CREATE OR REPLACE PACKAGE efno_rules AS -- /** -- Purpose : Nomination Rule engine functions -- #version $Revision: 1 $ -- #author $Author: Laceyk $ -- Created : 12/02/2007 16:15:16 */ -- g_package_name VARCHAR2(30) := 'efno_rules'; g_header CONSTANT VARCHAR2(160) := '$Header: $'; g_revision CONSTANT VARCHAR2(160) := '$Revision: $ Patch 0.3'; -- Package Types TYPE nom_record IS RECORD ( nr_nepo_id NUMBER , nr_gas_day DATE , nr_rule_id NUMBER , nr_rule_type VARCHAR2(5) , nr_left_side_value NUMBER , nr_right_side_value NUMBER , nr_valid BOOLEAN DEFAULT FALSE ); TYPE nom_validation_table IS TABLE of nom_record INDEX BY BINARY_INTEGER; -- g_empty_nom_val_table nom_validation_table; -- -- -- -- PROCEDURE evaluate_rule_sql( p_sql IN VARCHAR2 , p_success IN OUT BOOLEAN , p_no_data OUT BOOLEAN , p_return_value OUT NUMBER ); -- -- -- -- /* FUNCTION valid_category( p_template_id IN NUMBER , p_contract_id IN NUMBER , p_temp_code IN VARCHAR2 , p_category_id OUT NUMBER ) RETURN BOOLEAN; -- -- -- -- FUNCTION valid_parameter( p_template_id IN NUMBER , p_contract_id IN NUMBER , p_temp_code IN VARCHAR2 , p_parameter_id OUT NUMBER ) RETURN BOOLEAN; */ -- -- -- -- FUNCTION rule_test_passed ( p_left_value IN VARCHAR2 , p_right_value IN VARCHAR2 , p_relation IN VARCHAR2 ) RETURN BOOLEAN; -- -- -- -- /** -- FUNCTION rule_text -- -- Validates one side of a rule defined through the EFT Nominations Web interface -- and optionally returns the various parts of the required SQL statement for running the rules -- Note : Once passed back to the calling routine, if the hours_in_gas_day function has -- been included in the text, a further substitution to replace 'p_gas_day' must take place -- -- %param p_text The stored text of one side of the rule to be evaluated -- %param p_rule_type SHEET or ROW rule (changes how it is validated) -- %param p_select The evaluated SQL for the first part of the SQL select statement -- %param p_from The evaluated SQL for the FROM clause -- %param p_where The evaluated SQL for the WHERE clause -- %param p_nnpcv_tab Table of Nom Net Point Cat Vals - ID and COCA and CONP id -- %param p_contract_id The unique identifier of the the contract for which this nomination is for -- %param p_conf_id The Unique Identifier of the specific confirmation being validated for this rule -- %param p_nomination_id The unique identifier for the specific nomination being validated for this rule -- %param p_net_point_id The Unique Identifier of a Network Point - for ROW rules -- %param p_gas_day For Row Rules, Each Network point requires a category value for each gas day -- %param p_parse_only TRUE if we only want to see if the rule is syntactically valid -- %param p_force_conf TRUE if the rule_text function is being called whilst forcing a confirmation -- Will ensure that a list of nnpcv items are returned in p_nnpcv_tab -- %param p_return_error OUT parameter containing an error message if things have gone wrong -- -- %return BOOLEAN TRUE indicating that the passed text is valid syntactically */ FUNCTION rule_text ( p_text IN VARCHAR2 , p_rule_type IN VARCHAR2 , p_select OUT VARCHAR2 , p_from OUT VARCHAR2 , p_where OUT VARCHAR2 , p_nnpcv_tab IN OUT NOCOPY efno_confirmations.nnpcv_tab , p_template_id IN contract_templates.cote_id%TYPE DEFAULT 0 , p_contract_id IN contracts.cont_id%TYPE DEFAULT 0 , p_conf_id IN confirmations.conf_id%TYPE DEFAULT 0 , p_nomination_id IN nominations.nomi_id%TYPE DEFAULT 0 , p_net_point_id IN network_points.nepo_id%TYPE DEFAULT 0 , p_gas_day IN DATE DEFAULT NULL , p_parse_only IN BOOLEAN DEFAULT FALSE -- MUST NOT be TRUE if p_force_conf is TRUE , p_force_conf IN BOOLEAN DEFAULT FALSE -- MUST NOT be TRUE if p_parse_only is TRUE , p_return_error OUT VARCHAR2 ) RETURN BOOLEAN; /** -- FUNCTION validate_rule -- Validates a single EXISTING rule previously defined through the EFT Nominations Web interface -- and optionally validates the data stored -- -- Examples -- To just parse an existing ROW rule (not assigned to a contract or contract template) -- l_boolean := validate_rule( 12, 'ROW', TRUE, l_dummy_nnpcv_tab, l_dummy_nom_data_table ); -- -- To parse a Rule for a specified contract template -- l_boolean := validate_rule( 12, 'ROW', TRUE, l_dummy_nnpcv_tab, l_dummy_nom_data_table, 1 ); -- -- To parse a Rule for a specified contract -- l_boolean := validate_rule( 12, 'ROW', TRUE, l_dummy_nnpcv_tab, l_dummy_nom_data_table, p_contract_id => 2 ); -- OR l_boolean := validate_rule( 12, 'ROW', TRUE, l_dummy_nnpcv_tab, l_dummy_nom_data_table, NULL, 2 ); -- -- To parse a Rule for a contract AND validate the data for a nomination -- l_boolean := validate_rule( 12, 'ROW', FALSE, l_nnpcv_tab, l_nom_data_table, p_contract_id => 2, p_nomination_id => 3 ); -- OR l_boolean := validate_rule( 12, 'ROW', FALSE, l_nnpcv_tab l_nom_data_table, NULL, 2, 3 ); -- -- %param p_rule_id The Unique identifier of the ROW or SHEET rule -- %param p_rule_type ROW or SHEET -- %param p_parse_only TRUE indicates that only syntax checking is required -- %param p_nnpcv_tab Will return a table of CONP and COCA id's used in the rule when NOT parsing -- %param p_nom_table Table of resulting values passed out to the calling routine for evaluation -- %param p_template_id Unique identifier of a contract template -- %param p_contract_id Unique identifier of a contract -- %param p_nomination_id Unique identifier of a Nomination - used if not parsing -- -- %return BOOLEAN TRUE indicating that the rule is valid syntactically if parse only or that the data passed the test -- and values have been returned for further checking */ FUNCTION validate_rule ( p_rule_id IN NUMBER , p_rule_type IN VARCHAR2 , p_parse_only IN BOOLEAN , p_nnpcv_tab OUT efno_confirmations.nnpcv_tab , p_nom_table OUT nom_validation_table , p_template_id IN NUMBER DEFAULT 0 , p_contract_id IN NUMBER DEFAULT 0 , p_nomination_id IN NUMBER DEFAULT 0 ) RETURN BOOLEAN; /* -- -- %param p_rule_id The Unique identifier of the ROW or SHEET rule -- %param p_rule_type ROW or SHEET -- %param p_parse_only TRUE indicates that only syntax checking is required -- %param p_nnpcv_tab Will return a table of CONP and COCA id's used in the rule when NOT parsing -- %param p_nom_table Table of resulting values passed out to the calling routine for evaluation -- %param p_template_id Unique identifier of a contract template -- %param p_contract_id Unique identifier of a contract -- %param p_nomination_id Unique identifier of a Nomination - used if not parsing -- -- %return BOOLEAN TRUE indicating that the rule is valid syntactically if parse only or that the data passed the test -- and values have been returned for further checking */ FUNCTION validate_rule_conf (p_gas_day IN DATE , p_rule_id IN NUMBER , p_rule_type IN VARCHAR2 , p_parse_only IN BOOLEAN , p_nnpcv_tab IN OUT efno_confirmations.nnpcv_tab , p_nom_table OUT nom_validation_table , p_template_id IN NUMBER DEFAULT 0 , p_contract_id IN NUMBER DEFAULT 0 , p_nomination_id IN NUMBER DEFAULT 0 ) RETURN BOOLEAN; PROCEDURE upd_cotr_seq( p_template_id IN NUMBER , p_cotr_id IN NUMBER , p_sequence IN VARCHAR2 ); PROCEDURE delete_template_rule( p_template_id IN NUMBER , p_cotr_id IN NUMBER ); PROCEDURE add_template_rule( p_template_id IN NUMBER , p_rule_id IN NUMBER ); PROCEDURE upd_coru_seq( p_contract_id IN NUMBER , p_coru_id IN NUMBER , p_sequence IN VARCHAR2 ); PROCEDURE delete_contract_rule( p_contract_id IN NUMBER , p_coru_id IN NUMBER ); PROCEDURE add_contract_row_rule( p_contract_id IN NUMBER , p_rule_id IN NUMBER ); /** -- PROCEDURE insert_or_update_rule -- As it says on the tin -- validates the data stored passed and then inserts new rule or updates existing one -- -- %param p_ins_or_upd INSERT or UPDATE -- %param p_template_id Unique Identifier of a Contract Template -- %param p_contract_id Unique Identifier of a Contract -- %param p_rule_type Rule type - ROW or SHEET -- %param p_coru_id Unique identifier of the SHEET based rule (optional) -- %param p_rule_id Unique identifier of the ROW based rule (optional) -- %param p_rule_name Descriptive name of the rule -- %param p_left_side The text of the rule to the left hand side of the relation -- %param p_right_side The text of the rule to the right hand side of the relation -- %param p_rule_relation <, <=, >, >=, =, != -- %param p_err_message_hu Error message to display if values fail this rule -- %param p_err_message_en Error message in English */ PROCEDURE insert_or_update_rule( p_ins_or_upd IN VARCHAR2 DEFAULT NULL , p_template_id IN NUMBER DEFAULT NULL , p_contract_id IN NUMBER DEFAULT NULL , p_coru_id IN NUMBER DEFAULT NULL , p_rule_id IN NUMBER DEFAULT NULL , p_rule_name IN VARCHAR2 DEFAULT NULL , p_rule_type IN VARCHAR2 DEFAULT NULL , p_err_message_hu IN VARCHAR2 DEFAULT NULL , p_err_message_en IN VARCHAR2 DEFAULT NULL , p_left_side IN VARCHAR2 DEFAULT NULL , p_rule_relation IN VARCHAR2 DEFAULT NULL , p_right_side IN VARCHAR2 DEFAULT NULL ); FUNCTION get_nepg_value(p_nomi_id IN NUMBER, p_nepg_id IN NUMBER, p_coca_id IN NUMBER, p_conf_id IN NUMBER, p_gas_day IN nom_net_point_cat_vals.gas_day%TYPE) RETURN NUMBER; FUNCTION get_npgp_value(p_cont_id IN NUMBER, p_nepg_id IN NUMBER) RETURN NUMBER; /** -- FUNCTION about -- -- %return A textual description of the version number and VSS header for this package */ FUNCTION about RETURN VARCHAR2; END efno_rules; /