-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(getlayerstofilter): returns are the layers that have the columns…
… muni_id and sector_id (p. ex) in their primitive tables
- Loading branch information
1 parent
10bad17
commit 5f3fc68
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
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: 3380 | ||
|
||
DROP FUNCTION SCHEMA_NAME.gw_fct_getlayerstofilter(json); | ||
|
||
CREATE OR REPLACE FUNCTION SCHEMA_NAME.gw_fct_getlayerstofilter(p_data json) | ||
RETURNS json | ||
LANGUAGE plpgsql | ||
AS $function$ | ||
|
||
/* | ||
SELECT SCHEMA_NAME.gw_fct_getselectorsfiltered($${"client":{"device": 5, "lang": "es_ES", "cur_user": "bgeo", "tiled": "False", "infoType": 1}, "form":{}, "feature":{}, | ||
"data":{"filterFields":{}, "pageInfo":{}, "filter": ["muni_id", "sector_id"],"layers": ["Node","Connec"]}}$$); | ||
*/ | ||
|
||
DECLARE | ||
|
||
v_layer text; | ||
v_msgerr json; | ||
v_version json; | ||
v_errcontext text; | ||
v_device integer; | ||
v_layers jsonb; | ||
v_cur_user text; | ||
v_layersFiltered text[] := ARRAY[]::text[]; | ||
v_columns jsonb; | ||
v_schemaname text; | ||
v_filter jsonb; | ||
|
||
BEGIN | ||
|
||
-- Set search path to local schema | ||
SET search_path = "SCHEMA_NAME", public; | ||
v_schemaname = "SCHEMA_NAME"; | ||
|
||
-- get api version | ||
EXECUTE 'SELECT row_to_json(row) FROM (SELECT value FROM config_param_system WHERE parameter=''admin_version'') row' INTO v_version; | ||
|
||
-- Get input parameters: | ||
v_cur_user := (p_data ->> 'client')::json->> 'cur_user'; | ||
v_device := (p_data ->> 'client')::json->> 'device'; | ||
v_filter := (p_data ->> 'data')::jsonb->> 'filter'; | ||
v_layers := (p_data ->> 'data')::jsonb->> 'layers'; | ||
|
||
FOR v_layer IN SELECT jsonb_array_elements_text(v_layers) | ||
LOOP | ||
SELECT json_agg(column_name) INTO v_columns FROM information_schema.columns WHERE table_schema = v_schemaname AND table_name = lower(v_layer); | ||
-- Check if v_columns contain the columns filter | ||
IF v_columns @> v_filter THEN | ||
v_layersFiltered := array_append(v_layersFiltered,v_layer); | ||
END IF; | ||
END LOOP; | ||
|
||
RETURN gw_fct_json_create_return(json_build_object( | ||
'status', 'Accepted', | ||
'version', v_version, | ||
'body', json_build_object('layers', v_layersFiltered) | ||
),3380, null, null, NULL); | ||
|
||
-- Exception handling | ||
EXCEPTION WHEN OTHERS THEN | ||
GET STACKED DIAGNOSTICS v_errcontext = pg_exception_context; | ||
RETURN json_build_object('status', 'Failed','NOSQLERR', SQLERRM, 'version', v_version, 'SQLSTATE', SQLSTATE, 'MSGERR', (v_msgerr::json ->> 'MSGERR'))::json; | ||
|
||
END; | ||
$function$ | ||
; |