Skip to content

Commit

Permalink
feat(trg_edit): insert sector_id and muni_id automatically if null
Browse files Browse the repository at this point in the history
  • Loading branch information
mguzman14 committed Aug 29, 2024
1 parent f77d33c commit 8beacdc
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 6 deletions.
18 changes: 15 additions & 3 deletions ud/ftrg/ud_gw_trg_edit_dma.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,26 @@ BEGIN
ST_DWithin(NEW.the_geom, exploitation.the_geom,0.001) LIMIT 1);
END IF;
END IF;


-- Sector
IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := (SELECT sector_id FROM sector WHERE ST_intersects(NEW.the_geom, sector.the_geom) AND active IS TRUE limit 1);

IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := 0;
END IF;
END IF;



-- active
IF NEW.active IS NULL THEN
NEW.active = TRUE;
END IF;

INSERT INTO dma (dma_id, name, descript, macrodma_id, the_geom, undelete, expl_id, link, active, stylesheet, expl_id2, sector_id)
VALUES (NEW.dma_id, NEW.name, NEW.descript, NEW.macrodma_id, NEW.the_geom, NEW.undelete, NEW.expl_id, NEW.link, NEW.active, NEW.stylesheet, NEW.expl_id2, NEW.sector_id);
INSERT INTO dma (dma_id, name, descript, macrodma_id, the_geom, undelete, expl_id, link, active, stylesheet, sector_id)
VALUES (NEW.dma_id, NEW.name, NEW.descript, NEW.macrodma_id, NEW.the_geom, NEW.undelete, NEW.expl_id, NEW.link, NEW.active, NEW.stylesheet, NEW.sector_id);

RETURN NEW;

Expand All @@ -44,7 +56,7 @@ BEGIN
UPDATE dma
SET dma_id=NEW.dma_id, name=NEW.name, descript=NEW.descript, the_geom=NEW.the_geom, undelete=NEW.undelete, expl_id=NEW.expl_id,
link=NEW.link, active=NEW.active, lastupdate=now(),
lastupdate_user = current_user, macrodma_id = NEW.macrodma_id, stylesheet=NEW.stylesheet, expl_id2 = NEW.expl_id2, sector=NEW.sector_id
lastupdate_user = current_user, macrodma_id = NEW.macrodma_id, stylesheet=NEW.stylesheet, sector=NEW.sector_id
WHERE dma_id=OLD.dma_id;

RETURN NEW;
Expand Down
9 changes: 9 additions & 0 deletions ud/ftrg/ud_gw_trg_edit_drainzone.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ BEGIN
END IF;
END IF;

-- Sector
IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := (SELECT sector_id FROM sector WHERE ST_intersects(NEW.the_geom, sector.the_geom) AND active IS TRUE limit 1);
END IF;

IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := 0;
END IF;

-- active
IF NEW.active IS NULL THEN
NEW.active = TRUE;
Expand Down
11 changes: 11 additions & 0 deletions ud/ftrg/ud_gw_trg_edit_raingage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ BEGIN
END IF;
END IF;

-- Municipality

-- getting value from geometry of mapzone
IF (NEW.muni_id IS NULL) THEN
NEW.muni_id := (SELECT muni_id FROM ext_municipality WHERE ST_intersects(NEW.the_geom, ext_municipality.the_geom) AND active IS TRUE limit 1);
END IF;

IF (NEW.muni_id IS NULL) THEN
NEW.muni_id := 0
END IF;

-- FEATURE INSERT
INSERT INTO raingage (rg_id, form_type, intvl, scf, rgage_type, timser_id, fname, sta, units, the_geom, expl_id, muni_id)
VALUES (NEW.rg_id, NEW.form_type, NEW.intvl, NEW.scf, NEW.rgage_type, NEW.timser_id, NEW.fname, NEW.sta, NEW.units, NEW.the_geom, NEW.expl_id, NEW.muni_id);
Expand Down
2 changes: 2 additions & 0 deletions updates/36/36012/ud/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ SELECT gw_fct_admin_manage_fields($${"data":{"action":"DROP","table":"dma", "col
SELECT gw_fct_admin_manage_fields($${"data":{"action":"DROP","table":"dma", "column":"min"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"DROP","table":"dma", "column":"max"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"DROP","table":"dma", "column":"effec"}}$$);
SELECT gw_fct_admin_manage_fields($${"data":{"action":"DROP","table":"dma", "column":"expl_id2"}}$$);



DROP FUNCTION IF EXISTS gw_fct_graphanalytics_downstream_recursive;
Expand Down
1 change: 1 addition & 0 deletions updates/36/36012/ud/ddlview.sql
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ AS SELECT
dma.sector_id,
s.name as sector_name,
dma.descript,
dma.undelete,
dma.link,
dma.active,
dma.stylesheet,
Expand Down
19 changes: 19 additions & 0 deletions utils/ftrg/gw_trg_edit_dimensions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ BEGIN
END IF;
END IF;


-- Sector
IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := (SELECT sector_id FROM sector WHERE ST_intersects(NEW.the_geom, sector.the_geom) AND active IS TRUE limit 1);

IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := 0;
END IF;
END IF;

-- Municipality
IF (NEW.muni_id IS NULL) THEN
NEW.muni_id := (SELECT m.muni_id FROM sector, ext_municipality m WHERE ST_intersects(m.the_geom, sector.the_geom) AND sector.active IS TRUE limit 1);

IF (NEW.muni_id IS NULL) THEN
NEW.muni_id := 0;
END IF;
END IF;

-- State
IF (NEW.state IS NULL) THEN
NEW.state := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_state_vdefault' AND "cur_user"="current_user"());
Expand Down
20 changes: 20 additions & 0 deletions utils/ftrg/gw_trg_edit_element.sql
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,26 @@ BEGIN
END IF;
END IF;
END IF;

-- Sector
IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := (SELECT sector_id FROM sector WHERE ST_intersects(NEW.the_geom, sector.the_geom) AND active IS TRUE limit 1);

IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := 0;
END IF;
END IF;

-- Municipality
IF (NEW.muni_id IS NULL) THEN
NEW.muni_id := (SELECT m.muni_id FROM sector, ext_municipality m WHERE ST_intersects(m.the_geom, sector.the_geom) AND sector.active IS TRUE limit 1);


IF (NEW.muni_id IS NULL) THEN
NEW.muni_id := 0;
END IF;
END IF;


-- Enddate
IF (NEW.state > 0) THEN
Expand Down
23 changes: 22 additions & 1 deletion utils/ftrg/gw_trg_edit_samplepoint.sql
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ BEGIN
-- control error when no value
IF (NEW.expl_id IS NULL) THEN
EXECUTE 'SELECT gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{},
"data":{"message":"2012", "function":"1302","debug_msg":"'||NEW.arc_id::text||'"}}$$);';
"data":{"message":"2012", "function":"1302","debug_msg":"'||NEW.sample_id::text||'"}}$$);';
END IF;
END IF;

