Skip to content

Commit

Permalink
feat(go2epa_manager_button): add function and configurations for new …
Browse files Browse the repository at this point in the history
…btn show inp data
  • Loading branch information
FerranMart committed Aug 20, 2024
1 parent 49febe2 commit 7dc1bc8
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
29 changes: 28 additions & 1 deletion updates/36/36012/utils/dml.sql
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,31 @@ UPDATE config_param_system set value = gw_fct_json_object_set_key(value::json, '

UPDATE config_param_system set value = replace(value, 'sector_id >=0', 'sector_id >0') where parameter = 'basic_selector_tab_sector';

UPDATE link SET muni_id = c.muni_id FROM connec c WHERE connec_id = feature_id;
UPDATE link SET muni_id = c.muni_id FROM connec c WHERE connec_id = feature_id;

-- 20/08/2024
INSERT INTO config_function (id, function_name, "style", layermanager, actions) VALUES(3303, 'gw_fct_getinpdata', '{
"style": {
"point": {
"style": "categorized",
"field": "fid",
"width": 2,
"transparency": 0.5
},
"line": {
"style": "categorized",
"field": "result_id",
"width": 2,
"transparency": 0.5
},
"polygon": {
"style": "categorized",
"field": "fid",
"width": 2,
"transparency": 0.5
}
}
}'::json, NULL, NULL);

INSERT INTO sys_function (id,function_name,project_type,function_type,input_params,return_type,descript,sys_role,"source")
VALUES (3310,'gw_fct_getinpdata','utils','function','json','json','The function retrieves GeoJSON data for nodes and arcs based on selected result IDs and returns it in a structured JSON format.','role_epa','core');
71 changes: 71 additions & 0 deletions utils/fct/gw_fct_getinpdata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
This file is part of Giswater 3
The program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This version of Giswater is provided by Giswater Association
*/

--FUNCTION CODE: 3310

CREATE OR REPLACE FUNCTION gw_fct_getinpdata(result_ids TEXT[])
RETURNS json
LANGUAGE plpgsql
AS $function$
DECLARE
v_status TEXT := 'Accepted';
v_message TEXT := 'Data retrieved successfully';
v_node JSON;
v_result_point JSON;
v_result_line JSON;
v_result_polygon JSON := '{"geometryType":"Polygon","features":[]}'; -- Without polygon, empty

BEGIN
-- Check if result_ids is NULL or has an invalid value
IF result_ids IS NULL OR array_length(result_ids, 1) IS NULL THEN
RETURN gw_fct_json_create_return(
'{"status":"Failed", "message":{"level":3, "text":"Invalid input"}}'::json, 2218, null, null, null
);
END IF;

-- Get GeoJSON from rpt_inp_node (Point)
SELECT json_build_object(
'geometryType', 'Point',
'layerName', 'Rpt INP Node',
'features', json_agg(ST_AsGeoJSON(t.*)::json)
)
INTO v_node
FROM rpt_inp_node t
WHERE result_id = ANY(result_ids);

-- Get GeoJSON from rpt_inp_arc (LineString)
SELECT json_build_object(
'geometryType', 'LineString',
'layerName', 'Rpt INP Arc',
'features', json_agg(ST_AsGeoJSON(t.*)::json)
)
INTO v_result_line
FROM rpt_inp_arc t
WHERE result_id = ANY(result_ids);

-- Construct the JSON
RETURN gw_fct_json_create_return(
('{"status":"' || v_status || '", "message":{"level":3, "text":"' || v_message || '"},' ||
'"body":{"data":{' ||
'"point":' || COALESCE(v_node::text, '{"geometryType":"Point","features":[]}') || ',' ||
'"line":' || COALESCE(v_result_line::text, '{"geometryType":"LineString","features":[]}') || ',' ||
'"polygon":' || COALESCE(v_result_polygon::text, '{"geometryType":"Polygon","features":[]}') || '}}}'
)::json, 2218, null, null, null
);

EXCEPTION
WHEN OTHERS THEN
RETURN gw_fct_json_create_return(
json_build_object(
'status', 'Failed',
'message', json_build_object(
'level', 3,
'text', replace(SQLERRM, '"', '\"')
)
), 2218, null, null, null
);
END;
$function$;

0 comments on commit 7dc1bc8

Please sign in to comment.