Skip to content

Commit

Permalink
Merge branch 'master' into h3-filter-tool
Browse files Browse the repository at this point in the history
  • Loading branch information
underbluewaters committed Oct 9, 2024
2 parents 5b72501 + 36d1d36 commit e8087e1
Show file tree
Hide file tree
Showing 42 changed files with 2,053 additions and 607 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ jobs:
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
R2_ENDPOINT: ${{ secrets.R2_ENDPOINT }}
R2_FILE_UPLOADS_BUCKET: ${{ secrets.R2_FILE_UPLOADS_BUCKET }}
R2_TILES_BUCKET: ${{ secrets.R2_TILES_BUCKET }}
CLOUDFLARE_IMAGES_ACCOUNT: ${{ secrets.CLOUDFLARE_IMAGES_ACCOUNT }}
CLOUDFLARE_IMAGES_TOKEN: ${{ secrets.CLOUDFLARE_IMAGES_TOKEN }}
CLOUDFLARE_IMAGES_ACCOUNT_HASH: ${{ secrets.CLOUDFLARE_IMAGES_ACCOUNT_HASH }}
Expand Down
5 changes: 5 additions & 0 deletions packages/api/generated-schema-clean.gql
Original file line number Diff line number Diff line change
Expand Up @@ -3388,8 +3388,10 @@ enum DataUploadOutputType {
FLAT_GEOBUF
GEO_JSON
GEO_TIFF
NET_CDF
PMTILES
PNG
XMLMETADATA
ZIPPED_SHAPEFILE
}

Expand Down Expand Up @@ -9574,6 +9576,7 @@ type Mutation {
"""
input: UpdateTableOfContentsItemChildrenInput!
): UpdateTableOfContentsItemChildrenPayload
updateTocMetadataFromXML(filename: String, id: Int!, xmlMetadata: String!): TableOfContentsItem!

"""Updates a single `Topic` using a unique key and a patch."""
updateTopic(
Expand Down Expand Up @@ -14329,6 +14332,8 @@ type TableOfContentsItem implements Node {
DraftJS compatible representation of text content to display when a user requests layer metadata. Not valid for Folders
"""
metadata: JSON
metadataFormat: String
metadataXml: DataUploadOutput

"""
A globally unique identifier. Can be used in various places throughout the system to identify this single value.
Expand Down
6 changes: 5 additions & 1 deletion packages/api/generated-schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -3388,8 +3388,10 @@ enum DataUploadOutputType {
FLAT_GEOBUF
GEO_JSON
GEO_TIFF
NET_CDF
PMTILES
PNG
XMLMETADATA
ZIPPED_SHAPEFILE
}

Expand Down Expand Up @@ -9574,7 +9576,7 @@ type Mutation {
"""
input: UpdateTableOfContentsItemChildrenInput!
): UpdateTableOfContentsItemChildrenPayload
updateTocMetadataFromXML(id: Int!, xmlMetadata: String!): TableOfContentsItem!
updateTocMetadataFromXML(filename: String, id: Int!, xmlMetadata: String!): TableOfContentsItem!

"""Updates a single `Topic` using a unique key and a patch."""
updateTopic(
Expand Down Expand Up @@ -14330,6 +14332,8 @@ type TableOfContentsItem implements Node {
DraftJS compatible representation of text content to display when a user requests layer metadata. Not valid for Folders
"""
metadata: JSON
metadataFormat: String
metadataXml: DataUploadOutput

"""
A globally unique identifier. Can be used in various places throughout the system to identify this single value.
Expand Down
119 changes: 119 additions & 0 deletions packages/api/migrations/committed/000335.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
--! Previous: sha1:b29221121218a7daf08c79f2e2580f66236bfdfc
--! Hash: sha1:fc2579e6e5275d22de4e81f534d1666a014721f8

-- Enter migration here
alter type data_upload_output_type add value if not exists 'XMLMetadata';

drop function if exists table_of_contents_items_metadata_xml;
create or replace function table_of_contents_items_metadata_xml(item table_of_contents_items)
returns data_upload_outputs
language plpgsql
stable
security definer
as $$
declare
ds_id int;
data_upload_output data_upload_outputs;
begin
select data_source_id into ds_id from data_layers where id = item.data_layer_id;
if ds_id is null then
return null;
end if;
select * into data_upload_output from data_upload_outputs where data_source_id = ds_id and type = 'XMLMetadata';
return data_upload_output;
end;
$$;

grant execute on function table_of_contents_items_metadata_xml(table_of_contents_items) to anon;

drop function if exists create_metadata_xml_output;
create or replace function create_metadata_xml_output(data_source_id int, url text, remote text, size bigint, filename text, metadata_type text)
returns data_upload_outputs
language plpgsql
security definer
as $$
declare
source_exists boolean;
output_id int;
output data_upload_outputs;
original_fname text;
pid int;
begin
-- first, check if data_source even exists
select exists(select 1 from data_sources where id = data_source_id) into source_exists;
if source_exists = false then
raise exception 'Data source does not exist';
end if;

select
original_filename,
project_id
into original_fname, pid
from data_upload_outputs
where
data_upload_outputs.data_source_id = create_metadata_xml_output.data_source_id;
if session_is_admin(pid) = false then
raise exception 'Only admins can create metadata xml outputs';
end if;
-- delete existing metadata xml output
delete from
data_upload_outputs
where
data_upload_outputs.data_source_id = create_metadata_xml_output.data_source_id and
type = 'XMLMetadata';
insert into data_upload_outputs (
data_source_id,
project_id,
type,
url,
remote,
size,
filename,
original_filename
) values (
create_metadata_xml_output.data_source_id,
pid,
'XMLMetadata',
url,
remote,
size,
filename,
original_fname
) returning * into output;
UPDATE data_sources
SET geostats = jsonb_set(
geostats,
'{layers,0,metadata,type}',
metadata_type::jsonb,
true
)
WHERE data_sources.id = id and
jsonb_typeof(geostats->'layers'->0->'metadata'->'type') IS NOT NULL;
return output;
end;
$$;

grant execute on function create_metadata_xml_output to seasketch_user;

comment on function create_metadata_xml_output is '@omit';

drop function if exists table_of_contents_items_metadata_format;
create or replace function table_of_contents_items_metadata_format(item table_of_contents_items)
returns text
language plpgsql
stable
security definer
as $$
declare
ds_id int;
metadata_type text;
begin
select data_source_id into ds_id from data_layers where id = item.data_layer_id;
SELECT geostats->'layers'->0->'metadata'->>'type' into metadata_type
FROM data_sources
WHERE jsonb_typeof(geostats->'layers'->0->'metadata'->'type') IS NOT NULL;
return metadata_type;
end;
$$;

grant execute on function table_of_contents_items_metadata_format(table_of_contents_items) to anon;
5 changes: 5 additions & 0 deletions packages/api/migrations/committed/000336.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--! Previous: sha1:fc2579e6e5275d22de4e81f534d1666a014721f8
--! Hash: sha1:b8cbc01e7d5166e77a68f5e3072082b77ff40769

-- Enter migration here
alter type data_upload_output_type add value if not exists 'NetCDF';
Loading

0 comments on commit e8087e1

Please sign in to comment.