531 lines
19 KiB
Plaintext
531 lines
19 KiB
Plaintext
CREATE OR REPLACE PACKAGE BODY efno_nepg IS
|
|
|
|
-- For Updating Contract Network Points - to enable delete of those no longer attached
|
|
FUNCTION nepo_in_array( p_id IN NUMBER
|
|
, p_nepo_array IN network_point_array )
|
|
RETURN BOOLEAN
|
|
IS
|
|
l_success BOOLEAN := FALSE;
|
|
BEGIN
|
|
IF NVL(p_nepo_array.COUNT,0) > 0 THEN
|
|
FOR i IN p_nepo_array.FIRST..p_nepo_array.LAST LOOP
|
|
IF p_nepo_array(i) = p_id THEN
|
|
l_success := TRUE;
|
|
END IF;
|
|
END LOOP;
|
|
END IF;
|
|
RETURN l_success;
|
|
END nepo_in_array;
|
|
|
|
--
|
|
-- For Updating Contract Network Points - to determine if we need to insert into DB
|
|
FUNCTION nepo_in_db( p_nepo_id IN NUMBER
|
|
, p_nepg_id IN NUMBER )
|
|
RETURN BOOLEAN
|
|
IS
|
|
CURSOR c_nepo IS
|
|
SELECT 'Y'
|
|
FROM network_point_mappings
|
|
WHERE nepg_id = p_nepg_id
|
|
AND nepo_id = p_nepo_id;
|
|
--
|
|
l_success BOOLEAN := FALSE;
|
|
l_dummy VARCHAR2(1) := 'X';
|
|
--
|
|
BEGIN
|
|
OPEN c_nepo;
|
|
FETCH c_nepo INTO l_dummy;
|
|
IF c_nepo%FOUND THEN
|
|
l_success := TRUE;
|
|
END IF;
|
|
CLOSE c_nepo;
|
|
RETURN l_success;
|
|
END nepo_in_db;
|
|
|
|
PROCEDURE find_passed_net_points( p_nepo_array IN owa_util.vc_arr
|
|
, p_network_point_array OUT network_point_array )
|
|
IS
|
|
l_count NUMBER := 0;
|
|
BEGIN
|
|
--
|
|
IF NVL(p_nepo_array.COUNT,0) > 0 THEN
|
|
FOR i IN p_nepo_array.FIRST .. p_nepo_array.LAST LOOP
|
|
--
|
|
l_count := l_count + 1;
|
|
p_network_point_array(l_count) := TO_NUMBER(p_nepo_array(i));
|
|
--
|
|
END LOOP;
|
|
END IF;
|
|
--
|
|
END find_passed_net_points;
|
|
|
|
FUNCTION insert_nepm( p_nepg_id IN network_point_groups.nepg_id%TYPE
|
|
, p_network_point_array IN network_point_array
|
|
, p_return_error OUT VARCHAR2 )
|
|
RETURN BOOLEAN
|
|
IS
|
|
--
|
|
l_success BOOLEAN := TRUE;
|
|
--
|
|
BEGIN
|
|
SAVEPOINT before_ins_nepm;
|
|
--
|
|
<<ins_net_point_loop>>
|
|
FOR i IN 1..p_network_point_array.COUNT LOOP
|
|
--
|
|
BEGIN
|
|
INSERT INTO network_point_mappings
|
|
( nepg_id
|
|
, nepo_id)
|
|
VALUES
|
|
( p_nepg_id
|
|
, p_network_point_array(i) );
|
|
EXCEPTION
|
|
WHEN others THEN
|
|
l_success := FALSE;
|
|
p_return_error := caco_utilities.get_module_text(3907);
|
|
-- An unexpected error has occurred while inserting new network point group. Please contact support
|
|
caco_debug.putline('efno_nepg.insert_nepm : '
|
|
||'Insert of new network point mapping failed : '||sqlerrm(sqlcode));
|
|
-- Write an error and carry on
|
|
cout_err.report_and_go( p_exception_number => sqlcode
|
|
, p_exception_message => 'Failed inserting new NEPM: '||sqlerrm(sqlcode)
|
|
, p_source => 'efno_nepm.insert_nepm');
|
|
--
|
|
ROLLBACK TO SAVEPOINT before_ins_nepm;
|
|
EXIT ins_net_point_loop;
|
|
END;
|
|
--
|
|
IF NOT l_success THEN
|
|
EXIT ins_net_point_loop;
|
|
END IF;
|
|
--
|
|
END LOOP ins_net_point_loop;
|
|
--
|
|
RETURN l_success;
|
|
--
|
|
END insert_nepm;
|
|
|
|
PROCEDURE del_redundant_nepo( p_nepg_id IN network_point_groups.nepg_id%TYPE
|
|
, p_network_point_array IN network_point_array
|
|
, p_success OUT BOOLEAN
|
|
, p_return_error OUT VARCHAR2 )
|
|
IS
|
|
--
|
|
CURSOR c_nepm( cp_nepg_id IN NUMBER) IS
|
|
SELECT nepo_id
|
|
FROM network_point_mappings
|
|
WHERE nepg_id = cp_nepg_id
|
|
FOR UPDATE;
|
|
--
|
|
BEGIN
|
|
p_success := TRUE;
|
|
--
|
|
<<upd_del_net_point_loop>>
|
|
FOR r IN c_nepm( p_nepg_id ) LOOP
|
|
--
|
|
IF NOT nepo_in_array( r.nepo_id
|
|
, p_network_point_array )
|
|
THEN
|
|
--
|
|
-- This network point doesn't exist in the new set, needs to be removed if possible
|
|
-- remove the nepm record
|
|
--
|
|
BEGIN
|
|
DELETE network_point_mappings
|
|
WHERE CURRENT OF c_nepm;
|
|
EXCEPTION
|
|
WHEN others THEN
|
|
p_success := FALSE;
|
|
p_return_error := caco_utilities.get_module_text(3908);
|
|
-- An unexpected error has occurred while updating a network point group. Please contact support
|
|
caco_debug.putline('efno_nepg.del_redundant_nepo: '
|
|
||'Update of network point mapping failed (delete): '||sqlerrm(sqlcode));
|
|
-- Write an error and carry on
|
|
cout_err.report_and_go( p_exception_number => sqlcode
|
|
, p_exception_message => 'Failed deleting NEPM: '||sqlerrm(sqlcode)
|
|
, p_source => 'efno_nepg.del_redundant_nepo');
|
|
--
|
|
EXIT upd_del_net_point_loop;
|
|
END;
|
|
END IF;
|
|
--
|
|
END LOOP upd_del_net_point_loop;
|
|
--
|
|
END del_redundant_nepo;
|
|
|
|
|
|
PROCEDURE ins_required_nepo( p_nepg_id IN network_point_groups.nepg_id%TYPE
|
|
, p_network_point_array IN network_point_array
|
|
, p_success OUT BOOLEAN
|
|
, p_return_error OUT VARCHAR2 )
|
|
IS
|
|
BEGIN
|
|
SAVEPOINT before_ins_nepo;
|
|
--
|
|
p_success := TRUE;
|
|
--
|
|
<<upd_ins_net_point_loop>>
|
|
FOR i IN 1..p_network_point_array.COUNT LOOP
|
|
--
|
|
IF NOT nepo_in_db( p_network_point_array(i)
|
|
, p_nepg_id )
|
|
THEN
|
|
--
|
|
BEGIN
|
|
INSERT INTO network_point_mappings
|
|
( nepg_id
|
|
, nepo_id)
|
|
VALUES
|
|
( p_nepg_id
|
|
, p_network_point_array(i) );
|
|
EXCEPTION
|
|
WHEN others THEN
|
|
p_success := FALSE;
|
|
p_return_error := caco_utilities.get_module_text(3908);
|
|
-- An unexpected error has occurred while updating a network point group. Please contact support
|
|
caco_debug.putline('efno_nepg.ins_required_nepo: '
|
|
||'Update of network point mapping failed (insert): '
|
|
||sqlerrm(sqlcode));
|
|
-- Write an error and carry on
|
|
cout_err.report_and_go( p_exception_number => sqlcode
|
|
, p_exception_message => 'Failed inserting NEPM: '||sqlerrm(sqlcode)
|
|
, p_source => 'efno_nepg.ins_required_nepo');
|
|
--
|
|
ROLLBACK TO SAVEPOINT before_ins_nepo;
|
|
EXIT upd_ins_net_point_loop;
|
|
END;
|
|
--
|
|
IF NOT p_success THEN
|
|
EXIT upd_ins_net_point_loop;
|
|
END IF;
|
|
--
|
|
END IF;
|
|
--
|
|
END LOOP upd_ins_net_point_loop;
|
|
--
|
|
END ins_required_nepo;
|
|
|
|
PROCEDURE ins_or_upd_nepg( p_ins_or_upd IN VARCHAR2 DEFAULT 'INSERT'
|
|
, p_nepg_id IN network_point_groups.nepg_id%TYPE DEFAULT 0
|
|
, p_nepg_name IN VARCHAR2 DEFAULT NULL
|
|
, p_nepg_code IN VARCHAR2 DEFAULT NULL
|
|
, p_nepg_status IN contracts.status%TYPE DEFAULT NULL
|
|
, p_nepo_id IN owa_util.vc_arr DEFAULT g_vc_arr
|
|
)
|
|
IS
|
|
--
|
|
CURSOR c_nepg (cp_nepg_id IN NUMBER) IS
|
|
SELECT *
|
|
FROM network_point_groups
|
|
WHERE nepg_id = cp_nepg_id;
|
|
--
|
|
-- Cursor to determine if the nepg code has been used previously
|
|
CURSOR c_unique_nepg_code( cp_code IN VARCHAR2 ) IS
|
|
SELECT 'X'
|
|
FROM network_point_groups nepg
|
|
WHERE UPPER(nepg.code) = UPPER(cp_code)
|
|
AND nepg.nepg_id != NVL(p_nepg_id,0);
|
|
--
|
|
-- Cursor to determine if the nepg code is not the same as a nepo code
|
|
CURSOR c_unique_nepo_code( cp_code IN VARCHAR2 ) IS
|
|
SELECT 'X'
|
|
FROM network_points nepo
|
|
WHERE UPPER(nepo.code) = UPPER(cp_code);
|
|
--
|
|
--
|
|
l_error VARCHAR2(1);
|
|
l_return_error VARCHAR2(250); -- If the insert or update fails - put an error message in here.
|
|
--
|
|
l_network_point_array network_point_array;
|
|
--
|
|
l_dummy_char VARCHAR2(1);
|
|
--
|
|
l_nepo_id owa_util.vc_arr;
|
|
--
|
|
l_success BOOLEAN := TRUE; -- Used to track how well we are doing in this code..
|
|
l_success_char VARCHAR2(1) := NULL;
|
|
--
|
|
l_code_position VARCHAR2(4) := '0000';
|
|
--
|
|
l_nepg network_point_groups%ROWTYPE;
|
|
--
|
|
l_nepg_id network_point_groups.nepg_id%TYPE;
|
|
l_nepg_code VARCHAR2(2000);
|
|
l_nepg_name VARCHAR2(2000);
|
|
l_nepg_status network_point_groups.status%TYPE;
|
|
--
|
|
BEGIN
|
|
-- Check we have permission to be using this module.
|
|
-- Only called from the Create contracts screen
|
|
IF NOT caco_security.security_check('efnow250$') THEN
|
|
RETURN;
|
|
END IF;
|
|
--
|
|
-- Look for whether we are inserting or updating
|
|
IF p_ins_or_upd IS NULL
|
|
AND l_success
|
|
OR ( UPPER(p_ins_or_upd) != 'INSERT' AND UPPER(p_ins_or_upd) != 'UPDATE' )
|
|
THEN
|
|
-- Cannot tell if we should be inserting or updating. Well, we could
|
|
-- but it's easier to enforce this on the calling prog instead of Assuming.
|
|
-- and you know the old adage about ASSUME eh?
|
|
l_success := FALSE;
|
|
l_return_error := caco_utilities.get_module_text(2331);
|
|
-- Could not determine if Inserting or Updating
|
|
--
|
|
END IF;
|
|
--
|
|
-- Only check nepg id if updating
|
|
IF l_success
|
|
AND p_ins_or_upd = 'UPDATE'
|
|
AND ( p_nepg_id IS NULL OR p_nepg_id = 0 )
|
|
THEN
|
|
l_success := FALSE;
|
|
l_return_error := caco_utilities.get_module_text(3902);
|
|
-- Update of Network Point Group failed - No Nepg Id was provided
|
|
END IF;
|
|
--
|
|
-- Get Nepg Code
|
|
IF l_success
|
|
AND ( p_nepg_code IS NULL OR LENGTH(p_nepg_code) > 12 )
|
|
THEN
|
|
l_success := FALSE;
|
|
l_return_error := caco_utilities.get_module_text(3904);
|
|
-- Network Point Group Code must be present with a maximum length of 12 characters
|
|
ELSIF l_success THEN
|
|
-- Need to ensure that the Nepg code is unique
|
|
OPEN c_unique_nepg_code( p_nepg_code );
|
|
FETCH c_unique_nepg_code INTO l_dummy_char;
|
|
IF c_unique_nepg_code%FOUND THEN
|
|
l_success := FALSE;
|
|
l_return_error := caco_utilities.get_module_text(3905);
|
|
-- Duplicate Network Point Group Code already exists
|
|
END IF;
|
|
CLOSE c_unique_nepg_code;
|
|
--
|
|
ELSIF l_success THEN
|
|
-- Need to ensure that the Nepg code is not the same as a network point code
|
|
OPEN c_unique_nepo_code( p_nepg_code );
|
|
FETCH c_unique_nepo_code INTO l_dummy_char;
|
|
IF c_unique_nepo_code%FOUND THEN
|
|
l_success := FALSE;
|
|
l_return_error := caco_utilities.get_module_text(3911);
|
|
-- Duplicate Network Point Code already exists
|
|
END IF;
|
|
CLOSE c_unique_nepo_code;
|
|
--
|
|
END IF;
|
|
-- Get Nepg Name
|
|
IF l_success
|
|
AND ( p_nepg_name IS NULL OR LENGTH(p_nepg_name) > 30 )
|
|
THEN
|
|
l_success := FALSE;
|
|
l_return_error := caco_utilities.get_module_text(3903);
|
|
-- Network Point Group Name must be present with a maximum length of 30 characters
|
|
--
|
|
END IF;
|
|
--
|
|
-- Get Status
|
|
IF l_success
|
|
AND ( p_nepg_status IS NULL
|
|
OR ( p_nepg_status != 'I' AND p_nepg_status != 'A' ) )
|
|
THEN
|
|
l_success := FALSE;
|
|
l_return_error := caco_utilities.get_module_text(3906);
|
|
-- Status must be present as either ACTIVE or INACTIVE
|
|
END IF;
|
|
--
|
|
--
|
|
l_code_position := '0200';
|
|
--
|
|
--
|
|
-- Insert or Update the basic part of the contract/template
|
|
-- and then the network points, categories and parameters
|
|
-- Remember - for each category, add its associated parameters.
|
|
--
|
|
l_code_position := '0900';
|
|
--
|
|
IF l_success THEN
|
|
l_code_position := '1000';
|
|
-- Lets look at Inserting the nepg first...
|
|
IF p_ins_or_upd = 'INSERT' THEN
|
|
BEGIN
|
|
INSERT INTO network_point_groups
|
|
( nepg_id
|
|
, code
|
|
, name
|
|
, status)
|
|
VALUES
|
|
( nepg_seq.NEXTVAL
|
|
, p_nepg_code
|
|
, p_nepg_name
|
|
, p_nepg_status)
|
|
RETURNING nepg_id INTO l_nepg_id;
|
|
EXCEPTION
|
|
WHEN others THEN
|
|
l_success := FALSE;
|
|
l_return_error := caco_utilities.get_module_text(3907);
|
|
-- An unexpected error has occurred while inserting new network point group. Please contact support
|
|
caco_debug.putline('efno_nepg.ins_or_upd_nepg: '
|
|
||'Insert of new nepg failed : '||sqlerrm(sqlcode));
|
|
-- Write an error and carry on
|
|
cout_err.report_and_go( p_exception_number => sqlcode
|
|
, p_exception_message => 'Failed inserting new nepg: '||sqlerrm(sqlcode)
|
|
, p_source => 'efno_nepg.ins_or_upd_nepg');
|
|
--
|
|
END;
|
|
ELSE
|
|
l_code_position := '1100';
|
|
--
|
|
-- get the currect contract values before updating so we can check for changes
|
|
OPEN c_nepg(p_nepg_id);
|
|
FETCH c_nepg INTO l_nepg;
|
|
CLOSE c_nepg;
|
|
-- Update
|
|
BEGIN
|
|
UPDATE network_point_groups
|
|
SET name = p_nepg_name
|
|
, code = p_nepg_code
|
|
, status = p_nepg_status
|
|
WHERE nepg_id = p_nepg_id;
|
|
--
|
|
EXCEPTION
|
|
WHEN others THEN
|
|
l_success := FALSE;
|
|
l_return_error := caco_utilities.get_module_text(3908);
|
|
-- An unexpected error has occurred while updating a network point group. Please contact support
|
|
caco_debug.putline('efno_nepg.ins_or_upd_nepg: '
|
|
||'Update of nepg failed : '||sqlerrm(sqlcode));
|
|
-- Write an error and carry on
|
|
cout_err.report_and_go( p_exception_number => sqlcode
|
|
, p_exception_message => 'Failed updating contract (ID = '||p_nepg_id||'): '||sqlerrm(sqlcode)
|
|
, p_source => 'efno_nepg.ins_or_upd_nepg');
|
|
--
|
|
END;
|
|
--
|
|
l_nepg_id := p_nepg_id;
|
|
--
|
|
END IF; -- Insert or Update of contract
|
|
END IF; -- End of basic insert
|
|
--
|
|
l_code_position := '1200';
|
|
--
|
|
-- Get Network Points
|
|
IF l_success THEN
|
|
l_code_position := '2000';
|
|
-- Find passed network points
|
|
find_passed_net_points( p_nepo_id
|
|
, l_network_point_array );
|
|
--
|
|
IF p_ins_or_upd = 'INSERT' THEN
|
|
l_code_position := '2100';
|
|
-- Insert all Network Points
|
|
l_success := insert_nepm( l_nepg_id
|
|
, l_network_point_array
|
|
, l_return_error );
|
|
--
|
|
ELSE
|
|
l_code_position := '2200';
|
|
-- Update
|
|
-- This is easier to get to grips with as a two pass process
|
|
-- First, zip through the existing DB data for the contract and delete existing rows not in our array
|
|
del_redundant_nepo( l_nepg_id
|
|
, l_network_point_array
|
|
, l_success
|
|
, l_return_error );
|
|
--
|
|
l_code_position := '2250';
|
|
-- Second time around go through the passed array and insert those that dont exist.
|
|
IF l_success THEN
|
|
--
|
|
ins_required_nepo( l_nepg_id
|
|
, l_network_point_array
|
|
, l_success
|
|
, l_return_error );
|
|
--
|
|
END IF; -- end of if successful delete of existing cont net points
|
|
--
|
|
END IF; -- end of insert or update contract network points
|
|
END IF; -- end of network points
|
|
--
|
|
l_code_position := '2900';
|
|
--
|
|
IF l_success THEN
|
|
-- Commit the changes
|
|
COMMIT;
|
|
--
|
|
l_success_char := 'Y';
|
|
--
|
|
ELSE
|
|
l_code_position := '9020';
|
|
--
|
|
-- Failed somewhere
|
|
-- Rollback any partially made inserts/updates
|
|
ROLLBACK;
|
|
--
|
|
--
|
|
l_success_char := NULL;
|
|
l_error := 'Y';
|
|
l_nepg_id := p_nepg_id;
|
|
l_nepg_code := p_nepg_code;
|
|
l_nepg_name := p_nepg_name;
|
|
l_nepg_status := p_nepg_status;
|
|
l_nepo_id := p_nepo_id;
|
|
--
|
|
END IF;
|
|
--
|
|
l_code_position := '9100';
|
|
--
|
|
caco_debug.putline('efno_contracts.ins_or_upd_nepg: '||chr(10)
|
|
||chr(10)||'p_ins_or_upd : '||p_ins_or_upd
|
|
||chr(10)||'p_success : '||l_success_char
|
|
||chr(10)||'p_error : '||l_error
|
|
||chr(10)||'p_err_msg : '||l_return_error
|
|
||chr(10)||'p_nepg_id : '||l_nepg_id
|
|
||chr(10)||'p_nepg_code : '||l_nepg_code
|
|
||chr(10)||'p_nepg_name : '||l_nepg_name
|
|
||chr(10)||'p_nepg_status : '||l_nepg_status
|
|
);
|
|
--
|
|
l_code_position := '9110';
|
|
-- Call the nepg screen
|
|
efnow250$.nepg_startup(p_ins_or_upd => p_ins_or_upd,
|
|
p_success => l_success_char,
|
|
p_nepg_id => l_nepg_id,
|
|
p_nepg_name => l_nepg_name,
|
|
p_nepg_code => l_nepg_code,
|
|
p_nepg_status => l_nepg_status,
|
|
p_error => l_error,
|
|
p_err_msg => l_return_error,
|
|
p_nepo_id => l_nepo_id);
|
|
--
|
|
EXCEPTION
|
|
WHEN others THEN
|
|
caco_debug.debug_on;
|
|
caco_debug.putline('efno_nepg.ins_or_upd_nepg: '
|
|
||'Position in Code : '||l_code_position||' : '||chr(10)
|
|
||sqlerrm(sqlcode));
|
|
-- Write an error and carry on
|
|
cout_err.report_and_go( p_exception_number => sqlcode
|
|
, p_exception_message => 'Failed at position : '||l_code_position||' : '||sqlerrm(sqlcode)
|
|
, p_source => 'efno_nepg.ins_or_upd_nepg');
|
|
--
|
|
ROLLBACK;
|
|
RAISE;
|
|
END ins_or_upd_nepg;
|
|
--
|
|
/**
|
|
-- FUNCTION about --
|
|
-- Returns the version number and VSS header for this package
|
|
--
|
|
-- %return The version number and VSS header for this package
|
|
*/
|
|
FUNCTION about RETURN VARCHAR2 IS
|
|
BEGIN
|
|
RETURN ( g_revision || CHR(10) || g_header );
|
|
END about;
|
|
|
|
END efno_nepg;
|
|
/
|