Expand All @@ -79,6 +79,27 @@ BEGIN
NEW.dma_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_dma_vdefault' AND "cur_user"="current_user"());
END IF;
END IF;


-- Sector
IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := (SELECT sector_id FROM sector WHERE ST_intersects(NEW.the_geom, sector.the_geom) AND active IS TRUE limit 1);

IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := 0;
END IF;
END IF;

-- Municipality
IF (NEW.muni_id IS NULL) THEN
NEW.muni_id := (SELECT m.muni_id FROM sector, ext_municipality m WHERE ST_intersects(m.the_geom, sector.the_geom) AND sector.active IS TRUE limit 1);


IF (NEW.muni_id IS NULL) THEN
NEW.muni_id := 0;
END IF;
END IF;


IF v_projectype = 'WS' THEN
INSERT INTO samplepoint (sample_id, code, lab_code, feature_id, featurecat_id, dma_id, presszone_id, "state", builtdate, enddate,
Expand Down
9 changes: 9 additions & 0 deletions ws/ftrg/ws_gw_trg_edit_dma.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ BEGIN
END IF;
END IF;

-- Sector
IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := (SELECT sector_id FROM sector WHERE ST_intersects(NEW.the_geom, sector.the_geom) AND active IS TRUE limit 1);

IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := 0;
END IF;
END IF;

-- active
IF NEW.active IS NULL THEN
NEW.active = TRUE;
Expand Down
10 changes: 10 additions & 0 deletions ws/ftrg/ws_gw_trg_edit_dqa.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ BEGIN
END IF;
END IF;

-- Sector
IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := (SELECT sector_id FROM sector WHERE ST_intersects(NEW.the_geom, sector.the_geom) AND active IS TRUE limit 1);

IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := 0;
END IF;
END IF;


-- active
IF NEW.active IS NULL THEN
NEW.active = TRUE;
Expand Down
10 changes: 10 additions & 0 deletions ws/ftrg/ws_gw_trg_edit_presszone.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ BEGIN
END IF;
END IF;

-- Sector
IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := (SELECT sector_id FROM sector WHERE ST_intersects(NEW.the_geom, sector.the_geom) AND active IS TRUE limit 1);

IF (NEW.sector_id IS NULL) THEN
NEW.sector_id := 0;
END IF;
END IF;


-- active
IF NEW.active IS NULL THEN
NEW.active = TRUE;
Expand Down
14 changes: 12 additions & 2 deletions ws/ftrg/ws_gw_trg_edit_unconnected.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ BEGIN
IF (expl_id_int IS NULL) THEN
expl_id_int := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_exploitation_vdefault' AND "cur_user"="current_user"());
END IF;

-- Municipality
IF (NEW.muni_id IS NULL) THEN
NEW.muni_id := (SELECT m.muni_id FROM ext_municipality m WHERE ST_intersects(NEW.the_geom, m.the_geom) AND active IS TRUE limit 1);

IF (NEW.muni_id IS NULL) THEN
NEW.muni_id := 0;
END IF;
END IF;

-- State
IF (NEW.state IS NULL) THEN
NEW.state := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_state_vdefault' AND "cur_user"="current_user"());
Expand All @@ -52,14 +61,15 @@ BEGIN
--"data":{"message":"1012", "function":"1330","debug_msg":null, "variables":null}}$$);
RETURN NULL;
END IF;
NEW.dma_id := (SELECT dma_id FROM dma WHERE ST_DWithin(NEW.the_geom, dma.the_geom,0.001) AND active IS TRUE LIMIT 1);
NEW.dma_id := (SELECT dma_id FROM dma WHERE ST_DWithin(NEW.the_geom, dma.the_geom,0.001) AND dma.active IS TRUE LIMIT 1);
IF (NEW.dma_id IS NULL) THEN
NEW.dma_id := (SELECT "value" FROM config_param_user WHERE "parameter"='edit_dma_vdefault' AND "cur_user"="current_user"());
END IF;
IF (NEW.dma_id IS NULL) THEN
--PERFORM gw_fct_getmessage($${"client":{"device":4, "infoType":1, "lang":"ES"},"feature":{},
--"data":{"message":"1014", "function":"1330","debug_msg":null, "variables":null}}$$);
RETURN NULL;
NEW.dma_id := 0;

END IF;
END IF;

Expand Down

0 comments on commit 8beacdc

Please sign in to comment.