-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development-quarkus' of github.com:ScorpioBroker/Scorpi…
…oBroker into development-quarkus
- Loading branch information
Showing
11 changed files
with
82 additions
and
23 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
AllInOneRunner/src/main/resources/db/migration/V20230811.1__bugfix_mergepatch.sql
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,52 @@ | ||
CREATE OR REPLACE FUNCTION MERGE_JSON(a text, b JSONB) | ||
RETURNS JSONB AS $$ | ||
DECLARE | ||
merged_json JSONB; | ||
key TEXT; | ||
value JSONB; | ||
value2 JSONB; | ||
previous_entity JSONB; | ||
BEGIN | ||
merged_json := (Select entity from entity where id =a); | ||
previous_entity := (Select entity from entity where id =a); | ||
-- Iterate through keys in JSON B | ||
FOR key, value IN SELECT * FROM JSONB_EACH(b) | ||
LOOP | ||
IF value::TEXT LIKE '%"https://uri.etsi.org/ngsi-ld/hasValue": [{"@value": "urn:ngsi-ld:null"}]%'::TEXT | ||
OR value::TEXT LIKE '%"https://uri.etsi.org/ngsi-ld/hasObject": [{"@id": "urn:ngsi-ld:null"}]%'::TEXT | ||
THEN | ||
-- Delete the key | ||
merged_json := merged_json - key; | ||
ELSIF merged_json ? key THEN | ||
-- Update the value | ||
raise notice '%', 'update'; | ||
value2 := (value->0)::jsonb ; | ||
IF jsonb_typeof(value2) = 'object' THEN | ||
value2 :=value2 - 'https://uri.etsi.org/ngsi-ld/createdAt'; | ||
end if; | ||
merged_json := jsonb_set(merged_json, ARRAY[key], jsonb_build_array(value2), true); | ||
IF previous_entity->key->0 ? 'https://uri.etsi.org/ngsi-ld/createdAt' then | ||
merged_json := jsonb_set(merged_json, ARRAY[key,'0','https://uri.etsi.org/ngsi-ld/createdAt'], (previous_entity->key->0->'https://uri.etsi.org/ngsi-ld/createdAt'), true); | ||
end if; | ||
ELSE | ||
-- Add the key-value pair | ||
raise notice '%', 'add'; | ||
merged_json := jsonb_set(merged_json, ARRAY[key], value, true); | ||
END IF; | ||
|
||
END LOOP; | ||
merged_json := jsonb_strip_nulls(replace(merged_json::text,'"urn:ngsi-ld:null"','null')::jsonb); | ||
merged_json := regexp_replace(merged_json::text, '{"@language": "[^"]*"}', 'null', 'g')::jsonb; | ||
while merged_json::text like '%[]%' | ||
or merged_json::text like '%{}%' | ||
or merged_json::text like '%null%' loop | ||
merged_json := jsonb_strip_nulls(replace(merged_json::text,'null,','')::jsonb); | ||
merged_json := jsonb_strip_nulls(replace(merged_json::text,', null','')::jsonb); | ||
merged_json := jsonb_strip_nulls(replace(merged_json::text,'[null]','null')::jsonb); | ||
merged_json := jsonb_strip_nulls(replace(merged_json::text,'[]','null')::jsonb); | ||
merged_json := jsonb_strip_nulls(replace(merged_json::text,'{}','null')::jsonb); | ||
end loop; | ||
update entity set entity = merged_json, e_types = ARRAY(SELECT jsonb_array_elements_text(merged_json->'@type')) where id = a; | ||
RETURN previous_entity; | ||
END; | ||
$$ LANGUAGE plpgsql; |
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
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 |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
* @created 11-Jun-2018 11:13:22 | ||
*/ | ||
public enum Format { | ||
keyValues, normalized | ||
keyValues, normalized,concise | ||
} |
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
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
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