Skip to content

Commit

Permalink
fix(various): manage_planmode, initproject, pg2epa and state views
Browse files Browse the repository at this point in the history
  • Loading branch information
xtorret committed Sep 21, 2024
1 parent 9758571 commit b2ebc5d
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 56 deletions.
45 changes: 27 additions & 18 deletions updates/36/36013/ud/ddlview.sql
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ p AS (SELECT connec_id, psector_id, state, arc_id FROM plan_psector_x_connec WHE
s AS (SELECT * FROM selector_psector WHERE cur_user = current_user),
c as (SELECT connec_id, state, arc_id FROM connec)
SELECT c.connec_id::varchar(30), c.arc_id FROM selector_state,c WHERE c.state = selector_state.state_id AND selector_state.cur_user = "current_user"()::text
EXCEPT
SELECT p.connec_id::varchar(30), p.arc_id FROM selector_psector, p WHERE p.psector_id = selector_psector.psector_id AND selector_psector.cur_user = "current_user"()::text AND p.state = 0
UNION
SELECT p.connec_id::varchar(30), p.arc_id FROM selector_psector, p WHERE p.psector_id = selector_psector.psector_id AND selector_psector.cur_user = "current_user"()::text AND p.state = 1;
EXCEPT ALL
SELECT p.connec_id::varchar(30), p.arc_id FROM s, p WHERE p.psector_id = s.psector_id AND s.cur_user = "current_user"()::text AND p.state = 0
UNION ALL
SELECT DISTINCT ON (p.connec_id) p.connec_id::varchar(30), p.arc_id FROM s, p WHERE p.psector_id = s.psector_id AND s.cur_user = "current_user"()::text AND p.state = 1;



Expand All @@ -156,10 +156,10 @@ p AS (SELECT gully_id, psector_id, state, arc_id FROM plan_psector_x_gully WHERE
s AS (SELECT * FROM selector_psector WHERE cur_user = current_user),
c as (SELECT gully_id, state, arc_id FROM gully)
SELECT c.gully_id, c.arc_id FROM selector_state,c WHERE c.state = selector_state.state_id AND selector_state.cur_user = "current_user"()::text
EXCEPT
SELECT p.gully_id, p.arc_id FROM selector_psector, p WHERE p.psector_id = selector_psector.psector_id AND selector_psector.cur_user = "current_user"()::text AND p.state = 0
UNION
SELECT p.gully_id, p.arc_id FROM selector_psector, p WHERE p.psector_id = selector_psector.psector_id AND selector_psector.cur_user = "current_user"()::text AND p.state = 1;
EXCEPT ALL
SELECT p.gully_id, p.arc_id FROM s, p WHERE p.psector_id = s.psector_id AND s.cur_user = "current_user"()::text AND p.state = 0
UNION ALL
SELECT DISTINCT ON (p.gully_id) p.gully_id, p.arc_id FROM s, p WHERE p.psector_id = s.psector_id AND s.cur_user = "current_user"()::text AND p.state = 1;



Expand All @@ -170,9 +170,9 @@ sp AS (SELECT * FROM selector_psector WHERE cur_user = current_user),
se AS (SELECT * FROM selector_expl WHERE cur_user = current_user),
l AS (SELECT link_id, state, expl_id, expl_id2 FROM link)
SELECT l.link_id FROM selector_state, se, l WHERE l.state = selector_state.state_id AND (l.expl_id = se.expl_id OR l.expl_id2 = se.expl_id) AND selector_state.cur_user = "current_user"()::text AND se.cur_user = "current_user"()::text
EXCEPT
EXCEPT ALL
SELECT p.link_id FROM sp, se, p JOIN l USING (link_id) WHERE p.psector_id = sp.psector_id AND sp.cur_user = "current_user"()::text AND p.state = 0 AND l.expl_id = se.expl_id AND se.cur_user = CURRENT_USER::text
UNION
UNION ALL
SELECT p.link_id FROM sp, se, p JOIN l USING (link_id) WHERE p.psector_id = sp.psector_id AND sp.cur_user = "current_user"()::text AND p.state = 1 AND l.expl_id = se.expl_id AND se.cur_user = CURRENT_USER::text;


Expand All @@ -183,16 +183,25 @@ sp AS (SELECT * FROM selector_psector WHERE cur_user = current_user),
se AS (SELECT * FROM selector_expl WHERE cur_user = current_user),
l AS (SELECT link_id, state, expl_id, expl_id2 FROM link)
SELECT l.link_id FROM selector_state, se, l WHERE l.state = selector_state.state_id AND (l.expl_id = se.expl_id OR l.expl_id2 = se.expl_id) AND selector_state.cur_user = "current_user"()::text AND se.cur_user = "current_user"()::text
EXCEPT
EXCEPT ALL
SELECT p.link_id FROM sp, se, p JOIN l USING (link_id) WHERE p.psector_id = sp.psector_id AND sp.cur_user = "current_user"()::text AND p.state = 0 AND l.expl_id = se.expl_id AND se.cur_user = CURRENT_USER::text
UNION
UNION ALL
SELECT p.link_id FROM sp, se, p JOIN l USING (link_id) WHERE p.psector_id = sp.psector_id AND sp.cur_user = "current_user"()::text AND p.state = 1 AND l.expl_id = se.expl_id AND se.cur_user = CURRENT_USER::text;


CREATE OR REPLACE VIEW v_state_link AS
SELECT * FROM v_state_link_connec
UNION
SELECT * FROM v_state_link_gully;



WITH
c AS (SELECT connec_id, psector_id, state, link_id FROM plan_psector_x_connec WHERE active),
g AS (SELECT gully_id, psector_id, state, link_id FROM plan_psector_x_gully WHERE active),
sp AS (SELECT * FROM selector_psector WHERE cur_user = current_user),
se AS (SELECT * FROM selector_expl WHERE cur_user = current_user),
l AS (SELECT link_id, state, expl_id, expl_id2 FROM link)
SELECT l.link_id FROM selector_state, se, l WHERE l.state = selector_state.state_id AND (l.expl_id = se.expl_id OR l.expl_id2 = se.expl_id) AND selector_state.cur_user = "current_user"()::text AND se.cur_user = "current_user"()::text
EXCEPT ALL
SELECT c.link_id FROM sp, se, c JOIN l USING (link_id) WHERE c.psector_id = sp.psector_id AND sp.cur_user = "current_user"()::text AND c.state = 0 AND l.expl_id = se.expl_id AND se.cur_user = CURRENT_USER::text
EXCEPT ALL
SELECT g.link_id FROM sp, se, g JOIN l USING (link_id) WHERE g.psector_id = sp.psector_id AND sp.cur_user = "current_user"()::text AND g.state = 0 AND l.expl_id = se.expl_id AND se.cur_user = CURRENT_USER::text
UNION ALL
SELECT c.link_id FROM sp, se, c JOIN l USING (link_id) WHERE c.psector_id = sp.psector_id AND sp.cur_user = "current_user"()::text AND c.state = 1 AND l.expl_id = se.expl_id AND se.cur_user = CURRENT_USER::text
UNION ALL
SELECT g.link_id FROM sp, se, g JOIN l USING (link_id) WHERE g.psector_id = sp.psector_id AND sp.cur_user = "current_user"()::text AND g.state = 1 AND l.expl_id = se.expl_id AND se.cur_user = CURRENT_USER::text;
12 changes: 6 additions & 6 deletions updates/36/36013/utils/ddlview.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ p AS (SELECT arc_id, psector_id, state FROM plan_psector_x_arc WHERE active),
s AS (SELECT * FROM selector_psector WHERE cur_user = current_user),
a as (SELECT arc_id, state FROM arc)
SELECT arc.arc_id FROM selector_state,arc WHERE arc.state = selector_state.state_id AND selector_state.cur_user = "current_user"()::text
EXCEPT
EXCEPT ALL
SELECT p.arc_id FROM s, p WHERE p.psector_id = s.psector_id AND p.state = 0
UNION
SELECT p.arc_id FROM s,p WHERE p.psector_id = s.psector_id AND p.state = 1;
UNION ALL
SELECT DISTINCT p.arc_id FROM s,p WHERE p.psector_id = s.psector_id AND p.state = 1;


CREATE OR REPLACE VIEW v_state_node AS
Expand All @@ -25,7 +25,7 @@ p AS (SELECT node_id, psector_id, state FROM plan_psector_x_node WHERE active),
s AS (SELECT * FROM selector_psector WHERE cur_user = current_user),
n AS (SELECT node_id, state FROM node)
SELECT n.node_id FROM selector_state,n WHERE n.state = selector_state.state_id AND selector_state.cur_user = "current_user"()::text
EXCEPT
EXCEPT ALL
SELECT p.node_id FROM s, p WHERE p.psector_id = s.psector_id AND p.state = 0
UNION
SELECT p.node_id FROM s,p WHERE p.psector_id = s.psector_id AND p.state = 1;
UNION ALL
SELECT DISTINCT p.node_id FROM s,p WHERE p.psector_id = s.psector_id AND p.state = 1;
18 changes: 9 additions & 9 deletions updates/36/36013/ws/ddlview.sql
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,18 @@ CREATE OR REPLACE VIEW v_edit_minsector AS
m.the_geom
FROM selector_expl, minsector m
WHERE (m.expl_id = selector_expl.expl_id AND selector_expl.cur_user = "current_user"()::text);


CREATE OR REPLACE VIEW v_state_link AS
WITH
p AS (SELECT connec_id, psector_id, state, link_id FROM plan_psector_x_connec WHERE active),
sp AS (SELECT * FROM selector_psector WHERE cur_user = current_user),
se AS (SELECT * FROM selector_expl WHERE cur_user = current_user),
l AS (SELECT link_id, state, expl_id, expl_id2 FROM link)
SELECT l.link_id FROM selector_state, se, l WHERE l.state = selector_state.state_id AND (l.expl_id = se.expl_id OR l.expl_id2 = se.expl_id) AND selector_state.cur_user = "current_user"()::text AND se.cur_user = "current_user"()::text
EXCEPT
EXCEPT ALL
SELECT p.link_id FROM sp, se, p JOIN l USING (link_id) WHERE p.psector_id = sp.psector_id AND sp.cur_user = "current_user"()::text AND p.state = 0 AND l.expl_id = se.expl_id AND se.cur_user = CURRENT_USER::text
UNION
UNION ALL
SELECT p.link_id FROM sp, se, p JOIN l USING (link_id) WHERE p.psector_id = sp.psector_id AND sp.cur_user = "current_user"()::text AND p.state = 1 AND l.expl_id = se.expl_id AND se.cur_user = CURRENT_USER::text;


Expand All @@ -307,8 +307,8 @@ WITH
p AS (SELECT connec_id, psector_id, state, arc_id FROM plan_psector_x_connec WHERE active),
s AS (SELECT * FROM selector_psector WHERE cur_user = current_user),
c as (SELECT connec_id, state, arc_id FROM connec)
SELECT c.connec_id, c.arc_id FROM selector_state,c WHERE c.state = selector_state.state_id AND selector_state.cur_user = "current_user"()::text
EXCEPT
SELECT p.connec_id, p.arc_id FROM selector_psector, p WHERE p.psector_id = selector_psector.psector_id AND selector_psector.cur_user = "current_user"()::text AND p.state = 0
UNION
SELECT p.connec_id, p.arc_id FROM selector_psector, p WHERE p.psector_id = selector_psector.psector_id AND selector_psector.cur_user = "current_user"()::text AND p.state = 1;
SELECT c.connec_id, c.arc_id, 1::int2 flag FROM selector_state,c WHERE c.state = selector_state.state_id AND selector_state.cur_user = "current_user"()::text
EXCEPT ALL
SELECT p.connec_id, p.arc_id, 1::int2 FROM s, p WHERE p.psector_id = s.psector_id AND s.cur_user = "current_user"()::text AND p.state = 0
UNION ALL
SELECT DISTINCT ON (p.connec_id) p.connec_id, p.arc_id, 2::int2 FROM s, p WHERE p.psector_id = s.psector_id AND s.cur_user = "current_user"()::text AND p.state = 1;
64 changes: 45 additions & 19 deletions utils/fct/gw_fct_admin_manage_planmode.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This version of Giswater is provided by Giswater Association

--FUNCTION CODE: 3304

CREATE OR REPLACE FUNCTION ws36013_2.gw_fct_admin_manage_planmode(p_data json)
CREATE OR REPLACE FUNCTION SCHEMA_NAME.gw_fct_admin_manage_planmode(p_data json)
RETURNS json AS
$BODY$

Expand Down Expand Up @@ -151,19 +151,19 @@ BEGIN
SELECT p.node_id FROM s,p WHERE p.psector_id = s.psector_id AND p.state = 1;


CREATE OR REPLACE VIEW v_state_connec AS
WITH
p AS (SELECT connec_id, psector_id, state, arc_id FROM plan_psector_x_connec WHERE active),
s AS (SELECT * FROM selector_psector WHERE cur_user = current_user),
c as (SELECT connec_id, state, arc_id FROM connec)
SELECT c.connec_id::varchar(30), c.arc_id, state as flag FROM selector_state,c WHERE c.state = selector_state.state_id AND selector_state.cur_user = "current_user"()::text
EXCEPT
SELECT p.connec_id::varchar(30), p.arc_id, p.state FROM selector_psector, p WHERE p.psector_id = selector_psector.psector_id AND selector_psector.cur_user = "current_user"()::text AND p.state = 0
UNION
SELECT p.connec_id::varchar(30), p.arc_id, p.state FROM selector_psector, p WHERE p.psector_id = selector_psector.psector_id AND selector_psector.cur_user = "current_user"()::text AND p.state = 1;
IF v_project_type ='WS' THEN

CREATE OR REPLACE VIEW v_state_connec AS
WITH
p AS (SELECT connec_id, psector_id, state, arc_id FROM plan_psector_x_connec WHERE active),
s AS (SELECT * FROM selector_psector WHERE cur_user = current_user),
c as (SELECT connec_id, state, arc_id FROM connec)
SELECT c.connec_id, c.arc_id, 1::int2 flag FROM selector_state,c WHERE c.state = selector_state.state_id AND selector_state.cur_user = "current_user"()::text
EXCEPT
SELECT p.connec_id, p.arc_id, 1::int2 FROM s, p WHERE p.psector_id = s.psector_id AND s.cur_user = "current_user"()::text AND p.state = 0
UNION
SELECT DISTINCT ON (p.connec_id) p.connec_id, p.arc_id, 2::int2 FROM s, p WHERE p.psector_id = s.psector_id AND s.cur_user = "current_user"()::text AND p.state = 1;

IF v_project_type ='WS' THEN

CREATE OR REPLACE VIEW v_state_link AS
WITH
Expand All @@ -179,18 +179,31 @@ BEGIN

ELSIF v_project_type ='UD' THEN


CREATE OR REPLACE VIEW v_state_connec AS
WITH
p AS (SELECT connec_id, psector_id, state, arc_id FROM plan_psector_x_connec WHERE active),
s AS (SELECT * FROM selector_psector WHERE cur_user = current_user),
c as (SELECT connec_id, state, arc_id FROM connec)
SELECT c.connec_id::varchar(30), c.arc_id FROM selector_state,c WHERE c.state = selector_state.state_id AND selector_state.cur_user = "current_user"()::text
EXCEPT
SELECT p.connec_id::varchar(30), p.arc_id FROM s, p WHERE p.psector_id = s.psector_id AND s.cur_user = "current_user"()::text AND p.state = 0
UNION
SELECT DISTINCT ON (p.connec_id) p.connec_id::varchar(30), p.arc_id FROM s, p WHERE p.psector_id = s.psector_id AND s.cur_user = "current_user"()::text AND p.state = 1;


CREATE OR REPLACE VIEW v_state_gully AS
WITH
p AS (SELECT gully_id, psector_id, state, arc_id FROM plan_psector_x_gully WHERE active),
s AS (SELECT * FROM selector_psector WHERE cur_user = current_user),
c as (SELECT gully_id, state, arc_id FROM gully)
SELECT c.gully_id, c.arc_id FROM selector_state,c WHERE c.state = selector_state.state_id AND selector_state.cur_user = "current_user"()::text
EXCEPT
SELECT p.gully_id, p.arc_id FROM selector_psector, p WHERE p.psector_id = selector_psector.psector_id AND selector_psector.cur_user = "current_user"()::text AND p.state = 0
SELECT p.gully_id, p.arc_id FROM s, p WHERE p.psector_id = s.psector_id AND s.cur_user = "current_user"()::text AND p.state = 0
UNION
SELECT p.gully_id, p.arc_id FROM selector_psector, p WHERE p.psector_id = selector_psector.psector_id AND selector_psector.cur_user = "current_user"()::text AND p.state = 1;
SELECT DISTINCT ON (p.gully_id) p.gully_id, p.arc_id FROM s, p WHERE p.psector_id = s.psector_id AND s.cur_user = "current_user"()::text AND p.state = 1;


CREATE OR REPLACE VIEW v_state_link_connec AS
WITH
p AS (SELECT connec_id, psector_id, state, link_id FROM plan_psector_x_connec WHERE active),
Expand Down Expand Up @@ -218,9 +231,22 @@ BEGIN


CREATE OR REPLACE VIEW v_state_link AS
SELECT * FROM v_state_link_connec
UNION
SELECT * FROM v_state_link_gully;
WITH
c AS (SELECT connec_id, psector_id, state, link_id FROM plan_psector_x_connec WHERE active),
g AS (SELECT gully_id, psector_id, state, link_id FROM plan_psector_x_gully WHERE active),
sp AS (SELECT * FROM selector_psector WHERE cur_user = current_user),
se AS (SELECT * FROM selector_expl WHERE cur_user = current_user),
l AS (SELECT link_id, state, expl_id, expl_id2 FROM link)
SELECT l.link_id FROM selector_state, se, l WHERE l.state = selector_state.state_id AND (l.expl_id = se.expl_id OR l.expl_id2 = se.expl_id) AND selector_state.cur_user = "current_user"()::text AND se.cur_user = "current_user"()::text
EXCEPT
SELECT c.link_id FROM sp, se, c JOIN l USING (link_id) WHERE c.psector_id = sp.psector_id AND sp.cur_user = "current_user"()::text AND c.state = 0 AND l.expl_id = se.expl_id AND se.cur_user = CURRENT_USER::text
EXCEPT
SELECT g.link_id FROM sp, se, g JOIN l USING (link_id) WHERE g.psector_id = sp.psector_id AND sp.cur_user = "current_user"()::text AND g.state = 0 AND l.expl_id = se.expl_id AND se.cur_user = CURRENT_USER::text
UNION
SELECT c.link_id FROM sp, se, c JOIN l USING (link_id) WHERE c.psector_id = sp.psector_id AND sp.cur_user = "current_user"()::text AND c.state = 1 AND l.expl_id = se.expl_id AND se.cur_user = CURRENT_USER::text
UNION
SELECT g.link_id FROM sp, se, g JOIN l USING (link_id) WHERE g.psector_id = sp.psector_id AND sp.cur_user = "current_user"()::text AND g.state = 1 AND l.expl_id = se.expl_id AND se.cur_user = CURRENT_USER::text;

END IF;

v_message = 'PLAN MODE SUCESSFULLY RECOVERED';
Expand Down
8 changes: 6 additions & 2 deletions utils/fct/gw_fct_setinitproject.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ BEGIN
SET search_path = "SCHEMA_NAME", public;
v_schemaname = 'SCHEMA_NAME';

SELECT project_type, giswater, epsg INTO v_project_type, v_version, v_epsg FROM sys_version order by id desc limit 1;
SELECT project_type, giswater, epsg INTO v_project_type, v_version, v_epsg FROM sys_version order by id desc limit 1;

-- Get input parameters
v_user := (p_data ->> 'client')::json->> 'cur_user';
v_isaudit := (p_data ->> 'data')::json->> 'isAudit';
v_isaudit := (p_data ->> 'data')::json->> 'isAudit';

if v_user is null then
v_user = current_user;
end if;

-- check if role name exists
IF v_user IS NOT NULL THEN
Expand Down
4 changes: 2 additions & 2 deletions ws/fct/ws_gw_fct_pg2epa_main.sql
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ BEGIN
UPDATE temp_t_arc SET result_id = v_result;
UPDATE temp_t_node SET result_id = v_result;

PERFORM gw_fct_pg2epa_dscenario(v_result);

-- move patterns used
INSERT INTO temp_rpt_inp_pattern_value (result_id, pattern_id, factor_1, factor_2, factor_3, factor_4, factor_5, factor_6, factor_7, factor_8,
factor_9, factor_10, factor_11, factor_12, factor_13, factor_14, factor_15, factor_16, factor_17, factor_18)
Expand All @@ -315,8 +317,6 @@ BEGIN
AND pattern_id IS NOT NULL UNION SELECT distinct (pattern_id) FROM temp_t_node WHERE pattern_id IS NOT NULL)
order by pattern_id, id;

PERFORM gw_fct_pg2epa_dscenario(v_result);

v_return = '{"status": "Accepted", "message":{"level":1, "text":"Export INP file 4/7 - Structure data...... done succesfully"}}'::json;
RETURN v_return;

Expand Down

0 comments on commit b2ebc5d

Please sign in to comment.